summaryrefslogtreecommitdiff
authorzecke <zecke>2003-08-29 06:52:04 (UTC)
committer zecke <zecke>2003-08-29 06:52:04 (UTC)
commitd8fadaf4f510803983d0b8b99994fd70e770ccab (patch) (unidiff)
tree3921c576b3dbd0dc4fd3ccfe4d39204522bf57a6
parentb9861471966f8bb0e3bea2db58a0d1289add1d4f (diff)
downloadopie-d8fadaf4f510803983d0b8b99994fd70e770ccab.zip
opie-d8fadaf4f510803983d0b8b99994fd70e770ccab.tar.gz
opie-d8fadaf4f510803983d0b8b99994fd70e770ccab.tar.bz2
-IF the app is visible and has more than once topLevel widget
iterate over the list and activate the next one. -Install translation in .qm -Add an else again ( was lost in a merge )
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp142
-rw-r--r--library/qpeapplication.h11
2 files changed, 110 insertions, 43 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 9286f9f..149e6bb 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,1951 +1,2015 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the 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
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19** $Id$ 19*/
20**
21**********************************************************************/
22#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
23#include <stdlib.h> 21#include <stdlib.h>
24#include <unistd.h> 22#include <unistd.h>
25#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 23#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
26#include <qfile.h> 24#include <qfile.h>
27#ifdef Q_WS_QWS 25#ifdef Q_WS_QWS
28#ifndef QT_NO_COP 26#ifndef QT_NO_COP
29#if QT_VERSION <= 231 27#if QT_VERSION <= 231
30#define private public 28#define private public
31#define sendLocally processEvent 29#define sendLocally processEvent
32#include "qcopenvelope_qws.h" 30#include "qcopenvelope_qws.h"
33#undef private 31#undef private
34#else 32#else
35#include "qcopenvelope_qws.h" 33#include "qcopenvelope_qws.h"
36#endif 34#endif
37#endif 35#endif
38#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
39#endif 37#endif
40#include <qtextstream.h> 38#include <qtextstream.h>
41#include <qpalette.h> 39#include <qpalette.h>
42#include <qbuffer.h> 40#include <qbuffer.h>
43#include <qptrdict.h> 41#include <qptrdict.h>
44#include <qregexp.h> 42#include <qregexp.h>
45#include <qdir.h> 43#include <qdir.h>
46#include <qlabel.h> 44#include <qlabel.h>
47#include <qdialog.h> 45#include <qdialog.h>
48#include <qdragobject.h> 46#include <qdragobject.h>
49#include <qtextcodec.h> 47#include <qtextcodec.h>
50#include <qevent.h> 48#include <qevent.h>
51#include <qtooltip.h> 49#include <qtooltip.h>
52#include <qsignal.h> 50#include <qsignal.h>
53#include <qmainwindow.h> 51#include <qmainwindow.h>
52#include <qwidgetlist.h>
54 53
55#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 54#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
56#define QTOPIA_INTERNAL_INITAPP 55#define QTOPIA_INTERNAL_INITAPP
57#include "qpeapplication.h" 56#include "qpeapplication.h"
58#include "qpestyle.h" 57#include "qpestyle.h"
59#include "styleinterface.h" 58#include "styleinterface.h"
60#if QT_VERSION >= 300 59#if QT_VERSION >= 300
61#include <qstylefactory.h> 60#include <qstylefactory.h>
62#else 61#else
63#include <qplatinumstyle.h> 62#include <qplatinumstyle.h>
64#include <qwindowsstyle.h> 63#include <qwindowsstyle.h>
65#include <qmotifstyle.h> 64#include <qmotifstyle.h>
66#include <qmotifplusstyle.h> 65#include <qmotifplusstyle.h>
67#include "lightstyle.h" 66#include "lightstyle.h"
68 67
69#include <qpe/qlibrary.h> 68#include <qpe/qlibrary.h>
70#endif 69#endif
71#include "global.h" 70#include "global.h"
72#include "resource.h" 71#include "resource.h"
73#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 72#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
74#include "qutfcodec.h" 73#include "qutfcodec.h"
75#endif 74#endif
76#include "config.h" 75#include "config.h"
77#include "network.h" 76#include "network.h"
78#ifdef QWS 77#ifdef QWS
79#include "fontmanager.h" 78#include "fontmanager.h"
80#endif 79#endif
81 80
82#include "alarmserver.h" 81#include "alarmserver.h"
83#include "applnk.h" 82#include "applnk.h"
84#include "qpemenubar.h" 83#include "qpemenubar.h"
85#include "textcodecinterface.h" 84#include "textcodecinterface.h"
86#include "imagecodecinterface.h" 85#include "imagecodecinterface.h"
87 86
88#include <unistd.h> 87#include <unistd.h>
89#include <sys/file.h> 88#include <sys/file.h>
90#include <sys/ioctl.h> 89#include <sys/ioctl.h>
91#include <sys/soundcard.h> 90#include <sys/soundcard.h>
92 91
93#include "qt_override_p.h" 92#include "qt_override_p.h"
94 93
95 94
96class QPEApplicationData 95class QPEApplicationData
97{ 96{
98public: 97public:
99 QPEApplicationData ( ) 98 QPEApplicationData ( )
100 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 99 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
101 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 100 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
102 keep_running( true ), qpe_main_widget( 0 ) 101 keep_running( true ), qpe_main_widget( 0 )
103 102
104 { 103 {
105 qcopq.setAutoDelete( TRUE ); 104 qcopq.setAutoDelete( TRUE );
106 } 105 }
107 106
108 int presstimer; 107 int presstimer;
109 QWidget* presswidget; 108 QWidget* presswidget;
110 QPoint presspos; 109 QPoint presspos;
111 110
112 bool rightpressed : 1; 111 bool rightpressed : 1;
113 bool kbgrabbed : 1; 112 bool kbgrabbed : 1;
114 bool notbusysent : 1; 113 bool notbusysent : 1;
115 bool preloaded : 1; 114 bool preloaded : 1;
116 bool forceshow : 1; 115 bool forceshow : 1;
117 bool nomaximize : 1; 116 bool nomaximize : 1;
118 bool keep_running : 1; 117 bool keep_running : 1;
119 118
119 QStringList langs;
120 QString appName; 120 QString appName;
121 struct QCopRec 121 struct QCopRec
122 { 122 {
123 QCopRec( const QCString &ch, const QCString &msg, 123 QCopRec( const QCString &ch, const QCString &msg,
124 const QByteArray &d ) : 124 const QByteArray &d ) :
125 channel( ch ), message( msg ), data( d ) 125 channel( ch ), message( msg ), data( d )
126 { } 126 { }
127 127
128 QCString channel; 128 QCString channel;
129 QCString message; 129 QCString message;
130 QByteArray data; 130 QByteArray data;
131 }; 131 };
132 QWidget* qpe_main_widget; 132 QWidget* qpe_main_widget;
133 QGuardedPtr<QWidget> lastWidget;
133 QList<QCopRec> qcopq; 134 QList<QCopRec> qcopq;
135 QString styleName;
136 QString decorationName;
134 137
135 void enqueueQCop( const QCString &ch, const QCString &msg, 138 void enqueueQCop( const QCString &ch, const QCString &msg,
136 const QByteArray &data ) 139 const QByteArray &data )
137 { 140 {
138 qcopq.append( new QCopRec( ch, msg, data ) ); 141 qcopq.append( new QCopRec( ch, msg, data ) );
139 } 142 }
140 void sendQCopQ() 143 void sendQCopQ()
141 { 144 {
142 QCopRec * r; 145 QCopRec * r;
143#ifndef QT_NO_COP 146#ifndef QT_NO_COP
144 147
145 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it ) 148 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it )
146 QCopChannel::sendLocally( r->channel, r->message, r->data ); 149 QCopChannel::sendLocally( r->channel, r->message, r->data );
147#endif 150#endif
148 151
149 qcopq.clear(); 152 qcopq.clear();
150 } 153 }
151 static void show_mx(QWidget* mw, bool nomaximize) 154 static void show_mx(QWidget* mw, bool nomaximize)
152 { 155 {
153 156
154 // ugly hack, remove that later after finding a sane solution 157 // ugly hack, remove that later after finding a sane solution
155 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 158 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
156 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has 159 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
157 // a (physically) large enough display to use the small icons 160 // a (physically) large enough display to use the small icons
158#ifndef QT_QWS_SIMPAD 161#ifndef QT_QWS_SIMPAD
159 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 162 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
160 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 163 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
161 } 164 }
162#endif 165#endif
163 166
164 if ( mw->layout() && mw->inherits("QDialog") ) { 167 if ( mw->layout() && mw->inherits("QDialog") ) {
165 QPEApplication::showDialog((QDialog*)mw, nomaximize); 168 QPEApplication::showDialog((QDialog*)mw, nomaximize);
166 } 169 }
167 else { 170 else {
168#ifdef Q_WS_QWS 171#ifdef Q_WS_QWS
169 if ( !nomaximize ) 172 if ( !nomaximize )
170 mw->showMaximized(); 173 mw->showMaximized();
171 else 174 else
172#endif 175#endif
173 176
174 mw->show(); 177 mw->show();
175 } 178 }
176 } 179 }
177 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 180 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
178 { 181 {
179 /* 182 /*
180 // This works but disable it for now until it is safe to apply 183 // This works but disable it for now until it is safe to apply
181 // What is does is scan the .desktop files of all the apps for 184 // What is does is scan the .desktop files of all the apps for
182 // the applnk that has the corresponding argv[0] as this program 185 // the applnk that has the corresponding argv[0] as this program
183 // then it uses the name stored in the .desktop file as the caption 186 // then it uses the name stored in the .desktop file as the caption
184 // for the main widget. This saves duplicating translations for 187 // for the main widget. This saves duplicating translations for
185 // the app name in the program and in the .desktop files. 188 // the app name in the program and in the .desktop files.
186 189
187 AppLnkSet apps( appsPath ); 190 AppLnkSet apps( appsPath );
188 191
189 QList<AppLnk> appsList = apps.children(); 192 QList<AppLnk> appsList = apps.children();
190 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 193 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
191 if ( (*it)->exec() == appName ) { 194 if ( (*it)->exec() == appName ) {
192 mw->setCaption( (*it)->name() ); 195 mw->setCaption( (*it)->name() );
193 return TRUE; 196 return TRUE;
194 } 197 }
195 } 198 }
196 */ 199 */
197 return FALSE; 200 return FALSE;
198 } 201 }
199 202
200 203
201 void show(QWidget* mw, bool nomax) 204 void show(QWidget* mw, bool nomax)
202 { 205 {
203 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 206 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
204 nomaximize = nomax; 207 nomaximize = nomax;
205 qpe_main_widget = mw; 208 qpe_main_widget = mw;
206#ifndef QT_NO_COP 209#ifndef QT_NO_COP
207 210
208 sendQCopQ(); 211 sendQCopQ();
209#endif 212#endif
210 213
211 if ( preloaded ) { 214 if ( preloaded ) {
212 if (forceshow) 215 if (forceshow)
213 show_mx(mw, nomax); 216 show_mx(mw, nomax);
214 } 217 }
215 else if ( keep_running ) { 218 else if ( keep_running ) {
216 show_mx(mw, nomax); 219 show_mx(mw, nomax);
217 } 220 }
218 } 221 }
219 222
220 void loadTextCodecs() 223 void loadTextCodecs()
221 { 224 {
222 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 225 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
223 QDir dir( path, "lib*.so" ); 226 QDir dir( path, "lib*.so" );
224 QStringList list; 227 QStringList list;
225 if ( dir. exists ( )) 228 if ( dir. exists ( ))
226 list = dir.entryList(); 229 list = dir.entryList();
227 QStringList::Iterator it; 230 QStringList::Iterator it;
228 for ( it = list.begin(); it != list.end(); ++it ) { 231 for ( it = list.begin(); it != list.end(); ++it ) {
229 TextCodecInterface *iface = 0; 232 TextCodecInterface *iface = 0;
230 QLibrary *lib = new QLibrary( path + "/" + *it ); 233 QLibrary *lib = new QLibrary( path + "/" + *it );
231 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 234 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
232 QValueList<int> mibs = iface->mibEnums(); 235 QValueList<int> mibs = iface->mibEnums();
233 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 236 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
234 (void)iface->createForMib(*i); 237 (void)iface->createForMib(*i);
235 // ### it exists now; need to remember if we can delete it 238 // ### it exists now; need to remember if we can delete it
236 } 239 }
237 } 240 }
238 else { 241 else {
239 lib->unload(); 242 lib->unload();
240 delete lib; 243 delete lib;
241 } 244 }
242 } 245 }
243 } 246 }
244 247
245 void loadImageCodecs() 248 void loadImageCodecs()
246 { 249 {
247 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 250 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
248 QDir dir( path, "lib*.so" ); 251 QDir dir( path, "lib*.so" );
249 QStringList list; 252 QStringList list;
250 if ( dir. exists ( )) 253 if ( dir. exists ( ))
251 list = dir.entryList(); 254 list = dir.entryList();
252 QStringList::Iterator it; 255 QStringList::Iterator it;
253 for ( it = list.begin(); it != list.end(); ++it ) { 256 for ( it = list.begin(); it != list.end(); ++it ) {
254 ImageCodecInterface *iface = 0; 257 ImageCodecInterface *iface = 0;
255 QLibrary *lib = new QLibrary( path + "/" + *it ); 258 QLibrary *lib = new QLibrary( path + "/" + *it );
256 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 259 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
257 QStringList formats = iface->keys(); 260 QStringList formats = iface->keys();
258 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 261 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
259 (void)iface->installIOHandler(*i); 262 (void)iface->installIOHandler(*i);
260 // ### it exists now; need to remember if we can delete it 263 // ### it exists now; need to remember if we can delete it
261 } 264 }
262 } 265 }
263 else { 266 else {
264 lib->unload(); 267 lib->unload();
265 delete lib; 268 delete lib;
266 } 269 }
267 } 270 }
268 } 271 }
269 QString styleName;
270 QString decorationName;
271}; 272};
272 273
273class ResourceMimeFactory : public QMimeSourceFactory 274class ResourceMimeFactory : public QMimeSourceFactory
274{ 275{
275public: 276public:
276 ResourceMimeFactory() : resImage( 0 ) 277 ResourceMimeFactory() : resImage( 0 )
277 { 278 {
278 setFilePath( Global::helpPath() ); 279 setFilePath( Global::helpPath() );
279 setExtensionType( "html", "text/html;charset=UTF-8" ); 280 setExtensionType( "html", "text/html;charset=UTF-8" );
280 } 281 }
281 ~ResourceMimeFactory() { 282 ~ResourceMimeFactory() {
282 delete resImage; 283 delete resImage;
283 } 284 }
284 285
285 const QMimeSource* data( const QString& abs_name ) const 286 const QMimeSource* data( const QString& abs_name ) const
286 { 287 {
287 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 288 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
288 if ( !r ) { 289 if ( !r ) {
289 int sl = abs_name.length(); 290 int sl = abs_name.length();
290 do { 291 do {
291 sl = abs_name.findRev( '/', sl - 1 ); 292 sl = abs_name.findRev( '/', sl - 1 );
292 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 293 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
293 int dot = name.findRev( '.' ); 294 int dot = name.findRev( '.' );
294 if ( dot >= 0 ) 295 if ( dot >= 0 )
295 name = name.left( dot ); 296 name = name.left( dot );
296 QImage img = Resource::loadImage( name ); 297 QImage img = Resource::loadImage( name );
297 if ( !img.isNull() ) { 298 if ( !img.isNull() ) {
298 delete resImage; 299 delete resImage;
299 resImage = new QImageDrag( img ); 300 resImage = new QImageDrag( img );
300 r = resImage; 301 r = resImage;
301 } 302 }
302 } 303 }
303 while ( !r && sl > 0 ); 304 while ( !r && sl > 0 );
304 } 305 }
305 return r; 306 return r;
306 } 307 }
307private: 308private:
308 mutable QImageDrag *resImage; 309 mutable QImageDrag *resImage;
309}; 310};
310 311
311static int& hack(int& i) 312static int& hack(int& i)
312{ 313{
313#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 314#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
314 // These should be created, but aren't in Qt 2.3.0 315 // These should be created, but aren't in Qt 2.3.0
315 (void)new QUtf8Codec; 316 (void)new QUtf8Codec;
316 (void)new QUtf16Codec; 317 (void)new QUtf16Codec;
317#endif 318#endif
318 return i; 319 return i;
319} 320}
320 321
321static int muted = 0; 322static int muted = 0;
322static int micMuted = 0; 323static int micMuted = 0;
323 324
324static void setVolume( int t = 0, int percent = -1 ) 325static void setVolume( int t = 0, int percent = -1 )
325{ 326{
326 switch ( t ) { 327 switch ( t ) {
327 case 0: { 328 case 0: {
328 Config cfg( "qpe" ); 329 Config cfg( "qpe" );
329 cfg.setGroup( "Volume" ); 330 cfg.setGroup( "Volume" );
330 if ( percent < 0 ) 331 if ( percent < 0 )
331 percent = cfg.readNumEntry( "VolumePercent", 50 ); 332 percent = cfg.readNumEntry( "VolumePercent", 50 );
332 int fd = 0; 333 int fd = 0;
333 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 334 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
334 int vol = muted ? 0 : percent; 335 int vol = muted ? 0 : percent;
335 // set both channels to same volume 336 // set both channels to same volume
336 vol |= vol << 8; 337 vol |= vol << 8;
337 ioctl( fd, MIXER_WRITE( 0 ), &vol ); 338 ioctl( fd, MIXER_WRITE( 0 ), &vol );
338 ::close( fd ); 339 ::close( fd );
339 } 340 }
340 } 341 }
341 break; 342 break;
342 } 343 }
343} 344}
344 345
345static void setMic( int t = 0, int percent = -1 ) 346static void setMic( int t = 0, int percent = -1 )
346{ 347{
347 switch ( t ) { 348 switch ( t ) {
348 case 0: { 349 case 0: {
349 Config cfg( "qpe" ); 350 Config cfg( "qpe" );
350 cfg.setGroup( "Volume" ); 351 cfg.setGroup( "Volume" );
351 if ( percent < 0 ) 352 if ( percent < 0 )
352 percent = cfg.readNumEntry( "Mic", 50 ); 353 percent = cfg.readNumEntry( "Mic", 50 );
353 354
354 int fd = 0; 355 int fd = 0;
355 int mic = micMuted ? 0 : percent; 356 int mic = micMuted ? 0 : percent;
356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 357 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
357 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 358 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
358 ::close( fd ); 359 ::close( fd );
359 } 360 }
360 } 361 }
361 break; 362 break;
362 } 363 }
363} 364}
364 365
365 366
366static void setBass( int t = 0, int percent = -1 ) 367static void setBass( int t = 0, int percent = -1 )
367{ 368{
368 switch ( t ) { 369 switch ( t ) {
369 case 0: { 370 case 0: {
370 Config cfg( "qpe" ); 371 Config cfg( "qpe" );
371 cfg.setGroup( "Volume" ); 372 cfg.setGroup( "Volume" );
372 if ( percent < 0 ) 373 if ( percent < 0 )
373 percent = cfg.readNumEntry( "BassPercent", 50 ); 374 percent = cfg.readNumEntry( "BassPercent", 50 );
374 375
375 int fd = 0; 376 int fd = 0;
376 int bass = percent; 377 int bass = percent;
377 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 378 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
378 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 379 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
379 ::close( fd ); 380 ::close( fd );
380 } 381 }
381 } 382 }
382 break; 383 break;
383 } 384 }
384} 385}
385 386
386 387
387static void setTreble( int t = 0, int percent = -1 ) 388static void setTreble( int t = 0, int percent = -1 )
388{ 389{
389 switch ( t ) { 390 switch ( t ) {
390 case 0: { 391 case 0: {
391 Config cfg( "qpe" ); 392 Config cfg( "qpe" );
392 cfg.setGroup( "Volume" ); 393 cfg.setGroup( "Volume" );
393 if ( percent < 0 ) 394 if ( percent < 0 )
394 percent = cfg.readNumEntry( "TreblePercent", 50 ); 395 percent = cfg.readNumEntry( "TreblePercent", 50 );
395 396
396 int fd = 0; 397 int fd = 0;
397 int treble = percent; 398 int treble = percent;
398 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 399 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
399 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 400 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
400 ::close( fd ); 401 ::close( fd );
401 } 402 }
402 } 403 }
403 break; 404 break;
404 } 405 }
405} 406}
406 407
407 408
408/*! 409/*!
409 \class QPEApplication qpeapplication.h 410 \class QPEApplication qpeapplication.h
410 \brief The QPEApplication class implements various system services 411 \brief The QPEApplication class implements various system services
411 that are available to all Qtopia applications. 412 that are available to all Qtopia applications.
412 413
413 Simply by using QPEApplication instead of QApplication, a standard Qt 414 Simply by using QPEApplication instead of QApplication, a standard Qt
414 application becomes a Qtopia application. It automatically follows 415 application becomes a Qtopia application. It automatically follows
415 style changes, quits and raises, and in the 416 style changes, quits and raises, and in the
416 case of \link docwidget.html document-oriented\endlink applications, 417 case of \link docwidget.html document-oriented\endlink applications,
417 changes the currently displayed document in response to the environment. 418 changes the currently displayed document in response to the environment.
418 419
419 To create a \link docwidget.html document-oriented\endlink 420 To create a \link docwidget.html document-oriented\endlink
420 application use showMainDocumentWidget(); to create a 421 application use showMainDocumentWidget(); to create a
421 non-document-oriented application use showMainWidget(). The 422 non-document-oriented application use showMainWidget(). The
422 keepRunning() function indicates whether the application will 423 keepRunning() function indicates whether the application will
423 continue running after it's processed the last \link qcop.html 424 continue running after it's processed the last \link qcop.html
424 QCop\endlink message. This can be changed using setKeepRunning(). 425 QCop\endlink message. This can be changed using setKeepRunning().
425 426
426 A variety of signals are emitted when certain events occur, for 427 A variety of signals are emitted when certain events occur, for
427 example, timeChanged(), clockChanged(), weekChanged(), 428 example, timeChanged(), clockChanged(), weekChanged(),
428 dateFormatChanged() and volumeChanged(). If the application receives 429 dateFormatChanged() and volumeChanged(). If the application receives
429 a \link qcop.html QCop\endlink message on the application's 430 a \link qcop.html QCop\endlink message on the application's
430 QPE/Application/\e{appname} channel, the appMessage() signal is 431 QPE/Application/\e{appname} channel, the appMessage() signal is
431 emitted. There are also flush() and reload() signals, which 432 emitted. There are also flush() and reload() signals, which
432 are emitted when synching begins and ends respectively - upon these 433 are emitted when synching begins and ends respectively - upon these
433 signals, the application should save and reload any data 434 signals, the application should save and reload any data
434 files that are involved in synching. Most of these signals will initially 435 files that are involved in synching. Most of these signals will initially
435 be received and unfiltered through the appMessage() signal. 436 be received and unfiltered through the appMessage() signal.
436 437
437 This class also provides a set of useful static functions. The 438 This class also provides a set of useful static functions. The
438 qpeDir() and documentDir() functions return the respective paths. 439 qpeDir() and documentDir() functions return the respective paths.
439 The grabKeyboard() and ungrabKeyboard() functions are used to 440 The grabKeyboard() and ungrabKeyboard() functions are used to
440 control whether the application takes control of the device's 441 control whether the application takes control of the device's
441 physical buttons (e.g. application launch keys). The stylus' mode of 442 physical buttons (e.g. application launch keys). The stylus' mode of
442 operation is set with setStylusOperation() and retrieved with 443 operation is set with setStylusOperation() and retrieved with
443 stylusOperation(). There are also setInputMethodHint() and 444 stylusOperation(). There are also setInputMethodHint() and
444 inputMethodHint() functions. 445 inputMethodHint() functions.
445 446
446 \ingroup qtopiaemb 447 \ingroup qtopiaemb
447*/ 448*/
448 449
449/*! 450/*!
450 \fn void QPEApplication::clientMoused() 451 \fn void QPEApplication::clientMoused()
451 452
452 \internal 453 \internal
453*/ 454*/
454 455
455/*! 456/*!
456 \fn void QPEApplication::timeChanged(); 457 \fn void QPEApplication::timeChanged();
457 This signal is emitted when the time changes outside the normal 458 This signal is emitted when the time changes outside the normal
458 passage of time, i.e. if the time is set backwards or forwards. 459 passage of time, i.e. if the time is set backwards or forwards.
459*/ 460*/
460 461
461/*! 462/*!
462 \fn void QPEApplication::clockChanged( bool ampm ); 463 \fn void QPEApplication::clockChanged( bool ampm );
463 464
464 This signal is emitted when the user changes the clock's style. If 465 This signal is emitted when the user changes the clock's style. If
465 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 466 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
466 they want a 24-hour clock. 467 they want a 24-hour clock.
467*/ 468*/
468 469
469/*! 470/*!
470 \fn void QPEApplication::volumeChanged( bool muted ) 471 \fn void QPEApplication::volumeChanged( bool muted )
471 472
472 This signal is emitted whenever the mute state is changed. If \a 473 This signal is emitted whenever the mute state is changed. If \a
473 muted is TRUE, then sound output has been muted. 474 muted is TRUE, then sound output has been muted.
474*/ 475*/
475 476
476/*! 477/*!
477 \fn void QPEApplication::weekChanged( bool startOnMonday ) 478 \fn void QPEApplication::weekChanged( bool startOnMonday )
478 479
479 This signal is emitted if the week start day is changed. If \a 480 This signal is emitted if the week start day is changed. If \a
480 startOnMonday is TRUE then the first day of the week is Monday; if 481 startOnMonday is TRUE then the first day of the week is Monday; if
481 \a startOnMonday is FALSE then the first day of the week is 482 \a startOnMonday is FALSE then the first day of the week is
482 Sunday. 483 Sunday.
483*/ 484*/
484 485
485/*! 486/*!
486 \fn void QPEApplication::dateFormatChanged(DateFormat) 487 \fn void QPEApplication::dateFormatChanged(DateFormat)
487 488
488 This signal is emitted whenever the date format is changed. 489 This signal is emitted whenever the date format is changed.
489*/ 490*/
490 491
491/*! 492/*!
492 \fn void QPEApplication::flush() 493 \fn void QPEApplication::flush()
493 494
494 ### 495 ###
495*/ 496*/
496 497
497/*! 498/*!
498 \fn void QPEApplication::reload() 499 \fn void QPEApplication::reload()
499 500
500*/ 501*/
501 502
502 503
503 504
504void QPEApplication::processQCopFile() 505void QPEApplication::processQCopFile()
505{ 506{
506 QString qcopfn("/tmp/qcop-msg-"); 507 QString qcopfn("/tmp/qcop-msg-");
507 qcopfn += d->appName; // append command name 508 qcopfn += d->appName; // append command name
508 509
509 QFile f(qcopfn); 510 QFile f(qcopfn);
510 if ( f.open(IO_ReadWrite) ) { 511 if ( f.open(IO_ReadWrite) ) {
511#ifndef Q_OS_WIN32 512#ifndef Q_OS_WIN32
512 flock(f.handle(), LOCK_EX); 513 flock(f.handle(), LOCK_EX);
513#endif 514#endif
514 QDataStream ds(&f); 515 QDataStream ds(&f);
515 QCString channel, message; 516 QCString channel, message;
516 QByteArray data; 517 QByteArray data;
517 while(!ds.atEnd()) { 518 while(!ds.atEnd()) {
518 ds >> channel >> message >> data; 519 ds >> channel >> message >> data;
519 d->enqueueQCop(channel,message,data); 520 d->enqueueQCop(channel,message,data);
520 } 521 }
521 ::ftruncate(f.handle(), 0); 522 ::ftruncate(f.handle(), 0);
522#ifndef Q_OS_WIN32 523#ifndef Q_OS_WIN32
523 f.flush(); 524 f.flush();
524 flock(f.handle(), LOCK_UN); 525 flock(f.handle(), LOCK_UN);
525#endif 526#endif
526 } 527 }
527#endif 528#endif
528} 529}
529 530
530 531
531/*! 532/*!
532 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 533 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
533 534
534 This signal is emitted when a message is received on this 535 This signal is emitted when a message is received on this
535 application's QPE/Application/<i>appname</i> \link qcop.html 536 application's QPE/Application/<i>appname</i> \link qcop.html
536 QCop\endlink channel. 537 QCop\endlink channel.
537 538
538 The slot to which you connect this signal uses \a msg and \a data 539 The slot to which you connect this signal uses \a msg and \a data
539 in the following way: 540 in the following way:
540 541
541\code 542\code
542 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 543 void MyWidget::receive( const QCString& msg, const QByteArray& data )
543 { 544 {
544 QDataStream stream( data, IO_ReadOnly ); 545 QDataStream stream( data, IO_ReadOnly );
545 if ( msg == "someMessage(int,int,int)" ) { 546 if ( msg == "someMessage(int,int,int)" ) {
546 int a,b,c; 547 int a,b,c;
547 stream >> a >> b >> c; 548 stream >> a >> b >> c;
548 ... 549 ...
549 } else if ( msg == "otherMessage(QString)" ) { 550 } else if ( msg == "otherMessage(QString)" ) {
550 ... 551 ...
551 } 552 }
552 } 553 }
553\endcode 554\endcode
554 555
555 \sa qcop.html 556 \sa qcop.html
556 Note that messages received here may be processed by qpe application 557 Note that messages received here may be processed by qpe application
557 and emitted as signals, such as flush() and reload(). 558 and emitted as signals, such as flush() and reload().
558*/ 559*/
559 560
560/*! 561/*!
561 Constructs a QPEApplication just as you would construct 562 Constructs a QPEApplication just as you would construct
562 a QApplication, passing \a argc, \a argv, and \a t. 563 a QApplication, passing \a argc, \a argv, and \a t.
563 564
564 For applications, \a t should be the default, GuiClient. Only 565 For applications, \a t should be the default, GuiClient. Only
565 the Qtopia server passes GuiServer. 566 the Qtopia server passes GuiServer.
566*/ 567*/
567QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 568QPEApplication::QPEApplication( int & argc, char **argv, Type t )
568 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 569 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
569{ 570{
570 d = new QPEApplicationData; 571 d = new QPEApplicationData;
571 d->loadTextCodecs(); 572 d->loadTextCodecs();
572 d->loadImageCodecs(); 573 d->loadImageCodecs();
573 int dw = desktop() ->width(); 574 int dw = desktop() ->width();
574 575
575 if ( dw < 200 ) { 576 if ( dw < 200 ) {
576 setFont( QFont( "vera", 8 ) ); 577 setFont( QFont( "vera", 8 ) );
577 AppLnk::setSmallIconSize( 10 ); 578 AppLnk::setSmallIconSize( 10 );
578 AppLnk::setBigIconSize( 28 ); 579 AppLnk::setBigIconSize( 28 );
579 } 580 }
580#ifndef QT_QWS_SIMPAD 581#ifndef QT_QWS_SIMPAD
581 else if ( dw > 600 ) { 582 else if ( dw > 600 ) {
582 setFont( QFont( "vera", 16 ) ); 583 setFont( QFont( "vera", 16 ) );
583 AppLnk::setSmallIconSize( 24 ); 584 AppLnk::setSmallIconSize( 24 );
584 AppLnk::setBigIconSize( 48 ); 585 AppLnk::setBigIconSize( 48 );
585 } 586 }
586#endif 587#endif
587 else if ( dw > 200 ) { 588 else if ( dw > 200 ) {
588 setFont( QFont( "vera", 10 ) ); 589 setFont( QFont( "vera", 10 ) );
589 AppLnk::setSmallIconSize( 14 ); 590 AppLnk::setSmallIconSize( 14 );
590 AppLnk::setBigIconSize( 32 ); 591 AppLnk::setBigIconSize( 32 );
591 } 592 }
592 593
593 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 594 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
594 595
595 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 596 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
596 597
597 598
598 sysChannel = new QCopChannel( "QPE/System", this ); 599 sysChannel = new QCopChannel( "QPE/System", this );
599 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 600 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
600 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 601 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
601 602
602/* COde now in initapp */ 603/* COde now in initapp */
603#if 0 604#if 0
604#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 605#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
605 606
606 QString qcopfn( "/tmp/qcop-msg-" ); 607 QString qcopfn( "/tmp/qcop-msg-" );
607 qcopfn += QString( argv[ 0 ] ); // append command name 608 qcopfn += QString( argv[ 0 ] ); // append command name
608 609
609 QFile f( qcopfn ); 610 QFile f( qcopfn );
610 if ( f.open( IO_ReadOnly ) ) { 611 if ( f.open( IO_ReadOnly ) ) {
611 flock( f.handle(), LOCK_EX ); 612 flock( f.handle(), LOCK_EX );
612 } 613 }
613 614
614 615
615 616
616 QCString channel = QCString( argv[ 0 ] ); 617 QCString channel = QCString( argv[ 0 ] );
617 channel.replace( QRegExp( ".*/" ), "" ); 618 channel.replace( QRegExp( ".*/" ), "" );
618 d->appName = channel; 619 d->appName = channel;
619 channel = "QPE/Application/" + channel; 620 channel = "QPE/Application/" + channel;
620 pidChannel = new QCopChannel( channel, this ); 621 pidChannel = new QCopChannel( channel, this );
621 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 622 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
622 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); 623 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
623 624
624 if ( f.isOpen() ) { 625 if ( f.isOpen() ) {
625 d->keep_running = FALSE; 626 d->keep_running = FALSE;
626 QDataStream ds( &f ); 627 QDataStream ds( &f );
627 QCString channel, message; 628 QCString channel, message;
628 QByteArray data; 629 QByteArray data;
629 while ( !ds.atEnd() ) { 630 while ( !ds.atEnd() ) {
630 ds >> channel >> message >> data; 631 ds >> channel >> message >> data;
631 d->enqueueQCop( channel, message, data ); 632 d->enqueueQCop( channel, message, data );
632 } 633 }
633 634
634 flock( f.handle(), LOCK_UN ); 635 flock( f.handle(), LOCK_UN );
635 f.close(); 636 f.close();
636 f.remove(); 637 f.remove();
637 } 638 }
638 639
639 for ( int a = 0; a < argc; a++ ) { 640 for ( int a = 0; a < argc; a++ ) {
640 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 641 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
641 argv[ a ] = argv[ a + 1 ]; 642 argv[ a ] = argv[ a + 1 ];
642 a++; 643 a++;
643 d->preloaded = TRUE; 644 d->preloaded = TRUE;
644 argc -= 1; 645 argc -= 1;
645 } 646 }
646 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 647 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
647 argv[ a ] = argv[ a + 1 ]; 648 argv[ a ] = argv[ a + 1 ];
648 a++; 649 a++;
649 d->preloaded = TRUE; 650 d->preloaded = TRUE;
650 d->forceshow = TRUE; 651 d->forceshow = TRUE;
651 argc -= 1; 652 argc -= 1;
652 } 653 }
653 } 654 }
654 655
655 /* overide stored arguments */ 656 /* overide stored arguments */
656 setArgs( argc, argv ); 657 setArgs( argc, argv );
657 658
658#endif 659#endif
659#else 660#else
660 initApp( argc, argv ); 661 initApp( argc, argv );
661#endif 662#endif
662 // qwsSetDecoration( new QPEDecoration() ); 663 // qwsSetDecoration( new QPEDecoration() );
663 664
664#ifndef QT_NO_TRANSLATION 665#ifndef QT_NO_TRANSLATION
665 666
666 QStringList langs = Global::languageList(); 667 d->langs = Global::languageList();
667 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { 668 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
668 QString lang = *it; 669 QString lang = *it;
669 670
670 installTranslation( lang + "/libopie.qm"); 671 installTranslation( lang + "/libopie.qm");
671 installTranslation( lang + "/libqpe.qm" ); 672 installTranslation( lang + "/libqpe.qm" );
672 installTranslation( lang + "/" + d->appName + ".qm" ); 673 installTranslation( lang + "/" + d->appName + ".qm" );
673 674
674 675
675 //###language/font hack; should look it up somewhere 676 //###language/font hack; should look it up somewhere
676#ifdef QWS 677#ifdef QWS
677 678
678 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 679 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
679 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 680 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
680 setFont( fn ); 681 setFont( fn );
681 } 682 }
682#endif 683#endif
683 } 684 }
684#endif 685#endif
685 686
686 applyStyle(); 687 applyStyle();
687 688
688 if ( type() == GuiServer ) { 689 if ( type() == GuiServer ) {
689 setVolume(); 690 setVolume();
690 } 691 }
691 692
692 installEventFilter( this ); 693 installEventFilter( this );
693 694
694 QPEMenuToolFocusManager::initialize(); 695 QPEMenuToolFocusManager::initialize();
695 696
696#ifdef QT_NO_QWS_CURSOR 697#ifdef QT_NO_QWS_CURSOR
697 // if we have no cursor, probably don't want tooltips 698 // if we have no cursor, probably don't want tooltips
698 QToolTip::setEnabled( FALSE ); 699 QToolTip::setEnabled( FALSE );
699#endif 700#endif
700} 701}
701 702
702 703
703#ifdef QTOPIA_INTERNAL_INITAPP 704#ifdef QTOPIA_INTERNAL_INITAPP
704void QPEApplication::initApp( int argc, char **argv ) 705void QPEApplication::initApp( int argc, char **argv )
705{ 706{
706 delete pidChannel; 707 delete pidChannel;
707 d->keep_running = TRUE; 708 d->keep_running = TRUE;
708 d->preloaded = FALSE; 709 d->preloaded = FALSE;
709 d->forceshow = FALSE; 710 d->forceshow = FALSE;
710 711
711 QCString channel = QCString(argv[0]); 712 QCString channel = QCString(argv[0]);
712 713
713 channel.replace(QRegExp(".*/"),""); 714 channel.replace(QRegExp(".*/"),"");
714 d->appName = channel; 715 d->appName = channel;
715 716
716 #if QT_VERSION > 235 717 #if QT_VERSION > 235
717 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 718 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
718 #endif 719 #endif
719 720
720 channel = "QPE/Application/" + channel; 721 channel = "QPE/Application/" + channel;
721 pidChannel = new QCopChannel( channel, this); 722 pidChannel = new QCopChannel( channel, this);
722 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 723 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
723 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 724 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
724 725
725 processQCopFile(); 726 processQCopFile();
726 d->keep_running = d->qcopq.isEmpty(); 727 d->keep_running = d->qcopq.isEmpty();
727 728
728 for (int a=0; a<argc; a++) { 729 for (int a=0; a<argc; a++) {
729 if ( qstrcmp(argv[a],"-preload")==0 ) { 730 if ( qstrcmp(argv[a],"-preload")==0 ) {
730 argv[a] = argv[a+1]; 731 argv[a] = argv[a+1];
731 a++; 732 a++;
732 d->preloaded = TRUE; 733 d->preloaded = TRUE;
733 argc-=1; 734 argc-=1;
734 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 735 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
735 argv[a] = argv[a+1]; 736 argv[a] = argv[a+1];
736 a++; 737 a++;
737 d->preloaded = TRUE; 738 d->preloaded = TRUE;
738 d->forceshow = TRUE; 739 d->forceshow = TRUE;
739 argc-=1; 740 argc-=1;
740 } 741 }
741 } 742 }
742 743
743 /* overide stored arguments */ 744 /* overide stored arguments */
744 setArgs(argc, argv); 745 setArgs(argc, argv);
746
747 /* install translation here */
748 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
749 installTranslation( (*it) + "/" + d->appName + ".qm" );
745} 750}
746#endif 751#endif
747 752
748 753
749static QPtrDict<void>* inputMethodDict = 0; 754static QPtrDict<void>* inputMethodDict = 0;
750static void createInputMethodDict() 755static void createInputMethodDict()
751{ 756{
752 if ( !inputMethodDict ) 757 if ( !inputMethodDict )
753 inputMethodDict = new QPtrDict<void>; 758 inputMethodDict = new QPtrDict<void>;
754} 759}
755 760
756/*! 761/*!
757 Returns the currently set hint to the system as to whether 762 Returns the currently set hint to the system as to whether
758 widget \a w has any use for text input methods. 763 widget \a w has any use for text input methods.
759 764
760 765
761 \sa setInputMethodHint() InputMethodHint 766 \sa setInputMethodHint() InputMethodHint
762*/ 767*/
763QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 768QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
764{ 769{
765 if ( inputMethodDict && w ) 770 if ( inputMethodDict && w )
766 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 771 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
767 return Normal; 772 return Normal;
768} 773}
769 774
770/*! 775/*!
771 \enum QPEApplication::InputMethodHint 776 \enum QPEApplication::InputMethodHint
772 777
773 \value Normal the application sometimes needs text input (the default). 778 \value Normal the application sometimes needs text input (the default).
774 \value AlwaysOff the application never needs text input. 779 \value AlwaysOff the application never needs text input.
775 \value AlwaysOn the application always needs text input. 780 \value AlwaysOn the application always needs text input.
776*/ 781*/
777 782
778/*! 783/*!
779 Hints to the system that widget \a w has use for text input methods 784 Hints to the system that widget \a w has use for text input methods
780 as specified by \a mode. 785 as specified by \a mode.
781 786
782 \sa inputMethodHint() InputMethodHint 787 \sa inputMethodHint() InputMethodHint
783*/ 788*/
784void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 789void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
785{ 790{
786 createInputMethodDict(); 791 createInputMethodDict();
787 if ( mode == Normal ) { 792 if ( mode == Normal ) {
788 inputMethodDict->remove 793 inputMethodDict->remove
789 ( w ); 794 ( w );
790 } 795 }
791 else { 796 else {
792 inputMethodDict->insert( w, ( void* ) mode ); 797 inputMethodDict->insert( w, ( void* ) mode );
793 } 798 }
794} 799}
795 800
796class HackDialog : public QDialog 801class HackDialog : public QDialog
797{ 802{
798public: 803public:
799 void acceptIt() 804 void acceptIt()
800 { 805 {
801 accept(); 806 accept();
802 } 807 }
803 void rejectIt() 808 void rejectIt()
804 { 809 {
805 reject(); 810 reject();
806 } 811 }
807}; 812};
808 813
809 814
810void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 815void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
811{ 816{
812 // specialised actions for certain widgets. May want to 817 // specialised actions for certain widgets. May want to
813 // add more stuff here. 818 // add more stuff here.
814 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 819 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
815 && activePopupWidget() ->parentWidget() 820 && activePopupWidget() ->parentWidget()
816 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 821 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
817 key = Qt::Key_Return; 822 key = Qt::Key_Return;
818 823
819 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 824 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
820 key = Qt::Key_Return; 825 key = Qt::Key_Return;
821 826
822#ifdef QWS 827#ifdef QWS
823 828
824 ke->simpleData.keycode = key; 829 ke->simpleData.keycode = key;
825#endif 830#endif
826} 831}
827 832
828class HackWidget : public QWidget 833class HackWidget : public QWidget
829{ 834{
830public: 835public:
831 bool needsOk() 836 bool needsOk()
832 { 837 {
833 return ( getWState() & WState_Reserved1 ); 838 return ( getWState() & WState_Reserved1 );
834 } 839 }
835}; 840};
836 841
837/*! 842/*!
838 \internal 843 \internal
839*/ 844*/
840 845
841#ifdef QWS 846#ifdef QWS
842bool QPEApplication::qwsEventFilter( QWSEvent * e ) 847bool QPEApplication::qwsEventFilter( QWSEvent * e )
843{ 848{
844 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 849 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
845 if ( qApp->type() != QApplication::GuiServer ) { 850 if ( qApp->type() != QApplication::GuiServer ) {
846 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 851 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
847 e << d->appName; 852 e << d->appName;
848 } 853 }
849 d->notbusysent = TRUE; 854 d->notbusysent = TRUE;
850 } 855 }
851 if ( type() == GuiServer ) { 856 if ( type() == GuiServer ) {
852 switch ( e->type ) { 857 switch ( e->type ) {
853 case QWSEvent::Mouse: 858 case QWSEvent::Mouse:
854 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 859 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
855 emit clientMoused(); 860 emit clientMoused();
856 break; 861 break;
857 default: 862 default:
858 break; 863 break;
859 } 864 }
860 } 865 }
861 if ( e->type == QWSEvent::Key ) { 866 if ( e->type == QWSEvent::Key ) {
862 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 867 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
863 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 868 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
864 // Use special "OK" key to press "OK" on top level widgets 869 // Use special "OK" key to press "OK" on top level widgets
865 QWidget * active = activeWindow(); 870 QWidget * active = activeWindow();
866 QWidget *popup = 0; 871 QWidget *popup = 0;
867 if ( active && active->isPopup() ) { 872 if ( active && active->isPopup() ) {
868 popup = active; 873 popup = active;
869 active = active->parentWidget(); 874 active = active->parentWidget();
870 } 875 }
871 if ( active && ( int ) active->winId() == ke->simpleData.window && 876 if ( active && ( int ) active->winId() == ke->simpleData.window &&
872 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 877 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
873 if ( ke->simpleData.is_press ) { 878 if ( ke->simpleData.is_press ) {
874 if ( popup ) 879 if ( popup )
875 popup->close(); 880 popup->close();
876 if ( active->inherits( "QDialog" ) ) { 881 if ( active->inherits( "QDialog" ) ) {
877 HackDialog * d = ( HackDialog * ) active; 882 HackDialog * d = ( HackDialog * ) active;
878 d->acceptIt(); 883 d->acceptIt();
879 return TRUE; 884 return TRUE;
880 } 885 }
881 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 886 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
882 QSignal s; 887 QSignal s;
883 s.connect( active, SLOT( accept() ) ); 888 s.connect( active, SLOT( accept() ) );
884 s.activate(); 889 s.activate();
885 } 890 }
886 else { 891 else {
887 // do the same as with the select key: Map to the default action of the widget: 892 // do the same as with the select key: Map to the default action of the widget:
888 mapToDefaultAction( ke, Qt::Key_Return ); 893 mapToDefaultAction( ke, Qt::Key_Return );
889 } 894 }
890 } 895 }
891 } 896 }
892 } 897 }
893 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 898 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
894 // Use special "select" key to do whatever default action a widget has 899 // Use special "select" key to do whatever default action a widget has
895 mapToDefaultAction( ke, Qt::Key_Space ); 900 mapToDefaultAction( ke, Qt::Key_Space );
896 } 901 }
897 else if ( ke->simpleData.keycode == Qt::Key_Escape && 902 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
898 ke->simpleData.is_press ) { 903 ke->simpleData.is_press ) {
899 // Escape key closes app if focus on toplevel 904 // Escape key closes app if focus on toplevel
900 QWidget * active = activeWindow(); 905 QWidget * active = activeWindow();
901 if ( active && active->testWFlags( WType_TopLevel ) && 906 if ( active && active->testWFlags( WType_TopLevel ) &&
902 ( int ) active->winId() == ke->simpleData.window && 907 ( int ) active->winId() == ke->simpleData.window &&
903 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 908 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
904 if ( active->inherits( "QDialog" ) ) { 909 if ( active->inherits( "QDialog" ) ) {
905 HackDialog * d = ( HackDialog * ) active; 910 HackDialog * d = ( HackDialog * ) active;
906 d->rejectIt(); 911 d->rejectIt();
907 return TRUE; 912 return TRUE;
908 } 913 }
909 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 914 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
910 active->close(); 915 active->close();
911 } 916 }
912 } 917 }
913 } 918 }
914 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 919 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
915 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 920 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
916 // but we cannot access libopie function within libqpe :( 921 // but we cannot access libopie function within libqpe :(
917 922
918 QWidget * active = activeWindow ( ); 923 QWidget * active = activeWindow ( );
919 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 924 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
920 if ( d-> kbgrabbed ) { // we grabbed the keyboard 925 if ( d-> kbgrabbed ) { // we grabbed the keyboard
921 QChar ch ( ke-> simpleData.unicode ); 926 QChar ch ( ke-> simpleData.unicode );
922 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 927 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
923 ke-> simpleData.keycode, 928 ke-> simpleData.keycode,
924 ch. latin1 ( ), 929 ch. latin1 ( ),
925 ke-> simpleData.modifiers, 930 ke-> simpleData.modifiers,
926 QString ( ch ), 931 QString ( ch ),
927 ke-> simpleData.is_auto_repeat, 1 ); 932 ke-> simpleData.is_auto_repeat, 1 );
928 933
929 QObject *which = QWidget::keyboardGrabber ( ); 934 QObject *which = QWidget::keyboardGrabber ( );
930 if ( !which ) 935 if ( !which )
931 which = QApplication::focusWidget ( ); 936 which = QApplication::focusWidget ( );
932 if ( !which ) 937 if ( !which )
933 which = QApplication::activeWindow ( ); 938 which = QApplication::activeWindow ( );
934 if ( !which ) 939 if ( !which )
935 which = qApp; 940 which = qApp;
936 941
937 QApplication::sendEvent ( which, &qke ); 942 QApplication::sendEvent ( which, &qke );
938 } 943 }
939 else { // we didn't grab the keyboard, so send the event to the launcher 944 else { // we didn't grab the keyboard, so send the event to the launcher
940 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 945 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
941 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 946 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
942 } 947 }
943 } 948 }
944 return true; 949 return true;
945 } 950 }
946 } 951 }
947 if ( e->type == QWSEvent::Focus ) { 952 if ( e->type == QWSEvent::Focus ) {
948 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 953 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
949 if ( !fe->simpleData.get_focus ) { 954 if ( !fe->simpleData.get_focus ) {
950 QWidget * active = activeWindow(); 955 QWidget * active = activeWindow();
951 while ( active && active->isPopup() ) { 956 while ( active && active->isPopup() ) {
952 active->close(); 957 active->close();
953 active = activeWindow(); 958 active = activeWindow();
954 } 959 }
955 } 960 }
956 else { 961 else {
957 // make sure our modal widget is ALWAYS on top 962 // make sure our modal widget is ALWAYS on top
958 QWidget *topm = activeModalWidget(); 963 QWidget *topm = activeModalWidget();
959 if ( topm ) { 964 if ( topm ) {
960 topm->raise(); 965 topm->raise();
961 } 966 }
962 } 967 }
963 if ( fe->simpleData.get_focus && inputMethodDict ) { 968 if ( fe->simpleData.get_focus && inputMethodDict ) {
964 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 969 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
965 if ( m == AlwaysOff ) 970 if ( m == AlwaysOff )
966 Global::hideInputMethod(); 971 Global::hideInputMethod();
967 if ( m == AlwaysOn ) 972 if ( m == AlwaysOn )
968 Global::showInputMethod(); 973 Global::showInputMethod();
969 } 974 }
970 } 975 }
971 976
972 977
973 return QApplication::qwsEventFilter( e ); 978 return QApplication::qwsEventFilter( e );
974} 979}
975#endif 980#endif
976 981
977/*! 982/*!
978 Destroys the QPEApplication. 983 Destroys the QPEApplication.
979*/ 984*/
980QPEApplication::~QPEApplication() 985QPEApplication::~QPEApplication()
981{ 986{
982 ungrabKeyboard(); 987 ungrabKeyboard();
983#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 988#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
984 // Need to delete QCopChannels early, since the display will 989 // Need to delete QCopChannels early, since the display will
985 // be gone by the time we get to ~QObject(). 990 // be gone by the time we get to ~QObject().
986 delete sysChannel; 991 delete sysChannel;
987 delete pidChannel; 992 delete pidChannel;
988#endif 993#endif
989 994
990 delete d; 995 delete d;
991} 996}
992 997
993/*! 998/*!
994 Returns <tt>$OPIEDIR/</tt>. 999 Returns <tt>$OPIEDIR/</tt>.
995*/ 1000*/
996QString QPEApplication::qpeDir() 1001QString QPEApplication::qpeDir()
997{ 1002{
998 const char * base = getenv( "OPIEDIR" ); 1003 const char * base = getenv( "OPIEDIR" );
999 if ( base ) 1004 if ( base )
1000 return QString( base ) + "/"; 1005 return QString( base ) + "/";
1001 1006
1002 return QString( "../" ); 1007 return QString( "../" );
1003} 1008}
1004 1009
1005/*! 1010/*!
1006 Returns the user's current Document directory. There is a trailing "/". 1011 Returns the user's current Document directory. There is a trailing "/".
1007 .. well, it does now,, and there's no trailing '/' 1012 .. well, it does now,, and there's no trailing '/'
1008*/ 1013*/
1009QString QPEApplication::documentDir() 1014QString QPEApplication::documentDir()
1010{ 1015{
1011 const char* base = getenv( "HOME"); 1016 const char* base = getenv( "HOME");
1012 if ( base ) 1017 if ( base )
1013 return QString( base ) + "/Documents"; 1018 return QString( base ) + "/Documents";
1014 1019
1015 return QString( "../Documents" ); 1020 return QString( "../Documents" );
1016} 1021}
1017 1022
1018static int deforient = -1; 1023static int deforient = -1;
1019 1024
1020/*! 1025/*!
1021 \internal 1026 \internal
1022*/ 1027*/
1023int QPEApplication::defaultRotation() 1028int QPEApplication::defaultRotation()
1024{ 1029{
1025 if ( deforient < 0 ) { 1030 if ( deforient < 0 ) {
1026 QString d = getenv( "QWS_DISPLAY" ); 1031 QString d = getenv( "QWS_DISPLAY" );
1027 if ( d.contains( "Rot90" ) ) { 1032 if ( d.contains( "Rot90" ) ) {
1028 deforient = 90; 1033 deforient = 90;
1029 } 1034 }
1030 else if ( d.contains( "Rot180" ) ) { 1035 else if ( d.contains( "Rot180" ) ) {
1031 deforient = 180; 1036 deforient = 180;
1032 } 1037 }
1033 else if ( d.contains( "Rot270" ) ) { 1038 else if ( d.contains( "Rot270" ) ) {
1034 deforient = 270; 1039 deforient = 270;
1035 } 1040 }
1036 else { 1041 else {
1037 deforient = 0; 1042 deforient = 0;
1038 } 1043 }
1039 } 1044 }
1040 return deforient; 1045 return deforient;
1041} 1046}
1042 1047
1043/*! 1048/*!
1044 \internal 1049 \internal
1045*/ 1050*/
1046void QPEApplication::setDefaultRotation( int r ) 1051void QPEApplication::setDefaultRotation( int r )
1047{ 1052{
1048 if ( qApp->type() == GuiServer ) { 1053 if ( qApp->type() == GuiServer ) {
1049 deforient = r; 1054 deforient = r;
1050 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1055 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1051 Config config("qpe"); 1056 Config config("qpe");
1052 config.setGroup( "Rotation" ); 1057 config.setGroup( "Rotation" );
1053 config.writeEntry( "Rot", r ); 1058 config.writeEntry( "Rot", r );
1054 } 1059 }
1055 else { 1060 else {
1056#ifndef QT_NO_COP 1061#ifndef QT_NO_COP
1057 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1062 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1058 e << r; 1063 e << r;
1059 } 1064 }
1060#endif 1065#endif
1061 1066
1062 } 1067 }
1063} 1068}
1064 1069
1065 1070
1066/*! 1071/*!
1067 \internal 1072 \internal
1068*/ 1073*/
1069void QPEApplication::applyStyle() 1074void QPEApplication::applyStyle()
1070{ 1075{
1071 Config config( "qpe" ); 1076 Config config( "qpe" );
1072 config.setGroup( "Appearance" ); 1077 config.setGroup( "Appearance" );
1073 1078
1074 #if QT_VERSION > 233 1079 #if QT_VERSION > 233
1075 // don't block ourselves ... 1080 // don't block ourselves ...
1076 Opie::force_appearance = 0; 1081 Opie::force_appearance = 0;
1077 1082
1078 static QString appname = Opie::binaryName ( ); 1083 static QString appname = Opie::binaryName ( );
1079 1084
1080 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1085 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1081 int nostyle = 0; 1086 int nostyle = 0;
1082 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1087 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1083 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1088 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1084 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1089 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1085 break; 1090 break;
1086 } 1091 }
1087 } 1092 }
1088 1093
1089 // Widget style 1094 // Widget style
1090 QString style = config.readEntry( "Style", "FlatStyle" ); 1095 QString style = config.readEntry( "Style", "FlatStyle" );
1091 1096
1092 // don't set a custom style 1097 // don't set a custom style
1093 if ( nostyle & Opie::Force_Style ) 1098 if ( nostyle & Opie::Force_Style )
1094 style = "FlatStyle"; 1099 style = "FlatStyle";
1095 1100
1096 internalSetStyle ( style ); 1101 internalSetStyle ( style );
1097 1102
1098 // Colors - from /etc/colors/Liquid.scheme 1103 // Colors - from /etc/colors/Liquid.scheme
1099 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1104 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1100 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1105 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1101 QPalette pal( btncolor, bgcolor ); 1106 QPalette pal( btncolor, bgcolor );
1102 QString color = config.readEntry( "Highlight", "#73adef" ); 1107 QString color = config.readEntry( "Highlight", "#73adef" );
1103 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1108 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1104 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1109 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1105 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1110 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1106 color = config.readEntry( "Text", "#000000" ); 1111 color = config.readEntry( "Text", "#000000" );
1107 pal.setColor( QColorGroup::Text, QColor( color ) ); 1112 pal.setColor( QColorGroup::Text, QColor( color ) );
1108 color = config.readEntry( "ButtonText", "#000000" ); 1113 color = config.readEntry( "ButtonText", "#000000" );
1109 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1114 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1110 color = config.readEntry( "Base", "#FFFFFF" ); 1115 color = config.readEntry( "Base", "#FFFFFF" );
1111 pal.setColor( QColorGroup::Base, QColor( color ) ); 1116 pal.setColor( QColorGroup::Base, QColor( color ) );
1112 1117
1113 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1118 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1114 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1119 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1115 1120
1116 setPalette( pal, TRUE ); 1121 setPalette( pal, TRUE );
1117 1122
1118 // Window Decoration 1123 // Window Decoration
1119 QString dec = config.readEntry( "Decoration", "Flat" ); 1124 QString dec = config.readEntry( "Decoration", "Flat" );
1120 1125
1121 // don't set a custom deco 1126 // don't set a custom deco
1122 if ( nostyle & Opie::Force_Decoration ) 1127 if ( nostyle & Opie::Force_Decoration )
1123 dec = ""; 1128 dec = "";
1124 1129
1125 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); 1130 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
1126 1131
1127 if ( dec != d->decorationName ) { 1132 if ( dec != d->decorationName ) {
1128 qwsSetDecoration( new QPEDecoration( dec ) ); 1133 qwsSetDecoration( new QPEDecoration( dec ) );
1129 d->decorationName = dec; 1134 d->decorationName = dec;
1130 } 1135 }
1131 1136
1132 // Font 1137 // Font
1133 QString ff = config.readEntry( "FontFamily", font().family() ); 1138 QString ff = config.readEntry( "FontFamily", font().family() );
1134 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1139 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1135 1140
1136 // don't set a custom font 1141 // don't set a custom font
1137 if ( nostyle & Opie::Force_Font ) { 1142 if ( nostyle & Opie::Force_Font ) {
1138 ff = "Vera"; 1143 ff = "Vera";
1139 fs = 10; 1144 fs = 10;
1140 } 1145 }
1141 1146
1142 setFont ( QFont ( ff, fs ), true ); 1147 setFont ( QFont ( ff, fs ), true );
1143 1148
1144 // revert to global blocking policy ... 1149 // revert to global blocking policy ...
1145 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1150 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1146 Opie::force_appearance &= ~nostyle; 1151 Opie::force_appearance &= ~nostyle;
1147 #endif 1152 #endif
1148} 1153}
1149 1154
1150void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1155void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1151{ 1156{
1152#ifdef Q_WS_QWS 1157#ifdef Q_WS_QWS
1153 QDataStream stream( data, IO_ReadOnly ); 1158 QDataStream stream( data, IO_ReadOnly );
1154 if ( msg == "applyStyle()" ) { 1159 if ( msg == "applyStyle()" ) {
1155 applyStyle(); 1160 applyStyle();
1156 } 1161 }
1157 else if ( msg == "toggleApplicationMenu()" ) { 1162 else if ( msg == "toggleApplicationMenu()" ) {
1158 QWidget *active = activeWindow ( ); 1163 QWidget *active = activeWindow ( );
1159 1164
1160 if ( active ) { 1165 if ( active ) {
1161 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1166 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1162 bool oldactive = man-> isActive ( ); 1167 bool oldactive = man-> isActive ( );
1163 1168
1164 man-> setActive( !man-> isActive() ); 1169 man-> setActive( !man-> isActive() );
1165 1170
1166 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1171 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1167 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1172 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1168 } 1173 }
1169 } 1174 }
1170 } 1175 }
1171 else if ( msg == "setDefaultRotation(int)" ) { 1176 else if ( msg == "setDefaultRotation(int)" ) {
1172 if ( type() == GuiServer ) { 1177 if ( type() == GuiServer ) {
1173 int r; 1178 int r;
1174 stream >> r; 1179 stream >> r;
1175 setDefaultRotation( r ); 1180 setDefaultRotation( r );
1176 } 1181 }
1177 } 1182 }
1178 else if ( msg == "setCurrentRotation(int)" ) { 1183 else if ( msg == "setCurrentRotation(int)" ) {
1179 int r; 1184 int r;
1180 stream >> r; 1185 stream >> r;
1181 setCurrentRotation( r ); 1186 setCurrentRotation( r );
1182 } 1187 }
1183 else if ( msg == "shutdown()" ) { 1188 else if ( msg == "shutdown()" ) {
1184 if ( type() == GuiServer ) 1189 if ( type() == GuiServer )
1185 shutdown(); 1190 shutdown();
1186 } 1191 }
1187 else if ( msg == "quit()" ) { 1192 else if ( msg == "quit()" ) {
1188 if ( type() != GuiServer ) 1193 if ( type() != GuiServer )
1189 tryQuit(); 1194 tryQuit();
1190 } 1195 }
1191 else if ( msg == "forceQuit()" ) { 1196 else if ( msg == "forceQuit()" ) {
1192 if ( type() != GuiServer ) 1197 if ( type() != GuiServer )
1193 quit(); 1198 quit();
1194 } 1199 }
1195 else if ( msg == "restart()" ) { 1200 else if ( msg == "restart()" ) {
1196 if ( type() == GuiServer ) 1201 if ( type() == GuiServer )
1197 restart(); 1202 restart();
1198 } 1203 }
1199 else if ( msg == "language(QString)" ) { 1204 else if ( msg == "language(QString)" ) {
1200 if ( type() == GuiServer ) { 1205 if ( type() == GuiServer ) {
1201 QString l; 1206 QString l;
1202 stream >> l; 1207 stream >> l;
1203 QString cl = getenv( "LANG" ); 1208 QString cl = getenv( "LANG" );
1204 if ( cl != l ) { 1209 if ( cl != l ) {
1205 if ( l.isNull() ) 1210 if ( l.isNull() )
1206 unsetenv( "LANG" ); 1211 unsetenv( "LANG" );
1207 else 1212 else
1208 setenv( "LANG", l.latin1(), 1 ); 1213 setenv( "LANG", l.latin1(), 1 );
1209 restart(); 1214 restart();
1210 } 1215 }
1211 } 1216 }
1212 } 1217 }
1213 else if ( msg == "timeChange(QString)" ) { 1218 else if ( msg == "timeChange(QString)" ) {
1214 QString t; 1219 QString t;
1215 stream >> t; 1220 stream >> t;
1216 if ( t.isNull() ) 1221 if ( t.isNull() )
1217 unsetenv( "TZ" ); 1222 unsetenv( "TZ" );
1218 else 1223 else
1219 setenv( "TZ", t.latin1(), 1 ); 1224 setenv( "TZ", t.latin1(), 1 );
1220 // emit the signal so everyone else knows... 1225 // emit the signal so everyone else knows...
1221 emit timeChanged(); 1226 emit timeChanged();
1222 } 1227 }
1223 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1228 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1224 if ( type() == GuiServer ) { 1229 if ( type() == GuiServer ) {
1225 QDateTime when; 1230 QDateTime when;
1226 QCString channel, message; 1231 QCString channel, message;
1227 int data; 1232 int data;
1228 stream >> when >> channel >> message >> data; 1233 stream >> when >> channel >> message >> data;
1229 AlarmServer::addAlarm( when, channel, message, data ); 1234 AlarmServer::addAlarm( when, channel, message, data );
1230 } 1235 }
1231 } 1236 }
1232 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1237 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1233 if ( type() == GuiServer ) { 1238 if ( type() == GuiServer ) {
1234 QDateTime when; 1239 QDateTime when;
1235 QCString channel, message; 1240 QCString channel, message;
1236 int data; 1241 int data;
1237 stream >> when >> channel >> message >> data; 1242 stream >> when >> channel >> message >> data;
1238 AlarmServer::deleteAlarm( when, channel, message, data ); 1243 AlarmServer::deleteAlarm( when, channel, message, data );
1239 } 1244 }
1240 } 1245 }
1241 else if ( msg == "clockChange(bool)" ) { 1246 else if ( msg == "clockChange(bool)" ) {
1242 int tmp; 1247 int tmp;
1243 stream >> tmp; 1248 stream >> tmp;
1244 emit clockChanged( tmp ); 1249 emit clockChanged( tmp );
1245 } 1250 }
1246 else if ( msg == "weekChange(bool)" ) { 1251 else if ( msg == "weekChange(bool)" ) {
1247 int tmp; 1252 int tmp;
1248 stream >> tmp; 1253 stream >> tmp;
1249 emit weekChanged( tmp ); 1254 emit weekChanged( tmp );
1250 } 1255 }
1251 else if ( msg == "setDateFormat(DateFormat)" ) { 1256 else if ( msg == "setDateFormat(DateFormat)" ) {
1252 DateFormat tmp; 1257 DateFormat tmp;
1253 stream >> tmp; 1258 stream >> tmp;
1254 emit dateFormatChanged( tmp ); 1259 emit dateFormatChanged( tmp );
1255 } 1260 }
1256 else if ( msg == "setVolume(int,int)" ) { 1261 else if ( msg == "setVolume(int,int)" ) {
1257 int t, v; 1262 int t, v;
1258 stream >> t >> v; 1263 stream >> t >> v;
1259 setVolume( t, v ); 1264 setVolume( t, v );
1260 emit volumeChanged( muted ); 1265 emit volumeChanged( muted );
1261 } 1266 }
1262 else if ( msg == "volumeChange(bool)" ) { 1267 else if ( msg == "volumeChange(bool)" ) {
1263 stream >> muted; 1268 stream >> muted;
1264 setVolume(); 1269 setVolume();
1265 emit volumeChanged( muted ); 1270 emit volumeChanged( muted );
1266 } 1271 }
1267 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1272 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1268 int t, v; 1273 int t, v;
1269 stream >> t >> v; 1274 stream >> t >> v;
1270 setMic( t, v ); 1275 setMic( t, v );
1271 emit micChanged( micMuted ); 1276 emit micChanged( micMuted );
1272 } 1277 }
1273 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1278 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1274 stream >> micMuted; 1279 stream >> micMuted;
1275 setMic(); 1280 setMic();
1276 emit micChanged( micMuted ); 1281 emit micChanged( micMuted );
1277 } 1282 }
1278 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1283 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1279 int t, v; 1284 int t, v;
1280 stream >> t >> v; 1285 stream >> t >> v;
1281 setBass( t, v ); 1286 setBass( t, v );
1282 } 1287 }
1283 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1288 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1284 setBass(); 1289 setBass();
1285 } 1290 }
1286 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1291 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1287 int t, v; 1292 int t, v;
1288 stream >> t >> v; 1293 stream >> t >> v;
1289 setTreble( t, v ); 1294 setTreble( t, v );
1290 } 1295 }
1291 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1296 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1292 setTreble(); 1297 setTreble();
1293 } else if ( msg == "getMarkedText()" ) { 1298 } else if ( msg == "getMarkedText()" ) {
1294 if ( type() == GuiServer ) { 1299 if ( type() == GuiServer ) {
1295 const ushort unicode = 'C'-'@'; 1300 const ushort unicode = 'C'-'@';
1296 const int scan = Key_C; 1301 const int scan = Key_C;
1297 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1302 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1298 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1303 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1299 } 1304 }
1300 } else if ( msg == "newChannel(QString)") { 1305 } else if ( msg == "newChannel(QString)") {
1301 QString myChannel = "QPE/Application/" + d->appName; 1306 QString myChannel = "QPE/Application/" + d->appName;
1302 QString channel; 1307 QString channel;
1303 stream >> channel; 1308 stream >> channel;
1304 if (channel == myChannel) { 1309 if (channel == myChannel) {
1305 processQCopFile(); 1310 processQCopFile();
1306 d->sendQCopQ(); 1311 d->sendQCopQ();
1307 } 1312 }
1308 } 1313 }
1309 1314
1310 1315
1311#endif 1316#endif
1312} 1317}
1313 1318
1319#include <qmetaobject.h>
1320
1321QWidget *QPEApplication::nextWidget(QWidgetList* list, QWidget* _wid) {
1322 QWidget *next = 0;
1323 if ( list->isEmpty() || list->count() == 1 )
1324 next = _wid;
1325 else{
1326 QWidget* wid;
1327 uint idx = list->findRef( _wid );
1328 uint count = list->count();
1329
1330 /* one time through the list hacky we may not start with idx but end with it*/
1331 for (uint i = (idx + 1)%count; true; i=(i+1)%count ) {
1332 wid = list->at(i);
1333 if ( wid == _wid ) {
1334 next = _wid;
1335 break;
1336 }else if ((( wid->inherits("QMainWindow") ||
1337 wid->inherits("QDialog") ) &&
1338 wid != qApp->desktop() && !wid->isHidden() ) ||
1339 ( wid == mainWidget() || wid == d->qpe_main_widget ) ){
1340 next = wid;
1341 break;
1342 }
1343 }
1344 }
1345
1346 delete list;
1347 return next;
1348}
1314/*! 1349/*!
1315 \internal 1350 \internal
1316*/ 1351*/
1352// ########## raise()ing main window should raise and set active
1353// ########## it and then all childen. This belongs in Qt/Embedded
1354/*
1355 * slightly change in behaviour to kill the need of modality in Opie
1356 * If any of the topLevelWidgets !isFullyObscured we highlight the next
1357 * top level window
1358 * 1)If visible and not modal we iterate over the list of top level widgets
1359 * 2)If modal we we make the modal and its parent toplevel widget visible if available
1360 * 3)else make topLevel visible
1361 *
1362 * send qcop if necessary and save current visible widget if not modal
1363 */
1317bool QPEApplication::raiseAppropriateWindow() 1364bool QPEApplication::raiseAppropriateWindow()
1318{ 1365{
1319 bool r = FALSE; 1366 bool r = FALSE;
1320 // ########## raise()ing main window should raise and set active 1367
1321 // ########## it and then all childen. This belongs in Qt/Embedded 1368 QWidget *top = d->qpe_main_widget ? d->qpe_main_widget : mainWidget();
1322 QWidget *top = d->qpe_main_widget; 1369 /* 1. */
1323 if ( !top ) 1370 if ( ( top && (top->isVisible() ) || ( d->lastWidget && d->lastWidget->isVisible() ) ) &&
1324 top = mainWidget(); 1371 !activeModalWidget() ) {
1325 if ( top && d->keep_running ) { 1372 r = TRUE;
1326 if ( top->isVisible() ) 1373 /*wid will be valid and topLevelWidgets will be deleted properly.. */
1327 r = TRUE; 1374 QWidget *wid = nextWidget( topLevelWidgets(),
1328 else if (d->preloaded) { 1375 d->lastWidget ? (QWidget*)d->lastWidget : top );
1329 // We are preloaded and not visible.. pretend we just started.. 1376 /* keep the size window got but not for root*/
1330 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1377 if ( top == wid )
1331 e << d->appName; 1378 d->show_mx(top, d->nomaximize );
1332 } 1379 else
1380 wid->show();
1381
1382 wid->raise();
1383 wid->setActiveWindow();
1384 d->lastWidget = wid;
1385 }else if ( activeModalWidget() ) {
1386 QWidget* mod = activeModalWidget();
1387 /* get the parent of the modal and its topLevelWidget as background widget */
1388 QWidget* par = activeModalWidget()->parentWidget() ? activeModalWidget()->parentWidget()->topLevelWidget() : 0;
1389 if (par ) {
1390 if (par == top )
1391 d->show_mx(par, d->nomaximize );
1392 else
1393 par->show();
1394 par->raise();
1395 par->setActiveWindow();
1396 }
1397 mod->show();
1398 mod->raise();
1399 mod->setActiveWindow();
1400 }else if (top){
1401 d->show_mx(top, d->nomaximize );
1402 top->raise();
1403 top->setActiveWindow();
1404 d->lastWidget = top;
1405 }
1333 1406
1334 d->show_mx(top, d->nomaximize); 1407 if (!r && d->preloaded ) {
1335 top->raise(); 1408 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1336 top->setActiveWindow(); 1409 e << d->appName;
1337 } 1410 }
1338 QWidget *topm = activeModalWidget(); 1411
1339 if ( topm && topm != top ) { 1412 return r;
1340 topm->show();
1341 topm->raise();
1342 topm->setActiveWindow();
1343 // If we haven't already handled the fastAppShowing message
1344 if (!top && d->preloaded) {
1345 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1346 e << d->appName;
1347 }
1348 r = FALSE;
1349 }
1350 return r;
1351} 1413}
1352 1414
1415
1353void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1416void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1354{ 1417{
1355#ifdef Q_WS_QWS 1418#ifdef Q_WS_QWS
1356 1419
1357 if ( msg == "quit()" ) { 1420 if ( msg == "quit()" ) {
1358 tryQuit(); 1421 tryQuit();
1359 } 1422 }
1360 else if ( msg == "quitIfInvisible()" ) { 1423 else if ( msg == "quitIfInvisible()" ) {
1361 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1424 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1362 quit(); 1425 quit();
1363 } 1426 }
1364 else if ( msg == "close()" ) { 1427 else if ( msg == "close()" ) {
1365 hideOrQuit(); 1428 hideOrQuit();
1366 } 1429 }
1367 else if ( msg == "disablePreload()" ) { 1430 else if ( msg == "disablePreload()" ) {
1368 d->preloaded = FALSE; 1431 d->preloaded = FALSE;
1369 d->keep_running = TRUE; 1432 d->keep_running = TRUE;
1370 /* so that quit will quit */ 1433 /* so that quit will quit */
1371 } 1434 }
1372 else if ( msg == "enablePreload()" ) { 1435 else if ( msg == "enablePreload()" ) {
1373 if (d->qpe_main_widget) 1436 if (d->qpe_main_widget)
1374 d->preloaded = TRUE; 1437 d->preloaded = TRUE;
1375 d->keep_running = TRUE; 1438 d->keep_running = TRUE;
1376 /* so next quit won't quit */ 1439 /* so next quit won't quit */
1377 } 1440 }
1378 else if ( msg == "raise()" ) { 1441 else if ( msg == "raise()" ) {
1379 d->keep_running = TRUE; 1442 d->keep_running = TRUE;
1380 d->notbusysent = FALSE; 1443 d->notbusysent = FALSE;
1381 raiseAppropriateWindow(); 1444 raiseAppropriateWindow();
1382 // Tell the system we're still chugging along... 1445 // Tell the system we're still chugging along...
1383 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1446 QCopEnvelope e("QPE/System", "appRaised(QString)");
1384 e << d->appName; 1447 e << d->appName;
1385 } 1448 }
1386 else if ( msg == "flush()" ) { 1449 else if ( msg == "flush()" ) {
1387 emit flush(); 1450 emit flush();
1388 // we need to tell the desktop 1451 // we need to tell the desktop
1389 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1452 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1390 e << d->appName; 1453 e << d->appName;
1391 } 1454 }
1392 else if ( msg == "reload()" ) { 1455 else if ( msg == "reload()" ) {
1393 emit reload(); 1456 emit reload();
1394 } 1457 }
1395 else if ( msg == "setDocument(QString)" ) { 1458 else if ( msg == "setDocument(QString)" ) {
1396 d->keep_running = TRUE; 1459 d->keep_running = TRUE;
1397 QDataStream stream( data, IO_ReadOnly ); 1460 QDataStream stream( data, IO_ReadOnly );
1398 QString doc; 1461 QString doc;
1399 stream >> doc; 1462 stream >> doc;
1400 QWidget *mw = mainWidget(); 1463 QWidget *mw = mainWidget();
1401 if ( !mw ) 1464 if ( !mw )
1402 mw = d->qpe_main_widget; 1465 mw = d->qpe_main_widget;
1403 if ( mw ) 1466 if ( mw )
1404 Global::setDocument( mw, doc ); 1467 Global::setDocument( mw, doc );
1468
1405 } else if ( msg == "QPEProcessQCop()" ) { 1469 } else if ( msg == "QPEProcessQCop()" ) {
1406 processQCopFile(); 1470 processQCopFile();
1407 d->sendQCopQ(); 1471 d->sendQCopQ();
1408 } 1472 }else
1409 { 1473 {
1410 bool p = d->keep_running; 1474 bool p = d->keep_running;
1411 d->keep_running = FALSE; 1475 d->keep_running = FALSE;
1412 emit appMessage( msg, data); 1476 emit appMessage( msg, data);
1413 if ( d->keep_running ) { 1477 if ( d->keep_running ) {
1414 d->notbusysent = FALSE; 1478 d->notbusysent = FALSE;
1415 raiseAppropriateWindow(); 1479 raiseAppropriateWindow();
1416 if ( !p ) { 1480 if ( !p ) {
1417 // Tell the system we're still chugging along... 1481 // Tell the system we're still chugging along...
1418#ifndef QT_NO_COP 1482#ifndef QT_NO_COP
1419 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1483 QCopEnvelope e("QPE/System", "appRaised(QString)");
1420 e << d->appName; 1484 e << d->appName;
1421#endif 1485#endif
1422 } 1486 }
1423 } 1487 }
1424 if ( p ) 1488 if ( p )
1425 d->keep_running = p; 1489 d->keep_running = p;
1426 } 1490 }
1427#endif 1491#endif
1428} 1492}
1429 1493
1430 1494
1431/*! 1495/*!
1432 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1496 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1433 consider passing TRUE for \a nomaximize rather than the default FALSE. 1497 consider passing TRUE for \a nomaximize rather than the default FALSE.
1434 1498
1435 \sa showMainDocumentWidget() 1499 \sa showMainDocumentWidget()
1436*/ 1500*/
1437void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1501void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1438{ 1502{
1439 d->show(mw, nomaximize ); 1503 d->show(mw, nomaximize );
1440} 1504}
1441 1505
1442/*! 1506/*!
1443 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1507 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1444 consider passing TRUE for \a nomaximize rather than the default FALSE. 1508 consider passing TRUE for \a nomaximize rather than the default FALSE.
1445 1509
1446 This calls designates the application as 1510 This calls designates the application as
1447 a \link docwidget.html document-oriented\endlink application. 1511 a \link docwidget.html document-oriented\endlink application.
1448 1512
1449 The \a mw widget \e must have this slot: setDocument(const QString&). 1513 The \a mw widget \e must have this slot: setDocument(const QString&).
1450 1514
1451 \sa showMainWidget() 1515 \sa showMainWidget()
1452*/ 1516*/
1453void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1517void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1454{ 1518{
1455 if ( mw && argc() == 2 ) 1519 if ( mw && argc() == 2 )
1456 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1520 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1457 1521
1458 1522
1459 d->show(mw, nomaximize ); 1523 d->show(mw, nomaximize );
1460} 1524}
1461 1525
1462 1526
1463/*! 1527/*!
1464 If an application is started via a \link qcop.html QCop\endlink 1528 If an application is started via a \link qcop.html QCop\endlink
1465 message, the application will process the \link qcop.html 1529 message, the application will process the \link qcop.html
1466 QCop\endlink message and then quit. If the application calls this 1530 QCop\endlink message and then quit. If the application calls this
1467 function while processing a \link qcop.html QCop\endlink message, 1531 function while processing a \link qcop.html QCop\endlink message,
1468 after processing its outstanding \link qcop.html QCop\endlink 1532 after processing its outstanding \link qcop.html QCop\endlink
1469 messages the application will start 'properly' and show itself. 1533 messages the application will start 'properly' and show itself.
1470 1534
1471 \sa keepRunning() 1535 \sa keepRunning()
1472*/ 1536*/
1473void QPEApplication::setKeepRunning() 1537void QPEApplication::setKeepRunning()
1474{ 1538{
1475 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1539 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1476 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1540 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1477 qpeApp->d->keep_running = TRUE; 1541 qpeApp->d->keep_running = TRUE;
1478 } 1542 }
1479} 1543}
1480 1544
1481/*! 1545/*!
1482 Returns TRUE if the application will quit after processing the 1546 Returns TRUE if the application will quit after processing the
1483 current list of qcop messages; otherwise returns FALSE. 1547 current list of qcop messages; otherwise returns FALSE.
1484 1548
1485 \sa setKeepRunning() 1549 \sa setKeepRunning()
1486*/ 1550*/
1487bool QPEApplication::keepRunning() const 1551bool QPEApplication::keepRunning() const
1488{ 1552{
1489 return d->keep_running; 1553 return d->keep_running;
1490} 1554}
1491 1555
1492/*! 1556/*!
1493 \internal 1557 \internal
1494*/ 1558*/
1495void QPEApplication::internalSetStyle( const QString &style ) 1559void QPEApplication::internalSetStyle( const QString &style )
1496{ 1560{
1497#if QT_VERSION >= 300 1561#if QT_VERSION >= 300
1498 if ( style == "QPE" ) { 1562 if ( style == "QPE" ) {
1499 setStyle( new QPEStyle ); 1563 setStyle( new QPEStyle );
1500 } 1564 }
1501 else { 1565 else {
1502 QStyle *s = QStyleFactory::create( style ); 1566 QStyle *s = QStyleFactory::create( style );
1503 if ( s ) 1567 if ( s )
1504 setStyle( s ); 1568 setStyle( s );
1505 } 1569 }
1506#else 1570#else
1507 if ( style == "Windows" ) { 1571 if ( style == "Windows" ) {
1508 setStyle( new QWindowsStyle ); 1572 setStyle( new QWindowsStyle );
1509 } 1573 }
1510 else if ( style == "QPE" ) { 1574 else if ( style == "QPE" ) {
1511 setStyle( new QPEStyle ); 1575 setStyle( new QPEStyle );
1512 } 1576 }
1513 else if ( style == "Light" ) { 1577 else if ( style == "Light" ) {
1514 setStyle( new LightStyle ); 1578 setStyle( new LightStyle );
1515 } 1579 }
1516#ifndef QT_NO_STYLE_PLATINUM 1580#ifndef QT_NO_STYLE_PLATINUM
1517 else if ( style == "Platinum" ) { 1581 else if ( style == "Platinum" ) {
1518 setStyle( new QPlatinumStyle ); 1582 setStyle( new QPlatinumStyle );
1519 } 1583 }
1520#endif 1584#endif
1521#ifndef QT_NO_STYLE_MOTIF 1585#ifndef QT_NO_STYLE_MOTIF
1522 else if ( style == "Motif" ) { 1586 else if ( style == "Motif" ) {
1523 setStyle( new QMotifStyle ); 1587 setStyle( new QMotifStyle );
1524 } 1588 }
1525#endif 1589#endif
1526#ifndef QT_NO_STYLE_MOTIFPLUS 1590#ifndef QT_NO_STYLE_MOTIFPLUS
1527 else if ( style == "MotifPlus" ) { 1591 else if ( style == "MotifPlus" ) {
1528 setStyle( new QMotifPlusStyle ); 1592 setStyle( new QMotifPlusStyle );
1529 } 1593 }
1530#endif 1594#endif
1531 1595
1532 else { 1596 else {
1533 QStyle *sty = 0; 1597 QStyle *sty = 0;
1534 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 1598 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
1535 1599
1536 if ( style. find ( ".so" ) > 0 ) 1600 if ( style. find ( ".so" ) > 0 )
1537 path += style; 1601 path += style;
1538 else 1602 else
1539 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1603 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1540 1604
1541 static QLibrary *lastlib = 0; 1605 static QLibrary *lastlib = 0;
1542 static StyleInterface *lastiface = 0; 1606 static StyleInterface *lastiface = 0;
1543 1607
1544 QLibrary *lib = new QLibrary ( path ); 1608 QLibrary *lib = new QLibrary ( path );
1545 StyleInterface *iface = 0; 1609 StyleInterface *iface = 0;
1546 1610
1547 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1611 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1548 sty = iface-> style ( ); 1612 sty = iface-> style ( );
1549 1613
1550 if ( sty ) { 1614 if ( sty ) {
1551 setStyle ( sty ); 1615 setStyle ( sty );
1552 1616
1553 if ( lastiface ) 1617 if ( lastiface )
1554 lastiface-> release ( ); 1618 lastiface-> release ( );
1555 lastiface = iface; 1619 lastiface = iface;
1556 1620
1557 if ( lastlib ) { 1621 if ( lastlib ) {
1558 lastlib-> unload ( ); 1622 lastlib-> unload ( );
1559 delete lastlib; 1623 delete lastlib;
1560 } 1624 }
1561 lastlib = lib; 1625 lastlib = lib;
1562 } 1626 }
1563 else { 1627 else {
1564 if ( iface ) 1628 if ( iface )
1565 iface-> release ( ); 1629 iface-> release ( );
1566 delete lib; 1630 delete lib;
1567 1631
1568 setStyle ( new LightStyle ( )); 1632 setStyle ( new LightStyle ( ));
1569 } 1633 }
1570 } 1634 }
1571#endif 1635#endif
1572} 1636}
1573 1637
1574/*! 1638/*!
1575 \internal 1639 \internal
1576*/ 1640*/
1577void QPEApplication::prepareForTermination( bool willrestart ) 1641void QPEApplication::prepareForTermination( bool willrestart )
1578{ 1642{
1579 if ( willrestart ) { 1643 if ( willrestart ) {
1580 // Draw a big wait icon, the image can be altered in later revisions 1644 // Draw a big wait icon, the image can be altered in later revisions
1581 // QWidget *d = QApplication::desktop(); 1645 // QWidget *d = QApplication::desktop();
1582 QImage img = Resource::loadImage( "launcher/new_wait" ); 1646 QImage img = Resource::loadImage( "launcher/new_wait" );
1583 QPixmap pix; 1647 QPixmap pix;
1584 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1648 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1585 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1649 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1586 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1650 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1587 lblWait->setPixmap( pix ); 1651 lblWait->setPixmap( pix );
1588 lblWait->setAlignment( QWidget::AlignCenter ); 1652 lblWait->setAlignment( QWidget::AlignCenter );
1589 lblWait->show(); 1653 lblWait->show();
1590 lblWait->showMaximized(); 1654 lblWait->showMaximized();
1591 } 1655 }
1592#ifndef SINGLE_APP 1656#ifndef SINGLE_APP
1593 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1657 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1594 } 1658 }
1595 processEvents(); // ensure the message goes out. 1659 processEvents(); // ensure the message goes out.
1596 sleep( 1 ); // You have 1 second to comply. 1660 sleep( 1 ); // You have 1 second to comply.
1597#endif 1661#endif
1598} 1662}
1599 1663
1600/*! 1664/*!
1601 \internal 1665 \internal
1602*/ 1666*/
1603void QPEApplication::shutdown() 1667void QPEApplication::shutdown()
1604{ 1668{
1605 // Implement in server's QPEApplication subclass 1669 // Implement in server's QPEApplication subclass
1606} 1670}
1607 1671
1608/*! 1672/*!
1609 \internal 1673 \internal
1610*/ 1674*/
1611void QPEApplication::restart() 1675void QPEApplication::restart()
1612{ 1676{
1613 // Implement in server's QPEApplication subclass 1677 // Implement in server's QPEApplication subclass
1614} 1678}
1615 1679
1616static QPtrDict<void>* stylusDict = 0; 1680static QPtrDict<void>* stylusDict = 0;
1617static void createDict() 1681static void createDict()
1618{ 1682{
1619 if ( !stylusDict ) 1683 if ( !stylusDict )
1620 stylusDict = new QPtrDict<void>; 1684 stylusDict = new QPtrDict<void>;
1621} 1685}
1622 1686
1623/*! 1687/*!
1624 Returns the current StylusMode for widget \a w. 1688 Returns the current StylusMode for widget \a w.
1625 1689
1626 \sa setStylusOperation() StylusMode 1690 \sa setStylusOperation() StylusMode
1627*/ 1691*/
1628QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1692QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1629{ 1693{
1630 if ( stylusDict ) 1694 if ( stylusDict )
1631 return ( StylusMode ) ( int ) stylusDict->find( w ); 1695 return ( StylusMode ) ( int ) stylusDict->find( w );
1632 return LeftOnly; 1696 return LeftOnly;
1633} 1697}
1634 1698
1635/*! 1699/*!
1636 \enum QPEApplication::StylusMode 1700 \enum QPEApplication::StylusMode
1637 1701
1638 \value LeftOnly the stylus only generates LeftButton 1702 \value LeftOnly the stylus only generates LeftButton
1639 events (the default). 1703 events (the default).
1640 \value RightOnHold the stylus generates RightButton events 1704 \value RightOnHold the stylus generates RightButton events
1641 if the user uses the press-and-hold gesture. 1705 if the user uses the press-and-hold gesture.
1642 1706
1643 \sa setStylusOperation() stylusOperation() 1707 \sa setStylusOperation() stylusOperation()
1644*/ 1708*/
1645 1709
1646/*! 1710/*!
1647 Causes widget \a w to receive mouse events according to the stylus 1711 Causes widget \a w to receive mouse events according to the stylus
1648 \a mode. 1712 \a mode.
1649 1713
1650 \sa stylusOperation() StylusMode 1714 \sa stylusOperation() StylusMode
1651*/ 1715*/
1652void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1716void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1653{ 1717{
1654 createDict(); 1718 createDict();
1655 if ( mode == LeftOnly ) { 1719 if ( mode == LeftOnly ) {
1656 stylusDict->remove 1720 stylusDict->remove
1657 ( w ); 1721 ( w );
1658 w->removeEventFilter( qApp ); 1722 w->removeEventFilter( qApp );
1659 } 1723 }
1660 else { 1724 else {
1661 stylusDict->insert( w, ( void* ) mode ); 1725 stylusDict->insert( w, ( void* ) mode );
1662 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 1726 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
1663 w->installEventFilter( qApp ); 1727 w->installEventFilter( qApp );
1664 } 1728 }
1665} 1729}
1666 1730
1667 1731
1668/*! 1732/*!
1669 \reimp 1733 \reimp
1670*/ 1734*/
1671bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1735bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1672{ 1736{
1673 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1737 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1674 QMouseEvent * me = ( QMouseEvent* ) e; 1738 QMouseEvent * me = ( QMouseEvent* ) e;
1675 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 1739 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1676 switch (mode) { 1740 switch (mode) {
1677 case RightOnHold: 1741 case RightOnHold:
1678 switch ( me->type() ) { 1742 switch ( me->type() ) {
1679 case QEvent::MouseButtonPress: 1743 case QEvent::MouseButtonPress:
1680 if ( me->button() == LeftButton ) { 1744 if ( me->button() == LeftButton ) {
1681 d->presstimer = startTimer(500); // #### pref. 1745 d->presstimer = startTimer(500); // #### pref.
1682 d->presswidget = (QWidget*)o; 1746 d->presswidget = (QWidget*)o;
1683 d->presspos = me->pos(); 1747 d->presspos = me->pos();
1684 d->rightpressed = FALSE; 1748 d->rightpressed = FALSE;
1685 } 1749 }
1686 break; 1750 break;
1687 case QEvent::MouseMove: 1751 case QEvent::MouseMove:
1688 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 1752 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
1689 killTimer(d->presstimer); 1753 killTimer(d->presstimer);
1690 d->presstimer = 0; 1754 d->presstimer = 0;
1691 } 1755 }
1692 break; 1756 break;
1693 case QEvent::MouseButtonRelease: 1757 case QEvent::MouseButtonRelease:
1694 if ( me->button() == LeftButton ) { 1758 if ( me->button() == LeftButton ) {
1695 if ( d->presstimer ) { 1759 if ( d->presstimer ) {
1696 killTimer(d->presstimer); 1760 killTimer(d->presstimer);
1697 d->presstimer = 0; 1761 d->presstimer = 0;
1698 } 1762 }
1699 if ( d->rightpressed && d->presswidget ) { 1763 if ( d->rightpressed && d->presswidget ) {
1700 // Right released 1764 // Right released
1701 postEvent( d->presswidget, 1765 postEvent( d->presswidget,
1702 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 1766 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1703 RightButton, LeftButton + RightButton ) ); 1767 RightButton, LeftButton + RightButton ) );
1704 // Left released, off-widget 1768 // Left released, off-widget
1705 postEvent( d->presswidget, 1769 postEvent( d->presswidget,
1706 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 1770 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
1707 LeftButton, LeftButton ) ); 1771 LeftButton, LeftButton ) );
1708 postEvent( d->presswidget, 1772 postEvent( d->presswidget,
1709 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 1773 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
1710 LeftButton, LeftButton ) ); 1774 LeftButton, LeftButton ) );
1711 d->rightpressed = FALSE; 1775 d->rightpressed = FALSE;
1712 return TRUE; // don't send the real Left release 1776 return TRUE; // don't send the real Left release
1713 } 1777 }
1714 } 1778 }
1715 break; 1779 break;
1716 default: 1780 default:
1717 break; 1781 break;
1718 } 1782 }
1719 break; 1783 break;
1720 default: 1784 default:
1721 ; 1785 ;
1722 } 1786 }
1723 } 1787 }
1724 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1788 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1725 QKeyEvent *ke = (QKeyEvent *)e; 1789 QKeyEvent *ke = (QKeyEvent *)e;
1726 if ( ke->key() == Key_Enter ) { 1790 if ( ke->key() == Key_Enter ) {
1727 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1791 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1728 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1792 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1729 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1793 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1730 return TRUE; 1794 return TRUE;
1731 } 1795 }
1732 } 1796 }
1733 } 1797 }
1734 return FALSE; 1798 return FALSE;
1735} 1799}
1736 1800
1737/*! 1801/*!
1738 \reimp 1802 \reimp
1739*/ 1803*/
1740void QPEApplication::timerEvent( QTimerEvent *e ) 1804void QPEApplication::timerEvent( QTimerEvent *e )
1741{ 1805{
1742 if ( e->timerId() == d->presstimer && d->presswidget ) { 1806 if ( e->timerId() == d->presstimer && d->presswidget ) {
1743 // Right pressed 1807 // Right pressed
1744 postEvent( d->presswidget, 1808 postEvent( d->presswidget,
1745 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 1809 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
1746 RightButton, LeftButton ) ); 1810 RightButton, LeftButton ) );
1747 killTimer( d->presstimer ); 1811 killTimer( d->presstimer );
1748 d->presstimer = 0; 1812 d->presstimer = 0;
1749 d->rightpressed = TRUE; 1813 d->rightpressed = TRUE;
1750 } 1814 }
1751} 1815}
1752 1816
1753void QPEApplication::removeSenderFromStylusDict() 1817void QPEApplication::removeSenderFromStylusDict()
1754{ 1818{
1755 stylusDict->remove 1819 stylusDict->remove
1756 ( ( void* ) sender() ); 1820 ( ( void* ) sender() );
1757 if ( d->presswidget == sender() ) 1821 if ( d->presswidget == sender() )
1758 d->presswidget = 0; 1822 d->presswidget = 0;
1759} 1823}
1760 1824
1761/*! 1825/*!
1762 \internal 1826 \internal
1763*/ 1827*/
1764bool QPEApplication::keyboardGrabbed() const 1828bool QPEApplication::keyboardGrabbed() const
1765{ 1829{
1766 return d->kbgrabbed; 1830 return d->kbgrabbed;
1767} 1831}
1768 1832
1769 1833
1770/*! 1834/*!
1771 Reverses the effect of grabKeyboard(). This is called automatically 1835 Reverses the effect of grabKeyboard(). This is called automatically
1772 on program exit. 1836 on program exit.
1773*/ 1837*/
1774void QPEApplication::ungrabKeyboard() 1838void QPEApplication::ungrabKeyboard()
1775{ 1839{
1776 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 1840 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
1777} 1841}
1778 1842
1779/*! 1843/*!
1780 Grabs the physical keyboard keys, e.g. the application's launching 1844 Grabs the physical keyboard keys, e.g. the application's launching
1781 keys. Instead of launching applications when these keys are pressed 1845 keys. Instead of launching applications when these keys are pressed
1782 the signals emitted are sent to this application instead. Some games 1846 the signals emitted are sent to this application instead. Some games
1783 programs take over the launch keys in this way to make interaction 1847 programs take over the launch keys in this way to make interaction
1784 easier. 1848 easier.
1785 1849
1786 \sa ungrabKeyboard() 1850 \sa ungrabKeyboard()
1787*/ 1851*/
1788void QPEApplication::grabKeyboard() 1852void QPEApplication::grabKeyboard()
1789{ 1853{
1790 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 1854 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
1791} 1855}
1792 1856
1793/*! 1857/*!
1794 \reimp 1858 \reimp
1795*/ 1859*/
1796int QPEApplication::exec() 1860int QPEApplication::exec()
1797{ 1861{
1798#ifndef QT_NO_COP 1862#ifndef QT_NO_COP
1799 d->sendQCopQ(); 1863 d->sendQCopQ();
1800#endif 1864#endif
1801 1865
1802 if ( d->keep_running ) 1866 if ( d->keep_running )
1803 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1867 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1804 return QApplication::exec(); 1868 return QApplication::exec();
1805 1869
1806#ifndef QT_NO_COP 1870#ifndef QT_NO_COP
1807 1871
1808 { 1872 {
1809 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1873 QCopEnvelope e( "QPE/System", "closing(QString)" );
1810 e << d->appName; 1874 e << d->appName;
1811 } 1875 }
1812#endif 1876#endif
1813 processEvents(); 1877 processEvents();
1814 return 0; 1878 return 0;
1815} 1879}
1816 1880
1817/*! 1881/*!
1818 \internal 1882 \internal
1819 External request for application to quit. Quits if possible without 1883 External request for application to quit. Quits if possible without
1820 loosing state. 1884 loosing state.
1821*/ 1885*/
1822void QPEApplication::tryQuit() 1886void QPEApplication::tryQuit()
1823{ 1887{
1824 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 1888 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1825 return ; // Inside modal loop or konsole. Too hard to save state. 1889 return ; // Inside modal loop or konsole. Too hard to save state.
1826#ifndef QT_NO_COP 1890#ifndef QT_NO_COP
1827 1891
1828 { 1892 {
1829 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1893 QCopEnvelope e( "QPE/System", "closing(QString)" );
1830 e << d->appName; 1894 e << d->appName;
1831 } 1895 }
1832#endif 1896#endif
1833 processEvents(); 1897 processEvents();
1834 1898
1835 quit(); 1899 quit();
1836} 1900}
1837 1901
1838/*! 1902/*!
1839 \internal 1903 \internal
1840*/ 1904*/
1841void QPEApplication::installTranslation( const QString& baseName ) { 1905void QPEApplication::installTranslation( const QString& baseName ) {
1842 QTranslator* trans = new QTranslator(this); 1906 QTranslator* trans = new QTranslator(this);
1843 QString tfn = qpeDir() + "/i18n/"+baseName; 1907 QString tfn = qpeDir() + "/i18n/"+baseName;
1844 if ( trans->load( tfn ) ) 1908 if ( trans->load( tfn ) )
1845 installTranslator( trans ); 1909 installTranslator( trans );
1846 else 1910 else
1847 delete trans; 1911 delete trans;
1848} 1912}
1849 1913
1850/*! 1914/*!
1851 \internal 1915 \internal
1852 User initiated quit. Makes the window 'Go Away'. If preloaded this means 1916 User initiated quit. Makes the window 'Go Away'. If preloaded this means
1853 hiding the window. If not it means quitting the application. 1917 hiding the window. If not it means quitting the application.
1854 As this is user initiated we don't need to check state. 1918 As this is user initiated we don't need to check state.
1855*/ 1919*/
1856void QPEApplication::hideOrQuit() 1920void QPEApplication::hideOrQuit()
1857{ 1921{
1858 processEvents(); 1922 processEvents();
1859 1923
1860 // If we are a preloaded application we don't actually quit, so emit 1924 // If we are a preloaded application we don't actually quit, so emit
1861 // a System message indicating we're quasi-closing. 1925 // a System message indicating we're quasi-closing.
1862 if ( d->preloaded && d->qpe_main_widget ) 1926 if ( d->preloaded && d->qpe_main_widget )
1863#ifndef QT_NO_COP 1927#ifndef QT_NO_COP
1864 1928
1865 { 1929 {
1866 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 1930 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
1867 e << d->appName; 1931 e << d->appName;
1868 d->qpe_main_widget->hide(); 1932 d->qpe_main_widget->hide();
1869 } 1933 }
1870#endif 1934#endif
1871 else 1935 else
1872 quit(); 1936 quit();
1873} 1937}
1874 1938
1875#if (__GNUC__ > 2 ) 1939#if (__GNUC__ > 2 )
1876extern "C" void __cxa_pure_virtual(); 1940extern "C" void __cxa_pure_virtual();
1877 1941
1878void __cxa_pure_virtual() 1942void __cxa_pure_virtual()
1879{ 1943{
1880 fprintf( stderr, "Pure virtual called\n"); 1944 fprintf( stderr, "Pure virtual called\n");
1881 abort(); 1945 abort();
1882 1946
1883} 1947}
1884 1948
1885#endif 1949#endif
1886 1950
1887 1951
1888#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_RAMSES) 1952#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_RAMSES)
1889 1953
1890// The libraries with the skiff package (and possibly others) have 1954// The libraries with the skiff package (and possibly others) have
1891// completely useless implementations of builtin new and delete that 1955// completely useless implementations of builtin new and delete that
1892// use about 50% of your CPU. Here we revert to the simple libc 1956// use about 50% of your CPU. Here we revert to the simple libc
1893// functions. 1957// functions.
1894 1958
1895void* operator new[]( size_t size ) 1959void* operator new[]( size_t size )
1896{ 1960{
1897 return malloc( size ); 1961 return malloc( size );
1898} 1962}
1899 1963
1900void* operator new( size_t size ) 1964void* operator new( size_t size )
1901{ 1965{
1902 return malloc( size ); 1966 return malloc( size );
1903} 1967}
1904 1968
1905void operator delete[]( void* p ) 1969void operator delete[]( void* p )
1906{ 1970{
1907 free( p ); 1971 free( p );
1908} 1972}
1909 1973
1910void operator delete[]( void* p, size_t /*size*/ ) 1974void operator delete[]( void* p, size_t /*size*/ )
1911{ 1975{
1912 free( p ); 1976 free( p );
1913} 1977}
1914 1978
1915 1979
1916void operator delete( void* p ) 1980void operator delete( void* p )
1917{ 1981{
1918 free( p ); 1982 free( p );
1919} 1983}
1920 1984
1921void operator delete( void* p, size_t /*size*/ ) 1985void operator delete( void* p, size_t /*size*/ )
1922{ 1986{
1923 free( p ); 1987 free( p );
1924} 1988}
1925 1989
1926#endif 1990#endif
1927 1991
1928#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 1992#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
1929#include <qwidgetlist.h> 1993#include <qwidgetlist.h>
1930#ifdef QWS 1994#ifdef QWS
1931#include <qgfx_qws.h> 1995#include <qgfx_qws.h>
1932extern QRect qt_maxWindowRect; 1996extern QRect qt_maxWindowRect;
1933void qt_setMaxWindowRect(const QRect& r ) 1997void qt_setMaxWindowRect(const QRect& r )
1934{ 1998{
1935 qt_maxWindowRect = qt_screen->mapFromDevice( r, 1999 qt_maxWindowRect = qt_screen->mapFromDevice( r,
1936 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2000 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
1937 // Re-resize any maximized windows 2001 // Re-resize any maximized windows
1938 QWidgetList* l = QApplication::topLevelWidgets(); 2002 QWidgetList* l = QApplication::topLevelWidgets();
1939 if ( l ) { 2003 if ( l ) {
1940 QWidget * w = l->first(); 2004 QWidget * w = l->first();
1941 while ( w ) { 2005 while ( w ) {
1942 if ( w->isVisible() && w->isMaximized() ) { 2006 if ( w->isVisible() && w->isMaximized() ) {
1943 w->showMaximized(); 2007 w->showMaximized();
1944 } 2008 }
1945 w = l->next(); 2009 w = l->next();
1946 } 2010 }
1947 delete l; 2011 delete l;
1948 } 2012 }
1949} 2013}
1950#endif 2014#endif
1951#endif 2015#endif
diff --git a/library/qpeapplication.h b/library/qpeapplication.h
index 770ea23..343e0b9 100644
--- a/library/qpeapplication.h
+++ b/library/qpeapplication.h
@@ -1,204 +1,207 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the 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
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __QPE_APPLICATION_H__ 20#ifndef __QPE_APPLICATION_H__
21#define __QPE_APPLICATION_H__ 21#define __QPE_APPLICATION_H__
22 22
23#include <stdlib.h> // for setenv() 23#include <stdlib.h> // for setenv()
24 24
25#include <qglobal.h> 25#include <qglobal.h>
26#include <qapplication.h> 26#include <qapplication.h>
27#include <qdialog.h> 27#include <qdialog.h>
28#include <qwsdisplay_qws.h> 28#include <qwsdisplay_qws.h>
29#if defined(_WS_QWS_) && !defined(Q_WS_QWS) 29#if defined(_WS_QWS_) && !defined(Q_WS_QWS)
30#define Q_WS_QWS 30#define Q_WS_QWS
31#endif 31#endif
32#include "qpedecoration_qws.h" 32#include "qpedecoration_qws.h"
33#include "timestring.h" 33#include "timestring.h"
34 34
35class QCopChannel; 35class QCopChannel;
36class QPEApplicationData; 36class QPEApplicationData;
37class QWSEvent; 37class QWSEvent;
38class QWSKeyEvent; 38class QWSKeyEvent;
39 39
40 40
41class QPEApplication : public QApplication 41class QPEApplication : public QApplication
42{ 42{
43 Q_OBJECT 43 Q_OBJECT
44public: 44public:
45 QPEApplication( int& argc, char **argv, Type=GuiClient ); 45 QPEApplication( int& argc, char **argv, Type=GuiClient );
46 ~QPEApplication(); 46 ~QPEApplication();
47 47
48 static QString qpeDir(); 48 static QString qpeDir();
49 static QString documentDir(); 49 static QString documentDir();
50 void applyStyle(); 50 void applyStyle();
51 static int defaultRotation(); 51 static int defaultRotation();
52 static void setDefaultRotation(int r); 52 static void setDefaultRotation(int r);
53 static void setCurrentRotation(int r); 53 static void setCurrentRotation(int r);
54 static void grabKeyboard(); 54 static void grabKeyboard();
55 static void ungrabKeyboard(); 55 static void ungrabKeyboard();
56 56
57 enum StylusMode { 57 enum StylusMode {
58 LeftOnly, 58 LeftOnly,
59 RightOnHold 59 RightOnHold
60 // RightOnHoldLeftDelayed, etc. 60 // RightOnHoldLeftDelayed, etc.
61 }; 61 };
62 static void setStylusOperation( QWidget*, StylusMode ); 62 static void setStylusOperation( QWidget*, StylusMode );
63 static StylusMode stylusOperation( QWidget* ); 63 static StylusMode stylusOperation( QWidget* );
64 64
65 enum InputMethodHint { 65 enum InputMethodHint {
66 Normal, 66 Normal,
67 AlwaysOff, 67 AlwaysOff,
68 AlwaysOn 68 AlwaysOn
69 }; 69 };
70 70
71 enum screenSaverHint { 71 enum screenSaverHint {
72 Disable = 0, 72 Disable = 0,
73 DisableLightOff = 1, 73 DisableLightOff = 1,
74 DisableSuspend = 2, 74 DisableSuspend = 2,
75 Enable = 100 75 Enable = 100
76 }; 76 };
77 77
78 static void setInputMethodHint( QWidget *, InputMethodHint ); 78 static void setInputMethodHint( QWidget *, InputMethodHint );
79 static InputMethodHint inputMethodHint( QWidget * ); 79 static InputMethodHint inputMethodHint( QWidget * );
80 80
81 void showMainWidget( QWidget*, bool nomax=FALSE ); 81 void showMainWidget( QWidget*, bool nomax=FALSE );
82 void showMainDocumentWidget( QWidget*, bool nomax=FALSE ); 82 void showMainDocumentWidget( QWidget*, bool nomax=FALSE );
83 static void showDialog( QDialog*, bool nomax=FALSE ); 83 static void showDialog( QDialog*, bool nomax=FALSE );
84 static int execDialog( QDialog*, bool nomax=FALSE ); 84 static int execDialog( QDialog*, bool nomax=FALSE );
85 /* Merge setTempScreenSaverMode */ 85 /* Merge setTempScreenSaverMode */
86#ifdef QTOPIA_INTERNAL_INITAPP 86#ifdef QTOPIA_INTERNAL_INITAPP
87 void initApp( int argv, char **argv ); 87 void initApp( int argv, char **argv );
88#endif 88#endif
89 89
90 static void setKeepRunning(); 90 static void setKeepRunning();
91 bool keepRunning() const; 91 bool keepRunning() const;
92 92
93 bool keyboardGrabbed() const; 93 bool keyboardGrabbed() const;
94 94
95 int exec(); 95 int exec();
96 96
97signals: 97signals:
98 void clientMoused(); 98 void clientMoused();
99 void timeChanged(); 99 void timeChanged();
100 void clockChanged( bool pm ); 100 void clockChanged( bool pm );
101 void micChanged( bool muted ); 101 void micChanged( bool muted );
102 void volumeChanged( bool muted ); 102 void volumeChanged( bool muted );
103 void appMessage( const QCString& msg, const QByteArray& data); 103 void appMessage( const QCString& msg, const QByteArray& data);
104 void weekChanged( bool startOnMonday ); 104 void weekChanged( bool startOnMonday );
105 void dateFormatChanged( DateFormat ); 105 void dateFormatChanged( DateFormat );
106 void flush(); 106 void flush();
107 void reload(); 107 void reload();
108 /* linkChanged signal */ 108 /* linkChanged signal */
109 109
110private slots: 110private slots:
111 void systemMessage( const QCString &msg, const QByteArray &data ); 111 void systemMessage( const QCString &msg, const QByteArray &data );
112 void pidMessage( const QCString &msg, const QByteArray &data ); 112 void pidMessage( const QCString &msg, const QByteArray &data );
113 void removeSenderFromStylusDict(); 113 void removeSenderFromStylusDict();
114 void hideOrQuit(); 114 void hideOrQuit();
115 115
116private:
117 inline QWidget *nextWidget( QWidgetList*, QWidget* );
118
116protected: 119protected:
117 bool qwsEventFilter( QWSEvent * ); 120 bool qwsEventFilter( QWSEvent * );
118 void internalSetStyle( const QString &style ); 121 void internalSetStyle( const QString &style );
119 void prepareForTermination(bool willrestart); 122 void prepareForTermination(bool willrestart);
120 virtual void restart(); 123 virtual void restart();
121 virtual void shutdown(); 124 virtual void shutdown();
122 bool eventFilter( QObject *, QEvent * ); 125 bool eventFilter( QObject *, QEvent * );
123 void timerEvent( QTimerEvent * ); 126 void timerEvent( QTimerEvent * );
124 bool raiseAppropriateWindow(); 127 bool raiseAppropriateWindow();
125 virtual void tryQuit(); 128 virtual void tryQuit();
126#if QT_VERSION > 233 129#if QT_VERSION > 233
127 virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!) 130 virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!)
128#endif 131#endif
129private: 132private:
130#ifndef QT_NO_TRANSLATION 133#ifndef QT_NO_TRANSLATION
131 void installTranslation( const QString& baseName ); 134 void installTranslation( const QString& baseName );
132#endif 135#endif
133 void mapToDefaultAction( QWSKeyEvent *ke, int defKey ); 136 void mapToDefaultAction( QWSKeyEvent *ke, int defKey );
134 void processQCopFile(); 137 void processQCopFile();
135 138
136#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 139#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
137 QCopChannel *sysChannel; 140 QCopChannel *sysChannel;
138 QCopChannel *pidChannel; 141 QCopChannel *pidChannel;
139#endif 142#endif
140 QPEApplicationData *d; 143 QPEApplicationData *d;
141 144
142 bool reserved_sh; 145 bool reserved_sh;
143 146
144 147
145 148
146}; 149};
147 150
148inline void QPEApplication::showDialog( QDialog* d, bool nomax ) 151inline void QPEApplication::showDialog( QDialog* d, bool nomax )
149{ 152{
150 QSize sh = d->sizeHint(); 153 QSize sh = d->sizeHint();
151 int w = QMAX(sh.width(),d->width()); 154 int w = QMAX(sh.width(),d->width());
152 int h = QMAX(sh.height(),d->height()); 155 int h = QMAX(sh.height(),d->height());
153 if ( !nomax 156 if ( !nomax
154 && ( w > qApp->desktop()->width()*3/4 157 && ( w > qApp->desktop()->width()*3/4
155 || h > qApp->desktop()->height()*3/4 ) ) 158 || h > qApp->desktop()->height()*3/4 ) )
156 { 159 {
157 d->showMaximized(); 160 d->showMaximized();
158 } else { 161 } else {
159 d->resize(w,h); 162 d->resize(w,h);
160 d->show(); 163 d->show();
161 } 164 }
162} 165}
163 166
164inline int QPEApplication::execDialog( QDialog* d, bool nomax ) 167inline int QPEApplication::execDialog( QDialog* d, bool nomax )
165{ 168{
166 showDialog(d,nomax); 169 showDialog(d,nomax);
167 return d->exec(); 170 return d->exec();
168} 171}
169 172
170enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */ 173enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */
171 174
172inline int TransToDeg ( Transformation t ) 175inline int TransToDeg ( Transformation t )
173{ 176{
174 int d = static_cast<int>( t ); 177 int d = static_cast<int>( t );
175 return d * 90; 178 return d * 90;
176} 179}
177 180
178inline Transformation DegToTrans ( int d ) 181inline Transformation DegToTrans ( int d )
179{ 182{
180 Transformation t = static_cast<Transformation>( d / 90 ); 183 Transformation t = static_cast<Transformation>( d / 90 );
181 return t; 184 return t;
182} 185}
183 186
184/* 187/*
185 * Set current rotation of Opie, and rotation for newly started apps. 188 * Set current rotation of Opie, and rotation for newly started apps.
186 * Differs from setDefaultRotation in that 1) it rotates currently running apps, 189 * Differs from setDefaultRotation in that 1) it rotates currently running apps,
187 * and 2) does not set deforient or save orientation to qpe.conf. 190 * and 2) does not set deforient or save orientation to qpe.conf.
188 */ 191 */
189 192
190inline void QPEApplication::setCurrentRotation( int r ) 193inline void QPEApplication::setCurrentRotation( int r )
191{ 194{
192 // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots 195 // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots
193 // for compatibility with the SharpROM use fallback to setDefaultTransformation() 196 // for compatibility with the SharpROM use fallback to setDefaultTransformation()
194 #if QT_VERSION > 233 197#if QT_VERSION > 233
195 Transformation e = DegToTrans( r ); 198 Transformation e = DegToTrans( r );
196 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 199 ::setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
197 qApp->desktop()->qwsDisplay()->setTransformation( e ); 200 qApp->desktop()->qwsDisplay()->setTransformation( e );
198 #else 201#else
199 setDefaultRotation( r ); 202 setDefaultRotation( r );
200 #endif 203#endif
201} 204}
202 205
203 206
204#endif 207#endif