summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
authorllornkcor <llornkcor>2004-04-25 08:54:30 (UTC)
committer llornkcor <llornkcor>2004-04-25 08:54:30 (UTC)
commit5d3c80f70109bee75d55db2a11d7112eb7ebaa99 (patch) (unidiff)
tree4215d0bce8d8b270cead8afa829e59da173ae63f /library/qpeapplication.cpp
parentea4380df897798cf4bbadaf786868a18b3dee975 (diff)
downloadopie-5d3c80f70109bee75d55db2a11d7112eb7ebaa99.zip
opie-5d3c80f70109bee75d55db2a11d7112eb7ebaa99.tar.gz
opie-5d3c80f70109bee75d55db2a11d7112eb7ebaa99.tar.bz2
remove commented out ugly hack
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp25
1 files changed, 0 insertions, 25 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 5ce3011..10c6c40 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,2310 +1,2285 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the 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
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
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#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <stdlib.h> 21#include <stdlib.h>
22#include <unistd.h> 22#include <unistd.h>
23#ifndef Q_OS_MACX 23#ifndef Q_OS_MACX
24#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 24#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
25#endif 25#endif
26#include <qfile.h> 26#include <qfile.h>
27#include <qqueue.h> 27#include <qqueue.h>
28#ifdef Q_WS_QWS 28#ifdef Q_WS_QWS
29#ifndef QT_NO_COP 29#ifndef QT_NO_COP
30#if QT_VERSION <= 231 30#if QT_VERSION <= 231
31#define private public 31#define private public
32#define sendLocally processEvent 32#define sendLocally processEvent
33#include "qcopenvelope_qws.h" 33#include "qcopenvelope_qws.h"
34#undef private 34#undef private
35#else 35#else
36#include "qcopenvelope_qws.h" 36#include "qcopenvelope_qws.h"
37#endif 37#endif
38#endif 38#endif
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#endif 40#endif
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qpalette.h> 42#include <qpalette.h>
43#include <qbuffer.h> 43#include <qbuffer.h>
44#include <qptrdict.h> 44#include <qptrdict.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qdir.h> 46#include <qdir.h>
47#include <qlabel.h> 47#include <qlabel.h>
48#include <qdialog.h> 48#include <qdialog.h>
49#include <qdragobject.h> 49#include <qdragobject.h>
50#include <qtextcodec.h> 50#include <qtextcodec.h>
51#include <qevent.h> 51#include <qevent.h>
52#include <qtooltip.h> 52#include <qtooltip.h>
53#include <qsignal.h> 53#include <qsignal.h>
54#include <qmainwindow.h> 54#include <qmainwindow.h>
55#include <qwidgetlist.h> 55#include <qwidgetlist.h>
56#include <qpixmapcache.h> 56#include <qpixmapcache.h>
57 57
58#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 58#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
59#define QTOPIA_INTERNAL_INITAPP 59#define QTOPIA_INTERNAL_INITAPP
60#include "qpeapplication.h" 60#include "qpeapplication.h"
61#include "qpestyle.h" 61#include "qpestyle.h"
62#include "styleinterface.h" 62#include "styleinterface.h"
63#if QT_VERSION >= 300 63#if QT_VERSION >= 300
64#include <qstylefactory.h> 64#include <qstylefactory.h>
65#else 65#else
66#include <qplatinumstyle.h> 66#include <qplatinumstyle.h>
67#include <qwindowsstyle.h> 67#include <qwindowsstyle.h>
68#include <qmotifstyle.h> 68#include <qmotifstyle.h>
69#include <qmotifplusstyle.h> 69#include <qmotifplusstyle.h>
70#include "lightstyle.h" 70#include "lightstyle.h"
71 71
72#include <qpe/qlibrary.h> 72#include <qpe/qlibrary.h>
73#endif 73#endif
74#include "global.h" 74#include "global.h"
75#include "resource.h" 75#include "resource.h"
76#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 76#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
77#include "qutfcodec.h" 77#include "qutfcodec.h"
78#endif 78#endif
79#include "config.h" 79#include "config.h"
80#include "network.h" 80#include "network.h"
81#ifdef QWS 81#ifdef QWS
82#include "fontmanager.h" 82#include "fontmanager.h"
83#endif 83#endif
84 84
85#include "alarmserver.h" 85#include "alarmserver.h"
86#include "applnk.h" 86#include "applnk.h"
87#include "qpemenubar.h" 87#include "qpemenubar.h"
88#include "textcodecinterface.h" 88#include "textcodecinterface.h"
89#include "imagecodecinterface.h" 89#include "imagecodecinterface.h"
90 90
91#include <unistd.h> 91#include <unistd.h>
92#include <sys/file.h> 92#include <sys/file.h>
93#include <sys/ioctl.h> 93#include <sys/ioctl.h>
94#ifndef QT_NO_SOUND 94#ifndef QT_NO_SOUND
95#include <sys/soundcard.h> 95#include <sys/soundcard.h>
96#endif 96#endif
97#include "qt_override_p.h" 97#include "qt_override_p.h"
98 98
99class HackWidget : public QWidget 99class HackWidget : public QWidget
100{ 100{
101public: 101public:
102 bool needsOk() 102 bool needsOk()
103 { return (getWState() & WState_Reserved1 ); } 103 { return (getWState() & WState_Reserved1 ); }
104 104
105 QRect normalGeometry() 105 QRect normalGeometry()
106 { return topData()->normalGeometry; }; 106 { return topData()->normalGeometry; };
107}; 107};
108 108
109class QPEApplicationData 109class QPEApplicationData
110{ 110{
111public: 111public:
112 QPEApplicationData ( ) 112 QPEApplicationData ( )
113 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 113 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
114 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 114 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
115 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) 115 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 )
116 116
117 {} 117 {}
118 118
119 int presstimer; 119 int presstimer;
120 QWidget* presswidget; 120 QWidget* presswidget;
121 QPoint presspos; 121 QPoint presspos;
122 122
123 bool rightpressed : 1; 123 bool rightpressed : 1;
124 bool kbgrabbed : 1; 124 bool kbgrabbed : 1;
125 bool notbusysent : 1; 125 bool notbusysent : 1;
126 bool preloaded : 1; 126 bool preloaded : 1;
127 bool forceshow : 1; 127 bool forceshow : 1;
128 bool nomaximize : 1; 128 bool nomaximize : 1;
129 bool keep_running : 1; 129 bool keep_running : 1;
130 bool qcopQok : 1; 130 bool qcopQok : 1;
131 131
132 132
133 QStringList langs; 133 QStringList langs;
134 QString appName; 134 QString appName;
135 struct QCopRec 135 struct QCopRec
136 { 136 {
137 QCopRec( const QCString &ch, const QCString &msg, 137 QCopRec( const QCString &ch, const QCString &msg,
138 const QByteArray &d ) : 138 const QByteArray &d ) :
139 channel( ch ), message( msg ), data( d ) 139 channel( ch ), message( msg ), data( d )
140 { } 140 { }
141 141
142 QCString channel; 142 QCString channel;
143 QCString message; 143 QCString message;
144 QByteArray data; 144 QByteArray data;
145 }; 145 };
146 QWidget* qpe_main_widget; 146 QWidget* qpe_main_widget;
147 QGuardedPtr<QWidget> lastraised; 147 QGuardedPtr<QWidget> lastraised;
148 QQueue<QCopRec> qcopq; 148 QQueue<QCopRec> qcopq;
149 QString styleName; 149 QString styleName;
150 QString decorationName; 150 QString decorationName;
151 151
152 void enqueueQCop( const QCString &ch, const QCString &msg, 152 void enqueueQCop( const QCString &ch, const QCString &msg,
153 const QByteArray &data ) 153 const QByteArray &data )
154 { 154 {
155 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 155 qcopq.enqueue( new QCopRec( ch, msg, data ) );
156 } 156 }
157 void sendQCopQ() 157 void sendQCopQ()
158 { 158 {
159 if (!qcopQok ) 159 if (!qcopQok )
160 return; 160 return;
161 161
162 QCopRec * r; 162 QCopRec * r;
163 163
164 while((r=qcopq.dequeue())) { 164 while((r=qcopq.dequeue())) {
165 // remove from queue before sending... 165 // remove from queue before sending...
166 // event loop can come around again before getting 166 // event loop can come around again before getting
167 // back from sendLocally 167 // back from sendLocally
168#ifndef QT_NO_COP 168#ifndef QT_NO_COP
169 QCopChannel::sendLocally( r->channel, r->message, r->data ); 169 QCopChannel::sendLocally( r->channel, r->message, r->data );
170#endif 170#endif
171 171
172 delete r; 172 delete r;
173 } 173 }
174 } 174 }
175 175
176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */) 176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */)
177 { 177 {
178 QPoint p; 178 QPoint p;
179 QSize s; 179 QSize s;
180 bool max; 180 bool max;
181 if ( mw->isVisible() ) { 181 if ( mw->isVisible() ) {
182 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 182 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
183 mw->resize(s); 183 mw->resize(s);
184 mw->move(p); 184 mw->move(p);
185 } 185 }
186 mw->raise(); 186 mw->raise();
187 } else { 187 } else {
188 188
189 if ( mw->layout() && mw->inherits("QDialog") ) { 189 if ( mw->layout() && mw->inherits("QDialog") ) {
190 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 190 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
191 mw->resize(s); 191 mw->resize(s);
192 mw->move(p); 192 mw->move(p);
193 193
194 if ( max && !nomaximize ) { 194 if ( max && !nomaximize ) {
195 mw->showMaximized(); 195 mw->showMaximized();
196 } else { 196 } else {
197 mw->show(); 197 mw->show();
198 } 198 }
199 } else { 199 } else {
200 qpe_show_dialog((QDialog*)mw,nomaximize); 200 qpe_show_dialog((QDialog*)mw,nomaximize);
201 } 201 }
202 } else { 202 } else {
203 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 203 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
204 mw->resize(s); 204 mw->resize(s);
205 mw->move(p); 205 mw->move(p);
206 } else { //no stored rectangle, make an estimation 206 } else { //no stored rectangle, make an estimation
207 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; 207 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
208 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; 208 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
209 mw->move( QMAX(x,0), QMAX(y,0) ); 209 mw->move( QMAX(x,0), QMAX(y,0) );
210#ifdef Q_WS_QWS 210#ifdef Q_WS_QWS
211 if ( !nomaximize ) 211 if ( !nomaximize )
212 mw->showMaximized(); 212 mw->showMaximized();
213#endif 213#endif
214 } 214 }
215 if ( max && !nomaximize ) 215 if ( max && !nomaximize )
216 mw->showMaximized(); 216 mw->showMaximized();
217 else 217 else
218 mw->show(); 218 mw->show();
219 } 219 }
220 } 220 }
221 } 221 }
222// // ugly hack, remove that later after finding a sane solution
223// // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
224// // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
225// // a (physically) large enough display to use the small icons
226// #if defined(OPIE_HIGH_RES_SMALL_PHY)
227// if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
228// ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
229// }
230// #endif
231
232 // if ( mw->layout() && mw->inherits("QDialog") ) {
233 // QPEApplication::showDialog((QDialog*)mw, nomaximize);
234 // }
235 // else {
236// #ifdef Q_WS_QWS
237 // if ( !nomaximize ) {
238 // qDebug("QDialog special case XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
239 // mw->showMaximized();
240 // //QPEApplication::showWidget( mw, !nomaximize );
241 // }else
242// #endif
243 // mw->show();
244 // }
245 //}
246
247 222
248static void qpe_show_dialog( QDialog* d, bool nomax ) 223static void qpe_show_dialog( QDialog* d, bool nomax )
249{ 224{
250 QSize sh = d->sizeHint(); 225 QSize sh = d->sizeHint();
251 int w = QMAX(sh.width(),d->width()); 226 int w = QMAX(sh.width(),d->width());
252 int h = QMAX(sh.height(),d->height()); 227 int h = QMAX(sh.height(),d->height());
253 228
254 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() ) 229 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() )
255 nomax = TRUE; 230 nomax = TRUE;
256 231
257#ifndef Q_WS_QWS 232#ifndef Q_WS_QWS
258 QSize s(qApp->desktop()->width(), qApp->desktop()->height() ); 233 QSize s(qApp->desktop()->width(), qApp->desktop()->height() );
259#else 234#else
260 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() ); 235 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() );
261#endif 236#endif
262 237
263 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); 238 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width());
264 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); 239 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height());
265 240
266 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { 241 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) {
267 d->showMaximized(); 242 d->showMaximized();
268 } else { 243 } else {
269 // try centering the dialog around its parent 244 // try centering the dialog around its parent
270 QPoint p(0,0); 245 QPoint p(0,0);
271 if ( d->parentWidget() ) { 246 if ( d->parentWidget() ) {
272 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); 247 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
273 p = QPoint( pp.x() + d->parentWidget()->width()/2, 248 p = QPoint( pp.x() + d->parentWidget()->width()/2,
274 pp.y() + d->parentWidget()->height()/ 2 ); 249 pp.y() + d->parentWidget()->height()/ 2 );
275 } else { 250 } else {
276 p = QPoint( maxX/2, maxY/2 ); 251 p = QPoint( maxX/2, maxY/2 );
277 } 252 }
278 253
279 p = QPoint( p.x() - w/2, p.y() - h/2 ); 254 p = QPoint( p.x() - w/2, p.y() - h/2 );
280 //qDebug("p(x,y) is %d %d", p.x(), p.y() ); 255 //qDebug("p(x,y) is %d %d", p.x(), p.y() );
281 256
282 if ( w >= maxX ) { 257 if ( w >= maxX ) {
283 if ( p.y() < 0 ) 258 if ( p.y() < 0 )
284 p.setY(0); 259 p.setY(0);
285 if ( p.y() + h > maxY ) 260 if ( p.y() + h > maxY )
286 p.setY( maxY - h); 261 p.setY( maxY - h);
287 262
288 d->resize(maxX, h); 263 d->resize(maxX, h);
289 d->move(0, p.y() ); 264 d->move(0, p.y() );
290 } else if ( h >= maxY ) { 265 } else if ( h >= maxY ) {
291 if ( p.x() < 0 ) 266 if ( p.x() < 0 )
292 p.setX(0); 267 p.setX(0);
293 if ( p.x() + w > maxX ) 268 if ( p.x() + w > maxX )
294 p.setX( maxX - w); 269 p.setX( maxX - w);
295 270
296 d->resize(w, maxY); 271 d->resize(w, maxY);
297 d->move(p.x(),0); 272 d->move(p.x(),0);
298 } else { 273 } else {
299 d->resize(w, h); 274 d->resize(w, h);
300 } 275 }
301 276
302 d->show(); 277 d->show();
303 } 278 }
304} 279}
305 280
306 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) 281 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
307 { 282 {
308 maximized = TRUE; 283 maximized = TRUE;
309 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 284 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
310 if ( qApp->desktop()->width() <= 350 ) 285 if ( qApp->desktop()->width() <= 350 )
311 return FALSE; 286 return FALSE;
312 287
313 Config cfg( "qpe" ); 288 Config cfg( "qpe" );
314 cfg.setGroup("ApplicationPositions"); 289 cfg.setGroup("ApplicationPositions");
315 QString str = cfg.readEntry( app, QString::null ); 290 QString str = cfg.readEntry( app, QString::null );
316 QStringList l = QStringList::split(",", str); 291 QStringList l = QStringList::split(",", str);
317 292
318 if ( l.count() == 5) { 293 if ( l.count() == 5) {
319 p.setX( l[0].toInt() ); 294 p.setX( l[0].toInt() );
320 p.setY( l[1].toInt() ); 295 p.setY( l[1].toInt() );
321 296
322 s.setWidth( l[2].toInt() ); 297 s.setWidth( l[2].toInt() );
323 s.setHeight( l[3].toInt() ); 298 s.setHeight( l[3].toInt() );
324 299
325 maximized = l[4].toInt(); 300 maximized = l[4].toInt();
326 301
327 return TRUE; 302 return TRUE;
328 } 303 }
329 304
330 return FALSE; 305 return FALSE;
331 } 306 }
332 307
333 308
334 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 309 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
335 { 310 {
336#ifndef Q_WS_QWS 311#ifndef Q_WS_QWS
337 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 312 QRect qt_maxWindowRect = qApp->desktop()->geometry();
338#endif 313#endif
339 int maxX = qt_maxWindowRect.width(); 314 int maxX = qt_maxWindowRect.width();
340 int maxY = qt_maxWindowRect.height(); 315 int maxY = qt_maxWindowRect.height();
341 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 316 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
342 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 317 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
343 318
344 // total window size is not allowed to be larger than desktop window size 319 // total window size is not allowed to be larger than desktop window size
345 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 320 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
346 return FALSE; 321 return FALSE;
347 322
348 if ( wWidth > maxX ) { 323 if ( wWidth > maxX ) {
349 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 324 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
350 wWidth = maxX; 325 wWidth = maxX;
351 } 326 }
352 327
353 if ( wHeight > maxY ) { 328 if ( wHeight > maxY ) {
354 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 329 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
355 wHeight = maxY; 330 wHeight = maxY;
356 } 331 }
357 332
358 // any smaller than this and the maximize/close/help buttons will be overlapping 333 // any smaller than this and the maximize/close/help buttons will be overlapping
359 if ( wWidth < 80 || wHeight < 60 ) 334 if ( wWidth < 80 || wHeight < 60 )
360 return FALSE; 335 return FALSE;
361 336
362 if ( p.x() < 0 ) 337 if ( p.x() < 0 )
363 p.setX(0); 338 p.setX(0);
364 if ( p.y() < 0 ) 339 if ( p.y() < 0 )
365 p.setY(0); 340 p.setY(0);
366 341
367 if ( p.x() + wWidth > maxX ) 342 if ( p.x() + wWidth > maxX )
368 p.setX( maxX - wWidth ); 343 p.setX( maxX - wWidth );
369 if ( p.y() + wHeight > maxY ) 344 if ( p.y() + wHeight > maxY )
370 p.setY( maxY - wHeight ); 345 p.setY( maxY - wHeight );
371 346
372 return TRUE; 347 return TRUE;
373 } 348 }
374 349
375 static void store_widget_rect(QWidget *w, QString &app) 350 static void store_widget_rect(QWidget *w, QString &app)
376 { 351 {
377 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 352 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
378 if ( qApp->desktop()->width() <= 350 ) 353 if ( qApp->desktop()->width() <= 350 )
379 return; 354 return;
380 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 355 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
381 // get the non-maximized version, so we have to do it the hard way ) 356 // get the non-maximized version, so we have to do it the hard way )
382 int offsetX = w->x() - w->geometry().left(); 357 int offsetX = w->x() - w->geometry().left();
383 int offsetY = w->y() - w->geometry().top(); 358 int offsetY = w->y() - w->geometry().top();
384 359
385 QRect r; 360 QRect r;
386 if ( w->isMaximized() ) 361 if ( w->isMaximized() )
387 r = ( (HackWidget *) w)->normalGeometry(); 362 r = ( (HackWidget *) w)->normalGeometry();
388 else 363 else
389 r = w->geometry(); 364 r = w->geometry();
390 365
391 // Stores the window placement as pos(), size() (due to the offset mapping) 366 // Stores the window placement as pos(), size() (due to the offset mapping)
392 Config cfg( "qpe" ); 367 Config cfg( "qpe" );
393 cfg.setGroup("ApplicationPositions"); 368 cfg.setGroup("ApplicationPositions");
394 QString s; 369 QString s;
395 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 370 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
396 cfg.writeEntry( app, s ); 371 cfg.writeEntry( app, s );
397 } 372 }
398 373
399 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 374 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
400 { 375 {
401 /* 376 /*
402 // This works but disable it for now until it is safe to apply 377 // This works but disable it for now until it is safe to apply
403 // What is does is scan the .desktop files of all the apps for 378 // What is does is scan the .desktop files of all the apps for
404 // the applnk that has the corresponding argv[0] as this program 379 // the applnk that has the corresponding argv[0] as this program
405 // then it uses the name stored in the .desktop file as the caption 380 // then it uses the name stored in the .desktop file as the caption
406 // for the main widget. This saves duplicating translations for 381 // for the main widget. This saves duplicating translations for
407 // the app name in the program and in the .desktop files. 382 // the app name in the program and in the .desktop files.
408 383
409 AppLnkSet apps( appsPath ); 384 AppLnkSet apps( appsPath );
410 385
411 QList<AppLnk> appsList = apps.children(); 386 QList<AppLnk> appsList = apps.children();
412 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 387 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
413 if ( (*it)->exec() == appName ) { 388 if ( (*it)->exec() == appName ) {
414 mw->setCaption( (*it)->name() ); 389 mw->setCaption( (*it)->name() );
415 return TRUE; 390 return TRUE;
416 } 391 }
417 } 392 }
418 */ 393 */
419 return FALSE; 394 return FALSE;
420 } 395 }
421 396
422 397
423 void show(QWidget* mw, bool nomax) 398 void show(QWidget* mw, bool nomax)
424 { 399 {
425 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 400 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
426 nomaximize = nomax; 401 nomaximize = nomax;
427 qpe_main_widget = mw; 402 qpe_main_widget = mw;
428 qcopQok = TRUE; 403 qcopQok = TRUE;
429#ifndef QT_NO_COP 404#ifndef QT_NO_COP
430 405
431 sendQCopQ(); 406 sendQCopQ();
432#endif 407#endif
433 408
434 if ( preloaded ) { 409 if ( preloaded ) {
435 if (forceshow) 410 if (forceshow)
436 show_mx(mw, nomax, appName); 411 show_mx(mw, nomax, appName);
437 } 412 }
438 else if ( keep_running ) { 413 else if ( keep_running ) {
439 show_mx(mw, nomax, appName); 414 show_mx(mw, nomax, appName);
440 } 415 }
441 } 416 }
442 417
443 void loadTextCodecs() 418 void loadTextCodecs()
444 { 419 {
445 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 420 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
446#ifdef Q_OS_MACX 421#ifdef Q_OS_MACX
447 QDir dir( path, "lib*.dylib" ); 422 QDir dir( path, "lib*.dylib" );
448#else 423#else
449 QDir dir( path, "lib*.so" ); 424 QDir dir( path, "lib*.so" );
450#endif 425#endif
451 QStringList list; 426 QStringList list;
452 if ( dir. exists ( )) 427 if ( dir. exists ( ))
453 list = dir.entryList(); 428 list = dir.entryList();
454 QStringList::Iterator it; 429 QStringList::Iterator it;
455 for ( it = list.begin(); it != list.end(); ++it ) { 430 for ( it = list.begin(); it != list.end(); ++it ) {
456 TextCodecInterface *iface = 0; 431 TextCodecInterface *iface = 0;
457 QLibrary *lib = new QLibrary( path + "/" + *it ); 432 QLibrary *lib = new QLibrary( path + "/" + *it );
458 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 433 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
459 QValueList<int> mibs = iface->mibEnums(); 434 QValueList<int> mibs = iface->mibEnums();
460 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 435 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
461 (void)iface->createForMib(*i); 436 (void)iface->createForMib(*i);
462 // ### it exists now; need to remember if we can delete it 437 // ### it exists now; need to remember if we can delete it
463 } 438 }
464 } 439 }
465 else { 440 else {
466 lib->unload(); 441 lib->unload();
467 delete lib; 442 delete lib;
468 } 443 }
469 } 444 }
470 } 445 }
471 446
472 void loadImageCodecs() 447 void loadImageCodecs()
473 { 448 {
474 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 449 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
475#ifdef Q_OS_MACX 450#ifdef Q_OS_MACX
476 QDir dir( path, "lib*.dylib" ); 451 QDir dir( path, "lib*.dylib" );
477#else 452#else
478 QDir dir( path, "lib*.so" ); 453 QDir dir( path, "lib*.so" );
479#endif 454#endif
480 QStringList list; 455 QStringList list;
481 if ( dir. exists ( )) 456 if ( dir. exists ( ))
482 list = dir.entryList(); 457 list = dir.entryList();
483 QStringList::Iterator it; 458 QStringList::Iterator it;
484 for ( it = list.begin(); it != list.end(); ++it ) { 459 for ( it = list.begin(); it != list.end(); ++it ) {
485 ImageCodecInterface *iface = 0; 460 ImageCodecInterface *iface = 0;
486 QLibrary *lib = new QLibrary( path + "/" + *it ); 461 QLibrary *lib = new QLibrary( path + "/" + *it );
487 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 462 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
488 QStringList formats = iface->keys(); 463 QStringList formats = iface->keys();
489 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 464 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
490 (void)iface->installIOHandler(*i); 465 (void)iface->installIOHandler(*i);
491 // ### it exists now; need to remember if we can delete it 466 // ### it exists now; need to remember if we can delete it
492 } 467 }
493 } 468 }
494 else { 469 else {
495 lib->unload(); 470 lib->unload();
496 delete lib; 471 delete lib;
497 } 472 }
498 } 473 }
499 } 474 }
500}; 475};
501 476
502class ResourceMimeFactory : public QMimeSourceFactory 477class ResourceMimeFactory : public QMimeSourceFactory
503{ 478{
504public: 479public:
505 ResourceMimeFactory() : resImage( 0 ) 480 ResourceMimeFactory() : resImage( 0 )
506 { 481 {
507 setFilePath( Global::helpPath() ); 482 setFilePath( Global::helpPath() );
508 setExtensionType( "html", "text/html;charset=UTF-8" ); 483 setExtensionType( "html", "text/html;charset=UTF-8" );
509 } 484 }
510 ~ResourceMimeFactory() { 485 ~ResourceMimeFactory() {
511 delete resImage; 486 delete resImage;
512 } 487 }
513 488
514 const QMimeSource* data( const QString& abs_name ) const 489 const QMimeSource* data( const QString& abs_name ) const
515 { 490 {
516 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 491 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
517 if ( !r ) { 492 if ( !r ) {
518 int sl = abs_name.length(); 493 int sl = abs_name.length();
519 do { 494 do {
520 sl = abs_name.findRev( '/', sl - 1 ); 495 sl = abs_name.findRev( '/', sl - 1 );
521 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 496 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
522 int dot = name.findRev( '.' ); 497 int dot = name.findRev( '.' );
523 if ( dot >= 0 ) 498 if ( dot >= 0 )
524 name = name.left( dot ); 499 name = name.left( dot );
525 QImage img = Resource::loadImage( name ); 500 QImage img = Resource::loadImage( name );
526 if ( !img.isNull() ) { 501 if ( !img.isNull() ) {
527 delete resImage; 502 delete resImage;
528 resImage = new QImageDrag( img ); 503 resImage = new QImageDrag( img );
529 r = resImage; 504 r = resImage;
530 } 505 }
531 } 506 }
532 while ( !r && sl > 0 ); 507 while ( !r && sl > 0 );
533 } 508 }
534 return r; 509 return r;
535 } 510 }
536private: 511private:
537 mutable QImageDrag *resImage; 512 mutable QImageDrag *resImage;
538}; 513};
539 514
540static int& hack(int& i) 515static int& hack(int& i)
541{ 516{
542#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 517#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
543 // These should be created, but aren't in Qt 2.3.0 518 // These should be created, but aren't in Qt 2.3.0
544 (void)new QUtf8Codec; 519 (void)new QUtf8Codec;
545 (void)new QUtf16Codec; 520 (void)new QUtf16Codec;
546#endif 521#endif
547 return i; 522 return i;
548} 523}
549 524
550static int muted = 0; 525static int muted = 0;
551static int micMuted = 0; 526static int micMuted = 0;
552 527
553static void setVolume( int t = 0, int percent = -1 ) 528static void setVolume( int t = 0, int percent = -1 )
554{ 529{
555 switch ( t ) { 530 switch ( t ) {
556 case 0: { 531 case 0: {
557 Config cfg( "qpe" ); 532 Config cfg( "qpe" );
558 cfg.setGroup( "Volume" ); 533 cfg.setGroup( "Volume" );
559 if ( percent < 0 ) 534 if ( percent < 0 )
560 percent = cfg.readNumEntry( "VolumePercent", 50 ); 535 percent = cfg.readNumEntry( "VolumePercent", 50 );
561#ifndef QT_NO_SOUND 536#ifndef QT_NO_SOUND
562 int fd = 0; 537 int fd = 0;
563 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 538 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
564 int vol = muted ? 0 : percent; 539 int vol = muted ? 0 : percent;
565 // set both channels to same volume 540 // set both channels to same volume
566 vol |= vol << 8; 541 vol |= vol << 8;
567 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 542 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
568 ::close( fd ); 543 ::close( fd );
569 } 544 }
570#endif 545#endif
571 } 546 }
572 break; 547 break;
573 } 548 }
574} 549}
575 550
576static void setMic( int t = 0, int percent = -1 ) 551static void setMic( int t = 0, int percent = -1 )
577{ 552{
578 switch ( t ) { 553 switch ( t ) {
579 case 0: { 554 case 0: {
580 Config cfg( "qpe" ); 555 Config cfg( "qpe" );
581 cfg.setGroup( "Volume" ); 556 cfg.setGroup( "Volume" );
582 if ( percent < 0 ) 557 if ( percent < 0 )
583 percent = cfg.readNumEntry( "Mic", 50 ); 558 percent = cfg.readNumEntry( "Mic", 50 );
584 559
585#ifndef QT_NO_SOUND 560#ifndef QT_NO_SOUND
586 int fd = 0; 561 int fd = 0;
587 int mic = micMuted ? 0 : percent; 562 int mic = micMuted ? 0 : percent;
588 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 563 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
589 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 564 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
590 ::close( fd ); 565 ::close( fd );
591 } 566 }
592#endif 567#endif
593 } 568 }
594 break; 569 break;
595 } 570 }
596} 571}
597 572
598 573
599static void setBass( int t = 0, int percent = -1 ) 574static void setBass( int t = 0, int percent = -1 )
600{ 575{
601 switch ( t ) { 576 switch ( t ) {
602 case 0: { 577 case 0: {
603 Config cfg( "qpe" ); 578 Config cfg( "qpe" );
604 cfg.setGroup( "Volume" ); 579 cfg.setGroup( "Volume" );
605 if ( percent < 0 ) 580 if ( percent < 0 )
606 percent = cfg.readNumEntry( "BassPercent", 50 ); 581 percent = cfg.readNumEntry( "BassPercent", 50 );
607 582
608#ifndef QT_NO_SOUND 583#ifndef QT_NO_SOUND
609 int fd = 0; 584 int fd = 0;
610 int bass = percent; 585 int bass = percent;
611 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 586 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
612 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 587 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
613 ::close( fd ); 588 ::close( fd );
614 } 589 }
615#endif 590#endif
616 } 591 }
617 break; 592 break;
618 } 593 }
619} 594}
620 595
621 596
622static void setTreble( int t = 0, int percent = -1 ) 597static void setTreble( int t = 0, int percent = -1 )
623{ 598{
624 switch ( t ) { 599 switch ( t ) {
625 case 0: { 600 case 0: {
626 Config cfg( "qpe" ); 601 Config cfg( "qpe" );
627 cfg.setGroup( "Volume" ); 602 cfg.setGroup( "Volume" );
628 if ( percent < 0 ) 603 if ( percent < 0 )
629 percent = cfg.readNumEntry( "TreblePercent", 50 ); 604 percent = cfg.readNumEntry( "TreblePercent", 50 );
630 605
631#ifndef QT_NO_SOUND 606#ifndef QT_NO_SOUND
632 int fd = 0; 607 int fd = 0;
633 int treble = percent; 608 int treble = percent;
634 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 609 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
635 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 610 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
636 ::close( fd ); 611 ::close( fd );
637 } 612 }
638#endif 613#endif
639 } 614 }
640 break; 615 break;
641 } 616 }
642} 617}
643 618
644 619
645/** 620/**
646 \class QPEApplication 621 \class QPEApplication
647 \brief The QPEApplication class implements various system services 622 \brief The QPEApplication class implements various system services
648 that are available to all Qtopia applications. 623 that are available to all Qtopia applications.
649 624
650 Simply by using QPEApplication instead of QApplication, a standard Qt 625 Simply by using QPEApplication instead of QApplication, a standard Qt
651 application becomes a Qtopia application. It automatically follows 626 application becomes a Qtopia application. It automatically follows
652 style changes, quits and raises, and in the 627 style changes, quits and raises, and in the
653 case of \link docwidget.html document-oriented\endlink applications, 628 case of \link docwidget.html document-oriented\endlink applications,
654 changes the currently displayed document in response to the environment. 629 changes the currently displayed document in response to the environment.
655 630
656 To create a \link docwidget.html document-oriented\endlink 631 To create a \link docwidget.html document-oriented\endlink
657 application use showMainDocumentWidget(); to create a 632 application use showMainDocumentWidget(); to create a
658 non-document-oriented application use showMainWidget(). The 633 non-document-oriented application use showMainWidget(). The
659 keepRunning() function indicates whether the application will 634 keepRunning() function indicates whether the application will
660 continue running after it's processed the last \link qcop.html 635 continue running after it's processed the last \link qcop.html
661 QCop\endlink message. This can be changed using setKeepRunning(). 636 QCop\endlink message. This can be changed using setKeepRunning().
662 637
663 A variety of signals are emitted when certain events occur, for 638 A variety of signals are emitted when certain events occur, for
664 example, timeChanged(), clockChanged(), weekChanged(), 639 example, timeChanged(), clockChanged(), weekChanged(),
665 dateFormatChanged() and volumeChanged(). If the application receives 640 dateFormatChanged() and volumeChanged(). If the application receives
666 a \link qcop.html QCop\endlink message on the application's 641 a \link qcop.html QCop\endlink message on the application's
667 QPE/Application/\e{appname} channel, the appMessage() signal is 642 QPE/Application/\e{appname} channel, the appMessage() signal is
668 emitted. There are also flush() and reload() signals, which 643 emitted. There are also flush() and reload() signals, which
669 are emitted when synching begins and ends respectively - upon these 644 are emitted when synching begins and ends respectively - upon these
670 signals, the application should save and reload any data 645 signals, the application should save and reload any data
671 files that are involved in synching. Most of these signals will initially 646 files that are involved in synching. Most of these signals will initially
672 be received and unfiltered through the appMessage() signal. 647 be received and unfiltered through the appMessage() signal.
673 648
674 This class also provides a set of useful static functions. The 649 This class also provides a set of useful static functions. The
675 qpeDir() and documentDir() functions return the respective paths. 650 qpeDir() and documentDir() functions return the respective paths.
676 The grabKeyboard() and ungrabKeyboard() functions are used to 651 The grabKeyboard() and ungrabKeyboard() functions are used to
677 control whether the application takes control of the device's 652 control whether the application takes control of the device's
678 physical buttons (e.g. application launch keys). The stylus' mode of 653 physical buttons (e.g. application launch keys). The stylus' mode of
679 operation is set with setStylusOperation() and retrieved with 654 operation is set with setStylusOperation() and retrieved with
680 stylusOperation(). There are also setInputMethodHint() and 655 stylusOperation(). There are also setInputMethodHint() and
681 inputMethodHint() functions. 656 inputMethodHint() functions.
682 657
683 \ingroup qtopiaemb 658 \ingroup qtopiaemb
684*/ 659*/
685 660
686/*! 661/*!
687 \fn void QPEApplication::clientMoused() 662 \fn void QPEApplication::clientMoused()
688 663
689 \internal 664 \internal
690*/ 665*/
691 666
692/*! 667/*!
693 \fn void QPEApplication::timeChanged(); 668 \fn void QPEApplication::timeChanged();
694 This signal is emitted when the time changes outside the normal 669 This signal is emitted when the time changes outside the normal
695 passage of time, i.e. if the time is set backwards or forwards. 670 passage of time, i.e. if the time is set backwards or forwards.
696*/ 671*/
697 672
698/*! 673/*!
699 \fn void QPEApplication::clockChanged( bool ampm ); 674 \fn void QPEApplication::clockChanged( bool ampm );
700 675
701 This signal is emitted when the user changes the clock's style. If 676 This signal is emitted when the user changes the clock's style. If
702 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 677 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
703 they want a 24-hour clock. 678 they want a 24-hour clock.
704*/ 679*/
705 680
706/*! 681/*!
707 \fn void QPEApplication::volumeChanged( bool muted ) 682 \fn void QPEApplication::volumeChanged( bool muted )
708 683
709 This signal is emitted whenever the mute state is changed. If \a 684 This signal is emitted whenever the mute state is changed. If \a
710 muted is TRUE, then sound output has been muted. 685 muted is TRUE, then sound output has been muted.
711*/ 686*/
712 687
713/*! 688/*!
714 \fn void QPEApplication::weekChanged( bool startOnMonday ) 689 \fn void QPEApplication::weekChanged( bool startOnMonday )
715 690
716 This signal is emitted if the week start day is changed. If \a 691 This signal is emitted if the week start day is changed. If \a
717 startOnMonday is TRUE then the first day of the week is Monday; if 692 startOnMonday is TRUE then the first day of the week is Monday; if
718 \a startOnMonday is FALSE then the first day of the week is 693 \a startOnMonday is FALSE then the first day of the week is
719 Sunday. 694 Sunday.
720*/ 695*/
721 696
722/*! 697/*!
723 \fn void QPEApplication::dateFormatChanged(DateFormat) 698 \fn void QPEApplication::dateFormatChanged(DateFormat)
724 699
725 This signal is emitted whenever the date format is changed. 700 This signal is emitted whenever the date format is changed.
726*/ 701*/
727 702
728/*! 703/*!
729 \fn void QPEApplication::flush() 704 \fn void QPEApplication::flush()
730 705
731 ### 706 ###
732*/ 707*/
733 708
734/*! 709/*!
735 \fn void QPEApplication::reload() 710 \fn void QPEApplication::reload()
736 711
737*/ 712*/
738 713
739 714
740 715
741void QPEApplication::processQCopFile() 716void QPEApplication::processQCopFile()
742{ 717{
743 QString qcopfn("/tmp/qcop-msg-"); 718 QString qcopfn("/tmp/qcop-msg-");
744 qcopfn += d->appName; // append command name 719 qcopfn += d->appName; // append command name
745 720
746 QFile f(qcopfn); 721 QFile f(qcopfn);
747 if ( f.open(IO_ReadWrite) ) { 722 if ( f.open(IO_ReadWrite) ) {
748#ifndef Q_OS_WIN32 723#ifndef Q_OS_WIN32
749 flock(f.handle(), LOCK_EX); 724 flock(f.handle(), LOCK_EX);
750#endif 725#endif
751 QDataStream ds(&f); 726 QDataStream ds(&f);
752 QCString channel, message; 727 QCString channel, message;
753 QByteArray data; 728 QByteArray data;
754 while(!ds.atEnd()) { 729 while(!ds.atEnd()) {
755 ds >> channel >> message >> data; 730 ds >> channel >> message >> data;
756 d->enqueueQCop(channel,message,data); 731 d->enqueueQCop(channel,message,data);
757 } 732 }
758 ::ftruncate(f.handle(), 0); 733 ::ftruncate(f.handle(), 0);
759#ifndef Q_OS_WIN32 734#ifndef Q_OS_WIN32
760 f.flush(); 735 f.flush();
761 flock(f.handle(), LOCK_UN); 736 flock(f.handle(), LOCK_UN);
762#endif 737#endif
763 } 738 }
764#endif 739#endif
765} 740}
766 741
767 742
768/*! 743/*!
769 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 744 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
770 745
771 This signal is emitted when a message is received on this 746 This signal is emitted when a message is received on this
772 application's QPE/Application/<i>appname</i> \link qcop.html 747 application's QPE/Application/<i>appname</i> \link qcop.html
773 QCop\endlink channel. 748 QCop\endlink channel.
774 749
775 The slot to which you connect this signal uses \a msg and \a data 750 The slot to which you connect this signal uses \a msg and \a data
776 in the following way: 751 in the following way:
777 752
778\code 753\code
779 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 754 void MyWidget::receive( const QCString& msg, const QByteArray& data )
780 { 755 {
781 QDataStream stream( data, IO_ReadOnly ); 756 QDataStream stream( data, IO_ReadOnly );
782 if ( msg == "someMessage(int,int,int)" ) { 757 if ( msg == "someMessage(int,int,int)" ) {
783 int a,b,c; 758 int a,b,c;
784 stream >> a >> b >> c; 759 stream >> a >> b >> c;
785 ... 760 ...
786 } else if ( msg == "otherMessage(QString)" ) { 761 } else if ( msg == "otherMessage(QString)" ) {
787 ... 762 ...
788 } 763 }
789 } 764 }
790\endcode 765\endcode
791 766
792 \sa qcop.html 767 \sa qcop.html
793 Note that messages received here may be processed by qpe application 768 Note that messages received here may be processed by qpe application
794 and emitted as signals, such as flush() and reload(). 769 and emitted as signals, such as flush() and reload().
795*/ 770*/
796 771
797/*! 772/*!
798 Constructs a QPEApplication just as you would construct 773 Constructs a QPEApplication just as you would construct
799 a QApplication, passing \a argc, \a argv, and \a t. 774 a QApplication, passing \a argc, \a argv, and \a t.
800 775
801 For applications, \a t should be the default, GuiClient. Only 776 For applications, \a t should be the default, GuiClient. Only
802 the Qtopia server passes GuiServer. 777 the Qtopia server passes GuiServer.
803*/ 778*/
804QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 779QPEApplication::QPEApplication( int & argc, char **argv, Type t )
805 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 780 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
806{ 781{
807 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 782 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
808 783
809 d = new QPEApplicationData; 784 d = new QPEApplicationData;
810 d->loadTextCodecs(); 785 d->loadTextCodecs();
811 d->loadImageCodecs(); 786 d->loadImageCodecs();
812 int dw = desktop() ->width(); 787 int dw = desktop() ->width();
813 788
814 if ( dw < 200 ) { 789 if ( dw < 200 ) {
815 setFont( QFont( "vera", 8 ) ); 790 setFont( QFont( "vera", 8 ) );
816 AppLnk::setSmallIconSize( 10 ); 791 AppLnk::setSmallIconSize( 10 );
817 AppLnk::setBigIconSize( 28 ); 792 AppLnk::setBigIconSize( 28 );
818 } 793 }
819#if defined(OPIE_HIGH_RES_SMALL_PHY) 794#if defined(OPIE_HIGH_RES_SMALL_PHY)
820 else if ( dw > 600 ) { 795 else if ( dw > 600 ) {
821 setFont( QFont( "vera", 16 ) ); 796 setFont( QFont( "vera", 16 ) );
822 AppLnk::setSmallIconSize( 24 ); 797 AppLnk::setSmallIconSize( 24 );
823 AppLnk::setBigIconSize( 48 ); 798 AppLnk::setBigIconSize( 48 );
824 } 799 }
825#endif 800#endif
826 else if ( dw > 200 ) { 801 else if ( dw > 200 ) {
827 setFont( QFont( "vera", 10 ) ); 802 setFont( QFont( "vera", 10 ) );
828 AppLnk::setSmallIconSize( 14 ); 803 AppLnk::setSmallIconSize( 14 );
829 AppLnk::setBigIconSize( 32 ); 804 AppLnk::setBigIconSize( 32 );
830 } 805 }
831 806
832 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 807 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
833 808
834 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 809 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
835 810
836 811
837 sysChannel = new QCopChannel( "QPE/System", this ); 812 sysChannel = new QCopChannel( "QPE/System", this );
838 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 813 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
839 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); 814 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
840 815
841/* COde now in initapp */ 816/* COde now in initapp */
842#if 0 817#if 0
843#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 818#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
844 819
845 QString qcopfn( "/tmp/qcop-msg-" ); 820 QString qcopfn( "/tmp/qcop-msg-" );
846 qcopfn += QString( argv[ 0 ] ); // append command name 821 qcopfn += QString( argv[ 0 ] ); // append command name
847 822
848 QFile f( qcopfn ); 823 QFile f( qcopfn );
849 if ( f.open( IO_ReadOnly ) ) { 824 if ( f.open( IO_ReadOnly ) ) {
850 flock( f.handle(), LOCK_EX ); 825 flock( f.handle(), LOCK_EX );
851 } 826 }
852 827
853 828
854 829
855 QCString channel = QCString( argv[ 0 ] ); 830 QCString channel = QCString( argv[ 0 ] );
856 channel.replace( QRegExp( ".*/" ), "" ); 831 channel.replace( QRegExp( ".*/" ), "" );
857 d->appName = channel; 832 d->appName = channel;
858 channel = "QPE/Application/" + channel; 833 channel = "QPE/Application/" + channel;
859 pidChannel = new QCopChannel( channel, this ); 834 pidChannel = new QCopChannel( channel, this );
860 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 835 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
861 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 836 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
862 837
863 if ( f.isOpen() ) { 838 if ( f.isOpen() ) {
864 d->keep_running = FALSE; 839 d->keep_running = FALSE;
865 QDataStream ds( &f ); 840 QDataStream ds( &f );
866 QCString channel, message; 841 QCString channel, message;
867 QByteArray data; 842 QByteArray data;
868 while ( !ds.atEnd() ) { 843 while ( !ds.atEnd() ) {
869 ds >> channel >> message >> data; 844 ds >> channel >> message >> data;
870 d->enqueueQCop( channel, message, data ); 845 d->enqueueQCop( channel, message, data );
871 } 846 }
872 847
873 flock( f.handle(), LOCK_UN ); 848 flock( f.handle(), LOCK_UN );
874 f.close(); 849 f.close();
875 f.remove(); 850 f.remove();
876 } 851 }
877 852
878 for ( int a = 0; a < argc; a++ ) { 853 for ( int a = 0; a < argc; a++ ) {
879 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 854 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
880 argv[ a ] = argv[ a + 1 ]; 855 argv[ a ] = argv[ a + 1 ];
881 a++; 856 a++;
882 d->preloaded = TRUE; 857 d->preloaded = TRUE;
883 argc -= 1; 858 argc -= 1;
884 } 859 }
885 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 860 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
886 argv[ a ] = argv[ a + 1 ]; 861 argv[ a ] = argv[ a + 1 ];
887 a++; 862 a++;
888 d->preloaded = TRUE; 863 d->preloaded = TRUE;
889 d->forceshow = TRUE; 864 d->forceshow = TRUE;
890 argc -= 1; 865 argc -= 1;
891 } 866 }
892 } 867 }
893 868
894 /* overide stored arguments */ 869 /* overide stored arguments */
895 setArgs( argc, argv ); 870 setArgs( argc, argv );
896 871
897#endif 872#endif
898#else 873#else
899 initApp( argc, argv ); 874 initApp( argc, argv );
900#endif 875#endif
901 // qwsSetDecoration( new QPEDecoration() ); 876 // qwsSetDecoration( new QPEDecoration() );
902 877
903#ifndef QT_NO_TRANSLATION 878#ifndef QT_NO_TRANSLATION
904 879
905 d->langs = Global::languageList(); 880 d->langs = Global::languageList();
906 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 881 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
907 QString lang = *it; 882 QString lang = *it;
908 883
909 installTranslation( lang + "/libopie.qm"); 884 installTranslation( lang + "/libopie.qm");
910 installTranslation( lang + "/libqpe.qm" ); 885 installTranslation( lang + "/libqpe.qm" );
911 installTranslation( lang + "/" + d->appName + ".qm" ); 886 installTranslation( lang + "/" + d->appName + ".qm" );
912 887
913 888
914 //###language/font hack; should look it up somewhere 889 //###language/font hack; should look it up somewhere
915#ifdef QWS 890#ifdef QWS
916 891
917 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 892 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
918 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 893 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
919 setFont( fn ); 894 setFont( fn );
920 } 895 }
921#endif 896#endif
922 } 897 }
923#endif 898#endif
924 899
925 applyStyle(); 900 applyStyle();
926 901
927 if ( type() == GuiServer ) { 902 if ( type() == GuiServer ) {
928 setVolume(); 903 setVolume();
929 } 904 }
930 905
931 installEventFilter( this ); 906 installEventFilter( this );
932 907
933 QPEMenuToolFocusManager::initialize(); 908 QPEMenuToolFocusManager::initialize();
934 909
935#ifdef QT_NO_QWS_CURSOR 910#ifdef QT_NO_QWS_CURSOR
936 // if we have no cursor, probably don't want tooltips 911 // if we have no cursor, probably don't want tooltips
937 QToolTip::setEnabled( FALSE ); 912 QToolTip::setEnabled( FALSE );
938#endif 913#endif
939} 914}
940 915
941 916
942#ifdef QTOPIA_INTERNAL_INITAPP 917#ifdef QTOPIA_INTERNAL_INITAPP
943void QPEApplication::initApp( int argc, char **argv ) 918void QPEApplication::initApp( int argc, char **argv )
944{ 919{
945 delete pidChannel; 920 delete pidChannel;
946 d->keep_running = TRUE; 921 d->keep_running = TRUE;
947 d->preloaded = FALSE; 922 d->preloaded = FALSE;
948 d->forceshow = FALSE; 923 d->forceshow = FALSE;
949 924
950 QCString channel = QCString(argv[0]); 925 QCString channel = QCString(argv[0]);
951 926
952 channel.replace(QRegExp(".*/"),""); 927 channel.replace(QRegExp(".*/"),"");
953 d->appName = channel; 928 d->appName = channel;
954 929
955 #if QT_VERSION > 235 930 #if QT_VERSION > 235
956 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 931 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
957 #endif 932 #endif
958 933
959 channel = "QPE/Application/" + channel; 934 channel = "QPE/Application/" + channel;
960 pidChannel = new QCopChannel( channel, this); 935 pidChannel = new QCopChannel( channel, this);
961 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 936 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
962 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 937 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
963 938
964 939
965 940
966 processQCopFile(); 941 processQCopFile();
967 d->keep_running = d->qcopq.isEmpty(); 942 d->keep_running = d->qcopq.isEmpty();
968 943
969 for (int a=0; a<argc; a++) { 944 for (int a=0; a<argc; a++) {
970 if ( qstrcmp(argv[a],"-preload")==0 ) { 945 if ( qstrcmp(argv[a],"-preload")==0 ) {
971 argv[a] = argv[a+1]; 946 argv[a] = argv[a+1];
972 a++; 947 a++;
973 d->preloaded = TRUE; 948 d->preloaded = TRUE;
974 argc-=1; 949 argc-=1;
975 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 950 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
976 argv[a] = argv[a+1]; 951 argv[a] = argv[a+1];
977 a++; 952 a++;
978 d->preloaded = TRUE; 953 d->preloaded = TRUE;
979 d->forceshow = TRUE; 954 d->forceshow = TRUE;
980 argc-=1; 955 argc-=1;
981 } 956 }
982 } 957 }
983 958
984 /* overide stored arguments */ 959 /* overide stored arguments */
985 setArgs(argc, argv); 960 setArgs(argc, argv);
986 961
987 /* install translation here */ 962 /* install translation here */
988 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 963 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
989 installTranslation( (*it) + "/" + d->appName + ".qm" ); 964 installTranslation( (*it) + "/" + d->appName + ".qm" );
990} 965}
991#endif 966#endif
992 967
993 968
994static QPtrDict<void>* inputMethodDict = 0; 969static QPtrDict<void>* inputMethodDict = 0;
995static void createInputMethodDict() 970static void createInputMethodDict()
996{ 971{
997 if ( !inputMethodDict ) 972 if ( !inputMethodDict )
998 inputMethodDict = new QPtrDict<void>; 973 inputMethodDict = new QPtrDict<void>;
999} 974}
1000 975
1001/*! 976/*!
1002 Returns the currently set hint to the system as to whether 977 Returns the currently set hint to the system as to whether
1003 widget \a w has any use for text input methods. 978 widget \a w has any use for text input methods.
1004 979
1005 980
1006 \sa setInputMethodHint() InputMethodHint 981 \sa setInputMethodHint() InputMethodHint
1007*/ 982*/
1008QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 983QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
1009{ 984{
1010 if ( inputMethodDict && w ) 985 if ( inputMethodDict && w )
1011 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 986 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
1012 return Normal; 987 return Normal;
1013} 988}
1014 989
1015/*! 990/*!
1016 \enum QPEApplication::InputMethodHint 991 \enum QPEApplication::InputMethodHint
1017 992
1018 \value Normal the application sometimes needs text input (the default). 993 \value Normal the application sometimes needs text input (the default).
1019 \value AlwaysOff the application never needs text input. 994 \value AlwaysOff the application never needs text input.
1020 \value AlwaysOn the application always needs text input. 995 \value AlwaysOn the application always needs text input.
1021*/ 996*/
1022 997
1023/*! 998/*!
1024 Hints to the system that widget \a w has use for text input methods 999 Hints to the system that widget \a w has use for text input methods
1025 as specified by \a mode. 1000 as specified by \a mode.
1026 1001
1027 \sa inputMethodHint() InputMethodHint 1002 \sa inputMethodHint() InputMethodHint
1028*/ 1003*/
1029void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1004void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
1030{ 1005{
1031 createInputMethodDict(); 1006 createInputMethodDict();
1032 if ( mode == Normal ) { 1007 if ( mode == Normal ) {
1033 inputMethodDict->remove 1008 inputMethodDict->remove
1034 ( w ); 1009 ( w );
1035 } 1010 }
1036 else { 1011 else {
1037 inputMethodDict->insert( w, ( void* ) mode ); 1012 inputMethodDict->insert( w, ( void* ) mode );
1038 } 1013 }
1039} 1014}
1040 1015
1041class HackDialog : public QDialog 1016class HackDialog : public QDialog
1042{ 1017{
1043public: 1018public:
1044 void acceptIt() 1019 void acceptIt()
1045 { 1020 {
1046 accept(); 1021 accept();
1047 } 1022 }
1048 void rejectIt() 1023 void rejectIt()
1049 { 1024 {
1050 reject(); 1025 reject();
1051 } 1026 }
1052}; 1027};
1053 1028
1054 1029
1055void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1030void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
1056{ 1031{
1057 // specialised actions for certain widgets. May want to 1032 // specialised actions for certain widgets. May want to
1058 // add more stuff here. 1033 // add more stuff here.
1059 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1034 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
1060 && activePopupWidget() ->parentWidget() 1035 && activePopupWidget() ->parentWidget()
1061 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1036 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
1062 key = Qt::Key_Return; 1037 key = Qt::Key_Return;
1063 1038
1064 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1039 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
1065 key = Qt::Key_Return; 1040 key = Qt::Key_Return;
1066 1041
1067#ifdef QWS 1042#ifdef QWS
1068 1043
1069 ke->simpleData.keycode = key; 1044 ke->simpleData.keycode = key;
1070#endif 1045#endif
1071} 1046}
1072 1047
1073// class HackWidget : public QWidget 1048// class HackWidget : public QWidget
1074// { 1049// {
1075// public: 1050// public:
1076 // bool needsOk() 1051 // bool needsOk()
1077 // { 1052 // {
1078 // return ( getWState() & WState_Reserved1 ); 1053 // return ( getWState() & WState_Reserved1 );
1079 // } 1054 // }
1080// }; 1055// };
1081 1056
1082/*! 1057/*!
1083 \internal 1058 \internal
1084*/ 1059*/
1085 1060
1086#ifdef QWS 1061#ifdef QWS
1087bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1062bool QPEApplication::qwsEventFilter( QWSEvent * e )
1088{ 1063{
1089 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1064 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
1090 if ( qApp->type() != QApplication::GuiServer ) { 1065 if ( qApp->type() != QApplication::GuiServer ) {
1091 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1066 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
1092 e << d->appName; 1067 e << d->appName;
1093 } 1068 }
1094 d->notbusysent = TRUE; 1069 d->notbusysent = TRUE;
1095 } 1070 }
1096 if ( type() == GuiServer ) { 1071 if ( type() == GuiServer ) {
1097 switch ( e->type ) { 1072 switch ( e->type ) {
1098 case QWSEvent::Mouse: 1073 case QWSEvent::Mouse:
1099 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1074 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
1100 emit clientMoused(); 1075 emit clientMoused();
1101 break; 1076 break;
1102 default: 1077 default:
1103 break; 1078 break;
1104 } 1079 }
1105 } 1080 }
1106 if ( e->type == QWSEvent::Key ) { 1081 if ( e->type == QWSEvent::Key ) {
1107 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1082 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
1108 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1083 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
1109 // Use special "OK" key to press "OK" on top level widgets 1084 // Use special "OK" key to press "OK" on top level widgets
1110 QWidget * active = activeWindow(); 1085 QWidget * active = activeWindow();
1111 QWidget *popup = 0; 1086 QWidget *popup = 0;
1112 if ( active && active->isPopup() ) { 1087 if ( active && active->isPopup() ) {
1113 popup = active; 1088 popup = active;
1114 active = active->parentWidget(); 1089 active = active->parentWidget();
1115 } 1090 }
1116 if ( active && ( int ) active->winId() == ke->simpleData.window && 1091 if ( active && ( int ) active->winId() == ke->simpleData.window &&
1117 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1092 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1118 if ( ke->simpleData.is_press ) { 1093 if ( ke->simpleData.is_press ) {
1119 if ( popup ) 1094 if ( popup )
1120 popup->close(); 1095 popup->close();
1121 if ( active->inherits( "QDialog" ) ) { 1096 if ( active->inherits( "QDialog" ) ) {
1122 HackDialog * d = ( HackDialog * ) active; 1097 HackDialog * d = ( HackDialog * ) active;
1123 d->acceptIt(); 1098 d->acceptIt();
1124 return TRUE; 1099 return TRUE;
1125 } 1100 }
1126 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1101 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
1127 QSignal s; 1102 QSignal s;
1128 s.connect( active, SLOT( accept() ) ); 1103 s.connect( active, SLOT( accept() ) );
1129 s.activate(); 1104 s.activate();
1130 } 1105 }
1131 else { 1106 else {
1132 // do the same as with the select key: Map to the default action of the widget: 1107 // do the same as with the select key: Map to the default action of the widget:
1133 mapToDefaultAction( ke, Qt::Key_Return ); 1108 mapToDefaultAction( ke, Qt::Key_Return );
1134 } 1109 }
1135 } 1110 }
1136 } 1111 }
1137 } 1112 }
1138 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1113 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
1139 // Use special "select" key to do whatever default action a widget has 1114 // Use special "select" key to do whatever default action a widget has
1140 mapToDefaultAction( ke, Qt::Key_Space ); 1115 mapToDefaultAction( ke, Qt::Key_Space );
1141 } 1116 }
1142 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1117 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
1143 ke->simpleData.is_press ) { 1118 ke->simpleData.is_press ) {
1144 // Escape key closes app if focus on toplevel 1119 // Escape key closes app if focus on toplevel
1145 QWidget * active = activeWindow(); 1120 QWidget * active = activeWindow();
1146 if ( active && active->testWFlags( WType_TopLevel ) && 1121 if ( active && active->testWFlags( WType_TopLevel ) &&
1147 ( int ) active->winId() == ke->simpleData.window && 1122 ( int ) active->winId() == ke->simpleData.window &&
1148 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1123 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1149 if ( active->inherits( "QDialog" ) ) { 1124 if ( active->inherits( "QDialog" ) ) {
1150 HackDialog * d = ( HackDialog * ) active; 1125 HackDialog * d = ( HackDialog * ) active;
1151 d->rejectIt(); 1126 d->rejectIt();
1152 return TRUE; 1127 return TRUE;
1153 } 1128 }
1154 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 1129 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
1155 active->close(); 1130 active->close();
1156 } 1131 }
1157 } 1132 }
1158 } 1133 }
1159 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1134 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
1160 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1135 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
1161 // but we cannot access libopie function within libqpe :( 1136 // but we cannot access libopie function within libqpe :(
1162 1137
1163 QWidget * active = activeWindow ( ); 1138 QWidget * active = activeWindow ( );
1164 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1139 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
1165 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1140 if ( d-> kbgrabbed ) { // we grabbed the keyboard
1166 QChar ch ( ke-> simpleData.unicode ); 1141 QChar ch ( ke-> simpleData.unicode );
1167 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1142 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
1168 ke-> simpleData.keycode, 1143 ke-> simpleData.keycode,
1169 ch. latin1 ( ), 1144 ch. latin1 ( ),
1170 ke-> simpleData.modifiers, 1145 ke-> simpleData.modifiers,
1171 QString ( ch ), 1146 QString ( ch ),
1172 ke-> simpleData.is_auto_repeat, 1 ); 1147 ke-> simpleData.is_auto_repeat, 1 );
1173 1148
1174 QObject *which = QWidget::keyboardGrabber ( ); 1149 QObject *which = QWidget::keyboardGrabber ( );
1175 if ( !which ) 1150 if ( !which )
1176 which = QApplication::focusWidget ( ); 1151 which = QApplication::focusWidget ( );
1177 if ( !which ) 1152 if ( !which )
1178 which = QApplication::activeWindow ( ); 1153 which = QApplication::activeWindow ( );
1179 if ( !which ) 1154 if ( !which )
1180 which = qApp; 1155 which = qApp;
1181 1156
1182 QApplication::sendEvent ( which, &qke ); 1157 QApplication::sendEvent ( which, &qke );
1183 } 1158 }
1184 else { // we didn't grab the keyboard, so send the event to the launcher 1159 else { // we didn't grab the keyboard, so send the event to the launcher
1185 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1160 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
1186 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1161 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
1187 } 1162 }
1188 } 1163 }
1189 return true; 1164 return true;
1190 } 1165 }
1191 } 1166 }
1192 if ( e->type == QWSEvent::Focus ) { 1167 if ( e->type == QWSEvent::Focus ) {
1193 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1168 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
1194 if ( !fe->simpleData.get_focus ) { 1169 if ( !fe->simpleData.get_focus ) {
1195 QWidget * active = activeWindow(); 1170 QWidget * active = activeWindow();
1196 while ( active && active->isPopup() ) { 1171 while ( active && active->isPopup() ) {
1197 active->close(); 1172 active->close();
1198 active = activeWindow(); 1173 active = activeWindow();
1199 } 1174 }
1200 } 1175 }
1201 else { 1176 else {
1202 // make sure our modal widget is ALWAYS on top 1177 // make sure our modal widget is ALWAYS on top
1203 QWidget *topm = activeModalWidget(); 1178 QWidget *topm = activeModalWidget();
1204 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1179 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
1205 topm->raise(); 1180 topm->raise();
1206 } 1181 }
1207 } 1182 }
1208 if ( fe->simpleData.get_focus && inputMethodDict ) { 1183 if ( fe->simpleData.get_focus && inputMethodDict ) {
1209 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1184 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1210 if ( m == AlwaysOff ) 1185 if ( m == AlwaysOff )
1211 Global::hideInputMethod(); 1186 Global::hideInputMethod();
1212 if ( m == AlwaysOn ) 1187 if ( m == AlwaysOn )
1213 Global::showInputMethod(); 1188 Global::showInputMethod();
1214 } 1189 }
1215 } 1190 }
1216 1191
1217 1192
1218 return QApplication::qwsEventFilter( e ); 1193 return QApplication::qwsEventFilter( e );
1219} 1194}
1220#endif 1195#endif
1221 1196
1222/*! 1197/*!
1223 Destroys the QPEApplication. 1198 Destroys the QPEApplication.
1224*/ 1199*/
1225QPEApplication::~QPEApplication() 1200QPEApplication::~QPEApplication()
1226{ 1201{
1227 ungrabKeyboard(); 1202 ungrabKeyboard();
1228#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1203#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1229 // Need to delete QCopChannels early, since the display will 1204 // Need to delete QCopChannels early, since the display will
1230 // be gone by the time we get to ~QObject(). 1205 // be gone by the time we get to ~QObject().
1231 delete sysChannel; 1206 delete sysChannel;
1232 delete pidChannel; 1207 delete pidChannel;
1233#endif 1208#endif
1234 1209
1235 delete d; 1210 delete d;
1236} 1211}
1237 1212
1238/*! 1213/*!
1239 Returns <tt>$OPIEDIR/</tt>. 1214 Returns <tt>$OPIEDIR/</tt>.
1240*/ 1215*/
1241QString QPEApplication::qpeDir() 1216QString QPEApplication::qpeDir()
1242{ 1217{
1243 const char * base = getenv( "OPIEDIR" ); 1218 const char * base = getenv( "OPIEDIR" );
1244 if ( base ) 1219 if ( base )
1245 return QString( base ) + "/"; 1220 return QString( base ) + "/";
1246 1221
1247 return QString( "../" ); 1222 return QString( "../" );
1248} 1223}
1249 1224
1250/*! 1225/*!
1251 Returns the user's current Document directory. There is a trailing "/". 1226 Returns the user's current Document directory. There is a trailing "/".
1252 .. well, it does now,, and there's no trailing '/' 1227 .. well, it does now,, and there's no trailing '/'
1253*/ 1228*/
1254QString QPEApplication::documentDir() 1229QString QPEApplication::documentDir()
1255{ 1230{
1256 const char* base = getenv( "HOME"); 1231 const char* base = getenv( "HOME");
1257 if ( base ) 1232 if ( base )
1258 return QString( base ) + "/Documents"; 1233 return QString( base ) + "/Documents";
1259 1234
1260 return QString( "../Documents" ); 1235 return QString( "../Documents" );
1261} 1236}
1262 1237
1263static int deforient = -1; 1238static int deforient = -1;
1264 1239
1265/*! 1240/*!
1266 \internal 1241 \internal
1267*/ 1242*/
1268int QPEApplication::defaultRotation() 1243int QPEApplication::defaultRotation()
1269{ 1244{
1270 if ( deforient < 0 ) { 1245 if ( deforient < 0 ) {
1271 QString d = getenv( "QWS_DISPLAY" ); 1246 QString d = getenv( "QWS_DISPLAY" );
1272 if ( d.contains( "Rot90" ) ) { 1247 if ( d.contains( "Rot90" ) ) {
1273 deforient = 90; 1248 deforient = 90;
1274 } 1249 }
1275 else if ( d.contains( "Rot180" ) ) { 1250 else if ( d.contains( "Rot180" ) ) {
1276 deforient = 180; 1251 deforient = 180;
1277 } 1252 }
1278 else if ( d.contains( "Rot270" ) ) { 1253 else if ( d.contains( "Rot270" ) ) {
1279 deforient = 270; 1254 deforient = 270;
1280 } 1255 }
1281 else { 1256 else {
1282 deforient = 0; 1257 deforient = 0;
1283 } 1258 }
1284 } 1259 }
1285 return deforient; 1260 return deforient;
1286} 1261}
1287 1262
1288/*! 1263/*!
1289 \internal 1264 \internal
1290*/ 1265*/
1291void QPEApplication::setDefaultRotation( int r ) 1266void QPEApplication::setDefaultRotation( int r )
1292{ 1267{
1293 if ( qApp->type() == GuiServer ) { 1268 if ( qApp->type() == GuiServer ) {
1294 deforient = r; 1269 deforient = r;
1295 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1270 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1296 Config config("qpe"); 1271 Config config("qpe");
1297 config.setGroup( "Rotation" ); 1272 config.setGroup( "Rotation" );
1298 config.writeEntry( "Rot", r ); 1273 config.writeEntry( "Rot", r );
1299 } 1274 }
1300 else { 1275 else {
1301#ifndef QT_NO_COP 1276#ifndef QT_NO_COP
1302 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1277 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1303 e << r; 1278 e << r;
1304 } 1279 }
1305#endif 1280#endif
1306 1281
1307 } 1282 }
1308} 1283}
1309 1284
1310#include <qgfx_qws.h> 1285#include <qgfx_qws.h>
1311#include <qwindowsystem_qws.h> 1286#include <qwindowsystem_qws.h>
1312 1287
1313extern void qws_clearLoadedFonts(); 1288extern void qws_clearLoadedFonts();
1314 1289
1315void QPEApplication::setCurrentMode( int x, int y, int depth ) 1290void QPEApplication::setCurrentMode( int x, int y, int depth )
1316{ 1291{
1317 // Reset the caches 1292 // Reset the caches
1318 qws_clearLoadedFonts(); 1293 qws_clearLoadedFonts();
1319 QPixmapCache::clear(); 1294 QPixmapCache::clear();
1320 1295
1321 // Change the screen mode 1296 // Change the screen mode
1322 qt_screen->setMode(x, y, depth); 1297 qt_screen->setMode(x, y, depth);
1323 1298
1324 if ( qApp->type() == GuiServer ) { 1299 if ( qApp->type() == GuiServer ) {
1325 // Reconfigure the GuiServer 1300 // Reconfigure the GuiServer
1326 qwsServer->beginDisplayReconfigure(); 1301 qwsServer->beginDisplayReconfigure();
1327 qwsServer->endDisplayReconfigure(); 1302 qwsServer->endDisplayReconfigure();
1328 1303
1329 // Get all the running apps to reset 1304 // Get all the running apps to reset
1330 QCopEnvelope env( "QPE/System", "reset()" ); 1305 QCopEnvelope env( "QPE/System", "reset()" );
1331 } 1306 }
1332} 1307}
1333 1308
1334void QPEApplication::reset() { 1309void QPEApplication::reset() {
1335 // Reconnect to the screen 1310 // Reconnect to the screen
1336 qt_screen->disconnect(); 1311 qt_screen->disconnect();
1337 qt_screen->connect( QString::null ); 1312 qt_screen->connect( QString::null );
1338 1313
1339 // Redraw everything 1314 // Redraw everything
1340 applyStyle(); 1315 applyStyle();
1341} 1316}
1342 1317
1343/*! 1318/*!
1344 \internal 1319 \internal
1345*/ 1320*/
1346void QPEApplication::applyStyle() 1321void QPEApplication::applyStyle()
1347{ 1322{
1348 Config config( "qpe" ); 1323 Config config( "qpe" );
1349 config.setGroup( "Appearance" ); 1324 config.setGroup( "Appearance" );
1350 1325
1351#if QT_VERSION > 233 1326#if QT_VERSION > 233
1352#if !defined(OPIE_NO_OVERRIDE_QT) 1327#if !defined(OPIE_NO_OVERRIDE_QT)
1353 // don't block ourselves ... 1328 // don't block ourselves ...
1354 Opie::force_appearance = 0; 1329 Opie::force_appearance = 0;
1355 1330
1356 static QString appname = Opie::binaryName ( ); 1331 static QString appname = Opie::binaryName ( );
1357 1332
1358 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1333 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1359 int nostyle = 0; 1334 int nostyle = 0;
1360 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1335 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1361 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1336 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1362 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1337 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1363 break; 1338 break;
1364 } 1339 }
1365 } 1340 }
1366#else 1341#else
1367 int nostyle = 0; 1342 int nostyle = 0;
1368#endif 1343#endif
1369 1344
1370 // Widget style 1345 // Widget style
1371 QString style = config.readEntry( "Style", "FlatStyle" ); 1346 QString style = config.readEntry( "Style", "FlatStyle" );
1372 1347
1373 // don't set a custom style 1348 // don't set a custom style
1374 if ( nostyle & Opie::Force_Style ) 1349 if ( nostyle & Opie::Force_Style )
1375 style = "FlatStyle"; 1350 style = "FlatStyle";
1376 1351
1377 internalSetStyle ( style ); 1352 internalSetStyle ( style );
1378 1353
1379 // Colors - from /etc/colors/Liquid.scheme 1354 // Colors - from /etc/colors/Liquid.scheme
1380 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1355 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1381 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1356 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1382 QPalette pal( btncolor, bgcolor ); 1357 QPalette pal( btncolor, bgcolor );
1383 QString color = config.readEntry( "Highlight", "#73adef" ); 1358 QString color = config.readEntry( "Highlight", "#73adef" );
1384 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1359 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1385 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1360 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1386 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1361 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1387 color = config.readEntry( "Text", "#000000" ); 1362 color = config.readEntry( "Text", "#000000" );
1388 pal.setColor( QColorGroup::Text, QColor( color ) ); 1363 pal.setColor( QColorGroup::Text, QColor( color ) );
1389 color = config.readEntry( "ButtonText", "#000000" ); 1364 color = config.readEntry( "ButtonText", "#000000" );
1390 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1365 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1391 color = config.readEntry( "Base", "#FFFFFF" ); 1366 color = config.readEntry( "Base", "#FFFFFF" );
1392 pal.setColor( QColorGroup::Base, QColor( color ) ); 1367 pal.setColor( QColorGroup::Base, QColor( color ) );
1393 1368
1394 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1369 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1395 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1370 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1396 1371
1397 setPalette( pal, TRUE ); 1372 setPalette( pal, TRUE );
1398 1373
1399 // Window Decoration 1374 // Window Decoration
1400 QString dec = config.readEntry( "Decoration", "Flat" ); 1375 QString dec = config.readEntry( "Decoration", "Flat" );
1401 1376
1402 // don't set a custom deco 1377 // don't set a custom deco
1403 if ( nostyle & Opie::Force_Decoration ) 1378 if ( nostyle & Opie::Force_Decoration )
1404 dec = ""; 1379 dec = "";
1405 1380
1406 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); 1381 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
1407 1382
1408 if ( dec != d->decorationName ) { 1383 if ( dec != d->decorationName ) {
1409 qwsSetDecoration( new QPEDecoration( dec ) ); 1384 qwsSetDecoration( new QPEDecoration( dec ) );
1410 d->decorationName = dec; 1385 d->decorationName = dec;
1411 } 1386 }
1412 1387
1413 // Font 1388 // Font
1414 QString ff = config.readEntry( "FontFamily", font().family() ); 1389 QString ff = config.readEntry( "FontFamily", font().family() );
1415 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1390 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1416 1391
1417 // don't set a custom font 1392 // don't set a custom font
1418 if ( nostyle & Opie::Force_Font ) { 1393 if ( nostyle & Opie::Force_Font ) {
1419 ff = "Vera"; 1394 ff = "Vera";
1420 fs = 10; 1395 fs = 10;
1421 } 1396 }
1422 1397
1423 setFont ( QFont ( ff, fs ), true ); 1398 setFont ( QFont ( ff, fs ), true );
1424 1399
1425#if !defined(OPIE_NO_OVERRIDE_QT) 1400#if !defined(OPIE_NO_OVERRIDE_QT)
1426 // revert to global blocking policy ... 1401 // revert to global blocking policy ...
1427 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1402 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1428 Opie::force_appearance &= ~nostyle; 1403 Opie::force_appearance &= ~nostyle;
1429#endif 1404#endif
1430#endif 1405#endif
1431} 1406}
1432 1407
1433void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1408void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1434{ 1409{
1435#ifdef Q_WS_QWS 1410#ifdef Q_WS_QWS
1436 QDataStream stream( data, IO_ReadOnly ); 1411 QDataStream stream( data, IO_ReadOnly );
1437 if ( msg == "applyStyle()" ) { 1412 if ( msg == "applyStyle()" ) {
1438 applyStyle(); 1413 applyStyle();
1439 } 1414 }
1440 else if ( msg == "toggleApplicationMenu()" ) { 1415 else if ( msg == "toggleApplicationMenu()" ) {
1441 QWidget *active = activeWindow ( ); 1416 QWidget *active = activeWindow ( );
1442 1417
1443 if ( active ) { 1418 if ( active ) {
1444 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1419 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1445 bool oldactive = man-> isActive ( ); 1420 bool oldactive = man-> isActive ( );
1446 1421
1447 man-> setActive( !man-> isActive() ); 1422 man-> setActive( !man-> isActive() );
1448 1423
1449 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1424 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1450 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1425 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1451 } 1426 }
1452 } 1427 }
1453 } 1428 }
1454 else if ( msg == "setDefaultRotation(int)" ) { 1429 else if ( msg == "setDefaultRotation(int)" ) {
1455 if ( type() == GuiServer ) { 1430 if ( type() == GuiServer ) {
1456 int r; 1431 int r;
1457 stream >> r; 1432 stream >> r;
1458 setDefaultRotation( r ); 1433 setDefaultRotation( r );
1459 } 1434 }
1460 } 1435 }
1461 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1436 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1462 if ( type() == GuiServer ) { 1437 if ( type() == GuiServer ) {
1463 int x, y, depth; 1438 int x, y, depth;
1464 stream >> x; 1439 stream >> x;
1465 stream >> y; 1440 stream >> y;
1466 stream >> depth; 1441 stream >> depth;
1467 setCurrentMode( x, y, depth ); 1442 setCurrentMode( x, y, depth );
1468 } 1443 }
1469 } 1444 }
1470 else if ( msg == "reset()" ) { 1445 else if ( msg == "reset()" ) {
1471 if ( type() != GuiServer ) 1446 if ( type() != GuiServer )
1472 reset(); 1447 reset();
1473 } 1448 }
1474 else if ( msg == "setCurrentRotation(int)" ) { 1449 else if ( msg == "setCurrentRotation(int)" ) {
1475 int r; 1450 int r;
1476 stream >> r; 1451 stream >> r;
1477 setCurrentRotation( r ); 1452 setCurrentRotation( r );
1478 } 1453 }
1479 else if ( msg == "shutdown()" ) { 1454 else if ( msg == "shutdown()" ) {
1480 if ( type() == GuiServer ) 1455 if ( type() == GuiServer )
1481 shutdown(); 1456 shutdown();
1482 } 1457 }
1483 else if ( msg == "quit()" ) { 1458 else if ( msg == "quit()" ) {
1484 if ( type() != GuiServer ) 1459 if ( type() != GuiServer )
1485 tryQuit(); 1460 tryQuit();
1486 } 1461 }
1487 else if ( msg == "forceQuit()" ) { 1462 else if ( msg == "forceQuit()" ) {
1488 if ( type() != GuiServer ) 1463 if ( type() != GuiServer )
1489 quit(); 1464 quit();
1490 } 1465 }
1491 else if ( msg == "restart()" ) { 1466 else if ( msg == "restart()" ) {
1492 if ( type() == GuiServer ) 1467 if ( type() == GuiServer )
1493 restart(); 1468 restart();
1494 } 1469 }
1495 else if ( msg == "language(QString)" ) { 1470 else if ( msg == "language(QString)" ) {
1496 if ( type() == GuiServer ) { 1471 if ( type() == GuiServer ) {
1497 QString l; 1472 QString l;
1498 stream >> l; 1473 stream >> l;
1499 QString cl = getenv( "LANG" ); 1474 QString cl = getenv( "LANG" );
1500 if ( cl != l ) { 1475 if ( cl != l ) {
1501 if ( l.isNull() ) 1476 if ( l.isNull() )
1502 unsetenv( "LANG" ); 1477 unsetenv( "LANG" );
1503 else 1478 else
1504 setenv( "LANG", l.latin1(), 1 ); 1479 setenv( "LANG", l.latin1(), 1 );
1505 restart(); 1480 restart();
1506 } 1481 }
1507 } 1482 }
1508 } 1483 }
1509 else if ( msg == "timeChange(QString)" ) { 1484 else if ( msg == "timeChange(QString)" ) {
1510 QString t; 1485 QString t;
1511 stream >> t; 1486 stream >> t;
1512 if ( t.isNull() ) 1487 if ( t.isNull() )
1513 unsetenv( "TZ" ); 1488 unsetenv( "TZ" );
1514 else 1489 else
1515 setenv( "TZ", t.latin1(), 1 ); 1490 setenv( "TZ", t.latin1(), 1 );
1516 // emit the signal so everyone else knows... 1491 // emit the signal so everyone else knows...
1517 emit timeChanged(); 1492 emit timeChanged();
1518 } 1493 }
1519 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1494 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1520 if ( type() == GuiServer ) { 1495 if ( type() == GuiServer ) {
1521 QDateTime when; 1496 QDateTime when;
1522 QCString channel, message; 1497 QCString channel, message;
1523 int data; 1498 int data;
1524 stream >> when >> channel >> message >> data; 1499 stream >> when >> channel >> message >> data;
1525 AlarmServer::addAlarm( when, channel, message, data ); 1500 AlarmServer::addAlarm( when, channel, message, data );
1526 } 1501 }
1527 } 1502 }
1528 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1503 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1529 if ( type() == GuiServer ) { 1504 if ( type() == GuiServer ) {
1530 QDateTime when; 1505 QDateTime when;
1531 QCString channel, message; 1506 QCString channel, message;
1532 int data; 1507 int data;
1533 stream >> when >> channel >> message >> data; 1508 stream >> when >> channel >> message >> data;
1534 AlarmServer::deleteAlarm( when, channel, message, data ); 1509 AlarmServer::deleteAlarm( when, channel, message, data );
1535 } 1510 }
1536 } 1511 }
1537 else if ( msg == "clockChange(bool)" ) { 1512 else if ( msg == "clockChange(bool)" ) {
1538 int tmp; 1513 int tmp;
1539 stream >> tmp; 1514 stream >> tmp;
1540 emit clockChanged( tmp ); 1515 emit clockChanged( tmp );
1541 } 1516 }
1542 else if ( msg == "weekChange(bool)" ) { 1517 else if ( msg == "weekChange(bool)" ) {
1543 int tmp; 1518 int tmp;
1544 stream >> tmp; 1519 stream >> tmp;
1545 emit weekChanged( tmp ); 1520 emit weekChanged( tmp );
1546 } 1521 }
1547 else if ( msg == "setDateFormat(DateFormat)" ) { 1522 else if ( msg == "setDateFormat(DateFormat)" ) {
1548 DateFormat tmp; 1523 DateFormat tmp;
1549 stream >> tmp; 1524 stream >> tmp;
1550 emit dateFormatChanged( tmp ); 1525 emit dateFormatChanged( tmp );
1551 } 1526 }
1552 else if ( msg == "setVolume(int,int)" ) { 1527 else if ( msg == "setVolume(int,int)" ) {
1553 int t, v; 1528 int t, v;
1554 stream >> t >> v; 1529 stream >> t >> v;
1555 setVolume( t, v ); 1530 setVolume( t, v );
1556 emit volumeChanged( muted ); 1531 emit volumeChanged( muted );
1557 } 1532 }
1558 else if ( msg == "volumeChange(bool)" ) { 1533 else if ( msg == "volumeChange(bool)" ) {
1559 stream >> muted; 1534 stream >> muted;
1560 setVolume(); 1535 setVolume();
1561 emit volumeChanged( muted ); 1536 emit volumeChanged( muted );
1562 } 1537 }
1563 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1538 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1564 int t, v; 1539 int t, v;
1565 stream >> t >> v; 1540 stream >> t >> v;
1566 setMic( t, v ); 1541 setMic( t, v );
1567 emit micChanged( micMuted ); 1542 emit micChanged( micMuted );
1568 } 1543 }
1569 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1544 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1570 stream >> micMuted; 1545 stream >> micMuted;
1571 setMic(); 1546 setMic();
1572 emit micChanged( micMuted ); 1547 emit micChanged( micMuted );
1573 } 1548 }
1574 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1549 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1575 int t, v; 1550 int t, v;
1576 stream >> t >> v; 1551 stream >> t >> v;
1577 setBass( t, v ); 1552 setBass( t, v );
1578 } 1553 }
1579 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1554 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1580 setBass(); 1555 setBass();
1581 } 1556 }
1582 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1557 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1583 int t, v; 1558 int t, v;
1584 stream >> t >> v; 1559 stream >> t >> v;
1585 setTreble( t, v ); 1560 setTreble( t, v );
1586 } 1561 }
1587 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1562 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1588 setTreble(); 1563 setTreble();
1589 } else if ( msg == "getMarkedText()" ) { 1564 } else if ( msg == "getMarkedText()" ) {
1590 if ( type() == GuiServer ) { 1565 if ( type() == GuiServer ) {
1591 const ushort unicode = 'C'-'@'; 1566 const ushort unicode = 'C'-'@';
1592 const int scan = Key_C; 1567 const int scan = Key_C;
1593 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1568 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1594 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1569 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1595 } 1570 }
1596 } else if ( msg == "newChannel(QString)") { 1571 } else if ( msg == "newChannel(QString)") {
1597 QString myChannel = "QPE/Application/" + d->appName; 1572 QString myChannel = "QPE/Application/" + d->appName;
1598 QString channel; 1573 QString channel;
1599 stream >> channel; 1574 stream >> channel;
1600 if (channel == myChannel) { 1575 if (channel == myChannel) {
1601 processQCopFile(); 1576 processQCopFile();
1602 d->sendQCopQ(); 1577 d->sendQCopQ();
1603 } 1578 }
1604 } 1579 }
1605 1580
1606 1581
1607#endif 1582#endif
1608} 1583}
1609 1584
1610 1585
1611 1586
1612 1587
1613 1588
1614/*! 1589/*!
1615 \internal 1590 \internal
1616*/ 1591*/
1617bool QPEApplication::raiseAppropriateWindow() 1592bool QPEApplication::raiseAppropriateWindow()
1618{ 1593{
1619 bool r=FALSE; 1594 bool r=FALSE;
1620 1595
1621 // 1. Raise the main widget 1596 // 1. Raise the main widget
1622 QWidget *top = d->qpe_main_widget; 1597 QWidget *top = d->qpe_main_widget;
1623 if ( !top ) top = mainWidget(); 1598 if ( !top ) top = mainWidget();
1624 1599
1625 if ( top && d->keep_running ) { 1600 if ( top && d->keep_running ) {
1626 if ( top->isVisible() ) 1601 if ( top->isVisible() )
1627 r = TRUE; 1602 r = TRUE;
1628 else if (d->preloaded) { 1603 else if (d->preloaded) {
1629 // We are preloaded and not visible.. pretend we just started.. 1604 // We are preloaded and not visible.. pretend we just started..
1630#ifndef QT_NO_COP 1605#ifndef QT_NO_COP
1631 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1606 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1632 e << d->appName; 1607 e << d->appName;
1633#endif 1608#endif
1634 } 1609 }
1635 1610
1636 d->show_mx(top,d->nomaximize, d->appName); 1611 d->show_mx(top,d->nomaximize, d->appName);
1637 top->raise(); 1612 top->raise();
1638 } 1613 }
1639 1614
1640 QWidget *topm = activeModalWidget(); 1615 QWidget *topm = activeModalWidget();
1641 1616
1642 // 2. Raise any parentless widgets (except top and topm, as they 1617 // 2. Raise any parentless widgets (except top and topm, as they
1643 // are raised before and after this loop). Order from most 1618 // are raised before and after this loop). Order from most
1644 // recently raised as deepest to least recently as top, so 1619 // recently raised as deepest to least recently as top, so
1645 // that repeated calls cycle through widgets. 1620 // that repeated calls cycle through widgets.
1646 QWidgetList *list = topLevelWidgets(); 1621 QWidgetList *list = topLevelWidgets();
1647 if ( list ) { 1622 if ( list ) {
1648 bool foundlast = FALSE; 1623 bool foundlast = FALSE;
1649 QWidget* topsub = 0; 1624 QWidget* topsub = 0;
1650 if ( d->lastraised ) { 1625 if ( d->lastraised ) {
1651 for (QWidget* w = list->first(); w; w = list->next()) { 1626 for (QWidget* w = list->first(); w; w = list->next()) {
1652 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1627 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1653 if ( w == d->lastraised ) 1628 if ( w == d->lastraised )
1654 foundlast = TRUE; 1629 foundlast = TRUE;
1655 if ( foundlast ) { 1630 if ( foundlast ) {
1656 w->raise(); 1631 w->raise();
1657 topsub = w; 1632 topsub = w;
1658 } 1633 }
1659 } 1634 }
1660 } 1635 }
1661 } 1636 }
1662 for (QWidget* w = list->first(); w; w = list->next()) { 1637 for (QWidget* w = list->first(); w; w = list->next()) {
1663 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1638 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1664 if ( w == d->lastraised ) 1639 if ( w == d->lastraised )
1665 break; 1640 break;
1666 w->raise(); 1641 w->raise();
1667 topsub = w; 1642 topsub = w;
1668 } 1643 }
1669 } 1644 }
1670 d->lastraised = topsub; 1645 d->lastraised = topsub;
1671 delete list; 1646 delete list;
1672 } 1647 }
1673 1648
1674 // 3. Raise the active modal widget. 1649 // 3. Raise the active modal widget.
1675 if ( topm ) { 1650 if ( topm ) {
1676 topm->show(); 1651 topm->show();
1677 topm->raise(); 1652 topm->raise();
1678 // If we haven't already handled the fastAppShowing message 1653 // If we haven't already handled the fastAppShowing message
1679 if (!top && d->preloaded) { 1654 if (!top && d->preloaded) {
1680#ifndef QT_NO_COP 1655#ifndef QT_NO_COP
1681 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1656 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1682 e << d->appName; 1657 e << d->appName;
1683#endif 1658#endif
1684 } 1659 }
1685 r = FALSE; 1660 r = FALSE;
1686 } 1661 }
1687 1662
1688 return r; 1663 return r;
1689} 1664}
1690 1665
1691 1666
1692void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1667void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1693{ 1668{
1694#ifdef Q_WS_QWS 1669#ifdef Q_WS_QWS
1695 1670
1696 if ( msg == "quit()" ) { 1671 if ( msg == "quit()" ) {
1697 tryQuit(); 1672 tryQuit();
1698 } 1673 }
1699 else if ( msg == "quitIfInvisible()" ) { 1674 else if ( msg == "quitIfInvisible()" ) {
1700 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1675 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1701 quit(); 1676 quit();
1702 } 1677 }
1703 else if ( msg == "close()" ) { 1678 else if ( msg == "close()" ) {
1704 hideOrQuit(); 1679 hideOrQuit();
1705 } 1680 }
1706 else if ( msg == "disablePreload()" ) { 1681 else if ( msg == "disablePreload()" ) {
1707 d->preloaded = FALSE; 1682 d->preloaded = FALSE;
1708 d->keep_running = TRUE; 1683 d->keep_running = TRUE;
1709 /* so that quit will quit */ 1684 /* so that quit will quit */
1710 } 1685 }
1711 else if ( msg == "enablePreload()" ) { 1686 else if ( msg == "enablePreload()" ) {
1712 if (d->qpe_main_widget) 1687 if (d->qpe_main_widget)
1713 d->preloaded = TRUE; 1688 d->preloaded = TRUE;
1714 d->keep_running = TRUE; 1689 d->keep_running = TRUE;
1715 /* so next quit won't quit */ 1690 /* so next quit won't quit */
1716 } 1691 }
1717 else if ( msg == "raise()" ) { 1692 else if ( msg == "raise()" ) {
1718 d->keep_running = TRUE; 1693 d->keep_running = TRUE;
1719 d->notbusysent = FALSE; 1694 d->notbusysent = FALSE;
1720 raiseAppropriateWindow(); 1695 raiseAppropriateWindow();
1721 // Tell the system we're still chugging along... 1696 // Tell the system we're still chugging along...
1722 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1697 QCopEnvelope e("QPE/System", "appRaised(QString)");
1723 e << d->appName; 1698 e << d->appName;
1724 } 1699 }
1725 else if ( msg == "flush()" ) { 1700 else if ( msg == "flush()" ) {
1726 emit flush(); 1701 emit flush();
1727 // we need to tell the desktop 1702 // we need to tell the desktop
1728 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1703 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1729 e << d->appName; 1704 e << d->appName;
1730 } 1705 }
1731 else if ( msg == "reload()" ) { 1706 else if ( msg == "reload()" ) {
1732 emit reload(); 1707 emit reload();
1733 } 1708 }
1734 else if ( msg == "setDocument(QString)" ) { 1709 else if ( msg == "setDocument(QString)" ) {
1735 d->keep_running = TRUE; 1710 d->keep_running = TRUE;
1736 QDataStream stream( data, IO_ReadOnly ); 1711 QDataStream stream( data, IO_ReadOnly );
1737 QString doc; 1712 QString doc;
1738 stream >> doc; 1713 stream >> doc;
1739 QWidget *mw = mainWidget(); 1714 QWidget *mw = mainWidget();
1740 if ( !mw ) 1715 if ( !mw )
1741 mw = d->qpe_main_widget; 1716 mw = d->qpe_main_widget;
1742 if ( mw ) 1717 if ( mw )
1743 Global::setDocument( mw, doc ); 1718 Global::setDocument( mw, doc );
1744 1719
1745 } else if ( msg == "QPEProcessQCop()" ) { 1720 } else if ( msg == "QPEProcessQCop()" ) {
1746 processQCopFile(); 1721 processQCopFile();
1747 d->sendQCopQ(); 1722 d->sendQCopQ();
1748 }else 1723 }else
1749 { 1724 {
1750 bool p = d->keep_running; 1725 bool p = d->keep_running;
1751 d->keep_running = FALSE; 1726 d->keep_running = FALSE;
1752 emit appMessage( msg, data); 1727 emit appMessage( msg, data);
1753 if ( d->keep_running ) { 1728 if ( d->keep_running ) {
1754 d->notbusysent = FALSE; 1729 d->notbusysent = FALSE;
1755 raiseAppropriateWindow(); 1730 raiseAppropriateWindow();
1756 if ( !p ) { 1731 if ( !p ) {
1757 // Tell the system we're still chugging along... 1732 // Tell the system we're still chugging along...
1758#ifndef QT_NO_COP 1733#ifndef QT_NO_COP
1759 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1734 QCopEnvelope e("QPE/System", "appRaised(QString)");
1760 e << d->appName; 1735 e << d->appName;
1761#endif 1736#endif
1762 } 1737 }
1763 } 1738 }
1764 if ( p ) 1739 if ( p )
1765 d->keep_running = p; 1740 d->keep_running = p;
1766 } 1741 }
1767#endif 1742#endif
1768} 1743}
1769 1744
1770 1745
1771/*! 1746/*!
1772 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1747 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1773 consider passing TRUE for \a nomaximize rather than the default FALSE. 1748 consider passing TRUE for \a nomaximize rather than the default FALSE.
1774 1749
1775 \sa showMainDocumentWidget() 1750 \sa showMainDocumentWidget()
1776*/ 1751*/
1777void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1752void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1778{ 1753{
1779 // setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit 1754 // setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit
1780 d->show(mw, nomaximize ); 1755 d->show(mw, nomaximize );
1781} 1756}
1782 1757
1783/*! 1758/*!
1784 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1759 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1785 consider passing TRUE for \a nomaximize rather than the default FALSE. 1760 consider passing TRUE for \a nomaximize rather than the default FALSE.
1786 1761
1787 This calls designates the application as 1762 This calls designates the application as
1788 a \link docwidget.html document-oriented\endlink application. 1763 a \link docwidget.html document-oriented\endlink application.
1789 1764
1790 The \a mw widget \e must have this slot: setDocument(const QString&). 1765 The \a mw widget \e must have this slot: setDocument(const QString&).
1791 1766
1792 \sa showMainWidget() 1767 \sa showMainWidget()
1793*/ 1768*/
1794void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1769void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1795{ 1770{
1796 if ( mw && argc() == 2 ) 1771 if ( mw && argc() == 2 )
1797 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1772 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1798 1773
1799 1774
1800 //setMainWidget(mw); see above 1775 //setMainWidget(mw); see above
1801 d->show(mw, nomaximize ); 1776 d->show(mw, nomaximize );
1802} 1777}
1803 1778
1804 1779
1805/*! 1780/*!
1806 If an application is started via a \link qcop.html QCop\endlink 1781 If an application is started via a \link qcop.html QCop\endlink
1807 message, the application will process the \link qcop.html 1782 message, the application will process the \link qcop.html
1808 QCop\endlink message and then quit. If the application calls this 1783 QCop\endlink message and then quit. If the application calls this
1809 function while processing a \link qcop.html QCop\endlink message, 1784 function while processing a \link qcop.html QCop\endlink message,
1810 after processing its outstanding \link qcop.html QCop\endlink 1785 after processing its outstanding \link qcop.html QCop\endlink
1811 messages the application will start 'properly' and show itself. 1786 messages the application will start 'properly' and show itself.
1812 1787
1813 \sa keepRunning() 1788 \sa keepRunning()
1814*/ 1789*/
1815void QPEApplication::setKeepRunning() 1790void QPEApplication::setKeepRunning()
1816{ 1791{
1817 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1792 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1818 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1793 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1819 qpeApp->d->keep_running = TRUE; 1794 qpeApp->d->keep_running = TRUE;
1820 } 1795 }
1821} 1796}
1822 1797
1823/*! 1798/*!
1824 Returns TRUE if the application will quit after processing the 1799 Returns TRUE if the application will quit after processing the
1825 current list of qcop messages; otherwise returns FALSE. 1800 current list of qcop messages; otherwise returns FALSE.
1826 1801
1827 \sa setKeepRunning() 1802 \sa setKeepRunning()
1828*/ 1803*/
1829bool QPEApplication::keepRunning() const 1804bool QPEApplication::keepRunning() const
1830{ 1805{
1831 return d->keep_running; 1806 return d->keep_running;
1832} 1807}
1833 1808
1834/*! 1809/*!
1835 \internal 1810 \internal
1836*/ 1811*/
1837void QPEApplication::internalSetStyle( const QString &style ) 1812void QPEApplication::internalSetStyle( const QString &style )
1838{ 1813{
1839#if QT_VERSION >= 300 1814#if QT_VERSION >= 300
1840 if ( style == "QPE" ) { 1815 if ( style == "QPE" ) {
1841 setStyle( new QPEStyle ); 1816 setStyle( new QPEStyle );
1842 } 1817 }
1843 else { 1818 else {
1844 QStyle *s = QStyleFactory::create( style ); 1819 QStyle *s = QStyleFactory::create( style );
1845 if ( s ) 1820 if ( s )
1846 setStyle( s ); 1821 setStyle( s );
1847 } 1822 }
1848#else 1823#else
1849 if ( style == "Windows" ) { 1824 if ( style == "Windows" ) {
1850 setStyle( new QWindowsStyle ); 1825 setStyle( new QWindowsStyle );
1851 } 1826 }
1852 else if ( style == "QPE" ) { 1827 else if ( style == "QPE" ) {
1853 setStyle( new QPEStyle ); 1828 setStyle( new QPEStyle );
1854 } 1829 }
1855 else if ( style == "Light" ) { 1830 else if ( style == "Light" ) {
1856 setStyle( new LightStyle ); 1831 setStyle( new LightStyle );
1857 } 1832 }
1858#ifndef QT_NO_STYLE_PLATINUM 1833#ifndef QT_NO_STYLE_PLATINUM
1859 else if ( style == "Platinum" ) { 1834 else if ( style == "Platinum" ) {
1860 setStyle( new QPlatinumStyle ); 1835 setStyle( new QPlatinumStyle );
1861 } 1836 }
1862#endif 1837#endif
1863#ifndef QT_NO_STYLE_MOTIF 1838#ifndef QT_NO_STYLE_MOTIF
1864 else if ( style == "Motif" ) { 1839 else if ( style == "Motif" ) {
1865 setStyle( new QMotifStyle ); 1840 setStyle( new QMotifStyle );
1866 } 1841 }
1867#endif 1842#endif
1868#ifndef QT_NO_STYLE_MOTIFPLUS 1843#ifndef QT_NO_STYLE_MOTIFPLUS
1869 else if ( style == "MotifPlus" ) { 1844 else if ( style == "MotifPlus" ) {
1870 setStyle( new QMotifPlusStyle ); 1845 setStyle( new QMotifPlusStyle );
1871 } 1846 }
1872#endif 1847#endif
1873 1848
1874 else { 1849 else {
1875 QStyle *sty = 0; 1850 QStyle *sty = 0;
1876 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 1851 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
1877 1852
1878#ifdef Q_OS_MACX 1853#ifdef Q_OS_MACX
1879 if ( style. find ( ".dylib" ) > 0 ) 1854 if ( style. find ( ".dylib" ) > 0 )
1880 path += style; 1855 path += style;
1881 else 1856 else
1882 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility 1857 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
1883#else 1858#else
1884 if ( style. find ( ".so" ) > 0 ) 1859 if ( style. find ( ".so" ) > 0 )
1885 path += style; 1860 path += style;
1886 else 1861 else
1887 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1862 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1888#endif 1863#endif
1889 static QLibrary *lastlib = 0; 1864 static QLibrary *lastlib = 0;
1890 static StyleInterface *lastiface = 0; 1865 static StyleInterface *lastiface = 0;
1891 1866
1892 QLibrary *lib = new QLibrary ( path ); 1867 QLibrary *lib = new QLibrary ( path );
1893 StyleInterface *iface = 0; 1868 StyleInterface *iface = 0;
1894 1869
1895 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1870 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1896 sty = iface-> style ( ); 1871 sty = iface-> style ( );
1897 1872
1898 if ( sty ) { 1873 if ( sty ) {
1899 setStyle ( sty ); 1874 setStyle ( sty );
1900 1875
1901 if ( lastiface ) 1876 if ( lastiface )
1902 lastiface-> release ( ); 1877 lastiface-> release ( );
1903 lastiface = iface; 1878 lastiface = iface;
1904 1879
1905 if ( lastlib ) { 1880 if ( lastlib ) {
1906 lastlib-> unload ( ); 1881 lastlib-> unload ( );
1907 delete lastlib; 1882 delete lastlib;
1908 } 1883 }
1909 lastlib = lib; 1884 lastlib = lib;
1910 } 1885 }
1911 else { 1886 else {
1912 if ( iface ) 1887 if ( iface )
1913 iface-> release ( ); 1888 iface-> release ( );
1914 delete lib; 1889 delete lib;
1915 1890
1916 setStyle ( new LightStyle ( )); 1891 setStyle ( new LightStyle ( ));
1917 } 1892 }
1918 } 1893 }
1919#endif 1894#endif
1920} 1895}
1921 1896
1922/*! 1897/*!
1923 \internal 1898 \internal
1924*/ 1899*/
1925void QPEApplication::prepareForTermination( bool willrestart ) 1900void QPEApplication::prepareForTermination( bool willrestart )
1926{ 1901{
1927 if ( willrestart ) { 1902 if ( willrestart ) {
1928 // Draw a big wait icon, the image can be altered in later revisions 1903 // Draw a big wait icon, the image can be altered in later revisions
1929 // QWidget *d = QApplication::desktop(); 1904 // QWidget *d = QApplication::desktop();
1930 QImage img = Resource::loadImage( "launcher/new_wait" ); 1905 QImage img = Resource::loadImage( "launcher/new_wait" );
1931 QPixmap pix; 1906 QPixmap pix;
1932 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1907 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1933 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1908 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1934 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1909 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1935 lblWait->setPixmap( pix ); 1910 lblWait->setPixmap( pix );
1936 lblWait->setAlignment( QWidget::AlignCenter ); 1911 lblWait->setAlignment( QWidget::AlignCenter );
1937 lblWait->show(); 1912 lblWait->show();
1938 lblWait->showMaximized(); 1913 lblWait->showMaximized();
1939 } 1914 }
1940#ifndef SINGLE_APP 1915#ifndef SINGLE_APP
1941 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1916 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1942 } 1917 }
1943 processEvents(); // ensure the message goes out. 1918 processEvents(); // ensure the message goes out.
1944 sleep( 1 ); // You have 1 second to comply. 1919 sleep( 1 ); // You have 1 second to comply.
1945#endif 1920#endif
1946} 1921}
1947 1922
1948/*! 1923/*!
1949 \internal 1924 \internal
1950*/ 1925*/
1951void QPEApplication::shutdown() 1926void QPEApplication::shutdown()
1952{ 1927{
1953 // Implement in server's QPEApplication subclass 1928 // Implement in server's QPEApplication subclass
1954} 1929}
1955 1930
1956/*! 1931/*!
1957 \internal 1932 \internal
1958*/ 1933*/
1959void QPEApplication::restart() 1934void QPEApplication::restart()
1960{ 1935{
1961 // Implement in server's QPEApplication subclass 1936 // Implement in server's QPEApplication subclass
1962} 1937}
1963 1938
1964static QPtrDict<void>* stylusDict = 0; 1939static QPtrDict<void>* stylusDict = 0;
1965static void createDict() 1940static void createDict()
1966{ 1941{
1967 if ( !stylusDict ) 1942 if ( !stylusDict )
1968 stylusDict = new QPtrDict<void>; 1943 stylusDict = new QPtrDict<void>;
1969} 1944}
1970 1945
1971/*! 1946/*!
1972 Returns the current StylusMode for widget \a w. 1947 Returns the current StylusMode for widget \a w.
1973 1948
1974 \sa setStylusOperation() StylusMode 1949 \sa setStylusOperation() StylusMode
1975*/ 1950*/
1976QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1951QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1977{ 1952{
1978 if ( stylusDict ) 1953 if ( stylusDict )
1979 return ( StylusMode ) ( int ) stylusDict->find( w ); 1954 return ( StylusMode ) ( int ) stylusDict->find( w );
1980 return LeftOnly; 1955 return LeftOnly;
1981} 1956}
1982 1957
1983/*! 1958/*!
1984 \enum QPEApplication::StylusMode 1959 \enum QPEApplication::StylusMode
1985 1960
1986 \value LeftOnly the stylus only generates LeftButton 1961 \value LeftOnly the stylus only generates LeftButton
1987 events (the default). 1962 events (the default).
1988 \value RightOnHold the stylus generates RightButton events 1963 \value RightOnHold the stylus generates RightButton events
1989 if the user uses the press-and-hold gesture. 1964 if the user uses the press-and-hold gesture.
1990 1965
1991 \sa setStylusOperation() stylusOperation() 1966 \sa setStylusOperation() stylusOperation()
1992*/ 1967*/
1993 1968
1994/*! 1969/*!
1995 Causes widget \a w to receive mouse events according to the stylus 1970 Causes widget \a w to receive mouse events according to the stylus
1996 \a mode. 1971 \a mode.
1997 1972
1998 \sa stylusOperation() StylusMode 1973 \sa stylusOperation() StylusMode
1999*/ 1974*/
2000void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1975void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
2001{ 1976{
2002 createDict(); 1977 createDict();
2003 if ( mode == LeftOnly ) { 1978 if ( mode == LeftOnly ) {
2004 stylusDict->remove 1979 stylusDict->remove
2005 ( w ); 1980 ( w );
2006 w->removeEventFilter( qApp ); 1981 w->removeEventFilter( qApp );
2007 } 1982 }
2008 else { 1983 else {
2009 stylusDict->insert( w, ( void* ) mode ); 1984 stylusDict->insert( w, ( void* ) mode );
2010 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 1985 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
2011 w->installEventFilter( qApp ); 1986 w->installEventFilter( qApp );
2012 } 1987 }
2013} 1988}
2014 1989
2015 1990
2016/*! 1991/*!
2017 \reimp 1992 \reimp
2018*/ 1993*/
2019bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1994bool QPEApplication::eventFilter( QObject *o, QEvent *e )
2020{ 1995{
2021 if ( !o->isWidgetType() ) 1996 if ( !o->isWidgetType() )
2022 return FALSE; 1997 return FALSE;
2023 1998
2024 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1999 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
2025 QMouseEvent * me = ( QMouseEvent* ) e; 2000 QMouseEvent * me = ( QMouseEvent* ) e;
2026 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 2001 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
2027 switch (mode) { 2002 switch (mode) {
2028 case RightOnHold: 2003 case RightOnHold:
2029 switch ( me->type() ) { 2004 switch ( me->type() ) {
2030 case QEvent::MouseButtonPress: 2005 case QEvent::MouseButtonPress:
2031 if ( me->button() == LeftButton ) { 2006 if ( me->button() == LeftButton ) {
2032 if (!d->presstimer ) 2007 if (!d->presstimer )
2033 d->presstimer = startTimer(500); // #### pref. 2008 d->presstimer = startTimer(500); // #### pref.
2034 d->presswidget = (QWidget*)o; 2009 d->presswidget = (QWidget*)o;
2035 d->presspos = me->pos(); 2010 d->presspos = me->pos();
2036 d->rightpressed = FALSE; 2011 d->rightpressed = FALSE;
2037 } 2012 }
2038 break; 2013 break;
2039 case QEvent::MouseMove: 2014 case QEvent::MouseMove:
2040 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 2015 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
2041 killTimer(d->presstimer); 2016 killTimer(d->presstimer);
2042 d->presstimer = 0; 2017 d->presstimer = 0;
2043 } 2018 }
2044 break; 2019 break;
2045 case QEvent::MouseButtonRelease: 2020 case QEvent::MouseButtonRelease:
2046 if ( me->button() == LeftButton ) { 2021 if ( me->button() == LeftButton ) {
2047 if ( d->presstimer ) { 2022 if ( d->presstimer ) {
2048 killTimer(d->presstimer); 2023 killTimer(d->presstimer);
2049 d->presstimer = 0; 2024 d->presstimer = 0;
2050 } 2025 }
2051 if ( d->rightpressed && d->presswidget ) { 2026 if ( d->rightpressed && d->presswidget ) {
2052 // Right released 2027 // Right released
2053 postEvent( d->presswidget, 2028 postEvent( d->presswidget,
2054 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 2029 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
2055 RightButton, LeftButton + RightButton ) ); 2030 RightButton, LeftButton + RightButton ) );
2056 // Left released, off-widget 2031 // Left released, off-widget
2057 postEvent( d->presswidget, 2032 postEvent( d->presswidget,
2058 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 2033 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
2059 LeftButton, LeftButton ) ); 2034 LeftButton, LeftButton ) );
2060 postEvent( d->presswidget, 2035 postEvent( d->presswidget,
2061 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 2036 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
2062 LeftButton, LeftButton ) ); 2037 LeftButton, LeftButton ) );
2063 d->rightpressed = FALSE; 2038 d->rightpressed = FALSE;
2064 return TRUE; // don't send the real Left release 2039 return TRUE; // don't send the real Left release
2065 } 2040 }
2066 } 2041 }
2067 break; 2042 break;
2068 default: 2043 default:
2069 break; 2044 break;
2070 } 2045 }
2071 break; 2046 break;
2072 default: 2047 default:
2073 ; 2048 ;
2074 } 2049 }
2075 } 2050 }
2076 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 2051 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
2077 QKeyEvent *ke = (QKeyEvent *)e; 2052 QKeyEvent *ke = (QKeyEvent *)e;
2078 if ( ke->key() == Key_Enter ) { 2053 if ( ke->key() == Key_Enter ) {
2079 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 2054 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
2080 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 2055 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
2081 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 2056 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
2082 return TRUE; 2057 return TRUE;
2083 } 2058 }
2084 } 2059 }
2085 } 2060 }
2086 return FALSE; 2061 return FALSE;
2087} 2062}
2088 2063
2089/*! 2064/*!
2090 \reimp 2065 \reimp
2091*/ 2066*/
2092void QPEApplication::timerEvent( QTimerEvent *e ) 2067void QPEApplication::timerEvent( QTimerEvent *e )
2093{ 2068{
2094 if ( e->timerId() == d->presstimer && d->presswidget ) { 2069 if ( e->timerId() == d->presstimer && d->presswidget ) {
2095 // Right pressed 2070 // Right pressed
2096 postEvent( d->presswidget, 2071 postEvent( d->presswidget,
2097 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 2072 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
2098 RightButton, LeftButton ) ); 2073 RightButton, LeftButton ) );
2099 killTimer( d->presstimer ); 2074 killTimer( d->presstimer );
2100 d->presstimer = 0; 2075 d->presstimer = 0;
2101 d->rightpressed = TRUE; 2076 d->rightpressed = TRUE;
2102 } 2077 }
2103} 2078}
2104 2079
2105void QPEApplication::removeSenderFromStylusDict() 2080void QPEApplication::removeSenderFromStylusDict()
2106{ 2081{
2107 stylusDict->remove 2082 stylusDict->remove
2108 ( ( void* ) sender() ); 2083 ( ( void* ) sender() );
2109 if ( d->presswidget == sender() ) 2084 if ( d->presswidget == sender() )
2110 d->presswidget = 0; 2085 d->presswidget = 0;
2111} 2086}
2112 2087
2113/*! 2088/*!
2114 \internal 2089 \internal
2115*/ 2090*/
2116bool QPEApplication::keyboardGrabbed() const 2091bool QPEApplication::keyboardGrabbed() const
2117{ 2092{
2118 return d->kbgrabbed; 2093 return d->kbgrabbed;
2119} 2094}
2120 2095
2121 2096
2122/*! 2097/*!
2123 Reverses the effect of grabKeyboard(). This is called automatically 2098 Reverses the effect of grabKeyboard(). This is called automatically
2124 on program exit. 2099 on program exit.
2125*/ 2100*/
2126void QPEApplication::ungrabKeyboard() 2101void QPEApplication::ungrabKeyboard()
2127{ 2102{
2128 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 2103 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
2129} 2104}
2130 2105
2131/*! 2106/*!
2132 Grabs the physical keyboard keys, e.g. the application's launching 2107 Grabs the physical keyboard keys, e.g. the application's launching
2133 keys. Instead of launching applications when these keys are pressed 2108 keys. Instead of launching applications when these keys are pressed
2134 the signals emitted are sent to this application instead. Some games 2109 the signals emitted are sent to this application instead. Some games
2135 programs take over the launch keys in this way to make interaction 2110 programs take over the launch keys in this way to make interaction
2136 easier. 2111 easier.
2137 2112
2138 \sa ungrabKeyboard() 2113 \sa ungrabKeyboard()
2139*/ 2114*/
2140void QPEApplication::grabKeyboard() 2115void QPEApplication::grabKeyboard()
2141{ 2116{
2142 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 2117 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
2143} 2118}
2144 2119
2145/*! 2120/*!
2146 \reimp 2121 \reimp
2147*/ 2122*/
2148int QPEApplication::exec() 2123int QPEApplication::exec()
2149{ 2124{
2150 d->qcopQok = true; 2125 d->qcopQok = true;
2151#ifndef QT_NO_COP 2126#ifndef QT_NO_COP
2152 d->sendQCopQ(); 2127 d->sendQCopQ();
2153 if ( !d->keep_running ) 2128 if ( !d->keep_running )
2154 processEvents(); // we may have received QCop messages in the meantime. 2129 processEvents(); // we may have received QCop messages in the meantime.
2155#endif 2130#endif
2156 2131
2157 if ( d->keep_running ) 2132 if ( d->keep_running )
2158 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 2133 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
2159 return QApplication::exec(); 2134 return QApplication::exec();
2160 2135
2161#ifndef QT_NO_COP 2136#ifndef QT_NO_COP
2162 2137
2163 { 2138 {
2164 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2139 QCopEnvelope e( "QPE/System", "closing(QString)" );
2165 e << d->appName; 2140 e << d->appName;
2166 } 2141 }
2167#endif 2142#endif
2168 processEvents(); 2143 processEvents();
2169 return 0; 2144 return 0;
2170} 2145}
2171 2146
2172/*! 2147/*!
2173 \internal 2148 \internal
2174 External request for application to quit. Quits if possible without 2149 External request for application to quit. Quits if possible without
2175 loosing state. 2150 loosing state.
2176*/ 2151*/
2177void QPEApplication::tryQuit() 2152void QPEApplication::tryQuit()
2178{ 2153{
2179 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 2154 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
2180 return ; // Inside modal loop or konsole. Too hard to save state. 2155 return ; // Inside modal loop or konsole. Too hard to save state.
2181#ifndef QT_NO_COP 2156#ifndef QT_NO_COP
2182 2157
2183 { 2158 {
2184 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2159 QCopEnvelope e( "QPE/System", "closing(QString)" );
2185 e << d->appName; 2160 e << d->appName;
2186 } 2161 }
2187#endif 2162#endif
2188 if ( d->keep_running ) 2163 if ( d->keep_running )
2189 d->store_widget_rect(d->qpe_main_widget, d->appName); 2164 d->store_widget_rect(d->qpe_main_widget, d->appName);
2190 processEvents(); 2165 processEvents();
2191 2166
2192 quit(); 2167 quit();
2193} 2168}
2194 2169
2195/*! 2170/*!
2196 \internal 2171 \internal
2197*/ 2172*/
2198void QPEApplication::installTranslation( const QString& baseName ) { 2173void QPEApplication::installTranslation( const QString& baseName ) {
2199 QTranslator* trans = new QTranslator(this); 2174 QTranslator* trans = new QTranslator(this);
2200 QString tfn = qpeDir() + "/i18n/"+baseName; 2175 QString tfn = qpeDir() + "/i18n/"+baseName;
2201 if ( trans->load( tfn ) ) 2176 if ( trans->load( tfn ) )
2202 installTranslator( trans ); 2177 installTranslator( trans );
2203 else 2178 else
2204 delete trans; 2179 delete trans;
2205} 2180}
2206 2181
2207/*! 2182/*!
2208 \internal 2183 \internal
2209 User initiated quit. Makes the window 'Go Away'. If preloaded this means 2184 User initiated quit. Makes the window 'Go Away'. If preloaded this means
2210 hiding the window. If not it means quitting the application. 2185 hiding the window. If not it means quitting the application.
2211 As this is user initiated we don't need to check state. 2186 As this is user initiated we don't need to check state.
2212*/ 2187*/
2213void QPEApplication::hideOrQuit() 2188void QPEApplication::hideOrQuit()
2214{ 2189{
2215 if ( d->keep_running ) 2190 if ( d->keep_running )
2216 d->store_widget_rect(d->qpe_main_widget, d->appName); 2191 d->store_widget_rect(d->qpe_main_widget, d->appName);
2217 processEvents(); 2192 processEvents();
2218 2193
2219 // If we are a preloaded application we don't actually quit, so emit 2194 // If we are a preloaded application we don't actually quit, so emit
2220 // a System message indicating we're quasi-closing. 2195 // a System message indicating we're quasi-closing.
2221 if ( d->preloaded && d->qpe_main_widget ) 2196 if ( d->preloaded && d->qpe_main_widget )
2222#ifndef QT_NO_COP 2197#ifndef QT_NO_COP
2223 2198
2224 { 2199 {
2225 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 2200 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
2226 e << d->appName; 2201 e << d->appName;
2227 d->qpe_main_widget->hide(); 2202 d->qpe_main_widget->hide();
2228 } 2203 }
2229#endif 2204#endif
2230 else 2205 else
2231 quit(); 2206 quit();
2232} 2207}
2233 2208
2234#if (__GNUC__ > 2 ) 2209#if (__GNUC__ > 2 )
2235extern "C" void __cxa_pure_virtual(); 2210extern "C" void __cxa_pure_virtual();
2236 2211
2237void __cxa_pure_virtual() 2212void __cxa_pure_virtual()
2238{ 2213{
2239 fprintf( stderr, "Pure virtual called\n"); 2214 fprintf( stderr, "Pure virtual called\n");
2240 abort(); 2215 abort();
2241 2216
2242} 2217}
2243 2218
2244#endif 2219#endif
2245 2220
2246 2221
2247#if defined(OPIE_NEW_MALLOC) 2222#if defined(OPIE_NEW_MALLOC)
2248 2223
2249// The libraries with the skiff package (and possibly others) have 2224// The libraries with the skiff package (and possibly others) have
2250// completely useless implementations of builtin new and delete that 2225// completely useless implementations of builtin new and delete that
2251// use about 50% of your CPU. Here we revert to the simple libc 2226// use about 50% of your CPU. Here we revert to the simple libc
2252// functions. 2227// functions.
2253 2228
2254void* operator new[]( size_t size ) 2229void* operator new[]( size_t size )
2255{ 2230{
2256 return malloc( size ); 2231 return malloc( size );
2257} 2232}
2258 2233
2259void* operator new( size_t size ) 2234void* operator new( size_t size )
2260{ 2235{
2261 return malloc( size ); 2236 return malloc( size );
2262} 2237}
2263 2238
2264void operator delete[]( void* p ) 2239void operator delete[]( void* p )
2265{ 2240{
2266 free( p ); 2241 free( p );
2267} 2242}
2268 2243
2269void operator delete[]( void* p, size_t /*size*/ ) 2244void operator delete[]( void* p, size_t /*size*/ )
2270{ 2245{
2271 free( p ); 2246 free( p );
2272} 2247}
2273 2248
2274 2249
2275void operator delete( void* p ) 2250void operator delete( void* p )
2276{ 2251{
2277 free( p ); 2252 free( p );
2278} 2253}
2279 2254
2280void operator delete( void* p, size_t /*size*/ ) 2255void operator delete( void* p, size_t /*size*/ )
2281{ 2256{
2282 free( p ); 2257 free( p );
2283} 2258}
2284 2259
2285#endif 2260#endif
2286 2261
2287#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 2262#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
2288#include <qwidgetlist.h> 2263#include <qwidgetlist.h>
2289#ifdef QWS 2264#ifdef QWS
2290#include <qgfx_qws.h> 2265#include <qgfx_qws.h>
2291extern QRect qt_maxWindowRect; 2266extern QRect qt_maxWindowRect;
2292void qt_setMaxWindowRect(const QRect& r ) 2267void qt_setMaxWindowRect(const QRect& r )
2293{ 2268{
2294 qt_maxWindowRect = qt_screen->mapFromDevice( r, 2269 qt_maxWindowRect = qt_screen->mapFromDevice( r,
2295 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2270 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
2296 // Re-resize any maximized windows 2271 // Re-resize any maximized windows
2297 QWidgetList* l = QApplication::topLevelWidgets(); 2272 QWidgetList* l = QApplication::topLevelWidgets();
2298 if ( l ) { 2273 if ( l ) {
2299 QWidget * w = l->first(); 2274 QWidget * w = l->first();
2300 while ( w ) { 2275 while ( w ) {
2301 if ( w->isVisible() && w->isMaximized() ) { 2276 if ( w->isVisible() && w->isMaximized() ) {
2302 w->showMaximized(); 2277 w->showMaximized();
2303 } 2278 }
2304 w = l->next(); 2279 w = l->next();
2305 } 2280 }
2306 delete l; 2281 delete l;
2307 } 2282 }
2308} 2283}
2309#endif 2284#endif
2310#endif 2285#endif