summaryrefslogtreecommitdiff
path: root/library
authorzecke <zecke>2003-09-30 08:28:21 (UTC)
committer zecke <zecke>2003-09-30 08:28:21 (UTC)
commit4dd842eacb6c04303932e4cbebedff14db7cbc87 (patch) (unidiff)
treefce6ebe83d9c3863b1cf9313a264c85014a716dc /library
parent5430b226e390cc9af6a3257d6998e34bf806c9e2 (diff)
downloadopie-4dd842eacb6c04303932e4cbebedff14db7cbc87.zip
opie-4dd842eacb6c04303932e4cbebedff14db7cbc87.tar.gz
opie-4dd842eacb6c04303932e4cbebedff14db7cbc87.tar.bz2
Use a QQueue as in Qtopia
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 4d0b0ea..98af70a 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,925 +1,927 @@
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#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <stdlib.h> 21#include <stdlib.h>
22#include <unistd.h> 22#include <unistd.h>
23#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 23#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
24#include <qfile.h> 24#include <qfile.h>
25#include <qqueue.h>
25#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
26#ifndef QT_NO_COP 27#ifndef QT_NO_COP
27#if QT_VERSION <= 231 28#if QT_VERSION <= 231
28#define private public 29#define private public
29#define sendLocally processEvent 30#define sendLocally processEvent
30#include "qcopenvelope_qws.h" 31#include "qcopenvelope_qws.h"
31#undef private 32#undef private
32#else 33#else
33#include "qcopenvelope_qws.h" 34#include "qcopenvelope_qws.h"
34#endif 35#endif
35#endif 36#endif
36#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
37#endif 38#endif
38#include <qtextstream.h> 39#include <qtextstream.h>
39#include <qpalette.h> 40#include <qpalette.h>
40#include <qbuffer.h> 41#include <qbuffer.h>
41#include <qptrdict.h> 42#include <qptrdict.h>
42#include <qregexp.h> 43#include <qregexp.h>
43#include <qdir.h> 44#include <qdir.h>
44#include <qlabel.h> 45#include <qlabel.h>
45#include <qdialog.h> 46#include <qdialog.h>
46#include <qdragobject.h> 47#include <qdragobject.h>
47#include <qtextcodec.h> 48#include <qtextcodec.h>
48#include <qevent.h> 49#include <qevent.h>
49#include <qtooltip.h> 50#include <qtooltip.h>
50#include <qsignal.h> 51#include <qsignal.h>
51#include <qmainwindow.h> 52#include <qmainwindow.h>
52#include <qwidgetlist.h> 53#include <qwidgetlist.h>
53 54
54#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 55#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
55#define QTOPIA_INTERNAL_INITAPP 56#define QTOPIA_INTERNAL_INITAPP
56#include "qpeapplication.h" 57#include "qpeapplication.h"
57#include "qpestyle.h" 58#include "qpestyle.h"
58#include "styleinterface.h" 59#include "styleinterface.h"
59#if QT_VERSION >= 300 60#if QT_VERSION >= 300
60#include <qstylefactory.h> 61#include <qstylefactory.h>
61#else 62#else
62#include <qplatinumstyle.h> 63#include <qplatinumstyle.h>
63#include <qwindowsstyle.h> 64#include <qwindowsstyle.h>
64#include <qmotifstyle.h> 65#include <qmotifstyle.h>
65#include <qmotifplusstyle.h> 66#include <qmotifplusstyle.h>
66#include "lightstyle.h" 67#include "lightstyle.h"
67 68
68#include <qpe/qlibrary.h> 69#include <qpe/qlibrary.h>
69#endif 70#endif
70#include "global.h" 71#include "global.h"
71#include "resource.h" 72#include "resource.h"
72#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 73#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
73#include "qutfcodec.h" 74#include "qutfcodec.h"
74#endif 75#endif
75#include "config.h" 76#include "config.h"
76#include "network.h" 77#include "network.h"
77#ifdef QWS 78#ifdef QWS
78#include "fontmanager.h" 79#include "fontmanager.h"
79#endif 80#endif
80 81
81#include "alarmserver.h" 82#include "alarmserver.h"
82#include "applnk.h" 83#include "applnk.h"
83#include "qpemenubar.h" 84#include "qpemenubar.h"
84#include "textcodecinterface.h" 85#include "textcodecinterface.h"
85#include "imagecodecinterface.h" 86#include "imagecodecinterface.h"
86 87
87#include <unistd.h> 88#include <unistd.h>
88#include <sys/file.h> 89#include <sys/file.h>
89#include <sys/ioctl.h> 90#include <sys/ioctl.h>
90#include <sys/soundcard.h> 91#include <sys/soundcard.h>
91 92
92#include "qt_override_p.h" 93#include "qt_override_p.h"
93 94
94 95
95class QPEApplicationData 96class QPEApplicationData
96{ 97{
97public: 98public:
98 QPEApplicationData ( ) 99 QPEApplicationData ( )
99 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 100 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
100 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 101 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
101 keep_running( true ), qpe_main_widget( 0 ), qcopQok( false ) 102 keep_running( true ), qpe_main_widget( 0 ), qcopQok( false )
102 103
103 { 104 {}
104 qcopq.setAutoDelete( TRUE );
105 }
106 105
107 int presstimer; 106 int presstimer;
108 QWidget* presswidget; 107 QWidget* presswidget;
109 QPoint presspos; 108 QPoint presspos;
110 109
111 bool rightpressed : 1; 110 bool rightpressed : 1;
112 bool kbgrabbed : 1; 111 bool kbgrabbed : 1;
113 bool notbusysent : 1; 112 bool notbusysent : 1;
114 bool preloaded : 1; 113 bool preloaded : 1;
115 bool forceshow : 1; 114 bool forceshow : 1;
116 bool nomaximize : 1; 115 bool nomaximize : 1;
117 bool qcopQok : 1; 116 bool qcopQok : 1;
118 bool keep_running : 1; 117 bool keep_running : 1;
119 118
120 119
121 QStringList langs; 120 QStringList langs;
122 QString appName; 121 QString appName;
123 struct QCopRec 122 struct QCopRec
124 { 123 {
125 QCopRec( const QCString &ch, const QCString &msg, 124 QCopRec( const QCString &ch, const QCString &msg,
126 const QByteArray &d ) : 125 const QByteArray &d ) :
127 channel( ch ), message( msg ), data( d ) 126 channel( ch ), message( msg ), data( d )
128 { } 127 { }
129 128
130 QCString channel; 129 QCString channel;
131 QCString message; 130 QCString message;
132 QByteArray data; 131 QByteArray data;
133 }; 132 };
134 QWidget* qpe_main_widget; 133 QWidget* qpe_main_widget;
135 QGuardedPtr<QWidget> lastraised; 134 QGuardedPtr<QWidget> lastraised;
136 QList<QCopRec> qcopq; 135 QQueue<QCopRec> qcopq;
137 QString styleName; 136 QString styleName;
138 QString decorationName; 137 QString decorationName;
139 138
140 void enqueueQCop( const QCString &ch, const QCString &msg, 139 void enqueueQCop( const QCString &ch, const QCString &msg,
141 const QByteArray &data ) 140 const QByteArray &data )
142 { 141 {
143 qcopq.append( new QCopRec( ch, msg, data ) ); 142 qcopq.enqueue( new QCopRec( ch, msg, data ) );
144 } 143 }
145 void sendQCopQ() 144 void sendQCopQ()
146 { 145 {
147 if (!qcopQok ) 146 if (!qcopQok )
148 return; 147 return;
149 148
150 QCopRec * r; 149 QCopRec * r;
151#ifndef QT_NO_COP 150#ifndef QT_NO_COP
152 151 while((r=qcopq.dequeue())) {
153 for ( QListIterator<QCopRec> it( qcopq ); ( r = it.current() ); ++it ) 152 // remove from queue before sending...
154 QCopChannel::sendLocally( r->channel, r->message, r->data ); 153 // event loop can come around again before getting
154 // back from sendLocally
155 QCopChannel::sendLocally( r->channel, r->message, r->data );
155#endif 156#endif
156 157
157 qcopq.clear(); 158 delete r;
159 }
158 } 160 }
159 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) 161 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null )
160 { 162 {
161 163
162 // ugly hack, remove that later after finding a sane solution 164 // ugly hack, remove that later after finding a sane solution
163 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 165 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
164 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has 166 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
165 // a (physically) large enough display to use the small icons 167 // a (physically) large enough display to use the small icons
166#ifndef QT_QWS_SIMPAD 168#ifndef QT_QWS_SIMPAD
167 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 169 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
168 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 170 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
169 } 171 }
170#endif 172#endif
171 173
172 if ( mw->layout() && mw->inherits("QDialog") ) { 174 if ( mw->layout() && mw->inherits("QDialog") ) {
173 QPEApplication::showDialog((QDialog*)mw, nomaximize); 175 QPEApplication::showDialog((QDialog*)mw, nomaximize);
174 } 176 }
175 else { 177 else {
176#ifdef Q_WS_QWS 178#ifdef Q_WS_QWS
177 if ( !nomaximize ) 179 if ( !nomaximize )
178 mw->showMaximized(); 180 mw->showMaximized();
179 else 181 else
180#endif 182#endif
181 183
182 mw->show(); 184 mw->show();
183 } 185 }
184 } 186 }
185 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 187 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
186 { 188 {
187 /* 189 /*
188 // This works but disable it for now until it is safe to apply 190 // This works but disable it for now until it is safe to apply
189 // What is does is scan the .desktop files of all the apps for 191 // What is does is scan the .desktop files of all the apps for
190 // the applnk that has the corresponding argv[0] as this program 192 // the applnk that has the corresponding argv[0] as this program
191 // then it uses the name stored in the .desktop file as the caption 193 // then it uses the name stored in the .desktop file as the caption
192 // for the main widget. This saves duplicating translations for 194 // for the main widget. This saves duplicating translations for
193 // the app name in the program and in the .desktop files. 195 // the app name in the program and in the .desktop files.
194 196
195 AppLnkSet apps( appsPath ); 197 AppLnkSet apps( appsPath );
196 198
197 QList<AppLnk> appsList = apps.children(); 199 QList<AppLnk> appsList = apps.children();
198 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 200 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
199 if ( (*it)->exec() == appName ) { 201 if ( (*it)->exec() == appName ) {
200 mw->setCaption( (*it)->name() ); 202 mw->setCaption( (*it)->name() );
201 return TRUE; 203 return TRUE;
202 } 204 }
203 } 205 }
204 */ 206 */
205 return FALSE; 207 return FALSE;
206 } 208 }
207 209
208 210
209 void show(QWidget* mw, bool nomax) 211 void show(QWidget* mw, bool nomax)
210 { 212 {
211 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 213 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
212 nomaximize = nomax; 214 nomaximize = nomax;
213 qpe_main_widget = mw; 215 qpe_main_widget = mw;
214#ifndef QT_NO_COP 216#ifndef QT_NO_COP
215 217
216 sendQCopQ(); 218 sendQCopQ();
217#endif 219#endif
218 220
219 if ( preloaded ) { 221 if ( preloaded ) {
220 if (forceshow) 222 if (forceshow)
221 show_mx(mw, nomax); 223 show_mx(mw, nomax);
222 } 224 }
223 else if ( keep_running ) { 225 else if ( keep_running ) {
224 show_mx(mw, nomax); 226 show_mx(mw, nomax);
225 } 227 }
226 } 228 }
227 229
228 void loadTextCodecs() 230 void loadTextCodecs()
229 { 231 {
230 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 232 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
231 QDir dir( path, "lib*.so" ); 233 QDir dir( path, "lib*.so" );
232 QStringList list; 234 QStringList list;
233 if ( dir. exists ( )) 235 if ( dir. exists ( ))
234 list = dir.entryList(); 236 list = dir.entryList();
235 QStringList::Iterator it; 237 QStringList::Iterator it;
236 for ( it = list.begin(); it != list.end(); ++it ) { 238 for ( it = list.begin(); it != list.end(); ++it ) {
237 TextCodecInterface *iface = 0; 239 TextCodecInterface *iface = 0;
238 QLibrary *lib = new QLibrary( path + "/" + *it ); 240 QLibrary *lib = new QLibrary( path + "/" + *it );
239 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 241 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
240 QValueList<int> mibs = iface->mibEnums(); 242 QValueList<int> mibs = iface->mibEnums();
241 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 243 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
242 (void)iface->createForMib(*i); 244 (void)iface->createForMib(*i);
243 // ### it exists now; need to remember if we can delete it 245 // ### it exists now; need to remember if we can delete it
244 } 246 }
245 } 247 }
246 else { 248 else {
247 lib->unload(); 249 lib->unload();
248 delete lib; 250 delete lib;
249 } 251 }
250 } 252 }
251 } 253 }
252 254
253 void loadImageCodecs() 255 void loadImageCodecs()
254 { 256 {
255 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 257 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
256 QDir dir( path, "lib*.so" ); 258 QDir dir( path, "lib*.so" );
257 QStringList list; 259 QStringList list;
258 if ( dir. exists ( )) 260 if ( dir. exists ( ))
259 list = dir.entryList(); 261 list = dir.entryList();
260 QStringList::Iterator it; 262 QStringList::Iterator it;
261 for ( it = list.begin(); it != list.end(); ++it ) { 263 for ( it = list.begin(); it != list.end(); ++it ) {
262 ImageCodecInterface *iface = 0; 264 ImageCodecInterface *iface = 0;
263 QLibrary *lib = new QLibrary( path + "/" + *it ); 265 QLibrary *lib = new QLibrary( path + "/" + *it );
264 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 266 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
265 QStringList formats = iface->keys(); 267 QStringList formats = iface->keys();
266 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 268 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
267 (void)iface->installIOHandler(*i); 269 (void)iface->installIOHandler(*i);
268 // ### it exists now; need to remember if we can delete it 270 // ### it exists now; need to remember if we can delete it
269 } 271 }
270 } 272 }
271 else { 273 else {
272 lib->unload(); 274 lib->unload();
273 delete lib; 275 delete lib;
274 } 276 }
275 } 277 }
276 } 278 }
277}; 279};
278 280
279class ResourceMimeFactory : public QMimeSourceFactory 281class ResourceMimeFactory : public QMimeSourceFactory
280{ 282{
281public: 283public:
282 ResourceMimeFactory() : resImage( 0 ) 284 ResourceMimeFactory() : resImage( 0 )
283 { 285 {
284 setFilePath( Global::helpPath() ); 286 setFilePath( Global::helpPath() );
285 setExtensionType( "html", "text/html;charset=UTF-8" ); 287 setExtensionType( "html", "text/html;charset=UTF-8" );
286 } 288 }
287 ~ResourceMimeFactory() { 289 ~ResourceMimeFactory() {
288 delete resImage; 290 delete resImage;
289 } 291 }
290 292
291 const QMimeSource* data( const QString& abs_name ) const 293 const QMimeSource* data( const QString& abs_name ) const
292 { 294 {
293 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 295 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
294 if ( !r ) { 296 if ( !r ) {
295 int sl = abs_name.length(); 297 int sl = abs_name.length();
296 do { 298 do {
297 sl = abs_name.findRev( '/', sl - 1 ); 299 sl = abs_name.findRev( '/', sl - 1 );
298 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 300 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
299 int dot = name.findRev( '.' ); 301 int dot = name.findRev( '.' );
300 if ( dot >= 0 ) 302 if ( dot >= 0 )
301 name = name.left( dot ); 303 name = name.left( dot );
302 QImage img = Resource::loadImage( name ); 304 QImage img = Resource::loadImage( name );
303 if ( !img.isNull() ) { 305 if ( !img.isNull() ) {
304 delete resImage; 306 delete resImage;
305 resImage = new QImageDrag( img ); 307 resImage = new QImageDrag( img );
306 r = resImage; 308 r = resImage;
307 } 309 }
308 } 310 }
309 while ( !r && sl > 0 ); 311 while ( !r && sl > 0 );
310 } 312 }
311 return r; 313 return r;
312 } 314 }
313private: 315private:
314 mutable QImageDrag *resImage; 316 mutable QImageDrag *resImage;
315}; 317};
316 318
317static int& hack(int& i) 319static int& hack(int& i)
318{ 320{
319#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 321#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
320 // These should be created, but aren't in Qt 2.3.0 322 // These should be created, but aren't in Qt 2.3.0
321 (void)new QUtf8Codec; 323 (void)new QUtf8Codec;
322 (void)new QUtf16Codec; 324 (void)new QUtf16Codec;
323#endif 325#endif
324 return i; 326 return i;
325} 327}
326 328
327static int muted = 0; 329static int muted = 0;
328static int micMuted = 0; 330static int micMuted = 0;
329 331
330static void setVolume( int t = 0, int percent = -1 ) 332static void setVolume( int t = 0, int percent = -1 )
331{ 333{
332 switch ( t ) { 334 switch ( t ) {
333 case 0: { 335 case 0: {
334 Config cfg( "qpe" ); 336 Config cfg( "qpe" );
335 cfg.setGroup( "Volume" ); 337 cfg.setGroup( "Volume" );
336 if ( percent < 0 ) 338 if ( percent < 0 )
337 percent = cfg.readNumEntry( "VolumePercent", 50 ); 339 percent = cfg.readNumEntry( "VolumePercent", 50 );
338 int fd = 0; 340 int fd = 0;
339 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 341 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
340 int vol = muted ? 0 : percent; 342 int vol = muted ? 0 : percent;
341 // set both channels to same volume 343 // set both channels to same volume
342 vol |= vol << 8; 344 vol |= vol << 8;
343 ioctl( fd, MIXER_WRITE( 0 ), &vol ); 345 ioctl( fd, MIXER_WRITE( 0 ), &vol );
344 ::close( fd ); 346 ::close( fd );
345 } 347 }
346 } 348 }
347 break; 349 break;
348 } 350 }
349} 351}
350 352
351static void setMic( int t = 0, int percent = -1 ) 353static void setMic( int t = 0, int percent = -1 )
352{ 354{
353 switch ( t ) { 355 switch ( t ) {
354 case 0: { 356 case 0: {
355 Config cfg( "qpe" ); 357 Config cfg( "qpe" );
356 cfg.setGroup( "Volume" ); 358 cfg.setGroup( "Volume" );
357 if ( percent < 0 ) 359 if ( percent < 0 )
358 percent = cfg.readNumEntry( "Mic", 50 ); 360 percent = cfg.readNumEntry( "Mic", 50 );
359 361
360 int fd = 0; 362 int fd = 0;
361 int mic = micMuted ? 0 : percent; 363 int mic = micMuted ? 0 : percent;
362 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 364 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
363 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 365 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
364 ::close( fd ); 366 ::close( fd );
365 } 367 }
366 } 368 }
367 break; 369 break;
368 } 370 }
369} 371}
370 372
371 373
372static void setBass( int t = 0, int percent = -1 ) 374static void setBass( int t = 0, int percent = -1 )
373{ 375{
374 switch ( t ) { 376 switch ( t ) {
375 case 0: { 377 case 0: {
376 Config cfg( "qpe" ); 378 Config cfg( "qpe" );
377 cfg.setGroup( "Volume" ); 379 cfg.setGroup( "Volume" );
378 if ( percent < 0 ) 380 if ( percent < 0 )
379 percent = cfg.readNumEntry( "BassPercent", 50 ); 381 percent = cfg.readNumEntry( "BassPercent", 50 );
380 382
381 int fd = 0; 383 int fd = 0;
382 int bass = percent; 384 int bass = percent;
383 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 385 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
384 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 386 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
385 ::close( fd ); 387 ::close( fd );
386 } 388 }
387 } 389 }
388 break; 390 break;
389 } 391 }
390} 392}
391 393
392 394
393static void setTreble( int t = 0, int percent = -1 ) 395static void setTreble( int t = 0, int percent = -1 )
394{ 396{
395 switch ( t ) { 397 switch ( t ) {
396 case 0: { 398 case 0: {
397 Config cfg( "qpe" ); 399 Config cfg( "qpe" );
398 cfg.setGroup( "Volume" ); 400 cfg.setGroup( "Volume" );
399 if ( percent < 0 ) 401 if ( percent < 0 )
400 percent = cfg.readNumEntry( "TreblePercent", 50 ); 402 percent = cfg.readNumEntry( "TreblePercent", 50 );
401 403
402 int fd = 0; 404 int fd = 0;
403 int treble = percent; 405 int treble = percent;
404 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 406 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
405 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 407 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
406 ::close( fd ); 408 ::close( fd );
407 } 409 }
408 } 410 }
409 break; 411 break;
410 } 412 }
411} 413}
412 414
413 415
414/*! 416/*!
415 \class QPEApplication qpeapplication.h 417 \class QPEApplication qpeapplication.h
416 \brief The QPEApplication class implements various system services 418 \brief The QPEApplication class implements various system services
417 that are available to all Qtopia applications. 419 that are available to all Qtopia applications.
418 420
419 Simply by using QPEApplication instead of QApplication, a standard Qt 421 Simply by using QPEApplication instead of QApplication, a standard Qt
420 application becomes a Qtopia application. It automatically follows 422 application becomes a Qtopia application. It automatically follows
421 style changes, quits and raises, and in the 423 style changes, quits and raises, and in the
422 case of \link docwidget.html document-oriented\endlink applications, 424 case of \link docwidget.html document-oriented\endlink applications,
423 changes the currently displayed document in response to the environment. 425 changes the currently displayed document in response to the environment.
424 426
425 To create a \link docwidget.html document-oriented\endlink 427 To create a \link docwidget.html document-oriented\endlink
426 application use showMainDocumentWidget(); to create a 428 application use showMainDocumentWidget(); to create a
427 non-document-oriented application use showMainWidget(). The 429 non-document-oriented application use showMainWidget(). The
428 keepRunning() function indicates whether the application will 430 keepRunning() function indicates whether the application will
429 continue running after it's processed the last \link qcop.html 431 continue running after it's processed the last \link qcop.html
430 QCop\endlink message. This can be changed using setKeepRunning(). 432 QCop\endlink message. This can be changed using setKeepRunning().
431 433
432 A variety of signals are emitted when certain events occur, for 434 A variety of signals are emitted when certain events occur, for
433 example, timeChanged(), clockChanged(), weekChanged(), 435 example, timeChanged(), clockChanged(), weekChanged(),
434 dateFormatChanged() and volumeChanged(). If the application receives 436 dateFormatChanged() and volumeChanged(). If the application receives
435 a \link qcop.html QCop\endlink message on the application's 437 a \link qcop.html QCop\endlink message on the application's
436 QPE/Application/\e{appname} channel, the appMessage() signal is 438 QPE/Application/\e{appname} channel, the appMessage() signal is
437 emitted. There are also flush() and reload() signals, which 439 emitted. There are also flush() and reload() signals, which
438 are emitted when synching begins and ends respectively - upon these 440 are emitted when synching begins and ends respectively - upon these
439 signals, the application should save and reload any data 441 signals, the application should save and reload any data
440 files that are involved in synching. Most of these signals will initially 442 files that are involved in synching. Most of these signals will initially
441 be received and unfiltered through the appMessage() signal. 443 be received and unfiltered through the appMessage() signal.
442 444
443 This class also provides a set of useful static functions. The 445 This class also provides a set of useful static functions. The
444 qpeDir() and documentDir() functions return the respective paths. 446 qpeDir() and documentDir() functions return the respective paths.
445 The grabKeyboard() and ungrabKeyboard() functions are used to 447 The grabKeyboard() and ungrabKeyboard() functions are used to
446 control whether the application takes control of the device's 448 control whether the application takes control of the device's
447 physical buttons (e.g. application launch keys). The stylus' mode of 449 physical buttons (e.g. application launch keys). The stylus' mode of
448 operation is set with setStylusOperation() and retrieved with 450 operation is set with setStylusOperation() and retrieved with
449 stylusOperation(). There are also setInputMethodHint() and 451 stylusOperation(). There are also setInputMethodHint() and
450 inputMethodHint() functions. 452 inputMethodHint() functions.
451 453
452 \ingroup qtopiaemb 454 \ingroup qtopiaemb
453*/ 455*/
454 456
455/*! 457/*!
456 \fn void QPEApplication::clientMoused() 458 \fn void QPEApplication::clientMoused()
457 459
458 \internal 460 \internal
459*/ 461*/
460 462
461/*! 463/*!
462 \fn void QPEApplication::timeChanged(); 464 \fn void QPEApplication::timeChanged();
463 This signal is emitted when the time changes outside the normal 465 This signal is emitted when the time changes outside the normal
464 passage of time, i.e. if the time is set backwards or forwards. 466 passage of time, i.e. if the time is set backwards or forwards.
465*/ 467*/
466 468
467/*! 469/*!
468 \fn void QPEApplication::clockChanged( bool ampm ); 470 \fn void QPEApplication::clockChanged( bool ampm );
469 471
470 This signal is emitted when the user changes the clock's style. If 472 This signal is emitted when the user changes the clock's style. If
471 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 473 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
472 they want a 24-hour clock. 474 they want a 24-hour clock.
473*/ 475*/
474 476
475/*! 477/*!
476 \fn void QPEApplication::volumeChanged( bool muted ) 478 \fn void QPEApplication::volumeChanged( bool muted )
477 479
478 This signal is emitted whenever the mute state is changed. If \a 480 This signal is emitted whenever the mute state is changed. If \a
479 muted is TRUE, then sound output has been muted. 481 muted is TRUE, then sound output has been muted.
480*/ 482*/
481 483
482/*! 484/*!
483 \fn void QPEApplication::weekChanged( bool startOnMonday ) 485 \fn void QPEApplication::weekChanged( bool startOnMonday )
484 486
485 This signal is emitted if the week start day is changed. If \a 487 This signal is emitted if the week start day is changed. If \a
486 startOnMonday is TRUE then the first day of the week is Monday; if 488 startOnMonday is TRUE then the first day of the week is Monday; if
487 \a startOnMonday is FALSE then the first day of the week is 489 \a startOnMonday is FALSE then the first day of the week is
488 Sunday. 490 Sunday.
489*/ 491*/
490 492
491/*! 493/*!
492 \fn void QPEApplication::dateFormatChanged(DateFormat) 494 \fn void QPEApplication::dateFormatChanged(DateFormat)
493 495
494 This signal is emitted whenever the date format is changed. 496 This signal is emitted whenever the date format is changed.
495*/ 497*/
496 498
497/*! 499/*!
498 \fn void QPEApplication::flush() 500 \fn void QPEApplication::flush()
499 501
500 ### 502 ###
501*/ 503*/
502 504
503/*! 505/*!
504 \fn void QPEApplication::reload() 506 \fn void QPEApplication::reload()
505 507
506*/ 508*/
507 509
508 510
509 511
510void QPEApplication::processQCopFile() 512void QPEApplication::processQCopFile()
511{ 513{
512 QString qcopfn("/tmp/qcop-msg-"); 514 QString qcopfn("/tmp/qcop-msg-");
513 qcopfn += d->appName; // append command name 515 qcopfn += d->appName; // append command name
514 516
515 QFile f(qcopfn); 517 QFile f(qcopfn);
516 if ( f.open(IO_ReadWrite) ) { 518 if ( f.open(IO_ReadWrite) ) {
517#ifndef Q_OS_WIN32 519#ifndef Q_OS_WIN32
518 flock(f.handle(), LOCK_EX); 520 flock(f.handle(), LOCK_EX);
519#endif 521#endif
520 QDataStream ds(&f); 522 QDataStream ds(&f);
521 QCString channel, message; 523 QCString channel, message;
522 QByteArray data; 524 QByteArray data;
523 while(!ds.atEnd()) { 525 while(!ds.atEnd()) {
524 ds >> channel >> message >> data; 526 ds >> channel >> message >> data;
525 d->enqueueQCop(channel,message,data); 527 d->enqueueQCop(channel,message,data);
526 } 528 }
527 ::ftruncate(f.handle(), 0); 529 ::ftruncate(f.handle(), 0);
528#ifndef Q_OS_WIN32 530#ifndef Q_OS_WIN32
529 f.flush(); 531 f.flush();
530 flock(f.handle(), LOCK_UN); 532 flock(f.handle(), LOCK_UN);
531#endif 533#endif
532 } 534 }
533#endif 535#endif
534} 536}
535 537
536 538
537/*! 539/*!
538 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 540 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
539 541
540 This signal is emitted when a message is received on this 542 This signal is emitted when a message is received on this
541 application's QPE/Application/<i>appname</i> \link qcop.html 543 application's QPE/Application/<i>appname</i> \link qcop.html
542 QCop\endlink channel. 544 QCop\endlink channel.
543 545
544 The slot to which you connect this signal uses \a msg and \a data 546 The slot to which you connect this signal uses \a msg and \a data
545 in the following way: 547 in the following way:
546 548
547\code 549\code
548 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 550 void MyWidget::receive( const QCString& msg, const QByteArray& data )
549 { 551 {
550 QDataStream stream( data, IO_ReadOnly ); 552 QDataStream stream( data, IO_ReadOnly );
551 if ( msg == "someMessage(int,int,int)" ) { 553 if ( msg == "someMessage(int,int,int)" ) {
552 int a,b,c; 554 int a,b,c;
553 stream >> a >> b >> c; 555 stream >> a >> b >> c;
554 ... 556 ...
555 } else if ( msg == "otherMessage(QString)" ) { 557 } else if ( msg == "otherMessage(QString)" ) {
556 ... 558 ...
557 } 559 }
558 } 560 }
559\endcode 561\endcode
560 562
561 \sa qcop.html 563 \sa qcop.html
562 Note that messages received here may be processed by qpe application 564 Note that messages received here may be processed by qpe application
563 and emitted as signals, such as flush() and reload(). 565 and emitted as signals, such as flush() and reload().
564*/ 566*/
565 567
566/*! 568/*!
567 Constructs a QPEApplication just as you would construct 569 Constructs a QPEApplication just as you would construct
568 a QApplication, passing \a argc, \a argv, and \a t. 570 a QApplication, passing \a argc, \a argv, and \a t.
569 571
570 For applications, \a t should be the default, GuiClient. Only 572 For applications, \a t should be the default, GuiClient. Only
571 the Qtopia server passes GuiServer. 573 the Qtopia server passes GuiServer.
572*/ 574*/
573QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 575QPEApplication::QPEApplication( int & argc, char **argv, Type t )
574 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 576 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
575{ 577{
576 d = new QPEApplicationData; 578 d = new QPEApplicationData;
577 d->loadTextCodecs(); 579 d->loadTextCodecs();
578 d->loadImageCodecs(); 580 d->loadImageCodecs();
579 int dw = desktop() ->width(); 581 int dw = desktop() ->width();
580 582
581 if ( dw < 200 ) { 583 if ( dw < 200 ) {
582 setFont( QFont( "vera", 8 ) ); 584 setFont( QFont( "vera", 8 ) );
583 AppLnk::setSmallIconSize( 10 ); 585 AppLnk::setSmallIconSize( 10 );
584 AppLnk::setBigIconSize( 28 ); 586 AppLnk::setBigIconSize( 28 );
585 } 587 }
586#ifndef QT_QWS_SIMPAD 588#ifndef QT_QWS_SIMPAD
587 else if ( dw > 600 ) { 589 else if ( dw > 600 ) {
588 setFont( QFont( "vera", 16 ) ); 590 setFont( QFont( "vera", 16 ) );
589 AppLnk::setSmallIconSize( 24 ); 591 AppLnk::setSmallIconSize( 24 );
590 AppLnk::setBigIconSize( 48 ); 592 AppLnk::setBigIconSize( 48 );
591 } 593 }
592#endif 594#endif
593 else if ( dw > 200 ) { 595 else if ( dw > 200 ) {
594 setFont( QFont( "vera", 10 ) ); 596 setFont( QFont( "vera", 10 ) );
595 AppLnk::setSmallIconSize( 14 ); 597 AppLnk::setSmallIconSize( 14 );
596 AppLnk::setBigIconSize( 32 ); 598 AppLnk::setBigIconSize( 32 );
597 } 599 }
598 600
599 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 601 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
600 602
601 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 603 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
602 604
603 605
604 sysChannel = new QCopChannel( "QPE/System", this ); 606 sysChannel = new QCopChannel( "QPE/System", this );
605 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 607 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
606 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 608 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
607 609
608/* COde now in initapp */ 610/* COde now in initapp */
609#if 0 611#if 0
610#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 612#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
611 613
612 QString qcopfn( "/tmp/qcop-msg-" ); 614 QString qcopfn( "/tmp/qcop-msg-" );
613 qcopfn += QString( argv[ 0 ] ); // append command name 615 qcopfn += QString( argv[ 0 ] ); // append command name
614 616
615 QFile f( qcopfn ); 617 QFile f( qcopfn );
616 if ( f.open( IO_ReadOnly ) ) { 618 if ( f.open( IO_ReadOnly ) ) {
617 flock( f.handle(), LOCK_EX ); 619 flock( f.handle(), LOCK_EX );
618 } 620 }
619 621
620 622
621 623
622 QCString channel = QCString( argv[ 0 ] ); 624 QCString channel = QCString( argv[ 0 ] );
623 channel.replace( QRegExp( ".*/" ), "" ); 625 channel.replace( QRegExp( ".*/" ), "" );
624 d->appName = channel; 626 d->appName = channel;
625 channel = "QPE/Application/" + channel; 627 channel = "QPE/Application/" + channel;
626 pidChannel = new QCopChannel( channel, this ); 628 pidChannel = new QCopChannel( channel, this );
627 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 629 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
628 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); 630 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
629 631
630 if ( f.isOpen() ) { 632 if ( f.isOpen() ) {
631 d->keep_running = FALSE; 633 d->keep_running = FALSE;
632 QDataStream ds( &f ); 634 QDataStream ds( &f );
633 QCString channel, message; 635 QCString channel, message;
634 QByteArray data; 636 QByteArray data;
635 while ( !ds.atEnd() ) { 637 while ( !ds.atEnd() ) {
636 ds >> channel >> message >> data; 638 ds >> channel >> message >> data;
637 d->enqueueQCop( channel, message, data ); 639 d->enqueueQCop( channel, message, data );
638 } 640 }
639 641
640 flock( f.handle(), LOCK_UN ); 642 flock( f.handle(), LOCK_UN );
641 f.close(); 643 f.close();
642 f.remove(); 644 f.remove();
643 } 645 }
644 646
645 for ( int a = 0; a < argc; a++ ) { 647 for ( int a = 0; a < argc; a++ ) {
646 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 648 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
647 argv[ a ] = argv[ a + 1 ]; 649 argv[ a ] = argv[ a + 1 ];
648 a++; 650 a++;
649 d->preloaded = TRUE; 651 d->preloaded = TRUE;
650 argc -= 1; 652 argc -= 1;
651 } 653 }
652 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 654 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
653 argv[ a ] = argv[ a + 1 ]; 655 argv[ a ] = argv[ a + 1 ];
654 a++; 656 a++;
655 d->preloaded = TRUE; 657 d->preloaded = TRUE;
656 d->forceshow = TRUE; 658 d->forceshow = TRUE;
657 argc -= 1; 659 argc -= 1;
658 } 660 }
659 } 661 }
660 662
661 /* overide stored arguments */ 663 /* overide stored arguments */
662 setArgs( argc, argv ); 664 setArgs( argc, argv );
663 665
664#endif 666#endif
665#else 667#else
666 initApp( argc, argv ); 668 initApp( argc, argv );
667#endif 669#endif
668 // qwsSetDecoration( new QPEDecoration() ); 670 // qwsSetDecoration( new QPEDecoration() );
669 671
670#ifndef QT_NO_TRANSLATION 672#ifndef QT_NO_TRANSLATION
671 673
672 d->langs = Global::languageList(); 674 d->langs = Global::languageList();
673 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 675 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
674 QString lang = *it; 676 QString lang = *it;
675 677
676 installTranslation( lang + "/libopie.qm"); 678 installTranslation( lang + "/libopie.qm");
677 installTranslation( lang + "/libqpe.qm" ); 679 installTranslation( lang + "/libqpe.qm" );
678 installTranslation( lang + "/" + d->appName + ".qm" ); 680 installTranslation( lang + "/" + d->appName + ".qm" );
679 681
680 682
681 //###language/font hack; should look it up somewhere 683 //###language/font hack; should look it up somewhere
682#ifdef QWS 684#ifdef QWS
683 685
684 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 686 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
685 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 687 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
686 setFont( fn ); 688 setFont( fn );
687 } 689 }
688#endif 690#endif
689 } 691 }
690#endif 692#endif
691 693
692 applyStyle(); 694 applyStyle();
693 695
694 if ( type() == GuiServer ) { 696 if ( type() == GuiServer ) {
695 setVolume(); 697 setVolume();
696 } 698 }
697 699
698 installEventFilter( this ); 700 installEventFilter( this );
699 701
700 QPEMenuToolFocusManager::initialize(); 702 QPEMenuToolFocusManager::initialize();
701 703
702#ifdef QT_NO_QWS_CURSOR 704#ifdef QT_NO_QWS_CURSOR
703 // if we have no cursor, probably don't want tooltips 705 // if we have no cursor, probably don't want tooltips
704 QToolTip::setEnabled( FALSE ); 706 QToolTip::setEnabled( FALSE );
705#endif 707#endif
706} 708}
707 709
708 710
709#ifdef QTOPIA_INTERNAL_INITAPP 711#ifdef QTOPIA_INTERNAL_INITAPP
710void QPEApplication::initApp( int argc, char **argv ) 712void QPEApplication::initApp( int argc, char **argv )
711{ 713{
712 bool initial = pidChannel; // was set to 0 in the initializer 714 bool initial = pidChannel; // was set to 0 in the initializer
713 delete pidChannel; 715 delete pidChannel;
714 d->keep_running = TRUE; 716 d->keep_running = TRUE;
715 d->preloaded = FALSE; 717 d->preloaded = FALSE;
716 d->forceshow = FALSE; 718 d->forceshow = FALSE;
717 719
718 QCString channel = QCString(argv[0]); 720 QCString channel = QCString(argv[0]);
719 721
720 channel.replace(QRegExp(".*/"),""); 722 channel.replace(QRegExp(".*/"),"");
721 d->appName = channel; 723 d->appName = channel;
722 724
723 #if QT_VERSION > 235 725 #if QT_VERSION > 235
724 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 726 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
725 #endif 727 #endif
726 728
727 channel = "QPE/Application/" + channel; 729 channel = "QPE/Application/" + channel;
728 pidChannel = new QCopChannel( channel, this); 730 pidChannel = new QCopChannel( channel, this);
729 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 731 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
730 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 732 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
731 733
732 if (!initial) { 734 if (!initial) {
733 processQCopFile(); 735 processQCopFile();
734 d->keep_running = d->qcopq.isEmpty(); 736 d->keep_running = d->qcopq.isEmpty();
735 } 737 }
736 738
737 for (int a=0; a<argc; a++) { 739 for (int a=0; a<argc; a++) {
738 if ( qstrcmp(argv[a],"-preload")==0 ) { 740 if ( qstrcmp(argv[a],"-preload")==0 ) {
739 argv[a] = argv[a+1]; 741 argv[a] = argv[a+1];
740 a++; 742 a++;
741 d->preloaded = TRUE; 743 d->preloaded = TRUE;
742 argc-=1; 744 argc-=1;
743 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 745 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
744 argv[a] = argv[a+1]; 746 argv[a] = argv[a+1];
745 a++; 747 a++;
746 d->preloaded = TRUE; 748 d->preloaded = TRUE;
747 d->forceshow = TRUE; 749 d->forceshow = TRUE;
748 argc-=1; 750 argc-=1;
749 } 751 }
750 } 752 }
751 753
752 /* overide stored arguments */ 754 /* overide stored arguments */
753 setArgs(argc, argv); 755 setArgs(argc, argv);
754 756
755 /* install translation here */ 757 /* install translation here */
756 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 758 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
757 installTranslation( (*it) + "/" + d->appName + ".qm" ); 759 installTranslation( (*it) + "/" + d->appName + ".qm" );
758} 760}
759#endif 761#endif
760 762
761 763
762static QPtrDict<void>* inputMethodDict = 0; 764static QPtrDict<void>* inputMethodDict = 0;
763static void createInputMethodDict() 765static void createInputMethodDict()
764{ 766{
765 if ( !inputMethodDict ) 767 if ( !inputMethodDict )
766 inputMethodDict = new QPtrDict<void>; 768 inputMethodDict = new QPtrDict<void>;
767} 769}
768 770
769/*! 771/*!
770 Returns the currently set hint to the system as to whether 772 Returns the currently set hint to the system as to whether
771 widget \a w has any use for text input methods. 773 widget \a w has any use for text input methods.
772 774
773 775
774 \sa setInputMethodHint() InputMethodHint 776 \sa setInputMethodHint() InputMethodHint
775*/ 777*/
776QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 778QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
777{ 779{
778 if ( inputMethodDict && w ) 780 if ( inputMethodDict && w )
779 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 781 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
780 return Normal; 782 return Normal;
781} 783}
782 784
783/*! 785/*!
784 \enum QPEApplication::InputMethodHint 786 \enum QPEApplication::InputMethodHint
785 787
786 \value Normal the application sometimes needs text input (the default). 788 \value Normal the application sometimes needs text input (the default).
787 \value AlwaysOff the application never needs text input. 789 \value AlwaysOff the application never needs text input.
788 \value AlwaysOn the application always needs text input. 790 \value AlwaysOn the application always needs text input.
789*/ 791*/
790 792
791/*! 793/*!
792 Hints to the system that widget \a w has use for text input methods 794 Hints to the system that widget \a w has use for text input methods
793 as specified by \a mode. 795 as specified by \a mode.
794 796
795 \sa inputMethodHint() InputMethodHint 797 \sa inputMethodHint() InputMethodHint
796*/ 798*/
797void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 799void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
798{ 800{
799 createInputMethodDict(); 801 createInputMethodDict();
800 if ( mode == Normal ) { 802 if ( mode == Normal ) {
801 inputMethodDict->remove 803 inputMethodDict->remove
802 ( w ); 804 ( w );
803 } 805 }
804 else { 806 else {
805 inputMethodDict->insert( w, ( void* ) mode ); 807 inputMethodDict->insert( w, ( void* ) mode );
806 } 808 }
807} 809}
808 810
809class HackDialog : public QDialog 811class HackDialog : public QDialog
810{ 812{
811public: 813public:
812 void acceptIt() 814 void acceptIt()
813 { 815 {
814 accept(); 816 accept();
815 } 817 }
816 void rejectIt() 818 void rejectIt()
817 { 819 {
818 reject(); 820 reject();
819 } 821 }
820}; 822};
821 823
822 824
823void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 825void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
824{ 826{
825 // specialised actions for certain widgets. May want to 827 // specialised actions for certain widgets. May want to
826 // add more stuff here. 828 // add more stuff here.
827 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 829 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
828 && activePopupWidget() ->parentWidget() 830 && activePopupWidget() ->parentWidget()
829 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 831 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
830 key = Qt::Key_Return; 832 key = Qt::Key_Return;
831 833
832 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 834 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
833 key = Qt::Key_Return; 835 key = Qt::Key_Return;
834 836
835#ifdef QWS 837#ifdef QWS
836 838
837 ke->simpleData.keycode = key; 839 ke->simpleData.keycode = key;
838#endif 840#endif
839} 841}
840 842
841class HackWidget : public QWidget 843class HackWidget : public QWidget
842{ 844{
843public: 845public:
844 bool needsOk() 846 bool needsOk()
845 { 847 {
846 return ( getWState() & WState_Reserved1 ); 848 return ( getWState() & WState_Reserved1 );
847 } 849 }
848}; 850};
849 851
850/*! 852/*!
851 \internal 853 \internal
852*/ 854*/
853 855
854#ifdef QWS 856#ifdef QWS
855bool QPEApplication::qwsEventFilter( QWSEvent * e ) 857bool QPEApplication::qwsEventFilter( QWSEvent * e )
856{ 858{
857 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 859 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
858 if ( qApp->type() != QApplication::GuiServer ) { 860 if ( qApp->type() != QApplication::GuiServer ) {
859 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 861 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
860 e << d->appName; 862 e << d->appName;
861 } 863 }
862 d->notbusysent = TRUE; 864 d->notbusysent = TRUE;
863 } 865 }
864 if ( type() == GuiServer ) { 866 if ( type() == GuiServer ) {
865 switch ( e->type ) { 867 switch ( e->type ) {
866 case QWSEvent::Mouse: 868 case QWSEvent::Mouse:
867 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 869 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
868 emit clientMoused(); 870 emit clientMoused();
869 break; 871 break;
870 default: 872 default:
871 break; 873 break;
872 } 874 }
873 } 875 }
874 if ( e->type == QWSEvent::Key ) { 876 if ( e->type == QWSEvent::Key ) {
875 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 877 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
876 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 878 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
877 // Use special "OK" key to press "OK" on top level widgets 879 // Use special "OK" key to press "OK" on top level widgets
878 QWidget * active = activeWindow(); 880 QWidget * active = activeWindow();
879 QWidget *popup = 0; 881 QWidget *popup = 0;
880 if ( active && active->isPopup() ) { 882 if ( active && active->isPopup() ) {
881 popup = active; 883 popup = active;
882 active = active->parentWidget(); 884 active = active->parentWidget();
883 } 885 }
884 if ( active && ( int ) active->winId() == ke->simpleData.window && 886 if ( active && ( int ) active->winId() == ke->simpleData.window &&
885 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 887 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
886 if ( ke->simpleData.is_press ) { 888 if ( ke->simpleData.is_press ) {
887 if ( popup ) 889 if ( popup )
888 popup->close(); 890 popup->close();
889 if ( active->inherits( "QDialog" ) ) { 891 if ( active->inherits( "QDialog" ) ) {
890 HackDialog * d = ( HackDialog * ) active; 892 HackDialog * d = ( HackDialog * ) active;
891 d->acceptIt(); 893 d->acceptIt();
892 return TRUE; 894 return TRUE;
893 } 895 }
894 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 896 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
895 QSignal s; 897 QSignal s;
896 s.connect( active, SLOT( accept() ) ); 898 s.connect( active, SLOT( accept() ) );
897 s.activate(); 899 s.activate();
898 } 900 }
899 else { 901 else {
900 // do the same as with the select key: Map to the default action of the widget: 902 // do the same as with the select key: Map to the default action of the widget:
901 mapToDefaultAction( ke, Qt::Key_Return ); 903 mapToDefaultAction( ke, Qt::Key_Return );
902 } 904 }
903 } 905 }
904 } 906 }
905 } 907 }
906 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 908 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
907 // Use special "select" key to do whatever default action a widget has 909 // Use special "select" key to do whatever default action a widget has
908 mapToDefaultAction( ke, Qt::Key_Space ); 910 mapToDefaultAction( ke, Qt::Key_Space );
909 } 911 }
910 else if ( ke->simpleData.keycode == Qt::Key_Escape && 912 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
911 ke->simpleData.is_press ) { 913 ke->simpleData.is_press ) {
912 // Escape key closes app if focus on toplevel 914 // Escape key closes app if focus on toplevel
913 QWidget * active = activeWindow(); 915 QWidget * active = activeWindow();
914 if ( active && active->testWFlags( WType_TopLevel ) && 916 if ( active && active->testWFlags( WType_TopLevel ) &&
915 ( int ) active->winId() == ke->simpleData.window && 917 ( int ) active->winId() == ke->simpleData.window &&
916 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 918 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
917 if ( active->inherits( "QDialog" ) ) { 919 if ( active->inherits( "QDialog" ) ) {
918 HackDialog * d = ( HackDialog * ) active; 920 HackDialog * d = ( HackDialog * ) active;
919 d->rejectIt(); 921 d->rejectIt();
920 return TRUE; 922 return TRUE;
921 } 923 }
922 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 924 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
923 active->close(); 925 active->close();
924 } 926 }
925 } 927 }