Commit 54310738 authored by Weixuan Xiao's avatar Weixuan Xiao

Add wrapper for macos dbus connection

parent af57aca5
Pipeline #4155 passed with stage
in 17 minutes and 40 seconds
......@@ -7,6 +7,7 @@ target_include_directories(kdeconnect-cli PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(kdeconnect-cli
kdeconnectinterfaces
kdeconnectcore
KF5::CoreAddons
KF5::I18n
)
......
......@@ -21,7 +21,6 @@
#include <QCryptographicHash>
#include <QIODevice>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QCoreApplication>
#include <QTextStream>
#include <QFile>
......@@ -34,6 +33,8 @@
#include "interfaces/dbushelpers.h"
#include "kdeconnect-version.h"
#include <dbushelper.h>
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 <phone number>");
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;
......
......@@ -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)
......
......@@ -20,7 +20,6 @@
#include "daemon.h"
#include <QDBusConnection>
#include <QDBusMetaType>
#include <QNetworkAccessManager>
#include <QDebug>
......@@ -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<QString,QString> >();
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();
......
......@@ -20,8 +20,6 @@
#include "dbushelper.h"
#include <QRegExp>
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
}
}
......@@ -21,11 +21,17 @@
#ifndef KDECONNECT_DBUSHELPER_H
#define KDECONNECT_DBUSHELPER_H
#include <QString>
#include <QDBusConnection>
#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
......@@ -20,7 +20,6 @@
#include "device.h"
#include <QDBusConnection>
#include <QVector>
#include <QSet>
#include <QSslCertificate>
......@@ -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();
......
......@@ -23,9 +23,9 @@
#include <QDir>
#include <QSettings>
#include <QDBusMessage>
#include <QDBusConnection>
#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()
......
......@@ -25,7 +25,6 @@
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QSessionManager>
#include <KAboutData>
......@@ -34,6 +33,8 @@
#include <KLocalizedString>
#include <KIO/AccessManager>
#include <dbushelper.h>
#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;
......
......@@ -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})
......@@ -35,6 +35,8 @@
#include <interfaces/devicesmodel.h>
#include <interfaces/dbusinterfaces.h>
#include <dbushelper.h>
K_PLUGIN_FACTORY(SendFileItemActionFactory, registerPlugin<SendFileItemAction>();)
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);
}
}
......
......@@ -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})
......@@ -24,6 +24,8 @@
#include "interfaces/dbusinterfaces.h"
#include <dbushelper.h>
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);
}
......
......@@ -37,6 +37,8 @@
#include "kdeconnect-version.h"
#include "deviceindicator.h"
#include <dbushelper.h>
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);
......
......@@ -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)
......
This diff is collapsed.
......@@ -30,6 +30,7 @@
#include <QDBusServiceWatcher>
#include "dbusinterfaces.h"
#include <dbushelper.h>
// #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);
......
......@@ -26,6 +26,8 @@
#include <QIcon>
#include <dbushelper.h>
//#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);
}
......
......@@ -24,6 +24,8 @@
#include <QDebug>
#include <QDBusInterface>
#include <dbushelper.h>
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);
}
......
......@@ -24,6 +24,8 @@
#include <QDebug>
#include <QDBusInterface>
#include <dbushelper.h>
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);
}
......
......@@ -24,11 +24,11 @@
#include <KPluginFactory>
#include <QDebug>
#include <QDBusConnection>
#include <QLoggingCategory>
#include "screensaverdbusinterface.h"
#include <core/device.h>
#include <dbushelper.h>
K_PLUGIN_FACTORY_WITH_JSON( KdeConnectLockPluginFactory, "kdeconnect_lockdevice.json", registerPlugin<LockDevicePlugin>(); )
......@@ -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";
}
......
......@@ -21,7 +21,6 @@
#include "mpriscontrolplugin.h"
#include <QDBusArgument>
#include <QDBusConnection>
#include <QDBusInterface>
#include <qdbusconnectioninterface.h>
#include <QDBusReply>
......@@ -31,6 +30,7 @@
#include <KPluginFactory>
#include <core/device.h>
#include <dbushelper.h>
#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);
......
......@@ -22,10 +22,9 @@
#include "notification_debug.h"
#include "notification.h"
#include <QDBusConnection>
#include <core/device.h>
#include <core/kdeconnectplugin.h>
#include <dbushelper.h>
#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);
......
......@@ -20,7 +20,6 @@
#include "pausemusicplugin.h"
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
......@@ -30,6 +29,8 @@
#include <PulseAudioQt/Context>
#include <PulseAudioQt/Sink>
#include <dbushelper.h>
//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"));
......
......@@ -33,7 +33,7 @@
#include <KLocalizedString>
#include <KPluginFactory>
#include <core/dbushelper.h>
#include <dbushelper.h>
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<RunCommandConfig>();)
......
......@@ -19,7 +19,6 @@
*/
#include "notificationslistener.h"
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusArgument>
#include <QtDebug>
......@@ -34,6 +33,8 @@
#include <core/device.h>
#include <core/kdeconnectplugin.h>
#include <dbushelper.h>
#include "sendnotificationsplugin.h"
#include "sendnotification_debug.h"
#include "notifyingapplication.h"
......@@ -47,7 +48,7 @@ NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin)
{
qRegisterMetaTypeStreamOperators<NotifyingApplication>("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()
......
......@@ -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
......
......@@ -25,11 +25,12 @@
#include <QTextStream>
#include <QUrl>
#include <QDBusMessage>
#include <QDBusConnection>
#include <KAboutData>
#include <KLocalizedString>
#include <dbushelper.h>
#include <interfaces/devicesmodel.h>
#include <interfaces/devicessortproxymodel.h>
#include <interfaces/dbusinterfaces.h>
......@@ -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;
......
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