Commit a4bdb16f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix open kmail when we click on button

parent 94ceb195
Pipeline #159513 passed with stage
in 13 minutes and 15 seconds
......@@ -46,6 +46,7 @@ target_link_libraries( akonadi_newmailnotifier_agent
KF5::Notifications
KF5::Service
KF5::I18n
KF5::KIOGui
)
if(Qt5TextToSpeech_FOUND)
......
......@@ -6,8 +6,10 @@
#include "newmailnotifiershowmessagejob.h"
#include "newmailnotifier_debug.h"
#include <KIO/ApplicationLauncherJob>
#include <KLocalizedString>
#include <KService>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
......@@ -27,24 +29,27 @@ void NewMailNotifierShowMessageJob::start()
emitResult();
return;
}
const QString kmailInterface = QStringLiteral("org.kde.kmail");
QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered(kmailInterface);
if (!reply.isValid() || !reply.value()) {
// Program is not already running, so start it
QString errmsg;
if (!QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.kmail2")).isValid()) {
qCDebug(NEWMAILNOTIFIER_LOG) << " Can not start kmail";
setError(UserDefinedError);
setErrorText(i18n("Unable to start KMail application."));
emitResult();
return;
}
}
QDBusInterface kmail(kmailInterface, QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail"));
if (kmail.isValid()) {
kmail.call(QStringLiteral("showMail"), mId);
} else {
qCWarning(NEWMAILNOTIFIER_LOG) << "Impossible to access to DBus interface";
// start the kmail application if it isn't running yet
const auto service = KService::serviceByDesktopName(QStringLiteral("org.kde.kmail2"));
if (!service) {
qCDebug(NEWMAILNOTIFIER_LOG) << " Can not start kmail";
setError(UserDefinedError);
setErrorText(i18n("Unable to start KMail application."));
emitResult();
return;
}
emitResult();
auto job = new KIO::ApplicationLauncherJob(service, this);
connect(job, &KJob::finished, this, [this]() {
const QString kmailInterface = QStringLiteral("org.kde.kmail");
QDBusInterface kmail(kmailInterface, QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail"));
if (kmail.isValid()) {
kmail.call(QStringLiteral("showMail"), mId);
} else {
qCWarning(NEWMAILNOTIFIER_LOG) << "Impossible to access to DBus interface";
}
emitResult();
});
job->start();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment