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