File indexing completed on 2024-05-12 05:20:40

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kmlaunchexternalcomponent.h"
0008 #include "kmail_debug.h"
0009 #include "newmailnotifierinterface.h"
0010 #include <Akonadi/AgentConfigurationDialog>
0011 #include <Akonadi/AgentManager>
0012 #include <KLocalizedString>
0013 #include <KMessageBox>
0014 
0015 #include <MailCommon/FilterManager>
0016 
0017 #include <KDialogJobUiDelegate>
0018 #include <KIO/ApplicationLauncherJob>
0019 #include <KIO/CommandLauncherJob>
0020 #include <QPointer>
0021 
0022 #include <QProcess>
0023 #include <QStandardPaths>
0024 
0025 KMLaunchExternalComponent::KMLaunchExternalComponent(QWidget *parentWidget, QObject *parent)
0026     : QObject(parent)
0027     , mParentWidget(parentWidget)
0028 {
0029 }
0030 
0031 KMLaunchExternalComponent::~KMLaunchExternalComponent() = default;
0032 
0033 void KMLaunchExternalComponent::slotConfigureAutomaticArchiving()
0034 {
0035     auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_archivemail_agent"));
0036     if (agent.isValid()) {
0037         Akonadi::AgentConfigurationDialog dlg(agent, mParentWidget);
0038         dlg.exec();
0039     } else {
0040         KMessageBox::error(mParentWidget, i18n("Archive Mail Agent was not registered."));
0041     }
0042 }
0043 
0044 void KMLaunchExternalComponent::slotConfigureSendLater()
0045 {
0046     auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_sendlater_agent"));
0047     if (agent.isValid()) {
0048         Akonadi::AgentConfigurationDialog dlg(agent, mParentWidget);
0049         dlg.exec();
0050     } else {
0051         KMessageBox::error(mParentWidget, i18n("Send Later Agent was not registered."));
0052     }
0053 }
0054 
0055 void KMLaunchExternalComponent::slotConfigureMailMerge()
0056 {
0057     auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_mailmerge_agent"));
0058     if (agent.isValid()) {
0059         Akonadi::AgentConfigurationDialog dlg(agent, mParentWidget);
0060         dlg.exec();
0061     } else {
0062         KMessageBox::error(mParentWidget, i18n("Mail Merge Agent was not registered."));
0063     }
0064 }
0065 
0066 void KMLaunchExternalComponent::slotConfigureFollowupReminder()
0067 {
0068     auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_followupreminder_agent"));
0069     if (agent.isValid()) {
0070         QPointer<Akonadi::AgentConfigurationDialog> dlg = new Akonadi::AgentConfigurationDialog(agent, mParentWidget);
0071         dlg->exec();
0072         delete dlg;
0073     } else {
0074         KMessageBox::error(mParentWidget, i18n("Followup Reminder Agent was not registered."));
0075     }
0076 }
0077 
0078 void KMLaunchExternalComponent::slotStartCertManager()
0079 {
0080     const KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.kleopatra"));
0081     if (service) {
0082         auto job = new KIO::ApplicationLauncherJob(service);
0083         job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, mParentWidget->window()));
0084         job->start();
0085     } else {
0086         KMessageBox::error(mParentWidget,
0087                            i18n("Could not start certificate manager; "
0088                                 "please make sure you have Kleopatra properly installed."),
0089                            i18nc("@title:window", "KMail Error"));
0090     }
0091 }
0092 
0093 void KMLaunchExternalComponent::slotImportWizard()
0094 {
0095     const KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.akonadiimportwizard"));
0096     if (service) {
0097         auto job = new KIO::ApplicationLauncherJob(service);
0098         job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, mParentWidget->window()));
0099         job->start();
0100     } else {
0101         KMessageBox::error(mParentWidget,
0102                            i18n("Could not start the import wizard. "
0103                                 "Please make sure you have ImportWizard properly installed."),
0104                            i18nc("@title:window", "Unable to start import wizard"));
0105     }
0106 }
0107 
0108 void KMLaunchExternalComponent::slotExportData()
0109 {
0110     const KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.pimdataexporter"));
0111     if (service) {
0112         auto job = new KIO::ApplicationLauncherJob(service);
0113         job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, mParentWidget->window()));
0114         job->start();
0115     } else {
0116         KMessageBox::error(mParentWidget,
0117                            i18n("Could not start \"PIM Data Exporter\" program. "
0118                                 "Please check your installation."),
0119                            i18nc("@title:window", "Unable to start \"PIM Data Exporter\" program"));
0120     }
0121 }
0122 
0123 void KMLaunchExternalComponent::slotRunAddressBook()
0124 {
0125     auto job = new KIO::CommandLauncherJob(QStringLiteral("kaddressbook"), {}, this);
0126     job->setDesktopName(QStringLiteral("org.kde.kaddressbook"));
0127     job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, mParentWidget->window()));
0128     job->start();
0129 }
0130 
0131 void KMLaunchExternalComponent::slotImport()
0132 {
0133     const QStringList lst = {QStringLiteral("--mode"), QStringLiteral("manual")};
0134     const QString path = QStandardPaths::findExecutable(QStringLiteral("akonadiimportwizard"));
0135     if (path.isEmpty() || !QProcess::startDetached(path, lst)) {
0136         KMessageBox::error(mParentWidget,
0137                            i18n("Could not start the ImportWizard. "
0138                                 "Please make sure you have ImportWizard properly installed."),
0139                            i18nc("@title:window", "Unable to start ImportWizard"));
0140     }
0141 }
0142 
0143 void KMLaunchExternalComponent::slotAccountWizard()
0144 {
0145     const QString path = QStandardPaths::findExecutable(QStringLiteral("accountwizard"));
0146     if (path.isEmpty() || !QProcess::startDetached(path, {})) {
0147         KMessageBox::error(mParentWidget,
0148                            i18n("Could not start the account wizard. "
0149                                 "Please make sure you have AccountWizard properly installed."),
0150                            i18nc("@title:window", "Unable to start account wizard"));
0151     }
0152 }
0153 
0154 void KMLaunchExternalComponent::slotFilterLogViewer()
0155 {
0156     MailCommon::FilterManager::instance()->showFilterLogDialog(static_cast<qlonglong>(mParentWidget->winId()));
0157 }
0158 
0159 void KMLaunchExternalComponent::slotShowNotificationHistory()
0160 {
0161     const auto service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("akonadi_newmailnotifier_agent"));
0162     auto newMailNotifierInterface =
0163         new OrgFreedesktopAkonadiNewMailNotifierInterface(service, QStringLiteral("/NewMailNotifierAgent"), QDBusConnection::sessionBus(), this);
0164     if (!newMailNotifierInterface->isValid()) {
0165         qCDebug(KMAIL_LOG) << " org.freedesktop.Akonadi.NewMailNotifierAgent not found. Please verify your installation";
0166     } else {
0167         newMailNotifierInterface->showNotNotificationHistoryDialog(0); // TODO fix me windid
0168     }
0169     delete newMailNotifierInterface;
0170 }
0171 
0172 #include "moc_kmlaunchexternalcomponent.cpp"