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