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