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