summaryrefslogtreecommitdiff
path: root/library
authorzecke <zecke>2003-10-04 07:23:27 (UTC)
committer zecke <zecke>2003-10-04 07:23:27 (UTC)
commit271ba635536db4a9f4ae1e575194d0f388b1c991 (patch) (unidiff)
treedbd2664b1a6422c6195a3b4eb17b591ff82a4499 /library
parenta4793f5226e9eb5c8a718cca9335c23530e08b08 (diff)
downloadopie-271ba635536db4a9f4ae1e575194d0f388b1c991.zip
opie-271ba635536db4a9f4ae1e575194d0f388b1c991.tar.gz
opie-271ba635536db4a9f4ae1e575194d0f388b1c991.tar.bz2
merges of qcopQok
and QPIxmapCache 'calibration' for PDA needs
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 0e469ae..28fb13a 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -6,160 +6,161 @@
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19*/ 19*/
20#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <stdlib.h> 21#include <stdlib.h>
22#include <unistd.h> 22#include <unistd.h>
23#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 23#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
24#include <qfile.h> 24#include <qfile.h>
25#include <qqueue.h> 25#include <qqueue.h>
26#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
27#ifndef QT_NO_COP 27#ifndef QT_NO_COP
28#if QT_VERSION <= 231 28#if QT_VERSION <= 231
29#define private public 29#define private public
30#define sendLocally processEvent 30#define sendLocally processEvent
31#include "qcopenvelope_qws.h" 31#include "qcopenvelope_qws.h"
32#undef private 32#undef private
33#else 33#else
34#include "qcopenvelope_qws.h" 34#include "qcopenvelope_qws.h"
35#endif 35#endif
36#endif 36#endif
37#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
38#endif 38#endif
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qpalette.h> 40#include <qpalette.h>
41#include <qbuffer.h> 41#include <qbuffer.h>
42#include <qptrdict.h> 42#include <qptrdict.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qdir.h> 44#include <qdir.h>
45#include <qlabel.h> 45#include <qlabel.h>
46#include <qdialog.h> 46#include <qdialog.h>
47#include <qdragobject.h> 47#include <qdragobject.h>
48#include <qtextcodec.h> 48#include <qtextcodec.h>
49#include <qevent.h> 49#include <qevent.h>
50#include <qtooltip.h> 50#include <qtooltip.h>
51#include <qsignal.h> 51#include <qsignal.h>
52#include <qmainwindow.h> 52#include <qmainwindow.h>
53#include <qwidgetlist.h> 53#include <qwidgetlist.h>
54#include <qpixmapcache.h>
54 55
55#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 56#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
56#define QTOPIA_INTERNAL_INITAPP 57#define QTOPIA_INTERNAL_INITAPP
57#include "qpeapplication.h" 58#include "qpeapplication.h"
58#include "qpestyle.h" 59#include "qpestyle.h"
59#include "styleinterface.h" 60#include "styleinterface.h"
60#if QT_VERSION >= 300 61#if QT_VERSION >= 300
61#include <qstylefactory.h> 62#include <qstylefactory.h>
62#else 63#else
63#include <qplatinumstyle.h> 64#include <qplatinumstyle.h>
64#include <qwindowsstyle.h> 65#include <qwindowsstyle.h>
65#include <qmotifstyle.h> 66#include <qmotifstyle.h>
66#include <qmotifplusstyle.h> 67#include <qmotifplusstyle.h>
67#include "lightstyle.h" 68#include "lightstyle.h"
68 69
69#include <qpe/qlibrary.h> 70#include <qpe/qlibrary.h>
70#endif 71#endif
71#include "global.h" 72#include "global.h"
72#include "resource.h" 73#include "resource.h"
73#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 74#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
74#include "qutfcodec.h" 75#include "qutfcodec.h"
75#endif 76#endif
76#include "config.h" 77#include "config.h"
77#include "network.h" 78#include "network.h"
78#ifdef QWS 79#ifdef QWS
79#include "fontmanager.h" 80#include "fontmanager.h"
80#endif 81#endif
81 82
82#include "alarmserver.h" 83#include "alarmserver.h"
83#include "applnk.h" 84#include "applnk.h"
84#include "qpemenubar.h" 85#include "qpemenubar.h"
85#include "textcodecinterface.h" 86#include "textcodecinterface.h"
86#include "imagecodecinterface.h" 87#include "imagecodecinterface.h"
87 88
88#include <unistd.h> 89#include <unistd.h>
89#include <sys/file.h> 90#include <sys/file.h>
90#include <sys/ioctl.h> 91#include <sys/ioctl.h>
91#include <sys/soundcard.h> 92#include <sys/soundcard.h>
92 93
93#include "qt_override_p.h" 94#include "qt_override_p.h"
94 95
95 96
96class QPEApplicationData 97class QPEApplicationData
97{ 98{
98public: 99public:
99 QPEApplicationData ( ) 100 QPEApplicationData ( )
100 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 101 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
101 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 102 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
102 keep_running( true ), qpe_main_widget( 0 ), qcopQok( false ) 103 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 )
103 104
104 {} 105 {}
105 106
106 int presstimer; 107 int presstimer;
107 QWidget* presswidget; 108 QWidget* presswidget;
108 QPoint presspos; 109 QPoint presspos;
109 110
110 bool rightpressed : 1; 111 bool rightpressed : 1;
111 bool kbgrabbed : 1; 112 bool kbgrabbed : 1;
112 bool notbusysent : 1; 113 bool notbusysent : 1;
113 bool preloaded : 1; 114 bool preloaded : 1;
114 bool forceshow : 1; 115 bool forceshow : 1;
115 bool nomaximize : 1; 116 bool nomaximize : 1;
116 bool qcopQok : 1;
117 bool keep_running : 1; 117 bool keep_running : 1;
118 bool qcopQok : 1;
118 119
119 120
120 QStringList langs; 121 QStringList langs;
121 QString appName; 122 QString appName;
122 struct QCopRec 123 struct QCopRec
123 { 124 {
124 QCopRec( const QCString &ch, const QCString &msg, 125 QCopRec( const QCString &ch, const QCString &msg,
125 const QByteArray &d ) : 126 const QByteArray &d ) :
126 channel( ch ), message( msg ), data( d ) 127 channel( ch ), message( msg ), data( d )
127 { } 128 { }
128 129
129 QCString channel; 130 QCString channel;
130 QCString message; 131 QCString message;
131 QByteArray data; 132 QByteArray data;
132 }; 133 };
133 QWidget* qpe_main_widget; 134 QWidget* qpe_main_widget;
134 QGuardedPtr<QWidget> lastraised; 135 QGuardedPtr<QWidget> lastraised;
135 QQueue<QCopRec> qcopq; 136 QQueue<QCopRec> qcopq;
136 QString styleName; 137 QString styleName;
137 QString decorationName; 138 QString decorationName;
138 139
139 void enqueueQCop( const QCString &ch, const QCString &msg, 140 void enqueueQCop( const QCString &ch, const QCString &msg,
140 const QByteArray &data ) 141 const QByteArray &data )
141 { 142 {
142 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 143 qcopq.enqueue( new QCopRec( ch, msg, data ) );
143 } 144 }
144 void sendQCopQ() 145 void sendQCopQ()
145 { 146 {
146 if (!qcopQok ) 147 if (!qcopQok )
147 return; 148 return;
148 149
149 QCopRec * r; 150 QCopRec * r;
150 151
151 while((r=qcopq.dequeue())) { 152 while((r=qcopq.dequeue())) {
152 // remove from queue before sending... 153 // remove from queue before sending...
153 // event loop can come around again before getting 154 // event loop can come around again before getting
154 // back from sendLocally 155 // back from sendLocally
155#ifndef QT_NO_COP 156#ifndef QT_NO_COP
156 QCopChannel::sendLocally( r->channel, r->message, r->data ); 157 QCopChannel::sendLocally( r->channel, r->message, r->data );
157#endif 158#endif
158 159
159 delete r; 160 delete r;
160 } 161 }
161 } 162 }
162 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) 163 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null )
163 { 164 {
164 165
165 // ugly hack, remove that later after finding a sane solution 166 // ugly hack, remove that later after finding a sane solution
@@ -169,96 +170,97 @@ public:
169#ifndef QT_QWS_SIMPAD 170#ifndef QT_QWS_SIMPAD
170 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 171 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
171 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 172 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
172 } 173 }
173#endif 174#endif
174 175
175 if ( mw->layout() && mw->inherits("QDialog") ) { 176 if ( mw->layout() && mw->inherits("QDialog") ) {
176 QPEApplication::showDialog((QDialog*)mw, nomaximize); 177 QPEApplication::showDialog((QDialog*)mw, nomaximize);
177 } 178 }
178 else { 179 else {
179#ifdef Q_WS_QWS 180#ifdef Q_WS_QWS
180 if ( !nomaximize ) 181 if ( !nomaximize )
181 mw->showMaximized(); 182 mw->showMaximized();
182 else 183 else
183#endif 184#endif
184 185
185 mw->show(); 186 mw->show();
186 } 187 }
187 } 188 }
188 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 189 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
189 { 190 {
190 /* 191 /*
191 // This works but disable it for now until it is safe to apply 192 // This works but disable it for now until it is safe to apply
192 // What is does is scan the .desktop files of all the apps for 193 // What is does is scan the .desktop files of all the apps for
193 // the applnk that has the corresponding argv[0] as this program 194 // the applnk that has the corresponding argv[0] as this program
194 // then it uses the name stored in the .desktop file as the caption 195 // then it uses the name stored in the .desktop file as the caption
195 // for the main widget. This saves duplicating translations for 196 // for the main widget. This saves duplicating translations for
196 // the app name in the program and in the .desktop files. 197 // the app name in the program and in the .desktop files.
197 198
198 AppLnkSet apps( appsPath ); 199 AppLnkSet apps( appsPath );
199 200
200 QList<AppLnk> appsList = apps.children(); 201 QList<AppLnk> appsList = apps.children();
201 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 202 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
202 if ( (*it)->exec() == appName ) { 203 if ( (*it)->exec() == appName ) {
203 mw->setCaption( (*it)->name() ); 204 mw->setCaption( (*it)->name() );
204 return TRUE; 205 return TRUE;
205 } 206 }
206 } 207 }
207 */ 208 */
208 return FALSE; 209 return FALSE;
209 } 210 }
210 211
211 212
212 void show(QWidget* mw, bool nomax) 213 void show(QWidget* mw, bool nomax)
213 { 214 {
214 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 215 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
215 nomaximize = nomax; 216 nomaximize = nomax;
216 qpe_main_widget = mw; 217 qpe_main_widget = mw;
218 qcopQok = TRUE;
217#ifndef QT_NO_COP 219#ifndef QT_NO_COP
218 220
219 sendQCopQ(); 221 sendQCopQ();
220#endif 222#endif
221 223
222 if ( preloaded ) { 224 if ( preloaded ) {
223 if (forceshow) 225 if (forceshow)
224 show_mx(mw, nomax); 226 show_mx(mw, nomax);
225 } 227 }
226 else if ( keep_running ) { 228 else if ( keep_running ) {
227 show_mx(mw, nomax); 229 show_mx(mw, nomax);
228 } 230 }
229 } 231 }
230 232
231 void loadTextCodecs() 233 void loadTextCodecs()
232 { 234 {
233 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 235 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
234 QDir dir( path, "lib*.so" ); 236 QDir dir( path, "lib*.so" );
235 QStringList list; 237 QStringList list;
236 if ( dir. exists ( )) 238 if ( dir. exists ( ))
237 list = dir.entryList(); 239 list = dir.entryList();
238 QStringList::Iterator it; 240 QStringList::Iterator it;
239 for ( it = list.begin(); it != list.end(); ++it ) { 241 for ( it = list.begin(); it != list.end(); ++it ) {
240 TextCodecInterface *iface = 0; 242 TextCodecInterface *iface = 0;
241 QLibrary *lib = new QLibrary( path + "/" + *it ); 243 QLibrary *lib = new QLibrary( path + "/" + *it );
242 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 244 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
243 QValueList<int> mibs = iface->mibEnums(); 245 QValueList<int> mibs = iface->mibEnums();
244 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 246 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
245 (void)iface->createForMib(*i); 247 (void)iface->createForMib(*i);
246 // ### it exists now; need to remember if we can delete it 248 // ### it exists now; need to remember if we can delete it
247 } 249 }
248 } 250 }
249 else { 251 else {
250 lib->unload(); 252 lib->unload();
251 delete lib; 253 delete lib;
252 } 254 }
253 } 255 }
254 } 256 }
255 257
256 void loadImageCodecs() 258 void loadImageCodecs()
257 { 259 {
258 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 260 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
259 QDir dir( path, "lib*.so" ); 261 QDir dir( path, "lib*.so" );
260 QStringList list; 262 QStringList list;
261 if ( dir. exists ( )) 263 if ( dir. exists ( ))
262 list = dir.entryList(); 264 list = dir.entryList();
263 QStringList::Iterator it; 265 QStringList::Iterator it;
264 for ( it = list.begin(); it != list.end(); ++it ) { 266 for ( it = list.begin(); it != list.end(); ++it ) {
@@ -531,96 +533,98 @@ void QPEApplication::processQCopFile()
531#ifndef Q_OS_WIN32 533#ifndef Q_OS_WIN32
532 f.flush(); 534 f.flush();
533 flock(f.handle(), LOCK_UN); 535 flock(f.handle(), LOCK_UN);
534#endif 536#endif
535 } 537 }
536#endif 538#endif
537} 539}
538 540
539 541
540/*! 542/*!
541 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 543 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
542 544
543 This signal is emitted when a message is received on this 545 This signal is emitted when a message is received on this
544 application's QPE/Application/<i>appname</i> \link qcop.html 546 application's QPE/Application/<i>appname</i> \link qcop.html
545 QCop\endlink channel. 547 QCop\endlink channel.
546 548
547 The slot to which you connect this signal uses \a msg and \a data 549 The slot to which you connect this signal uses \a msg and \a data
548 in the following way: 550 in the following way:
549 551
550\code 552\code
551 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 553 void MyWidget::receive( const QCString& msg, const QByteArray& data )
552 { 554 {
553 QDataStream stream( data, IO_ReadOnly ); 555 QDataStream stream( data, IO_ReadOnly );
554 if ( msg == "someMessage(int,int,int)" ) { 556 if ( msg == "someMessage(int,int,int)" ) {
555 int a,b,c; 557 int a,b,c;
556 stream >> a >> b >> c; 558 stream >> a >> b >> c;
557 ... 559 ...
558 } else if ( msg == "otherMessage(QString)" ) { 560 } else if ( msg == "otherMessage(QString)" ) {
559 ... 561 ...
560 } 562 }
561 } 563 }
562\endcode 564\endcode
563 565
564 \sa qcop.html 566 \sa qcop.html
565 Note that messages received here may be processed by qpe application 567 Note that messages received here may be processed by qpe application
566 and emitted as signals, such as flush() and reload(). 568 and emitted as signals, such as flush() and reload().
567*/ 569*/
568 570
569/*! 571/*!
570 Constructs a QPEApplication just as you would construct 572 Constructs a QPEApplication just as you would construct
571 a QApplication, passing \a argc, \a argv, and \a t. 573 a QApplication, passing \a argc, \a argv, and \a t.
572 574
573 For applications, \a t should be the default, GuiClient. Only 575 For applications, \a t should be the default, GuiClient. Only
574 the Qtopia server passes GuiServer. 576 the Qtopia server passes GuiServer.
575*/ 577*/
576QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 578QPEApplication::QPEApplication( int & argc, char **argv, Type t )
577 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 579 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
578{ 580{
581 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
582
579 d = new QPEApplicationData; 583 d = new QPEApplicationData;
580 d->loadTextCodecs(); 584 d->loadTextCodecs();
581 d->loadImageCodecs(); 585 d->loadImageCodecs();
582 int dw = desktop() ->width(); 586 int dw = desktop() ->width();
583 587
584 if ( dw < 200 ) { 588 if ( dw < 200 ) {
585 setFont( QFont( "vera", 8 ) ); 589 setFont( QFont( "vera", 8 ) );
586 AppLnk::setSmallIconSize( 10 ); 590 AppLnk::setSmallIconSize( 10 );
587 AppLnk::setBigIconSize( 28 ); 591 AppLnk::setBigIconSize( 28 );
588 } 592 }
589#ifndef QT_QWS_SIMPAD 593#ifndef QT_QWS_SIMPAD
590 else if ( dw > 600 ) { 594 else if ( dw > 600 ) {
591 setFont( QFont( "vera", 16 ) ); 595 setFont( QFont( "vera", 16 ) );
592 AppLnk::setSmallIconSize( 24 ); 596 AppLnk::setSmallIconSize( 24 );
593 AppLnk::setBigIconSize( 48 ); 597 AppLnk::setBigIconSize( 48 );
594 } 598 }
595#endif 599#endif
596 else if ( dw > 200 ) { 600 else if ( dw > 200 ) {
597 setFont( QFont( "vera", 10 ) ); 601 setFont( QFont( "vera", 10 ) );
598 AppLnk::setSmallIconSize( 14 ); 602 AppLnk::setSmallIconSize( 14 );
599 AppLnk::setBigIconSize( 32 ); 603 AppLnk::setBigIconSize( 32 );
600 } 604 }
601 605
602 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 606 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
603 607
604 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 608 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
605 609
606 610
607 sysChannel = new QCopChannel( "QPE/System", this ); 611 sysChannel = new QCopChannel( "QPE/System", this );
608 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 612 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
609 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 613 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
610 614
611/* COde now in initapp */ 615/* COde now in initapp */
612#if 0 616#if 0
613#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 617#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
614 618
615 QString qcopfn( "/tmp/qcop-msg-" ); 619 QString qcopfn( "/tmp/qcop-msg-" );
616 qcopfn += QString( argv[ 0 ] ); // append command name 620 qcopfn += QString( argv[ 0 ] ); // append command name
617 621
618 QFile f( qcopfn ); 622 QFile f( qcopfn );
619 if ( f.open( IO_ReadOnly ) ) { 623 if ( f.open( IO_ReadOnly ) ) {
620 flock( f.handle(), LOCK_EX ); 624 flock( f.handle(), LOCK_EX );
621 } 625 }
622 626
623 627
624 628
625 QCString channel = QCString( argv[ 0 ] ); 629 QCString channel = QCString( argv[ 0 ] );
626 channel.replace( QRegExp( ".*/" ), "" ); 630 channel.replace( QRegExp( ".*/" ), "" );
@@ -1731,105 +1735,109 @@ static void createDict()
1731 1735
1732 \sa setStylusOperation() StylusMode 1736 \sa setStylusOperation() StylusMode
1733*/ 1737*/
1734QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1738QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1735{ 1739{
1736 if ( stylusDict ) 1740 if ( stylusDict )
1737 return ( StylusMode ) ( int ) stylusDict->find( w ); 1741 return ( StylusMode ) ( int ) stylusDict->find( w );
1738 return LeftOnly; 1742 return LeftOnly;
1739} 1743}
1740 1744
1741/*! 1745/*!
1742 \enum QPEApplication::StylusMode 1746 \enum QPEApplication::StylusMode
1743 1747
1744 \value LeftOnly the stylus only generates LeftButton 1748 \value LeftOnly the stylus only generates LeftButton
1745 events (the default). 1749 events (the default).
1746 \value RightOnHold the stylus generates RightButton events 1750 \value RightOnHold the stylus generates RightButton events
1747 if the user uses the press-and-hold gesture. 1751 if the user uses the press-and-hold gesture.
1748 1752
1749 \sa setStylusOperation() stylusOperation() 1753 \sa setStylusOperation() stylusOperation()
1750*/ 1754*/
1751 1755
1752/*! 1756/*!
1753 Causes widget \a w to receive mouse events according to the stylus 1757 Causes widget \a w to receive mouse events according to the stylus
1754 \a mode. 1758 \a mode.
1755 1759
1756 \sa stylusOperation() StylusMode 1760 \sa stylusOperation() StylusMode
1757*/ 1761*/
1758void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1762void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1759{ 1763{
1760 createDict(); 1764 createDict();
1761 if ( mode == LeftOnly ) { 1765 if ( mode == LeftOnly ) {
1762 stylusDict->remove 1766 stylusDict->remove
1763 ( w ); 1767 ( w );
1764 w->removeEventFilter( qApp ); 1768 w->removeEventFilter( qApp );
1765 } 1769 }
1766 else { 1770 else {
1767 stylusDict->insert( w, ( void* ) mode ); 1771 stylusDict->insert( w, ( void* ) mode );
1768 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 1772 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
1769 w->installEventFilter( qApp ); 1773 w->installEventFilter( qApp );
1770 } 1774 }
1771} 1775}
1772 1776
1773 1777
1774/*! 1778/*!
1775 \reimp 1779 \reimp
1776*/ 1780*/
1777bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1781bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1778{ 1782{
1783 if ( !o->isWidgetType() )
1784 return FALSE;
1785
1779 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1786 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1780 QMouseEvent * me = ( QMouseEvent* ) e; 1787 QMouseEvent * me = ( QMouseEvent* ) e;
1781 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 1788 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1782 switch (mode) { 1789 switch (mode) {
1783 case RightOnHold: 1790 case RightOnHold:
1784 switch ( me->type() ) { 1791 switch ( me->type() ) {
1785 case QEvent::MouseButtonPress: 1792 case QEvent::MouseButtonPress:
1786 if ( me->button() == LeftButton ) { 1793 if ( me->button() == LeftButton ) {
1787 d->presstimer = startTimer(500); // #### pref. 1794 if (!d->presstimer )
1795 d->presstimer = startTimer(500); // #### pref.
1788 d->presswidget = (QWidget*)o; 1796 d->presswidget = (QWidget*)o;
1789 d->presspos = me->pos(); 1797 d->presspos = me->pos();
1790 d->rightpressed = FALSE; 1798 d->rightpressed = FALSE;
1791 } 1799 }
1792 break; 1800 break;
1793 case QEvent::MouseMove: 1801 case QEvent::MouseMove:
1794 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 1802 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
1795 killTimer(d->presstimer); 1803 killTimer(d->presstimer);
1796 d->presstimer = 0; 1804 d->presstimer = 0;
1797 } 1805 }
1798 break; 1806 break;
1799 case QEvent::MouseButtonRelease: 1807 case QEvent::MouseButtonRelease:
1800 if ( me->button() == LeftButton ) { 1808 if ( me->button() == LeftButton ) {
1801 if ( d->presstimer ) { 1809 if ( d->presstimer ) {
1802 killTimer(d->presstimer); 1810 killTimer(d->presstimer);
1803 d->presstimer = 0; 1811 d->presstimer = 0;
1804 } 1812 }
1805 if ( d->rightpressed && d->presswidget ) { 1813 if ( d->rightpressed && d->presswidget ) {
1806 // Right released 1814 // Right released
1807 postEvent( d->presswidget, 1815 postEvent( d->presswidget,
1808 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 1816 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1809 RightButton, LeftButton + RightButton ) ); 1817 RightButton, LeftButton + RightButton ) );
1810 // Left released, off-widget 1818 // Left released, off-widget
1811 postEvent( d->presswidget, 1819 postEvent( d->presswidget,
1812 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 1820 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
1813 LeftButton, LeftButton ) ); 1821 LeftButton, LeftButton ) );
1814 postEvent( d->presswidget, 1822 postEvent( d->presswidget,
1815 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 1823 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
1816 LeftButton, LeftButton ) ); 1824 LeftButton, LeftButton ) );
1817 d->rightpressed = FALSE; 1825 d->rightpressed = FALSE;
1818 return TRUE; // don't send the real Left release 1826 return TRUE; // don't send the real Left release
1819 } 1827 }
1820 } 1828 }
1821 break; 1829 break;
1822 default: 1830 default:
1823 break; 1831 break;
1824 } 1832 }
1825 break; 1833 break;
1826 default: 1834 default:
1827 ; 1835 ;
1828 } 1836 }
1829 } 1837 }
1830 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1838 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1831 QKeyEvent *ke = (QKeyEvent *)e; 1839 QKeyEvent *ke = (QKeyEvent *)e;
1832 if ( ke->key() == Key_Enter ) { 1840 if ( ke->key() == Key_Enter ) {
1833 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1841 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1834 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1842 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1835 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1843 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
@@ -1859,96 +1867,98 @@ void QPEApplication::timerEvent( QTimerEvent *e )
1859void QPEApplication::removeSenderFromStylusDict() 1867void QPEApplication::removeSenderFromStylusDict()
1860{ 1868{
1861 stylusDict->remove 1869 stylusDict->remove
1862 ( ( void* ) sender() ); 1870 ( ( void* ) sender() );
1863 if ( d->presswidget == sender() ) 1871 if ( d->presswidget == sender() )
1864 d->presswidget = 0; 1872 d->presswidget = 0;
1865} 1873}
1866 1874
1867/*! 1875/*!
1868 \internal 1876 \internal
1869*/ 1877*/
1870bool QPEApplication::keyboardGrabbed() const 1878bool QPEApplication::keyboardGrabbed() const
1871{ 1879{
1872 return d->kbgrabbed; 1880 return d->kbgrabbed;
1873} 1881}
1874 1882
1875 1883
1876/*! 1884/*!
1877 Reverses the effect of grabKeyboard(). This is called automatically 1885 Reverses the effect of grabKeyboard(). This is called automatically
1878 on program exit. 1886 on program exit.
1879*/ 1887*/
1880void QPEApplication::ungrabKeyboard() 1888void QPEApplication::ungrabKeyboard()
1881{ 1889{
1882 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 1890 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
1883} 1891}
1884 1892
1885/*! 1893/*!
1886 Grabs the physical keyboard keys, e.g. the application's launching 1894 Grabs the physical keyboard keys, e.g. the application's launching
1887 keys. Instead of launching applications when these keys are pressed 1895 keys. Instead of launching applications when these keys are pressed
1888 the signals emitted are sent to this application instead. Some games 1896 the signals emitted are sent to this application instead. Some games
1889 programs take over the launch keys in this way to make interaction 1897 programs take over the launch keys in this way to make interaction
1890 easier. 1898 easier.
1891 1899
1892 \sa ungrabKeyboard() 1900 \sa ungrabKeyboard()
1893*/ 1901*/
1894void QPEApplication::grabKeyboard() 1902void QPEApplication::grabKeyboard()
1895{ 1903{
1896 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 1904 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
1897} 1905}
1898 1906
1899/*! 1907/*!
1900 \reimp 1908 \reimp
1901*/ 1909*/
1902int QPEApplication::exec() 1910int QPEApplication::exec()
1903{ 1911{
1904 d->qcopQok = true; 1912 d->qcopQok = true;
1905#ifndef QT_NO_COP 1913#ifndef QT_NO_COP
1906 d->sendQCopQ(); 1914 d->sendQCopQ();
1915 if ( !d->keep_running )
1916 processEvents(); // we may have received QCop messages in the meantime.
1907#endif 1917#endif
1908 1918
1909 if ( d->keep_running ) 1919 if ( d->keep_running )
1910 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1920 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1911 return QApplication::exec(); 1921 return QApplication::exec();
1912 1922
1913#ifndef QT_NO_COP 1923#ifndef QT_NO_COP
1914 1924
1915 { 1925 {
1916 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1926 QCopEnvelope e( "QPE/System", "closing(QString)" );
1917 e << d->appName; 1927 e << d->appName;
1918 } 1928 }
1919#endif 1929#endif
1920 processEvents(); 1930 processEvents();
1921 return 0; 1931 return 0;
1922} 1932}
1923 1933
1924/*! 1934/*!
1925 \internal 1935 \internal
1926 External request for application to quit. Quits if possible without 1936 External request for application to quit. Quits if possible without
1927 loosing state. 1937 loosing state.
1928*/ 1938*/
1929void QPEApplication::tryQuit() 1939void QPEApplication::tryQuit()
1930{ 1940{
1931 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 1941 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1932 return ; // Inside modal loop or konsole. Too hard to save state. 1942 return ; // Inside modal loop or konsole. Too hard to save state.
1933#ifndef QT_NO_COP 1943#ifndef QT_NO_COP
1934 1944
1935 { 1945 {
1936 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1946 QCopEnvelope e( "QPE/System", "closing(QString)" );
1937 e << d->appName; 1947 e << d->appName;
1938 } 1948 }
1939#endif 1949#endif
1940 processEvents(); 1950 processEvents();
1941 1951
1942 quit(); 1952 quit();
1943} 1953}
1944 1954
1945/*! 1955/*!
1946 \internal 1956 \internal
1947*/ 1957*/
1948void QPEApplication::installTranslation( const QString& baseName ) { 1958void QPEApplication::installTranslation( const QString& baseName ) {
1949 QTranslator* trans = new QTranslator(this); 1959 QTranslator* trans = new QTranslator(this);
1950 QString tfn = qpeDir() + "/i18n/"+baseName; 1960 QString tfn = qpeDir() + "/i18n/"+baseName;
1951 if ( trans->load( tfn ) ) 1961 if ( trans->load( tfn ) )
1952 installTranslator( trans ); 1962 installTranslator( trans );
1953 else 1963 else
1954 delete trans; 1964 delete trans;