diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ade16f..d0de984 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,107 +1,106 @@ cmake_minimum_required(VERSION 3.5) set(PIM_VERSION "5.13.40") project(Akonadi-Mime VERSION ${PIM_VERSION}) # ECM setup set(KF5_MIN_VERSION "5.67.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(QT_REQUIRED_VERSION "5.12.0") include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMSetupVersion) include(FeatureSummary) include(ECMQtDeclareLoggingCategory) set(AKONADI_MIME_VERSION ${PIM_VERSION}) set(AKONADI_VERSION "5.13.40") set(KF5_MIME_VERSION "5.13.40") ecm_setup_version(PROJECT VARIABLE_PREFIX AKONADIMIME VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/akonadi-mime_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiMimeConfigVersion.cmake" SOVERSION 5 ) ########### Find packages ########### find_package(KF5Codecs ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ConfigWidgets ${KF5_MIN_VERSION} CONFIG REQUIRED) -find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KF5_MIME_VERSION} CONFIG REQUIRED) find_package(KF5ItemModels ${KF5_MIME_VERSION} CONFIG REQUIRED) find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED) set( SharedMimeInfo_MINIMUM_VERSION "1.3" ) find_package(SharedMimeInfo ${SharedMimeInfo_MINIMUM_VERSION} REQUIRED) find_package(LibXslt) set_package_properties(LibXslt PROPERTIES DESCRIPTION "xsltproc" URL "http://xmlsoft.org/XSLT/" TYPE REQUIRED PURPOSE "Needed to generate D-Bus interface specifications" ) ########### Targets ########### if (EXISTS "${CMAKE_SOURCE_DIR}/.git") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x060000) endif() add_definitions(-DQT_NO_FOREACH) if(BUILD_TESTING) set(AKONADI_MIME_TEST_EXPORT AKONADI_MIME_EXPORT) endif() configure_file(akonadi-mimeprivate_export.h.in "${CMAKE_CURRENT_BINARY_DIR}/akonadi-mimeprivate_export.h") include_directories(${CMAKE_CURRENT_BINARY_DIR}) option(NO_REGENERATE_MIME "Don't regenerate mime file (only for developper)" FALSE ) add_subdirectory(src) add_subdirectory(serializers) if(BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5AkonadiMime") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5AkonadiMimeConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiMimeConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiMimeConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiMimeConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5AkonadiMimeTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5AkonadiMimeTargets.cmake NAMESPACE KF5::) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/akonadi-mime_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) install(FILES akonadi-mime.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/autotests/benchmarker/CMakeLists.txt b/autotests/benchmarker/CMakeLists.txt index d983fd7..9ee02b5 100644 --- a/autotests/benchmarker/CMakeLists.txt +++ b/autotests/benchmarker/CMakeLists.txt @@ -1,32 +1,32 @@ kde_enable_exceptions() set(benchmarker_SRCS maildir/maildir.cpp maildir/maildirimport.cpp main.cpp maketest.cpp test.cpp testmaildir.cpp maildir/maildirfetchallheaders.cpp maildir/maildir20percentread.cpp maildir/maildirfetchunreadheaders.cpp maildir/maildirremovereadmessages.cpp testvcard.cpp vcard/vcard.cpp vcard/vcardimport.cpp ) add_executable(akonadi_benchmarker ${benchmarker_SRCS}) target_link_libraries(akonadi_benchmarker KF5::AkonadiMime KF5::Mime Qt5::Test KF5::AkonadiCore - KF5::DBusAddons KF5::I18n Qt5::Widgets + Qt5::DBus ) install(TARGETS akonadi_benchmarker ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/autotests/benchmarker/maketest.cpp b/autotests/benchmarker/maketest.cpp index 912d043..a2869b5 100644 --- a/autotests/benchmarker/maketest.cpp +++ b/autotests/benchmarker/maketest.cpp @@ -1,130 +1,129 @@ /* Copyright (c) 2009 Igor Trindade Oliveira based on kdepimlibs/akonadi/tests/benchmarker.cpp wrote by Robert Zwerus 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 "test.h" -#include "KDBusConnectionPool" - #include #include #include #include #include #include +#include #include using namespace Akonadi; MakeTest::MakeTest() { connect(AgentManager::self(), &AgentManager::instanceRemoved, this, &MakeTest::instanceRemoved); connect(AgentManager::self(), &AgentManager::instanceStatusChanged, this, &MakeTest::instanceStatusChanged); } void MakeTest::createAgent(const QString &name) { const AgentType type = AgentManager::self()->type(name); AgentInstanceCreateJob *job = new AgentInstanceCreateJob(type); job->exec(); currentInstance = job->instance(); if (job->error() || !currentInstance.isValid()) { qDebug() << " Unable to create resource" << name; exit(-1); } else { qDebug() << " Created resource instance" << currentInstance.identifier(); } QTest::qWait(100); //fix this hack } void MakeTest::configureDBusIface(const QString &name, const QString &dir) { QDBusInterface *configIface = new QDBusInterface(QLatin1String("org.freedesktop.Akonadi.Resource.") + currentInstance.identifier(), - QStringLiteral("/Settings"), QLatin1String("org.kde.Akonadi.") + name + QLatin1String(".Settings"), KDBusConnectionPool::threadConnection(), this); + QStringLiteral("/Settings"), QLatin1String("org.kde.Akonadi.") + name + QLatin1String(".Settings"), QDBusConnection::sessionBus(), this); configIface->call(QStringLiteral("setPath"), dir); configIface->call(QStringLiteral("setReadOnly"), true); if (!configIface->isValid()) { qFatal("Could not configure instance %s.", qPrintable(currentInstance.identifier())); } } void MakeTest::instanceRemoved(const AgentInstance &instance) { Q_UNUSED(instance); done = true; // qDebug() << "agent removed:" << instance; } void MakeTest::instanceStatusChanged(const AgentInstance &instance) { //qDebug() << "agent status changed:" << agentIdentifier << status << message ; if (instance == currentInstance) { if (instance.status() == AgentInstance::Running) { //qDebug() << " " << message; } if (instance.status() == AgentInstance::Idle) { done = true; } } } void MakeTest::outputStats(const QString &description) { output(description + QLatin1String("\t\t") + currentAccount + QLatin1String("\t\t") + QString::number(timer.elapsed()) + QLatin1Char('\n')); } void MakeTest::output(const QString &message) { QTextStream out(stdout); out << message; } void MakeTest::removeCollections() { timer.restart(); qDebug() << " Removing every folder sequentially."; CollectionFetchJob *clj5 = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive); clj5->fetchScope().setResource(currentInstance.identifier()); clj5->exec(); const Collection::List list5 = clj5->collections(); for (const Collection &collection : list5) { CollectionDeleteJob *cdj = new CollectionDeleteJob(collection, this); cdj->exec(); } outputStats(QStringLiteral("removeallcollections")); } void MakeTest::removeResource() { qDebug() << " Removing resource."; AgentManager::self()->removeInstance(currentInstance); } void MakeTest::start() { runTest(); } diff --git a/autotests/localfolderstest.cpp b/autotests/localfolderstest.cpp index 2abbe87..427ff62 100644 --- a/autotests/localfolderstest.cpp +++ b/autotests/localfolderstest.cpp @@ -1,629 +1,629 @@ /* Copyright 2009 Constantin Berzan 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 "localfolderstest.h" #include "collectionpathresolver.h" -#include "kdbusconnectionpool.h" #include "specialmailcollectionssettings.h" +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "specialcollectionattribute.h" #include "specialcollections.h" #include #include #include "../src/specialmailcollectionstesting_p.h" using namespace Akonadi; typedef SpecialMailCollectionsSettings Settings; static Collection res1; void LocalFoldersTest::initTestCase() { qRegisterMetaType("Akonadi::AgentInstance"); mDisplayNameMap.insert("local-mail", i18nc("local mail folder", "Local Folders")); mDisplayNameMap.insert("inbox", i18nc("local mail folder", "inbox")); mDisplayNameMap.insert("outbox", i18nc("local mail folder", "outbox")); mDisplayNameMap.insert("sent-mail", i18nc("local mail folder", "sent-mail")); mDisplayNameMap.insert("trash", i18nc("local mail folder", "trash")); mDisplayNameMap.insert("drafts", i18nc("local mail folder", "drafts")); mDisplayNameMap.insert("templates", i18nc("local mail folder", "templates")); mIconNameMap.insert("local-mail", QLatin1String("folder")); mIconNameMap.insert("inbox", QLatin1String("mail-folder-inbox")); mIconNameMap.insert("outbox", QLatin1String("mail-folder-outbox")); mIconNameMap.insert("sent-mail", QLatin1String("mail-folder-sent")); mIconNameMap.insert("trash", QLatin1String("user-trash")); mIconNameMap.insert("drafts", QLatin1String("document-properties")); mIconNameMap.insert("templates", QLatin1String("document-new")); QVERIFY(Control::start()); QTest::qWait(1000); CollectionPathResolver *resolver = new CollectionPathResolver(QStringLiteral("res1"), this); QVERIFY(resolver->exec()); res1 = Collection(resolver->collection()); CollectionFetchJob *fjob = new CollectionFetchJob(res1, CollectionFetchJob::Base, this); AKVERIFYEXEC(fjob); Q_ASSERT(fjob->collections().count() == 1); res1 = fjob->collections().first(); QVERIFY(!res1.resource().isEmpty()); } void LocalFoldersTest::testLock() { QString dbusName = QString::fromLatin1("org.kde.pim.SpecialCollections"); if (ServerManager::hasInstanceIdentifier()) { dbusName += Akonadi::ServerManager::instanceIdentifier(); } // Initially not locked. - QVERIFY(!KDBusConnectionPool::threadConnection().interface()->isServiceRegistered(dbusName)); + QVERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(dbusName)); // Get the lock. { GetLockJob *ljob = new GetLockJob(this); AKVERIFYEXEC(ljob); - QVERIFY(KDBusConnectionPool::threadConnection().interface()->isServiceRegistered(dbusName)); + QVERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(dbusName)); } // Getting the lock again should fail. { GetLockJob *ljob = new GetLockJob(this); QVERIFY(!ljob->exec()); } // Release the lock. - QVERIFY(KDBusConnectionPool::threadConnection().interface()->isServiceRegistered(dbusName)); + QVERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(dbusName)); releaseLock(); - QVERIFY(!KDBusConnectionPool::threadConnection().interface()->isServiceRegistered(dbusName)); + QVERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(dbusName)); } void LocalFoldersTest::testInitialState() { SpecialMailCollections *smc = SpecialMailCollections::self(); SpecialCollections *sc = smc; SpecialMailCollectionsTesting *smct = SpecialMailCollectionsTesting::_t_self(); Q_ASSERT(smc); Q_ASSERT(smct); Q_UNUSED(smct); // No one has created the default resource. QVERIFY(sc->d->defaultResource().identifier().isEmpty()); // LF does not have a default Outbox folder (or any other). QCOMPARE(smc->hasDefaultCollection(SpecialMailCollections::Outbox), false); QVERIFY(!smc->defaultCollection(SpecialMailCollections::Outbox).isValid()); // LF treats unknown resources correctly. const QString resourceId = QString::fromLatin1("this_resource_does_not_exist"); QCOMPARE(smc->hasCollection(SpecialMailCollections::Outbox, AgentManager::self()->instance(resourceId)), false); QVERIFY(!smc->collection(SpecialMailCollections::Outbox, AgentManager::self()->instance(resourceId)).isValid()); } void LocalFoldersTest::testRegistrationErrors() { SpecialMailCollections *smc = SpecialMailCollections::self(); // A valid collection that can be registered. Collection outbox; outbox.setName(QLatin1String("my_outbox")); outbox.setParentCollection(res1); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); outbox.setResource(res1.resource()); // Needs to be valid. { Collection col(outbox); col.setId(-1); QVERIFY(!smc->registerCollection(SpecialMailCollections::Outbox, col)); } // Needs to have a resourceId. { Collection col(outbox); col.setResource(QString()); QVERIFY(!smc->registerCollection(SpecialMailCollections::Outbox, col)); } // Needs to have a LocalFolderAttribute. { Collection col(outbox); col.removeAttribute(); QVERIFY(!smc->registerCollection(SpecialMailCollections::Outbox, col)); } } void LocalFoldersTest::testDefaultFolderRegistration() { SpecialMailCollections *smc = SpecialMailCollections::self(); SpecialCollections *sc = smc; SpecialMailCollectionsTesting *smct = SpecialMailCollectionsTesting::_t_self(); Q_ASSERT(smc); Q_ASSERT(smct); QSignalSpy spy(smc, &SpecialMailCollections::collectionsChanged); QSignalSpy defSpy(smc, &SpecialMailCollections::defaultCollectionsChanged); QVERIFY(spy.isValid()); QVERIFY(defSpy.isValid()); // No one has created the default resource. QVERIFY(sc->d->defaultResource().identifier().isEmpty()); // Set the default resource. LF should still have no folders. smct->_t_setDefaultResourceId(res1.resource()); QCOMPARE(sc->d->defaultResource().identifier(), res1.resource()); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); // Manually create an Outbox collection. Collection outbox; outbox.setName(QLatin1String("my_outbox")); outbox.setParentCollection(res1); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); CollectionCreateJob *cjob = new CollectionCreateJob(outbox, this); AKVERIFYEXEC(cjob); outbox = cjob->collection(); // LF should still have no folders, since the Outbox wasn't registered. QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 0); QCOMPARE(defSpy.count(), 0); // Register the collection. LF should now know it. bool ok = smc->registerCollection(SpecialMailCollections::Outbox, outbox); QVERIFY(ok); QVERIFY(smc->hasDefaultCollection(SpecialMailCollections::Outbox)); QCOMPARE(smc->defaultCollection(SpecialMailCollections::Outbox), outbox); QCOMPARE(smct->_t_knownResourceCount(), 1); QCOMPARE(smct->_t_knownFolderCount(), 1); QCOMPARE(spy.count(), 1); QCOMPARE(defSpy.count(), 1); // Forget all folders in the default resource. smct->_t_forgetFoldersForResource(sc->d->defaultResource().identifier()); QCOMPARE(smc->hasDefaultCollection(SpecialMailCollections::Outbox), false); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 2); QCOMPARE(defSpy.count(), 2); // Delete the collection. CollectionDeleteJob *djob = new CollectionDeleteJob(outbox, this); AKVERIFYEXEC(djob); } void LocalFoldersTest::testCustomFolderRegistration() { SpecialMailCollections *smc = SpecialMailCollections::self(); SpecialMailCollectionsTesting *smct = SpecialMailCollectionsTesting::_t_self(); Q_ASSERT(smc); Q_ASSERT(smct); QSignalSpy spy(smc, &SpecialMailCollections::collectionsChanged); QSignalSpy defSpy(smc, &SpecialMailCollections::defaultCollectionsChanged); QVERIFY(spy.isValid()); QVERIFY(defSpy.isValid()); // Set a fake default resource, so that res1.resource() isn't seen as the default one. // LF should have no folders. smct->_t_setDefaultResourceId("dummy"); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); // Manually create an Outbox collection. Collection outbox; outbox.setName(QLatin1String("my_outbox")); outbox.setParentCollection(res1); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); CollectionCreateJob *cjob = new CollectionCreateJob(outbox, this); AKVERIFYEXEC(cjob); outbox = cjob->collection(); // LF should still have no folders, since the Outbox wasn't registered. QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 0); QCOMPARE(defSpy.count(), 0); // Register the collection. LF should now know it. bool ok = smc->registerCollection(SpecialMailCollections::Outbox, outbox); QVERIFY(ok); QVERIFY(!smc->hasDefaultCollection(SpecialMailCollections::Outbox)); QVERIFY(smc->hasCollection(SpecialMailCollections::Outbox, AgentManager::self()->instance(outbox.resource()))); QCOMPARE(smc->collection(SpecialMailCollections::Outbox, AgentManager::self()->instance(outbox.resource())), outbox); QCOMPARE(smct->_t_knownResourceCount(), 1); QCOMPARE(smct->_t_knownFolderCount(), 1); QCOMPARE(spy.count(), 1); QCOMPARE(defSpy.count(), 0); // Forget all folders in this resource. smct->_t_forgetFoldersForResource(outbox.resource()); QCOMPARE(smc->hasDefaultCollection(SpecialMailCollections::Outbox), false); QCOMPARE(smc->hasCollection(SpecialMailCollections::Outbox, AgentManager::self()->instance(outbox.resource())), false); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 2); QCOMPARE(defSpy.count(), 0); // Delete the collection. CollectionDeleteJob *djob = new CollectionDeleteJob(outbox, this); AKVERIFYEXEC(djob); } void LocalFoldersTest::testCollectionDelete() { SpecialMailCollections *smc = SpecialMailCollections::self(); SpecialCollections *sc = smc; SpecialMailCollectionsTesting *smct = SpecialMailCollectionsTesting::_t_self(); Q_ASSERT(smc); Q_ASSERT(smct); QSignalSpy spy(smc, &SpecialMailCollections::collectionsChanged); QSignalSpy defSpy(smc, &SpecialMailCollections::defaultCollectionsChanged); QVERIFY(spy.isValid()); QVERIFY(defSpy.isValid()); // Set the default resource. LF should have no folders. smct->_t_setDefaultResourceId(res1.resource()); QCOMPARE(sc->d->defaultResource().identifier(), res1.resource()); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); // Manually create an Outbox collection. Collection outbox; outbox.setName(QLatin1String("my_outbox")); outbox.setParentCollection(res1); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); CollectionCreateJob *cjob = new CollectionCreateJob(outbox, this); AKVERIFYEXEC(cjob); outbox = cjob->collection(); // LF should still have no folders, since the Outbox wasn't registered. QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 0); QCOMPARE(defSpy.count(), 0); // Register the collection. LF should now know it. bool ok = smc->registerCollection(SpecialMailCollections::Outbox, outbox); QVERIFY(ok); QVERIFY(smc->hasDefaultCollection(SpecialMailCollections::Outbox)); QCOMPARE(smc->defaultCollection(SpecialMailCollections::Outbox), outbox); QCOMPARE(smct->_t_knownResourceCount(), 1); QCOMPARE(smct->_t_knownFolderCount(), 1); QCOMPARE(spy.count(), 1); QCOMPARE(defSpy.count(), 1); // Delete the collection. LF should watch for that. CollectionDeleteJob *djob = new CollectionDeleteJob(outbox, this); AKVERIFYEXEC(djob); QTest::qWait(100); QVERIFY(!smc->hasDefaultCollection(SpecialMailCollections::Outbox)); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 2); QCOMPARE(defSpy.count(), 2); } void LocalFoldersTest::testBatchRegister() { SpecialMailCollections *smc = SpecialMailCollections::self(); SpecialCollections *sc = smc; SpecialMailCollectionsTesting *smct = SpecialMailCollectionsTesting::_t_self(); Q_ASSERT(smc); Q_ASSERT(smct); QSignalSpy spy(smc, &SpecialMailCollections::collectionsChanged); QSignalSpy defSpy(smc, &SpecialMailCollections::defaultCollectionsChanged); QVERIFY(spy.isValid()); QVERIFY(defSpy.isValid()); // Set the default resource. LF should have no folders. smct->_t_setDefaultResourceId(res1.resource()); QCOMPARE(sc->d->defaultResource().identifier(), res1.resource()); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); // Manually create an Outbox collection. Collection outbox; outbox.setName(QLatin1String("my_outbox")); outbox.setParentCollection(res1); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); CollectionCreateJob *cjob = new CollectionCreateJob(outbox, this); AKVERIFYEXEC(cjob); outbox = cjob->collection(); // Manually create a Drafts collection. Collection drafts; drafts.setName(QLatin1String("my_drafts")); drafts.setParentCollection(res1); drafts.addAttribute(new SpecialCollectionAttribute("drafts")); cjob = new CollectionCreateJob(drafts, this); AKVERIFYEXEC(cjob); drafts = cjob->collection(); // LF should still have no folders, since the folders were not registered. QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 0); QCOMPARE(defSpy.count(), 0); // Register the folders in batch mode. smct->_t_beginBatchRegister(); bool ok = smc->registerCollection(SpecialMailCollections::Outbox, outbox); QVERIFY(ok); QVERIFY(smc->hasDefaultCollection(SpecialMailCollections::Outbox)); QCOMPARE(smc->defaultCollection(SpecialMailCollections::Outbox), outbox); QCOMPARE(smct->_t_knownResourceCount(), 1); QCOMPARE(smct->_t_knownFolderCount(), 1); QCOMPARE(spy.count(), 0); QCOMPARE(defSpy.count(), 0); ok = smc->registerCollection(SpecialMailCollections::Drafts, drafts); QVERIFY(ok); QVERIFY(smc->hasDefaultCollection(SpecialMailCollections::Drafts)); QCOMPARE(smc->defaultCollection(SpecialMailCollections::Drafts), drafts); QCOMPARE(smct->_t_knownResourceCount(), 1); QCOMPARE(smct->_t_knownFolderCount(), 2); QCOMPARE(spy.count(), 0); QCOMPARE(defSpy.count(), 0); smct->_t_endBatchRegister(); QCOMPARE(smct->_t_knownResourceCount(), 1); QCOMPARE(smct->_t_knownFolderCount(), 2); QCOMPARE(spy.count(), 1); QCOMPARE(defSpy.count(), 1); // Forget all folders in the default resource. smct->_t_forgetFoldersForResource(sc->d->defaultResource().identifier()); QCOMPARE(smc->hasDefaultCollection(SpecialMailCollections::Outbox), false); QCOMPARE(smc->hasDefaultCollection(SpecialMailCollections::Drafts), false); QCOMPARE(smct->_t_knownResourceCount(), 0); QCOMPARE(smct->_t_knownFolderCount(), 0); QCOMPARE(spy.count(), 2); QCOMPARE(defSpy.count(), 2); // Delete the collections. CollectionDeleteJob *djob = new CollectionDeleteJob(outbox, this); AKVERIFYEXEC(djob); djob = new CollectionDeleteJob(drafts, this); AKVERIFYEXEC(djob); } void LocalFoldersTest::testResourceScanErrors() { // Job fails if no resourceId is given. ResourceScanJob *resjob = new ResourceScanJob(QString(), Settings::self(), this); QVERIFY(!resjob->exec()); } void LocalFoldersTest::testResourceScan() { // Verify that res1 has no collections. { CollectionFetchJob *fjob = new CollectionFetchJob(res1, CollectionFetchJob::Recursive, this); AKVERIFYEXEC(fjob); QCOMPARE(fjob->collections().count(), 0); } // Manually create an Outbox collection. Collection outbox; { outbox.setName(QLatin1String("my_outbox")); outbox.setParentCollection(res1); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); CollectionCreateJob *cjob = new CollectionCreateJob(outbox, this); AKVERIFYEXEC(cjob); outbox = cjob->collection(); } // Manually create a Drafts collection. Collection drafts; { drafts.setName(QLatin1String("my_drafts")); drafts.setParentCollection(res1); drafts.addAttribute(new SpecialCollectionAttribute("drafts")); CollectionCreateJob *cjob = new CollectionCreateJob(drafts, this); AKVERIFYEXEC(cjob); drafts = cjob->collection(); } // Manually create a non-LocalFolder collection. Collection intruder; { intruder.setName(QLatin1String("intruder")); intruder.setParentCollection(res1); CollectionCreateJob *cjob = new CollectionCreateJob(intruder, this); AKVERIFYEXEC(cjob); intruder = cjob->collection(); } // Verify that the collections have been created properly. { CollectionFetchJob *fjob = new CollectionFetchJob(res1, CollectionFetchJob::Recursive, this); AKVERIFYEXEC(fjob); QCOMPARE(fjob->collections().count(), 3); } // Test that ResourceScanJob finds everything correctly. ResourceScanJob *resjob = new ResourceScanJob(res1.resource(), Settings::self(), this); AKVERIFYEXEC(resjob); QCOMPARE(resjob->rootResourceCollection(), res1); const Collection::List folders = resjob->specialCollections(); QCOMPARE(folders.count(), 2); QVERIFY(folders.contains(outbox)); QVERIFY(folders.contains(drafts)); // Clean up after ourselves. CollectionDeleteJob *djob = new CollectionDeleteJob(outbox, this); AKVERIFYEXEC(djob); djob = new CollectionDeleteJob(drafts, this); AKVERIFYEXEC(djob); djob = new CollectionDeleteJob(intruder, this); AKVERIFYEXEC(djob); SpecialMailCollections::self()->destroy(); } void LocalFoldersTest::testDefaultResourceJob() { SpecialMailCollectionsTesting *scmt = SpecialMailCollectionsTesting::_t_self(); scmt->_t_setDefaultResourceId(QLatin1String("akonadi_maildir_resource")); // Initially the defaut maildir does not exist. QVERIFY(!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/local-mail"))); // Run the job. Collection maildirRoot; QString resourceId; { DefaultResourceJob *resjob = new DefaultResourceJob(Settings::self(), this); resjob->setDefaultResourceType(QLatin1String("akonadi_maildir_resource")); QVariantMap options; options.insert(QLatin1String("Name"), i18nc("local mail folder", "Local Folders")); options.insert(QLatin1String("Path"), QString(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/local-mail"))); resjob->setDefaultResourceOptions(options); resjob->setTypes(mDisplayNameMap.keys()); resjob->setNameForTypeMap(mDisplayNameMap); resjob->setIconForTypeMap(mIconNameMap); AKVERIFYEXEC(resjob); resourceId = resjob->resourceId(); const Collection::List folders = resjob->specialCollections(); QCOMPARE(folders.count(), 1); maildirRoot = folders.first(); QVERIFY(maildirRoot.hasAttribute()); QCOMPARE(maildirRoot.attribute()->collectionType(), QByteArray("local-mail")); } // The maildir should exist now. QVERIFY(QFile::exists(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/local-mail"))); // Create a LocalFolder in the default resource. Collection outbox; { outbox.setName(QLatin1String("outbox")); outbox.setParentCollection(maildirRoot); outbox.addAttribute(new SpecialCollectionAttribute("outbox")); CollectionCreateJob *cjob = new CollectionCreateJob(outbox, this); AKVERIFYEXEC(cjob); outbox = cjob->collection(); // Wait for the maildir resource to actually create the folder on disk... // (needed in testRecoverDefaultResource()) QTest::qWait(500); } // Run the job again. { DefaultResourceJob *resjob = new DefaultResourceJob(Settings::self(), this); resjob->setDefaultResourceType(QLatin1String("akonadi_maildir_resource")); QVariantMap options; options.insert(QLatin1String("Name"), i18nc("local mail folder", "Local Folders")); options.insert(QLatin1String("Path"), QString(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/local-mail"))); resjob->setDefaultResourceOptions(options); resjob->setTypes(mDisplayNameMap.keys()); resjob->setNameForTypeMap(mDisplayNameMap); resjob->setIconForTypeMap(mIconNameMap); AKVERIFYEXEC(resjob); QCOMPARE(resourceId, resjob->resourceId()); // Did not mistakenly create another resource. const Collection::List folders = resjob->specialCollections(); QCOMPARE(folders.count(), 2); QVERIFY(folders.contains(maildirRoot)); QVERIFY(folders.contains(outbox)); } } void LocalFoldersTest::testRecoverDefaultResource() { // The maildirs should exist (created in testDefaultResourceJob). const QString xdgPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/'); const QString rootPath = xdgPath + QLatin1String("local-mail"); const QString outboxPath = xdgPath + QString::fromLatin1(".%1.directory/%2") \ .arg(QLatin1String("local-mail")) .arg(QLatin1String("outbox")); QVERIFY(QFile::exists(rootPath)); QVERIFY(QFile::exists(outboxPath)); // Kill the default resource. const QString oldResourceId = static_cast(SpecialMailCollections::self())->d->defaultResource().identifier(); const AgentInstance resource = AgentManager::self()->instance(oldResourceId); QVERIFY(resource.isValid()); AgentManager::self()->removeInstance(resource); QTest::qWait(100); // Run the DefaultResourceJob now. It should recover the Root and Outbox folders // created in testDefaultResourceJob. { DefaultResourceJob *resjob = new DefaultResourceJob(Settings::self(), this); resjob->setDefaultResourceType(QLatin1String("akonadi_maildir_resource")); QVariantMap options; options.insert(QLatin1String("Name"), i18nc("local mail folder", "Local Folders")); options.insert(QLatin1String("Path"), QString(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/local-mail"))); resjob->setDefaultResourceOptions(options); resjob->setTypes(mDisplayNameMap.keys()); resjob->setNameForTypeMap(mDisplayNameMap); resjob->setIconForTypeMap(mIconNameMap); AKVERIFYEXEC(resjob); QVERIFY(resjob->resourceId() != oldResourceId); // Created another resource. Collection::List folders = resjob->specialCollections(); QCOMPARE(folders.count(), 2); // Reorder the folders. if (folders.first().parentCollection() != Collection::root()) { folders.move(1, 0); } // The first folder should be the Root. { Collection col = folders[0]; QCOMPARE(col.name(), QLatin1String("Local Folders")); QVERIFY(col.hasAttribute()); QCOMPARE(col.attribute()->collectionType(), QByteArray("local-mail")); } // The second folder should be the Outbox. { Collection col = folders[1]; QCOMPARE(col.name(), QLatin1String("outbox")); QVERIFY(col.hasAttribute()); QCOMPARE(col.attribute()->collectionType(), QByteArray("outbox")); } } } QTEST_AKONADIMAIN(LocalFoldersTest) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b27c63..2931240 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,150 +1,149 @@ add_definitions(-DTRANSLATION_DOMAIN=\"libakonadi-kmime5\") # generates 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 ${LIBXSLT_XSLTPROC_EXECUTABLE} --stringparam interfaceName ${_name} ${KF5Akonadi_DATA_DIR}/kcfg2dbus.xsl ${_kcfg} > ${CMAKE_CURRENT_BINARY_DIR}/${_name}.xml ${_kcfg} ) endmacro() macro(add_resource_iface _kcfgFile _ifaceName _className) kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/${_kcfgFile} ${_ifaceName}) string(TOLOWER ${_className} _codeFile) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${_ifaceName}.xml PROPERTIES INCLUDE "metatype.h") qt5_add_dbus_interface(akonadimime_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${_ifaceName}.xml ${_codeFile} ${_className} ) endmacro() ########### next target ############### set(akonadimime_SRCS addressattribute.cpp attributeregistrar.cpp removeduplicatesjob.cpp specialmailcollections.cpp specialmailcollectionsrequestjob.cpp specialmailcollectionsdiscoveryjob.cpp messagefolderattribute.cpp messagemodel.cpp messageparts.cpp messageflags.cpp messagestatus.cpp commandbase.cpp util.cpp emptytrashcommand.cpp markascommand.cpp movecommand.cpp movetotrashcommand.cpp standardmailactionmanager.cpp ) ecm_qt_declare_logging_category(akonadimime_SRCS HEADER akonadi_mime_debug.h IDENTIFIER AKONADIMIME_LOG CATEGORY_NAME log_akonadi_mime) add_resource_iface(imapresource.kcfg org.kde.Akonadi.Imap.Settings ImapSettings) # TODO: add the necessary API in SpecialCollections #if (BUILD_TESTING) # list(APPEND akonadimime_SRCS specialmailcollectionstesting.cpp) #endif() kconfig_add_kcfg_files(akonadimime_SRCS specialmailcollectionssettings.kcfgc ) install(FILES specialmailcollections.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} ) add_library(KF5AkonadiMime ${akonadimime_SRCS}) generate_export_header(KF5AkonadiMime BASE_NAME akonadi-mime) add_library(KF5::AkonadiMime ALIAS KF5AkonadiMime) # NOTE: The include directories remain 'akonadi/kmime' to be as SC as possible. target_include_directories(KF5AkonadiMime INTERFACE "$") target_include_directories(KF5AkonadiMime PUBLIC "$") target_include_directories(KF5AkonadiMime INTERFACE "$") target_link_libraries(KF5AkonadiMime PUBLIC KF5::AkonadiCore PRIVATE KF5::Mime KF5::AkonadiWidgets KF5::KIOCore - KF5::DBusAddons KF5::I18n KF5::ConfigWidgets KF5::XmlGui ) set_target_properties(KF5AkonadiMime PROPERTIES VERSION ${AKONADIMIME_VERSION_STRING} SOVERSION ${AKONADIMIME_SOVERSION} EXPORT_NAME AkonadiMime ) install(TARGETS KF5AkonadiMime EXPORT KF5AkonadiMimeTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ) ecm_generate_headers(AkonadiMime_CamelCase_HEADERS HEADER_NAMES AddressAttribute CommandBase MessageFlags MessageFolderAttribute MessageModel MessageParts MessageStatus MarkAsCommand MoveCommand RemoveDuplicatesJob SpecialMailCollections SpecialMailCollectionsDiscoveryJob SpecialMailCollectionsRequestJob StandardMailActionManager REQUIRED_HEADERS AkonadiMime_HEADERS PREFIX Akonadi/KMime ) install(FILES ${AkonadiMime_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/Akonadi/KMime COMPONENT Devel ) install(FILES ${AkonadiMime_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/akonadi-mime_export.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/akonadi/kmime COMPONENT Devel ) ecm_generate_pri_file(BASE_NAME AkonadiMime LIB_NAME KF5AkonadiMime DEPS "AkonadiCore" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/Akonadi/KMime ) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) ## install the MIME type spec file for KDEPIM specific MIME types install(FILES x-vnd.kde.contactgroup.xml DESTINATION ${KDE_INSTALL_MIMEDIR}) if (NOT NO_REGENERATE_MIME) update_xdg_mimetypes(${KDE_INSTALL_MIMEDIR}) endif() diff --git a/src/util.cpp b/src/util.cpp index 447cc3a..ca14dd4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,53 +1,53 @@ /* Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Copyright (c) 2010 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "util_p.h" #include "imapsettings.h" #include -#include +#include #include #include "akonadi_mime_debug.h" #include #include namespace Util { /// Helper to sanely show an error message for a job void showJobError(KJob *job) { assert(job); // we can be called from the KJob::kill, where we are no longer a KIO::Job // so better safe than sorry KIO::Job *kiojob = qobject_cast(job); if (kiojob && kiojob->uiDelegate()) { kiojob->uiDelegate()->showErrorMessage(); } else { qCWarning(AKONADIMIME_LOG) << "There is no GUI delegate set for a kjob, and it failed with error:" << job->errorString(); } } OrgKdeAkonadiImapSettingsInterface *createImapSettingsInterface(const QString &ident) { //NOTE(Andras): from kmail/util.cpp return new OrgKdeAkonadiImapSettingsInterface(Akonadi::ServerManager::agentServiceName(Akonadi::ServerManager::Resource, ident), QStringLiteral("/Settings"), - KDBusConnectionPool::threadConnection()); + QDBusConnection::sessionBus()); } }