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
|
/*
msystemtray.cpp - A system tray icon
Copyright (C) 2003 Konrad Twardowski <kdtonline@poczta.onet.pl>
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "configuration.h"
#include "miscutils.h"
#include "mmainwindow.h"
#include "msystemtray.h"
#include <ntqtimer.h>
#include <tdeaction.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <kpixmap.h>
#include <kpixmapeffect.h>
#include <tdepopupmenu.h>
#include <twin.h>
const double
KS_TRAY_FADE_CHANGE = 0.05f,
KS_TRAY_FADE_MAX = 0.7f;
const int KS_TRAY_FADE_TIMEOUT = 50;
const TQColor KS_TRAY_FADE_COLOR = TQt::yellow;
MSystemTray::Mode MSystemTray::_mode = Always;
MSystemTray *MSystemTray::_instance = 0;
// public
MSystemTray::~MSystemTray()
{
if (_flashIcon)
delete _flashIcon;
if (_saveIcon)
delete _saveIcon;
}
void MSystemTray::flashIcon()
{
if (_saveIcon)
delete _saveIcon;
_saveIcon = new TQPixmap();
*_saveIcon = *pixmap();
_flashCount = 0;
setPixmap(*_flashIcon);
_flashTimer->start(200);
}
void MSystemTray::setActive(const bool yes)
{
// kdDebug() << "MSystemTray::setActive: " << yes << endl;
if (_active == yes)
return;
_active = yes;
_incFade = _active;
_fadeTimer->start(KS_TRAY_FADE_TIMEOUT);
}
void MSystemTray::setMode(const Mode mode)
{
// kdDebug() << "MSystemTray::setMode: " << mode << endl;
_mode = mode;
switch (_mode)
{
case Always:
ks_tray; // init instance
if (ks_actions->active())
_instance->setActive(true);
_instance->show();
MiscUtils::setAutostart(true);
break;
case IfActive:
if (ks_actions->active())
{
ks_tray; // init instance
_instance->setActive(true);
_instance->show();
MiscUtils::setAutostart(true);
}
else
{
delete _instance;
_instance = 0;
MiscUtils::setAutostart(false);
}
break;
case Never:
delete _instance;
_instance = 0;
MiscUtils::setAutostart(false);
break;
}
}
// protected
void MSystemTray::mousePressEvent(TQMouseEvent *e)
{
// middle mouse button - display actions menu
// TODO: 2.0: configure middle button action
if (e->button() == MidButton)
contextMenu()->popup(e->globalPos());
else
KSystemTray::mousePressEvent(e);
}
// private
MSystemTray::MSystemTray()
: KSystemTray(ks_main, "MSystemTray"),
_active(false),
_incFade(true),
_fadeValue(0.0f),
_flashCount(0),
_saveIcon(0)
{
setPixmap(SmallIcon("system-log-out", TDEIcon::SizeSmallMedium)); // 22x22
// TODO: 2.0: mouse wheel: decrease/increase end time by 5min. (?)
// init fade timer
_fadeTimer = new TQTimer(this);
connect(_fadeTimer, SIGNAL(timeout()), SLOT(slotFade()));
// init flash timer
_flashTimer = new TQTimer(this);
connect(_flashTimer, SIGNAL(timeout()), SLOT(slotFlashTimeout()));
// init icons
KPixmap pm(SmallIcon("system-log-out", TDEIcon::SizeSmallMedium));
_flashIcon = new KPixmap(KPixmapEffect::fade(pm, 0.7f, white));
show();
// add some items to the context menu
TDEPopupMenu *pm_systemTrayMenu = contextMenu();
pm_systemTrayMenu->setCaption("KShutDown");
// id 0 = title
ks_main->shutDownAction()->plug(pm_systemTrayMenu, 1);
ks_main->rebootAction()->plug(pm_systemTrayMenu, 2);
ks_main->lockScreenAction()->plug(pm_systemTrayMenu, 3);
ks_main->logoutAction()->plug(pm_systemTrayMenu, 4);
pm_systemTrayMenu->insertSeparator(5);
ks_main->cancelAction()->plug(pm_systemTrayMenu, 6);
pm_systemTrayMenu->insertSeparator(7);
ks_main->configureKShutDownAction()->plug(pm_systemTrayMenu, 8);
pm_systemTrayMenu->insertTearOffHandle();
// quit signal
connect(
this, SIGNAL(quitSelected()),
ks_main, SLOT(slotQuit()));
}
// private slots
void MSystemTray::slotFade()
{
if (_incFade)
{
_fadeValue += KS_TRAY_FADE_CHANGE;
if (_fadeValue > KS_TRAY_FADE_MAX)
{
_fadeTimer->stop();
_fadeValue = KS_TRAY_FADE_MAX;
}
}
else
{
_fadeValue -= KS_TRAY_FADE_CHANGE;
if (_fadeValue < 0.0f)
{
_fadeTimer->stop();
_fadeValue = 0.0f;
}
}
KPixmap p(SmallIcon("system-log-out", TDEIcon::SizeSmallMedium));
setPixmap(KPixmapEffect::fade(p, _fadeValue, KS_TRAY_FADE_COLOR));
}
void MSystemTray::slotFlashTimeout()
{
_flashCount++;
if ((_flashCount % 2) == 0)
setPixmap(*_saveIcon);
else
setPixmap(*_flashIcon);
if (_flashCount == 6)
_flashTimer->stop();
}
|