statusnotifierwatcher.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "statusnotifierwatcher.h"
  2. QDBusConnection sni_sessionBus = QDBusConnection::sessionBus();
  3. StatusNotifierWatcher::StatusNotifierWatcher(QObject *parent) : QObject{parent} {
  4. sni_sessionBus.registerService("org.kde.StatusNotifierWatcher");
  5. sni_sessionBus.registerObject("/StatusNotifierWatcher",
  6. this,
  7. QDBusConnection::ExportAllContents);
  8. }
  9. void StatusNotifierWatcher::RegisterStatusNotifierItem(const QString &serviceOrPath) {
  10. if (!serviceOrPath.contains('/')) {
  11. items.append(serviceOrPath);
  12. QDBusServiceWatcher* watcher = new QDBusServiceWatcher(serviceOrPath,
  13. sni_sessionBus,
  14. QDBusServiceWatcher::WatchForUnregistration);
  15. this->connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this, serviceOrPath]() {
  16. deletedItems.append(serviceOrPath);
  17. emit StatusNotifierItemUnregistered(serviceOrPath);
  18. });
  19. emit StatusNotifierItemRegistered(serviceOrPath);
  20. qDebug() << "REGISTERED StatusNotifierItem:" << serviceOrPath;
  21. }
  22. else {
  23. qDebug() << "Seems that" << serviceOrPath << "is not valid D-Bus service.";
  24. }
  25. }
  26. void StatusNotifierWatcher::RegisterStatusNotifierHost(const QString &service) {
  27. hosts.append(service);
  28. emit StatusNotifierHostRegistered();
  29. qDebug() << "Registered StatusNotifierHost:" << service;
  30. }
  31. void StatusNotifierWatcher::UnregisterStatusNotifierItem(const QString &service, const QString &path) {
  32. qDebug() << "unREGISTERED ITEM: " << service;
  33. }