summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp25
1 files changed, 0 insertions, 25 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 5ce3011..10c6c40 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,758 +1,733 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19*/ 19*/
20#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <stdlib.h> 21#include <stdlib.h>
22#include <unistd.h> 22#include <unistd.h>
23#ifndef Q_OS_MACX 23#ifndef Q_OS_MACX
24#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 24#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
25#endif 25#endif
26#include <qfile.h> 26#include <qfile.h>
27#include <qqueue.h> 27#include <qqueue.h>
28#ifdef Q_WS_QWS 28#ifdef Q_WS_QWS
29#ifndef QT_NO_COP 29#ifndef QT_NO_COP
30#if QT_VERSION <= 231 30#if QT_VERSION <= 231
31#define private public 31#define private public
32#define sendLocally processEvent 32#define sendLocally processEvent
33#include "qcopenvelope_qws.h" 33#include "qcopenvelope_qws.h"
34#undef private 34#undef private
35#else 35#else
36#include "qcopenvelope_qws.h" 36#include "qcopenvelope_qws.h"
37#endif 37#endif
38#endif 38#endif
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#endif 40#endif
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qpalette.h> 42#include <qpalette.h>
43#include <qbuffer.h> 43#include <qbuffer.h>
44#include <qptrdict.h> 44#include <qptrdict.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qdir.h> 46#include <qdir.h>
47#include <qlabel.h> 47#include <qlabel.h>
48#include <qdialog.h> 48#include <qdialog.h>
49#include <qdragobject.h> 49#include <qdragobject.h>
50#include <qtextcodec.h> 50#include <qtextcodec.h>
51#include <qevent.h> 51#include <qevent.h>
52#include <qtooltip.h> 52#include <qtooltip.h>
53#include <qsignal.h> 53#include <qsignal.h>
54#include <qmainwindow.h> 54#include <qmainwindow.h>
55#include <qwidgetlist.h> 55#include <qwidgetlist.h>
56#include <qpixmapcache.h> 56#include <qpixmapcache.h>
57 57
58#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 58#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
59#define QTOPIA_INTERNAL_INITAPP 59#define QTOPIA_INTERNAL_INITAPP
60#include "qpeapplication.h" 60#include "qpeapplication.h"
61#include "qpestyle.h" 61#include "qpestyle.h"
62#include "styleinterface.h" 62#include "styleinterface.h"
63#if QT_VERSION >= 300 63#if QT_VERSION >= 300
64#include <qstylefactory.h> 64#include <qstylefactory.h>
65#else 65#else
66#include <qplatinumstyle.h> 66#include <qplatinumstyle.h>
67#include <qwindowsstyle.h> 67#include <qwindowsstyle.h>
68#include <qmotifstyle.h> 68#include <qmotifstyle.h>
69#include <qmotifplusstyle.h> 69#include <qmotifplusstyle.h>
70#include "lightstyle.h" 70#include "lightstyle.h"
71 71
72#include <qpe/qlibrary.h> 72#include <qpe/qlibrary.h>
73#endif 73#endif
74#include "global.h" 74#include "global.h"
75#include "resource.h" 75#include "resource.h"
76#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 76#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
77#include "qutfcodec.h" 77#include "qutfcodec.h"
78#endif 78#endif
79#include "config.h" 79#include "config.h"
80#include "network.h" 80#include "network.h"
81#ifdef QWS 81#ifdef QWS
82#include "fontmanager.h" 82#include "fontmanager.h"
83#endif 83#endif
84 84
85#include "alarmserver.h" 85#include "alarmserver.h"
86#include "applnk.h" 86#include "applnk.h"
87#include "qpemenubar.h" 87#include "qpemenubar.h"
88#include "textcodecinterface.h" 88#include "textcodecinterface.h"
89#include "imagecodecinterface.h" 89#include "imagecodecinterface.h"
90 90
91#include <unistd.h> 91#include <unistd.h>
92#include <sys/file.h> 92#include <sys/file.h>
93#include <sys/ioctl.h> 93#include <sys/ioctl.h>
94#ifndef QT_NO_SOUND 94#ifndef QT_NO_SOUND
95#include <sys/soundcard.h> 95#include <sys/soundcard.h>
96#endif 96#endif
97#include "qt_override_p.h" 97#include "qt_override_p.h"
98 98
99class HackWidget : public QWidget 99class HackWidget : public QWidget
100{ 100{
101public: 101public:
102 bool needsOk() 102 bool needsOk()
103 { return (getWState() & WState_Reserved1 ); } 103 { return (getWState() & WState_Reserved1 ); }
104 104
105 QRect normalGeometry() 105 QRect normalGeometry()
106 { return topData()->normalGeometry; }; 106 { return topData()->normalGeometry; };
107}; 107};
108 108
109class QPEApplicationData 109class QPEApplicationData
110{ 110{
111public: 111public:
112 QPEApplicationData ( ) 112 QPEApplicationData ( )
113 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 113 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
114 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 114 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
115 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) 115 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 )
116 116
117 {} 117 {}
118 118
119 int presstimer; 119 int presstimer;
120 QWidget* presswidget; 120 QWidget* presswidget;
121 QPoint presspos; 121 QPoint presspos;
122 122
123 bool rightpressed : 1; 123 bool rightpressed : 1;
124 bool kbgrabbed : 1; 124 bool kbgrabbed : 1;
125 bool notbusysent : 1; 125 bool notbusysent : 1;
126 bool preloaded : 1; 126 bool preloaded : 1;
127 bool forceshow : 1; 127 bool forceshow : 1;
128 bool nomaximize : 1; 128 bool nomaximize : 1;
129 bool keep_running : 1; 129 bool keep_running : 1;
130 bool qcopQok : 1; 130 bool qcopQok : 1;
131 131
132 132
133 QStringList langs; 133 QStringList langs;
134 QString appName; 134 QString appName;
135 struct QCopRec 135 struct QCopRec
136 { 136 {
137 QCopRec( const QCString &ch, const QCString &msg, 137 QCopRec( const QCString &ch, const QCString &msg,
138 const QByteArray &d ) : 138 const QByteArray &d ) :
139 channel( ch ), message( msg ), data( d ) 139 channel( ch ), message( msg ), data( d )
140 { } 140 { }
141 141
142 QCString channel; 142 QCString channel;
143 QCString message; 143 QCString message;
144 QByteArray data; 144 QByteArray data;
145 }; 145 };
146 QWidget* qpe_main_widget; 146 QWidget* qpe_main_widget;
147 QGuardedPtr<QWidget> lastraised; 147 QGuardedPtr<QWidget> lastraised;
148 QQueue<QCopRec> qcopq; 148 QQueue<QCopRec> qcopq;
149 QString styleName; 149 QString styleName;
150 QString decorationName; 150 QString decorationName;
151 151
152 void enqueueQCop( const QCString &ch, const QCString &msg, 152 void enqueueQCop( const QCString &ch, const QCString &msg,
153 const QByteArray &data ) 153 const QByteArray &data )
154 { 154 {
155 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 155 qcopq.enqueue( new QCopRec( ch, msg, data ) );
156 } 156 }
157 void sendQCopQ() 157 void sendQCopQ()
158 { 158 {
159 if (!qcopQok ) 159 if (!qcopQok )
160 return; 160 return;
161 161
162 QCopRec * r; 162 QCopRec * r;
163 163
164 while((r=qcopq.dequeue())) { 164 while((r=qcopq.dequeue())) {
165 // remove from queue before sending... 165 // remove from queue before sending...
166 // event loop can come around again before getting 166 // event loop can come around again before getting
167 // back from sendLocally 167 // back from sendLocally
168#ifndef QT_NO_COP 168#ifndef QT_NO_COP
169 QCopChannel::sendLocally( r->channel, r->message, r->data ); 169 QCopChannel::sendLocally( r->channel, r->message, r->data );
170#endif 170#endif
171 171
172 delete r; 172 delete r;
173 } 173 }
174 } 174 }
175 175
176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */) 176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */)
177 { 177 {
178 QPoint p; 178 QPoint p;
179 QSize s; 179 QSize s;
180 bool max; 180 bool max;
181 if ( mw->isVisible() ) { 181 if ( mw->isVisible() ) {
182 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 182 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
183 mw->resize(s); 183 mw->resize(s);
184 mw->move(p); 184 mw->move(p);
185 } 185 }
186 mw->raise(); 186 mw->raise();
187 } else { 187 } else {
188 188
189 if ( mw->layout() && mw->inherits("QDialog") ) { 189 if ( mw->layout() && mw->inherits("QDialog") ) {
190 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 190 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
191 mw->resize(s); 191 mw->resize(s);
192 mw->move(p); 192 mw->move(p);
193 193
194 if ( max && !nomaximize ) { 194 if ( max && !nomaximize ) {
195 mw->showMaximized(); 195 mw->showMaximized();
196 } else { 196 } else {
197 mw->show(); 197 mw->show();
198 } 198 }
199 } else { 199 } else {
200 qpe_show_dialog((QDialog*)mw,nomaximize); 200 qpe_show_dialog((QDialog*)mw,nomaximize);
201 } 201 }
202 } else { 202 } else {
203 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 203 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
204 mw->resize(s); 204 mw->resize(s);
205 mw->move(p); 205 mw->move(p);
206 } else { //no stored rectangle, make an estimation 206 } else { //no stored rectangle, make an estimation
207 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; 207 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
208 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; 208 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
209 mw->move( QMAX(x,0), QMAX(y,0) ); 209 mw->move( QMAX(x,0), QMAX(y,0) );
210#ifdef Q_WS_QWS 210#ifdef Q_WS_QWS
211 if ( !nomaximize ) 211 if ( !nomaximize )
212 mw->showMaximized(); 212 mw->showMaximized();
213#endif 213#endif
214 } 214 }
215 if ( max && !nomaximize ) 215 if ( max && !nomaximize )
216 mw->showMaximized(); 216 mw->showMaximized();
217 else 217 else
218 mw->show(); 218 mw->show();
219 } 219 }
220 } 220 }
221 } 221 }
222// // ugly hack, remove that later after finding a sane solution
223// // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
224// // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
225// // a (physically) large enough display to use the small icons
226// #if defined(OPIE_HIGH_RES_SMALL_PHY)
227// if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
228// ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
229// }
230// #endif
231
232 // if ( mw->layout() && mw->inherits("QDialog") ) {
233 // QPEApplication::showDialog((QDialog*)mw, nomaximize);
234 // }
235 // else {
236// #ifdef Q_WS_QWS
237 // if ( !nomaximize ) {
238 // qDebug("QDialog special case XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
239 // mw->showMaximized();
240 // //QPEApplication::showWidget( mw, !nomaximize );
241 // }else
242// #endif
243 // mw->show();
244 // }
245 //}
246
247 222
248static void qpe_show_dialog( QDialog* d, bool nomax ) 223static void qpe_show_dialog( QDialog* d, bool nomax )
249{ 224{
250 QSize sh = d->sizeHint(); 225 QSize sh = d->sizeHint();
251 int w = QMAX(sh.width(),d->width()); 226 int w = QMAX(sh.width(),d->width());
252 int h = QMAX(sh.height(),d->height()); 227 int h = QMAX(sh.height(),d->height());
253 228
254 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() ) 229 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() )
255 nomax = TRUE; 230 nomax = TRUE;
256 231
257#ifndef Q_WS_QWS 232#ifndef Q_WS_QWS
258 QSize s(qApp->desktop()->width(), qApp->desktop()->height() ); 233 QSize s(qApp->desktop()->width(), qApp->desktop()->height() );
259#else 234#else
260 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() ); 235 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() );
261#endif 236#endif
262 237
263 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); 238 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width());
264 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); 239 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height());
265 240
266 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { 241 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) {
267 d->showMaximized(); 242 d->showMaximized();
268 } else { 243 } else {
269 // try centering the dialog around its parent 244 // try centering the dialog around its parent
270 QPoint p(0,0); 245 QPoint p(0,0);
271 if ( d->parentWidget() ) { 246 if ( d->parentWidget() ) {
272 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); 247 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
273 p = QPoint( pp.x() + d->parentWidget()->width()/2, 248 p = QPoint( pp.x() + d->parentWidget()->width()/2,
274 pp.y() + d->parentWidget()->height()/ 2 ); 249 pp.y() + d->parentWidget()->height()/ 2 );
275 } else { 250 } else {
276 p = QPoint( maxX/2, maxY/2 ); 251 p = QPoint( maxX/2, maxY/2 );
277 } 252 }
278 253
279 p = QPoint( p.x() - w/2, p.y() - h/2 ); 254 p = QPoint( p.x() - w/2, p.y() - h/2 );
280 //qDebug("p(x,y) is %d %d", p.x(), p.y() ); 255 //qDebug("p(x,y) is %d %d", p.x(), p.y() );
281 256
282 if ( w >= maxX ) { 257 if ( w >= maxX ) {
283 if ( p.y() < 0 ) 258 if ( p.y() < 0 )
284 p.setY(0); 259 p.setY(0);
285 if ( p.y() + h > maxY ) 260 if ( p.y() + h > maxY )
286 p.setY( maxY - h); 261 p.setY( maxY - h);
287 262
288 d->resize(maxX, h); 263 d->resize(maxX, h);
289 d->move(0, p.y() ); 264 d->move(0, p.y() );
290 } else if ( h >= maxY ) { 265 } else if ( h >= maxY ) {
291 if ( p.x() < 0 ) 266 if ( p.x() < 0 )
292 p.setX(0); 267 p.setX(0);
293 if ( p.x() + w > maxX ) 268 if ( p.x() + w > maxX )
294 p.setX( maxX - w); 269 p.setX( maxX - w);
295 270
296 d->resize(w, maxY); 271 d->resize(w, maxY);
297 d->move(p.x(),0); 272 d->move(p.x(),0);
298 } else { 273 } else {
299 d->resize(w, h); 274 d->resize(w, h);
300 } 275 }
301 276
302 d->show(); 277 d->show();
303 } 278 }
304} 279}
305 280
306 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) 281 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
307 { 282 {
308 maximized = TRUE; 283 maximized = TRUE;
309 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 284 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
310 if ( qApp->desktop()->width() <= 350 ) 285 if ( qApp->desktop()->width() <= 350 )
311 return FALSE; 286 return FALSE;
312 287
313 Config cfg( "qpe" ); 288 Config cfg( "qpe" );
314 cfg.setGroup("ApplicationPositions"); 289 cfg.setGroup("ApplicationPositions");
315 QString str = cfg.readEntry( app, QString::null ); 290 QString str = cfg.readEntry( app, QString::null );
316 QStringList l = QStringList::split(",", str); 291 QStringList l = QStringList::split(",", str);
317 292
318 if ( l.count() == 5) { 293 if ( l.count() == 5) {
319 p.setX( l[0].toInt() ); 294 p.setX( l[0].toInt() );
320 p.setY( l[1].toInt() ); 295 p.setY( l[1].toInt() );
321 296
322 s.setWidth( l[2].toInt() ); 297 s.setWidth( l[2].toInt() );
323 s.setHeight( l[3].toInt() ); 298 s.setHeight( l[3].toInt() );
324 299
325 maximized = l[4].toInt(); 300 maximized = l[4].toInt();
326 301
327 return TRUE; 302 return TRUE;
328 } 303 }
329 304
330 return FALSE; 305 return FALSE;
331 } 306 }
332 307
333 308
334 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 309 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
335 { 310 {
336#ifndef Q_WS_QWS 311#ifndef Q_WS_QWS
337 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 312 QRect qt_maxWindowRect = qApp->desktop()->geometry();
338#endif 313#endif
339 int maxX = qt_maxWindowRect.width(); 314 int maxX = qt_maxWindowRect.width();
340 int maxY = qt_maxWindowRect.height(); 315 int maxY = qt_maxWindowRect.height();
341 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 316 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
342 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 317 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
343 318
344 // total window size is not allowed to be larger than desktop window size 319 // total window size is not allowed to be larger than desktop window size
345 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 320 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
346 return FALSE; 321 return FALSE;
347 322
348 if ( wWidth > maxX ) { 323 if ( wWidth > maxX ) {
349 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 324 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
350 wWidth = maxX; 325 wWidth = maxX;
351 } 326 }
352 327
353 if ( wHeight > maxY ) { 328 if ( wHeight > maxY ) {
354 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 329 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
355 wHeight = maxY; 330 wHeight = maxY;
356 } 331 }
357 332
358 // any smaller than this and the maximize/close/help buttons will be overlapping 333 // any smaller than this and the maximize/close/help buttons will be overlapping
359 if ( wWidth < 80 || wHeight < 60 ) 334 if ( wWidth < 80 || wHeight < 60 )
360 return FALSE; 335 return FALSE;
361 336
362 if ( p.x() < 0 ) 337 if ( p.x() < 0 )
363 p.setX(0); 338 p.setX(0);
364 if ( p.y() < 0 ) 339 if ( p.y() < 0 )
365 p.setY(0); 340 p.setY(0);
366 341
367 if ( p.x() + wWidth > maxX ) 342 if ( p.x() + wWidth > maxX )
368 p.setX( maxX - wWidth ); 343 p.setX( maxX - wWidth );
369 if ( p.y() + wHeight > maxY ) 344 if ( p.y() + wHeight > maxY )
370 p.setY( maxY - wHeight ); 345 p.setY( maxY - wHeight );
371 346
372 return TRUE; 347 return TRUE;
373 } 348 }
374 349
375 static void store_widget_rect(QWidget *w, QString &app) 350 static void store_widget_rect(QWidget *w, QString &app)
376 { 351 {
377 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 352 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
378 if ( qApp->desktop()->width() <= 350 ) 353 if ( qApp->desktop()->width() <= 350 )
379 return; 354 return;
380 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 355 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
381 // get the non-maximized version, so we have to do it the hard way ) 356 // get the non-maximized version, so we have to do it the hard way )
382 int offsetX = w->x() - w->geometry().left(); 357 int offsetX = w->x() - w->geometry().left();
383 int offsetY = w->y() - w->geometry().top(); 358 int offsetY = w->y() - w->geometry().top();
384 359
385 QRect r; 360 QRect r;
386 if ( w->isMaximized() ) 361 if ( w->isMaximized() )
387 r = ( (HackWidget *) w)->normalGeometry(); 362 r = ( (HackWidget *) w)->normalGeometry();
388 else 363 else
389 r = w->geometry(); 364 r = w->geometry();
390 365
391 // Stores the window placement as pos(), size() (due to the offset mapping) 366 // Stores the window placement as pos(), size() (due to the offset mapping)
392 Config cfg( "qpe" ); 367 Config cfg( "qpe" );
393 cfg.setGroup("ApplicationPositions"); 368 cfg.setGroup("ApplicationPositions");
394 QString s; 369 QString s;
395 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 370 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
396 cfg.writeEntry( app, s ); 371 cfg.writeEntry( app, s );
397 } 372 }
398 373
399 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 374 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
400 { 375 {
401 /* 376 /*
402 // This works but disable it for now until it is safe to apply 377 // This works but disable it for now until it is safe to apply
403 // What is does is scan the .desktop files of all the apps for 378 // What is does is scan the .desktop files of all the apps for
404 // the applnk that has the corresponding argv[0] as this program 379 // the applnk that has the corresponding argv[0] as this program
405 // then it uses the name stored in the .desktop file as the caption 380 // then it uses the name stored in the .desktop file as the caption
406 // for the main widget. This saves duplicating translations for 381 // for the main widget. This saves duplicating translations for
407 // the app name in the program and in the .desktop files. 382 // the app name in the program and in the .desktop files.
408 383
409 AppLnkSet apps( appsPath ); 384 AppLnkSet apps( appsPath );
410 385
411 QList<AppLnk> appsList = apps.children(); 386 QList<AppLnk> appsList = apps.children();
412 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 387 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
413 if ( (*it)->exec() == appName ) { 388 if ( (*it)->exec() == appName ) {
414 mw->setCaption( (*it)->name() ); 389 mw->setCaption( (*it)->name() );
415 return TRUE; 390 return TRUE;
416 } 391 }
417 } 392 }
418 */ 393 */
419 return FALSE; 394 return FALSE;
420 } 395 }
421 396
422 397
423 void show(QWidget* mw, bool nomax) 398 void show(QWidget* mw, bool nomax)
424 { 399 {
425 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 400 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
426 nomaximize = nomax; 401 nomaximize = nomax;
427 qpe_main_widget = mw; 402 qpe_main_widget = mw;
428 qcopQok = TRUE; 403 qcopQok = TRUE;
429#ifndef QT_NO_COP 404#ifndef QT_NO_COP
430 405
431 sendQCopQ(); 406 sendQCopQ();
432#endif 407#endif
433 408
434 if ( preloaded ) { 409 if ( preloaded ) {
435 if (forceshow) 410 if (forceshow)
436 show_mx(mw, nomax, appName); 411 show_mx(mw, nomax, appName);
437 } 412 }
438 else if ( keep_running ) { 413 else if ( keep_running ) {
439 show_mx(mw, nomax, appName); 414 show_mx(mw, nomax, appName);
440 } 415 }
441 } 416 }
442 417
443 void loadTextCodecs() 418 void loadTextCodecs()
444 { 419 {
445 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 420 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
446#ifdef Q_OS_MACX 421#ifdef Q_OS_MACX
447 QDir dir( path, "lib*.dylib" ); 422 QDir dir( path, "lib*.dylib" );
448#else 423#else
449 QDir dir( path, "lib*.so" ); 424 QDir dir( path, "lib*.so" );
450#endif 425#endif
451 QStringList list; 426 QStringList list;
452 if ( dir. exists ( )) 427 if ( dir. exists ( ))
453 list = dir.entryList(); 428 list = dir.entryList();
454 QStringList::Iterator it; 429 QStringList::Iterator it;
455 for ( it = list.begin(); it != list.end(); ++it ) { 430 for ( it = list.begin(); it != list.end(); ++it ) {
456 TextCodecInterface *iface = 0; 431 TextCodecInterface *iface = 0;
457 QLibrary *lib = new QLibrary( path + "/" + *it ); 432 QLibrary *lib = new QLibrary( path + "/" + *it );
458 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 433 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
459 QValueList<int> mibs = iface->mibEnums(); 434 QValueList<int> mibs = iface->mibEnums();
460 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 435 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
461 (void)iface->createForMib(*i); 436 (void)iface->createForMib(*i);
462 // ### it exists now; need to remember if we can delete it 437 // ### it exists now; need to remember if we can delete it
463 } 438 }
464 } 439 }
465 else { 440 else {
466 lib->unload(); 441 lib->unload();
467 delete lib; 442 delete lib;
468 } 443 }
469 } 444 }
470 } 445 }
471 446
472 void loadImageCodecs() 447 void loadImageCodecs()
473 { 448 {
474 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 449 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
475#ifdef Q_OS_MACX 450#ifdef Q_OS_MACX
476 QDir dir( path, "lib*.dylib" ); 451 QDir dir( path, "lib*.dylib" );
477#else 452#else
478 QDir dir( path, "lib*.so" ); 453 QDir dir( path, "lib*.so" );
479#endif 454#endif
480 QStringList list; 455 QStringList list;
481 if ( dir. exists ( )) 456 if ( dir. exists ( ))
482 list = dir.entryList(); 457 list = dir.entryList();
483 QStringList::Iterator it; 458 QStringList::Iterator it;
484 for ( it = list.begin(); it != list.end(); ++it ) { 459 for ( it = list.begin(); it != list.end(); ++it ) {
485 ImageCodecInterface *iface = 0; 460 ImageCodecInterface *iface = 0;
486 QLibrary *lib = new QLibrary( path + "/" + *it ); 461 QLibrary *lib = new QLibrary( path + "/" + *it );
487 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 462 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
488 QStringList formats = iface->keys(); 463 QStringList formats = iface->keys();
489 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 464 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
490 (void)iface->installIOHandler(*i); 465 (void)iface->installIOHandler(*i);
491 // ### it exists now; need to remember if we can delete it 466 // ### it exists now; need to remember if we can delete it
492 } 467 }
493 } 468 }
494 else { 469 else {
495 lib->unload(); 470 lib->unload();
496 delete lib; 471 delete lib;
497 } 472 }
498 } 473 }
499 } 474 }
500}; 475};
501 476
502class ResourceMimeFactory : public QMimeSourceFactory 477class ResourceMimeFactory : public QMimeSourceFactory
503{ 478{
504public: 479public:
505 ResourceMimeFactory() : resImage( 0 ) 480 ResourceMimeFactory() : resImage( 0 )
506 { 481 {
507 setFilePath( Global::helpPath() ); 482 setFilePath( Global::helpPath() );
508 setExtensionType( "html", "text/html;charset=UTF-8" ); 483 setExtensionType( "html", "text/html;charset=UTF-8" );
509 } 484 }
510 ~ResourceMimeFactory() { 485 ~ResourceMimeFactory() {
511 delete resImage; 486 delete resImage;
512 } 487 }
513 488
514 const QMimeSource* data( const QString& abs_name ) const 489 const QMimeSource* data( const QString& abs_name ) const
515 { 490 {
516 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 491 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
517 if ( !r ) { 492 if ( !r ) {
518 int sl = abs_name.length(); 493 int sl = abs_name.length();
519 do { 494 do {
520 sl = abs_name.findRev( '/', sl - 1 ); 495 sl = abs_name.findRev( '/', sl - 1 );
521 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 496 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
522 int dot = name.findRev( '.' ); 497 int dot = name.findRev( '.' );
523 if ( dot >= 0 ) 498 if ( dot >= 0 )
524 name = name.left( dot ); 499 name = name.left( dot );
525 QImage img = Resource::loadImage( name ); 500 QImage img = Resource::loadImage( name );
526 if ( !img.isNull() ) { 501 if ( !img.isNull() ) {
527 delete resImage; 502 delete resImage;
528 resImage = new QImageDrag( img ); 503 resImage = new QImageDrag( img );
529 r = resImage; 504 r = resImage;
530 } 505 }
531 } 506 }
532 while ( !r && sl > 0 ); 507 while ( !r && sl > 0 );
533 } 508 }
534 return r; 509 return r;
535 } 510 }
536private: 511private:
537 mutable QImageDrag *resImage; 512 mutable QImageDrag *resImage;
538}; 513};
539 514
540static int& hack(int& i) 515static int& hack(int& i)
541{ 516{
542#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 517#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
543 // These should be created, but aren't in Qt 2.3.0 518 // These should be created, but aren't in Qt 2.3.0
544 (void)new QUtf8Codec; 519 (void)new QUtf8Codec;
545 (void)new QUtf16Codec; 520 (void)new QUtf16Codec;
546#endif 521#endif
547 return i; 522 return i;
548} 523}
549 524
550static int muted = 0; 525static int muted = 0;
551static int micMuted = 0; 526static int micMuted = 0;
552 527
553static void setVolume( int t = 0, int percent = -1 ) 528static void setVolume( int t = 0, int percent = -1 )
554{ 529{
555 switch ( t ) { 530 switch ( t ) {
556 case 0: { 531 case 0: {
557 Config cfg( "qpe" ); 532 Config cfg( "qpe" );
558 cfg.setGroup( "Volume" ); 533 cfg.setGroup( "Volume" );
559 if ( percent < 0 ) 534 if ( percent < 0 )
560 percent = cfg.readNumEntry( "VolumePercent", 50 ); 535 percent = cfg.readNumEntry( "VolumePercent", 50 );
561#ifndef QT_NO_SOUND 536#ifndef QT_NO_SOUND
562 int fd = 0; 537 int fd = 0;
563 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 538 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
564 int vol = muted ? 0 : percent; 539 int vol = muted ? 0 : percent;
565 // set both channels to same volume 540 // set both channels to same volume
566 vol |= vol << 8; 541 vol |= vol << 8;
567 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 542 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
568 ::close( fd ); 543 ::close( fd );
569 } 544 }
570#endif 545#endif
571 } 546 }
572 break; 547 break;
573 } 548 }
574} 549}
575 550
576static void setMic( int t = 0, int percent = -1 ) 551static void setMic( int t = 0, int percent = -1 )
577{ 552{
578 switch ( t ) { 553 switch ( t ) {
579 case 0: { 554 case 0: {
580 Config cfg( "qpe" ); 555 Config cfg( "qpe" );
581 cfg.setGroup( "Volume" ); 556 cfg.setGroup( "Volume" );
582 if ( percent < 0 ) 557 if ( percent < 0 )
583 percent = cfg.readNumEntry( "Mic", 50 ); 558 percent = cfg.readNumEntry( "Mic", 50 );
584 559
585#ifndef QT_NO_SOUND 560#ifndef QT_NO_SOUND
586 int fd = 0; 561 int fd = 0;
587 int mic = micMuted ? 0 : percent; 562 int mic = micMuted ? 0 : percent;
588 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 563 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
589 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 564 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
590 ::close( fd ); 565 ::close( fd );
591 } 566 }
592#endif 567#endif
593 } 568 }
594 break; 569 break;
595 } 570 }
596} 571}
597 572
598 573
599static void setBass( int t = 0, int percent = -1 ) 574static void setBass( int t = 0, int percent = -1 )
600{ 575{
601 switch ( t ) { 576 switch ( t ) {
602 case 0: { 577 case 0: {
603 Config cfg( "qpe" ); 578 Config cfg( "qpe" );
604 cfg.setGroup( "Volume" ); 579 cfg.setGroup( "Volume" );
605 if ( percent < 0 ) 580 if ( percent < 0 )
606 percent = cfg.readNumEntry( "BassPercent", 50 ); 581 percent = cfg.readNumEntry( "BassPercent", 50 );
607 582
608#ifndef QT_NO_SOUND 583#ifndef QT_NO_SOUND
609 int fd = 0; 584 int fd = 0;
610 int bass = percent; 585 int bass = percent;
611 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 586 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
612 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 587 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
613 ::close( fd ); 588 ::close( fd );
614 } 589 }
615#endif 590#endif
616 } 591 }
617 break; 592 break;
618 } 593 }
619} 594}
620 595
621 596
622static void setTreble( int t = 0, int percent = -1 ) 597static void setTreble( int t = 0, int percent = -1 )
623{ 598{
624 switch ( t ) { 599 switch ( t ) {
625 case 0: { 600 case 0: {
626 Config cfg( "qpe" ); 601 Config cfg( "qpe" );
627 cfg.setGroup( "Volume" ); 602 cfg.setGroup( "Volume" );
628 if ( percent < 0 ) 603 if ( percent < 0 )
629 percent = cfg.readNumEntry( "TreblePercent", 50 ); 604 percent = cfg.readNumEntry( "TreblePercent", 50 );
630 605
631#ifndef QT_NO_SOUND 606#ifndef QT_NO_SOUND
632 int fd = 0; 607 int fd = 0;
633 int treble = percent; 608 int treble = percent;
634 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 609 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
635 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 610 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
636 ::close( fd ); 611 ::close( fd );
637 } 612 }
638#endif 613#endif
639 } 614 }
640 break; 615 break;
641 } 616 }
642} 617}
643 618
644 619
645/** 620/**
646 \class QPEApplication 621 \class QPEApplication
647 \brief The QPEApplication class implements various system services 622 \brief The QPEApplication class implements various system services
648 that are available to all Qtopia applications. 623 that are available to all Qtopia applications.
649 624
650 Simply by using QPEApplication instead of QApplication, a standard Qt 625 Simply by using QPEApplication instead of QApplication, a standard Qt
651 application becomes a Qtopia application. It automatically follows 626 application becomes a Qtopia application. It automatically follows
652 style changes, quits and raises, and in the 627 style changes, quits and raises, and in the
653 case of \link docwidget.html document-oriented\endlink applications, 628 case of \link docwidget.html document-oriented\endlink applications,
654 changes the currently displayed document in response to the environment. 629 changes the currently displayed document in response to the environment.
655 630
656 To create a \link docwidget.html document-oriented\endlink 631 To create a \link docwidget.html document-oriented\endlink
657 application use showMainDocumentWidget(); to create a 632 application use showMainDocumentWidget(); to create a
658 non-document-oriented application use showMainWidget(). The 633 non-document-oriented application use showMainWidget(). The
659 keepRunning() function indicates whether the application will 634 keepRunning() function indicates whether the application will
660 continue running after it's processed the last \link qcop.html 635 continue running after it's processed the last \link qcop.html
661 QCop\endlink message. This can be changed using setKeepRunning(). 636 QCop\endlink message. This can be changed using setKeepRunning().
662 637
663 A variety of signals are emitted when certain events occur, for 638 A variety of signals are emitted when certain events occur, for
664 example, timeChanged(), clockChanged(), weekChanged(), 639 example, timeChanged(), clockChanged(), weekChanged(),
665 dateFormatChanged() and volumeChanged(). If the application receives 640 dateFormatChanged() and volumeChanged(). If the application receives
666 a \link qcop.html QCop\endlink message on the application's 641 a \link qcop.html QCop\endlink message on the application's
667 QPE/Application/\e{appname} channel, the appMessage() signal is 642 QPE/Application/\e{appname} channel, the appMessage() signal is
668 emitted. There are also flush() and reload() signals, which 643 emitted. There are also flush() and reload() signals, which
669 are emitted when synching begins and ends respectively - upon these 644 are emitted when synching begins and ends respectively - upon these
670 signals, the application should save and reload any data 645 signals, the application should save and reload any data
671 files that are involved in synching. Most of these signals will initially 646 files that are involved in synching. Most of these signals will initially
672 be received and unfiltered through the appMessage() signal. 647 be received and unfiltered through the appMessage() signal.
673 648
674 This class also provides a set of useful static functions. The 649 This class also provides a set of useful static functions. The
675 qpeDir() and documentDir() functions return the respective paths. 650 qpeDir() and documentDir() functions return the respective paths.
676 The grabKeyboard() and ungrabKeyboard() functions are used to 651 The grabKeyboard() and ungrabKeyboard() functions are used to
677 control whether the application takes control of the device's 652 control whether the application takes control of the device's
678 physical buttons (e.g. application launch keys). The stylus' mode of 653 physical buttons (e.g. application launch keys). The stylus' mode of
679 operation is set with setStylusOperation() and retrieved with 654 operation is set with setStylusOperation() and retrieved with
680 stylusOperation(). There are also setInputMethodHint() and 655 stylusOperation(). There are also setInputMethodHint() and
681 inputMethodHint() functions. 656 inputMethodHint() functions.
682 657
683 \ingroup qtopiaemb 658 \ingroup qtopiaemb
684*/ 659*/
685 660
686/*! 661/*!
687 \fn void QPEApplication::clientMoused() 662 \fn void QPEApplication::clientMoused()
688 663
689 \internal 664 \internal
690*/ 665*/
691 666
692/*! 667/*!
693 \fn void QPEApplication::timeChanged(); 668 \fn void QPEApplication::timeChanged();
694 This signal is emitted when the time changes outside the normal 669 This signal is emitted when the time changes outside the normal
695 passage of time, i.e. if the time is set backwards or forwards. 670 passage of time, i.e. if the time is set backwards or forwards.
696*/ 671*/
697 672
698/*! 673/*!
699 \fn void QPEApplication::clockChanged( bool ampm ); 674 \fn void QPEApplication::clockChanged( bool ampm );
700 675
701 This signal is emitted when the user changes the clock's style. If 676 This signal is emitted when the user changes the clock's style. If
702 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 677 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
703 they want a 24-hour clock. 678 they want a 24-hour clock.
704*/ 679*/
705 680
706/*! 681/*!
707 \fn void QPEApplication::volumeChanged( bool muted ) 682 \fn void QPEApplication::volumeChanged( bool muted )
708 683
709 This signal is emitted whenever the mute state is changed. If \a 684 This signal is emitted whenever the mute state is changed. If \a
710 muted is TRUE, then sound output has been muted. 685 muted is TRUE, then sound output has been muted.
711*/ 686*/
712 687
713/*! 688/*!
714 \fn void QPEApplication::weekChanged( bool startOnMonday ) 689 \fn void QPEApplication::weekChanged( bool startOnMonday )
715 690
716 This signal is emitted if the week start day is changed. If \a 691 This signal is emitted if the week start day is changed. If \a
717 startOnMonday is TRUE then the first day of the week is Monday; if 692 startOnMonday is TRUE then the first day of the week is Monday; if
718 \a startOnMonday is FALSE then the first day of the week is 693 \a startOnMonday is FALSE then the first day of the week is
719 Sunday. 694 Sunday.
720*/ 695*/
721 696
722/*! 697/*!
723 \fn void QPEApplication::dateFormatChanged(DateFormat) 698 \fn void QPEApplication::dateFormatChanged(DateFormat)
724 699
725 This signal is emitted whenever the date format is changed. 700 This signal is emitted whenever the date format is changed.
726*/ 701*/
727 702
728/*! 703/*!
729 \fn void QPEApplication::flush() 704 \fn void QPEApplication::flush()
730 705
731 ### 706 ###
732*/ 707*/
733 708
734/*! 709/*!
735 \fn void QPEApplication::reload() 710 \fn void QPEApplication::reload()
736 711
737*/ 712*/
738 713
739 714
740 715
741void QPEApplication::processQCopFile() 716void QPEApplication::processQCopFile()
742{ 717{
743 QString qcopfn("/tmp/qcop-msg-"); 718 QString qcopfn("/tmp/qcop-msg-");
744 qcopfn += d->appName; // append command name 719 qcopfn += d->appName; // append command name
745 720
746 QFile f(qcopfn); 721 QFile f(qcopfn);
747 if ( f.open(IO_ReadWrite) ) { 722 if ( f.open(IO_ReadWrite) ) {
748#ifndef Q_OS_WIN32 723#ifndef Q_OS_WIN32
749 flock(f.handle(), LOCK_EX); 724 flock(f.handle(), LOCK_EX);
750#endif 725#endif
751 QDataStream ds(&f); 726 QDataStream ds(&f);
752 QCString channel, message; 727 QCString channel, message;
753 QByteArray data; 728 QByteArray data;
754 while(!ds.atEnd()) { 729 while(!ds.atEnd()) {
755 ds >> channel >> message >> data; 730 ds >> channel >> message >> data;
756 d->enqueueQCop(channel,message,data); 731 d->enqueueQCop(channel,message,data);
757 } 732 }
758 ::ftruncate(f.handle(), 0); 733 ::ftruncate(f.handle(), 0);