summaryrefslogtreecommitdiff
path: root/core/launcher/taskbar.cpp
blob: 1feae4a0c27fbd5fa3293e66905e0033a4808875 (plain)
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
*********************************************************************/

#include "startmenu.h"
#include "inputmethods.h"
#include "runningappbar.h"
#include "systray.h"
#include "calibrate.h"
#include "wait.h"
#include "appicons.h"

#include "taskbar.h"
#include "desktop.h"

#include <qpe/qpeapplication.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/global.h>

#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
#include <qpe/custom.h>
#endif

#include <opie/odevice.h>

#include <qlabel.h>
#include <qlayout.h>
#include <qtimer.h>
#include <qwindowsystem_qws.h>
#include <qwidgetstack.h>

#if defined( Q_WS_QWS )
#include <qwsdisplay_qws.h>
#include <qgfx_qws.h>
#endif


#define FACTORY(T) \
    static QWidget *new##T( bool maximized ) { \
  QWidget *w = new T( 0, "test", QWidget::WDestructiveClose | QWidget::WGroupLeader ); \
  if ( maximized ) { \
      if ( qApp->desktop()->width() <= 350 ) { \
    w->showMaximized(); \
      } else { \
    w->resize( QSize( 300, 300 ) ); \
      } \
  } \
  w->show(); \
  return w; \
    }


#ifdef SINGLE_APP
#define APP(a,b,c,d) FACTORY(b)
#include "../launcher/apps.h"
#undef APP
#endif // SINGLE_APP

static Global::Command builtins[] = {

#ifdef SINGLE_APP
#define APP(a,b,c,d) { a, new##b, c },
#include "../launcher/apps.h"
#undef APP
#endif

#if defined(QT_QWS_IPAQ) || defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_EBX)
        { "calibrate",          TaskBar::calibrate, 1, 0 },
#endif
#if !defined(QT_QWS_CASSIOPEIA)
  { "shutdown",           Global::shutdown,   1, 0 },
//  { "run",                run,      1, 0 },
#endif

  { 0,            TaskBar::calibrate, 0, 0 },
};

static bool initNumLock()
{
#ifdef QPE_INITIAL_NUMLOCK_STATE
    QPE_INITIAL_NUMLOCK_STATE
#endif
    return FALSE;
}

class LockKeyState : public QWidget
{
public:
    LockKeyState( QWidget *parent ) :
  QWidget(parent),
  nl(initNumLock()), cl(FALSE)
    {
  nl_pm = Resource::loadPixmap("numlock");
  cl_pm = Resource::loadPixmap("capslock");
    }
    QSize sizeHint() const
    {
  return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1);
    }
    void toggleNumLockState()
    {
  nl = !nl; repaint();
    }
    void toggleCapsLockState()
    {
  cl = !cl; repaint();
    }
    void paintEvent( QPaintEvent * )
    {
  int y = (height()-sizeHint().height())/2;
  QPainter p(this);
  if ( nl )
      p.drawPixmap(1,y,nl_pm);
  if ( cl )
      p.drawPixmap(1,y+nl_pm.height()+1,cl_pm);
    }
private:
    QPixmap nl_pm, cl_pm;
    bool nl, cl;
};

TaskBar::~TaskBar()
{
}


TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader)
{
    Global::setBuiltinCommands(builtins);

    sm = new StartMenu( this );

    inputMethods = new InputMethods( this );
    connect( inputMethods, SIGNAL(inputToggled(bool)),
       this, SLOT(calcMaxWindowRect()) );
    //new QuickLauncher( this );

    stack = new QWidgetStack( this );
    stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    label = new QLabel(stack);

    //mru = new MRUList( stack );
    //stack->raiseWidget( mru );

    runningAppBar = new RunningAppBar(stack);
    stack->raiseWidget(runningAppBar);

    waitIcon = new Wait( this );
    (void) new AppIcons( this );

    sysTray = new SysTray( this );

    // ## make customizable in some way?
#ifdef QT_QWS_CUSTOM
    lockState = new LockKeyState( this );
#else
    lockState = 0;
#endif

#if defined(Q_WS_QWS)
#if !defined(QT_NO_COP)
    QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this );
    connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
  this, SLOT(receive(const QCString&, const QByteArray&)) );
#endif
#endif
    waitTimer = new QTimer( this );
    connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) );
    clearer = new QTimer( this );
    QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar()));
    QObject::connect(clearer, SIGNAL(timeout()), sysTray, SLOT(show()));
}

void TaskBar::setStatusMessage( const QString &text )
{
    label->setText( text );
    stack->raiseWidget( label );
    if ( sysTray && ( label->fontMetrics().width( text ) > label->width() ) )
  sysTray->hide();
    clearer->start( 3000 );
}

void TaskBar::clearStatusBar()
{
    label->clear();
    stack->raiseWidget(runningAppBar);
     //  stack->raiseWidget( mru );
}

void TaskBar::startWait()
{
    waitIcon->setWaiting( true );
    // a catchall stop after 10 seconds...
    waitTimer->start( 10 * 1000, true );
}

void TaskBar::stopWait(const QString& app)
{
    waitTimer->stop();
    //mru->addTask(sm->execToLink(app));
    waitIcon->setWaiting( false );
}

void TaskBar::stopWait()
{
    waitTimer->stop();

    waitIcon->setWaiting( false );
}

void TaskBar::resizeEvent( QResizeEvent *e )
{
    QHBox::resizeEvent( e );
    calcMaxWindowRect();
}

void TaskBar::styleChange( QStyle &s )
{
    QHBox::styleChange( s );
    calcMaxWindowRect();
}

void TaskBar::calcMaxWindowRect()
{
#ifdef Q_WS_QWS
    QRect wr;
    int displayWidth  = qApp->desktop()->width();
    QRect ir = inputMethods->inputRect();
    if ( ir.isValid() ) {
  wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
    } else {
  wr.setCoords( 0, 0, displayWidth-1, y()-1 );
    }

#if QT_VERSION < 300
    QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,
  QSize(qt_screen->width(),qt_screen->height()))
  );
#else
    QWSServer::setMaxWindowRect( wr );
#endif
#endif
}

void TaskBar::receive( const QCString &msg, const QByteArray &data )
{
	QDataStream stream( data, IO_ReadOnly );
	if ( msg == "message(QString)" ) {
		QString text;
		stream >> text;
		setStatusMessage( text );
	} else if ( msg == "hideInputMethod()" ) {
		inputMethods->hideInputMethod();
	} else if ( msg == "showInputMethod()" ) {
		inputMethods->showInputMethod();
	} else if ( msg == "reloadInputMethods()" ) {
		inputMethods->loadInputMethods();
	} else if ( msg == "reloadApplets()" ) {
		sysTray->clearApplets();
		sysTray->addApplets();
	} else if ( msg == "soundAlarm()" ) {
		Desktop::soundAlarm();
	}
	else if ( msg == "setLed(int,bool)" ) {
		int led, status;
		stream >> led >> status;

		ODevice::inst ( )-> setLed ( led, status ? OLED_BlinkSlow : OLED_Off );
	}
}

QWidget *TaskBar::calibrate(bool)
{
#ifdef Q_WS_QWS
    Calibrate *c = new Calibrate;
    c->show();
    return c;
#else
    return 0;
#endif
}

void TaskBar::toggleNumLockState()
{
    if ( lockState ) lockState->toggleNumLockState();
}

void TaskBar::toggleCapsLockState()
{
    if ( lockState ) lockState->toggleCapsLockState();
}

void TaskBar::toggleSymbolInput()
{
    if ( inputMethods->currentShown() == "Unicode" ) {
  inputMethods->hideInputMethod();
    } else {
  inputMethods->showInputMethod("Unicode");
    }
}

bool TaskBar::recoverMemory()
{
    //eturn mru->quitOldApps();
    return true;
}