00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "startmenu.h"
00029 #include "inputmethods.h"
00030 #include "runningappbar.h"
00031 #include "systray.h"
00032 #include "wait.h"
00033 #include "appicons.h"
00034
00035 #include "taskbar.h"
00036 #include "server.h"
00037
00038
00039 #include <opie2/odebug.h>
00040 #include <opie2/oresource.h>
00041 #include <qtopia/config.h>
00042 #include <qtopia/qpeapplication.h>
00043 #ifdef QWS
00044 #include <qtopia/qcopenvelope_qws.h>
00045 #endif
00046 #include <qtopia/global.h>
00047 using namespace Opie::Core;
00048
00049
00050 #include <qlabel.h>
00051 #include <qlayout.h>
00052 #include <qtimer.h>
00053 #ifdef QWS
00054 #include <qwindowsystem_qws.h>
00055 #endif
00056 #include <qwidgetstack.h>
00057
00058 #if defined( Q_WS_QWS )
00059 #include <qwsdisplay_qws.h>
00060 #include <qgfx_qws.h>
00061 #endif
00062
00063
00064 static bool initNumLock()
00065 {
00066 #ifdef QPE_INITIAL_NUMLOCK_STATE
00067 QPE_INITIAL_NUMLOCK_STATE
00068 #endif
00069 return FALSE;
00070 }
00071
00072
00073
00074 class SafeMode : public QWidget
00075 {
00076 Q_OBJECT
00077 public:
00078 SafeMode( QWidget *parent ) : QWidget( parent ), menu(0)
00079 {
00080 message = tr("Safe Mode");
00081 QFont f( font() );
00082 f.setWeight( QFont::Bold );
00083 setFont( f );
00084 }
00085
00086 void mousePressEvent( QMouseEvent *);
00087 QSize sizeHint() const;
00088 void paintEvent( QPaintEvent* );
00089
00090 private slots:
00091 void action(int i);
00092
00093 private:
00094 QString message;
00095 QPopupMenu *menu;
00096 };
00097
00098 void SafeMode::mousePressEvent( QMouseEvent *)
00099 {
00100 if ( !menu ) {
00101 menu = new QPopupMenu(this);
00102 menu->insertItem( tr("Plugin Manager..."), 0 );
00103 menu->insertItem( tr("Restart Qtopia"), 1 );
00104 menu->insertItem( tr("Help..."), 2 );
00105 connect(menu, SIGNAL(activated(int)), this, SLOT(action(int)));
00106 }
00107 QPoint curPos = mapToGlobal( QPoint(0,0) );
00108 QSize sh = menu->sizeHint();
00109 menu->popup( curPos-QPoint((sh.width()-width())/2,sh.height()) );
00110 }
00111
00112 void SafeMode::action(int i)
00113 {
00114 switch (i) {
00115 case 0:
00116 Global::execute( "pluginmanager" );
00117 break;
00118 case 1:
00119 Global::restart();
00120 break;
00121 case 2:
00122 Global::execute( "helpbrowser", "safemode.html" );
00123 break;
00124 }
00125 }
00126
00127 QSize SafeMode::sizeHint() const
00128 {
00129 QFontMetrics fm = fontMetrics();
00130
00131 return QSize( fm.width(message), fm.height() );
00132 }
00133
00134 void SafeMode::paintEvent( QPaintEvent* )
00135 {
00136 QPainter p(this);
00137 p.drawText( rect(), AlignCenter, message );
00138 }
00139
00140
00141
00142 class LockKeyState : public QWidget
00143 {
00144 public:
00145 LockKeyState( QWidget *parent ) :
00146 QWidget(parent),
00147 nl(initNumLock()), cl(FALSE)
00148 {
00149 nl_pm = OResource::loadPixmap("numlock", OResource::NoScale);
00150 cl_pm = OResource::loadPixmap("capslock", OResource::NoScale);
00151 }
00152 QSize sizeHint() const
00153 {
00154 return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1);
00155 }
00156 void toggleNumLockState()
00157 {
00158 nl = !nl; repaint();
00159 }
00160 void toggleCapsLockState()
00161 {
00162 cl = !cl; repaint();
00163 }
00164 void paintEvent( QPaintEvent * )
00165 {
00166 int y = (height()-sizeHint().height())/2;
00167 QPainter p(this);
00168 if ( nl )
00169 p.drawPixmap(1,y,nl_pm);
00170 if ( cl )
00171 p.drawPixmap(1,y+nl_pm.height()+1,cl_pm);
00172 }
00173 private:
00174 QPixmap nl_pm, cl_pm;
00175 bool nl, cl;
00176 };
00177
00178
00179
00180 TaskBar::~TaskBar()
00181 {
00182 }
00183
00184
00185 TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader)
00186 {
00187
00188 readConfig();
00189
00190 sm = new StartMenu( this );
00191 connect( sm, SIGNAL(tabSelected(const QString&)), this,
00192 SIGNAL(tabSelected(const QString&)) );
00193
00194 inputMethods = new InputMethods( this );
00195 connect( inputMethods, SIGNAL(inputToggled(bool)),
00196 this, SLOT(calcMaxWindowRect()) );
00197
00198 stack = new QWidgetStack( this );
00199 stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
00200 label = new QLabel(stack);
00201
00202 runningAppBar = new RunningAppBar(stack);
00203 stack->raiseWidget(runningAppBar);
00204
00205 waitIcon = new Wait( this );
00206 (void) new AppIcons( this );
00207
00208 sysTray = new SysTray( this );
00209
00210
00211 #if 0
00212 if (PluginLoader::inSafeMode())
00213 (void)new SafeMode( this );
00214 #endif
00215
00216
00217 #ifdef OPIE_TASKBAR_LOCK_KEY_STATE
00218 lockState = new LockKeyState( this );
00219 #else
00220 lockState = 0;
00221 #endif
00222
00223 #if defined(Q_WS_QWS)
00224 #if !defined(QT_NO_COP)
00225 QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this );
00226 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
00227 this, SLOT(receive(const QCString&,const QByteArray&)) );
00228 #endif
00229 #endif
00230 waitTimer = new QTimer( this );
00231 connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) );
00232 clearer = new QTimer( this );
00233 QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar()));
00234
00235 connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) );
00236 connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) );
00237 connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) );
00238 }
00239
00240 void TaskBar::setStatusMessage( const QString &text )
00241 {
00242 if ( !text.isEmpty() ) {
00243 label->setText( text );
00244 stack->raiseWidget( label );
00245 if ( sysTray && ( label->fontMetrics().width( text ) > label->width() ) )
00246 sysTray->hide();
00247 clearer->start( 3000, TRUE );
00248 } else {
00249 clearStatusBar();
00250 }
00251 }
00252
00253 void TaskBar::clearStatusBar()
00254 {
00255 label->clear();
00256 stack->raiseWidget(runningAppBar);
00257 if ( sysTray )
00258 sysTray->show();
00259
00260 }
00261
00262 void TaskBar::startWait()
00263 {
00264 waitIcon->setWaiting( true );
00265
00266 waitTimer->start( 10 * 1000, true );
00267 }
00268
00269 void TaskBar::stopWait(const QString&)
00270 {
00271 waitTimer->stop();
00272 waitIcon->setWaiting( false );
00273 }
00274
00275 void TaskBar::stopWait()
00276 {
00277 waitTimer->stop();
00278 waitIcon->setWaiting( false );
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288 void TaskBar::resizeEvent( QResizeEvent *e )
00289 {
00290 if ( sysTray )
00291 sysTray->hide();
00292
00293 QHBox::resizeEvent( e );
00294
00295 if ( sysTray )
00296 sysTray->show();
00297 }
00298
00299 void TaskBar::styleChange( QStyle &s )
00300 {
00301 QHBox::styleChange( s );
00302 calcMaxWindowRect();
00303 }
00304
00305 void TaskBar::calcMaxWindowRect()
00306 {
00307 if ( resizeRunningApp )
00308 {
00309 #if defined(Q_WS_QWS)
00310 QRect wr;
00311 int displayWidth = qApp->desktop()->width();
00312 QRect ir = inputMethods->inputRect();
00313 if ( ir.isValid() ) {
00314 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
00315 } else {
00316 wr.setCoords( 0, 0, displayWidth-1, y()-1 );
00317 }
00318 #if QT_VERSION < 0x030000
00319 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,QSize(qt_screen->width(),qt_screen->height())) );
00320 #else
00321 QWSServer::setMaxWindowRect( wr );
00322 #endif
00323 #endif
00324 }
00325 }
00326
00327 void TaskBar::receive( const QCString &msg, const QByteArray &data )
00328 {
00329 QDataStream stream( data, IO_ReadOnly );
00330 if ( msg == "message(QString)" ) {
00331 QString text;
00332 stream >> text;
00333 setStatusMessage( text );
00334 } else if ( msg == "hideInputMethod()" ) {
00335 inputMethods->hideInputMethod();
00336 } else if ( msg == "showInputMethod()" ) {
00337 inputMethods->showInputMethod();
00338 } else if ( msg == "showInputMethod(QString)" ) {
00339 QString name;
00340 stream >> name;
00341 inputMethods->showInputMethod(name);
00342 } else if ( msg == "reloadInputMethods()" ) {
00343 readConfig();
00344 inputMethods->readConfig();
00345 inputMethods->loadInputMethods();
00346 } else if ( msg == "reloadApplets()" ) {
00347 sysTray->clearApplets();
00348 sm->createMenu();
00349 sysTray->addApplets();
00350 }else if ( msg == "toggleMenu()" ) {
00351 if ( sm-> launchMenu-> isVisible() )
00352 sm-> launch();
00353 else
00354 QCopEnvelope e( "QPE/System", "toggleApplicationMenu()" );
00355 }else if ( msg == "toggleStartMenu()" )
00356 sm->launch();
00357 }
00358
00359 void TaskBar::setApplicationState( const QString &name, ServerInterface::ApplicationState state )
00360 {
00361 if ( state == ServerInterface::Launching )
00362 runningAppBar->applicationLaunched( name );
00363 else if ( state == ServerInterface::Terminated )
00364 runningAppBar->applicationTerminated( name );
00365 }
00366
00367 void TaskBar::toggleNumLockState()
00368 {
00369 if ( lockState ) lockState->toggleNumLockState();
00370 }
00371
00372 void TaskBar::toggleCapsLockState()
00373 {
00374 if ( lockState ) lockState->toggleCapsLockState();
00375 }
00376
00377 void TaskBar::toggleSymbolInput()
00378 {
00379 QString unicodeInput = qApp->translate( "InputMethods", "Unicode" );
00380 if ( inputMethods->currentShown() == unicodeInput ) {
00381 inputMethods->hideInputMethod();
00382 } else {
00383 inputMethods->showInputMethod( unicodeInput );
00384 }
00385 }
00386
00387 void TaskBar::readConfig() {
00388 Config cfg( "Launcher" );
00389 cfg.setGroup( "InputMethods" );
00390 resizeRunningApp = cfg.readBoolEntry( "Resize", true );
00391 }
00392
00393 #include "taskbar.moc"