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