forked from maz-1/dukto-qt5
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsystemnotification.cpp
More file actions
187 lines (166 loc) · 4.3 KB
/
Copy pathsystemnotification.cpp
File metadata and controls
187 lines (166 loc) · 4.3 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifdef DESKTOP_APP
#ifdef NOTIFY_LIBNOTIFY
// put this on top, leave glib's mess behind
#include <libnotify/notify.h>
#else
#include "systemtray.h"
#endif
#endif
#ifdef Q_OS_WIN
#include "ecwin7.h"
#endif
#include "systemnotification.h"
#include "settings.h"
#include "duktowindow.h"
#ifdef Q_OS_ANDROID
#include "androidutils.h"
#endif
SystemNotification::SystemNotification(DuktoWindow *window, QObject *parent) : QObject(parent), window(window) {
#ifdef NOTIFY_LIBNOTIFY
notify_init("Dukto");
#endif
}
SystemNotification::~SystemNotification() {
#ifdef NOTIFY_LIBNOTIFY
notify_uninit();
#endif
}
void SystemNotification::notifyFileReceived(const QString &name, const QString &path, qint64 size) {
Q_UNUSED(size)
Q_UNUSED(path)
notify("Recieved File", name);
}
void SystemNotification::notifyFolderReceived(const QString &name, const QString &path) {
Q_UNUSED(path)
notify("Recieved Folder", name);
}
void SystemNotification::notifyTextReceived(const QString &text) {
notify("Recieved Text Snippet", text);
}
void SystemNotification::notifyTransferringStarted(bool inbound, const QString &buddyName, const QString &buddyIp) {
Q_UNUSED(buddyIp)
#ifdef Q_OS_WIN
showTaskbarProgress(0);
#endif
if (!gSettings->notificationEnabled()) {
return;
}
#ifdef Q_OS_ANDROID
if (inbound) {
AndroidNotification::start("Receiving from " + buddyName, true);
} else {
AndroidNotification::start("Sending to " + buddyName, false);
}
#else
Q_UNUSED(inbound)
Q_UNUSED(buddyName)
#endif
}
void SystemNotification::notifyTransferringCompleted(bool inbound) {
#ifdef Q_OS_WIN
hideTaskbarProgress();
#endif
if (!gSettings->notificationEnabled()) {
return;
}
#ifdef Q_OS_ANDROID
if (inbound) {
AndroidNotification::setDone("All data has been received!");
} else {
AndroidNotification::setDone("All data has been sent!");
}
#else
Q_UNUSED(inbound)
#endif
}
void SystemNotification::notifyTransferringError(bool inbound, const QString &error) {
Q_UNUSED(inbound)
#ifdef Q_OS_WIN
stopTaskbarProgress();
#endif
if (!gSettings->notificationEnabled()) {
return;
}
#ifdef Q_OS_ANDROID
if (error.isEmpty() == false) {
AndroidNotification::setError(error);
} else {
// no reason, cancelled by user
AndroidNotification::cancel();
}
#else
Q_UNUSED(error)
#endif
}
void SystemNotification::notifyTransferringProgress(double percent) {
#ifdef Q_OS_WIN
showTaskbarProgress(percent);
#endif
if (!gSettings->notificationEnabled()) {
return;
}
#ifdef Q_OS_ANDROID
AndroidNotification::setProgress(percent);
#else
Q_UNUSED(percent)
#endif
}
void SystemNotification::notifyTransferringItem(const QString &desc) {
if (!gSettings->notificationEnabled()) {
return;
}
// desc = "(<current> / <total>) <name>"
#ifdef Q_OS_ANDROID
AndroidNotification::setText(desc);
#else
Q_UNUSED(desc)
#endif
}
void SystemNotification::notify(const QString &title, const QString &text) {
if (!gSettings->notificationEnabled()) {
return;
}
#ifdef DESKTOP_APP
#ifdef NOTIFY_LIBNOTIFY
QByteArray titleBytes = title.toUtf8();
QByteArray textBytes = text.toUtf8();
NotifyNotification* msg = notify_notification_new(titleBytes.constData(), textBytes.constData(), nullptr);
notify_notification_show (msg, nullptr);
g_object_unref(G_OBJECT(msg));
#else
window->getTray()->notify(title, text);
#endif
#else
Q_UNUSED(title)
Q_UNUSED(text)
#endif
}
void SystemNotification::hideNotification() {
#ifdef Q_OS_ANDROID
AndroidNotification::cancel();
#endif
#ifdef Q_OS_WIN
hideTaskbarProgress();
#endif
}
#ifdef Q_OS_WIN
void SystemNotification::showTaskbarProgress(uint percent) {
EcWin7 *taskbar = window->getTaskBar();
if (taskbar != nullptr) {
taskbar->setProgressState(EcWin7::Normal);
taskbar->setProgressValue(percent, 100);
}
}
void SystemNotification::hideTaskbarProgress() {
EcWin7 *taskbar = window->getTaskBar();
if (taskbar != nullptr) {
taskbar->setProgressState(EcWin7::NoProgress);
}
}
void SystemNotification::stopTaskbarProgress() {
EcWin7 *taskbar = window->getTaskBar();
if (taskbar != nullptr) {
taskbar->setProgressState(EcWin7::Error);
}
}
#endif