author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/launcher/taskbar.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
-rw-r--r-- | core/launcher/taskbar.cpp | 314 |
1 files changed, 314 insertions, 0 deletions
diff --git a/core/launcher/taskbar.cpp b/core/launcher/taskbar.cpp new file mode 100644 index 0000000..d7f36bd --- a/dev/null +++ b/core/launcher/taskbar.cpp | |||
@@ -0,0 +1,314 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "startmenu.h" | ||
22 | #include "inputmethods.h" | ||
23 | #include "mrulist.h" | ||
24 | #include "systray.h" | ||
25 | #include "calibrate.h" | ||
26 | #include "wait.h" | ||
27 | #include "appicons.h" | ||
28 | |||
29 | #include "taskbar.h" | ||
30 | #include "desktop.h" | ||
31 | |||
32 | #include <qpe/qpeapplication.h> | ||
33 | #include <qpe/qcopenvelope_qws.h> | ||
34 | #include <qpe/global.h> | ||
35 | #ifdef QT_QWS_CUSTOM | ||
36 | #include <qpe/custom.h> | ||
37 | #endif | ||
38 | |||
39 | #include <qlabel.h> | ||
40 | #include <qlayout.h> | ||
41 | #include <qtimer.h> | ||
42 | #include <qwindowsystem_qws.h> | ||
43 | #include <qwidgetstack.h> | ||
44 | |||
45 | #if defined( Q_WS_QWS ) | ||
46 | #include <qwsdisplay_qws.h> | ||
47 | #include <qgfx_qws.h> | ||
48 | #endif | ||
49 | |||
50 | |||
51 | #define FACTORY(T) \ | ||
52 | static QWidget *new##T( bool maximized ) { \ | ||
53 | QWidget *w = new T( 0, "test", QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ | ||
54 | if ( maximized ) { \ | ||
55 | if ( qApp->desktop()->width() <= 350 ) { \ | ||
56 | w->showMaximized(); \ | ||
57 | } else { \ | ||
58 | w->resize( QSize( 300, 300 ) ); \ | ||
59 | } \ | ||
60 | } \ | ||
61 | w->show(); \ | ||
62 | return w; \ | ||
63 | } | ||
64 | |||
65 | |||
66 | #ifdef SINGLE_APP | ||
67 | #define APP(a,b,c,d) FACTORY(b) | ||
68 | #include "../taskbar/apps.h" | ||
69 | #undef APP | ||
70 | #endif // SINGLE_APP | ||
71 | |||
72 | static Global::Command builtins[] = { | ||
73 | |||
74 | #ifdef SINGLE_APP | ||
75 | #define APP(a,b,c,d) { a, new##b, c }, | ||
76 | #include "../taskbar/apps.h" | ||
77 | #undef APP | ||
78 | #endif | ||
79 | |||
80 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_EBX) | ||
81 | { "calibrate", TaskBar::calibrate,1, 0 }, | ||
82 | #endif | ||
83 | #if !defined(QT_QWS_CASSIOPEIA) | ||
84 | { "shutdown", Global::shutdown, 1, 0 }, | ||
85 | // { "run", run, 1, 0 }, | ||
86 | #endif | ||
87 | |||
88 | { 0, TaskBar::calibrate,0, 0 }, | ||
89 | }; | ||
90 | |||
91 | static bool initNumLock() | ||
92 | { | ||
93 | #ifdef QPE_INITIAL_NUMLOCK_STATE | ||
94 | QPE_INITIAL_NUMLOCK_STATE | ||
95 | #endif | ||
96 | return FALSE; | ||
97 | } | ||
98 | |||
99 | class LockKeyState : public QWidget | ||
100 | { | ||
101 | public: | ||
102 | LockKeyState( QWidget *parent ) : | ||
103 | QWidget(parent), | ||
104 | nl(initNumLock()), cl(FALSE) | ||
105 | { | ||
106 | nl_pm = Resource::loadPixmap("numlock"); | ||
107 | cl_pm = Resource::loadPixmap("capslock"); | ||
108 | } | ||
109 | QSize sizeHint() const | ||
110 | { | ||
111 | return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1); | ||
112 | } | ||
113 | void toggleNumLockState() | ||
114 | { | ||
115 | nl = !nl; repaint(); | ||
116 | } | ||
117 | void toggleCapsLockState() | ||
118 | { | ||
119 | cl = !cl; repaint(); | ||
120 | } | ||
121 | void paintEvent( QPaintEvent * ) | ||
122 | { | ||
123 | int y = (height()-sizeHint().height())/2; | ||
124 | QPainter p(this); | ||
125 | if ( nl ) | ||
126 | p.drawPixmap(1,y,nl_pm); | ||
127 | if ( cl ) | ||
128 | p.drawPixmap(1,y+nl_pm.height()+1,cl_pm); | ||
129 | } | ||
130 | private: | ||
131 | QPixmap nl_pm, cl_pm; | ||
132 | bool nl, cl; | ||
133 | }; | ||
134 | |||
135 | TaskBar::~TaskBar() | ||
136 | { | ||
137 | } | ||
138 | |||
139 | |||
140 | TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader) | ||
141 | { | ||
142 | Global::setBuiltinCommands(builtins); | ||
143 | |||
144 | sm = new StartMenu( this ); | ||
145 | |||
146 | inputMethods = new InputMethods( this ); | ||
147 | connect( inputMethods, SIGNAL(inputToggled(bool)), | ||
148 | this, SLOT(calcMaxWindowRect()) ); | ||
149 | //new QuickLauncher( this ); | ||
150 | |||
151 | stack = new QWidgetStack( this ); | ||
152 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | ||
153 | label = new QLabel(stack); | ||
154 | |||
155 | mru = new MRUList( stack ); | ||
156 | stack->raiseWidget( mru ); | ||
157 | |||
158 | waitIcon = new Wait( this ); | ||
159 | (void) new AppIcons( this ); | ||
160 | |||
161 | sysTray = new SysTray( this ); | ||
162 | |||
163 | // ## make customizable in some way? | ||
164 | #ifdef QT_QWS_CUSTOM | ||
165 | lockState = new LockKeyState( this ); | ||
166 | #else | ||
167 | lockState = 0; | ||
168 | #endif | ||
169 | |||
170 | #if defined(Q_WS_QWS) | ||
171 | #if !defined(QT_NO_COP) | ||
172 | QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this ); | ||
173 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | ||
174 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | ||
175 | #endif | ||
176 | #endif | ||
177 | waitTimer = new QTimer( this ); | ||
178 | connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) ); | ||
179 | clearer = new QTimer( this ); | ||
180 | QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar())); | ||
181 | QObject::connect(clearer, SIGNAL(timeout()), sysTray, SLOT(show())); | ||
182 | } | ||
183 | |||
184 | void TaskBar::setStatusMessage( const QString &text ) | ||
185 | { | ||
186 | label->setText( text ); | ||
187 | stack->raiseWidget( label ); | ||
188 | if ( sysTray && ( label->fontMetrics().width( text ) > label->width() ) ) | ||
189 | sysTray->hide(); | ||
190 | clearer->start( 3000 ); | ||
191 | } | ||
192 | |||
193 | void TaskBar::clearStatusBar() | ||
194 | { | ||
195 | label->clear(); | ||
196 | stack->raiseWidget( mru ); | ||
197 | } | ||
198 | |||
199 | void TaskBar::startWait() | ||
200 | { | ||
201 | waitIcon->setWaiting( true ); | ||
202 | // a catchall stop after 10 seconds... | ||
203 | waitTimer->start( 10 * 1000, true ); | ||
204 | } | ||
205 | |||
206 | void TaskBar::stopWait(const QString& app) | ||
207 | { | ||
208 | waitTimer->stop(); | ||
209 | mru->addTask(sm->execToLink(app)); | ||
210 | waitIcon->setWaiting( false ); | ||
211 | } | ||
212 | |||
213 | void TaskBar::stopWait() | ||
214 | { | ||
215 | waitTimer->stop(); | ||
216 | waitIcon->setWaiting( false ); | ||
217 | } | ||
218 | |||
219 | void TaskBar::resizeEvent( QResizeEvent *e ) | ||
220 | { | ||
221 | QHBox::resizeEvent( e ); | ||
222 | calcMaxWindowRect(); | ||
223 | } | ||
224 | |||
225 | void TaskBar::styleChange( QStyle &s ) | ||
226 | { | ||
227 | QHBox::styleChange( s ); | ||
228 | calcMaxWindowRect(); | ||
229 | } | ||
230 | |||
231 | void TaskBar::calcMaxWindowRect() | ||
232 | { | ||
233 | #ifdef Q_WS_QWS | ||
234 | QRect wr; | ||
235 | int displayWidth = qApp->desktop()->width(); | ||
236 | QRect ir = inputMethods->inputRect(); | ||
237 | if ( ir.isValid() ) { | ||
238 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); | ||
239 | } else { | ||
240 | wr.setCoords( 0, 0, displayWidth-1, y()-1 ); | ||
241 | } | ||
242 | |||
243 | #if QT_VERSION < 300 | ||
244 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, | ||
245 | QSize(qt_screen->width(),qt_screen->height())) | ||
246 | ); | ||
247 | #else | ||
248 | QWSServer::setMaxWindowRect( wr ); | ||
249 | #endif | ||
250 | #endif | ||
251 | } | ||
252 | |||
253 | void TaskBar::receive( const QCString &msg, const QByteArray &data ) | ||
254 | { | ||
255 | QDataStream stream( data, IO_ReadOnly ); | ||
256 | if ( msg == "message(QString)" ) { | ||
257 | QString text; | ||
258 | stream >> text; | ||
259 | setStatusMessage( text ); | ||
260 | } else if ( msg == "hideInputMethod()" ) { | ||
261 | inputMethods->hideInputMethod(); | ||
262 | } else if ( msg == "showInputMethod()" ) { | ||
263 | inputMethods->showInputMethod(); | ||
264 | } else if ( msg == "reloadInputMethods()" ) { | ||
265 | inputMethods->loadInputMethods(); | ||
266 | } else if ( msg == "reloadApplets()" ) { | ||
267 | sysTray->loadApplets(); | ||
268 | } else if ( msg == "soundAlarm()" ) { | ||
269 | Desktop::soundAlarm(); | ||
270 | } | ||
271 | #ifdef CUSTOM_LEDS | ||
272 | else if ( msg == "setLed(int,bool)" ) { | ||
273 | int led, status; | ||
274 | stream >> led >> status; | ||
275 | CUSTOM_LEDS( led, status ); | ||
276 | } | ||
277 | #endif | ||
278 | } | ||
279 | |||
280 | QWidget *TaskBar::calibrate(bool) | ||
281 | { | ||
282 | #ifdef Q_WS_QWS | ||
283 | Calibrate *c = new Calibrate; | ||
284 | c->show(); | ||
285 | return c; | ||
286 | #else | ||
287 | return 0; | ||
288 | #endif | ||
289 | } | ||
290 | |||
291 | void TaskBar::toggleNumLockState() | ||
292 | { | ||
293 | if ( lockState ) lockState->toggleNumLockState(); | ||
294 | } | ||
295 | |||
296 | void TaskBar::toggleCapsLockState() | ||
297 | { | ||
298 | if ( lockState ) lockState->toggleCapsLockState(); | ||
299 | } | ||
300 | |||
301 | void TaskBar::toggleSymbolInput() | ||
302 | { | ||
303 | if ( inputMethods->currentShown() == "Unicode" ) { | ||
304 | inputMethods->hideInputMethod(); | ||
305 | } else { | ||
306 | inputMethods->showInputMethod("Unicode"); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | bool TaskBar::recoverMemory() | ||
311 | { | ||
312 | return mru->quitOldApps(); | ||
313 | } | ||
314 | |||