Branch data Line data Source code
1 : : #include "MailJDDbusService.h"
2 : : #include "app/MainWindow.h"
3 : :
4 : : #include <QDBusConnection>
5 : : #include <QDBusInterface>
6 : : #include <QLoggingCategory>
7 : :
8 [ + + + - : 5 : Q_LOGGING_CATEGORY(lcDbus, "mailjd.dbus")
+ - - - ]
9 : :
10 : : #ifdef MAILJD_KDE_INTEGRATION
11 : : #include <KDBusService>
12 : : #endif
13 : :
14 : : static const QString s_serviceName = QStringLiteral("de.jdsoft.mailjd");
15 : : static const QString s_objectPath = QStringLiteral("/de/jdsoft/mailjd");
16 : :
17 : : #ifdef MAILJD_KDE_INTEGRATION
18 : :
19 : : MailJDDbusService::MailJDDbusService(QObject *parent) : QObject(parent) {
20 : : m_kDBusService = new KDBusService(KDBusService::Unique, this);
21 : : connect(m_kDBusService, &KDBusService::activateRequested, this,
22 : : [this](const QStringList &, const QString &) { Activate(); });
23 : :
24 : : QDBusConnection::sessionBus().registerService(s_serviceName);
25 : : QDBusConnection::sessionBus().registerObject(s_objectPath, this,
26 : : QDBusConnection::ExportAllSlots);
27 : : qCInfo(lcDbus) << "D-Bus service registered (KDE + custom)";
28 : : }
29 : :
30 : : #else
31 : :
32 : 5 : MailJDDbusService::MailJDDbusService(QObject *parent) : QObject(parent) {
33 : : bool registered =
34 [ + - + - ]: 5 : QDBusConnection::sessionBus().registerService(s_serviceName);
35 [ - + ]: 5 : if (!registered) {
36 [ # # # # : 0 : qCInfo(lcDbus) << "Another MailJD instance is already running";
# # # # ]
37 : 0 : return;
38 : : }
39 [ + - + - ]: 5 : QDBusConnection::sessionBus().registerObject(s_objectPath, this,
40 : : QDBusConnection::ExportAllSlots);
41 [ + - + - : 10 : qCInfo(lcDbus) << "D-Bus service registered (freedesktop)";
+ - + + ]
42 : 0 : }
43 : :
44 : : #endif
45 : :
46 : 5 : MailJDDbusService::~MailJDDbusService() = default;
47 : :
48 : 3 : bool MailJDDbusService::isRunning() {
49 : : QDBusInterface iface(s_serviceName, s_objectPath, s_serviceName,
50 [ + - + - ]: 3 : QDBusConnection::sessionBus());
51 [ + - ]: 6 : return iface.isValid();
52 : 3 : }
53 : :
54 : 2 : bool MailJDDbusService::activateExisting() {
55 : : QDBusInterface iface(s_serviceName, s_objectPath, s_serviceName,
56 [ + - + - ]: 2 : QDBusConnection::sessionBus());
57 [ + - - + ]: 2 : if (!iface.isValid())
58 : 0 : return false;
59 [ + - ]: 2 : iface.call(QStringLiteral("Activate"));
60 : 2 : return true;
61 : 2 : }
62 : :
63 : 2 : bool MailJDDbusService::sendCheckMail() {
64 : : QDBusInterface iface(s_serviceName, s_objectPath, s_serviceName,
65 [ + - + - ]: 2 : QDBusConnection::sessionBus());
66 [ + - - + ]: 2 : if (!iface.isValid())
67 : 0 : return false;
68 [ + - ]: 2 : iface.call(QStringLiteral("CheckMail"));
69 : 2 : return true;
70 : 2 : }
71 : :
72 : 2 : bool MailJDDbusService::sendCompose() {
73 : : QDBusInterface iface(s_serviceName, s_objectPath, s_serviceName,
74 [ + - + - ]: 2 : QDBusConnection::sessionBus());
75 [ + - - + ]: 2 : if (!iface.isValid())
76 : 0 : return false;
77 [ + - ]: 2 : iface.call(QStringLiteral("Compose"));
78 : 2 : return true;
79 : 2 : }
80 : :
81 : 1 : bool MailJDDbusService::sendMailto(const QString &url) {
82 : : QDBusInterface iface(s_serviceName, s_objectPath, s_serviceName,
83 [ + - + - ]: 1 : QDBusConnection::sessionBus());
84 [ + - - + ]: 1 : if (!iface.isValid())
85 : 0 : return false;
86 [ + - ]: 1 : iface.call(QStringLiteral("ComposeMailto"), url);
87 : 1 : return true;
88 : 1 : }
89 : :
90 : 2 : void MailJDDbusService::setMainWindow(MainWindow *w) { m_mainWindow = w; }
91 : :
92 : 5 : void MailJDDbusService::Activate() {
93 : : // T-76.A3: unified foreground activation via MainWindow::bringToFront().
94 [ + + ]: 5 : if (m_mainWindow)
95 : 2 : m_mainWindow->bringToFront();
96 : 5 : }
97 : :
98 : 4 : void MailJDDbusService::CheckMail() {
99 [ + + ]: 4 : if (m_mainWindow)
100 : 2 : m_mainWindow->triggerPollNow();
101 : 4 : }
102 : :
103 : 4 : void MailJDDbusService::Compose() {
104 [ + + ]: 4 : if (m_mainWindow) {
105 : 2 : m_mainWindow->bringToFront();
106 : 2 : m_mainWindow->openComposeNew();
107 : : }
108 : 4 : }
109 : :
110 : 2 : void MailJDDbusService::ComposeMailto(const QString &url) {
111 [ + + + - : 2 : if (m_mainWindow && m_mainWindow->openMailtoUrl(url)) {
+ + ]
112 : 1 : m_mainWindow->bringToFront();
113 : : }
114 : 2 : }
|