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