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