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