X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fdockmanagernotificationbackend.cpp;h=9e54ee31ccbde7cdf288e260489374a61c7e8878;hp=5654776337f465ec5383aac81725c336f4616f76;hb=9188f1a4880dc7f4c26612a265c1d874f6df5a8c;hpb=b50541ba6d7c58322846cc2eb9f023a117d8c47d diff --git a/src/qtui/dockmanagernotificationbackend.cpp b/src/qtui/dockmanagernotificationbackend.cpp index 56547763..9e54ee31 100644 --- a/src/qtui/dockmanagernotificationbackend.cpp +++ b/src/qtui/dockmanagernotificationbackend.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2013 by the Quassel Project * + * Copyright (C) 2013-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,32 +20,46 @@ #include "dockmanagernotificationbackend.h" -#include #include #include +#include #include "client.h" +#include "clientbacklogmanager.h" #include "clientsettings.h" #include "coreconnection.h" -#include "clientbacklogmanager.h" +#include "util.h" -DockManagerNotificationBackend::DockManagerNotificationBackend(QObject *parent) - : AbstractNotificationBackend(parent), _bus(QDBusConnection::sessionBus()), _dock(0), _item(0), _count(0) +DockManagerNotificationBackend::DockManagerNotificationBackend(QObject* parent) + : AbstractNotificationBackend(parent) + , _bus(QDBusConnection::sessionBus()) { NotificationSettings notificationSettings; _enabled = notificationSettings.value("DockManager/Enabled", false).toBool(); - notificationSettings.notify("DockManager/Enabled", this, SLOT(enabledChanged(const QVariant &))); + notificationSettings.notify("DockManager/Enabled", this, &DockManagerNotificationBackend::enabledChanged); _dock = new QDBusInterface("net.launchpad.DockManager", "/net/launchpad/DockManager", "net.launchpad.DockManager", _bus, this); if (_dock->isValid()) { - _bus.connect("net.launchpad.DockManager", "/net/launchpad/DockManager", "net.launchpad.DockManager", "ItemAdded", this, SLOT(itemAdded(QDBusObjectPath))); - } else { + _bus.connect("net.launchpad.DockManager", + "/net/launchpad/DockManager", + "net.launchpad.DockManager", + "ItemAdded", + this, + SLOT(itemAdded(QDBusObjectPath))); + } + else { // evil implementations (awn) use fd.o _dock = new QDBusInterface("org.freedesktop.DockManager", "/org/freedesktop/DockManager", "org.freedesktop.DockManager", _bus, this); if (_dock->isValid()) { - _bus.connect("org.freedesktop.DockManager", "/org/freedesktop/DockManager", "org.freedesktop.DockManager", "ItemAdded", this, SLOT(itemAdded(QDBusObjectPath))); - } else { + _bus.connect("org.freedesktop.DockManager", + "/org/freedesktop/DockManager", + "org.freedesktop.DockManager", + "ItemAdded", + this, + SLOT(itemAdded(QDBusObjectPath))); + } + else { _available = _enabled = false; return; } @@ -54,11 +68,13 @@ DockManagerNotificationBackend::DockManagerNotificationBackend(QObject *parent) itemAdded(QDBusObjectPath()); - connect(Client::coreConnection(), SIGNAL(progressValueChanged(int)), this, SLOT(updateProgress(int))); - connect(Client::coreConnection(), SIGNAL(synchronized()), this, SLOT(synchronized())); + connect(Client::coreConnection(), + &CoreConnection::progressValueChanged, + this, + selectOverload(&DockManagerNotificationBackend::updateProgress)); + connect(Client::coreConnection(), &CoreConnection::synchronized, this, &DockManagerNotificationBackend::synchronized); } - void DockManagerNotificationBackend::itemAdded(QDBusObjectPath p) { Q_UNUSED(p); @@ -67,7 +83,7 @@ void DockManagerNotificationBackend::itemAdded(QDBusObjectPath p) return; // stupid implementations (awn; kde?) use wrong casing of PID, but proper type - QDBusReply > paths = _dock->call("GetItemsByPid", (int)QCoreApplication::applicationPid()); + QDBusReply> paths = _dock->call("GetItemsByPid", (int)QCoreApplication::applicationPid()); if (!paths.isValid()) { // stupid implementations (i.e. docky) use uint, but proper casing paths = _dock->call("GetItemsByPID", (unsigned int)QCoreApplication::applicationPid()); @@ -76,21 +92,20 @@ void DockManagerNotificationBackend::itemAdded(QDBusObjectPath p) return; } } - if (paths.value().count() == 0) { // no icon for this instance + if (paths.value().count() == 0) { // no icon for this instance return; } - QString path = paths.value()[0].path(); // no sense in using multiple icons for one instance + QString path = paths.value()[0].path(); // no sense in using multiple icons for one instance _item = new QDBusInterface("org.freedesktop.DockManager", path, "org.freedesktop.DockItem", _bus, this); } - void DockManagerNotificationBackend::updateProgress(int progress) { if (!_enabled || !_item) return; - CoreConnection *c = Client::instance()->coreConnection(); + CoreConnection* c = Client::instance()->coreConnection(); int perc = 0; if (c->progressMaximum() == c->progressMinimum()) perc = 0; @@ -102,7 +117,6 @@ void DockManagerNotificationBackend::updateProgress(int progress) _item->call("UpdateDockItem", args); } - void DockManagerNotificationBackend::updateProgress(int done, int total) { if (!_enabled || !_item) @@ -110,9 +124,10 @@ void DockManagerNotificationBackend::updateProgress(int done, int total) int perc = 0; if (done == total) { - disconnect(Client::backlogManager(), 0, this, 0); + disconnect(Client::backlogManager(), nullptr, this, nullptr); perc = -1; - } else + } + else perc = (done * 100) / total; QHash args; @@ -120,14 +135,15 @@ void DockManagerNotificationBackend::updateProgress(int done, int total) _item->call("UpdateDockItem", args); } - void DockManagerNotificationBackend::synchronized() { - connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), this, SLOT(updateProgress(int, int))); + connect(Client::backlogManager(), + &ClientBacklogManager::updateProgress, + this, + selectOverload(&DockManagerNotificationBackend::updateProgress)); } - -void DockManagerNotificationBackend::notify(const Notification ¬ification) +void DockManagerNotificationBackend::notify(const Notification& notification) { if (!_enabled || !_item) { return; @@ -142,7 +158,6 @@ void DockManagerNotificationBackend::notify(const Notification ¬ification) _item->call("UpdateDockItem", args); } - void DockManagerNotificationBackend::close(uint notificationId) { Q_UNUSED(notificationId); @@ -155,8 +170,7 @@ void DockManagerNotificationBackend::close(uint notificationId) _item->call("UpdateDockItem", args); } - -void DockManagerNotificationBackend::enabledChanged(const QVariant &v) +void DockManagerNotificationBackend::enabledChanged(const QVariant& v) { _enabled = v.toBool(); @@ -168,47 +182,42 @@ void DockManagerNotificationBackend::enabledChanged(const QVariant &v) } } - -SettingsPage *DockManagerNotificationBackend::createConfigWidget() const +SettingsPage* DockManagerNotificationBackend::createConfigWidget() const { return new ConfigWidget(_available); } - /***************************************************************************/ -DockManagerNotificationBackend::ConfigWidget::ConfigWidget(bool enabled, QWidget *parent) +DockManagerNotificationBackend::ConfigWidget::ConfigWidget(bool enabled, QWidget* parent) : SettingsPage("Internal", "DockManagerNotification", parent) { - QHBoxLayout *layout = new QHBoxLayout(this); + auto* layout = new QHBoxLayout(this); layout->addWidget(enabledBox = new QCheckBox(tr("Mark dockmanager entry"), this)); - enabledBox->setEnabled(enabled); + enabledBox->setVisible(enabled); - connect(enabledBox, SIGNAL(toggled(bool)), SLOT(widgetChanged())); + connect(enabledBox, &QAbstractButton::toggled, this, &ConfigWidget::widgetChanged); } - void DockManagerNotificationBackend::ConfigWidget::widgetChanged() { bool changed = enabled != enabledBox->isChecked(); - if (changed != hasChanged()) setChangedState(changed); + if (changed != hasChanged()) + setChangedState(changed); } - bool DockManagerNotificationBackend::ConfigWidget::hasDefaults() const { return true; } - void DockManagerNotificationBackend::ConfigWidget::defaults() { enabledBox->setChecked(false); widgetChanged(); } - void DockManagerNotificationBackend::ConfigWidget::load() { NotificationSettings s; @@ -218,7 +227,6 @@ void DockManagerNotificationBackend::ConfigWidget::load() setChangedState(false); } - void DockManagerNotificationBackend::ConfigWidget::save() { NotificationSettings s;