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