diff --git a/agents/unifiedmailboxagent/mailkernel.cpp b/agents/unifiedmailboxagent/mailkernel.cpp index d13d713f0..d8164320b 100644 --- a/agents/unifiedmailboxagent/mailkernel.cpp +++ b/agents/unifiedmailboxagent/mailkernel.cpp @@ -1,144 +1,144 @@ /* Copyright (C) 2018 Daniel Vrátil 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mailkernel.h" #include #include #include #include #include #include #include #include #include -MailKernel::MailKernel(KSharedConfigPtr config, QObject *parent) +MailKernel::MailKernel(const KSharedConfigPtr &config, QObject *parent) : QObject(parent) , mConfig(config) { mMessageSender = new MessageComposer::AkonadiSender(this); mIdentityManager = new KIdentityManagement::IdentityManager(true, this); Akonadi::Session *session = new Akonadi::Session("UnifiedMailbox Kernel ETM", this); mFolderCollectionMonitor = new MailCommon::FolderCollectionMonitor(session, this); mEntityTreeModel = new Akonadi::EntityTreeModel(folderCollectionMonitor(), this); mEntityTreeModel->setListFilter(Akonadi::CollectionFetchScope::Enabled); mEntityTreeModel->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation); mCollectionModel = new Akonadi::EntityMimeTypeFilterModel(this); mCollectionModel->setSourceModel(mEntityTreeModel); mCollectionModel->addMimeTypeInclusionFilter(Akonadi::Collection::mimeType()); mCollectionModel->setHeaderGroup(Akonadi::EntityTreeModel::CollectionTreeHeaders); mCollectionModel->setDynamicSortFilter(true); mCollectionModel->setSortCaseSensitivity(Qt::CaseInsensitive); CommonKernel->registerKernelIf(this); CommonKernel->registerSettingsIf(this); } MailKernel::~MailKernel() { CommonKernel->registerKernelIf(nullptr); CommonKernel->registerSettingsIf(nullptr); } KIdentityManagement::IdentityManager *MailKernel::identityManager() { return mIdentityManager; } MessageComposer::MessageSender *MailKernel::msgSender() { return mMessageSender; } Akonadi::EntityMimeTypeFilterModel *MailKernel::collectionModel() const { return mCollectionModel; } KSharedConfig::Ptr MailKernel::config() { return mConfig; } void MailKernel::syncConfig() { Q_ASSERT(false); } MailCommon::JobScheduler *MailKernel::jobScheduler() const { Q_ASSERT(false); return nullptr; } Akonadi::ChangeRecorder *MailKernel::folderCollectionMonitor() const { return mFolderCollectionMonitor->monitor(); } void MailKernel::updateSystemTray() { Q_ASSERT(false); } bool MailKernel::showPopupAfterDnD() { return false; } qreal MailKernel::closeToQuotaThreshold() { return 80; } QStringList MailKernel::customTemplates() { Q_ASSERT(false); return QStringList(); } bool MailKernel::excludeImportantMailFromExpiry() { Q_ASSERT(false); return true; } Akonadi::Collection::Id MailKernel::lastSelectedFolder() { Q_ASSERT(false); return Akonadi::Collection::Id(); } void MailKernel::setLastSelectedFolder(Akonadi::Collection::Id col) { Q_UNUSED(col); } void MailKernel::expunge(Akonadi::Collection::Id id, bool sync) { Akonadi::Collection col(id); if (col.isValid()) { mFolderCollectionMonitor->expunge(Akonadi::Collection(col), sync); } } diff --git a/agents/unifiedmailboxagent/mailkernel.h b/agents/unifiedmailboxagent/mailkernel.h index 09d7276d7..79972333e 100644 --- a/agents/unifiedmailboxagent/mailkernel.h +++ b/agents/unifiedmailboxagent/mailkernel.h @@ -1,74 +1,74 @@ /* Copyright (C) 2018 Daniel Vrátil 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MAILKERNEL_H #define MAILKERNEL_H #include #include namespace Akonadi { class EntityTreeModel; class EntityMimeTypeFilterModel; } namespace MailCommon { class FolderCollectionMonitor; } class MailKernel : public QObject , public MailCommon::IKernel , public MailCommon::ISettings { Q_OBJECT public: - explicit MailKernel(KSharedConfigPtr config, QObject *parent = nullptr); + explicit MailKernel(const KSharedConfigPtr &config, QObject *parent = nullptr); ~MailKernel() override; KIdentityManagement::IdentityManager *identityManager() override; MessageComposer::MessageSender *msgSender() override; Akonadi::EntityMimeTypeFilterModel *collectionModel() const override; KSharedConfig::Ptr config() override; void syncConfig() override; MailCommon::JobScheduler *jobScheduler() const override; Akonadi::ChangeRecorder *folderCollectionMonitor() const override; void updateSystemTray() override; qreal closeToQuotaThreshold() override; bool excludeImportantMailFromExpiry() override; QStringList customTemplates() override; Akonadi::Collection::Id lastSelectedFolder() override; void setLastSelectedFolder(Akonadi::Collection::Id col) override; bool showPopupAfterDnD() override; void expunge(Akonadi::Collection::Id id, bool sync) override; private: Q_DISABLE_COPY(MailKernel) KSharedConfigPtr mConfig; KIdentityManagement::IdentityManager *mIdentityManager = nullptr; MessageComposer::MessageSender *mMessageSender = nullptr; MailCommon::FolderCollectionMonitor *mFolderCollectionMonitor = nullptr; Akonadi::EntityTreeModel *mEntityTreeModel = nullptr; Akonadi::EntityMimeTypeFilterModel *mCollectionModel = nullptr; }; #endif diff --git a/agents/unifiedmailboxagent/settingsdialog.cpp b/agents/unifiedmailboxagent/settingsdialog.cpp index 8d99ebd94..811b2d472 100644 --- a/agents/unifiedmailboxagent/settingsdialog.cpp +++ b/agents/unifiedmailboxagent/settingsdialog.cpp @@ -1,162 +1,162 @@ /* Copyright (C) 2018 Daniel Vrátil 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "settingsdialog.h" #include "unifiedmailboxmanager.h" #include "unifiedmailboxeditor.h" #include "unifiedmailbox.h" #include "mailkernel.h" #include #include #include #include #include #include #include #include #include #include #include namespace { static constexpr const char *DialogGroup = "__Dialog"; } -SettingsDialog::SettingsDialog(KSharedConfigPtr config, UnifiedMailboxManager &boxManager, WId, QWidget *parent) +SettingsDialog::SettingsDialog(const KSharedConfigPtr &config, UnifiedMailboxManager &boxManager, WId, QWidget *parent) : QDialog(parent) , mBoxManager(boxManager) , mKernel(new MailKernel(config, this)) , mConfig(config) { auto l = new QVBoxLayout; setLayout(l); auto h = new QHBoxLayout; l->addLayout(h); mBoxModel = new QStandardItemModel(this); auto view = new QListView(this); view->setEditTriggers(QListView::NoEditTriggers); view->setModel(mBoxModel); h->addWidget(view); auto v = new QVBoxLayout; h->addLayout(v); auto addButton = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add-symbolic")), i18n("Add")); v->addWidget(addButton); connect(addButton, &QPushButton::clicked, this, [this]() { auto mailbox = std::make_unique(); auto editor = new UnifiedMailboxEditor(mailbox.get(), mConfig, this); if (editor->exec()) { mailbox->setId(mailbox->name()); // assign ID addBox(mailbox.get()); mBoxManager.insertBox(std::move(mailbox)); } }); auto editButton = new QPushButton(QIcon::fromTheme(QStringLiteral("entry-edit")), i18n("Modify")); editButton->setEnabled(false); v->addWidget(editButton); connect(editButton, &QPushButton::clicked, this, [this, view]() { const auto indexes = view->selectionModel()->selectedIndexes(); if (!indexes.isEmpty()) { auto item = mBoxModel->itemFromIndex(indexes[0]); auto mailbox = item->data().value(); auto editor = new UnifiedMailboxEditor(mailbox, mConfig, this); if (editor->exec()) { item->setText(mailbox->name()); item->setIcon(QIcon::fromTheme(mailbox->icon())); } } }); auto removeButton = new QPushButton(QIcon::fromTheme(QStringLiteral("list-remove-symbolic")), i18n("Remove")); removeButton->setEnabled(false); v->addWidget(removeButton); connect(removeButton, &QPushButton::clicked, this, [this, view]() { const auto indexes = view->selectionModel()->selectedIndexes(); if (!indexes.isEmpty()) { auto item = mBoxModel->itemFromIndex(indexes[0]); const auto mailbox = item->data().value(); if (KMessageBox::warningYesNo( this, i18n("Do you really want to remove unified mailbox %1?", mailbox->name()), i18n("Really Remove?"), KStandardGuiItem::remove(), KStandardGuiItem::cancel()) == KMessageBox::Yes) { mBoxModel->removeRow(item->row()); mBoxManager.removeBox(mailbox->id()); } } }); v->addStretch(1); connect(view->selectionModel(), &QItemSelectionModel::selectionChanged, this, [view, editButton, removeButton]() { const bool hasSelection = view->selectionModel()->hasSelection(); editButton->setEnabled(hasSelection); removeButton->setEnabled(hasSelection); }); auto box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect(box, &QDialogButtonBox::accepted, this, &SettingsDialog::accept); connect(box, &QDialogButtonBox::rejected, this, &SettingsDialog::reject); l->addWidget(box); loadBoxes(); const auto dlgGroup = config->group(DialogGroup); if (dlgGroup.hasKey("geometry")) { restoreGeometry(dlgGroup.readEntry("geometry", QByteArray())); } else { resize(500, 500); } } SettingsDialog::~SettingsDialog() { auto dlgGroup = mConfig->group(DialogGroup); dlgGroup.writeEntry("geometry", saveGeometry()); } void SettingsDialog::accept() { mBoxManager.saveBoxes(); QDialog::accept(); } void SettingsDialog::loadBoxes() { mBoxModel->clear(); for (const auto &mailboxIt : mBoxManager) { addBox(mailboxIt.second.get()); } } void SettingsDialog::addBox(UnifiedMailbox *box) { auto item = new QStandardItem(QIcon::fromTheme(box->icon()), box->name()); item->setData(QVariant::fromValue(box)); mBoxModel->appendRow(item); } diff --git a/agents/unifiedmailboxagent/settingsdialog.h b/agents/unifiedmailboxagent/settingsdialog.h index c4b835c17..29fbaf94f 100644 --- a/agents/unifiedmailboxagent/settingsdialog.h +++ b/agents/unifiedmailboxagent/settingsdialog.h @@ -1,56 +1,56 @@ /* Copyright (C) 2018 Daniel Vrátil 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SETTINGSDIALOG_H_ #define SETTINGSDIALOG_H_ #include #include #include "unifiedmailboxmanager.h" class QStandardItemModel; class MailKernel; class SettingsDialog : public QDialog { Q_OBJECT public: - explicit SettingsDialog(KSharedConfigPtr config, UnifiedMailboxManager &manager, + explicit SettingsDialog(const KSharedConfigPtr &config, UnifiedMailboxManager &manager, WId windowId, QWidget *parent = nullptr); ~SettingsDialog() override; public Q_SLOTS: void accept() override; private: void loadBoxes(); void addBox(UnifiedMailbox *box); private: QStandardItemModel *mBoxModel = nullptr; UnifiedMailboxManager &mBoxManager; MailKernel *mKernel = nullptr; KSharedConfigPtr mConfig; }; #endif