Parent: [790848] (diff)

Child: [81cc60] (diff)

Download this file

trayicon.cpp    284 lines (232 with data), 7.2 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* GUI_TrayIcon.cpp */
/* Copyright (C) 2012 gleugner
*
* This file is part of sayonara player
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trayicon.h"
#include <QAction>
#include <QMenu>
#include <QEvent>
#include <QWheelEvent>
#include <QHoverEvent>
#include <QDebug>
#include <QIcon>
#include <QPixmap>
#include <QTimer>
#include "HelperStructs/CSettingsStorage.h"
#include "HelperStructs/Helper.h"
GUI_TrayIcon::GUI_TrayIcon(QObject *parent)
: QSystemTrayIcon(parent)
{
m_settings = CSettingsStorage::getInstance();
m_playing = false;
m_mute = false;
QString icon_path = Helper::getIconPath();
QIcon play_icon = QIcon(icon_path + "/play.png");
QIcon pause_icon = QIcon(icon_path + "/pause.png");
QIcon sayo_icon = QIcon(icon_path + "/logo.png");
QPixmap play_pixmap = play_icon.pixmap(24, 24);
QPixmap pause_pixmap = pause_icon.pixmap(24, 24);
QPixmap sayo_pixmap = sayo_icon.pixmap(24, 24);
setIcon(QIcon(sayo_pixmap));
m_playIcon = QIcon(play_pixmap);
m_pauseIcon = QIcon(pause_pixmap);
m_vol_step = 5;
// m_plugin_loader = NotificationPluginLoader::getInstance();
m_notification_active = m_settings->getShowNotifications();
m_timeout = m_settings->getNotificationTimeout();
_timer = new QTimer(this);
_timer->setInterval(300);
_md_set = false;
m_playAction = new QAction(tr("Play"), this);
m_playAction->setIcon(QIcon(icon_path + "play.png"));
m_stopAction = new QAction(tr("Stop"), this);
m_stopAction->setIcon(QIcon(icon_path + "stop.png"));
m_bwdAction = new QAction(tr("Previous"), this);
m_bwdAction->setIcon(QIcon(icon_path + "bwd.png"));
m_fwdAction = new QAction(tr("Next"), this);
m_fwdAction->setIcon(QIcon(icon_path + "fwd.png"));
m_muteAction = new QAction(tr("Mute"), this);
m_muteAction->setIcon(QIcon(icon_path + "vol_mute.png"));
m_closeAction = new QAction(tr("Close"), this);
m_closeAction->setIcon(QIcon(icon_path + "close.png"));
m_showAction = new QAction(tr("Show"), this);
m_trayContextMenu = new QMenu();
m_trayContextMenu->addAction(m_playAction);
m_trayContextMenu->addAction(m_stopAction);
m_trayContextMenu->addSeparator();
m_trayContextMenu->addAction(m_fwdAction);
m_trayContextMenu->addAction(m_bwdAction);
m_trayContextMenu->addSeparator();
m_trayContextMenu->addAction(m_muteAction);
m_trayContextMenu->addSeparator();
m_trayContextMenu->addAction(m_showAction);
m_trayContextMenu->addAction(m_closeAction);
setContextMenu(m_trayContextMenu);
connect(m_playAction, SIGNAL(triggered()), this, SLOT(play_clicked()));
connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(fwd_clicked()));
connect(m_bwdAction, SIGNAL(triggered()), this, SLOT(bwd_clicked()));
connect(m_stopAction, SIGNAL(triggered()), this, SLOT(stop_clicked()));
connect(m_showAction, SIGNAL(triggered()), this, SLOT(show_clicked()));
connect(m_closeAction, SIGNAL(triggered()), this, SLOT(close_clicked()));
connect(m_muteAction, SIGNAL(triggered()), this, SLOT(mute_clicked()));
connect(_timer, SIGNAL(timeout()), this, SLOT(timer_timed_out()));
}
GUI_TrayIcon::~GUI_TrayIcon()
{
}
void GUI_TrayIcon::change_skin(QString stylesheet)
{
this->m_trayContextMenu->setStyleSheet(stylesheet);
this->setMute(_mute);
}
bool GUI_TrayIcon::event(QEvent * e)
{
if (e->type() == QEvent::Wheel) {
QWheelEvent * wheelEvent = dynamic_cast <QWheelEvent *>(e);
emit sig_volume_changed_by_wheel(wheelEvent->delta());
}
return true;
}
void GUI_TrayIcon::timer_timed_out()
{
qDebug() << "Timed out";
_timer->stop();
if (_md_set) {
trackChanged(_md);
}
}
void GUI_TrayIcon::songChangedMessage(const MetaData& md)
{
_md = md;
_md_set = true;
#if 0
if (m_notification_active) {
Notification* n = m_plugin_loader->get_cur_plugin();
if (n) {
n->notification_show(md);
}
else if (this -> isSystemTrayAvailable()) {
this -> showMessage("Upplay", md.title + tr(" by ") + md.artist,
QSystemTrayIcon::Information, m_timeout);
}
}
#endif
}
void GUI_TrayIcon::trackChanged(const MetaData& md)
{
songChangedMessage(md);
}
void GUI_TrayIcon::set_timeout(int timeout_ms)
{
m_timeout = timeout_ms;
}
void GUI_TrayIcon::set_notification_active(bool active)
{
m_notification_active = active;
}
void GUI_TrayIcon::set_enable_play(bool b)
{
m_playAction->setEnabled(b);
}
void GUI_TrayIcon::set_enable_stop(bool b)
{
m_stopAction->setEnabled(b);
}
void GUI_TrayIcon::set_enable_mute(bool)
{
}
void GUI_TrayIcon::set_enable_fwd(bool b)
{
m_fwdAction->setEnabled(b);
}
void GUI_TrayIcon::set_enable_bwd(bool b)
{
m_bwdAction->setEnabled(b);
}
void GUI_TrayIcon::set_enable_show(bool b)
{
m_showAction->setEnabled(b);
}
void GUI_TrayIcon::play_clicked()
{
qDebug() << "tray: play clicked";
if (!m_playing) {
emit sig_play_clicked();
} else {
emit sig_pause_clicked();
}
}
void GUI_TrayIcon::stop_clicked()
{
emit sig_stop_clicked();
}
void GUI_TrayIcon::stop()
{
_md_set = false;
}
void GUI_TrayIcon::fwd_clicked()
{
emit sig_fwd_clicked();
}
void GUI_TrayIcon::bwd_clicked()
{
emit sig_bwd_clicked();
}
void GUI_TrayIcon::show_clicked()
{
emit sig_show_clicked();
}
void GUI_TrayIcon::close_clicked()
{
emit sig_close_clicked();
}
void GUI_TrayIcon::mute_clicked()
{
emit sig_mute_clicked();
}
void GUI_TrayIcon::setMute(bool mute)
{
_mute = mute;
QString suffix = "";
int style = CSettingsStorage::getInstance()->getPlayerStyle();
if (style == 1) {
suffix = "_dark";
}
if (!mute) {
m_muteAction->setIcon(QIcon(Helper::getIconPath() + "vol_mute" +
suffix + ".png"));
m_muteAction->setText(tr("Mute"));
} else {
m_muteAction->setIcon(QIcon(Helper::getIconPath() + "vol_3" +
suffix + ".png"));
m_muteAction->setText(tr("Unmute"));
}
}
void GUI_TrayIcon::setPlaying(bool playing)
{
//qDebug() << "GUI_TrayIcon::setPlaying: " << playing;
m_playing = playing;
if (playing) {
m_playAction->setIcon(m_pauseIcon);
m_playAction->setText(tr("Pause"));
} else {
m_playAction->setIcon(m_playIcon);
m_playAction->setText(tr("Play"));
}
}
int GUI_TrayIcon::get_vol_step()
{
return m_vol_step;
}