summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp271
1 files changed, 240 insertions, 31 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 755fb19..90cd5f1 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,424 +1,629 @@
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
100{
101public:
102 bool needsOk()
103 { return (getWState() & WState_Reserved1 ); }
104
105 QRect normalGeometry()
106 { return topData()->normalGeometry; };
107};
99 108
100class QPEApplicationData 109class QPEApplicationData
101{ 110{
102public: 111public:
103 QPEApplicationData ( ) 112 QPEApplicationData ( )
104 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 113 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
105 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 114 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
106 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) 115 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 )
107 116
108 {} 117 {}
109 118
110 int presstimer; 119 int presstimer;
111 QWidget* presswidget; 120 QWidget* presswidget;
112 QPoint presspos; 121 QPoint presspos;
113 122
114 bool rightpressed : 1; 123 bool rightpressed : 1;
115 bool kbgrabbed : 1; 124 bool kbgrabbed : 1;
116 bool notbusysent : 1; 125 bool notbusysent : 1;
117 bool preloaded : 1; 126 bool preloaded : 1;
118 bool forceshow : 1; 127 bool forceshow : 1;
119 bool nomaximize : 1; 128 bool nomaximize : 1;
120 bool keep_running : 1; 129 bool keep_running : 1;
121 bool qcopQok : 1; 130 bool qcopQok : 1;
122 131
123 132
124 QStringList langs; 133 QStringList langs;
125 QString appName; 134 QString appName;
126 struct QCopRec 135 struct QCopRec
127 { 136 {
128 QCopRec( const QCString &ch, const QCString &msg, 137 QCopRec( const QCString &ch, const QCString &msg,
129 const QByteArray &d ) : 138 const QByteArray &d ) :
130 channel( ch ), message( msg ), data( d ) 139 channel( ch ), message( msg ), data( d )
131 { } 140 { }
132 141
133 QCString channel; 142 QCString channel;
134 QCString message; 143 QCString message;
135 QByteArray data; 144 QByteArray data;
136 }; 145 };
137 QWidget* qpe_main_widget; 146 QWidget* qpe_main_widget;
138 QGuardedPtr<QWidget> lastraised; 147 QGuardedPtr<QWidget> lastraised;
139 QQueue<QCopRec> qcopq; 148 QQueue<QCopRec> qcopq;
140 QString styleName; 149 QString styleName;
141 QString decorationName; 150 QString decorationName;
142 151
143 void enqueueQCop( const QCString &ch, const QCString &msg, 152 void enqueueQCop( const QCString &ch, const QCString &msg,
144 const QByteArray &data ) 153 const QByteArray &data )
145 { 154 {
146 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 155 qcopq.enqueue( new QCopRec( ch, msg, data ) );
147 } 156 }
148 void sendQCopQ() 157 void sendQCopQ()
149 { 158 {
150 if (!qcopQok ) 159 if (!qcopQok )
151 return; 160 return;
152 161
153 QCopRec * r; 162 QCopRec * r;
154 163
155 while((r=qcopq.dequeue())) { 164 while((r=qcopq.dequeue())) {
156 // remove from queue before sending... 165 // remove from queue before sending...
157 // event loop can come around again before getting 166 // event loop can come around again before getting
158 // back from sendLocally 167 // back from sendLocally
159#ifndef QT_NO_COP 168#ifndef QT_NO_COP
160 QCopChannel::sendLocally( r->channel, r->message, r->data ); 169 QCopChannel::sendLocally( r->channel, r->message, r->data );
161#endif 170#endif
162 171
163 delete r; 172 delete r;
164 } 173 }
165 } 174 }
166 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) 175
176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */)
167 { 177 {
178 if ( mw->isVisible() ) {
179 mw->raise();
180 } else {
181 QPoint p;
182 QSize s;
183
184 if ( mw->layout() && mw->inherits("QDialog") ) {
185 bool max;
186 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
187 mw->resize(s);
188 mw->move(p);
189
190 if ( max && !nomaximize )
191 mw->showMaximized();
192 else
193 mw->show();
194 } else {
195 qpe_show_dialog((QDialog*)mw,nomaximize);
196 }
197 } else {
198 bool max;
199 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
200 mw->resize(s);
201 mw->move(p);
202 } else { //no stored rectangle, make an estimation
203 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
204 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
205 mw->move( QMAX(x,0), QMAX(y,0) );
206#ifdef Q_WS_QWS
207 if ( !nomaximize )
208 mw->showMaximized();
209#endif
210 }
211 if ( max && !nomaximize )
212 mw->showMaximized();
213 else
214 mw->show();
215 }
216 }
217 }
218// // ugly hack, remove that later after finding a sane solution
219// // 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
221// // a (physically) large enough display to use the small icons
222// #if defined(OPIE_HIGH_RES_SMALL_PHY)
223// if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
224// ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
225// }
226// #endif
227
228 // if ( mw->layout() && mw->inherits("QDialog") ) {
229 // QPEApplication::showDialog((QDialog*)mw, nomaximize);
230 // }
231 // else {
232// #ifdef Q_WS_QWS
233 // if ( !nomaximize ) {
234 // qDebug("QDialog special case XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
235 // mw->showMaximized();
236 // //QPEApplication::showWidget( mw, !nomaximize );
237 // }else
238// #endif
239 // mw->show();
240 // }
241 //}
242
243
244static void qpe_show_dialog( QDialog* d, bool nomax )
245{
246 QSize sh = d->sizeHint();
247 int w = QMAX(sh.width(),d->width());
248 int h = QMAX(sh.height(),d->height());
168 249
169 // ugly hack, remove that later after finding a sane solution 250 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() )
170 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 251 nomax = TRUE;
171 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has 252
172 // a (physically) large enough display to use the small icons 253#ifndef Q_WS_QWS
173#if defined(OPIE_HIGH_RES_SMALL_PHY) 254 QSize s(qApp->desktop()->width(), qApp->desktop()->height() );
174 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 255#else
175 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 256 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() );
176 }
177#endif 257#endif
178 258
179 if ( mw->layout() && mw->inherits("QDialog") ) { 259 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width());
180 QPEApplication::showDialog((QDialog*)mw, nomaximize); 260 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height());
181 } 261
182 else { 262 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) {
183#ifdef Q_WS_QWS 263 d->showMaximized();
184 if ( !nomaximize ) 264 } else {
185 mw->showMaximized(); 265 // try centering the dialog around its parent
186 else 266 QPoint p(0,0);
267 if ( d->parentWidget() ) {
268 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
269 p = QPoint( pp.x() + d->parentWidget()->width()/2,
270 pp.y() + d->parentWidget()->height()/ 2 );
271 } else {
272 p = QPoint( maxX/2, maxY/2 );
273 }
274
275 p = QPoint( p.x() - w/2, p.y() - h/2 );
276 //qDebug("p(x,y) is %d %d", p.x(), p.y() );
277
278 if ( w >= maxX ) {
279 if ( p.y() < 0 )
280 p.setY(0);
281 if ( p.y() + h > maxY )
282 p.setY( maxY - h);
283
284 d->resize(maxX, h);
285 d->move(0, p.y() );
286 } else if ( h >= maxY ) {
287 if ( p.x() < 0 )
288 p.setX(0);
289 if ( p.x() + w > maxX )
290 p.setX( maxX - w);
291
292 d->resize(w, maxY);
293 d->move(p.x(),0);
294 } else {
295 d->resize(w, h);
296 }
297
298 d->show();
299 }
300}
301
302 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
303 {
304 maximized = TRUE;
305
306 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
307 if ( qApp->desktop()->width() <= 350 )
308 return FALSE;
309
310 Config cfg( "qpe" );
311 cfg.setGroup("ApplicationPositions");
312 QString str = cfg.readEntry( app, QString::null );
313 QStringList l = QStringList::split(",", str);
314
315 if ( l.count() == 5) {
316 p.setX( l[0].toInt() );
317 p.setY( l[1].toInt() );
318
319 s.setWidth( l[2].toInt() );
320 s.setHeight( l[3].toInt() );
321
322 maximized = l[4].toInt();
323
324 return TRUE;
325 }
326
327 return FALSE;
328 }
329
330
331 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
332 {
333#ifndef Q_WS_QWS
334 QRect qt_maxWindowRect = qApp->desktop()->geometry();
187#endif 335#endif
336 int maxX = qt_maxWindowRect.width();
337 int maxY = qt_maxWindowRect.height();
338 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
339 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
188 340
189 mw->show(); 341 // total window size is not allowed to be larger than desktop window size
190 } 342 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
343 return FALSE;
344
345 if ( wWidth > maxX ) {
346 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
347 wWidth = maxX;
348 }
349
350 if ( wHeight > maxY ) {
351 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
352 wHeight = maxY;
191 } 353 }
354
355 // any smaller than this and the maximize/close/help buttons will be overlapping
356 if ( wWidth < 80 || wHeight < 60 )
357 return FALSE;
358
359 if ( p.x() < 0 )
360 p.setX(0);
361 if ( p.y() < 0 )
362 p.setY(0);
363
364 if ( p.x() + wWidth > maxX )
365 p.setX( maxX - wWidth );
366 if ( p.y() + wHeight > maxY )
367 p.setY( maxY - wHeight );
368
369 return TRUE;
370 }
371
372 static void store_widget_rect(QWidget *w, QString &app)
373 {
374 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
375 if ( qApp->desktop()->width() <= 350 )
376 return;
377
378 // 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 )
380 int offsetX = w->x() - w->geometry().left();
381 int offsetY = w->y() - w->geometry().top();
382
383 QRect r;
384 if ( w->isMaximized() )
385 r = ( (HackWidget *) w)->normalGeometry();
386 else
387 r = w->geometry();
388
389 // Stores the window placement as pos(), size() (due to the offset mapping)
390 Config cfg( "qpe" );
391 cfg.setGroup("ApplicationPositions");
392 QString s;
393 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
394 cfg.writeEntry( app, s );
395 }
396
192 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 397 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
193 { 398 {
194 /* 399 /*
195 // This works but disable it for now until it is safe to apply 400 // This works but disable it for now until it is safe to apply
196 // What is does is scan the .desktop files of all the apps for 401 // What is does is scan the .desktop files of all the apps for
197 // the applnk that has the corresponding argv[0] as this program 402 // the applnk that has the corresponding argv[0] as this program
198 // then it uses the name stored in the .desktop file as the caption 403 // then it uses the name stored in the .desktop file as the caption
199 // for the main widget. This saves duplicating translations for 404 // for the main widget. This saves duplicating translations for
200 // the app name in the program and in the .desktop files. 405 // the app name in the program and in the .desktop files.
201 406
202 AppLnkSet apps( appsPath ); 407 AppLnkSet apps( appsPath );
203 408
204 QList<AppLnk> appsList = apps.children(); 409 QList<AppLnk> appsList = apps.children();
205 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 410 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
206 if ( (*it)->exec() == appName ) { 411 if ( (*it)->exec() == appName ) {
207 mw->setCaption( (*it)->name() ); 412 mw->setCaption( (*it)->name() );
208 return TRUE; 413 return TRUE;
209 } 414 }
210 } 415 }
211 */ 416 */
212 return FALSE; 417 return FALSE;
213 } 418 }
214 419
215 420
216 void show(QWidget* mw, bool nomax) 421 void show(QWidget* mw, bool nomax)
217 { 422 {
218 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 423 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
219 nomaximize = nomax; 424 nomaximize = nomax;
220 qpe_main_widget = mw; 425 qpe_main_widget = mw;
221 qcopQok = TRUE; 426 qcopQok = TRUE;
222#ifndef QT_NO_COP 427#ifndef QT_NO_COP
223 428
224 sendQCopQ(); 429 sendQCopQ();
225#endif 430#endif
226 431
227 if ( preloaded ) { 432 if ( preloaded ) {
228 if (forceshow) 433 if (forceshow)
229 show_mx(mw, nomax); 434 show_mx(mw, nomax, appName);
230 } 435 }
231 else if ( keep_running ) { 436 else if ( keep_running ) {
232 show_mx(mw, nomax); 437 show_mx(mw, nomax, appName);
233 } 438 }
234 } 439 }
235 440
236 void loadTextCodecs() 441 void loadTextCodecs()
237 { 442 {
238 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 443 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
239#ifdef Q_OS_MACX 444#ifdef Q_OS_MACX
240 QDir dir( path, "lib*.dylib" ); 445 QDir dir( path, "lib*.dylib" );
241#else 446#else
242 QDir dir( path, "lib*.so" ); 447 QDir dir( path, "lib*.so" );
243#endif 448#endif
244 QStringList list; 449 QStringList list;
245 if ( dir. exists ( )) 450 if ( dir. exists ( ))
246 list = dir.entryList(); 451 list = dir.entryList();
247 QStringList::Iterator it; 452 QStringList::Iterator it;
248 for ( it = list.begin(); it != list.end(); ++it ) { 453 for ( it = list.begin(); it != list.end(); ++it ) {
249 TextCodecInterface *iface = 0; 454 TextCodecInterface *iface = 0;
250 QLibrary *lib = new QLibrary( path + "/" + *it ); 455 QLibrary *lib = new QLibrary( path + "/" + *it );
251 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 456 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
252 QValueList<int> mibs = iface->mibEnums(); 457 QValueList<int> mibs = iface->mibEnums();
253 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 458 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
254 (void)iface->createForMib(*i); 459 (void)iface->createForMib(*i);
255 // ### it exists now; need to remember if we can delete it 460 // ### it exists now; need to remember if we can delete it
256 } 461 }
257 } 462 }
258 else { 463 else {
259 lib->unload(); 464 lib->unload();
260 delete lib; 465 delete lib;
261 } 466 }
262 } 467 }
263 } 468 }
264 469
265 void loadImageCodecs() 470 void loadImageCodecs()
266 { 471 {
267 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 472 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
268#ifdef Q_OS_MACX 473#ifdef Q_OS_MACX
269 QDir dir( path, "lib*.dylib" ); 474 QDir dir( path, "lib*.dylib" );
270#else 475#else
271 QDir dir( path, "lib*.so" ); 476 QDir dir( path, "lib*.so" );
272#endif 477#endif
273 QStringList list; 478 QStringList list;
274 if ( dir. exists ( )) 479 if ( dir. exists ( ))
275 list = dir.entryList(); 480 list = dir.entryList();
276 QStringList::Iterator it; 481 QStringList::Iterator it;
277 for ( it = list.begin(); it != list.end(); ++it ) { 482 for ( it = list.begin(); it != list.end(); ++it ) {
278 ImageCodecInterface *iface = 0; 483 ImageCodecInterface *iface = 0;
279 QLibrary *lib = new QLibrary( path + "/" + *it ); 484 QLibrary *lib = new QLibrary( path + "/" + *it );
280 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 485 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
281 QStringList formats = iface->keys(); 486 QStringList formats = iface->keys();
282 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 487 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
283 (void)iface->installIOHandler(*i); 488 (void)iface->installIOHandler(*i);
284 // ### it exists now; need to remember if we can delete it 489 // ### it exists now; need to remember if we can delete it
285 } 490 }
286 } 491 }
287 else { 492 else {
288 lib->unload(); 493 lib->unload();
289 delete lib; 494 delete lib;
290 } 495 }
291 } 496 }
292 } 497 }
293}; 498};
294 499
295class ResourceMimeFactory : public QMimeSourceFactory 500class ResourceMimeFactory : public QMimeSourceFactory
296{ 501{
297public: 502public:
298 ResourceMimeFactory() : resImage( 0 ) 503 ResourceMimeFactory() : resImage( 0 )
299 { 504 {
300 setFilePath( Global::helpPath() ); 505 setFilePath( Global::helpPath() );
301 setExtensionType( "html", "text/html;charset=UTF-8" ); 506 setExtensionType( "html", "text/html;charset=UTF-8" );
302 } 507 }
303 ~ResourceMimeFactory() { 508 ~ResourceMimeFactory() {
304 delete resImage; 509 delete resImage;
305 } 510 }
306 511
307 const QMimeSource* data( const QString& abs_name ) const 512 const QMimeSource* data( const QString& abs_name ) const
308 { 513 {
309 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 514 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
310 if ( !r ) { 515 if ( !r ) {
311 int sl = abs_name.length(); 516 int sl = abs_name.length();
312 do { 517 do {
313 sl = abs_name.findRev( '/', sl - 1 ); 518 sl = abs_name.findRev( '/', sl - 1 );
314 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 519 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
315 int dot = name.findRev( '.' ); 520 int dot = name.findRev( '.' );
316 if ( dot >= 0 ) 521 if ( dot >= 0 )
317 name = name.left( dot ); 522 name = name.left( dot );
318 QImage img = Resource::loadImage( name ); 523 QImage img = Resource::loadImage( name );
319 if ( !img.isNull() ) { 524 if ( !img.isNull() ) {
320 delete resImage; 525 delete resImage;
321 resImage = new QImageDrag( img ); 526 resImage = new QImageDrag( img );
322 r = resImage; 527 r = resImage;
323 } 528 }
324 } 529 }
325 while ( !r && sl > 0 ); 530 while ( !r && sl > 0 );
326 } 531 }
327 return r; 532 return r;
328 } 533 }
329private: 534private:
330 mutable QImageDrag *resImage; 535 mutable QImageDrag *resImage;
331}; 536};
332 537
333static int& hack(int& i) 538static int& hack(int& i)
334{ 539{
335#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 540#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
336 // These should be created, but aren't in Qt 2.3.0 541 // These should be created, but aren't in Qt 2.3.0
337 (void)new QUtf8Codec; 542 (void)new QUtf8Codec;
338 (void)new QUtf16Codec; 543 (void)new QUtf16Codec;
339#endif 544#endif
340 return i; 545 return i;
341} 546}
342 547
343static int muted = 0; 548static int muted = 0;
344static int micMuted = 0; 549static int micMuted = 0;
345 550
346static void setVolume( int t = 0, int percent = -1 ) 551static void setVolume( int t = 0, int percent = -1 )
347{ 552{
348 switch ( t ) { 553 switch ( t ) {
349 case 0: { 554 case 0: {
350 Config cfg( "qpe" ); 555 Config cfg( "qpe" );
351 cfg.setGroup( "Volume" ); 556 cfg.setGroup( "Volume" );
352 if ( percent < 0 ) 557 if ( percent < 0 )
353 percent = cfg.readNumEntry( "VolumePercent", 50 ); 558 percent = cfg.readNumEntry( "VolumePercent", 50 );
354#ifndef QT_NO_SOUND 559#ifndef QT_NO_SOUND
355 int fd = 0; 560 int fd = 0;
356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 561 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
357 int vol = muted ? 0 : percent; 562 int vol = muted ? 0 : percent;
358 // set both channels to same volume 563 // set both channels to same volume
359 vol |= vol << 8; 564 vol |= vol << 8;
360 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 565 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
361 ::close( fd ); 566 ::close( fd );
362 } 567 }
363#endif 568#endif
364 } 569 }
365 break; 570 break;
366 } 571 }
367} 572}
368 573
369static void setMic( int t = 0, int percent = -1 ) 574static void setMic( int t = 0, int percent = -1 )
370{ 575{
371 switch ( t ) { 576 switch ( t ) {
372 case 0: { 577 case 0: {
373 Config cfg( "qpe" ); 578 Config cfg( "qpe" );
374 cfg.setGroup( "Volume" ); 579 cfg.setGroup( "Volume" );
375 if ( percent < 0 ) 580 if ( percent < 0 )
376 percent = cfg.readNumEntry( "Mic", 50 ); 581 percent = cfg.readNumEntry( "Mic", 50 );
377 582
378#ifndef QT_NO_SOUND 583#ifndef QT_NO_SOUND
379 int fd = 0; 584 int fd = 0;
380 int mic = micMuted ? 0 : percent; 585 int mic = micMuted ? 0 : percent;
381 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 586 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
382 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 587 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
383 ::close( fd ); 588 ::close( fd );
384 } 589 }
385#endif 590#endif
386 } 591 }
387 break; 592 break;
388 } 593 }
389} 594}
390 595
391 596
392static void setBass( int t = 0, int percent = -1 ) 597static void setBass( int t = 0, int percent = -1 )
393{ 598{
394 switch ( t ) { 599 switch ( t ) {
395 case 0: { 600 case 0: {
396 Config cfg( "qpe" ); 601 Config cfg( "qpe" );
397 cfg.setGroup( "Volume" ); 602 cfg.setGroup( "Volume" );
398 if ( percent < 0 ) 603 if ( percent < 0 )
399 percent = cfg.readNumEntry( "BassPercent", 50 ); 604 percent = cfg.readNumEntry( "BassPercent", 50 );
400 605
401#ifndef QT_NO_SOUND 606#ifndef QT_NO_SOUND
402 int fd = 0; 607 int fd = 0;
403 int bass = percent; 608 int bass = percent;
404 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 609 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
405 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 610 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
406 ::close( fd ); 611 ::close( fd );
407 } 612 }
408#endif 613#endif
409 } 614 }
410 break; 615 break;
411 } 616 }
412} 617}
413 618
414 619
415static void setTreble( int t = 0, int percent = -1 ) 620static void setTreble( int t = 0, int percent = -1 )
416{ 621{
417 switch ( t ) { 622 switch ( t ) {
418 case 0: { 623 case 0: {
419 Config cfg( "qpe" ); 624 Config cfg( "qpe" );
420 cfg.setGroup( "Volume" ); 625 cfg.setGroup( "Volume" );
421 if ( percent < 0 ) 626 if ( percent < 0 )
422 percent = cfg.readNumEntry( "TreblePercent", 50 ); 627 percent = cfg.readNumEntry( "TreblePercent", 50 );
423 628
424#ifndef QT_NO_SOUND 629#ifndef QT_NO_SOUND
@@ -674,392 +879,392 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
674 a++; 879 a++;
675 d->preloaded = TRUE; 880 d->preloaded = TRUE;
676 argc -= 1; 881 argc -= 1;
677 } 882 }
678 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 883 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
679 argv[ a ] = argv[ a + 1 ]; 884 argv[ a ] = argv[ a + 1 ];
680 a++; 885 a++;
681 d->preloaded = TRUE; 886 d->preloaded = TRUE;
682 d->forceshow = TRUE; 887 d->forceshow = TRUE;
683 argc -= 1; 888 argc -= 1;
684 } 889 }
685 } 890 }
686 891
687 /* overide stored arguments */ 892 /* overide stored arguments */
688 setArgs( argc, argv ); 893 setArgs( argc, argv );
689 894
690#endif 895#endif
691#else 896#else
692 initApp( argc, argv ); 897 initApp( argc, argv );
693#endif 898#endif
694 // qwsSetDecoration( new QPEDecoration() ); 899 // qwsSetDecoration( new QPEDecoration() );
695 900
696#ifndef QT_NO_TRANSLATION 901#ifndef QT_NO_TRANSLATION
697 902
698 d->langs = Global::languageList(); 903 d->langs = Global::languageList();
699 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 904 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
700 QString lang = *it; 905 QString lang = *it;
701 906
702 installTranslation( lang + "/libopie.qm"); 907 installTranslation( lang + "/libopie.qm");
703 installTranslation( lang + "/libqpe.qm" ); 908 installTranslation( lang + "/libqpe.qm" );
704 installTranslation( lang + "/" + d->appName + ".qm" ); 909 installTranslation( lang + "/" + d->appName + ".qm" );
705 910
706 911
707 //###language/font hack; should look it up somewhere 912 //###language/font hack; should look it up somewhere
708#ifdef QWS 913#ifdef QWS
709 914
710 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 915 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
711 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 916 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
712 setFont( fn ); 917 setFont( fn );
713 } 918 }
714#endif 919#endif
715 } 920 }
716#endif 921#endif
717 922
718 applyStyle(); 923 applyStyle();
719 924
720 if ( type() == GuiServer ) { 925 if ( type() == GuiServer ) {
721 setVolume(); 926 setVolume();
722 } 927 }
723 928
724 installEventFilter( this ); 929 installEventFilter( this );
725 930
726 QPEMenuToolFocusManager::initialize(); 931 QPEMenuToolFocusManager::initialize();
727 932
728#ifdef QT_NO_QWS_CURSOR 933#ifdef QT_NO_QWS_CURSOR
729 // if we have no cursor, probably don't want tooltips 934 // if we have no cursor, probably don't want tooltips
730 QToolTip::setEnabled( FALSE ); 935 QToolTip::setEnabled( FALSE );
731#endif 936#endif
732} 937}
733 938
734 939
735#ifdef QTOPIA_INTERNAL_INITAPP 940#ifdef QTOPIA_INTERNAL_INITAPP
736void QPEApplication::initApp( int argc, char **argv ) 941void QPEApplication::initApp( int argc, char **argv )
737{ 942{
738 delete pidChannel; 943 delete pidChannel;
739 d->keep_running = TRUE; 944 d->keep_running = TRUE;
740 d->preloaded = FALSE; 945 d->preloaded = FALSE;
741 d->forceshow = FALSE; 946 d->forceshow = FALSE;
742 947
743 QCString channel = QCString(argv[0]); 948 QCString channel = QCString(argv[0]);
744 949
745 channel.replace(QRegExp(".*/"),""); 950 channel.replace(QRegExp(".*/"),"");
746 d->appName = channel; 951 d->appName = channel;
747 952
748 #if QT_VERSION > 235 953 #if QT_VERSION > 235
749 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 954 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
750 #endif 955 #endif
751 956
752 channel = "QPE/Application/" + channel; 957 channel = "QPE/Application/" + channel;
753 pidChannel = new QCopChannel( channel, this); 958 pidChannel = new QCopChannel( channel, this);
754 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 959 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
755 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 960 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
756 961
757 962
758 963
759 processQCopFile(); 964 processQCopFile();
760 d->keep_running = d->qcopq.isEmpty(); 965 d->keep_running = d->qcopq.isEmpty();
761 966
762 for (int a=0; a<argc; a++) { 967 for (int a=0; a<argc; a++) {
763 if ( qstrcmp(argv[a],"-preload")==0 ) { 968 if ( qstrcmp(argv[a],"-preload")==0 ) {
764 argv[a] = argv[a+1]; 969 argv[a] = argv[a+1];
765 a++; 970 a++;
766 d->preloaded = TRUE; 971 d->preloaded = TRUE;
767 argc-=1; 972 argc-=1;
768 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 973 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
769 argv[a] = argv[a+1]; 974 argv[a] = argv[a+1];
770 a++; 975 a++;
771 d->preloaded = TRUE; 976 d->preloaded = TRUE;
772 d->forceshow = TRUE; 977 d->forceshow = TRUE;
773 argc-=1; 978 argc-=1;
774 } 979 }
775 } 980 }
776 981
777 /* overide stored arguments */ 982 /* overide stored arguments */
778 setArgs(argc, argv); 983 setArgs(argc, argv);
779 984
780 /* install translation here */ 985 /* install translation here */
781 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 986 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
782 installTranslation( (*it) + "/" + d->appName + ".qm" ); 987 installTranslation( (*it) + "/" + d->appName + ".qm" );
783} 988}
784#endif 989#endif
785 990
786 991
787static QPtrDict<void>* inputMethodDict = 0; 992static QPtrDict<void>* inputMethodDict = 0;
788static void createInputMethodDict() 993static void createInputMethodDict()
789{ 994{
790 if ( !inputMethodDict ) 995 if ( !inputMethodDict )
791 inputMethodDict = new QPtrDict<void>; 996 inputMethodDict = new QPtrDict<void>;
792} 997}
793 998
794/*! 999/*!
795 Returns the currently set hint to the system as to whether 1000 Returns the currently set hint to the system as to whether
796 widget \a w has any use for text input methods. 1001 widget \a w has any use for text input methods.
797 1002
798 1003
799 \sa setInputMethodHint() InputMethodHint 1004 \sa setInputMethodHint() InputMethodHint
800*/ 1005*/
801QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 1006QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
802{ 1007{
803 if ( inputMethodDict && w ) 1008 if ( inputMethodDict && w )
804 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 1009 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
805 return Normal; 1010 return Normal;
806} 1011}
807 1012
808/*! 1013/*!
809 \enum QPEApplication::InputMethodHint 1014 \enum QPEApplication::InputMethodHint
810 1015
811 \value Normal the application sometimes needs text input (the default). 1016 \value Normal the application sometimes needs text input (the default).
812 \value AlwaysOff the application never needs text input. 1017 \value AlwaysOff the application never needs text input.
813 \value AlwaysOn the application always needs text input. 1018 \value AlwaysOn the application always needs text input.
814*/ 1019*/
815 1020
816/*! 1021/*!
817 Hints to the system that widget \a w has use for text input methods 1022 Hints to the system that widget \a w has use for text input methods
818 as specified by \a mode. 1023 as specified by \a mode.
819 1024
820 \sa inputMethodHint() InputMethodHint 1025 \sa inputMethodHint() InputMethodHint
821*/ 1026*/
822void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1027void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
823{ 1028{
824 createInputMethodDict(); 1029 createInputMethodDict();
825 if ( mode == Normal ) { 1030 if ( mode == Normal ) {
826 inputMethodDict->remove 1031 inputMethodDict->remove
827 ( w ); 1032 ( w );
828 } 1033 }
829 else { 1034 else {
830 inputMethodDict->insert( w, ( void* ) mode ); 1035 inputMethodDict->insert( w, ( void* ) mode );
831 } 1036 }
832} 1037}
833 1038
834class HackDialog : public QDialog 1039class HackDialog : public QDialog
835{ 1040{
836public: 1041public:
837 void acceptIt() 1042 void acceptIt()
838 { 1043 {
839 accept(); 1044 accept();
840 } 1045 }
841 void rejectIt() 1046 void rejectIt()
842 { 1047 {
843 reject(); 1048 reject();
844 } 1049 }
845}; 1050};
846 1051
847 1052
848void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1053void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
849{ 1054{
850 // specialised actions for certain widgets. May want to 1055 // specialised actions for certain widgets. May want to
851 // add more stuff here. 1056 // add more stuff here.
852 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1057 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
853 && activePopupWidget() ->parentWidget() 1058 && activePopupWidget() ->parentWidget()
854 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1059 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
855 key = Qt::Key_Return; 1060 key = Qt::Key_Return;
856 1061
857 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1062 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
858 key = Qt::Key_Return; 1063 key = Qt::Key_Return;
859 1064
860#ifdef QWS 1065#ifdef QWS
861 1066
862 ke->simpleData.keycode = key; 1067 ke->simpleData.keycode = key;
863#endif 1068#endif
864} 1069}
865 1070
866class HackWidget : public QWidget 1071// class HackWidget : public QWidget
867{ 1072// {
868public: 1073// public:
869 bool needsOk() 1074 // bool needsOk()
870 { 1075 // {
871 return ( getWState() & WState_Reserved1 ); 1076 // return ( getWState() & WState_Reserved1 );
872 } 1077 // }
873}; 1078// };
874 1079
875/*! 1080/*!
876 \internal 1081 \internal
877*/ 1082*/
878 1083
879#ifdef QWS 1084#ifdef QWS
880bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1085bool QPEApplication::qwsEventFilter( QWSEvent * e )
881{ 1086{
882 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1087 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
883 if ( qApp->type() != QApplication::GuiServer ) { 1088 if ( qApp->type() != QApplication::GuiServer ) {
884 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1089 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
885 e << d->appName; 1090 e << d->appName;
886 } 1091 }
887 d->notbusysent = TRUE; 1092 d->notbusysent = TRUE;
888 } 1093 }
889 if ( type() == GuiServer ) { 1094 if ( type() == GuiServer ) {
890 switch ( e->type ) { 1095 switch ( e->type ) {
891 case QWSEvent::Mouse: 1096 case QWSEvent::Mouse:
892 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1097 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
893 emit clientMoused(); 1098 emit clientMoused();
894 break; 1099 break;
895 default: 1100 default:
896 break; 1101 break;
897 } 1102 }
898 } 1103 }
899 if ( e->type == QWSEvent::Key ) { 1104 if ( e->type == QWSEvent::Key ) {
900 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1105 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
901 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1106 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
902 // Use special "OK" key to press "OK" on top level widgets 1107 // Use special "OK" key to press "OK" on top level widgets
903 QWidget * active = activeWindow(); 1108 QWidget * active = activeWindow();
904 QWidget *popup = 0; 1109 QWidget *popup = 0;
905 if ( active && active->isPopup() ) { 1110 if ( active && active->isPopup() ) {
906 popup = active; 1111 popup = active;
907 active = active->parentWidget(); 1112 active = active->parentWidget();
908 } 1113 }
909 if ( active && ( int ) active->winId() == ke->simpleData.window && 1114 if ( active && ( int ) active->winId() == ke->simpleData.window &&
910 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1115 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
911 if ( ke->simpleData.is_press ) { 1116 if ( ke->simpleData.is_press ) {
912 if ( popup ) 1117 if ( popup )
913 popup->close(); 1118 popup->close();
914 if ( active->inherits( "QDialog" ) ) { 1119 if ( active->inherits( "QDialog" ) ) {
915 HackDialog * d = ( HackDialog * ) active; 1120 HackDialog * d = ( HackDialog * ) active;
916 d->acceptIt(); 1121 d->acceptIt();
917 return TRUE; 1122 return TRUE;
918 } 1123 }
919 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1124 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
920 QSignal s; 1125 QSignal s;
921 s.connect( active, SLOT( accept() ) ); 1126 s.connect( active, SLOT( accept() ) );
922 s.activate(); 1127 s.activate();
923 } 1128 }
924 else { 1129 else {
925 // do the same as with the select key: Map to the default action of the widget: 1130 // do the same as with the select key: Map to the default action of the widget:
926 mapToDefaultAction( ke, Qt::Key_Return ); 1131 mapToDefaultAction( ke, Qt::Key_Return );
927 } 1132 }
928 } 1133 }
929 } 1134 }
930 } 1135 }
931 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1136 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
932 // Use special "select" key to do whatever default action a widget has 1137 // Use special "select" key to do whatever default action a widget has
933 mapToDefaultAction( ke, Qt::Key_Space ); 1138 mapToDefaultAction( ke, Qt::Key_Space );
934 } 1139 }
935 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1140 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
936 ke->simpleData.is_press ) { 1141 ke->simpleData.is_press ) {
937 // Escape key closes app if focus on toplevel 1142 // Escape key closes app if focus on toplevel
938 QWidget * active = activeWindow(); 1143 QWidget * active = activeWindow();
939 if ( active && active->testWFlags( WType_TopLevel ) && 1144 if ( active && active->testWFlags( WType_TopLevel ) &&
940 ( int ) active->winId() == ke->simpleData.window && 1145 ( int ) active->winId() == ke->simpleData.window &&
941 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1146 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
942 if ( active->inherits( "QDialog" ) ) { 1147 if ( active->inherits( "QDialog" ) ) {
943 HackDialog * d = ( HackDialog * ) active; 1148 HackDialog * d = ( HackDialog * ) active;
944 d->rejectIt(); 1149 d->rejectIt();
945 return TRUE; 1150 return TRUE;
946 } 1151 }
947 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 1152 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
948 active->close(); 1153 active->close();
949 } 1154 }
950 } 1155 }
951 } 1156 }
952 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1157 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
953 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1158 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
954 // but we cannot access libopie function within libqpe :( 1159 // but we cannot access libopie function within libqpe :(
955 1160
956 QWidget * active = activeWindow ( ); 1161 QWidget * active = activeWindow ( );
957 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1162 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
958 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1163 if ( d-> kbgrabbed ) { // we grabbed the keyboard
959 QChar ch ( ke-> simpleData.unicode ); 1164 QChar ch ( ke-> simpleData.unicode );
960 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1165 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
961 ke-> simpleData.keycode, 1166 ke-> simpleData.keycode,
962 ch. latin1 ( ), 1167 ch. latin1 ( ),
963 ke-> simpleData.modifiers, 1168 ke-> simpleData.modifiers,
964 QString ( ch ), 1169 QString ( ch ),
965 ke-> simpleData.is_auto_repeat, 1 ); 1170 ke-> simpleData.is_auto_repeat, 1 );
966 1171
967 QObject *which = QWidget::keyboardGrabber ( ); 1172 QObject *which = QWidget::keyboardGrabber ( );
968 if ( !which ) 1173 if ( !which )
969 which = QApplication::focusWidget ( ); 1174 which = QApplication::focusWidget ( );
970 if ( !which ) 1175 if ( !which )
971 which = QApplication::activeWindow ( ); 1176 which = QApplication::activeWindow ( );
972 if ( !which ) 1177 if ( !which )
973 which = qApp; 1178 which = qApp;
974 1179
975 QApplication::sendEvent ( which, &qke ); 1180 QApplication::sendEvent ( which, &qke );
976 } 1181 }
977 else { // we didn't grab the keyboard, so send the event to the launcher 1182 else { // we didn't grab the keyboard, so send the event to the launcher
978 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1183 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
979 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1184 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
980 } 1185 }
981 } 1186 }
982 return true; 1187 return true;
983 } 1188 }
984 } 1189 }
985 if ( e->type == QWSEvent::Focus ) { 1190 if ( e->type == QWSEvent::Focus ) {
986 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1191 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
987 if ( !fe->simpleData.get_focus ) { 1192 if ( !fe->simpleData.get_focus ) {
988 QWidget * active = activeWindow(); 1193 QWidget * active = activeWindow();
989 while ( active && active->isPopup() ) { 1194 while ( active && active->isPopup() ) {
990 active->close(); 1195 active->close();
991 active = activeWindow(); 1196 active = activeWindow();
992 } 1197 }
993 } 1198 }
994 else { 1199 else {
995 // make sure our modal widget is ALWAYS on top 1200 // make sure our modal widget is ALWAYS on top
996 QWidget *topm = activeModalWidget(); 1201 QWidget *topm = activeModalWidget();
997 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1202 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
998 topm->raise(); 1203 topm->raise();
999 } 1204 }
1000 } 1205 }
1001 if ( fe->simpleData.get_focus && inputMethodDict ) { 1206 if ( fe->simpleData.get_focus && inputMethodDict ) {
1002 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1207 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1003 if ( m == AlwaysOff ) 1208 if ( m == AlwaysOff )
1004 Global::hideInputMethod(); 1209 Global::hideInputMethod();
1005 if ( m == AlwaysOn ) 1210 if ( m == AlwaysOn )
1006 Global::showInputMethod(); 1211 Global::showInputMethod();
1007 } 1212 }
1008 } 1213 }
1009 1214
1010 1215
1011 return QApplication::qwsEventFilter( e ); 1216 return QApplication::qwsEventFilter( e );
1012} 1217}
1013#endif 1218#endif
1014 1219
1015/*! 1220/*!
1016 Destroys the QPEApplication. 1221 Destroys the QPEApplication.
1017*/ 1222*/
1018QPEApplication::~QPEApplication() 1223QPEApplication::~QPEApplication()
1019{ 1224{
1020 ungrabKeyboard(); 1225 ungrabKeyboard();
1021#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1226#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1022 // Need to delete QCopChannels early, since the display will 1227 // Need to delete QCopChannels early, since the display will
1023 // be gone by the time we get to ~QObject(). 1228 // be gone by the time we get to ~QObject().
1024 delete sysChannel; 1229 delete sysChannel;
1025 delete pidChannel; 1230 delete pidChannel;
1026#endif 1231#endif
1027 1232
1028 delete d; 1233 delete d;
1029} 1234}
1030 1235
1031/*! 1236/*!
1032 Returns <tt>$OPIEDIR/</tt>. 1237 Returns <tt>$OPIEDIR/</tt>.
1033*/ 1238*/
1034QString QPEApplication::qpeDir() 1239QString QPEApplication::qpeDir()
1035{ 1240{
1036 const char * base = getenv( "OPIEDIR" ); 1241 const char * base = getenv( "OPIEDIR" );
1037 if ( base ) 1242 if ( base )
1038 return QString( base ) + "/"; 1243 return QString( base ) + "/";
1039 1244
1040 return QString( "../" ); 1245 return QString( "../" );
1041} 1246}
1042 1247
1043/*! 1248/*!
1044 Returns the user's current Document directory. There is a trailing "/". 1249 Returns the user's current Document directory. There is a trailing "/".
1045 .. well, it does now,, and there's no trailing '/' 1250 .. well, it does now,, and there's no trailing '/'
1046*/ 1251*/
1047QString QPEApplication::documentDir() 1252QString QPEApplication::documentDir()
1048{ 1253{
1049 const char* base = getenv( "HOME"); 1254 const char* base = getenv( "HOME");
1050 if ( base ) 1255 if ( base )
1051 return QString( base ) + "/Documents"; 1256 return QString( base ) + "/Documents";
1052 1257
1053 return QString( "../Documents" ); 1258 return QString( "../Documents" );
1054} 1259}
1055 1260
1056static int deforient = -1; 1261static int deforient = -1;
1057 1262
1058/*! 1263/*!
1059 \internal 1264 \internal
1060*/ 1265*/
1061int QPEApplication::defaultRotation() 1266int QPEApplication::defaultRotation()
1062{ 1267{
1063 if ( deforient < 0 ) { 1268 if ( deforient < 0 ) {
1064 QString d = getenv( "QWS_DISPLAY" ); 1269 QString d = getenv( "QWS_DISPLAY" );
1065 if ( d.contains( "Rot90" ) ) { 1270 if ( d.contains( "Rot90" ) ) {
@@ -1789,311 +1994,315 @@ QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1789 \a mode. 1994 \a mode.
1790 1995
1791 \sa stylusOperation() StylusMode 1996 \sa stylusOperation() StylusMode
1792*/ 1997*/
1793void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1998void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1794{ 1999{
1795 createDict(); 2000 createDict();
1796 if ( mode == LeftOnly ) { 2001 if ( mode == LeftOnly ) {
1797 stylusDict->remove 2002 stylusDict->remove
1798 ( w ); 2003 ( w );
1799 w->removeEventFilter( qApp ); 2004 w->removeEventFilter( qApp );
1800 } 2005 }
1801 else { 2006 else {
1802 stylusDict->insert( w, ( void* ) mode ); 2007 stylusDict->insert( w, ( void* ) mode );
1803 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 2008 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
1804 w->installEventFilter( qApp ); 2009 w->installEventFilter( qApp );
1805 } 2010 }
1806} 2011}
1807 2012
1808 2013
1809/*! 2014/*!
1810 \reimp 2015 \reimp
1811*/ 2016*/
1812bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 2017bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1813{ 2018{
1814 if ( !o->isWidgetType() ) 2019 if ( !o->isWidgetType() )
1815 return FALSE; 2020 return FALSE;
1816 2021
1817 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 2022 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1818 QMouseEvent * me = ( QMouseEvent* ) e; 2023 QMouseEvent * me = ( QMouseEvent* ) e;
1819 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 2024 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1820 switch (mode) { 2025 switch (mode) {
1821 case RightOnHold: 2026 case RightOnHold:
1822 switch ( me->type() ) { 2027 switch ( me->type() ) {
1823 case QEvent::MouseButtonPress: 2028 case QEvent::MouseButtonPress:
1824 if ( me->button() == LeftButton ) { 2029 if ( me->button() == LeftButton ) {
1825 if (!d->presstimer ) 2030 if (!d->presstimer )
1826 d->presstimer = startTimer(500); // #### pref. 2031 d->presstimer = startTimer(500); // #### pref.
1827 d->presswidget = (QWidget*)o; 2032 d->presswidget = (QWidget*)o;
1828 d->presspos = me->pos(); 2033 d->presspos = me->pos();
1829 d->rightpressed = FALSE; 2034 d->rightpressed = FALSE;
1830 } 2035 }
1831 break; 2036 break;
1832 case QEvent::MouseMove: 2037 case QEvent::MouseMove:
1833 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 2038 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
1834 killTimer(d->presstimer); 2039 killTimer(d->presstimer);
1835 d->presstimer = 0; 2040 d->presstimer = 0;
1836 } 2041 }
1837 break; 2042 break;
1838 case QEvent::MouseButtonRelease: 2043 case QEvent::MouseButtonRelease:
1839 if ( me->button() == LeftButton ) { 2044 if ( me->button() == LeftButton ) {
1840 if ( d->presstimer ) { 2045 if ( d->presstimer ) {
1841 killTimer(d->presstimer); 2046 killTimer(d->presstimer);
1842 d->presstimer = 0; 2047 d->presstimer = 0;
1843 } 2048 }
1844 if ( d->rightpressed && d->presswidget ) { 2049 if ( d->rightpressed && d->presswidget ) {
1845 // Right released 2050 // Right released
1846 postEvent( d->presswidget, 2051 postEvent( d->presswidget,
1847 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 2052 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1848 RightButton, LeftButton + RightButton ) ); 2053 RightButton, LeftButton + RightButton ) );
1849 // Left released, off-widget 2054 // Left released, off-widget
1850 postEvent( d->presswidget, 2055 postEvent( d->presswidget,
1851 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 2056 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
1852 LeftButton, LeftButton ) ); 2057 LeftButton, LeftButton ) );
1853 postEvent( d->presswidget, 2058 postEvent( d->presswidget,
1854 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 2059 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
1855 LeftButton, LeftButton ) ); 2060 LeftButton, LeftButton ) );
1856 d->rightpressed = FALSE; 2061 d->rightpressed = FALSE;
1857 return TRUE; // don't send the real Left release 2062 return TRUE; // don't send the real Left release
1858 } 2063 }
1859 } 2064 }
1860 break; 2065 break;
1861 default: 2066 default:
1862 break; 2067 break;
1863 } 2068 }
1864 break; 2069 break;
1865 default: 2070 default:
1866 ; 2071 ;
1867 } 2072 }
1868 } 2073 }
1869 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 2074 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1870 QKeyEvent *ke = (QKeyEvent *)e; 2075 QKeyEvent *ke = (QKeyEvent *)e;
1871 if ( ke->key() == Key_Enter ) { 2076 if ( ke->key() == Key_Enter ) {
1872 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 2077 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1873 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 2078 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1874 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 2079 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1875 return TRUE; 2080 return TRUE;
1876 } 2081 }
1877 } 2082 }
1878 } 2083 }
1879 return FALSE; 2084 return FALSE;
1880} 2085}
1881 2086
1882/*! 2087/*!
1883 \reimp 2088 \reimp
1884*/ 2089*/
1885void QPEApplication::timerEvent( QTimerEvent *e ) 2090void QPEApplication::timerEvent( QTimerEvent *e )
1886{ 2091{
1887 if ( e->timerId() == d->presstimer && d->presswidget ) { 2092 if ( e->timerId() == d->presstimer && d->presswidget ) {
1888 // Right pressed 2093 // Right pressed
1889 postEvent( d->presswidget, 2094 postEvent( d->presswidget,
1890 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 2095 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
1891 RightButton, LeftButton ) ); 2096 RightButton, LeftButton ) );
1892 killTimer( d->presstimer ); 2097 killTimer( d->presstimer );
1893 d->presstimer = 0; 2098 d->presstimer = 0;
1894 d->rightpressed = TRUE; 2099 d->rightpressed = TRUE;
1895 } 2100 }
1896} 2101}
1897 2102
1898void QPEApplication::removeSenderFromStylusDict() 2103void QPEApplication::removeSenderFromStylusDict()
1899{ 2104{
1900 stylusDict->remove 2105 stylusDict->remove
1901 ( ( void* ) sender() ); 2106 ( ( void* ) sender() );
1902 if ( d->presswidget == sender() ) 2107 if ( d->presswidget == sender() )
1903 d->presswidget = 0; 2108 d->presswidget = 0;
1904} 2109}
1905 2110
1906/*! 2111/*!
1907 \internal 2112 \internal
1908*/ 2113*/
1909bool QPEApplication::keyboardGrabbed() const 2114bool QPEApplication::keyboardGrabbed() const
1910{ 2115{
1911 return d->kbgrabbed; 2116 return d->kbgrabbed;
1912} 2117}
1913 2118
1914 2119
1915/*! 2120/*!
1916 Reverses the effect of grabKeyboard(). This is called automatically 2121 Reverses the effect of grabKeyboard(). This is called automatically
1917 on program exit. 2122 on program exit.
1918*/ 2123*/
1919void QPEApplication::ungrabKeyboard() 2124void QPEApplication::ungrabKeyboard()
1920{ 2125{
1921 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 2126 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
1922} 2127}
1923 2128
1924/*! 2129/*!
1925 Grabs the physical keyboard keys, e.g. the application's launching 2130 Grabs the physical keyboard keys, e.g. the application's launching
1926 keys. Instead of launching applications when these keys are pressed 2131 keys. Instead of launching applications when these keys are pressed
1927 the signals emitted are sent to this application instead. Some games 2132 the signals emitted are sent to this application instead. Some games
1928 programs take over the launch keys in this way to make interaction 2133 programs take over the launch keys in this way to make interaction
1929 easier. 2134 easier.
1930 2135
1931 \sa ungrabKeyboard() 2136 \sa ungrabKeyboard()
1932*/ 2137*/
1933void QPEApplication::grabKeyboard() 2138void QPEApplication::grabKeyboard()
1934{ 2139{
1935 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 2140 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
1936} 2141}
1937 2142
1938/*! 2143/*!
1939 \reimp 2144 \reimp
1940*/ 2145*/
1941int QPEApplication::exec() 2146int QPEApplication::exec()
1942{ 2147{
1943 d->qcopQok = true; 2148 d->qcopQok = true;
1944#ifndef QT_NO_COP 2149#ifndef QT_NO_COP
1945 d->sendQCopQ(); 2150 d->sendQCopQ();
1946 if ( !d->keep_running ) 2151 if ( !d->keep_running )
1947 processEvents(); // we may have received QCop messages in the meantime. 2152 processEvents(); // we may have received QCop messages in the meantime.
1948#endif 2153#endif
1949 2154
1950 if ( d->keep_running ) 2155 if ( d->keep_running )
1951 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 2156 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1952 return QApplication::exec(); 2157 return QApplication::exec();
1953 2158
1954#ifndef QT_NO_COP 2159#ifndef QT_NO_COP
1955 2160
1956 { 2161 {
1957 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2162 QCopEnvelope e( "QPE/System", "closing(QString)" );
1958 e << d->appName; 2163 e << d->appName;
1959 } 2164 }
1960#endif 2165#endif
1961 processEvents(); 2166 processEvents();
1962 return 0; 2167 return 0;
1963} 2168}
1964 2169
1965/*! 2170/*!
1966 \internal 2171 \internal
1967 External request for application to quit. Quits if possible without 2172 External request for application to quit. Quits if possible without
1968 loosing state. 2173 loosing state.
1969*/ 2174*/
1970void QPEApplication::tryQuit() 2175void QPEApplication::tryQuit()
1971{ 2176{
1972 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 2177 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1973 return ; // Inside modal loop or konsole. Too hard to save state. 2178 return ; // Inside modal loop or konsole. Too hard to save state.
1974#ifndef QT_NO_COP 2179#ifndef QT_NO_COP
1975 2180
1976 { 2181 {
1977 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2182 QCopEnvelope e( "QPE/System", "closing(QString)" );
1978 e << d->appName; 2183 e << d->appName;
1979 } 2184 }
1980#endif 2185#endif
2186 if ( d->keep_running )
2187 d->store_widget_rect(d->qpe_main_widget, d->appName);
1981 processEvents(); 2188 processEvents();
1982 2189
1983 quit(); 2190 quit();
1984} 2191}
1985 2192
1986/*! 2193/*!
1987 \internal 2194 \internal
1988*/ 2195*/
1989void QPEApplication::installTranslation( const QString& baseName ) { 2196void QPEApplication::installTranslation( const QString& baseName ) {
1990 QTranslator* trans = new QTranslator(this); 2197 QTranslator* trans = new QTranslator(this);
1991 QString tfn = qpeDir() + "/i18n/"+baseName; 2198 QString tfn = qpeDir() + "/i18n/"+baseName;
1992 if ( trans->load( tfn ) ) 2199 if ( trans->load( tfn ) )
1993 installTranslator( trans ); 2200 installTranslator( trans );
1994 else 2201 else
1995 delete trans; 2202 delete trans;
1996} 2203}
1997 2204
1998/*! 2205/*!
1999 \internal 2206 \internal
2000 User initiated quit. Makes the window 'Go Away'. If preloaded this means 2207 User initiated quit. Makes the window 'Go Away'. If preloaded this means
2001 hiding the window. If not it means quitting the application. 2208 hiding the window. If not it means quitting the application.
2002 As this is user initiated we don't need to check state. 2209 As this is user initiated we don't need to check state.
2003*/ 2210*/
2004void QPEApplication::hideOrQuit() 2211void QPEApplication::hideOrQuit()
2005{ 2212{
2213 if ( d->keep_running )
2214 d->store_widget_rect(d->qpe_main_widget, d->appName);
2006 processEvents(); 2215 processEvents();
2007 2216
2008 // If we are a preloaded application we don't actually quit, so emit 2217 // If we are a preloaded application we don't actually quit, so emit
2009 // a System message indicating we're quasi-closing. 2218 // a System message indicating we're quasi-closing.
2010 if ( d->preloaded && d->qpe_main_widget ) 2219 if ( d->preloaded && d->qpe_main_widget )
2011#ifndef QT_NO_COP 2220#ifndef QT_NO_COP
2012 2221
2013 { 2222 {
2014 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 2223 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
2015 e << d->appName; 2224 e << d->appName;
2016 d->qpe_main_widget->hide(); 2225 d->qpe_main_widget->hide();
2017 } 2226 }
2018#endif 2227#endif
2019 else 2228 else
2020 quit(); 2229 quit();
2021} 2230}
2022 2231
2023#if (__GNUC__ > 2 ) 2232#if (__GNUC__ > 2 )
2024extern "C" void __cxa_pure_virtual(); 2233extern "C" void __cxa_pure_virtual();
2025 2234
2026void __cxa_pure_virtual() 2235void __cxa_pure_virtual()
2027{ 2236{
2028 fprintf( stderr, "Pure virtual called\n"); 2237 fprintf( stderr, "Pure virtual called\n");
2029 abort(); 2238 abort();
2030 2239
2031} 2240}
2032 2241
2033#endif 2242#endif
2034 2243
2035 2244
2036#if defined(OPIE_NEW_MALLOC) 2245#if defined(OPIE_NEW_MALLOC)
2037 2246
2038// The libraries with the skiff package (and possibly others) have 2247// The libraries with the skiff package (and possibly others) have
2039// completely useless implementations of builtin new and delete that 2248// completely useless implementations of builtin new and delete that
2040// use about 50% of your CPU. Here we revert to the simple libc 2249// use about 50% of your CPU. Here we revert to the simple libc
2041// functions. 2250// functions.
2042 2251
2043void* operator new[]( size_t size ) 2252void* operator new[]( size_t size )
2044{ 2253{
2045 return malloc( size ); 2254 return malloc( size );
2046} 2255}
2047 2256
2048void* operator new( size_t size ) 2257void* operator new( size_t size )
2049{ 2258{
2050 return malloc( size ); 2259 return malloc( size );
2051} 2260}
2052 2261
2053void operator delete[]( void* p ) 2262void operator delete[]( void* p )
2054{ 2263{
2055 free( p ); 2264 free( p );
2056} 2265}
2057 2266
2058void operator delete[]( void* p, size_t /*size*/ ) 2267void operator delete[]( void* p, size_t /*size*/ )
2059{ 2268{
2060 free( p ); 2269 free( p );
2061} 2270}
2062 2271
2063 2272
2064void operator delete( void* p ) 2273void operator delete( void* p )
2065{ 2274{
2066 free( p ); 2275 free( p );
2067} 2276}
2068 2277
2069void operator delete( void* p, size_t /*size*/ ) 2278void operator delete( void* p, size_t /*size*/ )
2070{ 2279{
2071 free( p ); 2280 free( p );
2072} 2281}
2073 2282
2074#endif 2283#endif
2075 2284
2076#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 2285#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
2077#include <qwidgetlist.h> 2286#include <qwidgetlist.h>
2078#ifdef QWS 2287#ifdef QWS
2079#include <qgfx_qws.h> 2288#include <qgfx_qws.h>
2080extern QRect qt_maxWindowRect; 2289extern QRect qt_maxWindowRect;
2081void qt_setMaxWindowRect(const QRect& r ) 2290void qt_setMaxWindowRect(const QRect& r )
2082{ 2291{
2083 qt_maxWindowRect = qt_screen->mapFromDevice( r, 2292 qt_maxWindowRect = qt_screen->mapFromDevice( r,
2084 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2293 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
2085 // Re-resize any maximized windows 2294 // Re-resize any maximized windows
2086 QWidgetList* l = QApplication::topLevelWidgets(); 2295 QWidgetList* l = QApplication::topLevelWidgets();
2087 if ( l ) { 2296 if ( l ) {
2088 QWidget * w = l->first(); 2297 QWidget * w = l->first();
2089 while ( w ) { 2298 while ( w ) {
2090 if ( w->isVisible() && w->isMaximized() ) { 2299 if ( w->isVisible() && w->isMaximized() ) {
2091 w->showMaximized(); 2300 w->showMaximized();
2092 } 2301 }
2093 w = l->next(); 2302 w = l->next();
2094 } 2303 }
2095 delete l; 2304 delete l;
2096 } 2305 }
2097} 2306}
2098#endif 2307#endif
2099#endif 2308#endif