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