summaryrefslogtreecommitdiff
authorzecke <zecke>2003-09-30 08:28:21 (UTC)
committer zecke <zecke>2003-09-30 08:28:21 (UTC)
commit4dd842eacb6c04303932e4cbebedff14db7cbc87 (patch) (unidiff)
treefce6ebe83d9c3863b1cf9313a264c85014a716dc
parent5430b226e390cc9af6a3257d6998e34bf806c9e2 (diff)
downloadopie-4dd842eacb6c04303932e4cbebedff14db7cbc87.zip
opie-4dd842eacb6c04303932e4cbebedff14db7cbc87.tar.gz
opie-4dd842eacb6c04303932e4cbebedff14db7cbc87.tar.bz2
Use a QQueue as in Qtopia
Diffstat (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,349 +1,351 @@
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}