From 5431073844a694f9186d7fc4f540b96e4b0a6e24 Mon Sep 17 00:00:00 2001 From: Weixuan Xiao Date: Sun, 9 Jun 2019 15:28:49 +0000 Subject: [PATCH] Add wrapper for macos dbus connection --- cli/CMakeLists.txt | 1 + cli/kdeconnect-cli.cpp | 21 +++++----- core/CMakeLists.txt | 4 ++ core/daemon.cpp | 6 +-- core/dbushelper.cpp | 11 +++++- core/{dbushelper.h => dbushelper.h.in} | 6 +++ core/device.cpp | 8 ++-- core/kdeconnectpluginconfig.cpp | 8 ++-- daemon/kdeconnectd.cpp | 7 +++- fileitemactionplugin/CMakeLists.txt | 1 + fileitemactionplugin/sendfileitemaction.cpp | 4 +- indicator/CMakeLists.txt | 2 +- indicator/deviceindicator.cpp | 4 +- indicator/main.cpp | 4 ++ interfaces/CMakeLists.txt | 3 +- interfaces/dbusinterfaces.cpp | 39 ++++++++++--------- interfaces/devicesmodel.cpp | 3 +- interfaces/notificationsmodel.cpp | 4 +- interfaces/remotecommandsmodel.cpp | 4 +- interfaces/remotesinksmodel.cpp | 4 +- plugins/lockdevice/lockdeviceplugin.cpp | 4 +- plugins/mpriscontrol/mpriscontrolplugin.cpp | 10 ++--- .../notificationsdbusinterface.cpp | 7 ++-- plugins/pausemusic/pausemusicplugin.cpp | 5 ++- plugins/runcommand/runcommand_config.cpp | 2 +- .../notificationslistener.cpp | 9 +++-- urlhandler/CMakeLists.txt | 1 + urlhandler/kdeconnect-handler.cpp | 5 ++- 28 files changed, 115 insertions(+), 72 deletions(-) rename core/{dbushelper.h => dbushelper.h.in} (83%) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 8b0270f28..23a97aa4b 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -7,6 +7,7 @@ target_include_directories(kdeconnect-cli PUBLIC ${CMAKE_BINARY_DIR}) target_link_libraries(kdeconnect-cli kdeconnectinterfaces + kdeconnectcore KF5::CoreAddons KF5::I18n ) diff --git a/cli/kdeconnect-cli.cpp b/cli/kdeconnect-cli.cpp index 82641f9ca..7c44ca496 100644 --- a/cli/kdeconnect-cli.cpp +++ b/cli/kdeconnect-cli.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,8 @@ #include "interfaces/dbushelpers.h" #include "kdeconnect-version.h" +#include + int main(int argc, char** argv) { QCoreApplication app(argc, argv); @@ -166,7 +167,7 @@ int main(int argc, char** argv) } } else if(parser.isSet(QStringLiteral("refresh"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), QStringLiteral("/modules/kdeconnect"), QStringLiteral("org.kde.kdeconnect.daemon"), QStringLiteral("forceOnNetworkChange")); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } else { QString device = parser.value(QStringLiteral("device")); @@ -199,7 +200,7 @@ int main(int argc, char** argv) QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrls")); msg.setArguments(QVariantList() << QVariant(urls)); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); for (const QString& url : qAsConst(urls)) { QTextStream(stdout) << i18n("Shared %1", url) << endl; @@ -207,7 +208,7 @@ int main(int argc, char** argv) } else if (parser.isSet(QStringLiteral("share-text"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareText")); msg.setArguments(QVariantList() << parser.value(QStringLiteral("share-text"))); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); QTextStream(stdout) << i18n("Shared text: %1", parser.value(QStringLiteral("share-text"))) << endl; } else if(parser.isSet(QStringLiteral("pair"))) { DeviceDbusInterface dev(device); @@ -250,22 +251,22 @@ int main(int argc, char** argv) QString message = parser.value(QStringLiteral("ping-msg")); msg.setArguments(QVariantList() << message); } - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } else if(parser.isSet(QStringLiteral("send-sms"))) { if (parser.isSet(QStringLiteral("destination"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/sms", QStringLiteral("org.kde.kdeconnect.device.sms"), QStringLiteral("sendSms")); msg.setArguments({ parser.value("destination"), parser.value("send-sms") }); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } else { QTextStream(stderr) << i18n("error: should specify the SMS's recipient by passing --destination "); return 1; } } else if(parser.isSet(QStringLiteral("ring"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/findmyphone", QStringLiteral("org.kde.kdeconnect.device.findmyphone"), QStringLiteral("ring")); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } else if(parser.isSet(QStringLiteral("photo"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/photo", QStringLiteral("org.kde.kdeconnect.device.photo"), QStringLiteral("requestPhoto")); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } else if(parser.isSet("send-keys")) { QString seq = parser.value("send-keys"); QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/remotekeyboard", "org.kde.kdeconnect.device.remotekeyboard", "sendKeyPress"); @@ -276,13 +277,13 @@ int main(int argc, char** argv) while (!in.atEnd()) { QByteArray line = in.readLine(); // sanitize to ASCII-codes > 31? msg.setArguments({QString(line), -1, false, false, false}); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } in.close(); } } else { msg.setArguments({seq, -1, false, false, false}); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); } } else if(parser.isSet(QStringLiteral("list-notifications"))) { NotificationsModel notifications; diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index df11254d5..1edf7e00d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -2,6 +2,10 @@ project(KDEConnectCore) add_definitions(-DTRANSLATION_DOMAIN=\"kdeconnect-core\") +set(KDECONNECT_PRIVATE_DBUS_ADDR unix:path=/tmp/kdeconnect-dbus) +set(KDECONNECT_PRIVATE_DBUS_NAME DBusKDEConnectOnly) +configure_file(dbushelper.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbushelper.h) + add_subdirectory(backends/lan) add_subdirectory(backends/loopback) diff --git a/core/daemon.cpp b/core/daemon.cpp index 3d631801b..1fdfe68a8 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -20,7 +20,6 @@ #include "daemon.h" -#include #include #include #include @@ -29,6 +28,7 @@ #include "core_debug.h" #include "kdeconnectconfig.h" #include "networkpacket.h" +#include "dbushelper.h" #include "notificationserverinfo.h" #ifdef KDECONNECT_BLUETOOTH @@ -108,8 +108,8 @@ void Daemon::init() //Register on DBus qDBusRegisterMetaType< QMap >(); - QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect")); - QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents); + DbusHelper::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect")); + DbusHelper::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents); NotificationServerInfo::instance().init(); diff --git a/core/dbushelper.cpp b/core/dbushelper.cpp index bd201e659..c319eb92e 100644 --- a/core/dbushelper.cpp +++ b/core/dbushelper.cpp @@ -20,8 +20,6 @@ #include "dbushelper.h" -#include - namespace DbusHelper { void filterNonExportableCharacters(QString& s) @@ -30,4 +28,13 @@ void filterNonExportableCharacters(QString& s) s.replace(regexp,QLatin1String("_")); } +QDBusConnection sessionBus() +{ +#ifdef Q_OS_MAC + return QDBusConnection::connectToBus(QStringLiteral(KDECONNECT_PRIVATE_DBUS_ADDR), QStringLiteral(KDECONNECT_PRIVATE_DBUS_NAME)); +#else + return QDBusConnection::sessionBus(); +#endif +} + } diff --git a/core/dbushelper.h b/core/dbushelper.h.in similarity index 83% rename from core/dbushelper.h rename to core/dbushelper.h.in index 34f9004d7..9b8775fbd 100644 --- a/core/dbushelper.h +++ b/core/dbushelper.h.in @@ -21,11 +21,17 @@ #ifndef KDECONNECT_DBUSHELPER_H #define KDECONNECT_DBUSHELPER_H #include +#include #include "kdeconnectcore_export.h" +#define KDECONNECT_PRIVATE_DBUS_ADDR "${KDECONNECT_PRIVATE_DBUS_ADDR}" +#define KDECONNECT_PRIVATE_DBUS_NAME "${KDECONNECT_PRIVATE_DBUS_NAME}" + namespace DbusHelper { void KDECONNECTCORE_EXPORT filterNonExportableCharacters(QString& s); + + QDBusConnection KDECONNECTCORE_EXPORT sessionBus(); } #endif diff --git a/core/device.cpp b/core/device.cpp index afdbf2a9a..c745d0c7d 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -20,7 +20,6 @@ #include "device.h" -#include #include #include #include @@ -38,6 +37,7 @@ #include "networkpacket.h" #include "kdeconnectconfig.h" #include "daemon.h" +#include "dbushelper.h" //In older Qt released, qAsConst isnt available #include "qtcompat_p.h" @@ -87,7 +87,7 @@ Device::Device(QObject* parent, const QString& id) d->m_deviceType = str2type(info.deviceType); //Register in bus - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); + DbusHelper::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); //Assume every plugin is supported until addLink is called and we can get the actual list d->m_allPlugins = PluginLoader::instance()->getPluginList().toSet(); @@ -106,7 +106,7 @@ Device::Device(QObject* parent, const NetworkPacket& identityPacket, DeviceLink* addLink(identityPacket, dl); //Register in bus - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); + DbusHelper::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); connect(this, &Device::pairingError, this, &warn); } @@ -196,7 +196,7 @@ void Device::reloadPlugins() d->m_plugins = newPluginMap; d->m_pluginsByIncomingCapability = newPluginsByIncomingCapability; - QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusConnection bus = DbusHelper::sessionBus(); for (KdeConnectPlugin* plugin : qAsConst(d->m_plugins)) { //TODO: see how it works in Android (only done once, when created) plugin->connected(); diff --git a/core/kdeconnectpluginconfig.cpp b/core/kdeconnectpluginconfig.cpp index 60be9eeb4..271925306 100644 --- a/core/kdeconnectpluginconfig.cpp +++ b/core/kdeconnectpluginconfig.cpp @@ -23,9 +23,9 @@ #include #include #include -#include #include "kdeconnectconfig.h" +#include "dbushelper.h" struct KdeConnectPluginConfigPrivate { @@ -43,7 +43,7 @@ KdeConnectPluginConfig::KdeConnectPluginConfig(const QString& deviceId, const QS d->m_config = new QSettings(d->m_configDir.absoluteFilePath(QStringLiteral("config")), QSettings::IniFormat); d->m_signal = QDBusMessage::createSignal("/kdeconnect/"+deviceId+"/"+pluginName, QStringLiteral("org.kde.kdeconnect.config"), QStringLiteral("configChanged")); - QDBusConnection::sessionBus().connect(QLatin1String(""), "/kdeconnect/"+deviceId+"/"+pluginName, QStringLiteral("org.kde.kdeconnect.config"), QStringLiteral("configChanged"), this, SLOT(slotConfigChanged())); + DbusHelper::sessionBus().connect(QLatin1String(""), "/kdeconnect/"+deviceId+"/"+pluginName, QStringLiteral("org.kde.kdeconnect.config"), QStringLiteral("configChanged"), this, SLOT(slotConfigChanged())); } KdeConnectPluginConfig::~KdeConnectPluginConfig() @@ -79,7 +79,7 @@ void KdeConnectPluginConfig::set(const QString& key, const QVariant& value) { d->m_config->setValue(key, value); d->m_config->sync(); - QDBusConnection::sessionBus().send(d->m_signal); + DbusHelper::sessionBus().send(d->m_signal); } void KdeConnectPluginConfig::setList(const QString& key, const QVariantList& list) @@ -91,7 +91,7 @@ void KdeConnectPluginConfig::setList(const QString& key, const QVariantList& lis } d->m_config->endArray(); d->m_config->sync(); - QDBusConnection::sessionBus().send(d->m_signal); + DbusHelper::sessionBus().send(d->m_signal); } void KdeConnectPluginConfig::slotConfigChanged() diff --git a/daemon/kdeconnectd.cpp b/daemon/kdeconnectd.cpp index 62887097e..43ba66189 100644 --- a/daemon/kdeconnectd.cpp +++ b/daemon/kdeconnectd.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -34,6 +33,8 @@ #include #include +#include + #include "core/daemon.h" #include "core/device.h" #include "core/backends/pairinghandler.h" @@ -122,10 +123,12 @@ int main(int argc, char* argv[]) QStringLiteral("/MainApplication"), QStringLiteral("org.qtproject.Qt.QCoreApplication"), QStringLiteral("quit")); - QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits + DbusHelper::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits } +#ifndef Q_OS_MAC KDBusService dbusService(KDBusService::Unique); +#endif DesktopDaemon daemon; diff --git a/fileitemactionplugin/CMakeLists.txt b/fileitemactionplugin/CMakeLists.txt index d4af2952c..550d67a8b 100644 --- a/fileitemactionplugin/CMakeLists.txt +++ b/fileitemactionplugin/CMakeLists.txt @@ -6,6 +6,7 @@ target_link_libraries(kdeconnectfileitemaction KF5::KIOWidgets KF5::I18n kdeconnectinterfaces + kdeconnectcore ) install(TARGETS kdeconnectfileitemaction DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES kdeconnectsendfile.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/fileitemactionplugin/sendfileitemaction.cpp b/fileitemactionplugin/sendfileitemaction.cpp index 4b2136187..68c176109 100644 --- a/fileitemactionplugin/sendfileitemaction.cpp +++ b/fileitemactionplugin/sendfileitemaction.cpp @@ -35,6 +35,8 @@ #include #include +#include + K_PLUGIN_FACTORY(SendFileItemActionFactory, registerPlugin();) Q_LOGGING_CATEGORY(KDECONNECT_FILEITEMACTION, "kdeconnect.fileitemaction") @@ -92,7 +94,7 @@ void SendFileItemAction::sendFile() for (const QUrl& url : urls) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+id+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); msg.setArguments(QVariantList() << url.toString()); - QDBusConnection::sessionBus().call(msg); + DbusHelper::sessionBus().call(msg); } } diff --git a/indicator/CMakeLists.txt b/indicator/CMakeLists.txt index 5847ba7e5..1c4a4de5d 100644 --- a/indicator/CMakeLists.txt +++ b/indicator/CMakeLists.txt @@ -16,7 +16,7 @@ ecm_add_app_icon(indicator_SRCS ICONS add_executable(kdeconnect-indicator ${indicator_SRCS}) target_include_directories(kdeconnect-indicator PUBLIC ${CMAKE_BINARY_DIR}) -target_link_libraries(kdeconnect-indicator Qt5::Widgets KF5::CoreAddons KF5::I18n KF5::Notifications KF5::DBusAddons KF5::KCMUtils kdeconnectinterfaces) +target_link_libraries(kdeconnect-indicator Qt5::Widgets KF5::CoreAddons KF5::I18n KF5::Notifications KF5::DBusAddons KF5::KCMUtils kdeconnectinterfaces kdeconnectcore) install(TARGETS kdeconnect-indicator ${INSTALL_TARGETS_DEFAULT_ARGS}) install(PROGRAMS org.kde.kdeconnect.nonplasma.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) diff --git a/indicator/deviceindicator.cpp b/indicator/deviceindicator.cpp index 38bfadb6d..d2463d9b7 100644 --- a/indicator/deviceindicator.cpp +++ b/indicator/deviceindicator.cpp @@ -24,6 +24,8 @@ #include "interfaces/dbusinterfaces.h" +#include + class BatteryAction : public QAction { Q_OBJECT @@ -105,7 +107,7 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device) QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device->id()+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); msg.setArguments(QVariantList() << url.toString()); - QDBusConnection::sessionBus().call(msg); + DbusHelper::sessionBus().call(msg); }); setWhenAvailable(device->hasPlugin("kdeconnect_share"), [sendFile](bool available) { sendFile->setVisible(available); }, this); } diff --git a/indicator/main.cpp b/indicator/main.cpp index 703ce3c33..0cd95db1f 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -37,6 +37,8 @@ #include "kdeconnect-version.h" #include "deviceindicator.h" +#include + int main(int argc, char** argv) { QApplication app(argc, argv); @@ -52,7 +54,9 @@ int main(int argc, char** argv) QProcess::startDetached("kdeconnectd.exe"); #endif +#ifndef Q_OS_MAC KDBusService dbusService(KDBusService::Unique); +#endif DevicesModel model; model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired); diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index ab642b311..23fc030ae 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -64,7 +64,7 @@ set_target_properties(kdeconnectinterfaces PROPERTIES generate_export_header(kdeconnectinterfaces EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectinterfaces_export.h BASE_NAME KDEConnectInterfaces) -target_include_directories(kdeconnectinterfaces PUBLIC ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(kdeconnectinterfaces PUBLIC ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}) target_link_libraries(kdeconnectinterfaces LINK_PUBLIC @@ -73,6 +73,7 @@ LINK_PUBLIC LINK_PRIVATE KF5::ConfigCore KF5::I18n + kdeconnectcore ) configure_file(KDEConnectConfig.cmake.in ${CMAKE_BINARY_DIR}/interfaces/KDEConnectConfig.cmake @ONLY) diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp index a13d460b4..31e9c21c9 100644 --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -19,18 +19,19 @@ */ #include "dbusinterfaces.h" +#include QString DaemonDbusInterface::activatedService() { static const QString service = QStringLiteral("org.kde.kdeconnect"); - auto reply = QDBusConnection::sessionBus().interface()->startService(service); + auto reply = DbusHelper::sessionBus().interface()->startService(service); if (!reply.isValid()) { - qWarning() << "error activating kdeconnectd:" << QDBusConnection::sessionBus().interface()->lastError(); + qWarning() << "error activating kdeconnectd:" << DbusHelper::sessionBus().interface()->lastError(); } return service; } DaemonDbusInterface::DaemonDbusInterface(QObject* parent) - : OrgKdeKdeconnectDaemonInterface(DaemonDbusInterface::activatedService(), QStringLiteral("/modules/kdeconnect"), QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDaemonInterface(DaemonDbusInterface::activatedService(), QStringLiteral("/modules/kdeconnect"), DbusHelper::sessionBus(), parent) { connect(this, &OrgKdeKdeconnectDaemonInterface::pairingRequestsChanged, this, &DaemonDbusInterface::pairingRequestsChangedProxy); } @@ -41,7 +42,7 @@ DaemonDbusInterface::~DaemonDbusInterface() } DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, DbusHelper::sessionBus(), parent) , m_id(id) { connect(this, &OrgKdeKdeconnectDeviceInterface::trustedChanged, this, &DeviceDbusInterface::trustedChangedProxy); @@ -63,11 +64,11 @@ QString DeviceDbusInterface::id() const void DeviceDbusInterface::pluginCall(const QString& plugin, const QString& method) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+id()+'/'+plugin, "org.kde.kdeconnect.device."+plugin, method); - QDBusConnection::sessionBus().asyncCall(msg); + DbusHelper::sessionBus().asyncCall(msg); } DeviceBatteryDbusInterface::DeviceBatteryDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceBatteryInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceBatteryInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, DbusHelper::sessionBus(), parent) { } @@ -78,7 +79,7 @@ DeviceBatteryDbusInterface::~DeviceBatteryDbusInterface() } DeviceNotificationsDbusInterface::DeviceNotificationsDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceNotificationsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceNotificationsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, DbusHelper::sessionBus(), parent) { } @@ -89,7 +90,7 @@ DeviceNotificationsDbusInterface::~DeviceNotificationsDbusInterface() } NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent) - : OrgKdeKdeconnectDeviceNotificationsNotificationInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceNotificationsNotificationInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, DbusHelper::sessionBus(), parent) , id(notificationId) { @@ -101,7 +102,7 @@ NotificationDbusInterface::~NotificationDbusInterface() } DeviceConversationsDbusInterface::DeviceConversationsDbusInterface(const QString& deviceId, QObject* parent) - : OrgKdeKdeconnectDeviceConversationsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+deviceId, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceConversationsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+deviceId, DbusHelper::sessionBus(), parent) { } @@ -112,7 +113,7 @@ DeviceConversationsDbusInterface::~DeviceConversationsDbusInterface() } SftpDbusInterface::SftpDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceSftpInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceSftpInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/sftp", DbusHelper::sessionBus(), parent) { } @@ -123,7 +124,7 @@ SftpDbusInterface::~SftpDbusInterface() } MprisDbusInterface::MprisDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceMprisremoteInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/mprisremote", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceMprisremoteInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/mprisremote", DbusHelper::sessionBus(), parent) { connect(this, &OrgKdeKdeconnectDeviceMprisremoteInterface::propertiesChanged, this, &MprisDbusInterface::propertiesChangedProxy); } @@ -133,7 +134,7 @@ MprisDbusInterface::~MprisDbusInterface() } RemoteControlDbusInterface::RemoteControlDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceRemotecontrolInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/remotecontrol", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceRemotecontrolInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/remotecontrol", DbusHelper::sessionBus(), parent) { } @@ -142,7 +143,7 @@ RemoteControlDbusInterface::~RemoteControlDbusInterface() } LockDeviceDbusInterface::LockDeviceDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceLockdeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/lockdevice", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceLockdeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/lockdevice", DbusHelper::sessionBus(), parent) { connect(this, &OrgKdeKdeconnectDeviceLockdeviceInterface::lockedChanged, this, &LockDeviceDbusInterface::lockedChangedProxy); Q_ASSERT(isValid()); @@ -153,7 +154,7 @@ LockDeviceDbusInterface::~LockDeviceDbusInterface() } FindMyPhoneDeviceDbusInterface::FindMyPhoneDeviceDbusInterface(const QString& deviceId, QObject* parent): - OrgKdeKdeconnectDeviceFindmyphoneInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/findmyphone", QDBusConnection::sessionBus(), parent) + OrgKdeKdeconnectDeviceFindmyphoneInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/findmyphone", DbusHelper::sessionBus(), parent) { } @@ -162,14 +163,14 @@ FindMyPhoneDeviceDbusInterface::~FindMyPhoneDeviceDbusInterface() } RemoteCommandsDbusInterface::RemoteCommandsDbusInterface(const QString& deviceId, QObject* parent): - OrgKdeKdeconnectDeviceRemotecommandsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotecommands", QDBusConnection::sessionBus(), parent) + OrgKdeKdeconnectDeviceRemotecommandsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotecommands", DbusHelper::sessionBus(), parent) { } RemoteCommandsDbusInterface::~RemoteCommandsDbusInterface() = default; RemoteKeyboardDbusInterface::RemoteKeyboardDbusInterface(const QString& deviceId, QObject* parent): - OrgKdeKdeconnectDeviceRemotekeyboardInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotekeyboard", QDBusConnection::sessionBus(), parent) + OrgKdeKdeconnectDeviceRemotekeyboardInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotekeyboard", DbusHelper::sessionBus(), parent) { connect(this, &OrgKdeKdeconnectDeviceRemotekeyboardInterface::remoteStateChanged, this, &RemoteKeyboardDbusInterface::remoteStateChanged); } @@ -177,20 +178,20 @@ RemoteKeyboardDbusInterface::RemoteKeyboardDbusInterface(const QString& deviceId RemoteKeyboardDbusInterface::~RemoteKeyboardDbusInterface() = default; SmsDbusInterface::SmsDbusInterface(const QString& deviceId, QObject* parent): - OrgKdeKdeconnectDeviceSmsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/sms", QDBusConnection::sessionBus(), parent) + OrgKdeKdeconnectDeviceSmsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/sms", DbusHelper::sessionBus(), parent) { } SmsDbusInterface::~SmsDbusInterface() = default; ShareDbusInterface::ShareDbusInterface(const QString& deviceId, QObject* parent): - OrgKdeKdeconnectDeviceShareInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/share", QDBusConnection::sessionBus(), parent) + OrgKdeKdeconnectDeviceShareInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/share", DbusHelper::sessionBus(), parent) { } ShareDbusInterface::~ShareDbusInterface() = default; RemoteSystemVolumeDbusInterface::RemoteSystemVolumeDbusInterface(const QString& deviceId, QObject* parent): - OrgKdeKdeconnectDeviceRemotesystemvolumeInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotesystemvolume", QDBusConnection::sessionBus(), parent) + OrgKdeKdeconnectDeviceRemotesystemvolumeInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotesystemvolume", DbusHelper::sessionBus(), parent) { } diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index 58ebce636..25f2bc495 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -30,6 +30,7 @@ #include #include "dbusinterfaces.h" +#include // #include "modeltest.h" Q_LOGGING_CATEGORY(KDECONNECT_INTERFACES, "kdeconnect.interfaces"); @@ -59,7 +60,7 @@ DevicesModel::DevicesModel(QObject* parent) this, &DevicesModel::deviceRemoved); QDBusServiceWatcher* watcher = new QDBusServiceWatcher(DaemonDbusInterface::activatedService(), - QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + DbusHelper::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &DevicesModel::refreshDeviceList); connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &DevicesModel::clearDevices); diff --git a/interfaces/notificationsmodel.cpp b/interfaces/notificationsmodel.cpp index 2237d1eda..c690297ec 100644 --- a/interfaces/notificationsmodel.cpp +++ b/interfaces/notificationsmodel.cpp @@ -26,6 +26,8 @@ #include +#include + //#include "modeltest.h" //In older Qt released, qAsConst isnt available @@ -49,7 +51,7 @@ NotificationsModel::NotificationsModel(QObject* parent) this, &NotificationsModel::anyDismissableChanged); QDBusServiceWatcher* watcher = new QDBusServiceWatcher(DaemonDbusInterface::activatedService(), - QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + DbusHelper::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &NotificationsModel::refreshNotificationList); connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &NotificationsModel::clearNotifications); } diff --git a/interfaces/remotecommandsmodel.cpp b/interfaces/remotecommandsmodel.cpp index b667e5ef3..f53252477 100644 --- a/interfaces/remotecommandsmodel.cpp +++ b/interfaces/remotecommandsmodel.cpp @@ -24,6 +24,8 @@ #include #include +#include + RemoteCommandsModel::RemoteCommandsModel(QObject* parent) : QAbstractListModel(parent) , m_dbusInterface(nullptr) @@ -35,7 +37,7 @@ RemoteCommandsModel::RemoteCommandsModel(QObject* parent) this, &RemoteCommandsModel::rowsChanged); QDBusServiceWatcher* watcher = new QDBusServiceWatcher(DaemonDbusInterface::activatedService(), - QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + DbusHelper::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &RemoteCommandsModel::refreshCommandList); connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &RemoteCommandsModel::clearCommands); } diff --git a/interfaces/remotesinksmodel.cpp b/interfaces/remotesinksmodel.cpp index 1005fd9c1..8932ac65f 100644 --- a/interfaces/remotesinksmodel.cpp +++ b/interfaces/remotesinksmodel.cpp @@ -24,6 +24,8 @@ #include #include +#include + RemoteSinksModel::RemoteSinksModel(QObject* parent) : QAbstractListModel(parent) , m_dbusInterface(nullptr) @@ -35,7 +37,7 @@ RemoteSinksModel::RemoteSinksModel(QObject* parent) this, &RemoteSinksModel::rowsChanged); QDBusServiceWatcher* watcher = new QDBusServiceWatcher(DaemonDbusInterface::activatedService(), - QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + DbusHelper::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &RemoteSinksModel::refreshSinkList); connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &RemoteSinksModel::refreshSinkList); } diff --git a/plugins/lockdevice/lockdeviceplugin.cpp b/plugins/lockdevice/lockdeviceplugin.cpp index 67473f64b..efafb151e 100644 --- a/plugins/lockdevice/lockdeviceplugin.cpp +++ b/plugins/lockdevice/lockdeviceplugin.cpp @@ -24,11 +24,11 @@ #include #include -#include #include #include "screensaverdbusinterface.h" #include +#include K_PLUGIN_FACTORY_WITH_JSON( KdeConnectLockPluginFactory, "kdeconnect_lockdevice.json", registerPlugin(); ) @@ -82,7 +82,7 @@ bool LockDevicePlugin::receivePacket(const NetworkPacket & np) OrgFreedesktopScreenSaverInterface* LockDevicePlugin::iface() { if (!m_iface) { - m_iface = new OrgFreedesktopScreenSaverInterface(QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("/org/freedesktop/ScreenSaver"), QDBusConnection::sessionBus()); + m_iface = new OrgFreedesktopScreenSaverInterface(QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("/org/freedesktop/ScreenSaver"), DbusHelper::sessionBus()); if(!m_iface->isValid()) qCWarning(KDECONNECT_PLUGIN_LOCKREMOTE) << "Couldn't connect to the ScreenSaver interface"; } diff --git a/plugins/mpriscontrol/mpriscontrolplugin.cpp b/plugins/mpriscontrol/mpriscontrolplugin.cpp index 2bf05df54..c8603f908 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin.cpp @@ -21,7 +21,6 @@ #include "mpriscontrolplugin.h" #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include +#include #include "mprisdbusinterface.h" #include "propertiesdbusinterface.h" @@ -52,13 +52,13 @@ MprisControlPlugin::MprisControlPlugin(QObject* parent, const QVariantList& args : KdeConnectPlugin(parent, args) , prevVolume(-1) { - m_watcher = new QDBusServiceWatcher(QString(), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + m_watcher = new QDBusServiceWatcher(QString(), DbusHelper::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); // TODO: QDBusConnectionInterface::serviceOwnerChanged is deprecated, maybe query org.freedesktop.DBus directly? - connect(QDBusConnection::sessionBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, this, &MprisControlPlugin::serviceOwnerChanged); + connect(DbusHelper::sessionBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, this, &MprisControlPlugin::serviceOwnerChanged); //Add existing interfaces - const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + const QStringList services = DbusHelper::sessionBus().interface()->registeredServiceNames().value(); for (const QString& service : services) { // The string doesn't matter, it just needs to be empty/non-empty serviceOwnerChanged(service, QLatin1String(""), QStringLiteral("1")); @@ -100,7 +100,7 @@ void MprisControlPlugin::addPlayer(const QString& service) uniqueName = identity + QLatin1String(" [") + QString::number(i) + QLatin1Char(']'); } - MprisPlayer player(service, mediaPlayerObjectPath, QDBusConnection::sessionBus()); + MprisPlayer player(service, mediaPlayerObjectPath, DbusHelper::sessionBus()); playerList.insert(uniqueName, player); diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp index 9b9e1c617..f28d749f2 100644 --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -22,10 +22,9 @@ #include "notification_debug.h" #include "notification.h" -#include - #include #include +#include #include "notificationsplugin.h" #include "sendreplydialog.h" @@ -119,7 +118,7 @@ void NotificationsDbusInterface::addNotification(Notification* noti) m_notifications[publicId] = noti; m_internalIdToPublicId[internalId] = publicId; - QDBusConnection::sessionBus().registerObject(m_device->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); + DbusHelper::sessionBus().registerObject(m_device->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); Q_EMIT notificationPosted(publicId); } @@ -141,7 +140,7 @@ void NotificationsDbusInterface::removeNotification(const QString& internalId) } //Deleting the notification will unregister it automatically - //QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); + //DbusHelper::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); noti->deleteLater(); Q_EMIT notificationRemoved(publicId); diff --git a/plugins/pausemusic/pausemusicplugin.cpp b/plugins/pausemusic/pausemusicplugin.cpp index 7aa13b0e3..0e8c27172 100644 --- a/plugins/pausemusic/pausemusicplugin.cpp +++ b/plugins/pausemusic/pausemusicplugin.cpp @@ -20,7 +20,6 @@ #include "pausemusicplugin.h" -#include #include #include #include @@ -30,6 +29,8 @@ #include #include +#include + //In older Qt released, qAsConst isnt available #include "qtcompat_p.h" @@ -76,7 +77,7 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) if (pause) { //Search for interfaces currently playing - const QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + const QStringList interfaces = DbusHelper::sessionBus().interface()->registeredServiceNames().value(); for (const QString& iface : interfaces) { if (iface.startsWith(QLatin1String("org.mpris.MediaPlayer2"))) { QDBusInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.mpris.MediaPlayer2.Player")); diff --git a/plugins/runcommand/runcommand_config.cpp b/plugins/runcommand/runcommand_config.cpp index 8e1c8fab8..c48a7c9b9 100644 --- a/plugins/runcommand/runcommand_config.cpp +++ b/plugins/runcommand/runcommand_config.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin();) diff --git a/plugins/sendnotifications/notificationslistener.cpp b/plugins/sendnotifications/notificationslistener.cpp index be337a1ed..b954c6ddb 100644 --- a/plugins/sendnotifications/notificationslistener.cpp +++ b/plugins/sendnotifications/notificationslistener.cpp @@ -19,7 +19,6 @@ */ #include "notificationslistener.h" -#include #include #include #include @@ -34,6 +33,8 @@ #include #include +#include + #include "sendnotificationsplugin.h" #include "sendnotification_debug.h" #include "notifyingapplication.h" @@ -47,7 +48,7 @@ NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin) { qRegisterMetaTypeStreamOperators("NotifyingApplication"); - bool ret = QDBusConnection::sessionBus() + bool ret = DbusHelper::sessionBus() .registerObject(QStringLiteral("/org/freedesktop/Notifications"), this, QDBusConnection::ExportScriptableContents); @@ -55,7 +56,7 @@ NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin) qCWarning(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Error registering notifications listener for device" << m_plugin->device()->name() << ":" - << QDBusConnection::sessionBus().lastError(); + << DbusHelper::sessionBus().lastError(); else qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Registered notifications listener for device" @@ -79,7 +80,7 @@ NotificationsListener::~NotificationsListener() QStringLiteral("org.freedesktop.DBus")); QDBusMessage res = iface.call(QStringLiteral("RemoveMatch"), "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'"); - QDBusConnection::sessionBus().unregisterObject(QStringLiteral("/org/freedesktop/Notifications")); + DbusHelper::sessionBus().unregisterObject(QStringLiteral("/org/freedesktop/Notifications")); } void NotificationsListener::setTranslatedAppName() diff --git a/urlhandler/CMakeLists.txt b/urlhandler/CMakeLists.txt index 6009d3834..df9707007 100644 --- a/urlhandler/CMakeLists.txt +++ b/urlhandler/CMakeLists.txt @@ -6,6 +6,7 @@ target_include_directories(kdeconnect-handler PUBLIC ${CMAKE_BINARY_DIR}) target_link_libraries(kdeconnect-handler kdeconnectinterfaces + kdeconnectcore Qt5::Widgets KF5::CoreAddons KF5::I18n diff --git a/urlhandler/kdeconnect-handler.cpp b/urlhandler/kdeconnect-handler.cpp index 0682430ec..2aec828f1 100644 --- a/urlhandler/kdeconnect-handler.cpp +++ b/urlhandler/kdeconnect-handler.cpp @@ -25,11 +25,12 @@ #include #include #include -#include #include #include +#include + #include #include #include @@ -118,7 +119,7 @@ int main(int argc, char** argv) QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), action); msg.setArguments({ url.toString() }); - blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + blockOnReply(DbusHelper::sessionBus().asyncCall(msg)); return 0; } else { QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl;