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