-rw-r--r-- | library/qpeapplication.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 2bd7cbe..953f9d0 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,577 +1,580 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | */ | 19 | */ |
20 | #define QTOPIA_INTERNAL_LANGLIST | 20 | #define QTOPIA_INTERNAL_LANGLIST |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #ifndef Q_OS_MACX | 23 | #ifndef Q_OS_MACX |
24 | #include <linux/limits.h> // needed for some toolchains (PATH_MAX) | 24 | #include <linux/limits.h> // needed for some toolchains (PATH_MAX) |
25 | #endif | 25 | #endif |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qqueue.h> | 27 | #include <qqueue.h> |
28 | #ifdef Q_WS_QWS | 28 | #ifdef Q_WS_QWS |
29 | #ifndef QT_NO_COP | 29 | #ifndef QT_NO_COP |
30 | #if QT_VERSION <= 231 | 30 | #if QT_VERSION <= 231 |
31 | #define private public | 31 | #define private public |
32 | #define sendLocally processEvent | 32 | #define sendLocally processEvent |
33 | #include "qcopenvelope_qws.h" | 33 | #include "qcopenvelope_qws.h" |
34 | #undef private | 34 | #undef private |
35 | #else | 35 | #else |
36 | #include "qcopenvelope_qws.h" | 36 | #include "qcopenvelope_qws.h" |
37 | #endif | 37 | #endif |
38 | #endif | 38 | #endif |
39 | #include <qwindowsystem_qws.h> | 39 | #include <qwindowsystem_qws.h> |
40 | #endif | 40 | #endif |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qpalette.h> | 42 | #include <qpalette.h> |
43 | #include <qbuffer.h> | 43 | #include <qbuffer.h> |
44 | #include <qptrdict.h> | 44 | #include <qptrdict.h> |
45 | #include <qregexp.h> | 45 | #include <qregexp.h> |
46 | #include <qdir.h> | 46 | #include <qdir.h> |
47 | #include <qlabel.h> | 47 | #include <qlabel.h> |
48 | #include <qdialog.h> | 48 | #include <qdialog.h> |
49 | #include <qdragobject.h> | 49 | #include <qdragobject.h> |
50 | #include <qtextcodec.h> | 50 | #include <qtextcodec.h> |
51 | #include <qevent.h> | 51 | #include <qevent.h> |
52 | #include <qtooltip.h> | 52 | #include <qtooltip.h> |
53 | #include <qsignal.h> | 53 | #include <qsignal.h> |
54 | #include <qmainwindow.h> | 54 | #include <qmainwindow.h> |
55 | #include <qwidgetlist.h> | 55 | #include <qwidgetlist.h> |
56 | #include <qpixmapcache.h> | 56 | #include <qpixmapcache.h> |
57 | 57 | ||
58 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 58 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
59 | #define QTOPIA_INTERNAL_INITAPP | 59 | #define QTOPIA_INTERNAL_INITAPP |
60 | #include "qpeapplication.h" | 60 | #include "qpeapplication.h" |
61 | #include "qpestyle.h" | 61 | #include "qpestyle.h" |
62 | #include "styleinterface.h" | 62 | #include "styleinterface.h" |
63 | #if QT_VERSION >= 0x030000 | 63 | #if QT_VERSION >= 0x030000 |
64 | #include <qstylefactory.h> | 64 | #include <qstylefactory.h> |
65 | #else | 65 | #else |
66 | #include <qplatinumstyle.h> | 66 | #include <qplatinumstyle.h> |
67 | #include <qwindowsstyle.h> | 67 | #include <qwindowsstyle.h> |
68 | #include <qmotifstyle.h> | 68 | #include <qmotifstyle.h> |
69 | #include <qmotifplusstyle.h> | 69 | #include <qmotifplusstyle.h> |
70 | #include "lightstyle.h" | 70 | #include "lightstyle.h" |
71 | 71 | ||
72 | #include <qpe/qlibrary.h> | 72 | #include <qpe/qlibrary.h> |
73 | #endif | 73 | #endif |
74 | #include "global.h" | 74 | #include "global.h" |
75 | #include "resource.h" | 75 | #include "resource.h" |
76 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 76 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
77 | #include "qutfcodec.h" | 77 | #include "qutfcodec.h" |
78 | #endif | 78 | #endif |
79 | #include "config.h" | 79 | #include "config.h" |
80 | #include "network.h" | 80 | #include "network.h" |
81 | #ifdef QWS | 81 | #ifdef QWS |
82 | #include "fontmanager.h" | 82 | #include "fontmanager.h" |
83 | #include "fontdatabase.h" | 83 | #include "fontdatabase.h" |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | #include "alarmserver.h" | 86 | #include "alarmserver.h" |
87 | #include "applnk.h" | 87 | #include "applnk.h" |
88 | #include "qpemenubar.h" | 88 | #include "qpemenubar.h" |
89 | #include "textcodecinterface.h" | 89 | #include "textcodecinterface.h" |
90 | #include "imagecodecinterface.h" | 90 | #include "imagecodecinterface.h" |
91 | #include <qtopia/qpeglobal.h> | 91 | #include <qtopia/qpeglobal.h> |
92 | 92 | ||
93 | #include <unistd.h> | 93 | #include <unistd.h> |
94 | #include <sys/file.h> | 94 | #include <sys/file.h> |
95 | #include <sys/ioctl.h> | 95 | #include <sys/ioctl.h> |
96 | #ifndef QT_NO_SOUND | 96 | #ifndef QT_NO_SOUND |
97 | #include <sys/soundcard.h> | 97 | #include <sys/soundcard.h> |
98 | #endif | 98 | #endif |
99 | 99 | ||
100 | #include <backend/rohfeedback.h> | 100 | #include <backend/rohfeedback.h> |
101 | 101 | ||
102 | 102 | ||
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 | QString appName; | 158 | QString appName; |
159 | struct QCopRec | 159 | struct QCopRec |
160 | { | 160 | { |
161 | QCopRec( const QCString &ch, const QCString &msg, | 161 | QCopRec( const QCString &ch, const QCString &msg, |
162 | const QByteArray &d ) : | 162 | const QByteArray &d ) : |
163 | channel( ch ), message( msg ), data( d ) | 163 | channel( ch ), message( msg ), data( d ) |
164 | { } | 164 | { } |
165 | 165 | ||
166 | QCString channel; | 166 | QCString channel; |
167 | QCString message; | 167 | QCString message; |
168 | QByteArray data; | 168 | QByteArray data; |
169 | }; | 169 | }; |
170 | QWidget* qpe_main_widget; | 170 | QGuardedPtr<QWidget> qpe_main_widget; |
171 | QGuardedPtr<QWidget> lastraised; | 171 | QGuardedPtr<QWidget> lastraised; |
172 | QQueue<QCopRec> qcopq; | 172 | QQueue<QCopRec> qcopq; |
173 | QString styleName; | 173 | QString styleName; |
174 | QString decorationName; | 174 | QString decorationName; |
175 | 175 | ||
176 | void enqueueQCop( const QCString &ch, const QCString &msg, | 176 | void enqueueQCop( const QCString &ch, const QCString &msg, |
177 | const QByteArray &data ) | 177 | const QByteArray &data ) |
178 | { | 178 | { |
179 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); | 179 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); |
180 | } | 180 | } |
181 | void sendQCopQ() | 181 | void sendQCopQ() |
182 | { | 182 | { |
183 | if (!qcopQok ) | 183 | if (!qcopQok ) |
184 | return; | 184 | return; |
185 | 185 | ||
186 | QCopRec * r; | 186 | QCopRec * r; |
187 | 187 | ||
188 | while((r=qcopq.dequeue())) { | 188 | while((r=qcopq.dequeue())) { |
189 | // remove from queue before sending... | 189 | // remove from queue before sending... |
190 | // event loop can come around again before getting | 190 | // event loop can come around again before getting |
191 | // back from sendLocally | 191 | // back from sendLocally |
192 | #ifndef QT_NO_COP | 192 | #ifndef QT_NO_COP |
193 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 193 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
194 | #endif | 194 | #endif |
195 | 195 | ||
196 | delete r; | 196 | delete r; |
197 | } | 197 | } |
198 | } | 198 | } |
199 | 199 | ||
200 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { | 200 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { |
201 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) | 201 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) |
202 | { | 202 | { |
203 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); | 203 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); |
204 | } | 204 | } |
205 | QPoint p; | 205 | QPoint p; |
206 | QSize s; | 206 | QSize s; |
207 | bool max; | 207 | bool max; |
208 | 208 | ||
209 | if ( mw->isVisible() ) { | 209 | if ( mw->isVisible() ) { |
210 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 210 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
211 | mw->resize(s); | 211 | mw->resize(s); |
212 | mw->move(p); | 212 | mw->move(p); |
213 | } | 213 | } |
214 | mw->raise(); | 214 | mw->raise(); |
215 | } else { | 215 | } else { |
216 | 216 | ||
217 | if ( mw->layout() && mw->inherits("QDialog") ) { | 217 | if ( mw->layout() && mw->inherits("QDialog") ) { |
218 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 218 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
219 | mw->resize(s); | 219 | mw->resize(s); |
220 | mw->move(p); | 220 | mw->move(p); |
221 | 221 | ||
222 | if ( max && !nomaximize ) { | 222 | if ( max && !nomaximize ) { |
223 | mw->showMaximized(); | 223 | mw->showMaximized(); |
224 | } else { | 224 | } else { |
225 | mw->show(); | 225 | mw->show(); |
226 | } | 226 | } |
227 | } else { | 227 | } else { |
228 | QPEApplication::showDialog((QDialog*)mw,nomaximize); | 228 | QPEApplication::showDialog((QDialog*)mw,nomaximize); |
229 | } | 229 | } |
230 | } else { | 230 | } else { |
231 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 231 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
232 | mw->resize(s); | 232 | mw->resize(s); |
233 | mw->move(p); | 233 | mw->move(p); |
234 | } else { //no stored rectangle, make an estimation | 234 | } else { //no stored rectangle, make an estimation |
235 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; | 235 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; |
236 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; | 236 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; |
237 | mw->move( QMAX(x,0), QMAX(y,0) ); | 237 | mw->move( QMAX(x,0), QMAX(y,0) ); |
238 | #ifdef Q_WS_QWS | 238 | #ifdef Q_WS_QWS |
239 | if ( !nomaximize ) | 239 | if ( !nomaximize ) |
240 | mw->showMaximized(); | 240 | mw->showMaximized(); |
241 | #endif | 241 | #endif |
242 | } | 242 | } |
243 | if ( max && !nomaximize ) | 243 | if ( max && !nomaximize ) |
244 | mw->showMaximized(); | 244 | mw->showMaximized(); |
245 | else | 245 | else |
246 | mw->show(); | 246 | mw->show(); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) | 251 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) |
252 | { | 252 | { |
253 | maximized = TRUE; | 253 | maximized = TRUE; |
254 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 254 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
255 | if ( qApp->desktop()->width() <= 350 ) | 255 | if ( qApp->desktop()->width() <= 350 ) |
256 | return FALSE; | 256 | return FALSE; |
257 | 257 | ||
258 | Config cfg( "qpe" ); | 258 | Config cfg( "qpe" ); |
259 | cfg.setGroup("ApplicationPositions"); | 259 | cfg.setGroup("ApplicationPositions"); |
260 | QString str = cfg.readEntry( app, QString::null ); | 260 | QString str = cfg.readEntry( app, QString::null ); |
261 | QStringList l = QStringList::split(",", str); | 261 | QStringList l = QStringList::split(",", str); |
262 | 262 | ||
263 | if ( l.count() == 5) { | 263 | if ( l.count() == 5) { |
264 | p.setX( l[0].toInt() ); | 264 | p.setX( l[0].toInt() ); |
265 | p.setY( l[1].toInt() ); | 265 | p.setY( l[1].toInt() ); |
266 | 266 | ||
267 | s.setWidth( l[2].toInt() ); | 267 | s.setWidth( l[2].toInt() ); |
268 | s.setHeight( l[3].toInt() ); | 268 | s.setHeight( l[3].toInt() ); |
269 | 269 | ||
270 | maximized = l[4].toInt(); | 270 | maximized = l[4].toInt(); |
271 | 271 | ||
272 | return TRUE; | 272 | return TRUE; |
273 | } | 273 | } |
274 | 274 | ||
275 | return FALSE; | 275 | return FALSE; |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) | 279 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) |
280 | { | 280 | { |
281 | #ifndef Q_WS_QWS | 281 | #ifndef Q_WS_QWS |
282 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); | 282 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); |
283 | #endif | 283 | #endif |
284 | int maxX = qt_maxWindowRect.width(); | 284 | int maxX = qt_maxWindowRect.width(); |
285 | int maxY = qt_maxWindowRect.height(); | 285 | int maxY = qt_maxWindowRect.height(); |
286 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); | 286 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); |
287 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); | 287 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); |
288 | 288 | ||
289 | // total window size is not allowed to be larger than desktop window size | 289 | // total window size is not allowed to be larger than desktop window size |
290 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) | 290 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) |
291 | return FALSE; | 291 | return FALSE; |
292 | 292 | ||
293 | if ( wWidth > maxX ) { | 293 | if ( wWidth > maxX ) { |
294 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); | 294 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); |
295 | wWidth = maxX; | 295 | wWidth = maxX; |
296 | } | 296 | } |
297 | 297 | ||
298 | if ( wHeight > maxY ) { | 298 | if ( wHeight > maxY ) { |
299 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); | 299 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); |
300 | wHeight = maxY; | 300 | wHeight = maxY; |
301 | } | 301 | } |
302 | 302 | ||
303 | // any smaller than this and the maximize/close/help buttons will be overlapping | 303 | // any smaller than this and the maximize/close/help buttons will be overlapping |
304 | if ( wWidth < 80 || wHeight < 60 ) | 304 | if ( wWidth < 80 || wHeight < 60 ) |
305 | return FALSE; | 305 | return FALSE; |
306 | 306 | ||
307 | if ( p.x() < 0 ) | 307 | if ( p.x() < 0 ) |
308 | p.setX(0); | 308 | p.setX(0); |
309 | if ( p.y() < 0 ) | 309 | if ( p.y() < 0 ) |
310 | p.setY(0); | 310 | p.setY(0); |
311 | 311 | ||
312 | if ( p.x() + wWidth > maxX ) | 312 | if ( p.x() + wWidth > maxX ) |
313 | p.setX( maxX - wWidth ); | 313 | p.setX( maxX - wWidth ); |
314 | if ( p.y() + wHeight > maxY ) | 314 | if ( p.y() + wHeight > maxY ) |
315 | p.setY( maxY - wHeight ); | 315 | p.setY( maxY - wHeight ); |
316 | 316 | ||
317 | return TRUE; | 317 | return TRUE; |
318 | } | 318 | } |
319 | 319 | ||
320 | static void store_widget_rect(QWidget *w, QString &app) | 320 | static void store_widget_rect(QWidget *w, QString &app) |
321 | { | 321 | { |
322 | if( !w ) | ||
323 | return; | ||
324 | |||
322 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 325 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
323 | if ( qApp->desktop()->width() <= 350 ) | 326 | if ( qApp->desktop()->width() <= 350 ) |
324 | return; | 327 | return; |
325 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to | 328 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to |
326 | // get the non-maximized version, so we have to do it the hard way ) | 329 | // get the non-maximized version, so we have to do it the hard way ) |
327 | int offsetX = w->x() - w->geometry().left(); | 330 | int offsetX = w->x() - w->geometry().left(); |
328 | int offsetY = w->y() - w->geometry().top(); | 331 | int offsetY = w->y() - w->geometry().top(); |
329 | 332 | ||
330 | QRect r; | 333 | QRect r; |
331 | if ( w->isMaximized() ) | 334 | if ( w->isMaximized() ) |
332 | r = ( (HackWidget *) w)->normalGeometry(); | 335 | r = ( (HackWidget *) w)->normalGeometry(); |
333 | else | 336 | else |
334 | r = w->geometry(); | 337 | r = w->geometry(); |
335 | 338 | ||
336 | // Stores the window placement as pos(), size() (due to the offset mapping) | 339 | // Stores the window placement as pos(), size() (due to the offset mapping) |
337 | Config cfg( "qpe" ); | 340 | Config cfg( "qpe" ); |
338 | cfg.setGroup("ApplicationPositions"); | 341 | cfg.setGroup("ApplicationPositions"); |
339 | QString s; | 342 | QString s; |
340 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); | 343 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); |
341 | cfg.writeEntry( app, s ); | 344 | cfg.writeEntry( app, s ); |
342 | } | 345 | } |
343 | 346 | ||
344 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 347 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
345 | { | 348 | { |
346 | /* | 349 | /* |
347 | // This works but disable it for now until it is safe to apply | 350 | // This works but disable it for now until it is safe to apply |
348 | // What is does is scan the .desktop files of all the apps for | 351 | // What is does is scan the .desktop files of all the apps for |
349 | // the applnk that has the corresponding argv[0] as this program | 352 | // the applnk that has the corresponding argv[0] as this program |
350 | // then it uses the name stored in the .desktop file as the caption | 353 | // then it uses the name stored in the .desktop file as the caption |
351 | // for the main widget. This saves duplicating translations for | 354 | // for the main widget. This saves duplicating translations for |
352 | // the app name in the program and in the .desktop files. | 355 | // the app name in the program and in the .desktop files. |
353 | 356 | ||
354 | AppLnkSet apps( appsPath ); | 357 | AppLnkSet apps( appsPath ); |
355 | 358 | ||
356 | QList<AppLnk> appsList = apps.children(); | 359 | QList<AppLnk> appsList = apps.children(); |
357 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 360 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
358 | if ( (*it)->exec() == appName ) { | 361 | if ( (*it)->exec() == appName ) { |
359 | mw->setCaption( (*it)->name() ); | 362 | mw->setCaption( (*it)->name() ); |
360 | return TRUE; | 363 | return TRUE; |
361 | } | 364 | } |
362 | } | 365 | } |
363 | */ | 366 | */ |
364 | return FALSE; | 367 | return FALSE; |
365 | } | 368 | } |
366 | 369 | ||
367 | 370 | ||
368 | void show(QWidget* mw, bool nomax) | 371 | void show(QWidget* mw, bool nomax) |
369 | { | 372 | { |
370 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); | 373 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); |
371 | nomaximize = nomax; | 374 | nomaximize = nomax; |
372 | qpe_main_widget = mw; | 375 | qpe_main_widget = mw; |
373 | qcopQok = TRUE; | 376 | qcopQok = TRUE; |
374 | #ifndef QT_NO_COP | 377 | #ifndef QT_NO_COP |
375 | 378 | ||
376 | sendQCopQ(); | 379 | sendQCopQ(); |
377 | #endif | 380 | #endif |
378 | 381 | ||
379 | if ( preloaded ) { | 382 | if ( preloaded ) { |
380 | if (forceshow) | 383 | if (forceshow) |
381 | show_mx(mw, nomax, appName); | 384 | show_mx(mw, nomax, appName); |
382 | } | 385 | } |
383 | else if ( keep_running ) { | 386 | else if ( keep_running ) { |
384 | show_mx(mw, nomax, appName); | 387 | show_mx(mw, nomax, appName); |
385 | } | 388 | } |
386 | } | 389 | } |
387 | 390 | ||
388 | void loadTextCodecs() | 391 | void loadTextCodecs() |
389 | { | 392 | { |
390 | QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; | 393 | QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; |
391 | #ifdef Q_OS_MACX | 394 | #ifdef Q_OS_MACX |
392 | QDir dir( path, "lib*.dylib" ); | 395 | QDir dir( path, "lib*.dylib" ); |
393 | #else | 396 | #else |
394 | QDir dir( path, "lib*.so" ); | 397 | QDir dir( path, "lib*.so" ); |
395 | #endif | 398 | #endif |
396 | QStringList list; | 399 | QStringList list; |
397 | if ( dir. exists ( )) | 400 | if ( dir. exists ( )) |
398 | list = dir.entryList(); | 401 | list = dir.entryList(); |
399 | QStringList::Iterator it; | 402 | QStringList::Iterator it; |
400 | for ( it = list.begin(); it != list.end(); ++it ) { | 403 | for ( it = list.begin(); it != list.end(); ++it ) { |
401 | TextCodecInterface *iface = 0; | 404 | TextCodecInterface *iface = 0; |
402 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 405 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
403 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 406 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
404 | QValueList<int> mibs = iface->mibEnums(); | 407 | QValueList<int> mibs = iface->mibEnums(); |
405 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 408 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
406 | (void)iface->createForMib(*i); | 409 | (void)iface->createForMib(*i); |
407 | // ### it exists now; need to remember if we can delete it | 410 | // ### it exists now; need to remember if we can delete it |
408 | } | 411 | } |
409 | } | 412 | } |
410 | else { | 413 | else { |
411 | lib->unload(); | 414 | lib->unload(); |
412 | delete lib; | 415 | delete lib; |
413 | } | 416 | } |
414 | } | 417 | } |
415 | } | 418 | } |
416 | 419 | ||
417 | void loadImageCodecs() | 420 | void loadImageCodecs() |
418 | { | 421 | { |
419 | QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; | 422 | QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; |
420 | #ifdef Q_OS_MACX | 423 | #ifdef Q_OS_MACX |
421 | QDir dir( path, "lib*.dylib" ); | 424 | QDir dir( path, "lib*.dylib" ); |
422 | #else | 425 | #else |
423 | QDir dir( path, "lib*.so" ); | 426 | QDir dir( path, "lib*.so" ); |
424 | #endif | 427 | #endif |
425 | QStringList list; | 428 | QStringList list; |
426 | if ( dir. exists ( )) | 429 | if ( dir. exists ( )) |
427 | list = dir.entryList(); | 430 | list = dir.entryList(); |
428 | QStringList::Iterator it; | 431 | QStringList::Iterator it; |
429 | for ( it = list.begin(); it != list.end(); ++it ) { | 432 | for ( it = list.begin(); it != list.end(); ++it ) { |
430 | ImageCodecInterface *iface = 0; | 433 | ImageCodecInterface *iface = 0; |
431 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 434 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
432 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 435 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
433 | QStringList formats = iface->keys(); | 436 | QStringList formats = iface->keys(); |
434 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { | 437 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { |
435 | (void)iface->installIOHandler(*i); | 438 | (void)iface->installIOHandler(*i); |
436 | // ### it exists now; need to remember if we can delete it | 439 | // ### it exists now; need to remember if we can delete it |
437 | } | 440 | } |
438 | } | 441 | } |
439 | else { | 442 | else { |
440 | lib->unload(); | 443 | lib->unload(); |
441 | delete lib; | 444 | delete lib; |
442 | } | 445 | } |
443 | } | 446 | } |
444 | } | 447 | } |
445 | 448 | ||
446 | }; | 449 | }; |
447 | 450 | ||
448 | class ResourceMimeFactory : public QMimeSourceFactory | 451 | class ResourceMimeFactory : public QMimeSourceFactory |
449 | { | 452 | { |
450 | public: | 453 | public: |
451 | ResourceMimeFactory() : resImage( 0 ) | 454 | ResourceMimeFactory() : resImage( 0 ) |
452 | { | 455 | { |
453 | setFilePath( Global::helpPath() ); | 456 | setFilePath( Global::helpPath() ); |
454 | setExtensionType( "html", "text/html;charset=UTF-8" ); | 457 | setExtensionType( "html", "text/html;charset=UTF-8" ); |
455 | } | 458 | } |
456 | ~ResourceMimeFactory() { | 459 | ~ResourceMimeFactory() { |
457 | delete resImage; | 460 | delete resImage; |
458 | } | 461 | } |
459 | 462 | ||
460 | const QMimeSource* data( const QString& abs_name ) const | 463 | const QMimeSource* data( const QString& abs_name ) const |
461 | { | 464 | { |
462 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); | 465 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); |
463 | if ( !r ) { | 466 | if ( !r ) { |
464 | int sl = abs_name.length(); | 467 | int sl = abs_name.length(); |
465 | do { | 468 | do { |
466 | sl = abs_name.findRev( '/', sl - 1 ); | 469 | sl = abs_name.findRev( '/', sl - 1 ); |
467 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; | 470 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; |
468 | int dot = name.findRev( '.' ); | 471 | int dot = name.findRev( '.' ); |
469 | if ( dot >= 0 ) | 472 | if ( dot >= 0 ) |
470 | name = name.left( dot ); | 473 | name = name.left( dot ); |
471 | QImage img = Resource::loadImage( name ); | 474 | QImage img = Resource::loadImage( name ); |
472 | if ( !img.isNull() ) { | 475 | if ( !img.isNull() ) { |
473 | delete resImage; | 476 | delete resImage; |
474 | resImage = new QImageDrag( img ); | 477 | resImage = new QImageDrag( img ); |
475 | r = resImage; | 478 | r = resImage; |
476 | } | 479 | } |
477 | } | 480 | } |
478 | while ( !r && sl > 0 ); | 481 | while ( !r && sl > 0 ); |
479 | } | 482 | } |
480 | return r; | 483 | return r; |
481 | } | 484 | } |
482 | private: | 485 | private: |
483 | mutable QImageDrag *resImage; | 486 | mutable QImageDrag *resImage; |
484 | }; | 487 | }; |
485 | 488 | ||
486 | static int& hack(int& i) | 489 | static int& hack(int& i) |
487 | { | 490 | { |
488 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 491 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
489 | // These should be created, but aren't in Qt 2.3.0 | 492 | // These should be created, but aren't in Qt 2.3.0 |
490 | (void)new QUtf8Codec; | 493 | (void)new QUtf8Codec; |
491 | (void)new QUtf16Codec; | 494 | (void)new QUtf16Codec; |
492 | #endif | 495 | #endif |
493 | return i; | 496 | return i; |
494 | } | 497 | } |
495 | 498 | ||
496 | static int muted = 0; | 499 | static int muted = 0; |
497 | static int micMuted = 0; | 500 | static int micMuted = 0; |
498 | 501 | ||
499 | static void setVolume( int t = 0, int percent = -1 ) | 502 | static void setVolume( int t = 0, int percent = -1 ) |
500 | { | 503 | { |
501 | switch ( t ) { | 504 | switch ( t ) { |
502 | case 0: { | 505 | case 0: { |
503 | Config cfg( "qpe" ); | 506 | Config cfg( "qpe" ); |
504 | cfg.setGroup( "Volume" ); | 507 | cfg.setGroup( "Volume" ); |
505 | if ( percent < 0 ) | 508 | if ( percent < 0 ) |
506 | percent = cfg.readNumEntry( "VolumePercent", 50 ); | 509 | percent = cfg.readNumEntry( "VolumePercent", 50 ); |
507 | #ifndef QT_NO_SOUND | 510 | #ifndef QT_NO_SOUND |
508 | int fd = 0; | 511 | int fd = 0; |
509 | #ifdef QT_QWS_DEVFS | 512 | #ifdef QT_QWS_DEVFS |
510 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 513 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
511 | #else | 514 | #else |
512 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 515 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
513 | #endif | 516 | #endif |
514 | int vol = muted ? 0 : percent; | 517 | int vol = muted ? 0 : percent; |
515 | // set both channels to same volume | 518 | // set both channels to same volume |
516 | vol |= vol << 8; | 519 | vol |= vol << 8; |
517 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); | 520 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); |
518 | ::close( fd ); | 521 | ::close( fd ); |
519 | } | 522 | } |
520 | #endif | 523 | #endif |
521 | } | 524 | } |
522 | break; | 525 | break; |
523 | } | 526 | } |
524 | } | 527 | } |
525 | 528 | ||
526 | static void setMic( int t = 0, int percent = -1 ) | 529 | static void setMic( int t = 0, int percent = -1 ) |
527 | { | 530 | { |
528 | switch ( t ) { | 531 | switch ( t ) { |
529 | case 0: { | 532 | case 0: { |
530 | Config cfg( "qpe" ); | 533 | Config cfg( "qpe" ); |
531 | cfg.setGroup( "Volume" ); | 534 | cfg.setGroup( "Volume" ); |
532 | if ( percent < 0 ) | 535 | if ( percent < 0 ) |
533 | percent = cfg.readNumEntry( "Mic", 50 ); | 536 | percent = cfg.readNumEntry( "Mic", 50 ); |
534 | 537 | ||
535 | #ifndef QT_NO_SOUND | 538 | #ifndef QT_NO_SOUND |
536 | int fd = 0; | 539 | int fd = 0; |
537 | int mic = micMuted ? 0 : percent; | 540 | int mic = micMuted ? 0 : percent; |
538 | #ifdef QT_QWS_DEVFS | 541 | #ifdef QT_QWS_DEVFS |
539 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 542 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
540 | #else | 543 | #else |
541 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 544 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
542 | #endif | 545 | #endif |
543 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); | 546 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); |
544 | ::close( fd ); | 547 | ::close( fd ); |
545 | } | 548 | } |
546 | #endif | 549 | #endif |
547 | } | 550 | } |
548 | break; | 551 | break; |
549 | } | 552 | } |
550 | } | 553 | } |
551 | 554 | ||
552 | 555 | ||
553 | static void setBass( int t = 0, int percent = -1 ) | 556 | static void setBass( int t = 0, int percent = -1 ) |
554 | { | 557 | { |
555 | switch ( t ) { | 558 | switch ( t ) { |
556 | case 0: { | 559 | case 0: { |
557 | Config cfg( "qpe" ); | 560 | Config cfg( "qpe" ); |
558 | cfg.setGroup( "Volume" ); | 561 | cfg.setGroup( "Volume" ); |
559 | if ( percent < 0 ) | 562 | if ( percent < 0 ) |
560 | percent = cfg.readNumEntry( "BassPercent", 50 ); | 563 | percent = cfg.readNumEntry( "BassPercent", 50 ); |
561 | 564 | ||
562 | #ifndef QT_NO_SOUND | 565 | #ifndef QT_NO_SOUND |
563 | int fd = 0; | 566 | int fd = 0; |
564 | int bass = percent; | 567 | int bass = percent; |
565 | #ifdef QT_QWS_DEVFS | 568 | #ifdef QT_QWS_DEVFS |
566 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 569 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
567 | #else | 570 | #else |
568 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 571 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
569 | #endif | 572 | #endif |
570 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); | 573 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); |
571 | ::close( fd ); | 574 | ::close( fd ); |
572 | } | 575 | } |
573 | #endif | 576 | #endif |
574 | } | 577 | } |
575 | break; | 578 | break; |
576 | } | 579 | } |
577 | } | 580 | } |