diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,6 @@ find_package(Grantlee5 "5.0" CONFIG REQUIRED) -find_package(Xsltproc) - ##################### Definitions ##################### add_definitions(-DQT_NO_KEYWORDS) add_definitions(-DQT_NO_CAST_FROM_ASCII) diff --git a/cmake/modules/FindXsltproc.cmake b/cmake/modules/FindXsltproc.cmake deleted file mode 100644 --- a/cmake/modules/FindXsltproc.cmake +++ /dev/null @@ -1,32 +0,0 @@ -# Find xsltproc executable and provide a macro to generate D-Bus interfaces. -# -# The following variables are defined : -# XSLTPROC_EXECUTABLE - path to the xsltproc executable -# Xsltproc_FOUND - true if the program was found -# -find_program(XSLTPROC_EXECUTABLE xsltproc DOC "Path to the xsltproc executable") -mark_as_advanced(XSLTPROC_EXECUTABLE) - -if(XSLTPROC_EXECUTABLE) - set(Xsltproc_FOUND TRUE) - - # We depend on kdepimlibs, make sure it's found - if(NOT DEFINED KF5Akonadi_DATA_DIR) - find_package(KF5Akonadi REQUIRED) - endif() - - - # Macro to generate a D-Bus interface description from a KConfigXT file - macro(kcfg_generate_dbus_interface _kcfg _name) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.xml - COMMAND ${XSLTPROC_EXECUTABLE} --stringparam interfaceName ${_name} - ${KF5Akonadi_DATA_DIR}/kcfg2dbus.xsl - ${_kcfg} - > ${CMAKE_CURRENT_BINARY_DIR}/${_name}.xml - DEPENDS ${KF5Akonadi_DATA_DIR}/kcfg2dbus.xsl - ${_kcfg} - ) - endmacro() -endif() - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,6 @@ kjotswidget.cpp kjotsbrowser.cpp kjotslinkdialog.cpp - localresourcecreator.cpp kjotsbookshelfentryvalidator.cpp ${kjots_config_SRCS} ) diff --git a/src/kjotswidget.cpp b/src/kjotswidget.cpp --- a/src/kjotswidget.cpp +++ b/src/kjotswidget.cpp @@ -95,7 +95,6 @@ #include "kjotsbrowser.h" #include "noteshared/notelockattribute.h" #include "noteshared/standardnoteactionmanager.h" -#include "localresourcecreator.h" #include @@ -108,15 +107,6 @@ { ControlGui::widgetNeedsAkonadi(this); - KConfigGroup config(KSharedConfig::openConfig(), "General"); - const bool autoCreate = config.readEntry("AutoCreateResourceOnStart", true); - config.writeEntry("AutoCreateResourceOnStart", autoCreate); - config.sync(); - if (autoCreate) { - auto *creator = new LocalResourceCreator(this); - creator->createIfMissing(); - } - m_splitter = new QSplitter(this); m_splitter->setStretchFactor(1, 1); diff --git a/src/localresourcecreator.h b/src/localresourcecreator.h deleted file mode 100644 --- a/src/localresourcecreator.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef LOCALRESOURCECREATOR_H -#define LOCALRESOURCECREATOR_H - -#include - -#include "noteshared/localresourcecreator.h" - -class KJob; - -/** - * @brief Creates a notes resource, a book and a page if one does not already exist. - */ -class LocalResourceCreator : public NoteShared::LocalResourceCreator -{ - Q_OBJECT -public: - explicit LocalResourceCreator(QObject *parent = nullptr); - -protected: - void finishCreateResource() override; - -private Q_SLOTS: - void rootFetchFinished(KJob *job); - void topLevelFetchFinished(KJob *job); - void createFinished(KJob *job); - -}; - -#endif diff --git a/src/localresourcecreator.cpp b/src/localresourcecreator.cpp deleted file mode 100644 --- a/src/localresourcecreator.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "localresourcecreator.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -LocalResourceCreator::LocalResourceCreator(QObject *parent) - : NoteShared::LocalResourceCreator(parent) -{ - -} - -void LocalResourceCreator::finishCreateResource() -{ - auto *collectionFetchJob = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(), Akonadi::CollectionFetchJob::FirstLevel, this); - connect(collectionFetchJob, &Akonadi::CollectionFetchJob::result, this, &LocalResourceCreator::rootFetchFinished); -} - -void LocalResourceCreator::rootFetchFinished(KJob *job) -{ - if (job->error()) { - qWarning() << job->errorString(); - deleteLater(); - return; - } - - auto *lastCollectionFetchJob = qobject_cast(job); - if (!lastCollectionFetchJob) { - deleteLater(); - return; - } - - Akonadi::Collection::List list = lastCollectionFetchJob->collections(); - - if (list.isEmpty()) { - qWarning() << "Couldn't find new collection in resource"; - deleteLater(); - return; - } - - for (const Akonadi::Collection &col : qAsConst(list)) { - Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(col.resource()); - if (instance.type().identifier() == akonadiNotesInstanceName()) { - Akonadi::CollectionFetchJob *collectionFetchJob = new Akonadi::CollectionFetchJob(col, Akonadi::CollectionFetchJob::FirstLevel, this); - collectionFetchJob->setProperty("FetchedCollection", col.id()); - connect(collectionFetchJob, &Akonadi::CollectionFetchJob::result, this, &LocalResourceCreator::topLevelFetchFinished); - return; - } - } - Q_ASSERT(!"Couldn't find new collection"); - deleteLater(); -} - -void LocalResourceCreator::topLevelFetchFinished(KJob *job) -{ - if (job->error()) { - qWarning() << job->errorString(); - deleteLater(); - return; - } - - Akonadi::CollectionFetchJob *lastCollectionFetchJob = qobject_cast(job); - if (!lastCollectionFetchJob) { - deleteLater(); - return; - } - - Akonadi::Collection::List list = lastCollectionFetchJob->collections(); - - if (!list.isEmpty()) { - deleteLater(); - return; - } - - Akonadi::Collection::Id id = lastCollectionFetchJob->property("FetchedCollection").toLongLong(); - - Akonadi::Collection collection; - collection.setParentCollection(Akonadi::Collection(id)); - QString title = i18nc("The default name for new books.", "New Book"); - collection.setName(KRandom::randomString(10)); - collection.setContentMimeTypes({Akonadi::Collection::mimeType(), Akonadi::NoteUtils::noteMimeType()}); - - Akonadi::EntityDisplayAttribute *eda = new Akonadi::EntityDisplayAttribute(); - eda->setIconName(QStringLiteral("x-office-address-book")); - eda->setDisplayName(title); - collection.addAttribute(eda); - - Akonadi::CollectionCreateJob *createJob = new Akonadi::CollectionCreateJob(collection, this); - connect(createJob, &Akonadi::CollectionCreateJob::result, this, &LocalResourceCreator::createFinished); - -} - -void LocalResourceCreator::createFinished(KJob *job) -{ - if (job->error()) { - qWarning() << job->errorString(); - deleteLater(); - return; - } - - Akonadi::CollectionCreateJob *collectionCreateJob = qobject_cast(job); - if (!collectionCreateJob) { - deleteLater(); - return; - } - - Akonadi::Item item; - item.setParentCollection(collectionCreateJob->collection()); - item.setMimeType(Akonadi::NoteUtils::noteMimeType()); - - Akonadi::NoteUtils::NoteMessageWrapper note(KMime::Message::Ptr(new KMime::Message)); - note.setFrom(QStringLiteral("KJots@KDE5")); - note.setTitle(i18nc("The default name for new pages.", "New Page")); - note.setCreationDate(QDateTime::currentDateTime()); - note.setLastModifiedDate(QDateTime::currentDateTime()); - // Need a non-empty body part so that the serializer regards this as a valid message. - note.setText(QStringLiteral(" ")); - - item.setPayload(note.message()); - item.attribute(Akonadi::Item::AddIfMissing)->setIconName(QStringLiteral("text-plain")); - - auto itemJob = new Akonadi::ItemCreateJob(item, collectionCreateJob->collection(), this); - connect(itemJob, &Akonadi::ItemCreateJob::result, this, [this, itemJob](KJob*){ - if (itemJob->error()) { - qWarning() << "Failed to create a note:" << itemJob->errorString(); - } - deleteLater(); - }); -} - diff --git a/src/noteshared/CMakeLists.txt b/src/noteshared/CMakeLists.txt --- a/src/noteshared/CMakeLists.txt +++ b/src/noteshared/CMakeLists.txt @@ -2,7 +2,6 @@ notecreatorandselector.cpp notelockattribute.cpp noteeditorutils.cpp - localresourcecreator.cpp standardnoteactionmanager.cpp ) @@ -12,26 +11,7 @@ CATEGORY_NAME log_noteshared ) -macro(add_resource_iface _kcfgFile _ifaceName _className) - kcfg_generate_dbus_interface(${_kcfgFile} ${_ifaceName}) - string(TOLOWER ${_className} _codeFile) - set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_ifaceName}.xml PROPERTIES - INCLUDE "metatype.h") - qt5_add_dbus_interface(noteshared_SRCS - ${CMAKE_CURRENT_BINARY_DIR}/${_ifaceName}.xml ${_codeFile} ${_className} - ) -endmacro() - -add_resource_iface(${CMAKE_CURRENT_SOURCE_DIR}/maildirresource.kcfg - org.kde.Akonadi.Maildir.Settings MaildirSettings ) - -add_custom_target(noteshared_settings_xml ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.Maildir.Settings.xml - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/maildirresource.kcfg -) - add_library(noteshared STATIC ${noteshared_SRCS}) -add_dependencies(noteshared noteshared_settings_xml) target_link_libraries(noteshared Qt5::Core Qt5::Widgets diff --git a/src/noteshared/localresourcecreator.h b/src/noteshared/localresourcecreator.h deleted file mode 100644 --- a/src/noteshared/localresourcecreator.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) 2013-2015 Montel Laurent - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef NOTESHAREDLOCALRESOURCECREATOR_H -#define NOTESHAREDLOCALRESOURCECREATOR_H - -#include - -class KJob; -namespace NoteShared -{ -class LocalResourceCreator : public QObject -{ - Q_OBJECT -public: - explicit LocalResourceCreator(QObject *parent = nullptr); - - void createIfMissing(); - - static QString akonadiNotesInstanceName(); - -protected: - virtual void finishCreateResource(); - -private: - void createInstance(); - -private Q_SLOTS: - void slotInstanceCreated(KJob *job); - void slotSyncDone(KJob *job); -}; -} - -#endif diff --git a/src/noteshared/localresourcecreator.cpp b/src/noteshared/localresourcecreator.cpp deleted file mode 100644 --- a/src/noteshared/localresourcecreator.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright (c) 2013-2015 Montel Laurent - - based on localresourcecreator from kjots - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "localresourcecreator.h" - -#include -#include -#include -#include - -#include - -#include "maildirsettings.h" -#include "noteshared_debug.h" - -using namespace NoteShared; - -LocalResourceCreator::LocalResourceCreator(QObject *parent) - : QObject(parent) -{ - -} - -QString LocalResourceCreator::akonadiNotesInstanceName() -{ - return QStringLiteral("akonadi_akonotes_resource"); -} - -void LocalResourceCreator::createIfMissing() -{ - const Akonadi::AgentInstance::List instances = Akonadi::AgentManager::self()->instances(); - const bool found = std::any_of(instances.cbegin(), instances.cend(), [](const Akonadi::AgentInstance &instance) { - return instance.type().identifier() == akonadiNotesInstanceName(); - }); - if (found) { - deleteLater(); - return; - } - createInstance(); -} - -void LocalResourceCreator::createInstance() -{ - Akonadi::AgentType notesType = Akonadi::AgentManager::self()->type(akonadiNotesInstanceName()); - - auto *job = new Akonadi::AgentInstanceCreateJob(notesType); - connect(job, &Akonadi::AgentInstanceCreateJob::result, this, &LocalResourceCreator::slotInstanceCreated); - - job->start(); -} - -void LocalResourceCreator::slotInstanceCreated(KJob *job) -{ - if (job->error()) { - qCWarning(NOTESHARED_LOG) << job->errorString(); - deleteLater(); - return; - } - - auto *createJob = qobject_cast(job); - Akonadi::AgentInstance instance = createJob->instance(); - - instance.setName(i18nc("Default name for resource holding notes", "Local Notes")); - auto *iface = new org::kde::Akonadi::Maildir::Settings( - QStringLiteral("org.freedesktop.Akonadi.Resource.") + instance.identifier(), - QStringLiteral("/Settings"), QDBusConnection::sessionBus(), this); - - // TODO: Make errors user-visible. - if (!iface->isValid()) { - qCWarning(NOTESHARED_LOG) << "Failed to obtain D-Bus interface for remote configuration."; - delete iface; - deleteLater(); - return; - } - delete iface; - instance.reconfigure(); - - auto *syncJob = new Akonadi::ResourceSynchronizationJob(instance, this); - connect(syncJob, &Akonadi::ResourceSynchronizationJob::result, this, &LocalResourceCreator::slotSyncDone); - syncJob->start(); -} - -void LocalResourceCreator::slotSyncDone(KJob *job) -{ - if (job->error()) { - qCWarning(NOTESHARED_LOG) << "Synchronizing the resource failed:" << job->errorString(); - deleteLater(); - return; - } - - qCWarning(NOTESHARED_LOG) << "Instance synchronized"; - -} - -void LocalResourceCreator::finishCreateResource() -{ - deleteLater(); -} -