File indexing completed on 2024-12-22 04:56:53

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 "newmailnotifiershowmessagejob.h"
0008 #include "newmailnotifier_debug.h"
0009 #include <KLocalizedString>
0010 
0011 #include <QDBusConnection>
0012 #include <QDBusConnectionInterface>
0013 #include <QDBusInterface>
0014 #include <QDBusReply>
0015 
0016 NewMailNotifierShowMessageJob::NewMailNotifierShowMessageJob(Akonadi::Item::Id id, QObject *parent)
0017     : KJob(parent)
0018     , mId(id)
0019 {
0020 }
0021 
0022 NewMailNotifierShowMessageJob::~NewMailNotifierShowMessageJob() = default;
0023 
0024 void NewMailNotifierShowMessageJob::start()
0025 {
0026     if (mId < 0) {
0027         emitResult();
0028         return;
0029     }
0030 
0031     const QString kmailInterface = QStringLiteral("org.kde.kmail");
0032     auto startReply = QDBusConnection::sessionBus().interface()->startService(kmailInterface);
0033     if (!startReply.isValid()) {
0034         qCDebug(NEWMAILNOTIFIER_LOG) << "Can not start kmail";
0035         setError(UserDefinedError);
0036         setErrorText(i18n("Unable to start KMail application."));
0037         emitResult();
0038         return;
0039     }
0040 
0041     QDBusInterface kmail(kmailInterface, QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail"));
0042     if (kmail.isValid()) {
0043         kmail.call(QStringLiteral("showMail"), mId);
0044     } else {
0045         qCWarning(NEWMAILNOTIFIER_LOG) << "Impossible to access the DBus interface";
0046     }
0047 
0048     emitResult();
0049 }
0050 
0051 #include "moc_newmailnotifiershowmessagejob.cpp"