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
|
/*
(c) Copyright 2012 - 2018 Anton Sviridenko
https://picapica.im
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, version 3.
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 <https://www.gnu.org/licenses/>.
*/
#include "picasystray.h"
#include "globals.h"
#include "picaactioncenter.h"
#include "accounts.h"
#ifdef PACKAGE_VERSION
#define VERSION_STRING "v" PACKAGE_VERSION
#else
#define VERSION_STRING ""
#endif
PicaSysTray::PicaSysTray(QObject *parent) :
QObject(parent), emptyicon_(32, 32)
{
systrayMenu_ = new QMenu();
//Unity cannot into doubleclick on tray icon... :(
QAction *activate = new QAction(tr("&Activate"), this);
connect(activate, SIGNAL(triggered()), this, SIGNAL(doubleclicked()));
systrayMenu_->addAction(action_center->AboutAct());
systrayMenu_->addAction(action_center->MuteSoundsAct());
systrayMenu_->addAction(activate);
systrayMenu_->addSeparator();
systrayMenu_->addAction(action_center->ExitAct());
systray_ = new QSystemTrayIcon(picapica_ico_sit);
systray_->setContextMenu(systrayMenu_);
systray_->setToolTip("Pica Pica Messenger " VERSION_STRING);
systray_->show();
connect(systray_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systray_activated(QSystemTrayIcon::ActivationReason)));
connect(skynet, SIGNAL(BecameSelfAware()), this, SLOT(skynet_became_self_aware()));
connect(skynet, SIGNAL(LostSelfAwareness()), this, SLOT(skynet_lost_self_awareness()));
emptyicon_.fill(Qt::transparent);
}
void PicaSysTray::systray_activated(QSystemTrayIcon::ActivationReason r)
{
if (r == QSystemTrayIcon::DoubleClick)
{
emit doubleclicked();
}
}
void PicaSysTray::skynet_became_self_aware()
{
systray_->setIcon(picapica_ico_fly);
systray_->setToolTip(Accounts::GetCurrentAccount().name + " - Pica Pica Messenger " VERSION_STRING);
}
void PicaSysTray::skynet_lost_self_awareness()
{
systray_->setIcon(picapica_ico_sit);
}
void PicaSysTray::StartBlinking()
{
blink_ = systray_->icon();
timer_id_ = startTimer(300);
}
void PicaSysTray::StopBlinking()
{
killTimer(timer_id_);
systray_->setIcon(blink_);
}
void PicaSysTray::timerEvent(QTimerEvent *event)
{
static int blinker;
blinker++ % 2 ? systray_->setIcon(blink_)
:
systray_->setIcon(QIcon(emptyicon_));
}
|