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