Commit d7922985 authored by Konrad Materka's avatar Konrad Materka Committed by David Edmundson
Browse files

[applets/systemtray] Replace obsolete serviceOwnerChanged

QDBusConnectionInterface::serviceOwnerChanged is obsolete. It was used
because there was no support for watchin on serviwes usign wildcard.
Starting from Qt 5.14 it is possible, so that using obsolete function is
no longer necessary.
parent cfa9ee29
......@@ -25,6 +25,7 @@
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusPendingCallWatcher>
#include <QDBusServiceWatcher>
#include <QMenu>
#include <QQuickItem>
#include <QQuickWindow>
......@@ -46,10 +47,15 @@ SystemTray::SystemTray(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args),
m_systemTrayModel(nullptr),
m_sortedSystemTrayModel(nullptr),
m_configSystemTrayModel(nullptr)
m_configSystemTrayModel(nullptr),
m_sessionServiceWatcher(new QDBusServiceWatcher(this)),
m_systemServiceWatcher(new QDBusServiceWatcher(this))
{
setHasConfigurationInterface(true);
setContainmentType(Plasma::Types::CustomEmbeddedContainment);
m_sessionServiceWatcher->setConnection(QDBusConnection::sessionBus());
m_systemServiceWatcher->setConnection(QDBusConnection::systemBus());
}
SystemTray::~SystemTray()
......@@ -75,6 +81,10 @@ void SystemTray::init()
QRegExp rx(dbusactivation);
rx.setPatternSyntax(QRegExp::Wildcard);
m_dbusActivatableTasks[info.pluginId()] = rx;
const QString watchedService = QString(dbusactivation).replace(".*", "*");
m_sessionServiceWatcher->addWatchedService(watchedService);
m_systemServiceWatcher->addWatchedService(watchedService);
}
}
}
......@@ -480,45 +490,54 @@ void SystemTray::setAllowedPlasmoids(const QStringList &allowed)
emit allowedPlasmoidsChanged();
}
/* Loading and unloading Plasmoids when dbus services come and go
*
* This works as follows:
* - we collect a list of plugins and related services in m_dbusActivatableTasks
* - we query DBus for the list of services, async (initDBusActivatables())
* - we go over that list, adding tasks when a service and plugin match (serviceNameFetchFinished())
* - we start watching for new services, and do the same (serviceNameFetchFinished())
* - whenever a service is gone, we check whether to unload a Plasmoid (serviceUnregistered())
*
* Order of events has to be:
* - create a match rule for new service on DBus daemon
* - start fetching a list of names
* - ignore all changes that happen in the meantime
* - handle the list of all names
*/
void SystemTray::initDBusActivatables()
{
// Watch for new services
// We need to watch for all of new services here, since we want to "match" the names,
// not just compare them
// This makes mpris work, since it wants to match org.mpris.MediaPlayer2.dragonplayer
// against org.mpris.MediaPlayer2
// QDBusServiceWatcher is not capable for watching wildcard service right now
// See:
// https://bugreports.qt.io/browse/QTBUG-51683
// https://bugreports.qt.io/browse/QTBUG-33829
// This is fixed in Qt 5.15
// order of events has to be:
// - create a match rule for new servies on DBus daemon
// - start fetching a list of names
// - ignore all changes that happen in the meantime
// - handle the list of all names
connect(QDBusConnection::sessionBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, this, [=](const QString &serviceName, const QString &oldOwner, const QString &newOwner) {
connect(m_sessionServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this](const QString &serviceName)
{
if (!m_dbusSessionServiceNamesFetched) {
return;
}
serviceOwnerChanged(serviceName, oldOwner, newOwner);
serviceRegistered(serviceName);
});
connect(QDBusConnection::systemBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, this, [=](const QString &serviceName, const QString &oldOwner, const QString &newOwner) {
connect(m_sessionServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &serviceName)
{
if (!m_dbusSessionServiceNamesFetched) {
return;
}
serviceUnregistered(serviceName);
});
connect(m_systemServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this](const QString &serviceName)
{
if (!m_dbusSystemServiceNamesFetched) {
return;
}
serviceOwnerChanged(serviceName, oldOwner, newOwner);
serviceRegistered(serviceName);
});
/* Loading and unloading Plasmoids when dbus services come and go
*
* This works as follows:
* - we collect a list of plugins and related services in m_dbusActivatableTasks
* - we query DBus for the list of services, async (initDBusActivatables())
* - we go over that list, adding tasks when a service and plugin match (serviceNameFetchFinished())
* - we start watching for new services, and do the same (serviceNameFetchFinished())
* - whenever a service is gone, we check whether to unload a Plasmoid (serviceUnregistered())
*/
connect(m_systemServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &serviceName)
{
if (!m_dbusSystemServiceNamesFetched) {
return;
}
serviceUnregistered(serviceName);
});
// fetch list of existing services
QDBusPendingCall async = QDBusConnection::sessionBus().interface()->asyncCall(QStringLiteral("ListNames"));
QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(async, this);
connect(callWatcher, &QDBusPendingCallWatcher::finished, [=](QDBusPendingCallWatcher *callWatcher) {
......@@ -549,15 +568,6 @@ void SystemTray::serviceNameFetchFinished(QDBusPendingCallWatcher* watcher)
}
}
void SystemTray::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner)
{
if (oldOwner.isEmpty()) {
serviceRegistered(serviceName);
} else if (newOwner.isEmpty()) {
serviceUnregistered(serviceName);
}
}
void SystemTray::serviceRegistered(const QString &service)
{
if (service.startsWith(QLatin1Char(':'))) {
......
......@@ -27,7 +27,7 @@
#include <Plasma/Containment>
class QDBusPendingCallWatcher;
class QDBusConnection;
class QDBusServiceWatcher;
class QQuickItem;
namespace Plasma {
class Service;
......@@ -95,7 +95,6 @@ public:
private Q_SLOTS:
void serviceNameFetchFinished(QDBusPendingCallWatcher* watcher);
void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
private:
void serviceRegistered(const QString &service);
......@@ -119,6 +118,9 @@ private:
SortedSystemTrayModel *m_sortedSystemTrayModel;
SortedSystemTrayModel *m_configSystemTrayModel;
QHash<QString, int> m_knownPlugins;
QDBusServiceWatcher *m_sessionServiceWatcher;
QDBusServiceWatcher *m_systemServiceWatcher;
QHash<QString, int> m_dbusServiceCounts;
bool m_dbusSessionServiceNamesFetched = false;
bool m_dbusSystemServiceNamesFetched = false;
......
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