File indexing completed on 2024-12-22 05:01:13

0001 /*
0002   This file is part of the KDE project
0003 
0004   SPDX-FileCopyrightText: 2003 Sven Lüppken <sven@kde.org>
0005 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 #include "summaryview_plugin.h"
0010 #include "kmail-version.h"
0011 #include "kmailinterface.h"
0012 #include "summaryview_part.h"
0013 
0014 #include <KontactInterface/Core>
0015 
0016 #include <KAboutData>
0017 #include <KActionCollection>
0018 #include <KLocalizedString>
0019 #include <KSelectAction>
0020 #include <QIcon>
0021 
0022 #include <QMenu>
0023 
0024 EXPORT_KONTACT_PLUGIN_WITH_JSON(SummaryView, "summaryplugin.json")
0025 
0026 SummaryView::SummaryView(KontactInterface::Core *core, const KPluginMetaData &data, const QVariantList &)
0027     : KontactInterface::Plugin(core, core, data, nullptr)
0028 {
0029     mSyncAction = new KSelectAction(QIcon::fromTheme(QStringLiteral("view-refresh")), i18n("Sync All"), this);
0030     actionCollection()->addAction(QStringLiteral("kontact_summary_sync"), mSyncAction);
0031     connect(mSyncAction, &KSelectAction::actionTriggered, this, &SummaryView::syncAccount);
0032     connect(mSyncAction->menu(), &QMenu::aboutToShow, this, &SummaryView::fillSyncActionSubEntries);
0033 
0034     insertSyncAction(mSyncAction);
0035     fillSyncActionSubEntries();
0036 }
0037 
0038 void SummaryView::fillSyncActionSubEntries()
0039 {
0040     mSyncAction->clear();
0041 
0042     mAllSync = mSyncAction->addAction(i18nc("@action:inmenu sync everything", "All"));
0043 
0044     if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.kmail"))) {
0045         QStringList menuItems;
0046         org::kde::kmail::kmail kmail(QStringLiteral("org.kde.kmail"), QStringLiteral("/KMail"), QDBusConnection::sessionBus());
0047         const QDBusReply<QStringList> reply = kmail.accounts();
0048         if (reply.isValid()) {
0049             menuItems << reply.value();
0050         }
0051 
0052         for (const QString &acc : std::as_const(menuItems)) {
0053             mSyncAction->addAction(acc);
0054         }
0055     }
0056 }
0057 
0058 void SummaryView::syncAccount(QAction *act)
0059 {
0060     if (act == mAllSync) {
0061         doSync();
0062     } else {
0063         org::kde::kmail::kmail kmail(QStringLiteral("org.kde.kmail"), QStringLiteral("/KMail"), QDBusConnection::sessionBus());
0064         kmail.checkAccount(act->text());
0065     }
0066     fillSyncActionSubEntries();
0067 }
0068 
0069 SummaryView::~SummaryView() = default;
0070 
0071 void SummaryView::doSync()
0072 {
0073     if (mPart) {
0074         mPart->updateSummaries();
0075     }
0076 
0077     const QList<KontactInterface::Plugin *> pluginList = core()->pluginList();
0078     for (const KontactInterface::Plugin *i : pluginList) {
0079         // execute all sync actions but our own
0080         const QList<QAction *> actList = i->syncActions();
0081         for (QAction *j : actList) {
0082             if (j != mSyncAction) {
0083                 j->trigger();
0084             }
0085         }
0086     }
0087     fillSyncActionSubEntries();
0088 }
0089 
0090 KParts::Part *SummaryView::createPart()
0091 {
0092     mPart = new SummaryViewPart(core(), aboutData(), this);
0093     mPart->setObjectName(QLatin1StringView("summaryPart"));
0094     return mPart;
0095 }
0096 
0097 const KAboutData SummaryView::aboutData()
0098 {
0099     KAboutData aboutData = KAboutData(QStringLiteral("kontactsummary"),
0100                                       i18n("Kontact Summary"),
0101                                       QStringLiteral(KDEPIM_VERSION),
0102                                       i18n("Kontact Summary View"),
0103                                       KAboutLicense::LGPL,
0104                                       i18n("(c) 2003-2021 The Kontact developers"));
0105 
0106     aboutData.addAuthor(i18n("Sven Lueppken"), QString(), QStringLiteral("sven@kde.org"));
0107     aboutData.addAuthor(i18n("Cornelius Schumacher"), QString(), QStringLiteral("schumacher@kde.org"));
0108     aboutData.addAuthor(i18n("Tobias Koenig"), QString(), QStringLiteral("tokoe@kde.org"));
0109     aboutData.setProductName(QByteArrayLiteral("kontact/summary"));
0110     return aboutData;
0111 }
0112 
0113 #include "summaryview_plugin.moc"
0114 
0115 #include "moc_summaryview_plugin.cpp"