Changeset View
Changeset View
Standalone View
Standalone View
src/statusnotifier.cpp
Show All 13 Lines | 1 | /* | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "statusnotifier.h" | 18 | #include "statusnotifier.h" | ||
19 | 19 | | |||
20 | #include <QAction> | 20 | #include <QAction> | ||
21 | #include <QDBusConnectionInterface> | 21 | #include <QDBusConnectionInterface> | ||
22 | #include <QDBusServiceWatcher> | ||||
22 | #include <QMenu> | 23 | #include <QMenu> | ||
23 | #include <QTimer> | 24 | #include <QTimer> | ||
24 | 25 | | |||
25 | #include <KIdleTime> | 26 | #include <KIdleTime> | ||
26 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
27 | #include <KNotification> | 28 | #include <KNotification> | ||
28 | #include <KService> | 29 | #include <KService> | ||
29 | #include <KStatusNotifierItem> | 30 | #include <KStatusNotifierItem> | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 39 | { | |||
85 | 86 | | |||
86 | action = new QAction(QIcon::fromTheme(QStringLiteral("application-exit")), | 87 | action = new QAction(QIcon::fromTheme(QStringLiteral("application-exit")), | ||
87 | i18nc("Allows the user to hide this notifier item", "Hide"), nullptr); | 88 | i18nc("Allows the user to hide this notifier item", "Hide"), nullptr); | ||
88 | connect(action, &QAction::triggered, this, &StatusNotifier::expired); | 89 | connect(action, &QAction::triggered, this, &StatusNotifier::expired); | ||
89 | sniMenu->addAction(action); | 90 | sniMenu->addAction(action); | ||
90 | 91 | | |||
91 | m_sni->setContextMenu(sniMenu); | 92 | m_sni->setContextMenu(sniMenu); | ||
92 | 93 | | |||
94 | // Should the SNI host implode and not return within 10s, automatically | ||||
95 | // open the dialog. | ||||
96 | auto activateTimer = new QTimer(this); | ||||
97 | activateTimer->setInterval(10000); | ||||
98 | connect(activateTimer, &QTimer::timeout, this, &StatusNotifier::activated); | ||||
99 | | ||||
100 | auto watcher = new QDBusServiceWatcher(QStringLiteral("org.freedesktop.Notifications"), | ||||
davidedmundson: SNIs are different to notifications. | |||||
101 | QDBusConnection::sessionBus(), | ||||
102 | QDBusServiceWatcher::WatchForOwnerChange, | ||||
103 | this); | ||||
104 | connect(watcher, &QDBusServiceWatcher::serviceUnregistered, | ||||
105 | activateTimer, QOverload<>::of(&QTimer::start)); | ||||
106 | connect(watcher, &QDBusServiceWatcher::serviceRegistered, | ||||
107 | activateTimer, &QTimer::stop); | ||||
108 | | ||||
93 | // make sure the user doesn't miss the SNI by stopping the auto hide timer when the session becomes idle | 109 | // make sure the user doesn't miss the SNI by stopping the auto hide timer when the session becomes idle | ||
94 | int idleId = KIdleTime::instance()->addIdleTimeout(30000); | 110 | int idleId = KIdleTime::instance()->addIdleTimeout(30000); | ||
95 | connect(KIdleTime::instance(), static_cast<void (KIdleTime::*)(int)>(&KIdleTime::timeoutReached), this, [this, idleId](int id) { | 111 | connect(KIdleTime::instance(), static_cast<void (KIdleTime::*)(int)>(&KIdleTime::timeoutReached), this, [this, idleId](int id) { | ||
96 | if (idleId == id) { | 112 | if (idleId == id) { | ||
97 | m_autoCloseTimer->stop(); | 113 | m_autoCloseTimer->stop(); | ||
98 | } | 114 | } | ||
99 | // this is apparently needed or else resumingFromIdle is never called | 115 | // this is apparently needed or else resumingFromIdle is never called | ||
100 | KIdleTime::instance()->catchNextResumeEvent(); | 116 | KIdleTime::instance()->catchNextResumeEvent(); | ||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |
SNIs are different to notifications.