Warning, file /pim/trojita/src/IPC/DBusInterface.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include <QDBusConnection> 0024 #include <QDBusConnectionInterface> 0025 #include <QDBusInterface> 0026 0027 #include "MainWindowBridge.h" 0028 0029 #include "IPC.h" 0030 0031 namespace IPC { 0032 0033 static QString path = QStringLiteral("/Trojita"); 0034 0035 QString service() 0036 { 0037 QString str = QStringLiteral("net.flaska.trojita"); 0038 QString profileName = QString::fromUtf8(qgetenv("TROJITA_PROFILE")); 0039 return profileName.isEmpty() ? str : str + QLatin1Char('-') + profileName; 0040 } 0041 0042 namespace Instance { 0043 0044 static QDBusInterface &interface() 0045 { 0046 static QDBusInterface iface(service(), path, QStringLiteral("net.flaska.trojita")); 0047 return iface; 0048 } 0049 0050 bool isRunning() 0051 { 0052 return QDBusConnection::sessionBus().isConnected() && 0053 QDBusConnection::sessionBus().interface()->isServiceRegistered(service()); 0054 } 0055 0056 void showMainWindow() 0057 { 0058 interface().call(QDBus::NoBlock, QStringLiteral("showMainWindow")); 0059 } 0060 0061 void showAddressbookWindow() 0062 { 0063 interface().call(QDBus::NoBlock, QStringLiteral("showAddressbookWindow")); 0064 } 0065 0066 void composeMail(const QString &url) 0067 { 0068 interface().call(QDBus::NoBlock, QStringLiteral("composeMail"), url); 0069 } 0070 0071 } //namespace Instance 0072 0073 bool registerInstance(Gui::MainWindow *window, QString &error) 0074 { 0075 QDBusConnection conn = QDBusConnection::sessionBus(); 0076 if (!conn.isConnected()) { 0077 error = conn.lastError().message(); 0078 return false; 0079 } 0080 0081 bool serviceOk = conn.registerService(service()); 0082 if (!serviceOk) { 0083 error = conn.lastError().message(); 0084 return false; 0085 } 0086 0087 MainWindowBridge *object = new MainWindowBridge(window); 0088 bool objectOk = conn.registerObject(path, object, QDBusConnection::ExportAllSlots); 0089 if (!objectOk) { 0090 error = conn.lastError().message(); 0091 delete object; 0092 conn.unregisterService(service()); 0093 return false; 0094 } 0095 0096 return true; 0097 } 0098 0099 } //namespace IPC