summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp3
1 files changed, 0 insertions, 3 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 4c93111..b5dff3a 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,1746 +1,1743 @@
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** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22#define QTOPIA_INTERNAL_LANGLIST 22#define QTOPIA_INTERNAL_LANGLIST
23#include <stdlib.h> 23#include <stdlib.h>
24#include <unistd.h> 24#include <unistd.h>
25#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 25#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
26#include <qfile.h> 26#include <qfile.h>
27#ifdef Q_WS_QWS 27#ifdef Q_WS_QWS
28#ifndef QT_NO_COP 28#ifndef QT_NO_COP
29#if QT_VERSION <= 231 29#if QT_VERSION <= 231
30#define private public 30#define private public
31#define sendLocally processEvent 31#define sendLocally processEvent
32#include "qcopenvelope_qws.h" 32#include "qcopenvelope_qws.h"
33#undef private 33#undef private
34#else 34#else
35#include "qcopenvelope_qws.h" 35#include "qcopenvelope_qws.h"
36#endif 36#endif
37#endif 37#endif
38#include <qwindowsystem_qws.h> 38#include <qwindowsystem_qws.h>
39#endif 39#endif
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qpalette.h> 41#include <qpalette.h>
42#include <qbuffer.h> 42#include <qbuffer.h>
43#include <qptrdict.h> 43#include <qptrdict.h>
44#include <qregexp.h> 44#include <qregexp.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <qlabel.h> 46#include <qlabel.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qdragobject.h> 48#include <qdragobject.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qevent.h> 50#include <qevent.h>
51#include <qtooltip.h> 51#include <qtooltip.h>
52#include <qsignal.h> 52#include <qsignal.h>
53#include "qpeapplication.h" 53#include "qpeapplication.h"
54#include "qpestyle.h" 54#include "qpestyle.h"
55#include "styleinterface.h" 55#include "styleinterface.h"
56#if QT_VERSION >= 300 56#if QT_VERSION >= 300
57#include <qstylefactory.h> 57#include <qstylefactory.h>
58#else 58#else
59#include <qplatinumstyle.h> 59#include <qplatinumstyle.h>
60#include <qwindowsstyle.h> 60#include <qwindowsstyle.h>
61#include <qmotifstyle.h> 61#include <qmotifstyle.h>
62#include <qmotifplusstyle.h> 62#include <qmotifplusstyle.h>
63#include "lightstyle.h" 63#include "lightstyle.h"
64 64
65#include <qpe/qlibrary.h> 65#include <qpe/qlibrary.h>
66#endif 66#endif
67#include "global.h" 67#include "global.h"
68#include "resource.h" 68#include "resource.h"
69#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 69#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
70#include "qutfcodec.h" 70#include "qutfcodec.h"
71#endif 71#endif
72#include "config.h" 72#include "config.h"
73#include "network.h" 73#include "network.h"
74#ifdef QWS 74#ifdef QWS
75#include "fontmanager.h" 75#include "fontmanager.h"
76#endif 76#endif
77 77
78#include "alarmserver.h" 78#include "alarmserver.h"
79#include "applnk.h" 79#include "applnk.h"
80#include "qpemenubar.h" 80#include "qpemenubar.h"
81#include "textcodecinterface.h" 81#include "textcodecinterface.h"
82#include "imagecodecinterface.h" 82#include "imagecodecinterface.h"
83 83
84#include <unistd.h> 84#include <unistd.h>
85#include <sys/file.h> 85#include <sys/file.h>
86#include <sys/ioctl.h> 86#include <sys/ioctl.h>
87#include <sys/soundcard.h> 87#include <sys/soundcard.h>
88 88
89#include "qt_override_p.h" 89#include "qt_override_p.h"
90 90
91 91
92class QPEApplicationData 92class QPEApplicationData
93{ 93{
94public: 94public:
95 QPEApplicationData() : presstimer( 0 ), presswidget( 0 ), rightpressed( FALSE ), 95 QPEApplicationData() : presstimer( 0 ), presswidget( 0 ), rightpressed( FALSE ),
96 kbgrabber( 0 ), kbregrab( FALSE ), notbusysent( FALSE ), preloaded( FALSE ), 96 kbgrabber( 0 ), kbregrab( FALSE ), notbusysent( FALSE ), preloaded( FALSE ),
97 forceshow( FALSE ), nomaximize( FALSE ), qpe_main_widget( 0 ), 97 forceshow( FALSE ), nomaximize( FALSE ), qpe_main_widget( 0 ),
98 keep_running( TRUE ) 98 keep_running( TRUE )
99 { 99 {
100 qcopq.setAutoDelete( TRUE ); 100 qcopq.setAutoDelete( TRUE );
101 } 101 }
102 102
103 int presstimer; 103 int presstimer;
104 QWidget* presswidget; 104 QWidget* presswidget;
105 QPoint presspos; 105 QPoint presspos;
106bool rightpressed : 106bool rightpressed :
107 1; // AEH why not use uint foobar :1; if it's tt style -zecke 107 1; // AEH why not use uint foobar :1; if it's tt style -zecke
108 int kbgrabber; 108 int kbgrabber;
109bool kbregrab : 109bool kbregrab :
110 1; 110 1;
111bool notbusysent : 111bool notbusysent :
112 1; 112 1;
113 QString appName; 113 QString appName;
114 struct QCopRec 114 struct QCopRec
115 { 115 {
116 QCopRec( const QCString &ch, const QCString &msg, 116 QCopRec( const QCString &ch, const QCString &msg,
117 const QByteArray &d ) : 117 const QByteArray &d ) :
118 channel( ch ), message( msg ), data( d ) 118 channel( ch ), message( msg ), data( d )
119 { } 119 { }
120 120
121 QCString channel; 121 QCString channel;
122 QCString message; 122 QCString message;
123 QByteArray data; 123 QByteArray data;
124 }; 124 };
125bool preloaded : 125bool preloaded :
126 1; 126 1;
127bool forceshow : 127bool forceshow :
128 1; 128 1;
129bool nomaximize : 129bool nomaximize :
130 1; 130 1;
131 QWidget* qpe_main_widget; 131 QWidget* qpe_main_widget;
132bool keep_running : 132bool keep_running :
133 1; 133 1;
134 QList<QCopRec> qcopq; 134 QList<QCopRec> qcopq;
135 135
136 void enqueueQCop( const QCString &ch, const QCString &msg, 136 void enqueueQCop( const QCString &ch, const QCString &msg,
137 const QByteArray &data ) 137 const QByteArray &data )
138 { 138 {
139 qcopq.append( new QCopRec( ch, msg, data ) ); 139 qcopq.append( new QCopRec( ch, msg, data ) );
140 } 140 }
141 void sendQCopQ() 141 void sendQCopQ()
142 { 142 {
143 QCopRec * r; 143 QCopRec * r;
144#ifndef QT_NO_COP 144#ifndef QT_NO_COP
145 145
146 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it ) 146 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it )
147 QCopChannel::sendLocally( r->channel, r->message, r->data ); 147 QCopChannel::sendLocally( r->channel, r->message, r->data );
148#endif 148#endif
149 149
150 qcopq.clear(); 150 qcopq.clear();
151 } 151 }
152 static void show_mx(QWidget* mw, bool nomaximize) 152 static void show_mx(QWidget* mw, bool nomaximize)
153 { 153 {
154 if ( mw->layout() && mw->inherits("QDialog") ) { 154 if ( mw->layout() && mw->inherits("QDialog") ) {
155 QPEApplication::showDialog((QDialog*)mw, nomaximize); 155 QPEApplication::showDialog((QDialog*)mw, nomaximize);
156 } 156 }
157 else { 157 else {
158#ifdef Q_WS_QWS 158#ifdef Q_WS_QWS
159 if ( !nomaximize ) 159 if ( !nomaximize )
160 mw->showMaximized(); 160 mw->showMaximized();
161 else 161 else
162#endif 162#endif
163 163
164 mw->show(); 164 mw->show();
165 } 165 }
166 } 166 }
167 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 167 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
168 { 168 {
169 /* 169 /*
170 // This works but disable it for now until it is safe to apply 170 // This works but disable it for now until it is safe to apply
171 // What is does is scan the .desktop files of all the apps for 171 // What is does is scan the .desktop files of all the apps for
172 // the applnk that has the corresponding argv[0] as this program 172 // the applnk that has the corresponding argv[0] as this program
173 // then it uses the name stored in the .desktop file as the caption 173 // then it uses the name stored in the .desktop file as the caption
174 // for the main widget. This saves duplicating translations for 174 // for the main widget. This saves duplicating translations for
175 // the app name in the program and in the .desktop files. 175 // the app name in the program and in the .desktop files.
176 176
177 AppLnkSet apps( appsPath ); 177 AppLnkSet apps( appsPath );
178 178
179 QList<AppLnk> appsList = apps.children(); 179 QList<AppLnk> appsList = apps.children();
180 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 180 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
181 if ( (*it)->exec() == appName ) { 181 if ( (*it)->exec() == appName ) {
182 mw->setCaption( (*it)->name() ); 182 mw->setCaption( (*it)->name() );
183 return TRUE; 183 return TRUE;
184 } 184 }
185 } 185 }
186 */ 186 */
187 return FALSE; 187 return FALSE;
188 } 188 }
189 189
190 190
191 void show(QWidget* mw, bool nomax) 191 void show(QWidget* mw, bool nomax)
192 { 192 {
193 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 193 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
194 nomaximize = nomax; 194 nomaximize = nomax;
195 qpe_main_widget = mw; 195 qpe_main_widget = mw;
196#ifndef QT_NO_COP 196#ifndef QT_NO_COP
197 197
198 sendQCopQ(); 198 sendQCopQ();
199#endif 199#endif
200 200
201 if ( preloaded ) { 201 if ( preloaded ) {
202 if (forceshow) 202 if (forceshow)
203 show_mx(mw, nomax); 203 show_mx(mw, nomax);
204 } 204 }
205 else if ( keep_running ) { 205 else if ( keep_running ) {
206 show_mx(mw, nomax); 206 show_mx(mw, nomax);
207 } 207 }
208 } 208 }
209 209
210 void loadTextCodecs() 210 void loadTextCodecs()
211 { 211 {
212 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 212 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
213 QDir dir( path, "lib*.so" ); 213 QDir dir( path, "lib*.so" );
214 QStringList list = dir.entryList(); 214 QStringList list = dir.entryList();
215 QStringList::Iterator it; 215 QStringList::Iterator it;
216 for ( it = list.begin(); it != list.end(); ++it ) { 216 for ( it = list.begin(); it != list.end(); ++it ) {
217 TextCodecInterface *iface = 0; 217 TextCodecInterface *iface = 0;
218 QLibrary *lib = new QLibrary( path + "/" + *it ); 218 QLibrary *lib = new QLibrary( path + "/" + *it );
219 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 219 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
220 QValueList<int> mibs = iface->mibEnums(); 220 QValueList<int> mibs = iface->mibEnums();
221 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 221 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
222 (void)iface->createForMib(*i); 222 (void)iface->createForMib(*i);
223 // ### it exists now; need to remember if we can delete it 223 // ### it exists now; need to remember if we can delete it
224 } 224 }
225 } 225 }
226 else { 226 else {
227 lib->unload(); 227 lib->unload();
228 delete lib; 228 delete lib;
229 } 229 }
230 } 230 }
231 } 231 }
232 232
233 void loadImageCodecs() 233 void loadImageCodecs()
234 { 234 {
235 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 235 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
236 QDir dir( path, "lib*.so" ); 236 QDir dir( path, "lib*.so" );
237 QStringList list = dir.entryList(); 237 QStringList list = dir.entryList();
238 QStringList::Iterator it; 238 QStringList::Iterator it;
239 for ( it = list.begin(); it != list.end(); ++it ) { 239 for ( it = list.begin(); it != list.end(); ++it ) {
240 ImageCodecInterface *iface = 0; 240 ImageCodecInterface *iface = 0;
241 QLibrary *lib = new QLibrary( path + "/" + *it ); 241 QLibrary *lib = new QLibrary( path + "/" + *it );
242 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 242 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
243 QStringList formats = iface->keys(); 243 QStringList formats = iface->keys();
244 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 244 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
245 (void)iface->installIOHandler(*i); 245 (void)iface->installIOHandler(*i);
246 // ### it exists now; need to remember if we can delete it 246 // ### it exists now; need to remember if we can delete it
247 } 247 }
248 } 248 }
249 else { 249 else {
250 lib->unload(); 250 lib->unload();
251 delete lib; 251 delete lib;
252 } 252 }
253 } 253 }
254 } 254 }
255 QString styleName; 255 QString styleName;
256 QString decorationName; 256 QString decorationName;
257}; 257};
258 258
259class ResourceMimeFactory : public QMimeSourceFactory 259class ResourceMimeFactory : public QMimeSourceFactory
260{ 260{
261public: 261public:
262 ResourceMimeFactory() 262 ResourceMimeFactory()
263 { 263 {
264 setFilePath( Global::helpPath() ); 264 setFilePath( Global::helpPath() );
265 setExtensionType( "html", "text/html;charset=UTF-8" ); 265 setExtensionType( "html", "text/html;charset=UTF-8" );
266 } 266 }
267 267
268 const QMimeSource* data( const QString& abs_name ) const 268 const QMimeSource* data( const QString& abs_name ) const
269 { 269 {
270 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 270 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
271 if ( !r ) { 271 if ( !r ) {
272 int sl = abs_name.length(); 272 int sl = abs_name.length();
273 do { 273 do {
274 sl = abs_name.findRev( '/', sl - 1 ); 274 sl = abs_name.findRev( '/', sl - 1 );
275 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 275 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
276 int dot = name.findRev( '.' ); 276 int dot = name.findRev( '.' );
277 if ( dot >= 0 ) 277 if ( dot >= 0 )
278 name = name.left( dot ); 278 name = name.left( dot );
279 QImage img = Resource::loadImage( name ); 279 QImage img = Resource::loadImage( name );
280 if ( !img.isNull() ) 280 if ( !img.isNull() )
281 r = new QImageDrag( img ); 281 r = new QImageDrag( img );
282 } 282 }
283 while ( !r && sl > 0 ); 283 while ( !r && sl > 0 );
284 } 284 }
285 return r; 285 return r;
286 } 286 }
287}; 287};
288 288
289static int muted = 0; 289static int muted = 0;
290static int micMuted = 0; 290static int micMuted = 0;
291 291
292static void setVolume( int t = 0, int percent = -1 ) 292static void setVolume( int t = 0, int percent = -1 )
293{ 293{
294 switch ( t ) { 294 switch ( t ) {
295 case 0: { 295 case 0: {
296 Config cfg( "qpe" ); 296 Config cfg( "qpe" );
297 cfg.setGroup( "Volume" ); 297 cfg.setGroup( "Volume" );
298 if ( percent < 0 ) 298 if ( percent < 0 )
299 percent = cfg.readNumEntry( "VolumePercent", 50 ); 299 percent = cfg.readNumEntry( "VolumePercent", 50 );
300 int fd = 0; 300 int fd = 0;
301 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 301 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
302 int vol = muted ? 0 : percent; 302 int vol = muted ? 0 : percent;
303 // set both channels to same volume 303 // set both channels to same volume
304 vol |= vol << 8; 304 vol |= vol << 8;
305 ioctl( fd, MIXER_WRITE( 0 ), &vol ); 305 ioctl( fd, MIXER_WRITE( 0 ), &vol );
306 ::close( fd ); 306 ::close( fd );
307 } 307 }
308 } 308 }
309 break; 309 break;
310 } 310 }
311} 311}
312 312
313static void setMic( int t = 0, int percent = -1 ) 313static void setMic( int t = 0, int percent = -1 )
314{ 314{
315 switch ( t ) { 315 switch ( t ) {
316 case 0: { 316 case 0: {
317 Config cfg( "qpe" ); 317 Config cfg( "qpe" );
318 cfg.setGroup( "Volume" ); 318 cfg.setGroup( "Volume" );
319 if ( percent < 0 ) 319 if ( percent < 0 )
320 percent = cfg.readNumEntry( "Mic", 50 ); 320 percent = cfg.readNumEntry( "Mic", 50 );
321 321
322 int fd = 0; 322 int fd = 0;
323 int mic = micMuted ? 0 : percent; 323 int mic = micMuted ? 0 : percent;
324 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 324 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
325 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 325 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
326 ::close( fd ); 326 ::close( fd );
327 } 327 }
328 } 328 }
329 break; 329 break;
330 } 330 }
331} 331}
332 332
333 333
334/*! 334/*!
335 \class QPEApplication qpeapplication.h 335 \class QPEApplication qpeapplication.h
336 \brief The QPEApplication class implements various system services 336 \brief The QPEApplication class implements various system services
337 that are available to all Qtopia applications. 337 that are available to all Qtopia applications.
338 338
339 Simply by using QPEApplication instead of QApplication, a standard Qt 339 Simply by using QPEApplication instead of QApplication, a standard Qt
340 application becomes a Qtopia application. It automatically follows 340 application becomes a Qtopia application. It automatically follows
341 style changes, quits and raises, and in the 341 style changes, quits and raises, and in the
342 case of \link docwidget.html document-oriented\endlink applications, 342 case of \link docwidget.html document-oriented\endlink applications,
343 changes the currently displayed document in response to the environment. 343 changes the currently displayed document in response to the environment.
344 344
345 To create a \link docwidget.html document-oriented\endlink 345 To create a \link docwidget.html document-oriented\endlink
346 application use showMainDocumentWidget(); to create a 346 application use showMainDocumentWidget(); to create a
347 non-document-oriented application use showMainWidget(). The 347 non-document-oriented application use showMainWidget(). The
348 keepRunning() function indicates whether the application will 348 keepRunning() function indicates whether the application will
349 continue running after it's processed the last \link qcop.html 349 continue running after it's processed the last \link qcop.html
350 QCop\endlink message. This can be changed using setKeepRunning(). 350 QCop\endlink message. This can be changed using setKeepRunning().
351 351
352 A variety of signals are emitted when certain events occur, for 352 A variety of signals are emitted when certain events occur, for
353 example, timeChanged(), clockChanged(), weekChanged(), 353 example, timeChanged(), clockChanged(), weekChanged(),
354 dateFormatChanged() and volumeChanged(). If the application receives 354 dateFormatChanged() and volumeChanged(). If the application receives
355 a \link qcop.html QCop\endlink message on the application's 355 a \link qcop.html QCop\endlink message on the application's
356 QPE/Application/\e{appname} channel, the appMessage() signal is 356 QPE/Application/\e{appname} channel, the appMessage() signal is
357 emitted. There are also flush() and reload() signals, which 357 emitted. There are also flush() and reload() signals, which
358 are emitted when synching begins and ends respectively - upon these 358 are emitted when synching begins and ends respectively - upon these
359 signals, the application should save and reload any data 359 signals, the application should save and reload any data
360 files that are involved in synching. Most of these signals will initially 360 files that are involved in synching. Most of these signals will initially
361 be received and unfiltered through the appMessage() signal. 361 be received and unfiltered through the appMessage() signal.
362 362
363 This class also provides a set of useful static functions. The 363 This class also provides a set of useful static functions. The
364 qpeDir() and documentDir() functions return the respective paths. 364 qpeDir() and documentDir() functions return the respective paths.
365 The grabKeyboard() and ungrabKeyboard() functions are used to 365 The grabKeyboard() and ungrabKeyboard() functions are used to
366 control whether the application takes control of the device's 366 control whether the application takes control of the device's
367 physical buttons (e.g. application launch keys). The stylus' mode of 367 physical buttons (e.g. application launch keys). The stylus' mode of
368 operation is set with setStylusOperation() and retrieved with 368 operation is set with setStylusOperation() and retrieved with
369 stylusOperation(). There are also setInputMethodHint() and 369 stylusOperation(). There are also setInputMethodHint() and
370 inputMethodHint() functions. 370 inputMethodHint() functions.
371 371
372 \ingroup qtopiaemb 372 \ingroup qtopiaemb
373*/ 373*/
374 374
375/*! 375/*!
376 \fn void QPEApplication::clientMoused() 376 \fn void QPEApplication::clientMoused()
377 377
378 \internal 378 \internal
379*/ 379*/
380 380
381/*! 381/*!
382 \fn void QPEApplication::timeChanged(); 382 \fn void QPEApplication::timeChanged();
383 This signal is emitted when the time changes outside the normal 383 This signal is emitted when the time changes outside the normal
384 passage of time, i.e. if the time is set backwards or forwards. 384 passage of time, i.e. if the time is set backwards or forwards.
385*/ 385*/
386 386
387/*! 387/*!
388 \fn void QPEApplication::clockChanged( bool ampm ); 388 \fn void QPEApplication::clockChanged( bool ampm );
389 389
390 This signal is emitted when the user changes the clock's style. If 390 This signal is emitted when the user changes the clock's style. If
391 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 391 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
392 they want a 24-hour clock. 392 they want a 24-hour clock.
393*/ 393*/
394 394
395/*! 395/*!
396 \fn void QPEApplication::volumeChanged( bool muted ) 396 \fn void QPEApplication::volumeChanged( bool muted )
397 397
398 This signal is emitted whenever the mute state is changed. If \a 398 This signal is emitted whenever the mute state is changed. If \a
399 muted is TRUE, then sound output has been muted. 399 muted is TRUE, then sound output has been muted.
400*/ 400*/
401 401
402/*! 402/*!
403 \fn void QPEApplication::weekChanged( bool startOnMonday ) 403 \fn void QPEApplication::weekChanged( bool startOnMonday )
404 404
405 This signal is emitted if the week start day is changed. If \a 405 This signal is emitted if the week start day is changed. If \a
406 startOnMonday is TRUE then the first day of the week is Monday; if 406 startOnMonday is TRUE then the first day of the week is Monday; if
407 \a startOnMonday is FALSE then the first day of the week is 407 \a startOnMonday is FALSE then the first day of the week is
408 Sunday. 408 Sunday.
409*/ 409*/
410 410
411/*! 411/*!
412 \fn void QPEApplication::dateFormatChanged() 412 \fn void QPEApplication::dateFormatChanged()
413 413
414 This signal is emitted whenever the date format is changed. 414 This signal is emitted whenever the date format is changed.
415*/ 415*/
416 416
417/*! 417/*!
418 \fn void QPEApplication::flush() 418 \fn void QPEApplication::flush()
419 419
420 ### 420 ###
421*/ 421*/
422 422
423/*! 423/*!
424 \fn void QPEApplication::reload() 424 \fn void QPEApplication::reload()
425 425
426*/ 426*/
427 427
428/*! 428/*!
429 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 429 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
430 430
431 This signal is emitted when a message is received on this 431 This signal is emitted when a message is received on this
432 application's QPE/Application/<i>appname</i> \link qcop.html 432 application's QPE/Application/<i>appname</i> \link qcop.html
433 QCop\endlink channel. 433 QCop\endlink channel.
434 434
435 The slot to which you connect this signal uses \a msg and \a data 435 The slot to which you connect this signal uses \a msg and \a data
436 in the following way: 436 in the following way:
437 437
438\code 438\code
439 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 439 void MyWidget::receive( const QCString& msg, const QByteArray& data )
440 { 440 {
441 QDataStream stream( data, IO_ReadOnly ); 441 QDataStream stream( data, IO_ReadOnly );
442 if ( msg == "someMessage(int,int,int)" ) { 442 if ( msg == "someMessage(int,int,int)" ) {
443 int a,b,c; 443 int a,b,c;
444 stream >> a >> b >> c; 444 stream >> a >> b >> c;
445 ... 445 ...
446 } else if ( msg == "otherMessage(QString)" ) { 446 } else if ( msg == "otherMessage(QString)" ) {
447 ... 447 ...
448 } 448 }
449 } 449 }
450\endcode 450\endcode
451 451
452 \sa qcop.html 452 \sa qcop.html
453 Note that messages received here may be processed by qpe application 453 Note that messages received here may be processed by qpe application
454 and emitted as signals, such as flush() and reload(). 454 and emitted as signals, such as flush() and reload().
455*/ 455*/
456 456
457/*! 457/*!
458 Constructs a QPEApplication just as you would construct 458 Constructs a QPEApplication just as you would construct
459 a QApplication, passing \a argc, \a argv, and \a t. 459 a QApplication, passing \a argc, \a argv, and \a t.
460 460
461 For applications, \a t should be the default, GuiClient. Only 461 For applications, \a t should be the default, GuiClient. Only
462 the Qtopia server passes GuiServer. 462 the Qtopia server passes GuiServer.
463*/ 463*/
464QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 464QPEApplication::QPEApplication( int & argc, char **argv, Type t )
465 : QApplication( argc, argv, t ) 465 : QApplication( argc, argv, t )
466{ 466{
467 d = new QPEApplicationData; 467 d = new QPEApplicationData;
468 d->loadTextCodecs(); 468 d->loadTextCodecs();
469 d->loadImageCodecs(); 469 d->loadImageCodecs();
470 int dw = desktop() ->width(); 470 int dw = desktop() ->width();
471 qWarning( "Width %d", dw ); 471 qWarning( "Width %d", dw );
472 if ( dw < 200 ) { 472 if ( dw < 200 ) {
473 setFont( QFont( "helvetica", 8 ) ); 473 setFont( QFont( "helvetica", 8 ) );
474 AppLnk::setSmallIconSize( 10 ); 474 AppLnk::setSmallIconSize( 10 );
475 AppLnk::setBigIconSize( 28 ); 475 AppLnk::setBigIconSize( 28 );
476 } 476 }
477 else if ( dw > 600 ) { 477 else if ( dw > 600 ) {
478 setFont( QFont( "helvetica", 12 ) ); 478 setFont( QFont( "helvetica", 12 ) );
479 AppLnk::setSmallIconSize( 24 ); 479 AppLnk::setSmallIconSize( 24 );
480 AppLnk::setBigIconSize( 48 ); 480 AppLnk::setBigIconSize( 48 );
481 } 481 }
482 else if ( dw > 200 ) { 482 else if ( dw > 200 ) {
483 setFont( QFont( "helvetica", 10 ) ); 483 setFont( QFont( "helvetica", 10 ) );
484 AppLnk::setSmallIconSize( 16 ); 484 AppLnk::setSmallIconSize( 16 );
485 AppLnk::setBigIconSize( 32 ); 485 AppLnk::setBigIconSize( 32 );
486 } 486 }
487 487
488 488
489 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 489 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
490 490
491 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 491 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
492#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 492#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
493 493
494 QString qcopfn( "/tmp/qcop-msg-" ); 494 QString qcopfn( "/tmp/qcop-msg-" );
495 qcopfn += QString( argv[ 0 ] ); // append command name 495 qcopfn += QString( argv[ 0 ] ); // append command name
496 496
497 QFile f( qcopfn ); 497 QFile f( qcopfn );
498 if ( f.open( IO_ReadOnly ) ) { 498 if ( f.open( IO_ReadOnly ) ) {
499 flock( f.handle(), LOCK_EX ); 499 flock( f.handle(), LOCK_EX );
500 } 500 }
501 501
502 sysChannel = new QCopChannel( "QPE/System", this ); 502 sysChannel = new QCopChannel( "QPE/System", this );
503 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 503 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
504 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 504 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
505 505
506 QCString channel = QCString( argv[ 0 ] ); 506 QCString channel = QCString( argv[ 0 ] );
507 channel.replace( QRegExp( ".*/" ), "" ); 507 channel.replace( QRegExp( ".*/" ), "" );
508 d->appName = channel; 508 d->appName = channel;
509 channel = "QPE/Application/" + channel; 509 channel = "QPE/Application/" + channel;
510 pidChannel = new QCopChannel( channel, this ); 510 pidChannel = new QCopChannel( channel, this );
511 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 511 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
512 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); 512 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
513 513
514 if ( f.isOpen() ) { 514 if ( f.isOpen() ) {
515 d->keep_running = FALSE; 515 d->keep_running = FALSE;
516 QDataStream ds( &f ); 516 QDataStream ds( &f );
517 QCString channel, message; 517 QCString channel, message;
518 QByteArray data; 518 QByteArray data;
519 while ( !ds.atEnd() ) { 519 while ( !ds.atEnd() ) {
520 ds >> channel >> message >> data; 520 ds >> channel >> message >> data;
521 d->enqueueQCop( channel, message, data ); 521 d->enqueueQCop( channel, message, data );
522 } 522 }
523 523
524 flock( f.handle(), LOCK_UN ); 524 flock( f.handle(), LOCK_UN );
525 f.close(); 525 f.close();
526 f.remove(); 526 f.remove();
527 } 527 }
528 528
529 for ( int a = 0; a < argc; a++ ) { 529 for ( int a = 0; a < argc; a++ ) {
530 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 530 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
531 argv[ a ] = argv[ a + 1 ]; 531 argv[ a ] = argv[ a + 1 ];
532 a++; 532 a++;
533 d->preloaded = TRUE; 533 d->preloaded = TRUE;
534 argc -= 1; 534 argc -= 1;
535 } 535 }
536 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 536 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
537 argv[ a ] = argv[ a + 1 ]; 537 argv[ a ] = argv[ a + 1 ];
538 a++; 538 a++;
539 d->preloaded = TRUE; 539 d->preloaded = TRUE;
540 d->forceshow = TRUE; 540 d->forceshow = TRUE;
541 argc -= 1; 541 argc -= 1;
542 } 542 }
543 } 543 }
544 544
545 /* overide stored arguments */ 545 /* overide stored arguments */
546 setArgs( argc, argv ); 546 setArgs( argc, argv );
547 547
548#endif 548#endif
549 549
550 // qwsSetDecoration( new QPEDecoration() ); 550 // qwsSetDecoration( new QPEDecoration() );
551 551
552#ifndef QT_NO_TRANSLATION 552#ifndef QT_NO_TRANSLATION
553 553
554 QStringList langs = Global::languageList(); 554 QStringList langs = Global::languageList();
555 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { 555 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
556 QString lang = *it; 556 QString lang = *it;
557 557
558 QTranslator * trans; 558 QTranslator * trans;
559 QString tfn; 559 QString tfn;
560 560
561 trans = new QTranslator( this ); 561 trans = new QTranslator( this );
562 tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm"; 562 tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm";
563 if ( trans->load( tfn ) ) 563 if ( trans->load( tfn ) )
564 installTranslator( trans ); 564 installTranslator( trans );
565 else 565 else
566 delete trans; 566 delete trans;
567 567
568 trans = new QTranslator( this ); 568 trans = new QTranslator( this );
569 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm"; 569 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm";
570 if ( trans->load( tfn ) ) 570 if ( trans->load( tfn ) )
571 installTranslator( trans ); 571 installTranslator( trans );
572 else 572 else
573 delete trans; 573 delete trans;
574 574
575 //###language/font hack; should look it up somewhere 575 //###language/font hack; should look it up somewhere
576#ifdef QWS 576#ifdef QWS
577 577
578 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 578 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
579 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 579 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
580 setFont( fn ); 580 setFont( fn );
581 } 581 }
582#endif 582#endif
583 583
584 } 584 }
585#endif 585#endif
586 586
587 applyStyle(); 587 applyStyle();
588 588
589 if ( type() == GuiServer ) { 589 if ( type() == GuiServer ) {
590 setVolume(); 590 setVolume();
591 } 591 }
592 592
593 installEventFilter( this ); 593 installEventFilter( this );
594 594
595 QPEMenuToolFocusManager::initialize(); 595 QPEMenuToolFocusManager::initialize();
596 596
597#ifdef QT_NO_QWS_CURSOR 597#ifdef QT_NO_QWS_CURSOR
598 // if we have no cursor, probably don't want tooltips 598 // if we have no cursor, probably don't want tooltips
599 QToolTip::setEnabled( FALSE ); 599 QToolTip::setEnabled( FALSE );
600#endif 600#endif
601} 601}
602 602
603static QPtrDict<void>* inputMethodDict = 0; 603static QPtrDict<void>* inputMethodDict = 0;
604static void createInputMethodDict() 604static void createInputMethodDict()
605{ 605{
606 if ( !inputMethodDict ) 606 if ( !inputMethodDict )
607 inputMethodDict = new QPtrDict<void>; 607 inputMethodDict = new QPtrDict<void>;
608} 608}
609 609
610/*! 610/*!
611 Returns the currently set hint to the system as to whether 611 Returns the currently set hint to the system as to whether
612 widget \a w has any use for text input methods. 612 widget \a w has any use for text input methods.
613 613
614 614
615 \sa setInputMethodHint() InputMethodHint 615 \sa setInputMethodHint() InputMethodHint
616*/ 616*/
617QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 617QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
618{ 618{
619 if ( inputMethodDict && w ) 619 if ( inputMethodDict && w )
620 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 620 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
621 return Normal; 621 return Normal;
622} 622}
623 623
624/*! 624/*!
625 \enum QPEApplication::InputMethodHint 625 \enum QPEApplication::InputMethodHint
626 626
627 \value Normal the application sometimes needs text input (the default). 627 \value Normal the application sometimes needs text input (the default).
628 \value AlwaysOff the application never needs text input. 628 \value AlwaysOff the application never needs text input.
629 \value AlwaysOn the application always needs text input. 629 \value AlwaysOn the application always needs text input.
630*/ 630*/
631 631
632/*! 632/*!
633 Hints to the system that widget \a w has use for text input methods 633 Hints to the system that widget \a w has use for text input methods
634 as specified by \a mode. 634 as specified by \a mode.
635 635
636 \sa inputMethodHint() InputMethodHint 636 \sa inputMethodHint() InputMethodHint
637*/ 637*/
638void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 638void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
639{ 639{
640 createInputMethodDict(); 640 createInputMethodDict();
641 if ( mode == Normal ) { 641 if ( mode == Normal ) {
642 inputMethodDict->remove 642 inputMethodDict->remove
643 ( w ); 643 ( w );
644 } 644 }
645 else { 645 else {
646 inputMethodDict->insert( w, ( void* ) mode ); 646 inputMethodDict->insert( w, ( void* ) mode );
647 } 647 }
648} 648}
649 649
650class HackDialog : public QDialog 650class HackDialog : public QDialog
651{ 651{
652public: 652public:
653 void acceptIt() 653 void acceptIt()
654 { 654 {
655 accept(); 655 accept();
656 } 656 }
657 void rejectIt() 657 void rejectIt()
658 { 658 {
659 reject(); 659 reject();
660 } 660 }
661}; 661};
662 662
663 663
664void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 664void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
665{ 665{
666 // specialised actions for certain widgets. May want to 666 // specialised actions for certain widgets. May want to
667 // add more stuff here. 667 // add more stuff here.
668 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 668 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
669 && activePopupWidget() ->parentWidget() 669 && activePopupWidget() ->parentWidget()
670 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 670 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
671 key = Qt::Key_Return; 671 key = Qt::Key_Return;
672 672
673 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 673 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
674 key = Qt::Key_Return; 674 key = Qt::Key_Return;
675 675
676#ifdef QWS 676#ifdef QWS
677 677
678 ke->simpleData.keycode = key; 678 ke->simpleData.keycode = key;
679#endif 679#endif
680} 680}
681 681
682class HackWidget : public QWidget 682class HackWidget : public QWidget
683{ 683{
684public: 684public:
685 bool needsOk() 685 bool needsOk()
686 { 686 {
687 return ( getWState() & WState_Reserved1 ); 687 return ( getWState() & WState_Reserved1 );
688 } 688 }
689}; 689};
690 690
691/*! 691/*!
692 \internal 692 \internal
693*/ 693*/
694 694
695#ifdef QWS 695#ifdef QWS
696bool QPEApplication::qwsEventFilter( QWSEvent * e ) 696bool QPEApplication::qwsEventFilter( QWSEvent * e )
697{ 697{
698 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 698 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
699 if ( qApp->type() != QApplication::GuiServer ) { 699 if ( qApp->type() != QApplication::GuiServer ) {
700 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 700 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
701 e << d->appName; 701 e << d->appName;
702 } 702 }
703 d->notbusysent = TRUE; 703 d->notbusysent = TRUE;
704 } 704 }
705 if ( type() == GuiServer ) { 705 if ( type() == GuiServer ) {
706 switch ( e->type ) { 706 switch ( e->type ) {
707 case QWSEvent::Mouse: 707 case QWSEvent::Mouse:
708 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 708 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
709 emit clientMoused(); 709 emit clientMoused();
710 break; 710 break;
711 default: 711 default:
712 break; 712 break;
713 } 713 }
714 } 714 }
715 if ( e->type == QWSEvent::Key ) { 715 if ( e->type == QWSEvent::Key ) {
716 if ( d->kbgrabber == 1 ) 716 if ( d->kbgrabber == 1 )
717 return TRUE; 717 return TRUE;
718 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 718 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
719 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 719 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
720 // Use special "OK" key to press "OK" on top level widgets 720 // Use special "OK" key to press "OK" on top level widgets
721 QWidget * active = activeWindow(); 721 QWidget * active = activeWindow();
722 QWidget *popup = 0; 722 QWidget *popup = 0;
723 if ( active && active->isPopup() ) { 723 if ( active && active->isPopup() ) {
724 popup = active; 724 popup = active;
725 active = active->parentWidget(); 725 active = active->parentWidget();
726 } 726 }
727 if ( active && ( int ) active->winId() == ke->simpleData.window && 727 if ( active && ( int ) active->winId() == ke->simpleData.window &&
728 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 728 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
729 if ( ke->simpleData.is_press ) { 729 if ( ke->simpleData.is_press ) {
730 if ( popup ) 730 if ( popup )
731 popup->close(); 731 popup->close();
732 if ( active->inherits( "QDialog" ) ) { 732 if ( active->inherits( "QDialog" ) ) {
733 HackDialog * d = ( HackDialog * ) active; 733 HackDialog * d = ( HackDialog * ) active;
734 d->acceptIt(); 734 d->acceptIt();
735 return TRUE; 735 return TRUE;
736 } 736 }
737 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 737 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
738 QSignal s; 738 QSignal s;
739 s.connect( active, SLOT( accept() ) ); 739 s.connect( active, SLOT( accept() ) );
740 s.activate(); 740 s.activate();
741 } 741 }
742 else { 742 else {
743 // do the same as with the select key: Map to the default action of the widget: 743 // do the same as with the select key: Map to the default action of the widget:
744 mapToDefaultAction( ke, Qt::Key_Return ); 744 mapToDefaultAction( ke, Qt::Key_Return );
745 } 745 }
746 } 746 }
747 } 747 }
748 } 748 }
749 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 749 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
750 // Use special "select" key to do whatever default action a widget has 750 // Use special "select" key to do whatever default action a widget has
751 mapToDefaultAction( ke, Qt::Key_Space ); 751 mapToDefaultAction( ke, Qt::Key_Space );
752 } 752 }
753 else if ( ke->simpleData.keycode == Qt::Key_Escape && 753 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
754 ke->simpleData.is_press ) { 754 ke->simpleData.is_press ) {
755 // Escape key closes app if focus on toplevel 755 // Escape key closes app if focus on toplevel
756 QWidget * active = activeWindow(); 756 QWidget * active = activeWindow();
757 if ( active && active->testWFlags( WType_TopLevel ) && 757 if ( active && active->testWFlags( WType_TopLevel ) &&
758 ( int ) active->winId() == ke->simpleData.window && 758 ( int ) active->winId() == ke->simpleData.window &&
759 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 759 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
760 if ( active->inherits( "QDialog" ) ) { 760 if ( active->inherits( "QDialog" ) ) {
761 HackDialog * d = ( HackDialog * ) active; 761 HackDialog * d = ( HackDialog * ) active;
762 d->rejectIt(); 762 d->rejectIt();
763 return TRUE; 763 return TRUE;
764 } 764 }
765 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 765 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
766 active->close(); 766 active->close();
767 } 767 }
768 } 768 }
769 } 769 }
770 770
771#if QT_VERSION < 231 771#if QT_VERSION < 231
772 // Filter out the F4/Launcher key from apps 772 // Filter out the F4/Launcher key from apps
773 // ### The launcher key may not always be F4 on all devices 773 // ### The launcher key may not always be F4 on all devices
774 if ( ( ( QWSKeyEvent * ) e ) ->simpleData.keycode == Qt::Key_F4 ) 774 if ( ( ( QWSKeyEvent * ) e ) ->simpleData.keycode == Qt::Key_F4 )
775 return TRUE; 775 return TRUE;
776#endif 776#endif
777 777
778 } 778 }
779 if ( e->type == QWSEvent::Focus ) { 779 if ( e->type == QWSEvent::Focus ) {
780 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 780 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
781 QWidget* nfw = QWidget::find( e->window() ); 781 QWidget* nfw = QWidget::find( e->window() );
782 if ( !fe->simpleData.get_focus ) { 782 if ( !fe->simpleData.get_focus ) {
783 QWidget * active = activeWindow(); 783 QWidget * active = activeWindow();
784 while ( active && active->isPopup() ) { 784 while ( active && active->isPopup() ) {
785 active->close(); 785 active->close();
786 active = activeWindow(); 786 active = activeWindow();
787 } 787 }
788 if ( !nfw && d->kbgrabber == 2 ) { 788 if ( !nfw && d->kbgrabber == 2 ) {
789 ungrabKeyboard(); 789 ungrabKeyboard();
790 d->kbregrab = TRUE; // want kb back when we're active 790 d->kbregrab = TRUE; // want kb back when we're active
791 } 791 }
792 } 792 }
793 else { 793 else {
794 // make sure our modal widget is ALWAYS on top 794 // make sure our modal widget is ALWAYS on top
795 QWidget *topm = activeModalWidget(); 795 QWidget *topm = activeModalWidget();
796 if ( topm ) { 796 if ( topm ) {
797 topm->raise(); 797 topm->raise();
798 } 798 }
799 if ( d->kbregrab ) { 799 if ( d->kbregrab ) {
800 grabKeyboard(); 800 grabKeyboard();
801 d->kbregrab = FALSE; 801 d->kbregrab = FALSE;
802 } 802 }
803 } 803 }
804 if ( fe->simpleData.get_focus && inputMethodDict ) { 804 if ( fe->simpleData.get_focus && inputMethodDict ) {
805 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 805 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
806 if ( m == AlwaysOff ) 806 if ( m == AlwaysOff )
807 Global::hideInputMethod(); 807 Global::hideInputMethod();
808 if ( m == AlwaysOn ) 808 if ( m == AlwaysOn )
809 Global::showInputMethod(); 809 Global::showInputMethod();
810 } 810 }
811 } 811 }
812 return QApplication::qwsEventFilter( e ); 812 return QApplication::qwsEventFilter( e );
813} 813}
814#endif 814#endif
815 815
816/*! 816/*!
817 Destroys the QPEApplication. 817 Destroys the QPEApplication.
818*/ 818*/
819QPEApplication::~QPEApplication() 819QPEApplication::~QPEApplication()
820{ 820{
821 ungrabKeyboard(); 821 ungrabKeyboard();
822#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 822#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
823 // Need to delete QCopChannels early, since the display will 823 // Need to delete QCopChannels early, since the display will
824 // be gone by the time we get to ~QObject(). 824 // be gone by the time we get to ~QObject().
825 delete sysChannel; 825 delete sysChannel;
826 delete pidChannel; 826 delete pidChannel;
827#endif 827#endif
828 828
829 delete d; 829 delete d;
830} 830}
831 831
832/*! 832/*!
833 Returns <tt>$OPIEDIR/</tt>. 833 Returns <tt>$OPIEDIR/</tt>.
834*/ 834*/
835QString QPEApplication::qpeDir() 835QString QPEApplication::qpeDir()
836{ 836{
837 const char * base = getenv( "OPIEDIR" ); 837 const char * base = getenv( "OPIEDIR" );
838 if ( base ) 838 if ( base )
839 return QString( base ) + "/"; 839 return QString( base ) + "/";
840 840
841 return QString( "../" ); 841 return QString( "../" );
842} 842}
843 843
844/*! 844/*!
845 Returns the user's current Document directory. There is a trailing "/". 845 Returns the user's current Document directory. There is a trailing "/".
846 .. well, it does now,, and there's no trailing '/' 846 .. well, it does now,, and there's no trailing '/'
847*/ 847*/
848QString QPEApplication::documentDir() 848QString QPEApplication::documentDir()
849{ 849{
850 const char* base = getenv( "HOME"); 850 const char* base = getenv( "HOME");
851 if ( base ) 851 if ( base )
852 return QString( base ) + "/Documents"; 852 return QString( base ) + "/Documents";
853 853
854 return QString( "../Documents" ); 854 return QString( "../Documents" );
855} 855}
856 856
857static int deforient = -1; 857static int deforient = -1;
858 858
859/*! 859/*!
860 \internal 860 \internal
861*/ 861*/
862int QPEApplication::defaultRotation() 862int QPEApplication::defaultRotation()
863{ 863{
864 if ( deforient < 0 ) { 864 if ( deforient < 0 ) {
865 QString d = getenv( "QWS_DISPLAY" ); 865 QString d = getenv( "QWS_DISPLAY" );
866 if ( d.contains( "Rot90" ) ) { 866 if ( d.contains( "Rot90" ) ) {
867 deforient = 90; 867 deforient = 90;
868 } 868 }
869 else if ( d.contains( "Rot180" ) ) { 869 else if ( d.contains( "Rot180" ) ) {
870 deforient = 180; 870 deforient = 180;
871 } 871 }
872 else if ( d.contains( "Rot270" ) ) { 872 else if ( d.contains( "Rot270" ) ) {
873 deforient = 270; 873 deforient = 270;
874 } 874 }
875 else { 875 else {
876 deforient = 0; 876 deforient = 0;
877 } 877 }
878 } 878 }
879 return deforient; 879 return deforient;
880} 880}
881 881
882/*! 882/*!
883 \internal 883 \internal
884*/ 884*/
885void QPEApplication::setDefaultRotation( int r ) 885void QPEApplication::setDefaultRotation( int r )
886{ 886{
887 if ( qApp->type() == GuiServer ) { 887 if ( qApp->type() == GuiServer ) {
888 deforient = r; 888 deforient = r;
889 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 889 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
890 Config config("qpe"); 890 Config config("qpe");
891 config.setGroup( "Rotation" ); 891 config.setGroup( "Rotation" );
892 config.writeEntry( "Screen", getenv("QWS_DISPLAY") ); 892 config.writeEntry( "Screen", getenv("QWS_DISPLAY") );
893 } 893 }
894 else { 894 else {
895#ifndef QT_NO_COP 895#ifndef QT_NO_COP
896 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 896 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
897 e << r; 897 e << r;
898 } 898 }
899#endif 899#endif
900 900
901 } 901 }
902} 902}
903 903
904 904
905/*! 905/*!
906 \internal 906 \internal
907*/ 907*/
908void QPEApplication::applyStyle() 908void QPEApplication::applyStyle()
909{ 909{
910 Config config( "qpe" ); 910 Config config( "qpe" );
911 config.setGroup( "Appearance" ); 911 config.setGroup( "Appearance" );
912 912
913 // don't block ourselves ... 913 // don't block ourselves ...
914 Opie::force_appearance = 0; 914 Opie::force_appearance = 0;
915 915
916 static QString appname = Opie::binaryName ( ); 916 static QString appname = Opie::binaryName ( );
917 917
918 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 918 QStringList ex = config. readListEntry ( "NoStyle", ';' );
919 int nostyle = 0; 919 int nostyle = 0;
920 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 920 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
921 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 921 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
922 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 922 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
923 break; 923 break;
924 } 924 }
925 } 925 }
926 926
927 // Widget style 927 // Widget style
928 QString style = config.readEntry( "Style", "Light" ); 928 QString style = config.readEntry( "Style", "Light" );
929 929
930 // don't set a custom style 930 // don't set a custom style
931 if ( nostyle & Opie::Force_Style ) 931 if ( nostyle & Opie::Force_Style )
932 style = "Light"; 932 style = "Light";
933 933
934 internalSetStyle ( style ); 934 internalSetStyle ( style );
935 935
936 // Colors 936 // Colors
937 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); 937 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) );
938 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); 938 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) );
939 QPalette pal( btncolor, bgcolor ); 939 QPalette pal( btncolor, bgcolor );
940 QString color = config.readEntry( "Highlight", "#800000" ); 940 QString color = config.readEntry( "Highlight", "#800000" );
941 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 941 pal.setColor( QColorGroup::Highlight, QColor( color ) );
942 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 942 color = config.readEntry( "HighlightedText", "#FFFFFF" );
943 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 943 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
944 color = config.readEntry( "Text", "#000000" ); 944 color = config.readEntry( "Text", "#000000" );
945 pal.setColor( QColorGroup::Text, QColor( color ) ); 945 pal.setColor( QColorGroup::Text, QColor( color ) );
946 color = config.readEntry( "ButtonText", "#000000" ); 946 color = config.readEntry( "ButtonText", "#000000" );
947 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 947 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
948 color = config.readEntry( "Base", "#FFFFFF" ); 948 color = config.readEntry( "Base", "#FFFFFF" );
949 pal.setColor( QColorGroup::Base, QColor( color ) ); 949 pal.setColor( QColorGroup::Base, QColor( color ) );
950 950
951 pal.setColor( QPalette::Disabled, QColorGroup::Text, 951 pal.setColor( QPalette::Disabled, QColorGroup::Text,
952 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 952 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
953 953
954 setPalette( pal, TRUE ); 954 setPalette( pal, TRUE );
955 955
956 // Window Decoration 956 // Window Decoration
957 QString dec = config.readEntry( "Decoration", "Qtopia" ); 957 QString dec = config.readEntry( "Decoration", "Qtopia" );
958 958
959 // don't set a custom deco 959 // don't set a custom deco
960 if ( nostyle & Opie::Force_Decoration ) 960 if ( nostyle & Opie::Force_Decoration )
961 dec = ""; 961 dec = "";
962 962
963 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); 963 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
964 964
965 if ( dec != d->decorationName ) { 965 if ( dec != d->decorationName ) {
966 qwsSetDecoration( new QPEDecoration( dec ) ); 966 qwsSetDecoration( new QPEDecoration( dec ) );
967 d->decorationName = dec; 967 d->decorationName = dec;
968 } 968 }
969 969
970 // Font 970 // Font
971 QString ff = config.readEntry( "FontFamily", font().family() ); 971 QString ff = config.readEntry( "FontFamily", font().family() );
972 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 972 int fs = config.readNumEntry( "FontSize", font().pointSize() );
973 973
974 // don't set a custom font 974 // don't set a custom font
975 if ( nostyle & Opie::Force_Font ) { 975 if ( nostyle & Opie::Force_Font ) {
976 ff = "Helvetica"; 976 ff = "Helvetica";
977 fs = 10; 977 fs = 10;
978 } 978 }
979 979
980 setFont ( QFont ( ff, fs ), true ); 980 setFont ( QFont ( ff, fs ), true );
981 981
982 // revert to global blocking policy ... 982 // revert to global blocking policy ...
983 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 983 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
984 Opie::force_appearance &= ~nostyle; 984 Opie::force_appearance &= ~nostyle;
985} 985}
986 986
987void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 987void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
988{ 988{
989#ifdef Q_WS_QWS 989#ifdef Q_WS_QWS
990 QDataStream stream( data, IO_ReadOnly ); 990 QDataStream stream( data, IO_ReadOnly );
991 if ( msg == "applyStyle()" ) { 991 if ( msg == "applyStyle()" ) {
992 applyStyle(); 992 applyStyle();
993 } 993 }
994 else if ( msg == "setDefaultRotation(int)" ) { 994 else if ( msg == "setDefaultRotation(int)" ) {
995 if ( type() == GuiServer ) { 995 if ( type() == GuiServer ) {
996 int r; 996 int r;
997 stream >> r; 997 stream >> r;
998 setDefaultRotation( r ); 998 setDefaultRotation( r );
999 } 999 }
1000 } 1000 }
1001 else if ( msg == "shutdown()" ) { 1001 else if ( msg == "shutdown()" ) {
1002 if ( type() == GuiServer ) 1002 if ( type() == GuiServer )
1003 shutdown(); 1003 shutdown();
1004 } 1004 }
1005 else if ( msg == "quit()" ) { 1005 else if ( msg == "quit()" ) {
1006 if ( type() != GuiServer ) 1006 if ( type() != GuiServer )
1007 tryQuit(); 1007 tryQuit();
1008 } 1008 }
1009 else if ( msg == "forceQuit()" ) { 1009 else if ( msg == "forceQuit()" ) {
1010 if ( type() != GuiServer ) 1010 if ( type() != GuiServer )
1011 quit(); 1011 quit();
1012 } 1012 }
1013 else if ( msg == "restart()" ) { 1013 else if ( msg == "restart()" ) {
1014 if ( type() == GuiServer ) 1014 if ( type() == GuiServer )
1015 restart(); 1015 restart();
1016 } 1016 }
1017 else if ( msg == "grabKeyboard(QString)" ) { 1017 else if ( msg == "grabKeyboard(QString)" ) {
1018 QString who; 1018 QString who;
1019 stream >> who; 1019 stream >> who;
1020 if ( who.isEmpty() ) 1020 if ( who.isEmpty() )
1021 d->kbgrabber = 0; 1021 d->kbgrabber = 0;
1022 else if ( who != d->appName ) 1022 else if ( who != d->appName )
1023 d->kbgrabber = 1; 1023 d->kbgrabber = 1;
1024 else 1024 else
1025 d->kbgrabber = 2; 1025 d->kbgrabber = 2;
1026 } 1026 }
1027 else if ( msg == "language(QString)" ) { 1027 else if ( msg == "language(QString)" ) {
1028 if ( type() == GuiServer ) { 1028 if ( type() == GuiServer ) {
1029 QString l; 1029 QString l;
1030 stream >> l; 1030 stream >> l;
1031 QString cl = getenv( "LANG" ); 1031 QString cl = getenv( "LANG" );
1032 if ( cl != l ) { 1032 if ( cl != l ) {
1033 if ( l.isNull() ) 1033 if ( l.isNull() )
1034 unsetenv( "LANG" ); 1034 unsetenv( "LANG" );
1035 else 1035 else
1036 setenv( "LANG", l.latin1(), 1 ); 1036 setenv( "LANG", l.latin1(), 1 );
1037 restart(); 1037 restart();
1038 } 1038 }
1039 } 1039 }
1040 } 1040 }
1041 else if ( msg == "timeChange(QString)" ) { 1041 else if ( msg == "timeChange(QString)" ) {
1042 QString t; 1042 QString t;
1043 stream >> t; 1043 stream >> t;
1044 if ( t.isNull() ) 1044 if ( t.isNull() )
1045 unsetenv( "TZ" ); 1045 unsetenv( "TZ" );
1046 else 1046 else
1047 setenv( "TZ", t.latin1(), 1 ); 1047 setenv( "TZ", t.latin1(), 1 );
1048 // emit the signal so everyone else knows... 1048 // emit the signal so everyone else knows...
1049 emit timeChanged(); 1049 emit timeChanged();
1050 } 1050 }
1051 else if ( msg == "execute(QString)" ) { 1051 else if ( msg == "execute(QString)" ) {
1052 if ( type() == GuiServer ) { 1052 if ( type() == GuiServer ) {
1053 QString t; 1053 QString t;
1054 stream >> t; 1054 stream >> t;
1055 Global::execute( t ); 1055 Global::execute( t );
1056 } 1056 }
1057 } 1057 }
1058 else if ( msg == "execute(QString,QString)" ) { 1058 else if ( msg == "execute(QString,QString)" ) {
1059 if ( type() == GuiServer ) { 1059 if ( type() == GuiServer ) {
1060 QString t, d; 1060 QString t, d;
1061 stream >> t >> d; 1061 stream >> t >> d;
1062 Global::execute( t, d ); 1062 Global::execute( t, d );
1063 } 1063 }
1064 } 1064 }
1065 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1065 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1066 if ( type() == GuiServer ) { 1066 if ( type() == GuiServer ) {
1067 QDateTime when; 1067 QDateTime when;
1068 QCString channel, message; 1068 QCString channel, message;
1069 int data; 1069 int data;
1070 stream >> when >> channel >> message >> data; 1070 stream >> when >> channel >> message >> data;
1071 AlarmServer::addAlarm( when, channel, message, data ); 1071 AlarmServer::addAlarm( when, channel, message, data );
1072 } 1072 }
1073 } 1073 }
1074 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1074 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1075 if ( type() == GuiServer ) { 1075 if ( type() == GuiServer ) {
1076 QDateTime when; 1076 QDateTime when;
1077 QCString channel, message; 1077 QCString channel, message;
1078 int data; 1078 int data;
1079 stream >> when >> channel >> message >> data; 1079 stream >> when >> channel >> message >> data;
1080 AlarmServer::deleteAlarm( when, channel, message, data ); 1080 AlarmServer::deleteAlarm( when, channel, message, data );
1081 } 1081 }
1082 } 1082 }
1083 else if ( msg == "clockChange(bool)" ) { 1083 else if ( msg == "clockChange(bool)" ) {
1084 int tmp; 1084 int tmp;
1085 stream >> tmp; 1085 stream >> tmp;
1086 emit clockChanged( tmp ); 1086 emit clockChanged( tmp );
1087 } 1087 }
1088 else if ( msg == "weekChange(bool)" ) { 1088 else if ( msg == "weekChange(bool)" ) {
1089 int tmp; 1089 int tmp;
1090 stream >> tmp; 1090 stream >> tmp;
1091 emit weekChanged( tmp ); 1091 emit weekChanged( tmp );
1092 } 1092 }
1093 else if ( msg == "setDateFormat(DateFormat)" ) { 1093 else if ( msg == "setDateFormat(DateFormat)" ) {
1094 DateFormat tmp; 1094 DateFormat tmp;
1095 stream >> tmp; 1095 stream >> tmp;
1096 emit dateFormatChanged( tmp ); 1096 emit dateFormatChanged( tmp );
1097 } 1097 }
1098 else if ( msg == "setVolume(int,int)" ) { 1098 else if ( msg == "setVolume(int,int)" ) {
1099 int t, v; 1099 int t, v;
1100 stream >> t >> v; 1100 stream >> t >> v;
1101 setVolume( t, v ); 1101 setVolume( t, v );
1102 emit volumeChanged( muted ); 1102 emit volumeChanged( muted );
1103 } 1103 }
1104 else if ( msg == "volumeChange(bool)" ) { 1104 else if ( msg == "volumeChange(bool)" ) {
1105 stream >> muted; 1105 stream >> muted;
1106 setVolume(); 1106 setVolume();
1107 emit volumeChanged( muted ); 1107 emit volumeChanged( muted );
1108 } 1108 }
1109 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1109 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1110 int t, v; 1110 int t, v;
1111 stream >> t >> v; 1111 stream >> t >> v;
1112 setMic( t, v ); 1112 setMic( t, v );
1113 emit micChanged( micMuted ); 1113 emit micChanged( micMuted );
1114 } 1114 }
1115 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1115 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1116 stream >> micMuted; 1116 stream >> micMuted;
1117 setMic(); 1117 setMic();
1118 emit micChanged( micMuted ); 1118 emit micChanged( micMuted );
1119 } 1119 }
1120#endif 1120#endif
1121} 1121}
1122 1122
1123/*! 1123/*!
1124 \internal 1124 \internal
1125*/ 1125*/
1126bool QPEApplication::raiseAppropriateWindow() 1126bool QPEApplication::raiseAppropriateWindow()
1127{ 1127{
1128 bool r = FALSE; 1128 bool r = FALSE;
1129 // ########## raise()ing main window should raise and set active 1129 // ########## raise()ing main window should raise and set active
1130 // ########## it and then all childen. This belongs in Qt/Embedded 1130 // ########## it and then all childen. This belongs in Qt/Embedded
1131 QWidget *top = d->qpe_main_widget; 1131 QWidget *top = d->qpe_main_widget;
1132 if ( !top ) 1132 if ( !top )
1133 top = mainWidget(); 1133 top = mainWidget();
1134 if ( top && d->keep_running ) { 1134 if ( top && d->keep_running ) {
1135 if ( top->isVisible() ) 1135 if ( top->isVisible() )
1136 r = TRUE; 1136 r = TRUE;
1137 else if (d->preloaded) { 1137 else if (d->preloaded) {
1138 // We are preloaded and not visible.. pretend we just started.. 1138 // We are preloaded and not visible.. pretend we just started..
1139 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1139 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1140 e << d->appName; 1140 e << d->appName;
1141 } 1141 }
1142 1142
1143 d->show_mx(top, d->nomaximize); 1143 d->show_mx(top, d->nomaximize);
1144 top->raise(); 1144 top->raise();
1145 top->setActiveWindow(); 1145 top->setActiveWindow();
1146 } 1146 }
1147 QWidget *topm = activeModalWidget(); 1147 QWidget *topm = activeModalWidget();
1148 if ( topm && topm != top ) { 1148 if ( topm && topm != top ) {
1149 topm->show(); 1149 topm->show();
1150 topm->raise(); 1150 topm->raise();
1151 topm->setActiveWindow(); 1151 topm->setActiveWindow();
1152 // If we haven't already handled the fastAppShowing message 1152 // If we haven't already handled the fastAppShowing message
1153 if (!top && d->preloaded) { 1153 if (!top && d->preloaded) {
1154 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1154 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1155 e << d->appName; 1155 e << d->appName;
1156 } 1156 }
1157 r = FALSE; 1157 r = FALSE;
1158 } 1158 }
1159 return r; 1159 return r;
1160} 1160}
1161 1161
1162void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1162void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1163{ 1163{
1164#ifdef Q_WS_QWS 1164#ifdef Q_WS_QWS
1165 1165
1166 if ( msg == "quit()" ) { 1166 if ( msg == "quit()" ) {
1167 tryQuit(); 1167 tryQuit();
1168 } 1168 }
1169 else if ( msg == "quitIfInvisible()" ) { 1169 else if ( msg == "quitIfInvisible()" ) {
1170 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1170 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1171 quit(); 1171 quit();
1172 } 1172 }
1173 else if ( msg == "close()" ) { 1173 else if ( msg == "close()" ) {
1174 hideOrQuit(); 1174 hideOrQuit();
1175 } 1175 }
1176 else if ( msg == "disablePreload()" ) { 1176 else if ( msg == "disablePreload()" ) {
1177 d->preloaded = FALSE; 1177 d->preloaded = FALSE;
1178 d->keep_running = TRUE; 1178 d->keep_running = TRUE;
1179 /* so that quit will quit */ 1179 /* so that quit will quit */
1180 } 1180 }
1181 else if ( msg == "enablePreload()" ) { 1181 else if ( msg == "enablePreload()" ) {
1182 if (d->qpe_main_widget) 1182 if (d->qpe_main_widget)
1183 d->preloaded = TRUE; 1183 d->preloaded = TRUE;
1184 d->keep_running = TRUE; 1184 d->keep_running = TRUE;
1185 /* so next quit won't quit */ 1185 /* so next quit won't quit */
1186 } 1186 }
1187 else if ( msg == "raise()" ) { 1187 else if ( msg == "raise()" ) {
1188 d->keep_running = TRUE; 1188 d->keep_running = TRUE;
1189 d->notbusysent = FALSE; 1189 d->notbusysent = FALSE;
1190 raiseAppropriateWindow(); 1190 raiseAppropriateWindow();
1191 // Tell the system we're still chugging along... 1191 // Tell the system we're still chugging along...
1192 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1192 QCopEnvelope e("QPE/System", "appRaised(QString)");
1193 e << d->appName; 1193 e << d->appName;
1194 } 1194 }
1195 else if ( msg == "flush()" ) { 1195 else if ( msg == "flush()" ) {
1196 emit flush(); 1196 emit flush();
1197 // we need to tell the desktop 1197 // we need to tell the desktop
1198 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1198 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1199 e << d->appName; 1199 e << d->appName;
1200 } 1200 }
1201 else if ( msg == "reload()" ) { 1201 else if ( msg == "reload()" ) {
1202 emit reload(); 1202 emit reload();
1203 } 1203 }
1204 else if ( msg == "setDocument(QString)" ) { 1204 else if ( msg == "setDocument(QString)" ) {
1205 d->keep_running = TRUE; 1205 d->keep_running = TRUE;
1206 QDataStream stream( data, IO_ReadOnly ); 1206 QDataStream stream( data, IO_ReadOnly );
1207 QString doc; 1207 QString doc;
1208 stream >> doc; 1208 stream >> doc;
1209 QWidget *mw = mainWidget(); 1209 QWidget *mw = mainWidget();
1210 if ( !mw ) 1210 if ( !mw )
1211 mw = d->qpe_main_widget; 1211 mw = d->qpe_main_widget;
1212 if ( mw ) 1212 if ( mw )
1213 Global::setDocument( mw, doc ); 1213 Global::setDocument( mw, doc );
1214 } 1214 }
1215 else if ( msg == "nextView()" ) { 1215 else if ( msg == "nextView()" ) {
1216 qDebug("got nextView()"); 1216 qDebug("got nextView()");
1217 /* 1217 /*
1218 if ( raiseAppropriateWindow() ) 1218 if ( raiseAppropriateWindow() )
1219 */ 1219 */
1220 emit appMessage( msg, data); 1220 emit appMessage( msg, data);
1221 } 1221 }
1222 else { 1222 else {
1223 emit appMessage( msg, data); 1223 emit appMessage( msg, data);
1224 } 1224 }
1225 1225
1226#endif 1226#endif
1227} 1227}
1228 1228
1229 1229
1230/*! 1230/*!
1231 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1231 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1232 consider passing TRUE for \a nomaximize rather than the default FALSE. 1232 consider passing TRUE for \a nomaximize rather than the default FALSE.
1233 1233
1234 \sa showMainDocumentWidget() 1234 \sa showMainDocumentWidget()
1235*/ 1235*/
1236void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1236void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1237{ 1237{
1238 d->show(mw, nomaximize ); 1238 d->show(mw, nomaximize );
1239} 1239}
1240 1240
1241/*! 1241/*!
1242 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1242 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1243 consider passing TRUE for \a nomaximize rather than the default FALSE. 1243 consider passing TRUE for \a nomaximize rather than the default FALSE.
1244 1244
1245 This calls designates the application as 1245 This calls designates the application as
1246 a \link docwidget.html document-oriented\endlink application. 1246 a \link docwidget.html document-oriented\endlink application.
1247 1247
1248 The \a mw widget \e must have this slot: setDocument(const QString&). 1248 The \a mw widget \e must have this slot: setDocument(const QString&).
1249 1249
1250 \sa showMainWidget() 1250 \sa showMainWidget()
1251*/ 1251*/
1252void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1252void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1253{ 1253{
1254 if ( mw && argc() == 2 ) 1254 if ( mw && argc() == 2 )
1255 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1255 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1256 1256
1257 d->show(mw, nomaximize ); 1257 d->show(mw, nomaximize );
1258} 1258}
1259 1259
1260 1260
1261/*! 1261/*!
1262 If an application is started via a \link qcop.html QCop\endlink 1262 If an application is started via a \link qcop.html QCop\endlink
1263 message, the application will process the \link qcop.html 1263 message, the application will process the \link qcop.html
1264 QCop\endlink message and then quit. If the application calls this 1264 QCop\endlink message and then quit. If the application calls this
1265 function while processing a \link qcop.html QCop\endlink message, 1265 function while processing a \link qcop.html QCop\endlink message,
1266 after processing its outstanding \link qcop.html QCop\endlink 1266 after processing its outstanding \link qcop.html QCop\endlink
1267 messages the application will start 'properly' and show itself. 1267 messages the application will start 'properly' and show itself.
1268 1268
1269 \sa keepRunning() 1269 \sa keepRunning()
1270*/ 1270*/
1271void QPEApplication::setKeepRunning() 1271void QPEApplication::setKeepRunning()
1272{ 1272{
1273 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1273 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1274 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1274 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1275 qpeApp->d->keep_running = TRUE; 1275 qpeApp->d->keep_running = TRUE;
1276 } 1276 }
1277} 1277}
1278 1278
1279/*! 1279/*!
1280 Returns TRUE if the application will quit after processing the 1280 Returns TRUE if the application will quit after processing the
1281 current list of qcop messages; otherwise returns FALSE. 1281 current list of qcop messages; otherwise returns FALSE.
1282 1282
1283 \sa setKeepRunning() 1283 \sa setKeepRunning()
1284*/ 1284*/
1285bool QPEApplication::keepRunning() const 1285bool QPEApplication::keepRunning() const
1286{ 1286{
1287 return d->keep_running; 1287 return d->keep_running;
1288} 1288}
1289 1289
1290/*! 1290/*!
1291 \internal 1291 \internal
1292*/ 1292*/
1293void QPEApplication::internalSetStyle( const QString &style ) 1293void QPEApplication::internalSetStyle( const QString &style )
1294{ 1294{
1295#if QT_VERSION >= 300 1295#if QT_VERSION >= 300
1296 if ( style == "QPE" ) { 1296 if ( style == "QPE" ) {
1297 setStyle( new QPEStyle ); 1297 setStyle( new QPEStyle );
1298 } 1298 }
1299 else { 1299 else {
1300 QStyle *s = QStyleFactory::create( style ); 1300 QStyle *s = QStyleFactory::create( style );
1301 if ( s ) 1301 if ( s )
1302 setStyle( s ); 1302 setStyle( s );
1303 } 1303 }
1304#else 1304#else
1305 if ( style == "Windows" ) { 1305 if ( style == "Windows" ) {
1306 setStyle( new QWindowsStyle ); 1306 setStyle( new QWindowsStyle );
1307 } 1307 }
1308 else if ( style == "QPE" ) { 1308 else if ( style == "QPE" ) {
1309 setStyle( new QPEStyle ); 1309 setStyle( new QPEStyle );
1310 } 1310 }
1311 else if ( style == "Light" ) { 1311 else if ( style == "Light" ) {
1312 setStyle( new LightStyle ); 1312 setStyle( new LightStyle );
1313 } 1313 }
1314#ifndef QT_NO_STYLE_PLATINUM 1314#ifndef QT_NO_STYLE_PLATINUM
1315 else if ( style == "Platinum" ) { 1315 else if ( style == "Platinum" ) {
1316 setStyle( new QPlatinumStyle ); 1316 setStyle( new QPlatinumStyle );
1317 } 1317 }
1318#endif 1318#endif
1319#ifndef QT_NO_STYLE_MOTIF 1319#ifndef QT_NO_STYLE_MOTIF
1320 else if ( style == "Motif" ) { 1320 else if ( style == "Motif" ) {
1321 setStyle( new QMotifStyle ); 1321 setStyle( new QMotifStyle );
1322 } 1322 }
1323#endif 1323#endif
1324#ifndef QT_NO_STYLE_MOTIFPLUS 1324#ifndef QT_NO_STYLE_MOTIFPLUS
1325 else if ( style == "MotifPlus" ) { 1325 else if ( style == "MotifPlus" ) {
1326 setStyle( new QMotifPlusStyle ); 1326 setStyle( new QMotifPlusStyle );
1327 } 1327 }
1328#endif 1328#endif
1329 1329
1330 else { 1330 else {
1331 QStyle *sty = 0; 1331 QStyle *sty = 0;
1332 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 1332 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
1333 1333
1334 if ( style. find ( ".so" ) > 0 ) 1334 if ( style. find ( ".so" ) > 0 )
1335 path += style; 1335 path += style;
1336 else 1336 else
1337 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1337 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1338 1338
1339 static QLibrary *lastlib = 0; 1339 static QLibrary *lastlib = 0;
1340 static StyleInterface *lastiface = 0; 1340 static StyleInterface *lastiface = 0;
1341 1341
1342 QLibrary *lib = new QLibrary ( path ); 1342 QLibrary *lib = new QLibrary ( path );
1343 StyleInterface *iface = 0; 1343 StyleInterface *iface = 0;
1344 1344
1345 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1345 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1346 sty = iface-> style ( ); 1346 sty = iface-> style ( );
1347 1347
1348 if ( sty ) { 1348 if ( sty ) {
1349 setStyle ( sty ); 1349 setStyle ( sty );
1350 1350
1351 if ( lastiface ) 1351 if ( lastiface )
1352 lastiface-> release ( ); 1352 lastiface-> release ( );
1353 lastiface = iface; 1353 lastiface = iface;
1354 1354
1355 if ( lastlib ) { 1355 if ( lastlib ) {
1356 lastlib-> unload ( ); 1356 lastlib-> unload ( );
1357 delete lastlib; 1357 delete lastlib;
1358 } 1358 }
1359 lastlib = lib; 1359 lastlib = lib;
1360 } 1360 }
1361 else { 1361 else {
1362 if ( iface ) 1362 if ( iface )
1363 iface-> release ( ); 1363 iface-> release ( );
1364 delete lib; 1364 delete lib;
1365 1365
1366 setStyle ( new LightStyle ( )); 1366 setStyle ( new LightStyle ( ));
1367 } 1367 }
1368 } 1368 }
1369#endif 1369#endif
1370} 1370}
1371 1371
1372/*! 1372/*!
1373 \internal 1373 \internal
1374*/ 1374*/
1375void QPEApplication::prepareForTermination( bool willrestart ) 1375void QPEApplication::prepareForTermination( bool willrestart )
1376{ 1376{
1377 if ( willrestart ) { 1377 if ( willrestart ) {
1378 // Draw a big wait icon, the image can be altered in later revisions 1378 // Draw a big wait icon, the image can be altered in later revisions
1379 // QWidget *d = QApplication::desktop(); 1379 // QWidget *d = QApplication::desktop();
1380 QImage img = Resource::loadImage( "launcher/new_wait" ); 1380 QImage img = Resource::loadImage( "launcher/new_wait" );
1381 QPixmap pix; 1381 QPixmap pix;
1382 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1382 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1383 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1383 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1384 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1384 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1385 lblWait->setPixmap( pix ); 1385 lblWait->setPixmap( pix );
1386 lblWait->setAlignment( QWidget::AlignCenter ); 1386 lblWait->setAlignment( QWidget::AlignCenter );
1387 lblWait->show(); 1387 lblWait->show();
1388 lblWait->showMaximized(); 1388 lblWait->showMaximized();
1389 } 1389 }
1390#ifndef SINGLE_APP 1390#ifndef SINGLE_APP
1391 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1391 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1392 } 1392 }
1393 processEvents(); // ensure the message goes out. 1393 processEvents(); // ensure the message goes out.
1394 sleep( 1 ); // You have 1 second to comply. 1394 sleep( 1 ); // You have 1 second to comply.
1395#endif 1395#endif
1396} 1396}
1397 1397
1398/*! 1398/*!
1399 \internal 1399 \internal
1400*/ 1400*/
1401void QPEApplication::shutdown() 1401void QPEApplication::shutdown()
1402{ 1402{
1403 // Implement in server's QPEApplication subclass 1403 // Implement in server's QPEApplication subclass
1404} 1404}
1405 1405
1406/*! 1406/*!
1407 \internal 1407 \internal
1408*/ 1408*/
1409void QPEApplication::restart() 1409void QPEApplication::restart()
1410{ 1410{
1411 // Implement in server's QPEApplication subclass 1411 // Implement in server's QPEApplication subclass
1412} 1412}
1413 1413
1414static QPtrDict<void>* stylusDict = 0; 1414static QPtrDict<void>* stylusDict = 0;
1415static void createDict() 1415static void createDict()
1416{ 1416{
1417 if ( !stylusDict ) 1417 if ( !stylusDict )
1418 stylusDict = new QPtrDict<void>; 1418 stylusDict = new QPtrDict<void>;
1419} 1419}
1420 1420
1421/*! 1421/*!
1422 Returns the current StylusMode for widget \a w. 1422 Returns the current StylusMode for widget \a w.
1423 1423
1424 \sa setStylusOperation() StylusMode 1424 \sa setStylusOperation() StylusMode
1425*/ 1425*/
1426QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1426QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1427{ 1427{
1428 if ( stylusDict ) 1428 if ( stylusDict )
1429 return ( StylusMode ) ( int ) stylusDict->find( w ); 1429 return ( StylusMode ) ( int ) stylusDict->find( w );
1430 return LeftOnly; 1430 return LeftOnly;
1431} 1431}
1432 1432
1433/*! 1433/*!
1434 \enum QPEApplication::StylusMode 1434 \enum QPEApplication::StylusMode
1435 1435
1436 \value LeftOnly the stylus only generates LeftButton 1436 \value LeftOnly the stylus only generates LeftButton
1437 events (the default). 1437 events (the default).
1438 \value RightOnHold the stylus generates RightButton events 1438 \value RightOnHold the stylus generates RightButton events
1439 if the user uses the press-and-hold gesture. 1439 if the user uses the press-and-hold gesture.
1440 1440
1441 \sa setStylusOperation() stylusOperation() 1441 \sa setStylusOperation() stylusOperation()
1442*/ 1442*/
1443 1443
1444/*! 1444/*!
1445 Causes widget \a w to receive mouse events according to the stylus 1445 Causes widget \a w to receive mouse events according to the stylus
1446 \a mode. 1446 \a mode.
1447 1447
1448 \sa stylusOperation() StylusMode 1448 \sa stylusOperation() StylusMode
1449*/ 1449*/
1450void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1450void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1451{ 1451{
1452 createDict(); 1452 createDict();
1453 if ( mode == LeftOnly ) { 1453 if ( mode == LeftOnly ) {
1454 stylusDict->remove 1454 stylusDict->remove
1455 ( w ); 1455 ( w );
1456 w->removeEventFilter( qApp ); 1456 w->removeEventFilter( qApp );
1457 } 1457 }
1458 else { 1458 else {
1459 stylusDict->insert( w, ( void* ) mode ); 1459 stylusDict->insert( w, ( void* ) mode );
1460 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 1460 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
1461 w->installEventFilter( qApp ); 1461 w->installEventFilter( qApp );
1462 } 1462 }
1463} 1463}
1464 1464
1465 1465
1466/*! 1466/*!
1467 \reimp 1467 \reimp
1468*/ 1468*/
1469bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1469bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1470{ 1470{
1471 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1471 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1472 QMouseEvent * me = ( QMouseEvent* ) e; 1472 QMouseEvent * me = ( QMouseEvent* ) e;
1473 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 1473 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1474 switch (mode) { 1474 switch (mode) {
1475 case RightOnHold: 1475 case RightOnHold:
1476 switch ( me->type() ) { 1476 switch ( me->type() ) {
1477 case QEvent::MouseButtonPress: 1477 case QEvent::MouseButtonPress:
1478 if ( me->button() == LeftButton ) { 1478 if ( me->button() == LeftButton ) {
1479 d->presstimer = startTimer(500); // #### pref. 1479 d->presstimer = startTimer(500); // #### pref.
1480 d->presswidget = (QWidget*)o; 1480 d->presswidget = (QWidget*)o;
1481 d->presspos = me->pos(); 1481 d->presspos = me->pos();
1482 d->rightpressed = FALSE; 1482 d->rightpressed = FALSE;
1483 } 1483 }
1484 break; 1484 break;
1485 case QEvent::MouseMove: 1485 case QEvent::MouseMove:
1486 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 1486 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
1487 killTimer(d->presstimer); 1487 killTimer(d->presstimer);
1488 d->presstimer = 0; 1488 d->presstimer = 0;
1489 } 1489 }
1490 break; 1490 break;
1491 case QEvent::MouseButtonRelease: 1491 case QEvent::MouseButtonRelease:
1492 if ( me->button() == LeftButton ) { 1492 if ( me->button() == LeftButton ) {
1493 if ( d->presstimer ) { 1493 if ( d->presstimer ) {
1494 killTimer(d->presstimer); 1494 killTimer(d->presstimer);
1495 d->presstimer = 0; 1495 d->presstimer = 0;
1496 } 1496 }
1497 if ( d->rightpressed && d->presswidget ) { 1497 if ( d->rightpressed && d->presswidget ) {
1498 // Right released 1498 // Right released
1499 postEvent( d->presswidget, 1499 postEvent( d->presswidget,
1500 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 1500 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1501 RightButton, LeftButton + RightButton ) ); 1501 RightButton, LeftButton + RightButton ) );
1502 // Left released, off-widget 1502 // Left released, off-widget
1503 postEvent( d->presswidget, 1503 postEvent( d->presswidget,
1504 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 1504 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
1505 LeftButton, LeftButton ) ); 1505 LeftButton, LeftButton ) );
1506 postEvent( d->presswidget, 1506 postEvent( d->presswidget,
1507 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 1507 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
1508 LeftButton, LeftButton ) ); 1508 LeftButton, LeftButton ) );
1509 d->rightpressed = FALSE; 1509 d->rightpressed = FALSE;
1510 return TRUE; // don't send the real Left release 1510 return TRUE; // don't send the real Left release
1511 } 1511 }
1512 } 1512 }
1513 break; 1513 break;
1514 default: 1514 default:
1515 break; 1515 break;
1516 } 1516 }
1517 break; 1517 break;
1518 default: 1518 default:
1519 ; 1519 ;
1520 } 1520 }
1521 } 1521 }
1522 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1522 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1523 QKeyEvent *ke = (QKeyEvent *)e; 1523 QKeyEvent *ke = (QKeyEvent *)e;
1524 if ( ke->key() == Key_Enter ) { 1524 if ( ke->key() == Key_Enter ) {
1525 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1525 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1526 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1526 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1527 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1527 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1528 return TRUE; 1528 return TRUE;
1529 } 1529 }
1530 } 1530 }
1531 } 1531 }
1532 return FALSE; 1532 return FALSE;
1533} 1533}
1534 1534
1535/*! 1535/*!
1536 \reimp 1536 \reimp
1537*/ 1537*/
1538void QPEApplication::timerEvent( QTimerEvent *e ) 1538void QPEApplication::timerEvent( QTimerEvent *e )
1539{ 1539{
1540 if ( e->timerId() == d->presstimer && d->presswidget ) { 1540 if ( e->timerId() == d->presstimer && d->presswidget ) {
1541 // Right pressed 1541 // Right pressed
1542 postEvent( d->presswidget, 1542 postEvent( d->presswidget,
1543 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 1543 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
1544 RightButton, LeftButton ) ); 1544 RightButton, LeftButton ) );
1545 killTimer( d->presstimer ); 1545 killTimer( d->presstimer );
1546 d->presstimer = 0; 1546 d->presstimer = 0;
1547 d->rightpressed = TRUE; 1547 d->rightpressed = TRUE;
1548 } 1548 }
1549} 1549}
1550 1550
1551void QPEApplication::removeSenderFromStylusDict() 1551void QPEApplication::removeSenderFromStylusDict()
1552{ 1552{
1553 stylusDict->remove 1553 stylusDict->remove
1554 ( ( void* ) sender() ); 1554 ( ( void* ) sender() );
1555 if ( d->presswidget == sender() ) 1555 if ( d->presswidget == sender() )
1556 d->presswidget = 0; 1556 d->presswidget = 0;
1557} 1557}
1558 1558
1559/*! 1559/*!
1560 \internal 1560 \internal
1561*/ 1561*/
1562bool QPEApplication::keyboardGrabbed() const 1562bool QPEApplication::keyboardGrabbed() const
1563{ 1563{
1564 return d->kbgrabber; 1564 return d->kbgrabber;
1565} 1565}
1566 1566
1567 1567
1568/*! 1568/*!
1569 Reverses the effect of grabKeyboard(). This is called automatically 1569 Reverses the effect of grabKeyboard(). This is called automatically
1570 on program exit. 1570 on program exit.
1571*/ 1571*/
1572void QPEApplication::ungrabKeyboard() 1572void QPEApplication::ungrabKeyboard()
1573{ 1573{
1574 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d; 1574 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d;
1575 if ( d->kbgrabber == 2 ) { 1575 if ( d->kbgrabber == 2 ) {
1576#ifndef QT_NO_COP 1576#ifndef QT_NO_COP
1577 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); 1577 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
1578 e << QString::null; 1578 e << QString::null;
1579#endif 1579#endif
1580 1580
1581 d->kbregrab = FALSE; 1581 d->kbregrab = FALSE;
1582 d->kbgrabber = 0; 1582 d->kbgrabber = 0;
1583 } 1583 }
1584} 1584}
1585 1585
1586/*! 1586/*!
1587 Grabs the physical keyboard keys, e.g. the application's launching 1587 Grabs the physical keyboard keys, e.g. the application's launching
1588 keys. Instead of launching applications when these keys are pressed 1588 keys. Instead of launching applications when these keys are pressed
1589 the signals emitted are sent to this application instead. Some games 1589 the signals emitted are sent to this application instead. Some games
1590 programs take over the launch keys in this way to make interaction 1590 programs take over the launch keys in this way to make interaction
1591 easier. 1591 easier.
1592 1592
1593 \sa ungrabKeyboard() 1593 \sa ungrabKeyboard()
1594*/ 1594*/
1595void QPEApplication::grabKeyboard() 1595void QPEApplication::grabKeyboard()
1596{ 1596{
1597 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d; 1597 QPEApplicationData * d = ( ( QPEApplication* ) qApp ) ->d;
1598 if ( qApp->type() == QApplication::GuiServer ) 1598 if ( qApp->type() == QApplication::GuiServer )
1599 d->kbgrabber = 0; 1599 d->kbgrabber = 0;
1600 else { 1600 else {
1601#ifndef QT_NO_COP 1601#ifndef QT_NO_COP
1602 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); 1602 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
1603 e << d->appName; 1603 e << d->appName;
1604#endif 1604#endif
1605 1605
1606 d->kbgrabber = 2; // me 1606 d->kbgrabber = 2; // me
1607 } 1607 }
1608} 1608}
1609 1609
1610/*! 1610/*!
1611 \reimp 1611 \reimp
1612*/ 1612*/
1613int QPEApplication::exec() 1613int QPEApplication::exec()
1614{ 1614{
1615#ifndef QT_NO_COP 1615#ifndef QT_NO_COP
1616 d->sendQCopQ(); 1616 d->sendQCopQ();
1617#endif 1617#endif
1618 1618
1619 if ( d->keep_running ) 1619 if ( d->keep_running )
1620 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1620 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1621 return QApplication::exec(); 1621 return QApplication::exec();
1622 1622
1623#ifndef QT_NO_COP 1623#ifndef QT_NO_COP
1624 1624
1625 { 1625 {
1626 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1626 QCopEnvelope e( "QPE/System", "closing(QString)" );
1627 e << d->appName; 1627 e << d->appName;
1628 } 1628 }
1629#endif 1629#endif
1630 processEvents(); 1630 processEvents();
1631 return 0; 1631 return 0;
1632} 1632}
1633 1633
1634/*! 1634/*!
1635 \internal 1635 \internal
1636 External request for application to quit. Quits if possible without 1636 External request for application to quit. Quits if possible without
1637 loosing state. 1637 loosing state.
1638*/ 1638*/
1639void QPEApplication::tryQuit() 1639void QPEApplication::tryQuit()
1640{ 1640{
1641 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 1641 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1642 return ; // Inside modal loop or konsole. Too hard to save state. 1642 return ; // Inside modal loop or konsole. Too hard to save state.
1643#ifndef QT_NO_COP 1643#ifndef QT_NO_COP
1644 1644
1645 { 1645 {
1646 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1646 QCopEnvelope e( "QPE/System", "closing(QString)" );
1647 e << d->appName; 1647 e << d->appName;
1648 } 1648 }
1649#endif 1649#endif
1650 processEvents(); 1650 processEvents();
1651 1651
1652 quit(); 1652 quit();
1653} 1653}
1654 1654
1655/*! 1655/*!
1656 \internal 1656 \internal
1657 User initiated quit. Makes the window 'Go Away'. If preloaded this means 1657 User initiated quit. Makes the window 'Go Away'. If preloaded this means
1658 hiding the window. If not it means quitting the application. 1658 hiding the window. If not it means quitting the application.
1659 As this is user initiated we don't need to check state. 1659 As this is user initiated we don't need to check state.
1660*/ 1660*/
1661void QPEApplication::hideOrQuit() 1661void QPEApplication::hideOrQuit()
1662{ 1662{
1663 processEvents(); 1663 processEvents();
1664 1664
1665 // If we are a preloaded application we don't actually quit, so emit 1665 // If we are a preloaded application we don't actually quit, so emit
1666 // a System message indicating we're quasi-closing. 1666 // a System message indicating we're quasi-closing.
1667 if ( d->preloaded && d->qpe_main_widget ) 1667 if ( d->preloaded && d->qpe_main_widget )
1668#ifndef QT_NO_COP 1668#ifndef QT_NO_COP
1669 1669
1670 { 1670 {
1671 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 1671 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
1672 e << d->appName; 1672 e << d->appName;
1673 d->qpe_main_widget->hide(); 1673 d->qpe_main_widget->hide();
1674 } 1674 }
1675#endif 1675#endif
1676 else 1676 else
1677 quit(); 1677 quit();
1678} 1678}
1679 1679
1680 1680
1681// These 6 stubs below need 1.5K in the binary and besides that -
1682// we are not using ancient toolchains anymore - sandman
1683
1684#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SHARP) 1681#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SHARP)
1685 1682
1686// The libraries with the skiff package (and possibly others) have 1683// The libraries with the skiff package (and possibly others) have
1687// completely useless implementations of builtin new and delete that 1684// completely useless implementations of builtin new and delete that
1688// use about 50% of your CPU. Here we revert to the simple libc 1685// use about 50% of your CPU. Here we revert to the simple libc
1689// functions. 1686// functions.
1690 1687
1691void* operator new[]( size_t size ) 1688void* operator new[]( size_t size )
1692{ 1689{
1693 return malloc( size ); 1690 return malloc( size );
1694} 1691}
1695 1692
1696void* operator new( size_t size ) 1693void* operator new( size_t size )
1697{ 1694{
1698 return malloc( size ); 1695 return malloc( size );
1699} 1696}
1700 1697
1701void operator delete[]( void* p ) 1698void operator delete[]( void* p )
1702{ 1699{
1703 free( p ); 1700 free( p );
1704} 1701}
1705 1702
1706void operator delete[]( void* p, size_t /*size*/ ) 1703void operator delete[]( void* p, size_t /*size*/ )
1707{ 1704{
1708 free( p ); 1705 free( p );
1709} 1706}
1710 1707
1711void operator delete( void* p ) 1708void operator delete( void* p )
1712{ 1709{
1713 free( p ); 1710 free( p );
1714} 1711}
1715 1712
1716void operator delete( void* p, size_t /*size*/ ) 1713void operator delete( void* p, size_t /*size*/ )
1717{ 1714{
1718 free( p ); 1715 free( p );
1719} 1716}
1720 1717
1721#endif 1718#endif
1722 1719
1723#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 1720#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
1724#include <qwidgetlist.h> 1721#include <qwidgetlist.h>
1725#ifdef QWS 1722#ifdef QWS
1726#include <qgfx_qws.h> 1723#include <qgfx_qws.h>
1727extern QRect qt_maxWindowRect; 1724extern QRect qt_maxWindowRect;
1728void qt_setMaxWindowRect(const QRect& r ) 1725void qt_setMaxWindowRect(const QRect& r )
1729{ 1726{
1730 qt_maxWindowRect = qt_screen->mapFromDevice( r, 1727 qt_maxWindowRect = qt_screen->mapFromDevice( r,
1731 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 1728 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
1732 // Re-resize any maximized windows 1729 // Re-resize any maximized windows
1733 QWidgetList* l = QApplication::topLevelWidgets(); 1730 QWidgetList* l = QApplication::topLevelWidgets();
1734 if ( l ) { 1731 if ( l ) {
1735 QWidget * w = l->first(); 1732 QWidget * w = l->first();
1736 while ( w ) { 1733 while ( w ) {
1737 if ( w->isVisible() && w->isMaximized() ) { 1734 if ( w->isVisible() && w->isMaximized() ) {
1738 w->showMaximized(); 1735 w->showMaximized();
1739 } 1736 }
1740 w = l->next(); 1737 w = l->next();
1741 } 1738 }
1742 delete l; 1739 delete l;
1743 } 1740 }
1744} 1741}
1745#endif 1742#endif
1746#endif 1743#endif