File indexing completed on 2024-12-22 04:56:52
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "newmailnotifieropenfolderjob.h" 0007 #include "newmailnotifier_debug.h" 0008 0009 #include <KLocalizedString> 0010 0011 #include <QDBusConnection> 0012 #include <QDBusConnectionInterface> 0013 #include <QDBusInterface> 0014 #include <QDBusReply> 0015 0016 NewMailNotifierOpenFolderJob::NewMailNotifierOpenFolderJob(const QString &identifier, QObject *parent) 0017 : KJob{parent} 0018 , mIdentifer(identifier) 0019 { 0020 } 0021 0022 NewMailNotifierOpenFolderJob::~NewMailNotifierOpenFolderJob() = default; 0023 0024 void NewMailNotifierOpenFolderJob::start() 0025 { 0026 const qint64 identifier = mIdentifer.toLong(); 0027 if (identifier < 0) { 0028 emitResult(); 0029 return; 0030 } 0031 0032 const QString kmailInterface = QStringLiteral("org.kde.kmail"); 0033 auto startReply = QDBusConnection::sessionBus().interface()->startService(kmailInterface); 0034 if (!startReply.isValid()) { 0035 qCDebug(NEWMAILNOTIFIER_LOG) << "Can not start kmail"; 0036 setError(UserDefinedError); 0037 setErrorText(i18n("Unable to start KMail application.")); 0038 emitResult(); 0039 return; 0040 } 0041 0042 QDBusInterface kmail(kmailInterface, QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail")); 0043 if (kmail.isValid()) { 0044 kmail.call(QStringLiteral("selectFolder"), mIdentifer); 0045 } else { 0046 qCWarning(NEWMAILNOTIFIER_LOG) << "Impossible to access the DBus interface"; 0047 } 0048 0049 emitResult(); 0050 } 0051 0052 #include "moc_newmailnotifieropenfolderjob.cpp"