File indexing completed on 2025-05-04 04:54:54

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 "followupremindershowmessagejob.h"
0008 #include "followupreminderagent_debug.h"
0009 #include <QDBusConnection>
0010 #include <QDBusConnectionInterface>
0011 #include <QDBusInterface>
0012 
0013 FollowUpReminderShowMessageJob::FollowUpReminderShowMessageJob(Akonadi::Item::Id id, QObject *parent)
0014     : QObject(parent)
0015     , mId(id)
0016 {
0017 }
0018 
0019 FollowUpReminderShowMessageJob::~FollowUpReminderShowMessageJob() = default;
0020 
0021 void FollowUpReminderShowMessageJob::start()
0022 {
0023     if (mId < 0) {
0024         qCWarning(FOLLOWUPREMINDERAGENT_LOG) << " value < 0";
0025         deleteLater();
0026         return;
0027     }
0028     const QString kmailInterface = QStringLiteral("org.kde.kmail");
0029     QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered(kmailInterface);
0030     if (!reply.isValid() || !reply.value()) {
0031         // Program is not already running, so start it
0032         QString errmsg;
0033         if (!QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.kmail")).isValid()) {
0034             qCDebug(FOLLOWUPREMINDERAGENT_LOG) << " Can not start kmail";
0035             deleteLater();
0036             return;
0037         }
0038     }
0039     QDBusInterface kmail(kmailInterface, QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail"));
0040     if (kmail.isValid()) {
0041         kmail.call(QStringLiteral("showMail"), mId);
0042     } else {
0043         qCWarning(FOLLOWUPREMINDERAGENT_LOG) << "Impossible to access to DBus interface";
0044     }
0045     deleteLater();
0046 }
0047 
0048 #include "moc_followupremindershowmessagejob.cpp"