This repository was archived by the owner on Jun 19, 2020. It is now read-only.
forked from Skycoder42/QTaskbarControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtaskbarcontrol_x11.cpp
More file actions
80 lines (70 loc) · 2.13 KB
/
Copy pathqtaskbarcontrol_x11.cpp
File metadata and controls
80 lines (70 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "qtaskbarcontrol_x11.h"
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDebug>
QTaskbarControlPrivate *QTaskbarControlPrivate::createPrivate(QTaskbarControl *)
{
return new QX11TaskbarControl{};
}
void QX11TaskbarControl::setWindow(QWindow *window)
{
Q_UNUSED(window);
}
bool QX11TaskbarControl::setAttribute(QTaskbarControl::SetupKey key, const QVariant &data)
{
switch (key) {
case QTaskbarControl::LinuxDesktopFile:
if(!_desktopFile.isEmpty())
sendReset();
_desktopFile = data.toString();
sendReset();
return true;
default:
return false;
}
}
QVariant QX11TaskbarControl::attribute(QTaskbarControl::SetupKey key)
{
switch (key) {
case QTaskbarControl::LinuxDesktopFile:
return _desktopFile;
default:
return QVariant();
}
}
void QX11TaskbarControl::setProgress(bool progressVisible, double progress)
{
QVariantMap properties;
properties.insert(QStringLiteral("progress-visible"), progressVisible);
properties.insert(QStringLiteral("progress"), progress);
sendMessage(properties);
}
void QX11TaskbarControl::setCounter(bool counterVisible, int counter)
{
QVariantMap properties;
properties.insert(QStringLiteral("count-visible"), counterVisible);
properties.insert(QStringLiteral("count"), counter);
sendMessage(properties);
}
void QX11TaskbarControl::sendMessage(const QVariantMap ¶ms)
{
if(_desktopFile.isEmpty()) {
qWarning() << "You need to set the" << QTaskbarControl::LinuxDesktopFile << "attribute before you can use QTaskbarControl!";
return;
}
auto message = QDBusMessage::createSignal(QStringLiteral("/de/skycoder42/QTaskbarProgress"),
QStringLiteral("com.canonical.Unity.LauncherEntry"),
QStringLiteral("Update"));
message << QString{QStringLiteral("application://") + _desktopFile}
<< params;
QDBusConnection::sessionBus().send(message);
}
void QX11TaskbarControl::sendReset()
{
QVariantMap properties;
properties.insert(QStringLiteral("progress-visible"), false);
properties.insert(QStringLiteral("progress"), 0.0);
properties.insert(QStringLiteral("count-visible"), false);
properties.insert(QStringLiteral("count"), 0);
sendMessage(properties);
}