diff --git a/src/akonadi/akonadistoragesettings.cpp b/src/akonadi/akonadistoragesettings.cpp index 4c3f8436..a866539d 100644 --- a/src/akonadi/akonadistoragesettings.cpp +++ b/src/akonadi/akonadistoragesettings.cpp @@ -1,104 +1,76 @@ /* This file is part of Zanshin Todo. Copyright 2012 Christian Mollekopf This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 "akonadistoragesettings.h" #include #include using namespace Akonadi; StorageSettings::StorageSettings() : QObject() { } StorageSettings &StorageSettings::instance() { static StorageSettings i; return i; } -Collection::List StorageSettings::activeCollections() -{ - KConfigGroup config(KSharedConfig::openConfig(), "General"); - QList ids = config.readEntry("activeCollections", QList()); - Collection::List list; - list.reserve(ids.size()); - foreach (const auto &id, ids) { - list << Collection(id); - } - return list; -} - Collection StorageSettings::defaultNoteCollection() { KConfigGroup config(KSharedConfig::openConfig(), "General"); Collection::Id id = config.readEntry("defaultNoteCollection", -1); return Collection(id); } Collection StorageSettings::defaultTaskCollection() { KConfigGroup config(KSharedConfig::openConfig(), "General"); Collection::Id id = config.readEntry("defaultCollection", -1); return Collection(id); } void StorageSettings::setDefaultNoteCollection(const Collection &collection) { if (defaultNoteCollection() == collection) return; KConfigGroup config(KSharedConfig::openConfig(), "General"); config.writeEntry("defaultNoteCollection", QString::number(collection.id())); config.sync(); emit defaultNoteCollectionChanged(collection); } void StorageSettings::setDefaultTaskCollection(const Collection &collection) { if (defaultTaskCollection() == collection) return; KConfigGroup config(KSharedConfig::openConfig(), "General"); config.writeEntry("defaultCollection", QString::number(collection.id())); config.sync(); emit defaultTaskCollectionChanged(collection); } - -void StorageSettings::setActiveCollections(const Collection::List &collections) -{ - if (activeCollections() == collections) - return; - - QList ids; - for (const auto &col : collections) { - ids << col.id(); - } - - KConfigGroup config(KSharedConfig::openConfig(), "General"); - config.writeEntry("activeCollections", ids); - config.sync(); - emit activeCollectionsChanged(collections); -} diff --git a/src/akonadi/akonadistoragesettings.h b/src/akonadi/akonadistoragesettings.h index 71a1f4bf..93d70ea9 100644 --- a/src/akonadi/akonadistoragesettings.h +++ b/src/akonadi/akonadistoragesettings.h @@ -1,59 +1,56 @@ /* This file is part of Zanshin Todo. Copyright 2012 Christian Mollekopf Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 AKONADI_STORAGESETTINGS_H #define AKONADI_STORAGESETTINGS_H #include namespace Akonadi { class StorageSettings : public QObject { Q_OBJECT private: StorageSettings(); public: static StorageSettings &instance(); - Akonadi::Collection::List activeCollections(); Akonadi::Collection defaultNoteCollection(); Akonadi::Collection defaultTaskCollection(); public slots: - void setActiveCollections(const Akonadi::Collection::List &collections); void setDefaultNoteCollection(const Akonadi::Collection &collection); void setDefaultTaskCollection(const Akonadi::Collection &collection); signals: - void activeCollectionsChanged(const Akonadi::Collection::List &collections); void defaultNoteCollectionChanged(const Akonadi::Collection &collection); void defaultTaskCollectionChanged(const Akonadi::Collection &collection); }; } #endif // AKONADI_STORAGESETTINGS_H diff --git a/tests/units/akonadi/akonadistoragesettingstest.cpp b/tests/units/akonadi/akonadistoragesettingstest.cpp index 707f7049..519a8841 100644 --- a/tests/units/akonadi/akonadistoragesettingstest.cpp +++ b/tests/units/akonadi/akonadistoragesettingstest.cpp @@ -1,169 +1,147 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 #include #include #include "akonadi/akonadistoragesettings.h" using namespace Akonadi; Q_DECLARE_METATYPE(QSet) class AkonadiStorageSettingsTest : public QObject { Q_OBJECT public: explicit AkonadiStorageSettingsTest(QObject *parent = Q_NULLPTR) : QObject(parent) { qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType>(); } private: KConfigGroup configGroup() { return KConfigGroup(KSharedConfig::openConfig(), "General"); } QList idList(int max) { QList list; list.reserve(max); for (int i = 1; i < max; i++) { list << i; } return list; } Akonadi::Collection::List colList(int max) { Akonadi::Collection::List list; list.reserve(max); foreach (auto id, idList(max)) { list << Collection(id); } return list; } private slots: void shouldReadFromConfigurationFile() { // GIVEN KConfigGroup g = configGroup(); for (int i = 1; i <= 18; i += 3) { // WHEN g.writeEntry("defaultCollection", i); g.writeEntry("defaultNoteCollection", i + 1); - g.writeEntry("activeCollections", idList(i + 2)); // THEN QCOMPARE(StorageSettings::instance().defaultTaskCollection(), Collection(i)); QCOMPARE(StorageSettings::instance().defaultNoteCollection(), Collection(i + 1)); - QCOMPARE(StorageSettings::instance().activeCollections(), colList(i + 2)); } } void shouldWriteToConfigurationFile() { // GIVEN KConfigGroup g = configGroup(); for (int i = 1; i <= 18; i += 3) { // WHEN StorageSettings::instance().setDefaultTaskCollection(Collection(i)); StorageSettings::instance().setDefaultNoteCollection(Collection(i + 1)); - StorageSettings::instance().setActiveCollections(colList(i + 2)); // THEN QCOMPARE(g.readEntry("defaultCollection", -1), i); QCOMPARE(g.readEntry("defaultNoteCollection", -1), i + 1); - QCOMPARE(g.readEntry("activeCollections", QList()), idList(i + 2)); } } void shouldNotifyTaskCollectionChanges() { StorageSettings &settings = StorageSettings::instance(); QSignalSpy spy(&settings, &Akonadi::StorageSettings::defaultTaskCollectionChanged); settings.setDefaultTaskCollection(Collection(2)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().value(), Collection(2)); } void shouldNotNotifyIdenticalTaskCollectionChanges() { StorageSettings &settings = StorageSettings::instance(); settings.setDefaultTaskCollection(Collection(4)); QSignalSpy spy(&settings, &Akonadi::StorageSettings::defaultTaskCollectionChanged); settings.setDefaultTaskCollection(Collection(4)); QCOMPARE(spy.count(), 0); } void shouldNotifyNoteCollectionChanges() { StorageSettings &settings = StorageSettings::instance(); QSignalSpy spy(&settings, &Akonadi::StorageSettings::defaultNoteCollectionChanged); settings.setDefaultNoteCollection(Collection(2)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().value(), Collection(2)); } void shouldNotNotifyIdenticalNoteCollectionChanges() { StorageSettings &settings = StorageSettings::instance(); settings.setDefaultNoteCollection(Collection(4)); QSignalSpy spy(&settings, &Akonadi::StorageSettings::defaultNoteCollectionChanged); settings.setDefaultNoteCollection(Collection(4)); QCOMPARE(spy.count(), 0); } - - void shouldNotifyActiveCollectionsChanges() - { - StorageSettings &settings = StorageSettings::instance(); - QSignalSpy spy(&settings, &Akonadi::StorageSettings::activeCollectionsChanged); - settings.setActiveCollections(colList(2)); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.first().first().value(), colList(2)); - } - - void shouldNotNotifyIdenticalActiveCollectionsChanges() - { - StorageSettings &settings = StorageSettings::instance(); - settings.setActiveCollections(colList(4)); - QSignalSpy spy(&settings, &Akonadi::StorageSettings::activeCollectionsChanged); - settings.setActiveCollections(colList(4)); - QCOMPARE(spy.count(), 0); - } }; ZANSHIN_TEST_MAIN(AkonadiStorageSettingsTest) #include "akonadistoragesettingstest.moc"