-rw-r--r-- | core/launcher/taskbar.cpp | 277 |
1 files changed, 168 insertions, 109 deletions
diff --git a/core/launcher/taskbar.cpp b/core/launcher/taskbar.cpp index e8a81c3..37fdb30 100644 --- a/core/launcher/taskbar.cpp +++ b/core/launcher/taskbar.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 7 | ** GNU General Public License version 2 as published by the Free Software |
@@ -16,33 +16,31 @@ | |||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | *********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "startmenu.h" | 21 | #include "startmenu.h" |
22 | #include "inputmethods.h" | 22 | #include "inputmethods.h" |
23 | #include "runningappbar.h" | 23 | #include "runningappbar.h" |
24 | #include "systray.h" | 24 | #include "systray.h" |
25 | #include "calibrate.h" | ||
26 | #include "wait.h" | 25 | #include "wait.h" |
27 | #include "appicons.h" | 26 | #include "appicons.h" |
28 | 27 | ||
29 | #include "taskbar.h" | 28 | #include "taskbar.h" |
30 | #include "desktop.h" | 29 | #include "server.h" |
31 | 30 | ||
32 | #include <qpe/qpeapplication.h> | 31 | #include <qtopia/qpeapplication.h> |
33 | #include <qpe/qcopenvelope_qws.h> | 32 | #ifdef QWS |
34 | #include <qpe/global.h> | 33 | #include <qtopia/qcopenvelope_qws.h> |
35 | |||
36 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) || defined( QT_QWS_RAMSES) | ||
37 | #include <qpe/custom.h> | ||
38 | #endif | 34 | #endif |
39 | 35 | #include <qtopia/global.h> | |
40 | #include <opie/odevice.h> | 36 | #include <qtopia/custom.h> |
41 | 37 | ||
42 | #include <qlabel.h> | 38 | #include <qlabel.h> |
43 | #include <qlayout.h> | 39 | #include <qlayout.h> |
44 | #include <qtimer.h> | 40 | #include <qtimer.h> |
41 | #ifdef QWS | ||
45 | #include <qwindowsystem_qws.h> | 42 | #include <qwindowsystem_qws.h> |
43 | #endif | ||
46 | #include <qwidgetstack.h> | 44 | #include <qwidgetstack.h> |
47 | 45 | ||
48 | #if defined( Q_WS_QWS ) | 46 | #if defined( Q_WS_QWS ) |
@@ -51,21 +49,6 @@ | |||
51 | #endif | 49 | #endif |
52 | 50 | ||
53 | 51 | ||
54 | using namespace Opie; | ||
55 | |||
56 | static Global::Command builtins[] = { | ||
57 | |||
58 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_RAMSES) | ||
59 | { "calibrate", TaskBar::calibrate, 1, 0 }, | ||
60 | #endif | ||
61 | #if !defined(QT_QWS_CASSIOPEIA) | ||
62 | { "shutdown", Global::shutdown, 1, 0 }, | ||
63 | // { "run", run, 1, 0 }, | ||
64 | #endif | ||
65 | |||
66 | { 0, TaskBar::calibrate, 0, 0 }, | ||
67 | }; | ||
68 | |||
69 | static bool initNumLock() | 52 | static bool initNumLock() |
70 | { | 53 | { |
71 | #ifdef QPE_INITIAL_NUMLOCK_STATE | 54 | #ifdef QPE_INITIAL_NUMLOCK_STATE |
@@ -74,42 +57,114 @@ static bool initNumLock() | |||
74 | return FALSE; | 57 | return FALSE; |
75 | } | 58 | } |
76 | 59 | ||
60 | //--------------------------------------------------------------------------- | ||
61 | |||
62 | class SafeMode : public QWidget | ||
63 | { | ||
64 | Q_OBJECT | ||
65 | public: | ||
66 | SafeMode( QWidget *parent ) : QWidget( parent ), menu(0) | ||
67 | { | ||
68 | message = tr("Safe Mode"); | ||
69 | QFont f( font() ); | ||
70 | f.setWeight( QFont::Bold ); | ||
71 | setFont( f ); | ||
72 | } | ||
73 | |||
74 | void mousePressEvent( QMouseEvent *); | ||
75 | QSize sizeHint() const; | ||
76 | void paintEvent( QPaintEvent* ); | ||
77 | |||
78 | private slots: | ||
79 | void action(int i); | ||
80 | |||
81 | private: | ||
82 | QString message; | ||
83 | QPopupMenu *menu; | ||
84 | }; | ||
85 | |||
86 | void SafeMode::mousePressEvent( QMouseEvent *) | ||
87 | { | ||
88 | if ( !menu ) { | ||
89 | menu = new QPopupMenu(this); | ||
90 | menu->insertItem( tr("Plugin Manager..."), 0 ); | ||
91 | menu->insertItem( tr("Restart Qtopia"), 1 ); | ||
92 | menu->insertItem( tr("Help..."), 2 ); | ||
93 | connect(menu, SIGNAL(activated(int)), this, SLOT(action(int))); | ||
94 | } | ||
95 | QPoint curPos = mapToGlobal( QPoint(0,0) ); | ||
96 | QSize sh = menu->sizeHint(); | ||
97 | menu->popup( curPos-QPoint((sh.width()-width())/2,sh.height()) ); | ||
98 | } | ||
99 | |||
100 | void SafeMode::action(int i) | ||
101 | { | ||
102 | switch (i) { | ||
103 | case 0: | ||
104 | Global::execute( "pluginmanager" ); | ||
105 | break; | ||
106 | case 1: | ||
107 | Global::restart(); | ||
108 | break; | ||
109 | case 2: | ||
110 | Global::execute( "helpbrowser", "safemode.html" ); | ||
111 | break; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | QSize SafeMode::sizeHint() const | ||
116 | { | ||
117 | QFontMetrics fm = fontMetrics(); | ||
118 | |||
119 | return QSize( fm.width(message), fm.height() ); | ||
120 | } | ||
121 | |||
122 | void SafeMode::paintEvent( QPaintEvent* ) | ||
123 | { | ||
124 | QPainter p(this); | ||
125 | p.drawText( rect(), AlignCenter, message ); | ||
126 | } | ||
127 | |||
128 | //--------------------------------------------------------------------------- | ||
129 | |||
77 | class LockKeyState : public QWidget | 130 | class LockKeyState : public QWidget |
78 | { | 131 | { |
79 | public: | 132 | public: |
80 | LockKeyState( QWidget *parent ) : | 133 | LockKeyState( QWidget *parent ) : |
81 | QWidget(parent), | 134 | QWidget(parent), |
82 | nl(initNumLock()), cl(FALSE) | 135 | nl(initNumLock()), cl(FALSE) |
83 | { | 136 | { |
84 | nl_pm = Resource::loadPixmap("numlock"); | 137 | nl_pm = Resource::loadPixmap("numlock"); |
85 | cl_pm = Resource::loadPixmap("capslock"); | 138 | cl_pm = Resource::loadPixmap("capslock"); |
86 | } | 139 | } |
87 | QSize sizeHint() const | 140 | QSize sizeHint() const |
88 | { | 141 | { |
89 | return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1); | 142 | return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1); |
90 | } | 143 | } |
91 | void toggleNumLockState() | 144 | void toggleNumLockState() |
92 | { | 145 | { |
93 | nl = !nl; repaint(); | 146 | nl = !nl; repaint(); |
94 | } | 147 | } |
95 | void toggleCapsLockState() | 148 | void toggleCapsLockState() |
96 | { | 149 | { |
97 | cl = !cl; repaint(); | 150 | cl = !cl; repaint(); |
98 | } | 151 | } |
99 | void paintEvent( QPaintEvent * ) | 152 | void paintEvent( QPaintEvent * ) |
100 | { | 153 | { |
101 | int y = (height()-sizeHint().height())/2; | 154 | int y = (height()-sizeHint().height())/2; |
102 | QPainter p(this); | 155 | QPainter p(this); |
103 | if ( nl ) | 156 | if ( nl ) |
104 | p.drawPixmap(1,y,nl_pm); | 157 | p.drawPixmap(1,y,nl_pm); |
105 | if ( cl ) | 158 | if ( cl ) |
106 | p.drawPixmap(1,y+nl_pm.height()+1,cl_pm); | 159 | p.drawPixmap(1,y+nl_pm.height()+1,cl_pm); |
107 | } | 160 | } |
108 | private: | 161 | private: |
109 | QPixmap nl_pm, cl_pm; | 162 | QPixmap nl_pm, cl_pm; |
110 | bool nl, cl; | 163 | bool nl, cl; |
111 | }; | 164 | }; |
112 | 165 | ||
166 | //--------------------------------------------------------------------------- | ||
167 | |||
113 | TaskBar::~TaskBar() | 168 | TaskBar::~TaskBar() |
114 | { | 169 | { |
115 | } | 170 | } |
@@ -117,13 +172,13 @@ TaskBar::~TaskBar() | |||
117 | 172 | ||
118 | TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader) | 173 | TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader) |
119 | { | 174 | { |
120 | Global::setBuiltinCommands(builtins); | ||
121 | |||
122 | sm = new StartMenu( this ); | 175 | sm = new StartMenu( this ); |
176 | connect( sm, SIGNAL(tabSelected(const QString&)), this, | ||
177 | SIGNAL(tabSelected(const QString&)) ); | ||
123 | 178 | ||
124 | inputMethods = new InputMethods( this ); | 179 | inputMethods = new InputMethods( this ); |
125 | connect( inputMethods, SIGNAL(inputToggled(bool)), | 180 | connect( inputMethods, SIGNAL(inputToggled(bool)), |
126 | this, SLOT(calcMaxWindowRect()) ); | 181 | this, SLOT(calcMaxWindowRect()) ); |
127 | 182 | ||
128 | stack = new QWidgetStack( this ); | 183 | stack = new QWidgetStack( this ); |
129 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 184 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
@@ -137,21 +192,34 @@ TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOn | |||
137 | 192 | ||
138 | sysTray = new SysTray( this ); | 193 | sysTray = new SysTray( this ); |
139 | 194 | ||
140 | // ## make customizable in some way? | 195 | /* ### FIXME plugin loader and safe mode */ |
196 | #if 0 | ||
197 | if (PluginLoader::inSafeMode()) | ||
198 | (void)new SafeMode( this ); | ||
199 | #endif | ||
200 | |||
201 | // ## make customizable in some way? | ||
202 | #ifdef QT_QWS_CUSTOM | ||
141 | lockState = new LockKeyState( this ); | 203 | lockState = new LockKeyState( this ); |
204 | #else | ||
205 | lockState = 0; | ||
206 | #endif | ||
142 | 207 | ||
143 | #if defined(Q_WS_QWS) | 208 | #if defined(Q_WS_QWS) |
144 | #if !defined(QT_NO_COP) | 209 | #if !defined(QT_NO_COP) |
145 | QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this ); | 210 | QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this ); |
146 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 211 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
147 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 212 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
148 | #endif | 213 | #endif |
149 | #endif | 214 | #endif |
150 | waitTimer = new QTimer( this ); | 215 | waitTimer = new QTimer( this ); |
151 | connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) ); | 216 | connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) ); |
152 | clearer = new QTimer( this ); | 217 | clearer = new QTimer( this ); |
153 | QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar())); | 218 | QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar())); |
154 | QObject::connect(clearer, SIGNAL(timeout()), sysTray, SLOT(show())); | 219 | |
220 | connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); | ||
221 | connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); | ||
222 | connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); | ||
155 | } | 223 | } |
156 | 224 | ||
157 | void TaskBar::setStatusMessage( const QString &text ) | 225 | void TaskBar::setStatusMessage( const QString &text ) |
@@ -171,7 +239,9 @@ void TaskBar::clearStatusBar() | |||
171 | { | 239 | { |
172 | label->clear(); | 240 | label->clear(); |
173 | stack->raiseWidget(runningAppBar); | 241 | stack->raiseWidget(runningAppBar); |
174 | // stack->raiseWidget( mru ); | 242 | if ( sysTray ) |
243 | sysTray->show(); | ||
244 | // stack->raiseWidget( mru ); | ||
175 | } | 245 | } |
176 | 246 | ||
177 | void TaskBar::startWait() | 247 | void TaskBar::startWait() |
@@ -181,24 +251,36 @@ void TaskBar::startWait() | |||
181 | waitTimer->start( 10 * 1000, true ); | 251 | waitTimer->start( 10 * 1000, true ); |
182 | } | 252 | } |
183 | 253 | ||
184 | void TaskBar::stopWait(const QString& /*app*/) | 254 | void TaskBar::stopWait(const QString&) |
185 | { | 255 | { |
186 | waitTimer->stop(); | 256 | waitTimer->stop(); |
187 | //mru->addTask(sm->execToLink(app)); | ||
188 | waitIcon->setWaiting( false ); | 257 | waitIcon->setWaiting( false ); |
189 | } | 258 | } |
190 | 259 | ||
191 | void TaskBar::stopWait() | 260 | void TaskBar::stopWait() |
192 | { | 261 | { |
193 | waitTimer->stop(); | 262 | waitTimer->stop(); |
194 | |||
195 | waitIcon->setWaiting( false ); | 263 | waitIcon->setWaiting( false ); |
196 | } | 264 | } |
197 | 265 | ||
266 | /* | ||
267 | * This resizeEvent will be captured by | ||
268 | * the ServerInterface and it'll layout | ||
269 | * and calc rect. Now if we go from bigger | ||
270 | * to smaller screen the SysTray is out of | ||
271 | * bounds and repaint() won't trigger an Event | ||
272 | */ | ||
198 | void TaskBar::resizeEvent( QResizeEvent *e ) | 273 | void TaskBar::resizeEvent( QResizeEvent *e ) |
199 | { | 274 | { |
275 | if ( sysTray ) | ||
276 | sysTray->hide(); | ||
277 | |||
200 | QHBox::resizeEvent( e ); | 278 | QHBox::resizeEvent( e ); |
201 | calcMaxWindowRect(); | 279 | |
280 | if ( sysTray ) | ||
281 | sysTray->show(); | ||
282 | |||
283 | qWarning("TaskBar::resize event"); | ||
202 | } | 284 | } |
203 | 285 | ||
204 | void TaskBar::styleChange( QStyle &s ) | 286 | void TaskBar::styleChange( QStyle &s ) |
@@ -209,24 +291,26 @@ void TaskBar::styleChange( QStyle &s ) | |||
209 | 291 | ||
210 | void TaskBar::calcMaxWindowRect() | 292 | void TaskBar::calcMaxWindowRect() |
211 | { | 293 | { |
294 | /* | ||
212 | #ifdef Q_WS_QWS | 295 | #ifdef Q_WS_QWS |
213 | QRect wr; | 296 | QRect wr; |
214 | int displayWidth = qApp->desktop()->width(); | 297 | int displayWidth = qApp->desktop()->width(); |
215 | QRect ir = inputMethods->inputRect(); | 298 | QRect ir = inputMethods->inputRect(); |
216 | if ( ir.isValid() ) { | 299 | if ( ir.isValid() ) { |
217 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); | 300 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); |
218 | } else { | 301 | } else { |
219 | wr.setCoords( 0, 0, displayWidth-1, y()-1 ); | 302 | wr.setCoords( 0, 0, displayWidth-1, y()-1 ); |
220 | } | 303 | } |
221 | 304 | ||
222 | #if QT_VERSION < 300 | 305 | #if QT_VERSION < 0x030000 |
223 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, | 306 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, |
224 | QSize(qt_screen->width(),qt_screen->height())) | 307 | QSize(qt_screen->width(),qt_screen->height())) |
225 | ); | 308 | ); |
226 | #else | 309 | #else |
227 | QWSServer::setMaxWindowRect( wr ); | 310 | QWSServer::setMaxWindowRect( wr ); |
228 | #endif | 311 | #endif |
229 | #endif | 312 | #endif |
313 | */ | ||
230 | } | 314 | } |
231 | 315 | ||
232 | void TaskBar::receive( const QCString &msg, const QByteArray &data ) | 316 | void TaskBar::receive( const QCString &msg, const QByteArray &data ) |
@@ -237,55 +321,34 @@ void TaskBar::receive( const QCString &msg, const QByteArray &data ) | |||
237 | stream >> text; | 321 | stream >> text; |
238 | setStatusMessage( text ); | 322 | setStatusMessage( text ); |
239 | } else if ( msg == "hideInputMethod()" ) { | 323 | } else if ( msg == "hideInputMethod()" ) { |
240 | inputMethods->hideInputMethod(); | 324 | inputMethods->hideInputMethod(); |
241 | } else if ( msg == "showInputMethod()" ) { | 325 | } else if ( msg == "showInputMethod()" ) { |
242 | inputMethods->showInputMethod(); | 326 | inputMethods->showInputMethod(); |
327 | } else if ( msg == "showInputMethod(QString)" ) { | ||
328 | QString name; | ||
329 | stream >> name; | ||
330 | inputMethods->showInputMethod(name); | ||
243 | } else if ( msg == "reloadInputMethods()" ) { | 331 | } else if ( msg == "reloadInputMethods()" ) { |
244 | inputMethods->loadInputMethods(); | 332 | inputMethods->loadInputMethods(); |
245 | } else if ( msg == "toggleInputMethod()" ) { | ||
246 | inputMethods->shown() ? inputMethods->hideInputMethod() : inputMethods->showInputMethod(); | ||
247 | } else if ( msg == "reloadApps()" ) { | ||
248 | sm->reloadApps(); | ||
249 | } else if ( msg == "reloadApplets()" ) { | 333 | } else if ( msg == "reloadApplets()" ) { |
250 | sysTray->clearApplets(); | 334 | sysTray->clearApplets(); |
251 | sysTray->addApplets(); | 335 | sm->createMenu(); |
252 | sm->reloadApplets(); | 336 | sysTray->addApplets(); |
253 | } else if ( msg == "soundAlarm()" ) { | 337 | }else if ( msg == "toggleMenu()" ) { |
254 | DesktopApplication::soundAlarm ( ); | 338 | if ( sm-> launchMenu-> isVisible() ) |
255 | } | 339 | sm-> launch(); |
256 | else if ( msg == "setLed(int,bool)" ) { | 340 | else |
257 | int led, status; | 341 | QCopEnvelope e( "QPE/System", "toggleApplicationMenu()" ); |
258 | stream >> led >> status; | 342 | }else if ( msg == "toggleStartMenu()" ) |
259 | 343 | sm->launch(); | |
260 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); | ||
261 | if ( ll. count ( )){ | ||
262 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; | ||
263 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); | ||
264 | |||
265 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); | ||
266 | } | ||
267 | } | ||
268 | else if ( msg == "toggleMenu()" ) { | ||
269 | if ( sm-> launchMenu-> isVisible ( )) | ||
270 | sm-> launch ( ); | ||
271 | else { | ||
272 | QCopEnvelope e ( "QPE/System", "toggleApplicationMenu()" ); | ||
273 | } | ||
274 | } | ||
275 | else if ( msg == "toggleStartMenu()" ) { | ||
276 | sm-> launch ( ); | ||
277 | } | ||
278 | } | 344 | } |
279 | 345 | ||
280 | QWidget *TaskBar::calibrate(bool) | 346 | void TaskBar::setApplicationState( const QString &name, ServerInterface::ApplicationState state ) |
281 | { | 347 | { |
282 | #ifdef Q_WS_QWS | 348 | if ( state == ServerInterface::Launching ) |
283 | Calibrate *c = new Calibrate; | 349 | runningAppBar->applicationLaunched( name ); |
284 | c->show(); | 350 | else if ( state == ServerInterface::Terminated ) |
285 | return c; | 351 | runningAppBar->applicationTerminated( name ); |
286 | #else | ||
287 | return 0; | ||
288 | #endif | ||
289 | } | 352 | } |
290 | 353 | ||
291 | void TaskBar::toggleNumLockState() | 354 | void TaskBar::toggleNumLockState() |
@@ -300,16 +363,12 @@ void TaskBar::toggleCapsLockState() | |||
300 | 363 | ||
301 | void TaskBar::toggleSymbolInput() | 364 | void TaskBar::toggleSymbolInput() |
302 | { | 365 | { |
303 | if ( inputMethods->currentShown() == "Unicode" ) { | 366 | QString unicodeInput = qApp->translate( "InputMethods", "Unicode" ); |
304 | inputMethods->hideInputMethod(); | 367 | if ( inputMethods->currentShown() == unicodeInput ) { |
368 | inputMethods->hideInputMethod(); | ||
305 | } else { | 369 | } else { |
306 | inputMethods->showInputMethod("Unicode"); | 370 | inputMethods->showInputMethod( unicodeInput ); |
307 | } | 371 | } |
308 | } | 372 | } |
309 | 373 | ||
310 | bool TaskBar::recoverMemory() | 374 | #include "taskbar.moc" |
311 | { | ||
312 | //mru->quitOldApps() is no longer supported | ||
313 | return true; | ||
314 | } | ||
315 | |||