@@ -68,17 +68,29 @@ void StatusNotifierWatcher::onServiceUnregistered(const QString& service) {
6868 << " Active StatusNotifierWatcher unregistered, attempting registration" ;
6969 this ->tryRegister ();
7070 return ;
71- } else if (this ->items .removeAll (service) != 0 ) {
72- qCDebug (logStatusNotifierWatcher).noquote ()
73- << " Unregistered StatusNotifierItem" << service << " from watcher" ;
74- emit this ->StatusNotifierItemUnregistered (service);
75- } else if (this ->hosts .removeAll (service) != 0 ) {
76- qCDebug (logStatusNotifierWatcher).noquote ()
77- << " Unregistered StatusNotifierHost" << service << " from watcher" ;
78- emit this ->StatusNotifierHostUnregistered ();
71+ ;
7972 } else {
80- qCWarning (logStatusNotifierWatcher).noquote ()
81- << " Got service unregister event for untracked service" << service;
73+ QString qualifiedItem;
74+ this ->items .removeIf ([&](const QString& item) {
75+ if (item.startsWith (service)) {
76+ qualifiedItem = item;
77+ return true ;
78+ } else return false ;
79+ });
80+
81+ if (!qualifiedItem.isEmpty ()) {
82+ qCDebug (logStatusNotifierWatcher).noquote ()
83+ << " Unregistered StatusNotifierItem" << qualifiedItem << " from watcher" ;
84+
85+ emit this ->StatusNotifierItemUnregistered (qualifiedItem);
86+ } else if (this ->hosts .removeAll (service) != 0 ) {
87+ qCDebug (logStatusNotifierWatcher).noquote ()
88+ << " Unregistered StatusNotifierHost" << service << " from watcher" ;
89+ emit this ->StatusNotifierHostUnregistered ();
90+ } else {
91+ qCWarning (logStatusNotifierWatcher).noquote ()
92+ << " Got service unregister event for untracked service" << service;
93+ }
8294 }
8395
8496 this ->serviceWatcher .removeWatchedService (service);
@@ -112,23 +124,44 @@ void StatusNotifierWatcher::RegisterStatusNotifierHost(const QString& host) {
112124}
113125
114126void StatusNotifierWatcher::RegisterStatusNotifierItem (const QString& item) {
115- if (this ->items .contains (item)) {
127+ auto qualifiedItem = this ->qualifiedItem (item);
128+ auto service = qualifiedItem.split (" /" ).at (0 );
129+
130+ if (this ->items .contains (qualifiedItem)) {
116131 qCDebug (logStatusNotifierWatcher).noquote ()
117- << " Skipping duplicate registration of StatusNotifierItem" << item << " to watcher" ;
132+ << " Skipping duplicate registration of StatusNotifierItem" << qualifiedItem << " to watcher" ;
118133 return ;
119134 }
120135
121- if (!QDBusConnection::sessionBus ().interface ()->serviceOwner (item ).isValid ()) {
136+ if (!QDBusConnection::sessionBus ().interface ()->serviceOwner (service ).isValid ()) {
122137 qCWarning (logStatusNotifierWatcher).noquote ()
123- << " Ignoring invalid StatusNotifierItem registration of" << item << " to watcher" ;
138+ << " Ignoring invalid StatusNotifierItem registration of" << qualifiedItem << " to watcher" ;
124139 return ;
125140 }
126141
127- this ->serviceWatcher .addWatchedService (item);
128- this ->items .push_back (item);
142+ this ->serviceWatcher .addWatchedService (service);
143+ this ->items .push_back (qualifiedItem);
144+
129145 qCDebug (logStatusNotifierWatcher).noquote ()
130- << " Registered StatusNotifierItem" << item << " to watcher" ;
131- emit this ->StatusNotifierItemRegistered (item);
146+ << " Registered StatusNotifierItem" << qualifiedItem << " to watcher" ;
147+
148+ emit this ->StatusNotifierItemRegistered (qualifiedItem);
149+ }
150+
151+ QString StatusNotifierWatcher::qualifiedItem (const QString& item) {
152+ // Registered items are often missing either the service id or the path.
153+ QString qualifiedItem;
154+ if (item.startsWith (" /" )) {
155+ qualifiedItem = this ->message ().service () + item;
156+ } else {
157+ qualifiedItem = item;
158+ }
159+
160+ if (!qualifiedItem.contains (" /" )) {
161+ qualifiedItem += " /StatusNotifierItem" ;
162+ }
163+
164+ return qualifiedItem;
132165}
133166
134167StatusNotifierWatcher* StatusNotifierWatcher::instance () {
0 commit comments