author | zecke <zecke> | 2004-07-12 20:01:26 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-07-12 20:01:26 (UTC) |
commit | 5d2ec2e9b1dce49e914c260fe16a82ddccbaa92d (patch) (unidiff) | |
tree | cbac9fa8c94900e3486c3251206bdc22028b4a66 /library/qpeapplication.cpp | |
parent | e18cb7bddb3461a40ae1e8810ef408ceef101d38 (diff) | |
download | opie-5d2ec2e9b1dce49e914c260fe16a82ddccbaa92d.zip opie-5d2ec2e9b1dce49e914c260fe16a82ddccbaa92d.tar.gz opie-5d2ec2e9b1dce49e914c260fe16a82ddccbaa92d.tar.bz2 |
Query for FontFactories which implement the FontFactoryInterface on
QPEApplication creation.
Also update the comment in the API docu as now FontFactories are loaded
-rw-r--r-- | library/qpeapplication.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index b686e2e..f4a7f74 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,1394 +1,1396 @@ | |||
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 | #endif | 84 | #endif |
84 | 85 | ||
85 | #include "alarmserver.h" | 86 | #include "alarmserver.h" |
86 | #include "applnk.h" | 87 | #include "applnk.h" |
87 | #include "qpemenubar.h" | 88 | #include "qpemenubar.h" |
88 | #include "textcodecinterface.h" | 89 | #include "textcodecinterface.h" |
89 | #include "imagecodecinterface.h" | 90 | #include "imagecodecinterface.h" |
90 | 91 | ||
91 | #include <unistd.h> | 92 | #include <unistd.h> |
92 | #include <sys/file.h> | 93 | #include <sys/file.h> |
93 | #include <sys/ioctl.h> | 94 | #include <sys/ioctl.h> |
94 | #ifndef QT_NO_SOUND | 95 | #ifndef QT_NO_SOUND |
95 | #include <sys/soundcard.h> | 96 | #include <sys/soundcard.h> |
96 | #endif | 97 | #endif |
97 | #include "qt_override_p.h" | 98 | #include "qt_override_p.h" |
98 | 99 | ||
99 | static bool useBigPixmaps = 0; | 100 | static bool useBigPixmaps = 0; |
100 | 101 | ||
101 | class HackWidget : public QWidget | 102 | class HackWidget : public QWidget |
102 | { | 103 | { |
103 | public: | 104 | public: |
104 | bool needsOk() | 105 | bool needsOk() |
105 | { return (getWState() & WState_Reserved1 ); } | 106 | { return (getWState() & WState_Reserved1 ); } |
106 | 107 | ||
107 | QRect normalGeometry() | 108 | QRect normalGeometry() |
108 | { return topData()->normalGeometry; }; | 109 | { return topData()->normalGeometry; }; |
109 | }; | 110 | }; |
110 | 111 | ||
111 | class QPEApplicationData | 112 | class QPEApplicationData |
112 | { | 113 | { |
113 | public: | 114 | public: |
114 | QPEApplicationData ( ) | 115 | QPEApplicationData ( ) |
115 | : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), | 116 | : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), |
116 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), | 117 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), |
117 | keep_running( true ), qcopQok( false ), | 118 | keep_running( true ), qcopQok( false ), |
118 | fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), | 119 | fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), |
119 | bigIconSize( 32 ), qpe_main_widget( 0 ) | 120 | bigIconSize( 32 ), qpe_main_widget( 0 ) |
120 | { | 121 | { |
121 | Config cfg( "qpe" ); | 122 | Config cfg( "qpe" ); |
122 | cfg.setGroup( "Appearance" ); | 123 | cfg.setGroup( "Appearance" ); |
123 | useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); | 124 | useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); |
124 | fontFamily = cfg.readEntry( "FontFamily", "Vera" ); | 125 | fontFamily = cfg.readEntry( "FontFamily", "Vera" ); |
125 | fontSize = cfg.readNumEntry( "FontSize", 10 ); | 126 | fontSize = cfg.readNumEntry( "FontSize", 10 ); |
126 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); | 127 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); |
127 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); | 128 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); |
128 | } | 129 | } |
129 | 130 | ||
130 | int presstimer; | 131 | int presstimer; |
131 | QWidget* presswidget; | 132 | QWidget* presswidget; |
132 | QPoint presspos; | 133 | QPoint presspos; |
133 | 134 | ||
134 | bool rightpressed : 1; | 135 | bool rightpressed : 1; |
135 | bool kbgrabbed : 1; | 136 | bool kbgrabbed : 1; |
136 | bool notbusysent : 1; | 137 | bool notbusysent : 1; |
137 | bool preloaded : 1; | 138 | bool preloaded : 1; |
138 | bool forceshow : 1; | 139 | bool forceshow : 1; |
139 | bool nomaximize : 1; | 140 | bool nomaximize : 1; |
140 | bool keep_running : 1; | 141 | bool keep_running : 1; |
141 | bool qcopQok : 1; | 142 | bool qcopQok : 1; |
142 | 143 | ||
143 | QCString fontFamily; | 144 | QCString fontFamily; |
144 | int fontSize; | 145 | int fontSize; |
145 | int smallIconSize; | 146 | int smallIconSize; |
146 | int bigIconSize; | 147 | int bigIconSize; |
147 | 148 | ||
148 | QStringList langs; | 149 | QStringList langs; |
149 | QString appName; | 150 | QString appName; |
150 | struct QCopRec | 151 | struct QCopRec |
151 | { | 152 | { |
152 | QCopRec( const QCString &ch, const QCString &msg, | 153 | QCopRec( const QCString &ch, const QCString &msg, |
153 | const QByteArray &d ) : | 154 | const QByteArray &d ) : |
154 | channel( ch ), message( msg ), data( d ) | 155 | channel( ch ), message( msg ), data( d ) |
155 | { } | 156 | { } |
156 | 157 | ||
157 | QCString channel; | 158 | QCString channel; |
158 | QCString message; | 159 | QCString message; |
159 | QByteArray data; | 160 | QByteArray data; |
160 | }; | 161 | }; |
161 | QWidget* qpe_main_widget; | 162 | QWidget* qpe_main_widget; |
162 | QGuardedPtr<QWidget> lastraised; | 163 | QGuardedPtr<QWidget> lastraised; |
163 | QQueue<QCopRec> qcopq; | 164 | QQueue<QCopRec> qcopq; |
164 | QString styleName; | 165 | QString styleName; |
165 | QString decorationName; | 166 | QString decorationName; |
166 | 167 | ||
167 | void enqueueQCop( const QCString &ch, const QCString &msg, | 168 | void enqueueQCop( const QCString &ch, const QCString &msg, |
168 | const QByteArray &data ) | 169 | const QByteArray &data ) |
169 | { | 170 | { |
170 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); | 171 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); |
171 | } | 172 | } |
172 | void sendQCopQ() | 173 | void sendQCopQ() |
173 | { | 174 | { |
174 | if (!qcopQok ) | 175 | if (!qcopQok ) |
175 | return; | 176 | return; |
176 | 177 | ||
177 | QCopRec * r; | 178 | QCopRec * r; |
178 | 179 | ||
179 | while((r=qcopq.dequeue())) { | 180 | while((r=qcopq.dequeue())) { |
180 | // remove from queue before sending... | 181 | // remove from queue before sending... |
181 | // event loop can come around again before getting | 182 | // event loop can come around again before getting |
182 | // back from sendLocally | 183 | // back from sendLocally |
183 | #ifndef QT_NO_COP | 184 | #ifndef QT_NO_COP |
184 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 185 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
185 | #endif | 186 | #endif |
186 | 187 | ||
187 | delete r; | 188 | delete r; |
188 | } | 189 | } |
189 | } | 190 | } |
190 | 191 | ||
191 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) | 192 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) |
192 | { | 193 | { |
193 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) | 194 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) |
194 | { | 195 | { |
195 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); | 196 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); |
196 | } | 197 | } |
197 | QPoint p; | 198 | QPoint p; |
198 | QSize s; | 199 | QSize s; |
199 | bool max; | 200 | bool max; |
200 | if ( mw->isVisible() ) { | 201 | if ( mw->isVisible() ) { |
201 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 202 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
202 | mw->resize(s); | 203 | mw->resize(s); |
203 | mw->move(p); | 204 | mw->move(p); |
204 | } | 205 | } |
205 | mw->raise(); | 206 | mw->raise(); |
206 | } else { | 207 | } else { |
207 | 208 | ||
208 | if ( mw->layout() && mw->inherits("QDialog") ) { | 209 | if ( mw->layout() && mw->inherits("QDialog") ) { |
209 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 210 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
210 | mw->resize(s); | 211 | mw->resize(s); |
211 | mw->move(p); | 212 | mw->move(p); |
212 | 213 | ||
213 | if ( max && !nomaximize ) { | 214 | if ( max && !nomaximize ) { |
214 | mw->showMaximized(); | 215 | mw->showMaximized(); |
215 | } else { | 216 | } else { |
216 | mw->show(); | 217 | mw->show(); |
217 | } | 218 | } |
218 | } else { | 219 | } else { |
219 | qpe_show_dialog((QDialog*)mw,nomaximize); | 220 | qpe_show_dialog((QDialog*)mw,nomaximize); |
220 | } | 221 | } |
221 | } else { | 222 | } else { |
222 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 223 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
223 | mw->resize(s); | 224 | mw->resize(s); |
224 | mw->move(p); | 225 | mw->move(p); |
225 | } else { //no stored rectangle, make an estimation | 226 | } else { //no stored rectangle, make an estimation |
226 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; | 227 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; |
227 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; | 228 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; |
228 | mw->move( QMAX(x,0), QMAX(y,0) ); | 229 | mw->move( QMAX(x,0), QMAX(y,0) ); |
229 | #ifdef Q_WS_QWS | 230 | #ifdef Q_WS_QWS |
230 | if ( !nomaximize ) | 231 | if ( !nomaximize ) |
231 | mw->showMaximized(); | 232 | mw->showMaximized(); |
232 | #endif | 233 | #endif |
233 | } | 234 | } |
234 | if ( max && !nomaximize ) | 235 | if ( max && !nomaximize ) |
235 | mw->showMaximized(); | 236 | mw->showMaximized(); |
236 | else | 237 | else |
237 | mw->show(); | 238 | mw->show(); |
238 | } | 239 | } |
239 | } | 240 | } |
240 | } | 241 | } |
241 | 242 | ||
242 | static void qpe_show_dialog( QDialog* d, bool nomax ) | 243 | static void qpe_show_dialog( QDialog* d, bool nomax ) |
243 | { | 244 | { |
244 | QSize sh = d->sizeHint(); | 245 | QSize sh = d->sizeHint(); |
245 | int w = QMAX(sh.width(),d->width()); | 246 | int w = QMAX(sh.width(),d->width()); |
246 | int h = QMAX(sh.height(),d->height()); | 247 | int h = QMAX(sh.height(),d->height()); |
247 | 248 | ||
248 | if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() ) | 249 | if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() ) |
249 | nomax = TRUE; | 250 | nomax = TRUE; |
250 | 251 | ||
251 | #ifndef Q_WS_QWS | 252 | #ifndef Q_WS_QWS |
252 | QSize s(qApp->desktop()->width(), qApp->desktop()->height() ); | 253 | QSize s(qApp->desktop()->width(), qApp->desktop()->height() ); |
253 | #else | 254 | #else |
254 | QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() ); | 255 | QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() ); |
255 | #endif | 256 | #endif |
256 | 257 | ||
257 | int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); | 258 | int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); |
258 | int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); | 259 | int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); |
259 | 260 | ||
260 | if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { | 261 | if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { |
261 | d->showMaximized(); | 262 | d->showMaximized(); |
262 | } else { | 263 | } else { |
263 | // try centering the dialog around its parent | 264 | // try centering the dialog around its parent |
264 | QPoint p(0,0); | 265 | QPoint p(0,0); |
265 | if ( d->parentWidget() ) { | 266 | if ( d->parentWidget() ) { |
266 | QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); | 267 | QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); |
267 | p = QPoint( pp.x() + d->parentWidget()->width()/2, | 268 | p = QPoint( pp.x() + d->parentWidget()->width()/2, |
268 | pp.y() + d->parentWidget()->height()/ 2 ); | 269 | pp.y() + d->parentWidget()->height()/ 2 ); |
269 | } else { | 270 | } else { |
270 | p = QPoint( maxX/2, maxY/2 ); | 271 | p = QPoint( maxX/2, maxY/2 ); |
271 | } | 272 | } |
272 | 273 | ||
273 | p = QPoint( p.x() - w/2, p.y() - h/2 ); | 274 | p = QPoint( p.x() - w/2, p.y() - h/2 ); |
274 | // qDebug("p(x,y) is %d %d", p.x(), p.y() ); | 275 | // qDebug("p(x,y) is %d %d", p.x(), p.y() ); |
275 | 276 | ||
276 | if ( w >= maxX ) { | 277 | if ( w >= maxX ) { |
277 | if ( p.y() < 0 ) | 278 | if ( p.y() < 0 ) |
278 | p.setY(0); | 279 | p.setY(0); |
279 | if ( p.y() + h > maxY ) | 280 | if ( p.y() + h > maxY ) |
280 | p.setY( maxY - h); | 281 | p.setY( maxY - h); |
281 | 282 | ||
282 | d->resize(maxX, h); | 283 | d->resize(maxX, h); |
283 | d->move(0, p.y() ); | 284 | d->move(0, p.y() ); |
284 | } else if ( h >= maxY ) { | 285 | } else if ( h >= maxY ) { |
285 | if ( p.x() < 0 ) | 286 | if ( p.x() < 0 ) |
286 | p.setX(0); | 287 | p.setX(0); |
287 | if ( p.x() + w > maxX ) | 288 | if ( p.x() + w > maxX ) |
288 | p.setX( maxX - w); | 289 | p.setX( maxX - w); |
289 | 290 | ||
290 | d->resize(w, maxY); | 291 | d->resize(w, maxY); |
291 | d->move(p.x(),0); | 292 | d->move(p.x(),0); |
292 | } else { | 293 | } else { |
293 | d->resize(w, h); | 294 | d->resize(w, h); |
294 | } | 295 | } |
295 | 296 | ||
296 | d->show(); | 297 | d->show(); |
297 | } | 298 | } |
298 | } | 299 | } |
299 | 300 | ||
300 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) | 301 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) |
301 | { | 302 | { |
302 | maximized = TRUE; | 303 | maximized = TRUE; |
303 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 304 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
304 | if ( qApp->desktop()->width() <= 350 ) | 305 | if ( qApp->desktop()->width() <= 350 ) |
305 | return FALSE; | 306 | return FALSE; |
306 | 307 | ||
307 | Config cfg( "qpe" ); | 308 | Config cfg( "qpe" ); |
308 | cfg.setGroup("ApplicationPositions"); | 309 | cfg.setGroup("ApplicationPositions"); |
309 | QString str = cfg.readEntry( app, QString::null ); | 310 | QString str = cfg.readEntry( app, QString::null ); |
310 | QStringList l = QStringList::split(",", str); | 311 | QStringList l = QStringList::split(",", str); |
311 | 312 | ||
312 | if ( l.count() == 5) { | 313 | if ( l.count() == 5) { |
313 | p.setX( l[0].toInt() ); | 314 | p.setX( l[0].toInt() ); |
314 | p.setY( l[1].toInt() ); | 315 | p.setY( l[1].toInt() ); |
315 | 316 | ||
316 | s.setWidth( l[2].toInt() ); | 317 | s.setWidth( l[2].toInt() ); |
317 | s.setHeight( l[3].toInt() ); | 318 | s.setHeight( l[3].toInt() ); |
318 | 319 | ||
319 | maximized = l[4].toInt(); | 320 | maximized = l[4].toInt(); |
320 | 321 | ||
321 | return TRUE; | 322 | return TRUE; |
322 | } | 323 | } |
323 | 324 | ||
324 | return FALSE; | 325 | return FALSE; |
325 | } | 326 | } |
326 | 327 | ||
327 | 328 | ||
328 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) | 329 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) |
329 | { | 330 | { |
330 | #ifndef Q_WS_QWS | 331 | #ifndef Q_WS_QWS |
331 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); | 332 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); |
332 | #endif | 333 | #endif |
333 | int maxX = qt_maxWindowRect.width(); | 334 | int maxX = qt_maxWindowRect.width(); |
334 | int maxY = qt_maxWindowRect.height(); | 335 | int maxY = qt_maxWindowRect.height(); |
335 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); | 336 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); |
336 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); | 337 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); |
337 | 338 | ||
338 | // total window size is not allowed to be larger than desktop window size | 339 | // total window size is not allowed to be larger than desktop window size |
339 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) | 340 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) |
340 | return FALSE; | 341 | return FALSE; |
341 | 342 | ||
342 | if ( wWidth > maxX ) { | 343 | if ( wWidth > maxX ) { |
343 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); | 344 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); |
344 | wWidth = maxX; | 345 | wWidth = maxX; |
345 | } | 346 | } |
346 | 347 | ||
347 | if ( wHeight > maxY ) { | 348 | if ( wHeight > maxY ) { |
348 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); | 349 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); |
349 | wHeight = maxY; | 350 | wHeight = maxY; |
350 | } | 351 | } |
351 | 352 | ||
352 | // any smaller than this and the maximize/close/help buttons will be overlapping | 353 | // any smaller than this and the maximize/close/help buttons will be overlapping |
353 | if ( wWidth < 80 || wHeight < 60 ) | 354 | if ( wWidth < 80 || wHeight < 60 ) |
354 | return FALSE; | 355 | return FALSE; |
355 | 356 | ||
356 | if ( p.x() < 0 ) | 357 | if ( p.x() < 0 ) |
357 | p.setX(0); | 358 | p.setX(0); |
358 | if ( p.y() < 0 ) | 359 | if ( p.y() < 0 ) |
359 | p.setY(0); | 360 | p.setY(0); |
360 | 361 | ||
361 | if ( p.x() + wWidth > maxX ) | 362 | if ( p.x() + wWidth > maxX ) |
362 | p.setX( maxX - wWidth ); | 363 | p.setX( maxX - wWidth ); |
363 | if ( p.y() + wHeight > maxY ) | 364 | if ( p.y() + wHeight > maxY ) |
364 | p.setY( maxY - wHeight ); | 365 | p.setY( maxY - wHeight ); |
365 | 366 | ||
366 | return TRUE; | 367 | return TRUE; |
367 | } | 368 | } |
368 | 369 | ||
369 | static void store_widget_rect(QWidget *w, QString &app) | 370 | static void store_widget_rect(QWidget *w, QString &app) |
370 | { | 371 | { |
371 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 372 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
372 | if ( qApp->desktop()->width() <= 350 ) | 373 | if ( qApp->desktop()->width() <= 350 ) |
373 | return; | 374 | return; |
374 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to | 375 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to |
375 | // get the non-maximized version, so we have to do it the hard way ) | 376 | // get the non-maximized version, so we have to do it the hard way ) |
376 | int offsetX = w->x() - w->geometry().left(); | 377 | int offsetX = w->x() - w->geometry().left(); |
377 | int offsetY = w->y() - w->geometry().top(); | 378 | int offsetY = w->y() - w->geometry().top(); |
378 | 379 | ||
379 | QRect r; | 380 | QRect r; |
380 | if ( w->isMaximized() ) | 381 | if ( w->isMaximized() ) |
381 | r = ( (HackWidget *) w)->normalGeometry(); | 382 | r = ( (HackWidget *) w)->normalGeometry(); |
382 | else | 383 | else |
383 | r = w->geometry(); | 384 | r = w->geometry(); |
384 | 385 | ||
385 | // Stores the window placement as pos(), size() (due to the offset mapping) | 386 | // Stores the window placement as pos(), size() (due to the offset mapping) |
386 | Config cfg( "qpe" ); | 387 | Config cfg( "qpe" ); |
387 | cfg.setGroup("ApplicationPositions"); | 388 | cfg.setGroup("ApplicationPositions"); |
388 | QString s; | 389 | QString s; |
389 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); | 390 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); |
390 | cfg.writeEntry( app, s ); | 391 | cfg.writeEntry( app, s ); |
391 | } | 392 | } |
392 | 393 | ||
393 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 394 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
394 | { | 395 | { |
395 | /* | 396 | /* |
396 | // This works but disable it for now until it is safe to apply | 397 | // This works but disable it for now until it is safe to apply |
397 | // What is does is scan the .desktop files of all the apps for | 398 | // What is does is scan the .desktop files of all the apps for |
398 | // the applnk that has the corresponding argv[0] as this program | 399 | // the applnk that has the corresponding argv[0] as this program |
399 | // then it uses the name stored in the .desktop file as the caption | 400 | // then it uses the name stored in the .desktop file as the caption |
400 | // for the main widget. This saves duplicating translations for | 401 | // for the main widget. This saves duplicating translations for |
401 | // the app name in the program and in the .desktop files. | 402 | // the app name in the program and in the .desktop files. |
402 | 403 | ||
403 | AppLnkSet apps( appsPath ); | 404 | AppLnkSet apps( appsPath ); |
404 | 405 | ||
405 | QList<AppLnk> appsList = apps.children(); | 406 | QList<AppLnk> appsList = apps.children(); |
406 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 407 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
407 | if ( (*it)->exec() == appName ) { | 408 | if ( (*it)->exec() == appName ) { |
408 | mw->setCaption( (*it)->name() ); | 409 | mw->setCaption( (*it)->name() ); |
409 | return TRUE; | 410 | return TRUE; |
410 | } | 411 | } |
411 | } | 412 | } |
412 | */ | 413 | */ |
413 | return FALSE; | 414 | return FALSE; |
414 | } | 415 | } |
415 | 416 | ||
416 | 417 | ||
417 | void show(QWidget* mw, bool nomax) | 418 | void show(QWidget* mw, bool nomax) |
418 | { | 419 | { |
419 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); | 420 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); |
420 | nomaximize = nomax; | 421 | nomaximize = nomax; |
421 | qpe_main_widget = mw; | 422 | qpe_main_widget = mw; |
422 | qcopQok = TRUE; | 423 | qcopQok = TRUE; |
423 | #ifndef QT_NO_COP | 424 | #ifndef QT_NO_COP |
424 | 425 | ||
425 | sendQCopQ(); | 426 | sendQCopQ(); |
426 | #endif | 427 | #endif |
427 | 428 | ||
428 | if ( preloaded ) { | 429 | if ( preloaded ) { |
429 | if (forceshow) | 430 | if (forceshow) |
430 | show_mx(mw, nomax, appName); | 431 | show_mx(mw, nomax, appName); |
431 | } | 432 | } |
432 | else if ( keep_running ) { | 433 | else if ( keep_running ) { |
433 | show_mx(mw, nomax, appName); | 434 | show_mx(mw, nomax, appName); |
434 | } | 435 | } |
435 | } | 436 | } |
436 | 437 | ||
437 | void loadTextCodecs() | 438 | void loadTextCodecs() |
438 | { | 439 | { |
439 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; | 440 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; |
440 | #ifdef Q_OS_MACX | 441 | #ifdef Q_OS_MACX |
441 | QDir dir( path, "lib*.dylib" ); | 442 | QDir dir( path, "lib*.dylib" ); |
442 | #else | 443 | #else |
443 | QDir dir( path, "lib*.so" ); | 444 | QDir dir( path, "lib*.so" ); |
444 | #endif | 445 | #endif |
445 | QStringList list; | 446 | QStringList list; |
446 | if ( dir. exists ( )) | 447 | if ( dir. exists ( )) |
447 | list = dir.entryList(); | 448 | list = dir.entryList(); |
448 | QStringList::Iterator it; | 449 | QStringList::Iterator it; |
449 | for ( it = list.begin(); it != list.end(); ++it ) { | 450 | for ( it = list.begin(); it != list.end(); ++it ) { |
450 | TextCodecInterface *iface = 0; | 451 | TextCodecInterface *iface = 0; |
451 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 452 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
452 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 453 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
453 | QValueList<int> mibs = iface->mibEnums(); | 454 | QValueList<int> mibs = iface->mibEnums(); |
454 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 455 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
455 | (void)iface->createForMib(*i); | 456 | (void)iface->createForMib(*i); |
456 | // ### it exists now; need to remember if we can delete it | 457 | // ### it exists now; need to remember if we can delete it |
457 | } | 458 | } |
458 | } | 459 | } |
459 | else { | 460 | else { |
460 | lib->unload(); | 461 | lib->unload(); |
461 | delete lib; | 462 | delete lib; |
462 | } | 463 | } |
463 | } | 464 | } |
464 | } | 465 | } |
465 | 466 | ||
466 | void loadImageCodecs() | 467 | void loadImageCodecs() |
467 | { | 468 | { |
468 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; | 469 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; |
469 | #ifdef Q_OS_MACX | 470 | #ifdef Q_OS_MACX |
470 | QDir dir( path, "lib*.dylib" ); | 471 | QDir dir( path, "lib*.dylib" ); |
471 | #else | 472 | #else |
472 | QDir dir( path, "lib*.so" ); | 473 | QDir dir( path, "lib*.so" ); |
473 | #endif | 474 | #endif |
474 | QStringList list; | 475 | QStringList list; |
475 | if ( dir. exists ( )) | 476 | if ( dir. exists ( )) |
476 | list = dir.entryList(); | 477 | list = dir.entryList(); |
477 | QStringList::Iterator it; | 478 | QStringList::Iterator it; |
478 | for ( it = list.begin(); it != list.end(); ++it ) { | 479 | for ( it = list.begin(); it != list.end(); ++it ) { |
479 | ImageCodecInterface *iface = 0; | 480 | ImageCodecInterface *iface = 0; |
480 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 481 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
481 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 482 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
482 | QStringList formats = iface->keys(); | 483 | QStringList formats = iface->keys(); |
483 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { | 484 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { |
484 | (void)iface->installIOHandler(*i); | 485 | (void)iface->installIOHandler(*i); |
485 | // ### it exists now; need to remember if we can delete it | 486 | // ### it exists now; need to remember if we can delete it |
486 | } | 487 | } |
487 | } | 488 | } |
488 | else { | 489 | else { |
489 | lib->unload(); | 490 | lib->unload(); |
490 | delete lib; | 491 | delete lib; |
491 | } | 492 | } |
492 | } | 493 | } |
493 | } | 494 | } |
494 | }; | 495 | }; |
495 | 496 | ||
496 | class ResourceMimeFactory : public QMimeSourceFactory | 497 | class ResourceMimeFactory : public QMimeSourceFactory |
497 | { | 498 | { |
498 | public: | 499 | public: |
499 | ResourceMimeFactory() : resImage( 0 ) | 500 | ResourceMimeFactory() : resImage( 0 ) |
500 | { | 501 | { |
501 | setFilePath( Global::helpPath() ); | 502 | setFilePath( Global::helpPath() ); |
502 | setExtensionType( "html", "text/html;charset=UTF-8" ); | 503 | setExtensionType( "html", "text/html;charset=UTF-8" ); |
503 | } | 504 | } |
504 | ~ResourceMimeFactory() { | 505 | ~ResourceMimeFactory() { |
505 | delete resImage; | 506 | delete resImage; |
506 | } | 507 | } |
507 | 508 | ||
508 | const QMimeSource* data( const QString& abs_name ) const | 509 | const QMimeSource* data( const QString& abs_name ) const |
509 | { | 510 | { |
510 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); | 511 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); |
511 | if ( !r ) { | 512 | if ( !r ) { |
512 | int sl = abs_name.length(); | 513 | int sl = abs_name.length(); |
513 | do { | 514 | do { |
514 | sl = abs_name.findRev( '/', sl - 1 ); | 515 | sl = abs_name.findRev( '/', sl - 1 ); |
515 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; | 516 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; |
516 | int dot = name.findRev( '.' ); | 517 | int dot = name.findRev( '.' ); |
517 | if ( dot >= 0 ) | 518 | if ( dot >= 0 ) |
518 | name = name.left( dot ); | 519 | name = name.left( dot ); |
519 | QImage img = Resource::loadImage( name ); | 520 | QImage img = Resource::loadImage( name ); |
520 | if ( !img.isNull() ) { | 521 | if ( !img.isNull() ) { |
521 | delete resImage; | 522 | delete resImage; |
522 | resImage = new QImageDrag( img ); | 523 | resImage = new QImageDrag( img ); |
523 | r = resImage; | 524 | r = resImage; |
524 | } | 525 | } |
525 | } | 526 | } |
526 | while ( !r && sl > 0 ); | 527 | while ( !r && sl > 0 ); |
527 | } | 528 | } |
528 | return r; | 529 | return r; |
529 | } | 530 | } |
530 | private: | 531 | private: |
531 | mutable QImageDrag *resImage; | 532 | mutable QImageDrag *resImage; |
532 | }; | 533 | }; |
533 | 534 | ||
534 | static int& hack(int& i) | 535 | static int& hack(int& i) |
535 | { | 536 | { |
536 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 537 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
537 | // These should be created, but aren't in Qt 2.3.0 | 538 | // These should be created, but aren't in Qt 2.3.0 |
538 | (void)new QUtf8Codec; | 539 | (void)new QUtf8Codec; |
539 | (void)new QUtf16Codec; | 540 | (void)new QUtf16Codec; |
540 | #endif | 541 | #endif |
541 | return i; | 542 | return i; |
542 | } | 543 | } |
543 | 544 | ||
544 | static int muted = 0; | 545 | static int muted = 0; |
545 | static int micMuted = 0; | 546 | static int micMuted = 0; |
546 | 547 | ||
547 | static void setVolume( int t = 0, int percent = -1 ) | 548 | static void setVolume( int t = 0, int percent = -1 ) |
548 | { | 549 | { |
549 | switch ( t ) { | 550 | switch ( t ) { |
550 | case 0: { | 551 | case 0: { |
551 | Config cfg( "qpe" ); | 552 | Config cfg( "qpe" ); |
552 | cfg.setGroup( "Volume" ); | 553 | cfg.setGroup( "Volume" ); |
553 | if ( percent < 0 ) | 554 | if ( percent < 0 ) |
554 | percent = cfg.readNumEntry( "VolumePercent", 50 ); | 555 | percent = cfg.readNumEntry( "VolumePercent", 50 ); |
555 | #ifndef QT_NO_SOUND | 556 | #ifndef QT_NO_SOUND |
556 | int fd = 0; | 557 | int fd = 0; |
557 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 558 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
558 | int vol = muted ? 0 : percent; | 559 | int vol = muted ? 0 : percent; |
559 | // set both channels to same volume | 560 | // set both channels to same volume |
560 | vol |= vol << 8; | 561 | vol |= vol << 8; |
561 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); | 562 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); |
562 | ::close( fd ); | 563 | ::close( fd ); |
563 | } | 564 | } |
564 | #endif | 565 | #endif |
565 | } | 566 | } |
566 | break; | 567 | break; |
567 | } | 568 | } |
568 | } | 569 | } |
569 | 570 | ||
570 | static void setMic( int t = 0, int percent = -1 ) | 571 | static void setMic( int t = 0, int percent = -1 ) |
571 | { | 572 | { |
572 | switch ( t ) { | 573 | switch ( t ) { |
573 | case 0: { | 574 | case 0: { |
574 | Config cfg( "qpe" ); | 575 | Config cfg( "qpe" ); |
575 | cfg.setGroup( "Volume" ); | 576 | cfg.setGroup( "Volume" ); |
576 | if ( percent < 0 ) | 577 | if ( percent < 0 ) |
577 | percent = cfg.readNumEntry( "Mic", 50 ); | 578 | percent = cfg.readNumEntry( "Mic", 50 ); |
578 | 579 | ||
579 | #ifndef QT_NO_SOUND | 580 | #ifndef QT_NO_SOUND |
580 | int fd = 0; | 581 | int fd = 0; |
581 | int mic = micMuted ? 0 : percent; | 582 | int mic = micMuted ? 0 : percent; |
582 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 583 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
583 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); | 584 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); |
584 | ::close( fd ); | 585 | ::close( fd ); |
585 | } | 586 | } |
586 | #endif | 587 | #endif |
587 | } | 588 | } |
588 | break; | 589 | break; |
589 | } | 590 | } |
590 | } | 591 | } |
591 | 592 | ||
592 | 593 | ||
593 | static void setBass( int t = 0, int percent = -1 ) | 594 | static void setBass( int t = 0, int percent = -1 ) |
594 | { | 595 | { |
595 | switch ( t ) { | 596 | switch ( t ) { |
596 | case 0: { | 597 | case 0: { |
597 | Config cfg( "qpe" ); | 598 | Config cfg( "qpe" ); |
598 | cfg.setGroup( "Volume" ); | 599 | cfg.setGroup( "Volume" ); |
599 | if ( percent < 0 ) | 600 | if ( percent < 0 ) |
600 | percent = cfg.readNumEntry( "BassPercent", 50 ); | 601 | percent = cfg.readNumEntry( "BassPercent", 50 ); |
601 | 602 | ||
602 | #ifndef QT_NO_SOUND | 603 | #ifndef QT_NO_SOUND |
603 | int fd = 0; | 604 | int fd = 0; |
604 | int bass = percent; | 605 | int bass = percent; |
605 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 606 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
606 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); | 607 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); |
607 | ::close( fd ); | 608 | ::close( fd ); |
608 | } | 609 | } |
609 | #endif | 610 | #endif |
610 | } | 611 | } |
611 | break; | 612 | break; |
612 | } | 613 | } |
613 | } | 614 | } |
614 | 615 | ||
615 | 616 | ||
616 | static void setTreble( int t = 0, int percent = -1 ) | 617 | static void setTreble( int t = 0, int percent = -1 ) |
617 | { | 618 | { |
618 | switch ( t ) { | 619 | switch ( t ) { |
619 | case 0: { | 620 | case 0: { |
620 | Config cfg( "qpe" ); | 621 | Config cfg( "qpe" ); |
621 | cfg.setGroup( "Volume" ); | 622 | cfg.setGroup( "Volume" ); |
622 | if ( percent < 0 ) | 623 | if ( percent < 0 ) |
623 | percent = cfg.readNumEntry( "TreblePercent", 50 ); | 624 | percent = cfg.readNumEntry( "TreblePercent", 50 ); |
624 | 625 | ||
625 | #ifndef QT_NO_SOUND | 626 | #ifndef QT_NO_SOUND |
626 | int fd = 0; | 627 | int fd = 0; |
627 | int treble = percent; | 628 | int treble = percent; |
628 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 629 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
629 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); | 630 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); |
630 | ::close( fd ); | 631 | ::close( fd ); |
631 | } | 632 | } |
632 | #endif | 633 | #endif |
633 | } | 634 | } |
634 | break; | 635 | break; |
635 | } | 636 | } |
636 | } | 637 | } |
637 | 638 | ||
638 | 639 | ||
639 | /** | 640 | /** |
640 | \class QPEApplication | 641 | \class QPEApplication |
641 | \brief The QPEApplication class implements various system services | 642 | \brief The QPEApplication class implements various system services |
642 | that are available to all Qtopia applications. | 643 | that are available to all Qtopia applications. |
643 | 644 | ||
644 | Simply by using QPEApplication instead of QApplication, a standard Qt | 645 | Simply by using QPEApplication instead of QApplication, a standard Qt |
645 | application becomes a Qtopia application. It automatically follows | 646 | application becomes a Qtopia application. It automatically follows |
646 | style changes, quits and raises, and in the | 647 | style changes, quits and raises, and in the |
647 | case of \link docwidget.html document-oriented\endlink applications, | 648 | case of \link docwidget.html document-oriented\endlink applications, |
648 | changes the currently displayed document in response to the environment. | 649 | changes the currently displayed document in response to the environment. |
649 | 650 | ||
650 | To create a \link docwidget.html document-oriented\endlink | 651 | To create a \link docwidget.html document-oriented\endlink |
651 | application use showMainDocumentWidget(); to create a | 652 | application use showMainDocumentWidget(); to create a |
652 | non-document-oriented application use showMainWidget(). The | 653 | non-document-oriented application use showMainWidget(). The |
653 | keepRunning() function indicates whether the application will | 654 | keepRunning() function indicates whether the application will |
654 | continue running after it's processed the last \link qcop.html | 655 | continue running after it's processed the last \link qcop.html |
655 | QCop\endlink message. This can be changed using setKeepRunning(). | 656 | QCop\endlink message. This can be changed using setKeepRunning(). |
656 | 657 | ||
657 | A variety of signals are emitted when certain events occur, for | 658 | A variety of signals are emitted when certain events occur, for |
658 | example, timeChanged(), clockChanged(), weekChanged(), | 659 | example, timeChanged(), clockChanged(), weekChanged(), |
659 | dateFormatChanged() and volumeChanged(). If the application receives | 660 | dateFormatChanged() and volumeChanged(). If the application receives |
660 | a \link qcop.html QCop\endlink message on the application's | 661 | a \link qcop.html QCop\endlink message on the application's |
661 | QPE/Application/\e{appname} channel, the appMessage() signal is | 662 | QPE/Application/\e{appname} channel, the appMessage() signal is |
662 | emitted. There are also flush() and reload() signals, which | 663 | emitted. There are also flush() and reload() signals, which |
663 | are emitted when synching begins and ends respectively - upon these | 664 | are emitted when synching begins and ends respectively - upon these |
664 | signals, the application should save and reload any data | 665 | signals, the application should save and reload any data |
665 | files that are involved in synching. Most of these signals will initially | 666 | files that are involved in synching. Most of these signals will initially |
666 | be received and unfiltered through the appMessage() signal. | 667 | be received and unfiltered through the appMessage() signal. |
667 | 668 | ||
668 | This class also provides a set of useful static functions. The | 669 | This class also provides a set of useful static functions. The |
669 | qpeDir() and documentDir() functions return the respective paths. | 670 | qpeDir() and documentDir() functions return the respective paths. |
670 | The grabKeyboard() and ungrabKeyboard() functions are used to | 671 | The grabKeyboard() and ungrabKeyboard() functions are used to |
671 | control whether the application takes control of the device's | 672 | control whether the application takes control of the device's |
672 | physical buttons (e.g. application launch keys). The stylus' mode of | 673 | physical buttons (e.g. application launch keys). The stylus' mode of |
673 | operation is set with setStylusOperation() and retrieved with | 674 | operation is set with setStylusOperation() and retrieved with |
674 | stylusOperation(). There are also setInputMethodHint() and | 675 | stylusOperation(). There are also setInputMethodHint() and |
675 | inputMethodHint() functions. | 676 | inputMethodHint() functions. |
676 | 677 | ||
677 | \ingroup qtopiaemb | 678 | \ingroup qtopiaemb |
678 | */ | 679 | */ |
679 | 680 | ||
680 | /*! | 681 | /*! |
681 | \fn void QPEApplication::clientMoused() | 682 | \fn void QPEApplication::clientMoused() |
682 | 683 | ||
683 | \internal | 684 | \internal |
684 | */ | 685 | */ |
685 | 686 | ||
686 | /*! | 687 | /*! |
687 | \fn void QPEApplication::timeChanged(); | 688 | \fn void QPEApplication::timeChanged(); |
688 | This signal is emitted when the time changes outside the normal | 689 | This signal is emitted when the time changes outside the normal |
689 | passage of time, i.e. if the time is set backwards or forwards. | 690 | passage of time, i.e. if the time is set backwards or forwards. |
690 | */ | 691 | */ |
691 | 692 | ||
692 | /*! | 693 | /*! |
693 | \fn void QPEApplication::clockChanged( bool ampm ); | 694 | \fn void QPEApplication::clockChanged( bool ampm ); |
694 | 695 | ||
695 | This signal is emitted when the user changes the clock's style. If | 696 | This signal is emitted when the user changes the clock's style. If |
696 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, | 697 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, |
697 | they want a 24-hour clock. | 698 | they want a 24-hour clock. |
698 | */ | 699 | */ |
699 | 700 | ||
700 | /*! | 701 | /*! |
701 | \fn void QPEApplication::volumeChanged( bool muted ) | 702 | \fn void QPEApplication::volumeChanged( bool muted ) |
702 | 703 | ||
703 | This signal is emitted whenever the mute state is changed. If \a | 704 | This signal is emitted whenever the mute state is changed. If \a |
704 | muted is TRUE, then sound output has been muted. | 705 | muted is TRUE, then sound output has been muted. |
705 | */ | 706 | */ |
706 | 707 | ||
707 | /*! | 708 | /*! |
708 | \fn void QPEApplication::weekChanged( bool startOnMonday ) | 709 | \fn void QPEApplication::weekChanged( bool startOnMonday ) |
709 | 710 | ||
710 | This signal is emitted if the week start day is changed. If \a | 711 | This signal is emitted if the week start day is changed. If \a |
711 | startOnMonday is TRUE then the first day of the week is Monday; if | 712 | startOnMonday is TRUE then the first day of the week is Monday; if |
712 | \a startOnMonday is FALSE then the first day of the week is | 713 | \a startOnMonday is FALSE then the first day of the week is |
713 | Sunday. | 714 | Sunday. |
714 | */ | 715 | */ |
715 | 716 | ||
716 | /*! | 717 | /*! |
717 | \fn void QPEApplication::dateFormatChanged(DateFormat) | 718 | \fn void QPEApplication::dateFormatChanged(DateFormat) |
718 | 719 | ||
719 | This signal is emitted whenever the date format is changed. | 720 | This signal is emitted whenever the date format is changed. |
720 | */ | 721 | */ |
721 | 722 | ||
722 | /*! | 723 | /*! |
723 | \fn void QPEApplication::flush() | 724 | \fn void QPEApplication::flush() |
724 | 725 | ||
725 | ### | 726 | ### |
726 | */ | 727 | */ |
727 | 728 | ||
728 | /*! | 729 | /*! |
729 | \fn void QPEApplication::reload() | 730 | \fn void QPEApplication::reload() |
730 | 731 | ||
731 | */ | 732 | */ |
732 | 733 | ||
733 | 734 | ||
734 | 735 | ||
735 | void QPEApplication::processQCopFile() | 736 | void QPEApplication::processQCopFile() |
736 | { | 737 | { |
737 | QString qcopfn("/tmp/qcop-msg-"); | 738 | QString qcopfn("/tmp/qcop-msg-"); |
738 | qcopfn += d->appName; // append command name | 739 | qcopfn += d->appName; // append command name |
739 | 740 | ||
740 | QFile f(qcopfn); | 741 | QFile f(qcopfn); |
741 | if ( f.open(IO_ReadWrite) ) { | 742 | if ( f.open(IO_ReadWrite) ) { |
742 | #ifndef Q_OS_WIN32 | 743 | #ifndef Q_OS_WIN32 |
743 | flock(f.handle(), LOCK_EX); | 744 | flock(f.handle(), LOCK_EX); |
744 | #endif | 745 | #endif |
745 | QDataStream ds(&f); | 746 | QDataStream ds(&f); |
746 | QCString channel, message; | 747 | QCString channel, message; |
747 | QByteArray data; | 748 | QByteArray data; |
748 | while(!ds.atEnd()) { | 749 | while(!ds.atEnd()) { |
749 | ds >> channel >> message >> data; | 750 | ds >> channel >> message >> data; |
750 | d->enqueueQCop(channel,message,data); | 751 | d->enqueueQCop(channel,message,data); |
751 | } | 752 | } |
752 | ::ftruncate(f.handle(), 0); | 753 | ::ftruncate(f.handle(), 0); |
753 | #ifndef Q_OS_WIN32 | 754 | #ifndef Q_OS_WIN32 |
754 | f.flush(); | 755 | f.flush(); |
755 | flock(f.handle(), LOCK_UN); | 756 | flock(f.handle(), LOCK_UN); |
756 | #endif | 757 | #endif |
757 | } | 758 | } |
758 | #endif | 759 | #endif |
759 | } | 760 | } |
760 | 761 | ||
761 | 762 | ||
762 | /*! | 763 | /*! |
763 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) | 764 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) |
764 | 765 | ||
765 | This signal is emitted when a message is received on this | 766 | This signal is emitted when a message is received on this |
766 | application's QPE/Application/<i>appname</i> \link qcop.html | 767 | application's QPE/Application/<i>appname</i> \link qcop.html |
767 | QCop\endlink channel. | 768 | QCop\endlink channel. |
768 | 769 | ||
769 | The slot to which you connect this signal uses \a msg and \a data | 770 | The slot to which you connect this signal uses \a msg and \a data |
770 | in the following way: | 771 | in the following way: |
771 | 772 | ||
772 | \code | 773 | \code |
773 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) | 774 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) |
774 | { | 775 | { |
775 | QDataStream stream( data, IO_ReadOnly ); | 776 | QDataStream stream( data, IO_ReadOnly ); |
776 | if ( msg == "someMessage(int,int,int)" ) { | 777 | if ( msg == "someMessage(int,int,int)" ) { |
777 | int a,b,c; | 778 | int a,b,c; |
778 | stream >> a >> b >> c; | 779 | stream >> a >> b >> c; |
779 | ... | 780 | ... |
780 | } else if ( msg == "otherMessage(QString)" ) { | 781 | } else if ( msg == "otherMessage(QString)" ) { |
781 | ... | 782 | ... |
782 | } | 783 | } |
783 | } | 784 | } |
784 | \endcode | 785 | \endcode |
785 | 786 | ||
786 | \sa qcop.html | 787 | \sa qcop.html |
787 | Note that messages received here may be processed by qpe application | 788 | Note that messages received here may be processed by qpe application |
788 | and emitted as signals, such as flush() and reload(). | 789 | and emitted as signals, such as flush() and reload(). |
789 | */ | 790 | */ |
790 | 791 | ||
791 | /*! | 792 | /*! |
792 | Constructs a QPEApplication just as you would construct | 793 | Constructs a QPEApplication just as you would construct |
793 | a QApplication, passing \a argc, \a argv, and \a t. | 794 | a QApplication, passing \a argc, \a argv, and \a t. |
794 | 795 | ||
795 | For applications, \a t should be the default, GuiClient. Only | 796 | For applications, \a t should be the default, GuiClient. Only |
796 | the Qtopia server passes GuiServer. | 797 | the Qtopia server passes GuiServer. |
797 | */ | 798 | */ |
798 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) | 799 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) |
799 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) | 800 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) |
800 | { | 801 | { |
801 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. | 802 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. |
802 | 803 | ||
803 | d = new QPEApplicationData; | 804 | d = new QPEApplicationData; |
804 | d->loadTextCodecs(); | 805 | d->loadTextCodecs(); |
805 | d->loadImageCodecs(); | 806 | d->loadImageCodecs(); |
806 | int dw = desktop() ->width(); | ||
807 | 807 | ||
808 | setFont( QFont( d->fontFamily, d->fontSize ) ); | 808 | setFont( QFont( d->fontFamily, d->fontSize ) ); |
809 | AppLnk::setSmallIconSize( d->smallIconSize ); | 809 | AppLnk::setSmallIconSize( d->smallIconSize ); |
810 | AppLnk::setBigIconSize( d->bigIconSize ); | 810 | AppLnk::setBigIconSize( d->bigIconSize ); |
811 | 811 | ||
812 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); | 812 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); |
813 | 813 | ||
814 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); | 814 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); |
815 | 815 | ||
816 | 816 | ||
817 | sysChannel = new QCopChannel( "QPE/System", this ); | 817 | sysChannel = new QCopChannel( "QPE/System", this ); |
818 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 818 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
819 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); | 819 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); |
820 | 820 | ||
821 | /* COde now in initapp */ | 821 | /* COde now in initapp */ |
822 | #if 0 | 822 | #if 0 |
823 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 823 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
824 | 824 | ||
825 | QString qcopfn( "/tmp/qcop-msg-" ); | 825 | QString qcopfn( "/tmp/qcop-msg-" ); |
826 | qcopfn += QString( argv[ 0 ] ); // append command name | 826 | qcopfn += QString( argv[ 0 ] ); // append command name |
827 | 827 | ||
828 | QFile f( qcopfn ); | 828 | QFile f( qcopfn ); |
829 | if ( f.open( IO_ReadOnly ) ) { | 829 | if ( f.open( IO_ReadOnly ) ) { |
830 | flock( f.handle(), LOCK_EX ); | 830 | flock( f.handle(), LOCK_EX ); |
831 | } | 831 | } |
832 | 832 | ||
833 | 833 | ||
834 | 834 | ||
835 | QCString channel = QCString( argv[ 0 ] ); | 835 | QCString channel = QCString( argv[ 0 ] ); |
836 | channel.replace( QRegExp( ".*/" ), "" ); | 836 | channel.replace( QRegExp( ".*/" ), "" ); |
837 | d->appName = channel; | 837 | d->appName = channel; |
838 | channel = "QPE/Application/" + channel; | 838 | channel = "QPE/Application/" + channel; |
839 | pidChannel = new QCopChannel( channel, this ); | 839 | pidChannel = new QCopChannel( channel, this ); |
840 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 840 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
841 | this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); | 841 | this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); |
842 | 842 | ||
843 | if ( f.isOpen() ) { | 843 | if ( f.isOpen() ) { |
844 | d->keep_running = FALSE; | 844 | d->keep_running = FALSE; |
845 | QDataStream ds( &f ); | 845 | QDataStream ds( &f ); |
846 | QCString channel, message; | 846 | QCString channel, message; |
847 | QByteArray data; | 847 | QByteArray data; |
848 | while ( !ds.atEnd() ) { | 848 | while ( !ds.atEnd() ) { |
849 | ds >> channel >> message >> data; | 849 | ds >> channel >> message >> data; |
850 | d->enqueueQCop( channel, message, data ); | 850 | d->enqueueQCop( channel, message, data ); |
851 | } | 851 | } |
852 | 852 | ||
853 | flock( f.handle(), LOCK_UN ); | 853 | flock( f.handle(), LOCK_UN ); |
854 | f.close(); | 854 | f.close(); |
855 | f.remove(); | 855 | f.remove(); |
856 | } | 856 | } |
857 | 857 | ||
858 | for ( int a = 0; a < argc; a++ ) { | 858 | for ( int a = 0; a < argc; a++ ) { |
859 | if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { | 859 | if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { |
860 | argv[ a ] = argv[ a + 1 ]; | 860 | argv[ a ] = argv[ a + 1 ]; |
861 | a++; | 861 | a++; |
862 | d->preloaded = TRUE; | 862 | d->preloaded = TRUE; |
863 | argc -= 1; | 863 | argc -= 1; |
864 | } | 864 | } |
865 | else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { | 865 | else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { |
866 | argv[ a ] = argv[ a + 1 ]; | 866 | argv[ a ] = argv[ a + 1 ]; |
867 | a++; | 867 | a++; |
868 | d->preloaded = TRUE; | 868 | d->preloaded = TRUE; |
869 | d->forceshow = TRUE; | 869 | d->forceshow = TRUE; |
870 | argc -= 1; | 870 | argc -= 1; |
871 | } | 871 | } |
872 | } | 872 | } |
873 | 873 | ||
874 | /* overide stored arguments */ | 874 | /* overide stored arguments */ |
875 | setArgs( argc, argv ); | 875 | setArgs( argc, argv ); |
876 | 876 | ||
877 | #endif | 877 | #endif |
878 | #else | 878 | #else |
879 | initApp( argc, argv ); | 879 | initApp( argc, argv ); |
880 | #endif | 880 | #endif |
881 | // qwsSetDecoration( new QPEDecoration() ); | 881 | #ifdef Q_WS_QWS |
882 | 882 | /* load the font renderer factories */ | |
883 | FontDatabase::loadRenderers(); | ||
884 | #endif | ||
883 | #ifndef QT_NO_TRANSLATION | 885 | #ifndef QT_NO_TRANSLATION |
884 | 886 | ||
885 | d->langs = Global::languageList(); | 887 | d->langs = Global::languageList(); |
886 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { | 888 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { |
887 | QString lang = *it; | 889 | QString lang = *it; |
888 | 890 | ||
889 | installTranslation( lang + "/libopie.qm"); | 891 | installTranslation( lang + "/libopie.qm"); |
890 | installTranslation( lang + "/libqpe.qm" ); | 892 | installTranslation( lang + "/libqpe.qm" ); |
891 | installTranslation( lang + "/" + d->appName + ".qm" ); | 893 | installTranslation( lang + "/" + d->appName + ".qm" ); |
892 | 894 | ||
893 | 895 | ||
894 | //###language/font hack; should look it up somewhere | 896 | //###language/font hack; should look it up somewhere |
895 | #ifdef QWS | 897 | #ifdef QWS |
896 | 898 | ||
897 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { | 899 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { |
898 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 900 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
899 | setFont( fn ); | 901 | setFont( fn ); |
900 | } | 902 | } |
901 | #endif | 903 | #endif |
902 | } | 904 | } |
903 | #endif | 905 | #endif |
904 | 906 | ||
905 | applyStyle(); | 907 | applyStyle(); |
906 | 908 | ||
907 | if ( type() == GuiServer ) { | 909 | if ( type() == GuiServer ) { |
908 | setVolume(); | 910 | setVolume(); |
909 | } | 911 | } |
910 | 912 | ||
911 | installEventFilter( this ); | 913 | installEventFilter( this ); |
912 | 914 | ||
913 | QPEMenuToolFocusManager::initialize(); | 915 | QPEMenuToolFocusManager::initialize(); |
914 | 916 | ||
915 | #ifdef QT_NO_QWS_CURSOR | 917 | #ifdef QT_NO_QWS_CURSOR |
916 | // if we have no cursor, probably don't want tooltips | 918 | // if we have no cursor, probably don't want tooltips |
917 | QToolTip::setEnabled( FALSE ); | 919 | QToolTip::setEnabled( FALSE ); |
918 | #endif | 920 | #endif |
919 | } | 921 | } |
920 | 922 | ||
921 | 923 | ||
922 | #ifdef QTOPIA_INTERNAL_INITAPP | 924 | #ifdef QTOPIA_INTERNAL_INITAPP |
923 | void QPEApplication::initApp( int argc, char **argv ) | 925 | void QPEApplication::initApp( int argc, char **argv ) |
924 | { | 926 | { |
925 | delete pidChannel; | 927 | delete pidChannel; |
926 | d->keep_running = TRUE; | 928 | d->keep_running = TRUE; |
927 | d->preloaded = FALSE; | 929 | d->preloaded = FALSE; |
928 | d->forceshow = FALSE; | 930 | d->forceshow = FALSE; |
929 | 931 | ||
930 | QCString channel = QCString(argv[0]); | 932 | QCString channel = QCString(argv[0]); |
931 | 933 | ||
932 | channel.replace(QRegExp(".*/"),""); | 934 | channel.replace(QRegExp(".*/"),""); |
933 | d->appName = channel; | 935 | d->appName = channel; |
934 | 936 | ||
935 | #if QT_VERSION > 235 | 937 | #if QT_VERSION > 235 |
936 | qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 | 938 | qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 |
937 | #endif | 939 | #endif |
938 | 940 | ||
939 | channel = "QPE/Application/" + channel; | 941 | channel = "QPE/Application/" + channel; |
940 | pidChannel = new QCopChannel( channel, this); | 942 | pidChannel = new QCopChannel( channel, this); |
941 | connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 943 | connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
942 | this, SLOT(pidMessage(const QCString&,const QByteArray&))); | 944 | this, SLOT(pidMessage(const QCString&,const QByteArray&))); |
943 | 945 | ||
944 | 946 | ||
945 | 947 | ||
946 | processQCopFile(); | 948 | processQCopFile(); |
947 | d->keep_running = d->qcopq.isEmpty(); | 949 | d->keep_running = d->qcopq.isEmpty(); |
948 | 950 | ||
949 | for (int a=0; a<argc; a++) { | 951 | for (int a=0; a<argc; a++) { |
950 | if ( qstrcmp(argv[a],"-preload")==0 ) { | 952 | if ( qstrcmp(argv[a],"-preload")==0 ) { |
951 | argv[a] = argv[a+1]; | 953 | argv[a] = argv[a+1]; |
952 | a++; | 954 | a++; |
953 | d->preloaded = TRUE; | 955 | d->preloaded = TRUE; |
954 | argc-=1; | 956 | argc-=1; |
955 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { | 957 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { |
956 | argv[a] = argv[a+1]; | 958 | argv[a] = argv[a+1]; |
957 | a++; | 959 | a++; |
958 | d->preloaded = TRUE; | 960 | d->preloaded = TRUE; |
959 | d->forceshow = TRUE; | 961 | d->forceshow = TRUE; |
960 | argc-=1; | 962 | argc-=1; |
961 | } | 963 | } |
962 | } | 964 | } |
963 | 965 | ||
964 | /* overide stored arguments */ | 966 | /* overide stored arguments */ |
965 | setArgs(argc, argv); | 967 | setArgs(argc, argv); |
966 | 968 | ||
967 | /* install translation here */ | 969 | /* install translation here */ |
968 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) | 970 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) |
969 | installTranslation( (*it) + "/" + d->appName + ".qm" ); | 971 | installTranslation( (*it) + "/" + d->appName + ".qm" ); |
970 | } | 972 | } |
971 | #endif | 973 | #endif |
972 | 974 | ||
973 | 975 | ||
974 | static QPtrDict<void>* inputMethodDict = 0; | 976 | static QPtrDict<void>* inputMethodDict = 0; |
975 | static void createInputMethodDict() | 977 | static void createInputMethodDict() |
976 | { | 978 | { |
977 | if ( !inputMethodDict ) | 979 | if ( !inputMethodDict ) |
978 | inputMethodDict = new QPtrDict<void>; | 980 | inputMethodDict = new QPtrDict<void>; |
979 | } | 981 | } |
980 | 982 | ||
981 | /*! | 983 | /*! |
982 | Returns the currently set hint to the system as to whether | 984 | Returns the currently set hint to the system as to whether |
983 | widget \a w has any use for text input methods. | 985 | widget \a w has any use for text input methods. |
984 | 986 | ||
985 | 987 | ||
986 | \sa setInputMethodHint() InputMethodHint | 988 | \sa setInputMethodHint() InputMethodHint |
987 | */ | 989 | */ |
988 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) | 990 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) |
989 | { | 991 | { |
990 | if ( inputMethodDict && w ) | 992 | if ( inputMethodDict && w ) |
991 | return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); | 993 | return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); |
992 | return Normal; | 994 | return Normal; |
993 | } | 995 | } |
994 | 996 | ||
995 | /*! | 997 | /*! |
996 | \enum QPEApplication::InputMethodHint | 998 | \enum QPEApplication::InputMethodHint |
997 | 999 | ||
998 | \value Normal the application sometimes needs text input (the default). | 1000 | \value Normal the application sometimes needs text input (the default). |
999 | \value AlwaysOff the application never needs text input. | 1001 | \value AlwaysOff the application never needs text input. |
1000 | \value AlwaysOn the application always needs text input. | 1002 | \value AlwaysOn the application always needs text input. |
1001 | */ | 1003 | */ |
1002 | 1004 | ||
1003 | /*! | 1005 | /*! |
1004 | Hints to the system that widget \a w has use for text input methods | 1006 | Hints to the system that widget \a w has use for text input methods |
1005 | as specified by \a mode. | 1007 | as specified by \a mode. |
1006 | 1008 | ||
1007 | \sa inputMethodHint() InputMethodHint | 1009 | \sa inputMethodHint() InputMethodHint |
1008 | */ | 1010 | */ |
1009 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) | 1011 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) |
1010 | { | 1012 | { |
1011 | createInputMethodDict(); | 1013 | createInputMethodDict(); |
1012 | if ( mode == Normal ) { | 1014 | if ( mode == Normal ) { |
1013 | inputMethodDict->remove | 1015 | inputMethodDict->remove |
1014 | ( w ); | 1016 | ( w ); |
1015 | } | 1017 | } |
1016 | else { | 1018 | else { |
1017 | inputMethodDict->insert( w, ( void* ) mode ); | 1019 | inputMethodDict->insert( w, ( void* ) mode ); |
1018 | } | 1020 | } |
1019 | } | 1021 | } |
1020 | 1022 | ||
1021 | class HackDialog : public QDialog | 1023 | class HackDialog : public QDialog |
1022 | { | 1024 | { |
1023 | public: | 1025 | public: |
1024 | void acceptIt() | 1026 | void acceptIt() |
1025 | { | 1027 | { |
1026 | accept(); | 1028 | accept(); |
1027 | } | 1029 | } |
1028 | void rejectIt() | 1030 | void rejectIt() |
1029 | { | 1031 | { |
1030 | reject(); | 1032 | reject(); |
1031 | } | 1033 | } |
1032 | }; | 1034 | }; |
1033 | 1035 | ||
1034 | 1036 | ||
1035 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) | 1037 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) |
1036 | { | 1038 | { |
1037 | // specialised actions for certain widgets. May want to | 1039 | // specialised actions for certain widgets. May want to |
1038 | // add more stuff here. | 1040 | // add more stuff here. |
1039 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) | 1041 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) |
1040 | && activePopupWidget() ->parentWidget() | 1042 | && activePopupWidget() ->parentWidget() |
1041 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) | 1043 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) |
1042 | key = Qt::Key_Return; | 1044 | key = Qt::Key_Return; |
1043 | 1045 | ||
1044 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) | 1046 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) |
1045 | key = Qt::Key_Return; | 1047 | key = Qt::Key_Return; |
1046 | 1048 | ||
1047 | #ifdef QWS | 1049 | #ifdef QWS |
1048 | 1050 | ||
1049 | ke->simpleData.keycode = key; | 1051 | ke->simpleData.keycode = key; |
1050 | #endif | 1052 | #endif |
1051 | } | 1053 | } |
1052 | 1054 | ||
1053 | 1055 | ||
1054 | /*! | 1056 | /*! |
1055 | \internal | 1057 | \internal |
1056 | */ | 1058 | */ |
1057 | 1059 | ||
1058 | #ifdef QWS | 1060 | #ifdef QWS |
1059 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) | 1061 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) |
1060 | { | 1062 | { |
1061 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { | 1063 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { |
1062 | if ( qApp->type() != QApplication::GuiServer ) { | 1064 | if ( qApp->type() != QApplication::GuiServer ) { |
1063 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); | 1065 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); |
1064 | e << d->appName; | 1066 | e << d->appName; |
1065 | } | 1067 | } |
1066 | d->notbusysent = TRUE; | 1068 | d->notbusysent = TRUE; |
1067 | } | 1069 | } |
1068 | if ( type() == GuiServer ) { | 1070 | if ( type() == GuiServer ) { |
1069 | switch ( e->type ) { | 1071 | switch ( e->type ) { |
1070 | case QWSEvent::Mouse: | 1072 | case QWSEvent::Mouse: |
1071 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) | 1073 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) |
1072 | emit clientMoused(); | 1074 | emit clientMoused(); |
1073 | break; | 1075 | break; |
1074 | default: | 1076 | default: |
1075 | break; | 1077 | break; |
1076 | } | 1078 | } |
1077 | } | 1079 | } |
1078 | if ( e->type == QWSEvent::Key ) { | 1080 | if ( e->type == QWSEvent::Key ) { |
1079 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; | 1081 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; |
1080 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { | 1082 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { |
1081 | // Use special "OK" key to press "OK" on top level widgets | 1083 | // Use special "OK" key to press "OK" on top level widgets |
1082 | QWidget * active = activeWindow(); | 1084 | QWidget * active = activeWindow(); |
1083 | QWidget *popup = 0; | 1085 | QWidget *popup = 0; |
1084 | if ( active && active->isPopup() ) { | 1086 | if ( active && active->isPopup() ) { |
1085 | popup = active; | 1087 | popup = active; |
1086 | active = active->parentWidget(); | 1088 | active = active->parentWidget(); |
1087 | } | 1089 | } |
1088 | if ( active && ( int ) active->winId() == ke->simpleData.window && | 1090 | if ( active && ( int ) active->winId() == ke->simpleData.window && |
1089 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 1091 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
1090 | if ( ke->simpleData.is_press ) { | 1092 | if ( ke->simpleData.is_press ) { |
1091 | if ( popup ) | 1093 | if ( popup ) |
1092 | popup->close(); | 1094 | popup->close(); |
1093 | if ( active->inherits( "QDialog" ) ) { | 1095 | if ( active->inherits( "QDialog" ) ) { |
1094 | HackDialog * d = ( HackDialog * ) active; | 1096 | HackDialog * d = ( HackDialog * ) active; |
1095 | d->acceptIt(); | 1097 | d->acceptIt(); |
1096 | return TRUE; | 1098 | return TRUE; |
1097 | } | 1099 | } |
1098 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { | 1100 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { |
1099 | QSignal s; | 1101 | QSignal s; |
1100 | s.connect( active, SLOT( accept() ) ); | 1102 | s.connect( active, SLOT( accept() ) ); |
1101 | s.activate(); | 1103 | s.activate(); |
1102 | } | 1104 | } |
1103 | else { | 1105 | else { |
1104 | // do the same as with the select key: Map to the default action of the widget: | 1106 | // do the same as with the select key: Map to the default action of the widget: |
1105 | mapToDefaultAction( ke, Qt::Key_Return ); | 1107 | mapToDefaultAction( ke, Qt::Key_Return ); |
1106 | } | 1108 | } |
1107 | } | 1109 | } |
1108 | } | 1110 | } |
1109 | } | 1111 | } |
1110 | else if ( ke->simpleData.keycode == Qt::Key_F30 ) { | 1112 | else if ( ke->simpleData.keycode == Qt::Key_F30 ) { |
1111 | // Use special "select" key to do whatever default action a widget has | 1113 | // Use special "select" key to do whatever default action a widget has |
1112 | mapToDefaultAction( ke, Qt::Key_Space ); | 1114 | mapToDefaultAction( ke, Qt::Key_Space ); |
1113 | } | 1115 | } |
1114 | else if ( ke->simpleData.keycode == Qt::Key_Escape && | 1116 | else if ( ke->simpleData.keycode == Qt::Key_Escape && |
1115 | ke->simpleData.is_press ) { | 1117 | ke->simpleData.is_press ) { |
1116 | // Escape key closes app if focus on toplevel | 1118 | // Escape key closes app if focus on toplevel |
1117 | QWidget * active = activeWindow(); | 1119 | QWidget * active = activeWindow(); |
1118 | if ( active && active->testWFlags( WType_TopLevel ) && | 1120 | if ( active && active->testWFlags( WType_TopLevel ) && |
1119 | ( int ) active->winId() == ke->simpleData.window && | 1121 | ( int ) active->winId() == ke->simpleData.window && |
1120 | !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 1122 | !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
1121 | if ( active->inherits( "QDialog" ) ) { | 1123 | if ( active->inherits( "QDialog" ) ) { |
1122 | HackDialog * d = ( HackDialog * ) active; | 1124 | HackDialog * d = ( HackDialog * ) active; |
1123 | d->rejectIt(); | 1125 | d->rejectIt(); |
1124 | return TRUE; | 1126 | return TRUE; |
1125 | } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { | 1127 | } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { |
1126 | active->close(); | 1128 | active->close(); |
1127 | } | 1129 | } |
1128 | } | 1130 | } |
1129 | 1131 | ||
1130 | } | 1132 | } |
1131 | else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { | 1133 | else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { |
1132 | // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) | 1134 | // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) |
1133 | // but we cannot access libopie function within libqpe :( | 1135 | // but we cannot access libopie function within libqpe :( |
1134 | 1136 | ||
1135 | QWidget * active = activeWindow ( ); | 1137 | QWidget * active = activeWindow ( ); |
1136 | if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { | 1138 | if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { |
1137 | if ( d-> kbgrabbed ) { // we grabbed the keyboard | 1139 | if ( d-> kbgrabbed ) { // we grabbed the keyboard |
1138 | QChar ch ( ke-> simpleData.unicode ); | 1140 | QChar ch ( ke-> simpleData.unicode ); |
1139 | QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, | 1141 | QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, |
1140 | ke-> simpleData.keycode, | 1142 | ke-> simpleData.keycode, |
1141 | ch. latin1 ( ), | 1143 | ch. latin1 ( ), |
1142 | ke-> simpleData.modifiers, | 1144 | ke-> simpleData.modifiers, |
1143 | QString ( ch ), | 1145 | QString ( ch ), |
1144 | ke-> simpleData.is_auto_repeat, 1 ); | 1146 | ke-> simpleData.is_auto_repeat, 1 ); |
1145 | 1147 | ||
1146 | QObject *which = QWidget::keyboardGrabber ( ); | 1148 | QObject *which = QWidget::keyboardGrabber ( ); |
1147 | if ( !which ) | 1149 | if ( !which ) |
1148 | which = QApplication::focusWidget ( ); | 1150 | which = QApplication::focusWidget ( ); |
1149 | if ( !which ) | 1151 | if ( !which ) |
1150 | which = QApplication::activeWindow ( ); | 1152 | which = QApplication::activeWindow ( ); |
1151 | if ( !which ) | 1153 | if ( !which ) |
1152 | which = qApp; | 1154 | which = qApp; |
1153 | 1155 | ||
1154 | QApplication::sendEvent ( which, &qke ); | 1156 | QApplication::sendEvent ( which, &qke ); |
1155 | } | 1157 | } |
1156 | else { // we didn't grab the keyboard, so send the event to the launcher | 1158 | else { // we didn't grab the keyboard, so send the event to the launcher |
1157 | QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); | 1159 | QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); |
1158 | e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); | 1160 | e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); |
1159 | } | 1161 | } |
1160 | } | 1162 | } |
1161 | return true; | 1163 | return true; |
1162 | } | 1164 | } |
1163 | } | 1165 | } |
1164 | if ( e->type == QWSEvent::Focus ) { | 1166 | if ( e->type == QWSEvent::Focus ) { |
1165 | QWSFocusEvent * fe = ( QWSFocusEvent* ) e; | 1167 | QWSFocusEvent * fe = ( QWSFocusEvent* ) e; |
1166 | if ( !fe->simpleData.get_focus ) { | 1168 | if ( !fe->simpleData.get_focus ) { |
1167 | QWidget * active = activeWindow(); | 1169 | QWidget * active = activeWindow(); |
1168 | while ( active && active->isPopup() ) { | 1170 | while ( active && active->isPopup() ) { |
1169 | active->close(); | 1171 | active->close(); |
1170 | active = activeWindow(); | 1172 | active = activeWindow(); |
1171 | } | 1173 | } |
1172 | } | 1174 | } |
1173 | else { | 1175 | else { |
1174 | // make sure our modal widget is ALWAYS on top | 1176 | // make sure our modal widget is ALWAYS on top |
1175 | QWidget *topm = activeModalWidget(); | 1177 | QWidget *topm = activeModalWidget(); |
1176 | if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { | 1178 | if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { |
1177 | topm->raise(); | 1179 | topm->raise(); |
1178 | } | 1180 | } |
1179 | } | 1181 | } |
1180 | if ( fe->simpleData.get_focus && inputMethodDict ) { | 1182 | if ( fe->simpleData.get_focus && inputMethodDict ) { |
1181 | InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); | 1183 | InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); |
1182 | if ( m == AlwaysOff ) | 1184 | if ( m == AlwaysOff ) |
1183 | Global::hideInputMethod(); | 1185 | Global::hideInputMethod(); |
1184 | if ( m == AlwaysOn ) | 1186 | if ( m == AlwaysOn ) |
1185 | Global::showInputMethod(); | 1187 | Global::showInputMethod(); |
1186 | } | 1188 | } |
1187 | } | 1189 | } |
1188 | 1190 | ||
1189 | 1191 | ||
1190 | return QApplication::qwsEventFilter( e ); | 1192 | return QApplication::qwsEventFilter( e ); |
1191 | } | 1193 | } |
1192 | #endif | 1194 | #endif |
1193 | 1195 | ||
1194 | /*! | 1196 | /*! |
1195 | Destroys the QPEApplication. | 1197 | Destroys the QPEApplication. |
1196 | */ | 1198 | */ |
1197 | QPEApplication::~QPEApplication() | 1199 | QPEApplication::~QPEApplication() |
1198 | { | 1200 | { |
1199 | ungrabKeyboard(); | 1201 | ungrabKeyboard(); |
1200 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 1202 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
1201 | // Need to delete QCopChannels early, since the display will | 1203 | // Need to delete QCopChannels early, since the display will |
1202 | // be gone by the time we get to ~QObject(). | 1204 | // be gone by the time we get to ~QObject(). |
1203 | delete sysChannel; | 1205 | delete sysChannel; |
1204 | delete pidChannel; | 1206 | delete pidChannel; |
1205 | #endif | 1207 | #endif |
1206 | 1208 | ||
1207 | delete d; | 1209 | delete d; |
1208 | } | 1210 | } |
1209 | 1211 | ||
1210 | /*! | 1212 | /*! |
1211 | Returns <tt>$OPIEDIR/</tt>. | 1213 | Returns <tt>$OPIEDIR/</tt>. |
1212 | */ | 1214 | */ |
1213 | QString QPEApplication::qpeDir() | 1215 | QString QPEApplication::qpeDir() |
1214 | { | 1216 | { |
1215 | const char * base = getenv( "OPIEDIR" ); | 1217 | const char * base = getenv( "OPIEDIR" ); |
1216 | if ( base ) | 1218 | if ( base ) |
1217 | return QString( base ) + "/"; | 1219 | return QString( base ) + "/"; |
1218 | 1220 | ||
1219 | return QString( "../" ); | 1221 | return QString( "../" ); |
1220 | } | 1222 | } |
1221 | 1223 | ||
1222 | /*! | 1224 | /*! |
1223 | Returns the user's current Document directory. There is a trailing "/". | 1225 | Returns the user's current Document directory. There is a trailing "/". |
1224 | .. well, it does now,, and there's no trailing '/' | 1226 | .. well, it does now,, and there's no trailing '/' |
1225 | */ | 1227 | */ |
1226 | QString QPEApplication::documentDir() | 1228 | QString QPEApplication::documentDir() |
1227 | { | 1229 | { |
1228 | const char* base = getenv( "HOME"); | 1230 | const char* base = getenv( "HOME"); |
1229 | if ( base ) | 1231 | if ( base ) |
1230 | return QString( base ) + "/Documents"; | 1232 | return QString( base ) + "/Documents"; |
1231 | 1233 | ||
1232 | return QString( "../Documents" ); | 1234 | return QString( "../Documents" ); |
1233 | } | 1235 | } |
1234 | 1236 | ||
1235 | static int deforient = -1; | 1237 | static int deforient = -1; |
1236 | 1238 | ||
1237 | /*! | 1239 | /*! |
1238 | \internal | 1240 | \internal |
1239 | */ | 1241 | */ |
1240 | int QPEApplication::defaultRotation() | 1242 | int QPEApplication::defaultRotation() |
1241 | { | 1243 | { |
1242 | if ( deforient < 0 ) { | 1244 | if ( deforient < 0 ) { |
1243 | QString d = getenv( "QWS_DISPLAY" ); | 1245 | QString d = getenv( "QWS_DISPLAY" ); |
1244 | if ( d.contains( "Rot90" ) ) { | 1246 | if ( d.contains( "Rot90" ) ) { |
1245 | deforient = 90; | 1247 | deforient = 90; |
1246 | } | 1248 | } |
1247 | else if ( d.contains( "Rot180" ) ) { | 1249 | else if ( d.contains( "Rot180" ) ) { |
1248 | deforient = 180; | 1250 | deforient = 180; |
1249 | } | 1251 | } |
1250 | else if ( d.contains( "Rot270" ) ) { | 1252 | else if ( d.contains( "Rot270" ) ) { |
1251 | deforient = 270; | 1253 | deforient = 270; |
1252 | } | 1254 | } |
1253 | else { | 1255 | else { |
1254 | deforient = 0; | 1256 | deforient = 0; |
1255 | } | 1257 | } |
1256 | } | 1258 | } |
1257 | return deforient; | 1259 | return deforient; |
1258 | } | 1260 | } |
1259 | 1261 | ||
1260 | /*! | 1262 | /*! |
1261 | \internal | 1263 | \internal |
1262 | */ | 1264 | */ |
1263 | void QPEApplication::setDefaultRotation( int r ) | 1265 | void QPEApplication::setDefaultRotation( int r ) |
1264 | { | 1266 | { |
1265 | if ( qApp->type() == GuiServer ) { | 1267 | if ( qApp->type() == GuiServer ) { |
1266 | deforient = r; | 1268 | deforient = r; |
1267 | setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); | 1269 | setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); |
1268 | Config config("qpe"); | 1270 | Config config("qpe"); |
1269 | config.setGroup( "Rotation" ); | 1271 | config.setGroup( "Rotation" ); |
1270 | config.writeEntry( "Rot", r ); | 1272 | config.writeEntry( "Rot", r ); |
1271 | } | 1273 | } |
1272 | else { | 1274 | else { |
1273 | #ifndef QT_NO_COP | 1275 | #ifndef QT_NO_COP |
1274 | { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); | 1276 | { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); |
1275 | e << r; | 1277 | e << r; |
1276 | } | 1278 | } |
1277 | #endif | 1279 | #endif |
1278 | 1280 | ||
1279 | } | 1281 | } |
1280 | } | 1282 | } |
1281 | 1283 | ||
1282 | #include <qgfx_qws.h> | 1284 | #include <qgfx_qws.h> |
1283 | #include <qwindowsystem_qws.h> | 1285 | #include <qwindowsystem_qws.h> |
1284 | 1286 | ||
1285 | extern void qws_clearLoadedFonts(); | 1287 | extern void qws_clearLoadedFonts(); |
1286 | 1288 | ||
1287 | void QPEApplication::setCurrentMode( int x, int y, int depth ) | 1289 | void QPEApplication::setCurrentMode( int x, int y, int depth ) |
1288 | { | 1290 | { |
1289 | // Reset the caches | 1291 | // Reset the caches |
1290 | qws_clearLoadedFonts(); | 1292 | qws_clearLoadedFonts(); |
1291 | QPixmapCache::clear(); | 1293 | QPixmapCache::clear(); |
1292 | 1294 | ||
1293 | // Change the screen mode | 1295 | // Change the screen mode |
1294 | qt_screen->setMode(x, y, depth); | 1296 | qt_screen->setMode(x, y, depth); |
1295 | 1297 | ||
1296 | if ( qApp->type() == GuiServer ) { | 1298 | if ( qApp->type() == GuiServer ) { |
1297 | // Reconfigure the GuiServer | 1299 | // Reconfigure the GuiServer |
1298 | qwsServer->beginDisplayReconfigure(); | 1300 | qwsServer->beginDisplayReconfigure(); |
1299 | qwsServer->endDisplayReconfigure(); | 1301 | qwsServer->endDisplayReconfigure(); |
1300 | 1302 | ||
1301 | // Get all the running apps to reset | 1303 | // Get all the running apps to reset |
1302 | QCopEnvelope env( "QPE/System", "reset()" ); | 1304 | QCopEnvelope env( "QPE/System", "reset()" ); |
1303 | } | 1305 | } |
1304 | } | 1306 | } |
1305 | 1307 | ||
1306 | void QPEApplication::reset() { | 1308 | void QPEApplication::reset() { |
1307 | // Reconnect to the screen | 1309 | // Reconnect to the screen |
1308 | qt_screen->disconnect(); | 1310 | qt_screen->disconnect(); |
1309 | qt_screen->connect( QString::null ); | 1311 | qt_screen->connect( QString::null ); |
1310 | 1312 | ||
1311 | // Redraw everything | 1313 | // Redraw everything |
1312 | applyStyle(); | 1314 | applyStyle(); |
1313 | } | 1315 | } |
1314 | 1316 | ||
1315 | 1317 | ||
1316 | #ifdef Q_OS_MACX | 1318 | #ifdef Q_OS_MACX |
1317 | #define WEAK_SYMBOL __attribute__((weak_import)) | 1319 | #define WEAK_SYMBOL __attribute__((weak_import)) |
1318 | #else | 1320 | #else |
1319 | #define WEAK_SYMBOL __attribute__((weak)) | 1321 | #define WEAK_SYMBOL __attribute__((weak)) |
1320 | #endif | 1322 | #endif |
1321 | 1323 | ||
1322 | extern bool qt_left_hand_scrollbars WEAK_SYMBOL; | 1324 | extern bool qt_left_hand_scrollbars WEAK_SYMBOL; |
1323 | /*! | 1325 | /*! |
1324 | \internal | 1326 | \internal |
1325 | */ | 1327 | */ |
1326 | void QPEApplication::applyStyle() | 1328 | void QPEApplication::applyStyle() |
1327 | { | 1329 | { |
1328 | Config config( "qpe" ); | 1330 | Config config( "qpe" ); |
1329 | config.setGroup( "Appearance" ); | 1331 | config.setGroup( "Appearance" ); |
1330 | 1332 | ||
1331 | #if QT_VERSION > 233 | 1333 | #if QT_VERSION > 233 |
1332 | #if !defined(OPIE_NO_OVERRIDE_QT) | 1334 | #if !defined(OPIE_NO_OVERRIDE_QT) |
1333 | // don't block ourselves ... | 1335 | // don't block ourselves ... |
1334 | Opie::force_appearance = 0; | 1336 | Opie::force_appearance = 0; |
1335 | 1337 | ||
1336 | static QString appname = Opie::binaryName ( ); | 1338 | static QString appname = Opie::binaryName ( ); |
1337 | 1339 | ||
1338 | QStringList ex = config. readListEntry ( "NoStyle", ';' ); | 1340 | QStringList ex = config. readListEntry ( "NoStyle", ';' ); |
1339 | int nostyle = 0; | 1341 | int nostyle = 0; |
1340 | for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { | 1342 | for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { |
1341 | if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { | 1343 | if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { |
1342 | nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); | 1344 | nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); |
1343 | break; | 1345 | break; |
1344 | } | 1346 | } |
1345 | } | 1347 | } |
1346 | #else | 1348 | #else |
1347 | int nostyle = 0; | 1349 | int nostyle = 0; |
1348 | #endif | 1350 | #endif |
1349 | 1351 | ||
1350 | // Widget style | 1352 | // Widget style |
1351 | QString style = config.readEntry( "Style", "FlatStyle" ); | 1353 | QString style = config.readEntry( "Style", "FlatStyle" ); |
1352 | 1354 | ||
1353 | // don't set a custom style | 1355 | // don't set a custom style |
1354 | if ( nostyle & Opie::Force_Style ) | 1356 | if ( nostyle & Opie::Force_Style ) |
1355 | style = "FlatStyle"; | 1357 | style = "FlatStyle"; |
1356 | 1358 | ||
1357 | internalSetStyle ( style ); | 1359 | internalSetStyle ( style ); |
1358 | 1360 | ||
1359 | // Colors - from /etc/colors/Liquid.scheme | 1361 | // Colors - from /etc/colors/Liquid.scheme |
1360 | QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); | 1362 | QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); |
1361 | QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); | 1363 | QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); |
1362 | QPalette pal( btncolor, bgcolor ); | 1364 | QPalette pal( btncolor, bgcolor ); |
1363 | QString color = config.readEntry( "Highlight", "#73adef" ); | 1365 | QString color = config.readEntry( "Highlight", "#73adef" ); |
1364 | pal.setColor( QColorGroup::Highlight, QColor( color ) ); | 1366 | pal.setColor( QColorGroup::Highlight, QColor( color ) ); |
1365 | color = config.readEntry( "HighlightedText", "#FFFFFF" ); | 1367 | color = config.readEntry( "HighlightedText", "#FFFFFF" ); |
1366 | pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); | 1368 | pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); |
1367 | color = config.readEntry( "Text", "#000000" ); | 1369 | color = config.readEntry( "Text", "#000000" ); |
1368 | pal.setColor( QColorGroup::Text, QColor( color ) ); | 1370 | pal.setColor( QColorGroup::Text, QColor( color ) ); |
1369 | color = config.readEntry( "ButtonText", "#000000" ); | 1371 | color = config.readEntry( "ButtonText", "#000000" ); |
1370 | pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); | 1372 | pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); |
1371 | color = config.readEntry( "Base", "#FFFFFF" ); | 1373 | color = config.readEntry( "Base", "#FFFFFF" ); |
1372 | pal.setColor( QColorGroup::Base, QColor( color ) ); | 1374 | pal.setColor( QColorGroup::Base, QColor( color ) ); |
1373 | 1375 | ||
1374 | pal.setColor( QPalette::Disabled, QColorGroup::Text, | 1376 | pal.setColor( QPalette::Disabled, QColorGroup::Text, |
1375 | pal.color( QPalette::Active, QColorGroup::Background ).dark() ); | 1377 | pal.color( QPalette::Active, QColorGroup::Background ).dark() ); |
1376 | 1378 | ||
1377 | setPalette( pal, TRUE ); | 1379 | setPalette( pal, TRUE ); |
1378 | 1380 | ||
1379 | 1381 | ||
1380 | // Set the ScrollBar on the 'right' side but only if the weak symbol is present | 1382 | // Set the ScrollBar on the 'right' side but only if the weak symbol is present |
1381 | if (&qt_left_hand_scrollbars ) | 1383 | if (&qt_left_hand_scrollbars ) |
1382 | qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); | 1384 | qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); |
1383 | 1385 | ||
1384 | // Window Decoration | 1386 | // Window Decoration |
1385 | QString dec = config.readEntry( "Decoration", "Flat" ); | 1387 | QString dec = config.readEntry( "Decoration", "Flat" ); |
1386 | 1388 | ||
1387 | // don't set a custom deco | 1389 | // don't set a custom deco |
1388 | if ( nostyle & Opie::Force_Decoration ) | 1390 | if ( nostyle & Opie::Force_Decoration ) |
1389 | dec = ""; | 1391 | dec = ""; |
1390 | 1392 | ||
1391 | 1393 | ||
1392 | if ( dec != d->decorationName ) { | 1394 | if ( dec != d->decorationName ) { |
1393 | qwsSetDecoration( new QPEDecoration( dec ) ); | 1395 | qwsSetDecoration( new QPEDecoration( dec ) ); |
1394 | d->decorationName = dec; | 1396 | d->decorationName = dec; |