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