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