diff --git a/src/akonadi/akonadiconfigdialog.cpp b/src/akonadi/akonadiconfigdialog.cpp index cca2b23a..cf95759b 100644 --- a/src/akonadi/akonadiconfigdialog.cpp +++ b/src/akonadi/akonadiconfigdialog.cpp @@ -1,143 +1,156 @@ /* This file is part of Zanshin Copyright 2011-2015 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 "akonadiconfigdialog.h" #include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include +#include + using namespace Akonadi; -ConfigDialog::ConfigDialog(QWidget *parent) - : QDialog(parent) +ConfigDialog::ConfigDialog(StorageInterface::FetchContentTypes types, QWidget *parent) + : QDialog(parent), + m_agentInstanceWidget(new Akonadi::AgentInstanceWidget(this)), + m_types(types) { setWindowTitle(i18n("Configure")); auto description = new QLabel(this); description->setWordWrap(true); description->setText(i18n("Please select or create a resource which will be used by the application to store and query its TODOs.")); - m_agentInstanceWidget = new Akonadi::AgentInstanceWidget(this); - m_agentInstanceWidget->agentFilterProxyModel()->addMimeTypeFilter(QStringLiteral("application/x-vnd.akonadi.calendar.todo")); + applyContentTypes(m_agentInstanceWidget->agentFilterProxyModel()); auto toolBar = new QToolBar(this); toolBar->setIconSize(QSize(16, 16)); toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); auto addAction = new QAction(this); addAction->setObjectName(QStringLiteral("addAction")); addAction->setText(i18n("Add resource")); addAction->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); connect(addAction, &QAction::triggered, this, &ConfigDialog::onAddTriggered); toolBar->addAction(addAction); auto removeAction = new QAction(this); removeAction->setObjectName(QStringLiteral("removeAction")); removeAction->setText(i18n("Remove resource")); removeAction->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); connect(removeAction, &QAction::triggered, this, &ConfigDialog::onRemoveTriggered); toolBar->addAction(removeAction); auto configureAction = new QAction(this); configureAction->setObjectName(QStringLiteral("settingsAction")); configureAction->setText(i18n("Configure resource...")); configureAction->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); connect(configureAction, &QAction::triggered, this, &ConfigDialog::onConfigureTriggered); toolBar->addAction(configureAction); auto buttons = new QDialogButtonBox(this); buttons->setStandardButtons(QDialogButtonBox::Close); connect(buttons, &QDialogButtonBox::accepted, this, &ConfigDialog::accept); connect(buttons, &QDialogButtonBox::rejected, this, &ConfigDialog::reject); auto layout = new QVBoxLayout; layout->addWidget(description); layout->addWidget(m_agentInstanceWidget); auto toolBarLayout = new QHBoxLayout; toolBarLayout->setAlignment(Qt::AlignRight); toolBarLayout->addWidget(toolBar); layout->addLayout(toolBarLayout); layout->addWidget(buttons); setLayout(layout); } void ConfigDialog::onAddTriggered() { auto dlg = QPointer(new AgentTypeDialog(this)); - dlg->agentFilterProxyModel()->addMimeTypeFilter(QStringLiteral("application/x-vnd.akonadi.calendar.todo")); + applyContentTypes(dlg->agentFilterProxyModel()); if (dlg->exec()) { if (!dlg) return; const auto agentType = dlg->agentType(); if (agentType.isValid()) { auto job = new Akonadi::AgentInstanceCreateJob(agentType, this); job->configure(this); job->start(); } } delete dlg; } void ConfigDialog::onRemoveTriggered() { auto list = m_agentInstanceWidget->selectedAgentInstances(); if (!list.isEmpty()) { auto answer = QMessageBox::question(this, i18n("Multiple Agent Deletion"), i18n("Do you really want to delete the selected agent instances?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (answer == QMessageBox::Yes) { foreach (const auto &agent, list) { Akonadi::AgentManager::self()->removeInstance(agent); } } } } void ConfigDialog::onConfigureTriggered() { auto agent = m_agentInstanceWidget->currentAgentInstance(); if (agent.isValid()) agent.configure(this); } +void ConfigDialog::applyContentTypes(AgentFilterProxyModel *model) +{ + if (m_types & StorageInterface::Notes) + model->addMimeTypeFilter(NoteUtils::noteMimeType()); + if (m_types & StorageInterface::Tasks) + model->addMimeTypeFilter(KCalCore::Todo::todoMimeType()); +} + diff --git a/src/akonadi/akonadiconfigdialog.h b/src/akonadi/akonadiconfigdialog.h index bb0478e2..488ee180 100644 --- a/src/akonadi/akonadiconfigdialog.h +++ b/src/akonadi/akonadiconfigdialog.h @@ -1,52 +1,58 @@ /* This file is part of Zanshin Copyright 2011-2015 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_CONFIGDIALOG_H #define AKONADI_CONFIGDIALOG_H #include +#include "akonadistorageinterface.h" + namespace Akonadi { +class AgentFilterProxyModel; class AgentInstanceWidget; class ConfigDialog : public QDialog { Q_OBJECT public: - explicit ConfigDialog(QWidget *parent = 0); + explicit ConfigDialog(StorageInterface::FetchContentTypes types, QWidget *parent = 0); private slots: void onAddTriggered(); void onRemoveTriggered(); void onConfigureTriggered(); private: + void applyContentTypes(AgentFilterProxyModel *model); + Akonadi::AgentInstanceWidget *m_agentInstanceWidget; + const StorageInterface::FetchContentTypes m_types; }; } #endif // AKONADI_CONFIGDIALOG_H diff --git a/src/akonadi/akonadidatasourcerepository.cpp b/src/akonadi/akonadidatasourcerepository.cpp index 902e8221..1b0e9cc1 100644 --- a/src/akonadi/akonadidatasourcerepository.cpp +++ b/src/akonadi/akonadidatasourcerepository.cpp @@ -1,58 +1,60 @@ /* 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 "akonadidatasourcerepository.h" #include #include #include "akonadiconfigdialog.h" using namespace Akonadi; -DataSourceRepository::DataSourceRepository(const StorageInterface::Ptr &storage, +DataSourceRepository::DataSourceRepository(StorageInterface::FetchContentTypes contentTypes, + const StorageInterface::Ptr &storage, const SerializerInterface::Ptr &serializer) - : m_storage(storage), + : m_contentTypes(contentTypes), + m_storage(storage), m_serializer(serializer) { } KJob *DataSourceRepository::update(Domain::DataSource::Ptr source) { auto collection = m_serializer->createCollectionFromDataSource(source); Q_ASSERT(collection.isValid()); return m_storage->updateCollection(collection); } void DataSourceRepository::showConfigDialog() { - ConfigDialog dialog(qApp->activeWindow()); + ConfigDialog dialog(m_contentTypes, qApp->activeWindow()); dialog.exec(); } void DataSourceRepository::windowNeedsDataBackend(QWidget *window) { Akonadi::ControlGui::widgetNeedsAkonadi(window); } diff --git a/src/akonadi/akonadidatasourcerepository.h b/src/akonadi/akonadidatasourcerepository.h index 2a7affaa..afb3dbd9 100644 --- a/src/akonadi/akonadidatasourcerepository.h +++ b/src/akonadi/akonadidatasourcerepository.h @@ -1,58 +1,60 @@ /* 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. */ #ifndef AKONADI_DATASOURCEREPOSITORY_H #define AKONADI_DATASOURCEREPOSITORY_H #include "domain/datasourcerepository.h" #include "akonadi/akonadiserializerinterface.h" #include "akonadi/akonadistorageinterface.h" namespace Akonadi { class SerializerInterface; class StorageInterface; class DataSourceRepository : public QObject, public Domain::DataSourceRepository { Q_OBJECT public: typedef QSharedPointer Ptr; - DataSourceRepository(const StorageInterface::Ptr &storage, + DataSourceRepository(StorageInterface::FetchContentTypes contentTypes, + const StorageInterface::Ptr &storage, const SerializerInterface::Ptr &serializer); KJob *update(Domain::DataSource::Ptr source) Q_DECL_OVERRIDE; void showConfigDialog() Q_DECL_OVERRIDE; void windowNeedsDataBackend(QWidget *window) Q_DECL_OVERRIDE; private: + StorageInterface::FetchContentTypes m_contentTypes; StorageInterface::Ptr m_storage; SerializerInterface::Ptr m_serializer; }; } #endif // AKONADI_DATASOURCEREPOSITORY_H diff --git a/src/renku/app/dependencies.cpp b/src/renku/app/dependencies.cpp index 398eb603..a021cb69 100644 --- a/src/renku/app/dependencies.cpp +++ b/src/renku/app/dependencies.cpp @@ -1,109 +1,111 @@ /* This file is part of Renku Notes Copyright 2015 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 "dependencies.h" #include "akonadi/akonadidatasourcequeries.h" #include "akonadi/akonadidatasourcerepository.h" #include "akonadi/akonadinotequeries.h" #include "akonadi/akonadinoterepository.h" #include "akonadi/akonaditagqueries.h" #include "akonadi/akonaditagrepository.h" #include "akonadi/akonadicache.h" #include "akonadi/akonadicachingstorage.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadiserializer.h" #include "akonadi/akonadistorage.h" #include "presentation/artifacteditormodel.h" #include "presentation/availablenotepagesmodel.h" #include "presentation/availablesourcesmodel.h" #include "utils/dependencymanager.h" void App::initializeDependencies() { auto &deps = Utils::DependencyManager::globalInstance(); deps.add(); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { return new Akonadi::CachingStorage(deps->create(), Akonadi::StorageInterface::Ptr(new Akonadi::Storage)); }); deps.add([] (Utils::DependencyManager *deps) { return new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Notes, deps->create(), deps->create(), deps->create()); }); - deps.add(); + deps.add([] (Utils::DependencyManager *deps) { + return new Akonadi::DataSourceRepository(Akonadi::StorageInterface::Notes, + deps->create(), + deps->create()); + }); deps.add(); deps.add(); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { auto model = new Presentation::ArtifactEditorModel; auto repository = deps->create(); model->setSaveFunction([repository] (const Domain::Artifact::Ptr &artifact) { auto note = artifact.objectCast(); Q_ASSERT(note); return repository->update(note); }); return model; }); deps.add(); deps.add(); } diff --git a/src/zanshin/app/dependencies.cpp b/src/zanshin/app/dependencies.cpp index 8e26793d..84c64558 100644 --- a/src/zanshin/app/dependencies.cpp +++ b/src/zanshin/app/dependencies.cpp @@ -1,135 +1,137 @@ /* 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 "dependencies.h" #include "akonadi/akonadicontextqueries.h" #include "akonadi/akonadicontextrepository.h" #include "akonadi/akonadidatasourcequeries.h" #include "akonadi/akonadidatasourcerepository.h" #include "akonadi/akonadiprojectqueries.h" #include "akonadi/akonadiprojectrepository.h" #include "akonadi/akonaditaskqueries.h" #include "akonadi/akonaditaskrepository.h" #include "akonadi/akonadicache.h" #include "akonadi/akonadicachingstorage.h" #include "akonadi/akonadimessaging.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadiserializer.h" #include "akonadi/akonadistorage.h" #include "presentation/artifacteditormodel.h" #include "presentation/availablesourcesmodel.h" #include "presentation/availabletaskpagesmodel.h" #include "presentation/runningtaskmodel.h" #include "utils/dependencymanager.h" void App::initializeDependencies() { auto &deps = Utils::DependencyManager::globalInstance(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { return new Akonadi::CachingStorage(deps->create(), Akonadi::StorageInterface::Ptr(new Akonadi::Storage)); }); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { return new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks, deps->create(), deps->create(), deps->create()); }); - deps.add(); + deps.add([] (Utils::DependencyManager *deps) { + return new Akonadi::DataSourceRepository(Akonadi::StorageInterface::Tasks, + deps->create(), + deps->create()); + }); deps.add(); deps.add(); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { auto model = new Presentation::ArtifactEditorModel; auto repository = deps->create(); model->setSaveFunction([repository] (const Domain::Artifact::Ptr &artifact) { auto task = artifact.objectCast(); Q_ASSERT(task); return repository->update(task); }); model->setDelegateFunction([repository] (const Domain::Task::Ptr &task, const Domain::Task::Delegate &delegate) { return repository->delegate(task, delegate); }); return model; }); deps.add(); deps.add(); deps.add(); } diff --git a/tests/units/akonadi/akonadidatasourcerepositorytest.cpp b/tests/units/akonadi/akonadidatasourcerepositorytest.cpp index 3ed3a6d0..a1f2e71d 100644 --- a/tests/units/akonadi/akonadidatasourcerepositorytest.cpp +++ b/tests/units/akonadi/akonadidatasourcerepositorytest.cpp @@ -1,76 +1,77 @@ /* 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 "utils/mockobject.h" #include "testlib/akonadifakejobs.h" #include "testlib/akonadifakemonitor.h" #include "akonadi/akonadidatasourcerepository.h" #include "akonadi/akonadiserializerinterface.h" #include "akonadi/akonadistorageinterface.h" using namespace mockitopp; Q_DECLARE_METATYPE(Testlib::AkonadiFakeItemFetchJob*) class AkonadiDataSourceRepositoryTest : public QObject { Q_OBJECT private slots: void shouldUpdateExistingSources() { // GIVEN // A source and its corresponding collection already existing in storage Akonadi::Collection collection(42); auto source = Domain::DataSource::Ptr::create(); // A mock modify job auto collectionModifyJob = new FakeJob(this); // Storage mock returning the create job Utils::MockObject storageMock; storageMock(&Akonadi::StorageInterface::updateCollection).when(collection, Q_NULLPTR) .thenReturn(collectionModifyJob); // Serializer mock returning the item for the project Utils::MockObject serializerMock; serializerMock(&Akonadi::SerializerInterface::createCollectionFromDataSource).when(source).thenReturn(collection); // WHEN - QScopedPointer repository(new Akonadi::DataSourceRepository(storageMock.getInstance(), + QScopedPointer repository(new Akonadi::DataSourceRepository(Akonadi::StorageInterface::Tasks, + storageMock.getInstance(), serializerMock.getInstance())); repository->update(source)->exec(); // THEN QVERIFY(serializerMock(&Akonadi::SerializerInterface::createCollectionFromDataSource).when(source).exactly(1)); QVERIFY(storageMock(&Akonadi::StorageInterface::updateCollection).when(collection, Q_NULLPTR).exactly(1)); } }; ZANSHIN_TEST_MAIN(AkonadiDataSourceRepositoryTest) #include "akonadidatasourcerepositorytest.moc"