StatusNotifierButton::StatusNotifierButton(QString service, QString objectPath, ILXQtPanelPlugin* plugin, QWidget *parent) : QToolButton(parent), mMenu(nullptr), mStatus(Passive), mFallbackIcon(QIcon::fromTheme("application-x-executable")), mPlugin(plugin) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setAutoRaise(true); interface = new SniAsync(service, objectPath, QDBusConnection::sessionBus(), this); connect(interface, &SniAsync::NewIcon, this, &StatusNotifierButton::newIcon); connect(interface, &SniAsync::NewOverlayIcon, this, &StatusNotifierButton::newOverlayIcon); connect(interface, &SniAsync::NewAttentionIcon, this, &StatusNotifierButton::newAttentionIcon); connect(interface, &SniAsync::NewToolTip, this, &StatusNotifierButton::newToolTip); connect(interface, &SniAsync::NewStatus, this, &StatusNotifierButton::newStatus); interface->propertyGetAsync(QLatin1String("Menu"), [this] (QDBusObjectPath path) { if (!path.path().isEmpty()) { mMenu = (new MenuImporter{interface->service(), path.path(), this})->menu(); mMenu->setObjectName(QLatin1String("StatusNotifierMenu")); } }); interface->propertyGetAsync(QLatin1String("Status"), [this] (QString status) { newStatus(status); }); interface->propertyGetAsync(QLatin1String("IconThemePath"), [this] (QString value) { //do the logic of icons after we've got the theme path refetchIcon(Active, value); refetchIcon(Passive, value); refetchIcon(NeedsAttention, value); }); newToolTip(); }
StatusNotifierButton::StatusNotifierButton(QString service, QString objectPath, ILXQtPanelPlugin* plugin, QWidget *parent) : QToolButton(parent), mMenu(NULL), mStatus(Passive), mValid(true), mFallbackIcon(QIcon::fromTheme("application-x-executable")), mPlugin(plugin) { interface = new org::kde::StatusNotifierItem(service, objectPath, QDBusConnection::sessionBus(), this); QString menuPath = interface->menu().path(); if (!menuPath.isEmpty()) { mMenu = (new DBusMenuImporter(service, interface->menu().path(), this))->menu(); dynamic_cast<QObject &>(*mMenu).setParent(this); mMenu->setObjectName(QStringLiteral("StatusNotifierMenu")); } // HACK: sni-qt creates some invalid items (like one for konversarion 1.5) if (interface->title().isEmpty() && interface->id().isEmpty()) mValid = false; if (mValid) { newToolTip(); refetchIcon(Active); refetchIcon(Passive); refetchIcon(NeedsAttention); newStatus(interface->status()); resetIcon(); connect(interface, SIGNAL(NewIcon()), this, SLOT(newIcon())); connect(interface, SIGNAL(NewOverlayIcon()), this, SLOT(newOverlayIcon())); connect(interface, SIGNAL(NewAttentionIcon()), this, SLOT(newAttentionIcon())); connect(interface, SIGNAL(NewToolTip()), this, SLOT(newToolTip())); connect(interface, SIGNAL(NewStatus(QString)), this, SLOT(newStatus(QString))); } }
void StatusNotifierButton::newIcon() { interface->propertyGetAsync(QLatin1String("IconThemePath"), [this] (QString value) { refetchIcon(Passive, value); }); }
void StatusNotifierButton::newAttentionIcon() { interface->propertyGetAsync(QLatin1String("IconThemePath"), [this] (QString value) { refetchIcon(NeedsAttention, value); }); }
void StatusNotifierButton::newAttentionIcon() { refetchIcon(NeedsAttention); resetIcon(); }
void StatusNotifierButton::newOverlayIcon() { refetchIcon(Active); resetIcon(); }
void StatusNotifierButton::newIcon() { refetchIcon(Passive); resetIcon(); }