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