Fix mem leak
[kdepim.git] / kmail / kmlaunchexternalcomponent.cpp
blob315d468a87be83bbca215af95948e1c0ad1b883b
1 /*
2 Copyright (c) 2014-2016 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "kmlaunchexternalcomponent.h"
19 #include <KMessageBox>
20 #include <KLocalizedString>
21 #include <KRun>
23 #include "util.h"
24 #include "archivemailagentinterface.h"
25 #include "sendlateragentinterface.h"
26 #include "followupreminderinterface.h"
27 #include "MailCommon/FilterManager"
29 #include <QtDBus/QDBusInterface>
30 #include <QtDBus/QDBusReply>
31 #include <QProcess>
32 #include "kmail_debug.h"
33 #include <QStandardPaths>
35 KMLaunchExternalComponent::KMLaunchExternalComponent(QWidget *parentWidget, QObject *parent)
36 : QObject(parent),
37 mParentWidget(parentWidget)
42 KMLaunchExternalComponent::~KMLaunchExternalComponent()
47 void KMLaunchExternalComponent::slotConfigureAutomaticArchiving()
49 OrgFreedesktopAkonadiArchiveMailAgentInterface archiveMailInterface(QStringLiteral("org.freedesktop.Akonadi.ArchiveMailAgent"), QStringLiteral("/ArchiveMailAgent"), QDBusConnection::sessionBus(), this);
50 if (archiveMailInterface.isValid()) {
51 archiveMailInterface.showConfigureDialog((qlonglong)mParentWidget->winId());
52 } else {
53 KMessageBox::error(mParentWidget, i18n("Archive Mail Agent was not registered."));
57 void KMLaunchExternalComponent::slotConfigureSendLater()
59 OrgFreedesktopAkonadiSendLaterAgentInterface sendLaterInterface(QStringLiteral("org.freedesktop.Akonadi.SendLaterAgent"), QStringLiteral("/SendLaterAgent"), QDBusConnection::sessionBus(), this);
60 if (sendLaterInterface.isValid()) {
61 sendLaterInterface.showConfigureDialog((qlonglong)mParentWidget->winId());
62 } else {
63 KMessageBox::error(mParentWidget, i18n("Send Later Agent was not registered."));
67 void KMLaunchExternalComponent::slotConfigureFollowupReminder()
69 OrgFreedesktopAkonadiFollowUpReminderAgentInterface followUpInterface(QStringLiteral("org.freedesktop.Akonadi.FollowUpReminder"), QStringLiteral("/FollowUpReminder"), QDBusConnection::sessionBus(), this);
70 if (followUpInterface.isValid()) {
71 followUpInterface.showConfigureDialog((qlonglong)mParentWidget->winId());
72 } else {
73 KMessageBox::error(mParentWidget, i18n("Followup Reminder Agent was not registered."));
77 void KMLaunchExternalComponent::slotStartCertManager()
79 if (!QProcess::startDetached(QStringLiteral("kleopatra"))) {
80 KMessageBox::error(mParentWidget, i18n("Could not start certificate manager; "
81 "please check your installation."),
82 i18n("KMail Error"));
86 void KMLaunchExternalComponent::slotStartWatchGnuPG()
88 if (!QProcess::startDetached(QStringLiteral("kwatchgnupg"))) {
89 KMessageBox::error(mParentWidget, i18n("Could not start GnuPG LogViewer (kwatchgnupg); "
90 "please check your installation."),
91 i18n("KMail Error"));
95 void KMLaunchExternalComponent::slotImportWizard()
97 const QString path = QStandardPaths::findExecutable(QStringLiteral("importwizard"));
98 if (!QProcess::startDetached(path)) {
99 KMessageBox::error(mParentWidget, i18n("Could not start the import wizard. "
100 "Please check your installation."),
101 i18n("Unable to start import wizard"));
105 void KMLaunchExternalComponent::slotExportData()
107 const QString path = QStandardPaths::findExecutable(QStringLiteral("pimsettingexporter"));
108 if (!QProcess::startDetached(path)) {
109 KMessageBox::error(mParentWidget, i18n("Could not start \"PIM Setting Exporter\" program. "
110 "Please check your installation."),
111 i18n("Unable to start \"PIM Setting Exporter\" program"));
115 void KMLaunchExternalComponent::slotAddrBook()
117 KRun::runCommand(QStringLiteral("kaddressbook"), mParentWidget->window());
120 void KMLaunchExternalComponent::slotImport()
122 QStringList lst;
123 lst.append(QStringLiteral("--mode"));
124 lst.append(QStringLiteral("manual"));
125 const QString path = QStandardPaths::findExecutable(QStringLiteral("importwizard"));
126 if (!QProcess::startDetached(path, lst)) {
127 KMessageBox::error(mParentWidget, i18n("Could not start the ImportWizard. "
128 "Please check your installation."),
129 i18n("Unable to start ImportWizard"));
133 void KMLaunchExternalComponent::slotAccountWizard()
135 QStringList lst;
136 lst.append(QStringLiteral("--type"));
137 lst.append(QStringLiteral("message/rfc822"));
139 const QString path = QStandardPaths::findExecutable(QStringLiteral("accountwizard"));
140 if (!QProcess::startDetached(path, lst)) {
141 KMessageBox::error(mParentWidget, i18n("Could not start the account wizard. "
142 "Please check your installation."),
143 i18n("Unable to start account wizard"));
147 void KMLaunchExternalComponent::slotFilterLogViewer()
149 MailCommon::FilterManager::instance()->showFilterLogDialog((qlonglong)mParentWidget->winId());