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