author | zecke <zecke> | 2004-09-10 11:42:53 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-10 11:42:53 (UTC) |
commit | 6adde94c6ee292de5bc87a0c651fef69e8847d7e (patch) (unidiff) | |
tree | 56ae2a840932bd50e16b59232a185e62d17c0843 | |
parent | 854e3af27ee7208bbb3620733a24f0214c0b118a (diff) | |
download | opie-6adde94c6ee292de5bc87a0c651fef69e8847d7e.zip opie-6adde94c6ee292de5bc87a0c651fef69e8847d7e.tar.gz opie-6adde94c6ee292de5bc87a0c651fef69e8847d7e.tar.bz2 |
Remove unused code and mark parameter as Q_UNUSED
-rw-r--r-- | core/launcher/launcherview.cpp | 2 | ||||
-rw-r--r-- | core/launcher/server.cpp | 26 | ||||
-rw-r--r-- | core/launcher/serverapp.cpp | 4 |
3 files changed, 6 insertions, 26 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 0d0f2cb..cd9c14b 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp | |||
@@ -1,1059 +1,1061 @@ | |||
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 | 20 | ||
21 | #include "launcherview.h" | 21 | #include "launcherview.h" |
22 | 22 | ||
23 | /* OPIE */ | 23 | /* OPIE */ |
24 | #include <opie2/odebug.h> | 24 | #include <opie2/odebug.h> |
25 | #include <qtopia/qpeapplication.h> | 25 | #include <qtopia/qpeapplication.h> |
26 | #include <qtopia/private/categories.h> | 26 | #include <qtopia/private/categories.h> |
27 | #include <qtopia/categoryselect.h> | 27 | #include <qtopia/categoryselect.h> |
28 | #include <qtopia/mimetype.h> | 28 | #include <qtopia/mimetype.h> |
29 | #include <qtopia/resource.h> | 29 | #include <qtopia/resource.h> |
30 | using namespace Opie::Core; | 30 | using namespace Opie::Core; |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qiconview.h> | 35 | #include <qiconview.h> |
36 | #include <qobjectlist.h> | 36 | #include <qobjectlist.h> |
37 | 37 | ||
38 | 38 | ||
39 | // These define how the busy icon is animated and highlighted | 39 | // These define how the busy icon is animated and highlighted |
40 | #define BRIGHTEN_BUSY_ICON | 40 | #define BRIGHTEN_BUSY_ICON |
41 | //#define ALPHA_FADE_BUSY_ICON | 41 | //#define ALPHA_FADE_BUSY_ICON |
42 | //#define USE_ANIMATED_BUSY_ICON_OVERLAY | 42 | //#define USE_ANIMATED_BUSY_ICON_OVERLAY |
43 | #define BOUNCE_BUSY_ICON | 43 | #define BOUNCE_BUSY_ICON |
44 | 44 | ||
45 | 45 | ||
46 | class BgPixmap | 46 | class BgPixmap |
47 | { | 47 | { |
48 | public: | 48 | public: |
49 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} | 49 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} |
50 | QPixmap pm; | 50 | QPixmap pm; |
51 | int ref; | 51 | int ref; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | 54 | ||
55 | static QMap<QString,BgPixmap*> *bgCache = 0; | 55 | static QMap<QString,BgPixmap*> *bgCache = 0; |
56 | 56 | ||
57 | static void cleanup_cache() | 57 | static void cleanup_cache() |
58 | { | 58 | { |
59 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | 59 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); |
60 | while ( it != bgCache->end() ) { | 60 | while ( it != bgCache->end() ) { |
61 | QMap<QString,BgPixmap*>::Iterator curr = it; | 61 | QMap<QString,BgPixmap*>::Iterator curr = it; |
62 | ++it; | 62 | ++it; |
63 | delete (*curr); | 63 | delete (*curr); |
64 | bgCache->remove( curr ); | 64 | bgCache->remove( curr ); |
65 | } | 65 | } |
66 | delete bgCache; | 66 | delete bgCache; |
67 | bgCache = 0; | 67 | bgCache = 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | class LauncherItem : public QIconViewItem | 71 | class LauncherItem : public QIconViewItem |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); | 74 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); |
75 | ~LauncherItem(); | 75 | ~LauncherItem(); |
76 | 76 | ||
77 | AppLnk *appLnk() const { return app; } | 77 | AppLnk *appLnk() const { return app; } |
78 | AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } | 78 | AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } |
79 | 79 | ||
80 | void animateIcon(); | 80 | void animateIcon(); |
81 | void resetIcon(); | 81 | void resetIcon(); |
82 | 82 | ||
83 | virtual int compare ( QIconViewItem * i ) const; | 83 | virtual int compare ( QIconViewItem * i ) const; |
84 | void paintItem( QPainter *p, const QColorGroup &cg ); | 84 | void paintItem( QPainter *p, const QColorGroup &cg ); |
85 | 85 | ||
86 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } | 86 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } |
87 | protected: | 87 | protected: |
88 | bool isBigIcon; | 88 | bool isBigIcon; |
89 | int iteration; | 89 | int iteration; |
90 | AppLnk* app; | 90 | AppLnk* app; |
91 | private: | 91 | private: |
92 | void paintAnimatedIcon( QPainter *p ); | 92 | void paintAnimatedIcon( QPainter *p ); |
93 | BusyIndicatorType busyType; | 93 | BusyIndicatorType busyType; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | 96 | ||
97 | class LauncherIconView : public QIconView { | 97 | class LauncherIconView : public QIconView { |
98 | public: | 98 | public: |
99 | LauncherIconView( QWidget* parent, const char* name=0 ) : | 99 | LauncherIconView( QWidget* parent, const char* name=0 ) : |
100 | QIconView(parent,name), | 100 | QIconView(parent,name), |
101 | tf(""), | 101 | tf(""), |
102 | cf(0), | 102 | cf(0), |
103 | bsy(0), | 103 | bsy(0), |
104 | busyTimer(0), | 104 | busyTimer(0), |
105 | bigIcns(TRUE), | 105 | bigIcns(TRUE), |
106 | bgColor(white) | 106 | bgColor(white) |
107 | { | 107 | { |
108 | sortmeth = Name; | 108 | sortmeth = Name; |
109 | hidden.setAutoDelete(TRUE); | 109 | hidden.setAutoDelete(TRUE); |
110 | ike = FALSE; | 110 | ike = FALSE; |
111 | calculateGrid( Bottom ); | 111 | calculateGrid( Bottom ); |
112 | } | 112 | } |
113 | 113 | ||
114 | ~LauncherIconView() | 114 | ~LauncherIconView() |
115 | { | 115 | { |
116 | #if 0 // debuggery | 116 | #if 0 // debuggery |
117 | QListIterator<AppLnk> it(hidden); | 117 | QListIterator<AppLnk> it(hidden); |
118 | AppLnk* l; | 118 | AppLnk* l; |
119 | while ((l=it.current())) { | 119 | while ((l=it.current())) { |
120 | ++it; | 120 | ++it; |
121 | //odebug << "" << l << ": hidden (should remove)" << oendl; | 121 | //odebug << "" << l << ": hidden (should remove)" << oendl; |
122 | } | 122 | } |
123 | #endif | 123 | #endif |
124 | } | 124 | } |
125 | 125 | ||
126 | QIconViewItem* busyItem() const { return bsy; } | 126 | QIconViewItem* busyItem() const { return bsy; } |
127 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 127 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
128 | QPixmap busyPixmap() const { return busyPix; } | 128 | QPixmap busyPixmap() const { return busyPix; } |
129 | #endif | 129 | #endif |
130 | void setBigIcons( bool bi ) { | 130 | void setBigIcons( bool bi ) { |
131 | bigIcns = bi; | 131 | bigIcns = bi; |
132 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 132 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
133 | busyPix.resize(0,0); | 133 | busyPix.resize(0,0); |
134 | #endif | 134 | #endif |
135 | } | 135 | } |
136 | 136 | ||
137 | void updateCategoriesAndMimeTypes(); | 137 | void updateCategoriesAndMimeTypes(); |
138 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } | 138 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } |
139 | void doAutoScroll() | 139 | void doAutoScroll() |
140 | { | 140 | { |
141 | // We don't want rubberbanding (yet) | 141 | // We don't want rubberbanding (yet) |
142 | } | 142 | } |
143 | 143 | ||
144 | void setBusy(bool on) | 144 | void setBusy(bool on) |
145 | { | 145 | { |
146 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 146 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
147 | if ( busyPix.isNull() ) { | 147 | if ( busyPix.isNull() ) { |
148 | int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); | 148 | int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); |
149 | busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); | 149 | busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); |
150 | } | 150 | } |
151 | #endif | 151 | #endif |
152 | 152 | ||
153 | if ( on ) { | 153 | if ( on ) { |
154 | busyTimer = startTimer( 100 ); | 154 | busyTimer = startTimer( 100 ); |
155 | } else { | 155 | } else { |
156 | if ( busyTimer ) { | 156 | if ( busyTimer ) { |
157 | killTimer( busyTimer ); | 157 | killTimer( busyTimer ); |
158 | busyTimer = 0; | 158 | busyTimer = 0; |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; | 162 | LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; |
163 | 163 | ||
164 | if ( bsy != c ) { | 164 | if ( bsy != c ) { |
165 | LauncherItem *oldBusy = bsy; | 165 | LauncherItem *oldBusy = bsy; |
166 | bsy = c; | 166 | bsy = c; |
167 | if ( oldBusy ) { | 167 | if ( oldBusy ) { |
168 | oldBusy->resetIcon(); | 168 | oldBusy->resetIcon(); |
169 | } | 169 | } |
170 | if ( bsy ) { | 170 | if ( bsy ) { |
171 | bsy->setBusyIndicatorType( busyType ) ; | 171 | bsy->setBusyIndicatorType( busyType ) ; |
172 | bsy->animateIcon(); | 172 | bsy->animateIcon(); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | bool inKeyEvent() const { return ike; } | 177 | bool inKeyEvent() const { return ike; } |
178 | void keyPressEvent(QKeyEvent* e) | 178 | void keyPressEvent(QKeyEvent* e) |
179 | { | 179 | { |
180 | ike = TRUE; | 180 | ike = TRUE; |
181 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { | 181 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { |
182 | if ( (e->state() & ShiftButton) ) | 182 | if ( (e->state() & ShiftButton) ) |
183 | emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); | 183 | emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); |
184 | else | 184 | else |
185 | returnPressed(currentItem()); | 185 | returnPressed(currentItem()); |
186 | } | 186 | } |
187 | 187 | ||
188 | QIconView::keyPressEvent(e); | 188 | QIconView::keyPressEvent(e); |
189 | ike = FALSE; | 189 | ike = FALSE; |
190 | } | 190 | } |
191 | 191 | ||
192 | void addItem(AppLnk* app, bool resort=TRUE); | 192 | void addItem(AppLnk* app, bool resort=TRUE); |
193 | bool removeLink(const QString& linkfile); | 193 | bool removeLink(const QString& linkfile); |
194 | 194 | ||
195 | QStringList mimeTypes() const; | 195 | QStringList mimeTypes() const; |
196 | QStringList categories() const; | 196 | QStringList categories() const; |
197 | 197 | ||
198 | void clear() | 198 | void clear() |
199 | { | 199 | { |
200 | mimes.clear(); | 200 | mimes.clear(); |
201 | cats.clear(); | 201 | cats.clear(); |
202 | QIconView::clear(); | 202 | QIconView::clear(); |
203 | hidden.clear(); | 203 | hidden.clear(); |
204 | } | 204 | } |
205 | 205 | ||
206 | void addCatsAndMimes(AppLnk* app) | 206 | void addCatsAndMimes(AppLnk* app) |
207 | { | 207 | { |
208 | // QStringList c = app->categories(); | 208 | // QStringList c = app->categories(); |
209 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { | 209 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { |
210 | // cats.replace(*cit,(void*)1); | 210 | // cats.replace(*cit,(void*)1); |
211 | // } | 211 | // } |
212 | QString maj=app->type(); | 212 | QString maj=app->type(); |
213 | int sl=maj.find('/'); | 213 | int sl=maj.find('/'); |
214 | if (sl>=0) { | 214 | if (sl>=0) { |
215 | QString k; | 215 | QString k; |
216 | k = maj.left(12) == "application/" ? maj : maj.left(sl); | 216 | k = maj.left(12) == "application/" ? maj : maj.left(sl); |
217 | mimes.replace(k,(void*)1); | 217 | mimes.replace(k,(void*)1); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | void setBackgroundOrigin( QWidget::BackgroundOrigin ) { | 221 | void setBackgroundOrigin( QWidget::BackgroundOrigin ) { |
222 | } | 222 | } |
223 | 223 | ||
224 | void setBackgroundPixmap( const QPixmap &pm ) { | 224 | void setBackgroundPixmap( const QPixmap &pm ) { |
225 | bgPixmap = pm; | 225 | bgPixmap = pm; |
226 | } | 226 | } |
227 | 227 | ||
228 | void setBackgroundColor( const QColor &c ) { | 228 | void setBackgroundColor( const QColor &c ) { |
229 | bgColor = c; | 229 | bgColor = c; |
230 | } | 230 | } |
231 | 231 | ||
232 | void drawBackground( QPainter *p, const QRect &r ) | 232 | void drawBackground( QPainter *p, const QRect &r ) |
233 | { | 233 | { |
234 | if ( !bgPixmap.isNull() ) { | 234 | if ( !bgPixmap.isNull() ) { |
235 | p->drawTiledPixmap( r, bgPixmap, | 235 | p->drawTiledPixmap( r, bgPixmap, |
236 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), | 236 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), |
237 | (r.y() + contentsY()) % bgPixmap.height() ) ); | 237 | (r.y() + contentsY()) % bgPixmap.height() ) ); |
238 | } else { | 238 | } else { |
239 | p->fillRect( r, bgColor ); | 239 | p->fillRect( r, bgColor ); |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | void setItemTextPos( ItemTextPos pos ) | 243 | void setItemTextPos( ItemTextPos pos ) |
244 | { | 244 | { |
245 | calculateGrid( pos ); | 245 | calculateGrid( pos ); |
246 | QIconView::setItemTextPos( pos ); | 246 | QIconView::setItemTextPos( pos ); |
247 | } | 247 | } |
248 | 248 | ||
249 | void hideOrShowItems(bool resort); | 249 | void hideOrShowItems(bool resort); |
250 | 250 | ||
251 | void setTypeFilter(const QString& typefilter, bool resort) | 251 | void setTypeFilter(const QString& typefilter, bool resort) |
252 | { | 252 | { |
253 | tf = QRegExp(typefilter,FALSE,TRUE); | 253 | tf = QRegExp(typefilter,FALSE,TRUE); |
254 | hideOrShowItems(resort); | 254 | hideOrShowItems(resort); |
255 | } | 255 | } |
256 | 256 | ||
257 | void setCategoryFilter( int catfilter, bool resort ) | 257 | void setCategoryFilter( int catfilter, bool resort ) |
258 | { | 258 | { |
259 | Categories cat; | 259 | Categories cat; |
260 | cat.load( categoryFileName() ); | 260 | cat.load( categoryFileName() ); |
261 | QString str; | 261 | QString str; |
262 | if ( catfilter == -2 ) | 262 | if ( catfilter == -2 ) |
263 | cf = 0; | 263 | cf = 0; |
264 | else | 264 | else |
265 | cf = catfilter; | 265 | cf = catfilter; |
266 | hideOrShowItems(resort); | 266 | hideOrShowItems(resort); |
267 | } | 267 | } |
268 | 268 | ||
269 | enum SortMethod { Name, Date, Type }; | 269 | enum SortMethod { Name, Date, Type }; |
270 | 270 | ||
271 | void setSortMethod( SortMethod m ) | 271 | void setSortMethod( SortMethod m ) |
272 | { | 272 | { |
273 | if ( sortmeth != m ) { | 273 | if ( sortmeth != m ) { |
274 | sortmeth = m; | 274 | sortmeth = m; |
275 | sort(); | 275 | sort(); |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | int compare(const AppLnk* a, const AppLnk* b) | 279 | int compare(const AppLnk* a, const AppLnk* b) |
280 | { | 280 | { |
281 | switch (sortmeth) { | 281 | switch (sortmeth) { |
282 | case Name: | 282 | case Name: |
283 | return a->name().lower().compare(b->name().lower()); | 283 | return a->name().lower().compare(b->name().lower()); |
284 | case Date: { | 284 | case Date: { |
285 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); | 285 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); |
286 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); | 286 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); |
287 | return fa.lastModified().secsTo(fb.lastModified()); | 287 | return fa.lastModified().secsTo(fb.lastModified()); |
288 | } | 288 | } |
289 | case Type: | 289 | case Type: |
290 | return a->type().compare(b->type()); | 290 | return a->type().compare(b->type()); |
291 | } | 291 | } |
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
294 | 294 | ||
295 | protected: | 295 | protected: |
296 | 296 | ||
297 | void timerEvent( QTimerEvent *te ) | 297 | void timerEvent( QTimerEvent *te ) |
298 | { | 298 | { |
299 | if ( te->timerId() == busyTimer ) { | 299 | if ( te->timerId() == busyTimer ) { |
300 | if ( bsy ) | 300 | if ( bsy ) |
301 | bsy->animateIcon(); | 301 | bsy->animateIcon(); |
302 | } else { | 302 | } else { |
303 | QIconView::timerEvent( te ); | 303 | QIconView::timerEvent( te ); |
304 | } | 304 | } |
305 | } | 305 | } |
306 | 306 | ||
307 | void styleChange( QStyle &old ) | 307 | void styleChange( QStyle &old ) |
308 | { | 308 | { |
309 | QIconView::styleChange( old ); | 309 | QIconView::styleChange( old ); |
310 | calculateGrid( itemTextPos() ); | 310 | calculateGrid( itemTextPos() ); |
311 | } | 311 | } |
312 | 312 | ||
313 | void calculateGrid( ItemTextPos pos ) | 313 | void calculateGrid( ItemTextPos pos ) |
314 | { | 314 | { |
315 | int dw = QApplication::desktop()->width(); | 315 | int dw = QApplication::desktop()->width(); |
316 | int viewerWidth = dw-style().scrollBarExtent().width(); | 316 | int viewerWidth = dw-style().scrollBarExtent().width(); |
317 | if ( pos == Bottom ) { | 317 | if ( pos == Bottom ) { |
318 | int cols = 3; | 318 | int cols = 3; |
319 | if ( viewerWidth <= 200 ) | 319 | if ( viewerWidth <= 200 ) |
320 | cols = 2; | 320 | cols = 2; |
321 | else if ( viewerWidth >= 400 ) | 321 | else if ( viewerWidth >= 400 ) |
322 | cols = viewerWidth/96; | 322 | cols = viewerWidth/96; |
323 | setSpacing( 4 ); | 323 | setSpacing( 4 ); |
324 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 324 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
325 | setGridY( fontMetrics().height()*2+24 ); | 325 | setGridY( fontMetrics().height()*2+24 ); |
326 | } else { | 326 | } else { |
327 | int cols = 2; | 327 | int cols = 2; |
328 | if ( viewerWidth < 150 ) | 328 | if ( viewerWidth < 150 ) |
329 | cols = 1; | 329 | cols = 1; |
330 | else if ( viewerWidth >= 400 ) | 330 | else if ( viewerWidth >= 400 ) |
331 | cols = viewerWidth/150; | 331 | cols = viewerWidth/150; |
332 | setSpacing( 2 ); | 332 | setSpacing( 2 ); |
333 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 333 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
334 | setGridY( fontMetrics().height()+2 ); | 334 | setGridY( fontMetrics().height()+2 ); |
335 | } | 335 | } |
336 | } | 336 | } |
337 | 337 | ||
338 | void focusInEvent( QFocusEvent * ) {} | 338 | void focusInEvent( QFocusEvent * ) {} |
339 | void focusOutEvent( QFocusEvent * ) {} | 339 | void focusOutEvent( QFocusEvent * ) {} |
340 | 340 | ||
341 | private: | 341 | private: |
342 | QList<AppLnk> hidden; | 342 | QList<AppLnk> hidden; |
343 | QDict<void> mimes; | 343 | QDict<void> mimes; |
344 | QDict<void> cats; | 344 | QDict<void> cats; |
345 | SortMethod sortmeth; | 345 | SortMethod sortmeth; |
346 | QRegExp tf; | 346 | QRegExp tf; |
347 | int cf; | 347 | int cf; |
348 | LauncherItem* bsy; | 348 | LauncherItem* bsy; |
349 | int busyTimer; | 349 | int busyTimer; |
350 | bool ike; | 350 | bool ike; |
351 | bool bigIcns; | 351 | bool bigIcns; |
352 | QPixmap bgPixmap; | 352 | QPixmap bgPixmap; |
353 | QColor bgColor; | 353 | QColor bgColor; |
354 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 354 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
355 | QPixmap busyPix; | 355 | QPixmap busyPix; |
356 | #endif | 356 | #endif |
357 | BusyIndicatorType busyType; | 357 | BusyIndicatorType busyType; |
358 | }; | 358 | }; |
359 | 359 | ||
360 | 360 | ||
361 | bool LauncherView::bsy=FALSE; | 361 | bool LauncherView::bsy=FALSE; |
362 | 362 | ||
363 | void LauncherView::setBusy(bool on) | 363 | void LauncherView::setBusy(bool on) |
364 | { | 364 | { |
365 | icons->setBusy(on); | 365 | icons->setBusy(on); |
366 | } | 366 | } |
367 | 367 | ||
368 | void LauncherView::setBusyIndicatorType( const QString& type ) { | 368 | void LauncherView::setBusyIndicatorType( const QString& type ) { |
369 | if ( type. lower ( ) == "animated" ) | 369 | if ( type. lower ( ) == "animated" ) |
370 | icons->setBusyIndicatorType( BIT_Animated ) ; | 370 | icons->setBusyIndicatorType( BIT_Animated ) ; |
371 | else | 371 | else |
372 | icons->setBusyIndicatorType( BIT_Normal ) ; | 372 | icons->setBusyIndicatorType( BIT_Normal ) ; |
373 | } | 373 | } |
374 | 374 | ||
375 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) | 375 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) |
376 | : QIconViewItem( parent, applnk->name(), | 376 | : QIconViewItem( parent, applnk->name(), |
377 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), | 377 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), |
378 | isBigIcon( bigIcon ), | 378 | isBigIcon( bigIcon ), |
379 | iteration(0), | 379 | iteration(0), |
380 | app(applnk) // Takes ownership | 380 | app(applnk) // Takes ownership |
381 | { | 381 | { |
382 | } | 382 | } |
383 | 383 | ||
384 | LauncherItem::~LauncherItem() | 384 | LauncherItem::~LauncherItem() |
385 | { | 385 | { |
386 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 386 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
387 | if ( liv->busyItem() == this ) | 387 | if ( liv->busyItem() == this ) |
388 | liv->setBusy(FALSE); | 388 | liv->setBusy(FALSE); |
389 | delete app; | 389 | delete app; |
390 | } | 390 | } |
391 | 391 | ||
392 | int LauncherItem::compare ( QIconViewItem * i ) const | 392 | int LauncherItem::compare ( QIconViewItem * i ) const |
393 | { | 393 | { |
394 | LauncherIconView* view = (LauncherIconView*)iconView(); | 394 | LauncherIconView* view = (LauncherIconView*)iconView(); |
395 | return view->compare(app,((LauncherItem *)i)->appLnk()); | 395 | return view->compare(app,((LauncherItem *)i)->appLnk()); |
396 | } | 396 | } |
397 | 397 | ||
398 | void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) | 398 | void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) |
399 | { | 399 | { |
400 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 400 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
401 | QBrush oldBrush( liv->itemTextBackground() ); | 401 | QBrush oldBrush( liv->itemTextBackground() ); |
402 | QColorGroup mycg( cg ); | 402 | QColorGroup mycg( cg ); |
403 | if ( liv->currentItem() == this ) { | 403 | if ( liv->currentItem() == this ) { |
404 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); | 404 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); |
405 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); | 405 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); |
406 | } | 406 | } |
407 | 407 | ||
408 | QIconViewItem::paintItem(p,mycg); | 408 | QIconViewItem::paintItem(p,mycg); |
409 | 409 | ||
410 | // Paint animation overlay | 410 | // Paint animation overlay |
411 | if ( liv->busyItem() == this ) | 411 | if ( liv->busyItem() == this ) |
412 | paintAnimatedIcon(p); | 412 | paintAnimatedIcon(p); |
413 | 413 | ||
414 | if ( liv->currentItem() == this ) | 414 | if ( liv->currentItem() == this ) |
415 | liv->setItemTextBackground( oldBrush ); | 415 | liv->setItemTextBackground( oldBrush ); |
416 | } | 416 | } |
417 | 417 | ||
418 | 418 | ||
419 | 419 | ||
420 | void LauncherItem::paintAnimatedIcon( QPainter *p ) | 420 | void LauncherItem::paintAnimatedIcon( QPainter *p ) |
421 | { | 421 | { |
422 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 422 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
423 | int pic = iteration % 16; | 423 | int pic = iteration % 16; |
424 | int w = pixmap()->width(), h = pixmap()->height(); | 424 | int w = pixmap()->width(), h = pixmap()->height(); |
425 | QPixmap dblBuf( w, h + 4 ); | 425 | QPixmap dblBuf( w, h + 4 ); |
426 | QPainter p2( &dblBuf ); | 426 | QPainter p2( &dblBuf ); |
427 | int x1, y1; | 427 | int x1, y1; |
428 | if ( liv->itemTextPos() == QIconView::Bottom ) { | 428 | if ( liv->itemTextPos() == QIconView::Bottom ) { |
429 | x1 = x() + (width() - w) / 2 - liv->contentsX(); | 429 | x1 = x() + (width() - w) / 2 - liv->contentsX(); |
430 | y1 = y() - liv->contentsY(); | 430 | y1 = y() - liv->contentsY(); |
431 | } else { | 431 | } else { |
432 | x1 = x() - liv->contentsX(); | 432 | x1 = x() - liv->contentsX(); |
433 | y1 = y() + (height() - h) / 2 - liv->contentsY(); | 433 | y1 = y() + (height() - h) / 2 - liv->contentsY(); |
434 | } | 434 | } |
435 | y1 -= 2; | 435 | y1 -= 2; |
436 | p2.translate(-x1,-y1); | 436 | p2.translate(-x1,-y1); |
437 | liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); | 437 | liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); |
438 | int bounceY = 2; | 438 | int bounceY = 2; |
439 | #ifdef BOUNCE_BUSY_ICON | 439 | #ifdef BOUNCE_BUSY_ICON |
440 | if ( busyType == BIT_Animated ) { | 440 | if ( busyType == BIT_Animated ) { |
441 | bounceY = 4 - ((iteration+2)%8); | 441 | bounceY = 4 - ((iteration+2)%8); |
442 | bounceY = bounceY < 0 ? -bounceY : bounceY; | 442 | bounceY = bounceY < 0 ? -bounceY : bounceY; |
443 | } | 443 | } |
444 | #endif | 444 | #endif |
445 | p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); | 445 | p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); |
446 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 446 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
447 | p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); | 447 | p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); |
448 | #else | ||
449 | Q_UNUSED( pic ) | ||
448 | #endif | 450 | #endif |
449 | p->drawPixmap( x1, y1, dblBuf ); | 451 | p->drawPixmap( x1, y1, dblBuf ); |
450 | } | 452 | } |
451 | 453 | ||
452 | void LauncherItem::animateIcon() | 454 | void LauncherItem::animateIcon() |
453 | { | 455 | { |
454 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 456 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
455 | 457 | ||
456 | if ( liv->busyItem() != this || !app ) | 458 | if ( liv->busyItem() != this || !app ) |
457 | return; | 459 | return; |
458 | 460 | ||
459 | // Highlight the icon | 461 | // Highlight the icon |
460 | if ( iteration == 0 ) { | 462 | if ( iteration == 0 ) { |
461 | QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap(); | 463 | QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap(); |
462 | QImage img = src.convertToImage(); | 464 | QImage img = src.convertToImage(); |
463 | QRgb *rgb; | 465 | QRgb *rgb; |
464 | int count; | 466 | int count; |
465 | if ( img.depth() == 32 ) { | 467 | if ( img.depth() == 32 ) { |
466 | rgb = (QRgb*)img.bits(); | 468 | rgb = (QRgb*)img.bits(); |
467 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); | 469 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); |
468 | } else { | 470 | } else { |
469 | rgb = img.colorTable(); | 471 | rgb = img.colorTable(); |
470 | count = img.numColors(); | 472 | count = img.numColors(); |
471 | } | 473 | } |
472 | for ( int r = 0; r < count; r++, rgb++ ) { | 474 | for ( int r = 0; r < count; r++, rgb++ ) { |
473 | #if defined(BRIGHTEN_BUSY_ICON) | 475 | #if defined(BRIGHTEN_BUSY_ICON) |
474 | QColor c(*rgb); | 476 | QColor c(*rgb); |
475 | int h, s, v; | 477 | int h, s, v; |
476 | c.hsv(&h,&s,&v); | 478 | c.hsv(&h,&s,&v); |
477 | c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); | 479 | c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); |
478 | *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); | 480 | *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); |
479 | #elif defined(ALPHA_FADE_BUSY_ICON) | 481 | #elif defined(ALPHA_FADE_BUSY_ICON) |
480 | *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); | 482 | *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); |
481 | #endif | 483 | #endif |
482 | } | 484 | } |
483 | src.convertFromImage( img ); | 485 | src.convertFromImage( img ); |
484 | setPixmap( src ); | 486 | setPixmap( src ); |
485 | } | 487 | } |
486 | 488 | ||
487 | iteration++; | 489 | iteration++; |
488 | 490 | ||
489 | // Paint animation overlay | 491 | // Paint animation overlay |
490 | QPainter p( liv->viewport() ); | 492 | QPainter p( liv->viewport() ); |
491 | paintAnimatedIcon( &p ); | 493 | paintAnimatedIcon( &p ); |
492 | } | 494 | } |
493 | 495 | ||
494 | void LauncherItem::resetIcon() | 496 | void LauncherItem::resetIcon() |
495 | { | 497 | { |
496 | iteration = 0; | 498 | iteration = 0; |
497 | setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); | 499 | setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); |
498 | } | 500 | } |
499 | 501 | ||
500 | //=========================================================================== | 502 | //=========================================================================== |
501 | 503 | ||
502 | QStringList LauncherIconView::mimeTypes() const | 504 | QStringList LauncherIconView::mimeTypes() const |
503 | { | 505 | { |
504 | QStringList r; | 506 | QStringList r; |
505 | QDictIterator<void> it(mimes); | 507 | QDictIterator<void> it(mimes); |
506 | while (it.current()) { | 508 | while (it.current()) { |
507 | r.append(it.currentKey()); | 509 | r.append(it.currentKey()); |
508 | ++it; | 510 | ++it; |
509 | } | 511 | } |
510 | r.sort(); | 512 | r.sort(); |
511 | return r; | 513 | return r; |
512 | } | 514 | } |
513 | 515 | ||
514 | void LauncherIconView::addItem(AppLnk* app, bool resort) | 516 | void LauncherIconView::addItem(AppLnk* app, bool resort) |
515 | { | 517 | { |
516 | addCatsAndMimes(app); | 518 | addCatsAndMimes(app); |
517 | 519 | ||
518 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) | 520 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) |
519 | && (cf == 0 || app->categories().contains(cf) | 521 | && (cf == 0 || app->categories().contains(cf) |
520 | || cf == -1 && app->categories().count() == 0 ) ) | 522 | || cf == -1 && app->categories().count() == 0 ) ) |
521 | (void) new LauncherItem( this, app, bigIcns ); | 523 | (void) new LauncherItem( this, app, bigIcns ); |
522 | else | 524 | else |
523 | hidden.append(app); | 525 | hidden.append(app); |
524 | if ( resort ) | 526 | if ( resort ) |
525 | sort(); | 527 | sort(); |
526 | } | 528 | } |
527 | 529 | ||
528 | void LauncherIconView::updateCategoriesAndMimeTypes() | 530 | void LauncherIconView::updateCategoriesAndMimeTypes() |
529 | { | 531 | { |
530 | mimes.clear(); | 532 | mimes.clear(); |
531 | cats.clear(); | 533 | cats.clear(); |
532 | LauncherItem* item = (LauncherItem*)firstItem(); | 534 | LauncherItem* item = (LauncherItem*)firstItem(); |
533 | while (item) { | 535 | while (item) { |
534 | addCatsAndMimes(item->appLnk()); | 536 | addCatsAndMimes(item->appLnk()); |
535 | item = (LauncherItem*)item->nextItem(); | 537 | item = (LauncherItem*)item->nextItem(); |
536 | } | 538 | } |
537 | QListIterator<AppLnk> it(hidden); | 539 | QListIterator<AppLnk> it(hidden); |
538 | AppLnk* l; | 540 | AppLnk* l; |
539 | while ((l=it.current())) { | 541 | while ((l=it.current())) { |
540 | addCatsAndMimes(l); | 542 | addCatsAndMimes(l); |
541 | ++it; | 543 | ++it; |
542 | } | 544 | } |
543 | } | 545 | } |
544 | 546 | ||
545 | void LauncherIconView::hideOrShowItems(bool resort) | 547 | void LauncherIconView::hideOrShowItems(bool resort) |
546 | { | 548 | { |
547 | viewport()->setUpdatesEnabled( FALSE ); | 549 | viewport()->setUpdatesEnabled( FALSE ); |
548 | hidden.setAutoDelete(FALSE); | 550 | hidden.setAutoDelete(FALSE); |
549 | QList<AppLnk> links=hidden; | 551 | QList<AppLnk> links=hidden; |
550 | hidden.clear(); | 552 | hidden.clear(); |
551 | hidden.setAutoDelete(TRUE); | 553 | hidden.setAutoDelete(TRUE); |
552 | LauncherItem* item = (LauncherItem*)firstItem(); | 554 | LauncherItem* item = (LauncherItem*)firstItem(); |
553 | while (item) { | 555 | while (item) { |
554 | links.append(item->takeAppLnk()); | 556 | links.append(item->takeAppLnk()); |
555 | item = (LauncherItem*)item->nextItem(); | 557 | item = (LauncherItem*)item->nextItem(); |
556 | } | 558 | } |
557 | clear(); | 559 | clear(); |
558 | QListIterator<AppLnk> it(links); | 560 | QListIterator<AppLnk> it(links); |
559 | AppLnk* l; | 561 | AppLnk* l; |
560 | while ((l=it.current())) { | 562 | while ((l=it.current())) { |
561 | addItem(l,FALSE); | 563 | addItem(l,FALSE); |
562 | ++it; | 564 | ++it; |
563 | } | 565 | } |
564 | if ( resort && !autoArrange() ) | 566 | if ( resort && !autoArrange() ) |
565 | sort(); | 567 | sort(); |
566 | viewport()->setUpdatesEnabled( TRUE ); | 568 | viewport()->setUpdatesEnabled( TRUE ); |
567 | } | 569 | } |
568 | 570 | ||
569 | bool LauncherIconView::removeLink(const QString& linkfile) | 571 | bool LauncherIconView::removeLink(const QString& linkfile) |
570 | { | 572 | { |
571 | LauncherItem* item = (LauncherItem*)firstItem(); | 573 | LauncherItem* item = (LauncherItem*)firstItem(); |
572 | AppLnk* l; | 574 | AppLnk* l; |
573 | bool did = FALSE; | 575 | bool did = FALSE; |
574 | DocLnk dl(linkfile); | 576 | DocLnk dl(linkfile); |
575 | while (item) { | 577 | while (item) { |
576 | l = item->appLnk(); | 578 | l = item->appLnk(); |
577 | LauncherItem *nextItem = (LauncherItem *)item->nextItem(); | 579 | LauncherItem *nextItem = (LauncherItem *)item->nextItem(); |
578 | if ( l->linkFileKnown() && l->linkFile() == linkfile | 580 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
579 | || l->fileKnown() && ( | 581 | || l->fileKnown() && ( |
580 | l->file() == linkfile | 582 | l->file() == linkfile |
581 | || dl.isValid() && dl.file() == l->file() ) ) { | 583 | || dl.isValid() && dl.file() == l->file() ) ) { |
582 | delete item; | 584 | delete item; |
583 | did = TRUE; | 585 | did = TRUE; |
584 | } | 586 | } |
585 | item = nextItem; | 587 | item = nextItem; |
586 | } | 588 | } |
587 | QListIterator<AppLnk> it(hidden); | 589 | QListIterator<AppLnk> it(hidden); |
588 | while ((l=it.current())) { | 590 | while ((l=it.current())) { |
589 | ++it; | 591 | ++it; |
590 | if ( l->linkFileKnown() && l->linkFile() == linkfile | 592 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
591 | || l->file() == linkfile | 593 | || l->file() == linkfile |
592 | || dl.isValid() && dl.file() == l->file() ) { | 594 | || dl.isValid() && dl.file() == l->file() ) { |
593 | hidden.removeRef(l); | 595 | hidden.removeRef(l); |
594 | did = TRUE; | 596 | did = TRUE; |
595 | } | 597 | } |
596 | } | 598 | } |
597 | return did; | 599 | return did; |
598 | } | 600 | } |
599 | 601 | ||
600 | //=========================================================================== | 602 | //=========================================================================== |
601 | 603 | ||
602 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) | 604 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) |
603 | : QVBox( parent, name, fl ) | 605 | : QVBox( parent, name, fl ) |
604 | { | 606 | { |
605 | catmb = 0; | 607 | catmb = 0; |
606 | icons = new LauncherIconView( this ); | 608 | icons = new LauncherIconView( this ); |
607 | setFocusProxy(icons); | 609 | setFocusProxy(icons); |
608 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); | 610 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); |
609 | 611 | ||
610 | icons->setItemsMovable( FALSE ); | 612 | icons->setItemsMovable( FALSE ); |
611 | icons->setAutoArrange( TRUE ); | 613 | icons->setAutoArrange( TRUE ); |
612 | icons->setSorting( TRUE ); | 614 | icons->setSorting( TRUE ); |
613 | icons->setFrameStyle( QFrame::NoFrame ); | 615 | icons->setFrameStyle( QFrame::NoFrame ); |
614 | icons->setMargin( 0 ); | 616 | icons->setMargin( 0 ); |
615 | icons->setSelectionMode( QIconView::NoSelection ); | 617 | icons->setSelectionMode( QIconView::NoSelection ); |
616 | icons->setBackgroundMode( PaletteBase ); | 618 | icons->setBackgroundMode( PaletteBase ); |
617 | icons->setResizeMode( QIconView::Fixed ); | 619 | icons->setResizeMode( QIconView::Fixed ); |
618 | vmode = (ViewMode)-1; | 620 | vmode = (ViewMode)-1; |
619 | setViewMode( Icon ); | 621 | setViewMode( Icon ); |
620 | 622 | ||
621 | connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)), | 623 | connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)), |
622 | SLOT(itemClicked(int,QIconViewItem*)) ); | 624 | SLOT(itemClicked(int,QIconViewItem*)) ); |
623 | connect( icons, SIGNAL(selectionChanged()), | 625 | connect( icons, SIGNAL(selectionChanged()), |
624 | SLOT(selectionChanged()) ); | 626 | SLOT(selectionChanged()) ); |
625 | connect( icons, SIGNAL(returnPressed(QIconViewItem*)), | 627 | connect( icons, SIGNAL(returnPressed(QIconViewItem*)), |
626 | SLOT(returnPressed(QIconViewItem*)) ); | 628 | SLOT(returnPressed(QIconViewItem*)) ); |
627 | connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)), | 629 | connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)), |
628 | SLOT(itemPressed(int,QIconViewItem*)) ); | 630 | SLOT(itemPressed(int,QIconViewItem*)) ); |
629 | 631 | ||
630 | tools = 0; | 632 | tools = 0; |
631 | setBackgroundType( Ruled, QString::null ); | 633 | setBackgroundType( Ruled, QString::null ); |
632 | } | 634 | } |
633 | 635 | ||
634 | LauncherView::~LauncherView() | 636 | LauncherView::~LauncherView() |
635 | { | 637 | { |
636 | if ( bgCache && bgCache->contains( bgName ) ) | 638 | if ( bgCache && bgCache->contains( bgName ) ) |
637 | (*bgCache)[bgName]->ref--; | 639 | (*bgCache)[bgName]->ref--; |
638 | } | 640 | } |
639 | 641 | ||
640 | void LauncherView::hideIcons() | 642 | void LauncherView::hideIcons() |
641 | { | 643 | { |
642 | icons->hide(); | 644 | icons->hide(); |
643 | } | 645 | } |
644 | 646 | ||
645 | void LauncherView::setToolsEnabled(bool y) | 647 | void LauncherView::setToolsEnabled(bool y) |
646 | { | 648 | { |
647 | if ( !y != !tools ) { | 649 | if ( !y != !tools ) { |
648 | if ( y ) { | 650 | if ( y ) { |
649 | tools = new QHBox(this); | 651 | tools = new QHBox(this); |
650 | 652 | ||
651 | // Type filter | 653 | // Type filter |
652 | typemb = new QComboBox(tools); | 654 | typemb = new QComboBox(tools); |
653 | QSizePolicy p = typemb->sizePolicy(); | 655 | QSizePolicy p = typemb->sizePolicy(); |
654 | p.setHorData(QSizePolicy::Expanding); | 656 | p.setHorData(QSizePolicy::Expanding); |
655 | typemb->setSizePolicy(p); | 657 | typemb->setSizePolicy(p); |
656 | 658 | ||
657 | // Category filter | 659 | // Category filter |
658 | updateTools(); | 660 | updateTools(); |
659 | tools->show(); | 661 | tools->show(); |
660 | 662 | ||
661 | } else { | 663 | } else { |
662 | delete tools; | 664 | delete tools; |
663 | tools = 0; | 665 | tools = 0; |
664 | } | 666 | } |
665 | } | 667 | } |
666 | } | 668 | } |
667 | 669 | ||
668 | void LauncherView::updateTools() | 670 | void LauncherView::updateTools() |
669 | { | 671 | { |
670 | disconnect( typemb, SIGNAL(activated(int)), | 672 | disconnect( typemb, SIGNAL(activated(int)), |
671 | this, SLOT(showType(int)) ); | 673 | this, SLOT(showType(int)) ); |
672 | if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), | 674 | if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), |
673 | this, SLOT(showCategory(int)) ); | 675 | this, SLOT(showCategory(int)) ); |
674 | 676 | ||
675 | // ### I want to remove this | 677 | // ### I want to remove this |
676 | icons->updateCategoriesAndMimeTypes(); | 678 | icons->updateCategoriesAndMimeTypes(); |
677 | 679 | ||
678 | QString prev; | 680 | QString prev; |
679 | 681 | ||
680 | // Type filter | 682 | // Type filter |
681 | QStringList types; | 683 | QStringList types; |
682 | typelist = icons->mimeTypes(); | 684 | typelist = icons->mimeTypes(); |
683 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { | 685 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { |
684 | QString t = *it; | 686 | QString t = *it; |
685 | if ( t.left(12) == "application/" ) { | 687 | if ( t.left(12) == "application/" ) { |
686 | MimeType mt(t); | 688 | MimeType mt(t); |
687 | const AppLnk* app = mt.application(); | 689 | const AppLnk* app = mt.application(); |
688 | if ( app ) | 690 | if ( app ) |
689 | t = app->name(); | 691 | t = app->name(); |
690 | else | 692 | else |
691 | t = t.mid(12); | 693 | t = t.mid(12); |
692 | } else { | 694 | } else { |
693 | t[0] = t[0].upper(); | 695 | t[0] = t[0].upper(); |
694 | } | 696 | } |
695 | types += t; | 697 | types += t; |
696 | } | 698 | } |
697 | types << tr("All types"); | 699 | types << tr("All types"); |
698 | prev = typemb->currentText(); | 700 | prev = typemb->currentText(); |
699 | typemb->clear(); | 701 | typemb->clear(); |
700 | typemb->insertStringList(types); | 702 | typemb->insertStringList(types); |
701 | for (int i=0; i<typemb->count(); i++) { | 703 | for (int i=0; i<typemb->count(); i++) { |
702 | if ( typemb->text(i) == prev ) { | 704 | if ( typemb->text(i) == prev ) { |
703 | typemb->setCurrentItem(i); | 705 | typemb->setCurrentItem(i); |
704 | break; | 706 | break; |
705 | } | 707 | } |
706 | } | 708 | } |
707 | if ( prev.isNull() ) | 709 | if ( prev.isNull() ) |
708 | typemb->setCurrentItem(typemb->count()-1); | 710 | typemb->setCurrentItem(typemb->count()-1); |
709 | 711 | ||
710 | int pcat = catmb ? catmb->currentCategory() : -2; | 712 | int pcat = catmb ? catmb->currentCategory() : -2; |
711 | if ( !catmb ) | 713 | if ( !catmb ) |
712 | catmb = new CategorySelect(tools); | 714 | catmb = new CategorySelect(tools); |
713 | Categories cats( 0 ); | 715 | Categories cats( 0 ); |
714 | cats.load( categoryFileName() ); | 716 | cats.load( categoryFileName() ); |
715 | QArray<int> vl( 0 ); | 717 | QArray<int> vl( 0 ); |
716 | catmb->setCategories( vl, "Document View", // No tr | 718 | catmb->setCategories( vl, "Document View", // No tr |
717 | tr("Document View") ); | 719 | tr("Document View") ); |
718 | catmb->setRemoveCategoryEdit( TRUE ); | 720 | catmb->setRemoveCategoryEdit( TRUE ); |
719 | catmb->setAllCategories( TRUE ); | 721 | catmb->setAllCategories( TRUE ); |
720 | catmb->setCurrentCategory(pcat); | 722 | catmb->setCurrentCategory(pcat); |
721 | 723 | ||
722 | // if type has changed we need to redisplay | 724 | // if type has changed we need to redisplay |
723 | if ( typemb->currentText() != prev ) | 725 | if ( typemb->currentText() != prev ) |
724 | showType( typemb->currentItem() ); | 726 | showType( typemb->currentItem() ); |
725 | 727 | ||
726 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); | 728 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); |
727 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); | 729 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); |
728 | } | 730 | } |
729 | 731 | ||
730 | void LauncherView::sortBy(int s) | 732 | void LauncherView::sortBy(int s) |
731 | { | 733 | { |
732 | icons->setSortMethod((LauncherIconView::SortMethod)s); | 734 | icons->setSortMethod((LauncherIconView::SortMethod)s); |
733 | } | 735 | } |
734 | 736 | ||
735 | void LauncherView::showType(int t) | 737 | void LauncherView::showType(int t) |
736 | { | 738 | { |
737 | if ( t >= (int)typelist.count() ) { | 739 | if ( t >= (int)typelist.count() ) { |
738 | icons->setTypeFilter("",TRUE); | 740 | icons->setTypeFilter("",TRUE); |
739 | } else { | 741 | } else { |
740 | QString ty = typelist[t]; | 742 | QString ty = typelist[t]; |
741 | if ( !ty.contains('/') ) | 743 | if ( !ty.contains('/') ) |
742 | ty += "/*"; | 744 | ty += "/*"; |
743 | icons->setTypeFilter(ty,TRUE); | 745 | icons->setTypeFilter(ty,TRUE); |
744 | } | 746 | } |
745 | } | 747 | } |
746 | 748 | ||
747 | void LauncherView::showCategory( int c ) | 749 | void LauncherView::showCategory( int c ) |
748 | { | 750 | { |
749 | icons->setCategoryFilter( c, TRUE ); | 751 | icons->setCategoryFilter( c, TRUE ); |
750 | } | 752 | } |
751 | 753 | ||
752 | void LauncherView::setViewMode( ViewMode m ) | 754 | void LauncherView::setViewMode( ViewMode m ) |
753 | { | 755 | { |
754 | if ( vmode != m ) { | 756 | if ( vmode != m ) { |
755 | bool bigIcons = m == Icon; | 757 | bool bigIcons = m == Icon; |
756 | icons->viewport()->setUpdatesEnabled( FALSE ); | 758 | icons->viewport()->setUpdatesEnabled( FALSE ); |
757 | icons->setBigIcons( bigIcons ); | 759 | icons->setBigIcons( bigIcons ); |
758 | switch ( m ) { | 760 | switch ( m ) { |
759 | case List: | 761 | case List: |
760 | icons->setItemTextPos( QIconView::Right ); | 762 | icons->setItemTextPos( QIconView::Right ); |
761 | break; | 763 | break; |
762 | case Icon: | 764 | case Icon: |
763 | icons->setItemTextPos( QIconView::Bottom ); | 765 | icons->setItemTextPos( QIconView::Bottom ); |
764 | break; | 766 | break; |
765 | } | 767 | } |
766 | icons->hideOrShowItems( FALSE ); | 768 | icons->hideOrShowItems( FALSE ); |
767 | icons->viewport()->setUpdatesEnabled( TRUE ); | 769 | icons->viewport()->setUpdatesEnabled( TRUE ); |
768 | vmode = m; | 770 | vmode = m; |
769 | } | 771 | } |
770 | } | 772 | } |
771 | 773 | ||
772 | // | 774 | // |
773 | // User images may require scaling. | 775 | // User images may require scaling. |
774 | // | 776 | // |
775 | QImage LauncherView::loadBackgroundImage(QString &bgName) | 777 | QImage LauncherView::loadBackgroundImage(QString &bgName) |
776 | { | 778 | { |
777 | QImageIO imgio; | 779 | QImageIO imgio; |
778 | QSize ds = qApp->desktop()->size(); // should be launcher, not desktop | 780 | QSize ds = qApp->desktop()->size(); // should be launcher, not desktop |
779 | bool further_scaling = TRUE; | 781 | bool further_scaling = TRUE; |
780 | 782 | ||
781 | imgio.setFileName( bgName ); | 783 | imgio.setFileName( bgName ); |
782 | imgio.setParameters("GetHeaderInformation"); | 784 | imgio.setParameters("GetHeaderInformation"); |
783 | 785 | ||
784 | if (imgio.read() == FALSE) { | 786 | if (imgio.read() == FALSE) { |
785 | return imgio.image(); | 787 | return imgio.image(); |
786 | } | 788 | } |
787 | 789 | ||
788 | if (imgio.image().width() < ds.width() && | 790 | if (imgio.image().width() < ds.width() && |
789 | imgio.image().height() < ds.height()) { | 791 | imgio.image().height() < ds.height()) { |
790 | further_scaling = FALSE; | 792 | further_scaling = FALSE; |
791 | } | 793 | } |
792 | 794 | ||
793 | if (!imgio.image().bits()) { | 795 | if (!imgio.image().bits()) { |
794 | // | 796 | // |
795 | // Scale and load. Note we don't scale up. | 797 | // Scale and load. Note we don't scale up. |
796 | // | 798 | // |
797 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr | 799 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr |
798 | imgio.setParameters(further_scaling ? | 800 | imgio.setParameters(further_scaling ? |
799 | param.arg(ds.width()).arg(ds.height()).latin1() : | 801 | param.arg(ds.width()).arg(ds.height()).latin1() : |
800 | ""); | 802 | ""); |
801 | imgio.read(); | 803 | imgio.read(); |
802 | } else { | 804 | } else { |
803 | if (further_scaling) { | 805 | if (further_scaling) { |
804 | intt1 = imgio.image().width() * ds.height(); | 806 | intt1 = imgio.image().width() * ds.height(); |
805 | int t2 = imgio.image().height() * ds.width(); | 807 | int t2 = imgio.image().height() * ds.width(); |
806 | int dsth = ds.height(); | 808 | int dsth = ds.height(); |
807 | int dstw = ds.width(); | 809 | int dstw = ds.width(); |
808 | 810 | ||
809 | if (t1 > t2) { | 811 | if (t1 > t2) { |
810 | dsth = t2 / imgio.image().width(); | 812 | dsth = t2 / imgio.image().width(); |
811 | } else { | 813 | } else { |
812 | dstw = t1 / imgio.image().height(); | 814 | dstw = t1 / imgio.image().height(); |
813 | } | 815 | } |
814 | 816 | ||
815 | // | 817 | // |
816 | // Loader didn't scale for us. Do it manually. | 818 | // Loader didn't scale for us. Do it manually. |
817 | // | 819 | // |
818 | return imgio.image().smoothScale(dstw, dsth); | 820 | return imgio.image().smoothScale(dstw, dsth); |
819 | } | 821 | } |
820 | } | 822 | } |
821 | 823 | ||
822 | return imgio.image(); | 824 | return imgio.image(); |
823 | } | 825 | } |
824 | 826 | ||
825 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) | 827 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) |
826 | { | 828 | { |
827 | if ( !bgCache ) { | 829 | if ( !bgCache ) { |
828 | bgCache = new QMap<QString,BgPixmap*>; | 830 | bgCache = new QMap<QString,BgPixmap*>; |
829 | qAddPostRoutine( cleanup_cache ); | 831 | qAddPostRoutine( cleanup_cache ); |
830 | } | 832 | } |
831 | 833 | ||
832 | if ( bgCache->contains( bgName ) ) | 834 | if ( bgCache->contains( bgName ) ) |
833 | (*bgCache)[bgName]->ref--; | 835 | (*bgCache)[bgName]->ref--; |
834 | bgName = ""; | 836 | bgName = ""; |
835 | 837 | ||
836 | QPixmap bg; | 838 | QPixmap bg; |
837 | 839 | ||
838 | switch ( t ) { | 840 | switch ( t ) { |
839 | case Ruled: { | 841 | case Ruled: { |
840 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr | 842 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr |
841 | if ( bgCache->contains( bgName ) ) { | 843 | if ( bgCache->contains( bgName ) ) { |
842 | (*bgCache)[bgName]->ref++; | 844 | (*bgCache)[bgName]->ref++; |
843 | bg = (*bgCache)[bgName]->pm; | 845 | bg = (*bgCache)[bgName]->pm; |
844 | } else { | 846 | } else { |
845 | bg.resize( width(), 9 ); | 847 | bg.resize( width(), 9 ); |
846 | QPainter painter( &bg ); | 848 | QPainter painter( &bg ); |
847 | for ( int i = 0; i < 3; i++ ) { | 849 | for ( int i = 0; i < 3; i++ ) { |
848 | painter.setPen( white ); | 850 | painter.setPen( white ); |
849 | painter.drawLine( 0, i*3, width()-1, i*3 ); | 851 | painter.drawLine( 0, i*3, width()-1, i*3 ); |
850 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); | 852 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); |
851 | painter.setPen( colorGroup().background().light(105) ); | 853 | painter.setPen( colorGroup().background().light(105) ); |
852 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); | 854 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); |
853 | } | 855 | } |
854 | painter.end(); | 856 | painter.end(); |
855 | bgCache->insert( bgName, new BgPixmap(bg) ); | 857 | bgCache->insert( bgName, new BgPixmap(bg) ); |
856 | } | 858 | } |
857 | break; | 859 | break; |
858 | } | 860 | } |
859 | 861 | ||
860 | case Image: | 862 | case Image: |
861 | if (!val.isEmpty()) { | 863 | if (!val.isEmpty()) { |
862 | bgName = val; | 864 | bgName = val; |
863 | if ( bgCache->contains( bgName ) ) { | 865 | if ( bgCache->contains( bgName ) ) { |
864 | (*bgCache)[bgName]->ref++; | 866 | (*bgCache)[bgName]->ref++; |
865 | bg = (*bgCache)[bgName]->pm; | 867 | bg = (*bgCache)[bgName]->pm; |
866 | } else { | 868 | } else { |
867 | QString imgFile = bgName; | 869 | QString imgFile = bgName; |
868 | bool tile = FALSE; | 870 | bool tile = FALSE; |
869 | if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { | 871 | if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { |
870 | imgFile = Resource::findPixmap( imgFile ); | 872 | imgFile = Resource::findPixmap( imgFile ); |
871 | tile = TRUE; | 873 | tile = TRUE; |
872 | } | 874 | } |
873 | QImage img = loadBackgroundImage(imgFile); | 875 | QImage img = loadBackgroundImage(imgFile); |
874 | 876 | ||
875 | 877 | ||
876 | if ( img.depth() == 1 ) | 878 | if ( img.depth() == 1 ) |
877 | img = img.convertDepth(8); | 879 | img = img.convertDepth(8); |
878 | img.setAlphaBuffer(FALSE); | 880 | img.setAlphaBuffer(FALSE); |
879 | bg.convertFromImage(img); | 881 | bg.convertFromImage(img); |
880 | bgCache->insert( bgName, new BgPixmap(bg) ); | 882 | bgCache->insert( bgName, new BgPixmap(bg) ); |
881 | } | 883 | } |
882 | } | 884 | } |
883 | break; | 885 | break; |
884 | 886 | ||
885 | case SolidColor: | 887 | case SolidColor: |
886 | default: | 888 | default: |
887 | break; | 889 | break; |
888 | } | 890 | } |
889 | 891 | ||
890 | const QObjectList *list = queryList( "QWidget", 0, FALSE ); | 892 | const QObjectList *list = queryList( "QWidget", 0, FALSE ); |
891 | QObject *obj; | 893 | QObject *obj; |
892 | for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { | 894 | for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { |
893 | if ( obj->isWidgetType() ) { | 895 | if ( obj->isWidgetType() ) { |
894 | QWidget *w = (QWidget*)obj; | 896 | QWidget *w = (QWidget*)obj; |
895 | w->setBackgroundPixmap( bg ); | 897 | w->setBackgroundPixmap( bg ); |
896 | if ( bgName.isEmpty() ) { | 898 | if ( bgName.isEmpty() ) { |
897 | // Solid Color | 899 | // Solid Color |
898 | if ( val.isEmpty() ) | 900 | if ( val.isEmpty() ) |
899 | w->setBackgroundColor( colorGroup().base() ); | 901 | w->setBackgroundColor( colorGroup().base() ); |
900 | else | 902 | else |
901 | w->setBackgroundColor( val ); | 903 | w->setBackgroundColor( val ); |
902 | } else { | 904 | } else { |
903 | // Ruled or Image pixmap | 905 | // Ruled or Image pixmap |
904 | w->setBackgroundOrigin( ParentOrigin ); | 906 | w->setBackgroundOrigin( ParentOrigin ); |
905 | } | 907 | } |
906 | } | 908 | } |
907 | } | 909 | } |
908 | delete list; | 910 | delete list; |
909 | 911 | ||
910 | bgType = t; | 912 | bgType = t; |
911 | icons->viewport()->update(); | 913 | icons->viewport()->update(); |
912 | 914 | ||
913 | QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); | 915 | QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); |
914 | } | 916 | } |
915 | 917 | ||
916 | void LauncherView::setTextColor( const QColor &tc ) | 918 | void LauncherView::setTextColor( const QColor &tc ) |
917 | { | 919 | { |
918 | textCol = tc; | 920 | textCol = tc; |
919 | QColorGroup cg = icons->colorGroup(); | 921 | QColorGroup cg = icons->colorGroup(); |
920 | cg.setColor( QColorGroup::Text, tc ); | 922 | cg.setColor( QColorGroup::Text, tc ); |
921 | icons->setPalette( QPalette(cg,cg,cg) ); | 923 | icons->setPalette( QPalette(cg,cg,cg) ); |
922 | icons->viewport()->update(); | 924 | icons->viewport()->update(); |
923 | } | 925 | } |
924 | 926 | ||
925 | void LauncherView::setViewFont( const QFont &f ) | 927 | void LauncherView::setViewFont( const QFont &f ) |
926 | { | 928 | { |
927 | icons->setFont( f ); | 929 | icons->setFont( f ); |
928 | icons->hideOrShowItems( FALSE ); | 930 | icons->hideOrShowItems( FALSE ); |
929 | } | 931 | } |
930 | 932 | ||
931 | void LauncherView::clearViewFont() | 933 | void LauncherView::clearViewFont() |
932 | { | 934 | { |
933 | icons->unsetFont(); | 935 | icons->unsetFont(); |
934 | icons->hideOrShowItems( FALSE ); | 936 | icons->hideOrShowItems( FALSE ); |
935 | } | 937 | } |
936 | 938 | ||
937 | void LauncherView::resizeEvent(QResizeEvent *e) | 939 | void LauncherView::resizeEvent(QResizeEvent *e) |
938 | { | 940 | { |
939 | //qDebug("LauncherView resize event"); | 941 | //qDebug("LauncherView resize event"); |
940 | QVBox::resizeEvent( e ); | 942 | QVBox::resizeEvent( e ); |
941 | // commented out for launcherview and qt/e 2.3.8 problems, probably needs real fixing somewhere... | 943 | // commented out for launcherview and qt/e 2.3.8 problems, probably needs real fixing somewhere... |
942 | // if ( e->size().width() != e->oldSize().width() ) | 944 | // if ( e->size().width() != e->oldSize().width() ) |
943 | sort(); | 945 | sort(); |
944 | } | 946 | } |
945 | 947 | ||
946 | void LauncherView::selectionChanged() | 948 | void LauncherView::selectionChanged() |
947 | { | 949 | { |
948 | QIconViewItem* item = icons->currentItem(); | 950 | QIconViewItem* item = icons->currentItem(); |
949 | if ( item && item->isSelected() ) { | 951 | if ( item && item->isSelected() ) { |
950 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 952 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
951 | if ( icons->inKeyEvent() ) // not for mouse press | 953 | if ( icons->inKeyEvent() ) // not for mouse press |
952 | emit clicked( appLnk ); | 954 | emit clicked( appLnk ); |
953 | item->setSelected(FALSE); | 955 | item->setSelected(FALSE); |
954 | } | 956 | } |
955 | } | 957 | } |
956 | 958 | ||
957 | void LauncherView::returnPressed( QIconViewItem *item ) | 959 | void LauncherView::returnPressed( QIconViewItem *item ) |
958 | { | 960 | { |
959 | if ( item ) { | 961 | if ( item ) { |
960 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 962 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
961 | emit clicked( appLnk ); | 963 | emit clicked( appLnk ); |
962 | } | 964 | } |
963 | } | 965 | } |
964 | 966 | ||
965 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) | 967 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) |
966 | { | 968 | { |
967 | if ( item ) { | 969 | if ( item ) { |
968 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 970 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
969 | if ( btn == LeftButton ) { | 971 | if ( btn == LeftButton ) { |
970 | // Make sure it's the item we execute that gets highlighted | 972 | // Make sure it's the item we execute that gets highlighted |
971 | icons->setCurrentItem( item ); | 973 | icons->setCurrentItem( item ); |
972 | emit clicked( appLnk ); | 974 | emit clicked( appLnk ); |
973 | } | 975 | } |
974 | item->setSelected(FALSE); | 976 | item->setSelected(FALSE); |
975 | } | 977 | } |
976 | } | 978 | } |
977 | 979 | ||
978 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) | 980 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) |
979 | { | 981 | { |
980 | if ( item ) { | 982 | if ( item ) { |
981 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 983 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
982 | if ( btn == RightButton ) | 984 | if ( btn == RightButton ) |
983 | emit rightPressed( appLnk ); | 985 | emit rightPressed( appLnk ); |
984 | else if ( btn == ShiftButton ) | 986 | else if ( btn == ShiftButton ) |
985 | emit rightPressed( appLnk ); | 987 | emit rightPressed( appLnk ); |
986 | item->setSelected(FALSE); | 988 | item->setSelected(FALSE); |
987 | } | 989 | } |
988 | } | 990 | } |
989 | 991 | ||
990 | void LauncherView::removeAllItems() | 992 | void LauncherView::removeAllItems() |
991 | { | 993 | { |
992 | icons->clear(); | 994 | icons->clear(); |
993 | } | 995 | } |
994 | 996 | ||
995 | bool LauncherView::removeLink(const QString& linkfile) | 997 | bool LauncherView::removeLink(const QString& linkfile) |
996 | { | 998 | { |
997 | return icons->removeLink(linkfile); | 999 | return icons->removeLink(linkfile); |
998 | } | 1000 | } |
999 | 1001 | ||
1000 | void LauncherView::setSortEnabled( bool v ) | 1002 | void LauncherView::setSortEnabled( bool v ) |
1001 | { | 1003 | { |
1002 | icons->setSorting( v ); | 1004 | icons->setSorting( v ); |
1003 | if ( v ) | 1005 | if ( v ) |
1004 | sort(); | 1006 | sort(); |
1005 | } | 1007 | } |
1006 | 1008 | ||
1007 | void LauncherView::setUpdatesEnabled( bool u ) | 1009 | void LauncherView::setUpdatesEnabled( bool u ) |
1008 | { | 1010 | { |
1009 | icons->setUpdatesEnabled( u ); | 1011 | icons->setUpdatesEnabled( u ); |
1010 | } | 1012 | } |
1011 | 1013 | ||
1012 | void LauncherView::sort() | 1014 | void LauncherView::sort() |
1013 | { | 1015 | { |
1014 | icons->sort(); | 1016 | icons->sort(); |
1015 | } | 1017 | } |
1016 | 1018 | ||
1017 | void LauncherView::addItem(AppLnk* app, bool resort) | 1019 | void LauncherView::addItem(AppLnk* app, bool resort) |
1018 | { | 1020 | { |
1019 | icons->addItem(app,resort); | 1021 | icons->addItem(app,resort); |
1020 | } | 1022 | } |
1021 | 1023 | ||
1022 | void LauncherView::paletteChange( const QPalette &p ) | 1024 | void LauncherView::paletteChange( const QPalette &p ) |
1023 | { | 1025 | { |
1024 | icons->unsetPalette(); | 1026 | icons->unsetPalette(); |
1025 | QVBox::paletteChange( p ); | 1027 | QVBox::paletteChange( p ); |
1026 | if ( bgType == Ruled ) | 1028 | if ( bgType == Ruled ) |
1027 | setBackgroundType( Ruled, QString::null ); | 1029 | setBackgroundType( Ruled, QString::null ); |
1028 | QColorGroup cg = icons->colorGroup(); | 1030 | QColorGroup cg = icons->colorGroup(); |
1029 | cg.setColor( QColorGroup::Text, textCol ); | 1031 | cg.setColor( QColorGroup::Text, textCol ); |
1030 | icons->setPalette( QPalette(cg,cg,cg) ); | 1032 | icons->setPalette( QPalette(cg,cg,cg) ); |
1031 | } | 1033 | } |
1032 | 1034 | ||
1033 | void LauncherView::fontChanged(const QFont&) | 1035 | void LauncherView::fontChanged(const QFont&) |
1034 | { | 1036 | { |
1035 | odebug << "LauncherView::fontChanged()" << oendl; | 1037 | odebug << "LauncherView::fontChanged()" << oendl; |
1036 | icons->hideOrShowItems( FALSE ); | 1038 | icons->hideOrShowItems( FALSE ); |
1037 | } | 1039 | } |
1038 | 1040 | ||
1039 | void LauncherView::relayout(void) | 1041 | void LauncherView::relayout(void) |
1040 | { | 1042 | { |
1041 | icons->hideOrShowItems(FALSE); | 1043 | icons->hideOrShowItems(FALSE); |
1042 | } | 1044 | } |
1043 | 1045 | ||
1044 | void LauncherView::flushBgCache() | 1046 | void LauncherView::flushBgCache() |
1045 | { | 1047 | { |
1046 | if ( !bgCache ) | 1048 | if ( !bgCache ) |
1047 | return; | 1049 | return; |
1048 | // remove unreferenced backgrounds. | 1050 | // remove unreferenced backgrounds. |
1049 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | 1051 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); |
1050 | while ( it != bgCache->end() ) { | 1052 | while ( it != bgCache->end() ) { |
1051 | QMap<QString,BgPixmap*>::Iterator curr = it; | 1053 | QMap<QString,BgPixmap*>::Iterator curr = it; |
1052 | ++it; | 1054 | ++it; |
1053 | if ( (*curr)->ref == 0 ) { | 1055 | if ( (*curr)->ref == 0 ) { |
1054 | delete (*curr); | 1056 | delete (*curr); |
1055 | bgCache->remove( curr ); | 1057 | bgCache->remove( curr ); |
1056 | } | 1058 | } |
1057 | } | 1059 | } |
1058 | } | 1060 | } |
1059 | 1061 | ||
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp index 950032d..5ae517b 100644 --- a/core/launcher/server.cpp +++ b/core/launcher/server.cpp | |||
@@ -1,729 +1,707 @@ | |||
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 | 20 | ||
21 | #include "server.h" | 21 | #include "server.h" |
22 | #include "serverapp.h" | 22 | #include "serverapp.h" |
23 | #include "startmenu.h" | 23 | #include "startmenu.h" |
24 | #include "launcher.h" | 24 | #include "launcher.h" |
25 | #include "transferserver.h" | 25 | #include "transferserver.h" |
26 | #include "qcopbridge.h" | 26 | #include "qcopbridge.h" |
27 | #include "irserver.h" | 27 | #include "irserver.h" |
28 | #include "packageslave.h" | 28 | #include "packageslave.h" |
29 | #include "calibrate.h" | 29 | #include "calibrate.h" |
30 | #include "qrsync.h" | 30 | #include "qrsync.h" |
31 | #include "syncdialog.h" | 31 | #include "syncdialog.h" |
32 | #include "shutdownimpl.h" | 32 | #include "shutdownimpl.h" |
33 | #include "applauncher.h" | 33 | #include "applauncher.h" |
34 | #if 0 | 34 | #if 0 |
35 | #include "suspendmonitor.h" | 35 | #include "suspendmonitor.h" |
36 | #endif | 36 | #endif |
37 | #include "documentlist.h" | 37 | #include "documentlist.h" |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | #include <opie2/odebug.h> | 40 | #include <opie2/odebug.h> |
41 | #include <opie2/odevicebutton.h> | 41 | #include <opie2/odevicebutton.h> |
42 | #include <opie2/odevice.h> | 42 | #include <opie2/odevice.h> |
43 | #include <qtopia/applnk.h> | 43 | #include <qtopia/applnk.h> |
44 | #include <qtopia/private/categories.h> | 44 | #include <qtopia/private/categories.h> |
45 | #include <qtopia/mimetype.h> | 45 | #include <qtopia/mimetype.h> |
46 | #include <qtopia/config.h> | 46 | #include <qtopia/config.h> |
47 | #include <qtopia/resource.h> | 47 | #include <qtopia/resource.h> |
48 | #include <qtopia/version.h> | 48 | #include <qtopia/version.h> |
49 | #include <qtopia/storage.h> | 49 | #include <qtopia/storage.h> |
50 | #include <qtopia/qcopenvelope_qws.h> | 50 | #include <qtopia/qcopenvelope_qws.h> |
51 | #include <qtopia/global.h> | 51 | #include <qtopia/global.h> |
52 | using namespace Opie::Core; | 52 | using namespace Opie::Core; |
53 | 53 | ||
54 | /* QT */ | 54 | /* QT */ |
55 | #include <qmainwindow.h> | 55 | #include <qmainwindow.h> |
56 | #include <qmessagebox.h> | 56 | #include <qmessagebox.h> |
57 | #include <qtimer.h> | 57 | #include <qtimer.h> |
58 | #include <qtextstream.h> | 58 | #include <qtextstream.h> |
59 | #include <qwindowsystem_qws.h> | 59 | #include <qwindowsystem_qws.h> |
60 | #include <qgfx_qws.h> | 60 | #include <qgfx_qws.h> |
61 | 61 | ||
62 | /* STD */ | 62 | /* STD */ |
63 | #include <unistd.h> | 63 | #include <unistd.h> |
64 | #include <stdlib.h> | 64 | #include <stdlib.h> |
65 | 65 | ||
66 | extern QRect qt_maxWindowRect; | 66 | extern QRect qt_maxWindowRect; |
67 | 67 | ||
68 | static QWidget *calibrate(bool) | 68 | static QWidget *calibrate(bool) |
69 | { | 69 | { |
70 | #ifdef Q_WS_QWS | 70 | #ifdef Q_WS_QWS |
71 | Calibrate *c = new Calibrate; | 71 | Calibrate *c = new Calibrate; |
72 | c->show(); | 72 | c->show(); |
73 | return c; | 73 | return c; |
74 | #else | 74 | #else |
75 | return 0; | 75 | return 0; |
76 | #endif | 76 | #endif |
77 | } | 77 | } |
78 | 78 | ||
79 | #define FACTORY(T) \ | 79 | #define FACTORY(T) \ |
80 | static QWidget *new##T( bool maximized ) { \ | 80 | static QWidget *new##T( bool maximized ) { \ |
81 | QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ | 81 | QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ |
82 | if ( maximized ) { \ | 82 | if ( maximized ) { \ |
83 | if ( qApp->desktop()->width() <= 350 ) { \ | 83 | if ( qApp->desktop()->width() <= 350 ) { \ |
84 | w->showMaximized(); \ | 84 | w->showMaximized(); \ |
85 | } else { \ | 85 | } else { \ |
86 | w->resize( QSize( 300, 300 ) ); \ | 86 | w->resize( QSize( 300, 300 ) ); \ |
87 | } \ | 87 | } \ |
88 | } \ | 88 | } \ |
89 | w->show(); \ | 89 | w->show(); \ |
90 | return w; \ | 90 | return w; \ |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | #ifdef SINGLE_APP | 94 | #ifdef SINGLE_APP |
95 | #define APP(a,b,c,d) FACTORY(b) | 95 | #define APP(a,b,c,d) FACTORY(b) |
96 | #include "apps.h" | 96 | #include "apps.h" |
97 | #undef APP | 97 | #undef APP |
98 | #endif // SINGLE_APP | 98 | #endif // SINGLE_APP |
99 | 99 | ||
100 | static Global::Command builtins[] = { | 100 | static Global::Command builtins[] = { |
101 | 101 | ||
102 | #ifdef SINGLE_APP | 102 | #ifdef SINGLE_APP |
103 | #define APP(a,b,c,d) { a, new##b, c, d }, | 103 | #define APP(a,b,c,d) { a, new##b, c, d }, |
104 | #include "apps.h" | 104 | #include "apps.h" |
105 | #undef APP | 105 | #undef APP |
106 | #endif | 106 | #endif |
107 | 107 | ||
108 | /* FIXME defines need to be defined*/ | 108 | /* FIXME defines need to be defined*/ |
109 | #if !defined(OPIE_NO_BUILTIN_CALIBRATE) | 109 | #if !defined(OPIE_NO_BUILTIN_CALIBRATE) |
110 | { "calibrate", calibrate, 1, 0 }, // No tr | 110 | { "calibrate", calibrate, 1, 0 }, // No tr |
111 | #endif | 111 | #endif |
112 | #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) | 112 | #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) |
113 | { "shutdown", Global::shutdown, 1, 0 }, // No tr | 113 | { "shutdown", Global::shutdown, 1, 0 }, // No tr |
114 | // { "run", run, 1, 0 }, // No tr | 114 | // { "run", run, 1, 0 }, // No tr |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | { 0, calibrate, 0, 0 }, | 117 | { 0, calibrate, 0, 0 }, |
118 | }; | 118 | }; |
119 | 119 | ||
120 | 120 | ||
121 | //--------------------------------------------------------------------------- | 121 | //--------------------------------------------------------------------------- |
122 | 122 | ||
123 | 123 | ||
124 | //=========================================================================== | 124 | //=========================================================================== |
125 | 125 | ||
126 | Server::Server() : | 126 | Server::Server() : |
127 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | 127 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), |
128 | qcopBridge( 0 ), | 128 | qcopBridge( 0 ), |
129 | transferServer( 0 ), | 129 | transferServer( 0 ), |
130 | packageHandler( 0 ), | 130 | packageHandler( 0 ), |
131 | syncDialog( 0 ) | 131 | syncDialog( 0 ) |
132 | { | 132 | { |
133 | Global::setBuiltinCommands(builtins); | 133 | Global::setBuiltinCommands(builtins); |
134 | 134 | ||
135 | tid_xfer = 0; | 135 | tid_xfer = 0; |
136 | /* ### FIXME ### */ | 136 | /* ### FIXME ### */ |
137 | /* tid_today = startTimer(3600*2*1000);*/ | 137 | /* tid_today = startTimer(3600*2*1000);*/ |
138 | last_today_show = QDate::currentDate(); | 138 | last_today_show = QDate::currentDate(); |
139 | 139 | ||
140 | #if 0 | 140 | #if 0 |
141 | tsmMonitor = new TempScreenSaverMode(); | 141 | tsmMonitor = new TempScreenSaverMode(); |
142 | connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); | 142 | connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | serverGui = new Launcher; | 145 | serverGui = new Launcher; |
146 | serverGui->createGUI(); | 146 | serverGui->createGUI(); |
147 | 147 | ||
148 | docList = new DocumentList( serverGui ); | 148 | docList = new DocumentList( serverGui ); |
149 | appLauncher = new AppLauncher(this); | 149 | appLauncher = new AppLauncher(this); |
150 | connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) ); | 150 | connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) ); |
151 | connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) ); | 151 | connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) ); |
152 | connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) ); | 152 | connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) ); |
153 | 153 | ||
154 | storage = new StorageInfo( this ); | 154 | storage = new StorageInfo( this ); |
155 | connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); | 155 | connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); |
156 | 156 | ||
157 | // start services | 157 | // start services |
158 | startTransferServer(); | 158 | startTransferServer(); |
159 | (void) new IrServer( this ); | 159 | (void) new IrServer( this ); |
160 | 160 | ||
161 | packageHandler = new PackageHandler( this ); | 161 | packageHandler = new PackageHandler( this ); |
162 | connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), | 162 | connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), |
163 | this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); | 163 | this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); |
164 | 164 | ||
165 | setGeometry( -10, -10, 9, 9 ); | 165 | setGeometry( -10, -10, 9, 9 ); |
166 | 166 | ||
167 | QCopChannel *channel = new QCopChannel("QPE/System", this); | 167 | QCopChannel *channel = new QCopChannel("QPE/System", this); |
168 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | 168 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), |
169 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); | 169 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); |
170 | 170 | ||
171 | QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); | 171 | QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); |
172 | connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 172 | connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
173 | this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); | 173 | this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); |
174 | 174 | ||
175 | connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); | 175 | connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); |
176 | connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); | 176 | connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); |
177 | 177 | ||
178 | preloadApps(); | 178 | preloadApps(); |
179 | } | 179 | } |
180 | 180 | ||
181 | void Server::show() | 181 | void Server::show() |
182 | { | 182 | { |
183 | ServerApplication::login(TRUE); | 183 | ServerApplication::login(TRUE); |
184 | QWidget::show(); | 184 | QWidget::show(); |
185 | } | 185 | } |
186 | 186 | ||
187 | Server::~Server() | 187 | Server::~Server() |
188 | { | 188 | { |
189 | serverGui->destroyGUI(); | 189 | serverGui->destroyGUI(); |
190 | delete docList; | 190 | delete docList; |
191 | delete qcopBridge; | 191 | delete qcopBridge; |
192 | delete transferServer; | 192 | delete transferServer; |
193 | delete serverGui; | 193 | delete serverGui; |
194 | #if 0 | 194 | #if 0 |
195 | delete tsmMonitor; | 195 | delete tsmMonitor; |
196 | #endif | 196 | #endif |
197 | } | 197 | } |
198 | 198 | ||
199 | static bool hasVisibleWindow(const QString& clientname, bool partial) | ||
200 | { | ||
201 | #ifdef QWS | ||
202 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | ||
203 | QWSWindow* w; | ||
204 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { | ||
205 | if ( w->client()->identity() == clientname ) { | ||
206 | if ( partial && !w->isFullyObscured() ) | ||
207 | return TRUE; | ||
208 | if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { | ||
209 | # if QT_VERSION < 0x030000 | ||
210 | QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, | ||
211 | QSize(qt_screen->width(),qt_screen->height()) ); | ||
212 | # else | ||
213 | QRect mwr = qt_maxWindowRect; | ||
214 | # endif | ||
215 | if ( mwr.contains(w->requested().boundingRect()) ) | ||
216 | return TRUE; | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | #endif | ||
221 | return FALSE; | ||
222 | } | ||
223 | 199 | ||
224 | void Server::activate(const ODeviceButton* button, bool held) | 200 | void Server::activate(const ODeviceButton* button, bool held) |
225 | { | 201 | { |
226 | Global::terminateBuiltin("calibrate"); // No tr | 202 | Global::terminateBuiltin("calibrate"); // No tr |
227 | OQCopMessage om; | 203 | OQCopMessage om; |
228 | if ( held ) { | 204 | if ( held ) { |
229 | om = button->heldAction(); | 205 | om = button->heldAction(); |
230 | } else { | 206 | } else { |
231 | om = button->pressedAction(); | 207 | om = button->pressedAction(); |
232 | } | 208 | } |
233 | 209 | ||
234 | if ( om.channel() != "ignore" ) | 210 | if ( om.channel() != "ignore" ) |
235 | om.send(); | 211 | om.send(); |
236 | 212 | ||
237 | // A button with no action defined, will return a null ServiceRequest. Don't attempt | 213 | // A button with no action defined, will return a null ServiceRequest. Don't attempt |
238 | // to send/do anything with this as it will crash | 214 | // to send/do anything with this as it will crash |
239 | /* ### FIXME */ | 215 | /* ### FIXME */ |
240 | #if 0 | 216 | #if 0 |
241 | if ( !sr.isNull() ) { | 217 | if ( !sr.isNull() ) { |
242 | QString app = sr.app(); | 218 | QString app = sr.app(); |
243 | bool vis = hasVisibleWindow(app, app != "qpe"); | 219 | bool vis = hasVisibleWindow(app, app != "qpe"); |
244 | if ( sr.message() == "raise()" && vis ) { | 220 | if ( sr.message() == "raise()" && vis ) { |
245 | sr.setMessage("nextView()"); | 221 | sr.setMessage("nextView()"); |
246 | } else { | 222 | } else { |
247 | // "back door" | 223 | // "back door" |
248 | sr << (int)vis; | 224 | sr << (int)vis; |
249 | } | 225 | } |
250 | 226 | ||
251 | sr.send(); | 227 | sr.send(); |
252 | } | 228 | } |
253 | #endif | 229 | #endif |
254 | } | 230 | } |
255 | 231 | ||
256 | 232 | ||
257 | #ifdef Q_WS_QWS | 233 | #ifdef Q_WS_QWS |
258 | 234 | ||
259 | 235 | ||
260 | typedef struct KeyOverride { | 236 | typedef struct KeyOverride { |
261 | ushort scan_code; | 237 | ushort scan_code; |
262 | QWSServer::KeyMap map; | 238 | QWSServer::KeyMap map; |
263 | }; | 239 | }; |
264 | 240 | ||
265 | 241 | ||
266 | static const KeyOverride jp109keys[] = { | 242 | static const KeyOverride jp109keys[] = { |
267 | { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, | 243 | { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, |
268 | { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, | 244 | { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, |
269 | { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, | 245 | { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, |
270 | { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, | 246 | { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, |
271 | { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, | 247 | { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, |
272 | { 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } }, | 248 | { 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } }, |
273 | { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, | 249 | { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, |
274 | { 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } }, | 250 | { 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } }, |
275 | { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, | 251 | { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, |
276 | { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } }, | 252 | { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } }, |
277 | { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, | 253 | { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, |
278 | { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, | 254 | { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, |
279 | { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } }, | 255 | { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } }, |
280 | { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, | 256 | { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, |
281 | { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } }, | 257 | { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } }, |
282 | { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, | 258 | { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, |
283 | { 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } }, | 259 | { 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } }, |
284 | { 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } }, | 260 | { 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } }, |
285 | { 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } }, | 261 | { 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } }, |
286 | { 0x00, { 0, 0xffff , 0xffff , 0xffff } } | 262 | { 0x00, { 0, 0xffff , 0xffff , 0xffff } } |
287 | }; | 263 | }; |
288 | 264 | ||
289 | bool Server::setKeyboardLayout( const QString &kb ) | 265 | bool Server::setKeyboardLayout( const QString &kb ) |
290 | { | 266 | { |
291 | //quick demo version that can be extended | 267 | //quick demo version that can be extended |
292 | 268 | ||
293 | QIntDict<QWSServer::KeyMap> *om = 0; | 269 | QIntDict<QWSServer::KeyMap> *om = 0; |
294 | if ( kb == "us101" ) { // No tr | 270 | if ( kb == "us101" ) { // No tr |
295 | om = 0; | 271 | om = 0; |
296 | } else if ( kb == "jp109" ) { | 272 | } else if ( kb == "jp109" ) { |
297 | om = new QIntDict<QWSServer::KeyMap>(37); | 273 | om = new QIntDict<QWSServer::KeyMap>(37); |
298 | const KeyOverride *k = jp109keys; | 274 | const KeyOverride *k = jp109keys; |
299 | while ( k->scan_code ) { | 275 | while ( k->scan_code ) { |
300 | om->insert( k->scan_code, &k->map ); | 276 | om->insert( k->scan_code, &k->map ); |
301 | k++; | 277 | k++; |
302 | } | 278 | } |
303 | } | 279 | } |
304 | QWSServer::setOverrideKeys( om ); | 280 | QWSServer::setOverrideKeys( om ); |
305 | 281 | ||
306 | return TRUE; | 282 | return TRUE; |
307 | } | 283 | } |
308 | 284 | ||
309 | #endif | 285 | #endif |
310 | 286 | ||
311 | void Server::systemMsg(const QCString &msg, const QByteArray &data) | 287 | void Server::systemMsg(const QCString &msg, const QByteArray &data) |
312 | { | 288 | { |
313 | QDataStream stream( data, IO_ReadOnly ); | 289 | QDataStream stream( data, IO_ReadOnly ); |
314 | 290 | ||
315 | if ( msg == "securityChanged()" ) { | 291 | if ( msg == "securityChanged()" ) { |
316 | if ( transferServer ) | 292 | if ( transferServer ) |
317 | transferServer->authorizeConnections(); | 293 | transferServer->authorizeConnections(); |
318 | if ( qcopBridge ) | 294 | if ( qcopBridge ) |
319 | qcopBridge->authorizeConnections(); | 295 | qcopBridge->authorizeConnections(); |
320 | } | 296 | } |
321 | /* ### FIXME support TempScreenSaverMode */ | 297 | /* ### FIXME support TempScreenSaverMode */ |
322 | #if 0 | 298 | #if 0 |
323 | else if ( msg == "setTempScreenSaverMode(int,int)" ) { | 299 | else if ( msg == "setTempScreenSaverMode(int,int)" ) { |
324 | int mode, pid; | 300 | int mode, pid; |
325 | stream >> mode >> pid; | 301 | stream >> mode >> pid; |
326 | tsmMonitor->setTempMode(mode, pid); | 302 | tsmMonitor->setTempMode(mode, pid); |
327 | } | 303 | } |
328 | #endif | 304 | #endif |
329 | else if ( msg == "linkChanged(QString)" ) { | 305 | else if ( msg == "linkChanged(QString)" ) { |
330 | QString link; | 306 | QString link; |
331 | stream >> link; | 307 | stream >> link; |
332 | odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; | 308 | odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; |
333 | docList->linkChanged(link); | 309 | docList->linkChanged(link); |
334 | } else if ( msg == "serviceChanged(QString)" ) { | 310 | } else if ( msg == "serviceChanged(QString)" ) { |
335 | MimeType::updateApplications(); | 311 | MimeType::updateApplications(); |
336 | } else if ( msg == "mkdir(QString)" ) { | 312 | } else if ( msg == "mkdir(QString)" ) { |
337 | QString dir; | 313 | QString dir; |
338 | stream >> dir; | 314 | stream >> dir; |
339 | if ( !dir.isEmpty() ) | 315 | if ( !dir.isEmpty() ) |
340 | mkdir( dir ); | 316 | mkdir( dir ); |
341 | } else if ( msg == "rdiffGenSig(QString,QString)" ) { | 317 | } else if ( msg == "rdiffGenSig(QString,QString)" ) { |
342 | QString baseFile, sigFile; | 318 | QString baseFile, sigFile; |
343 | stream >> baseFile >> sigFile; | 319 | stream >> baseFile >> sigFile; |
344 | QRsync::generateSignature( baseFile, sigFile ); | 320 | QRsync::generateSignature( baseFile, sigFile ); |
345 | } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { | 321 | } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { |
346 | QString baseFile, sigFile, deltaFile; | 322 | QString baseFile, sigFile, deltaFile; |
347 | stream >> baseFile >> sigFile >> deltaFile; | 323 | stream >> baseFile >> sigFile >> deltaFile; |
348 | QRsync::generateDiff( baseFile, sigFile, deltaFile ); | 324 | QRsync::generateDiff( baseFile, sigFile, deltaFile ); |
349 | } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { | 325 | } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { |
350 | QString baseFile, deltaFile; | 326 | QString baseFile, deltaFile; |
351 | stream >> baseFile >> deltaFile; | 327 | stream >> baseFile >> deltaFile; |
352 | if ( !QFile::exists( baseFile ) ) { | 328 | if ( !QFile::exists( baseFile ) ) { |
353 | QFile f( baseFile ); | 329 | QFile f( baseFile ); |
354 | f.open( IO_WriteOnly ); | 330 | f.open( IO_WriteOnly ); |
355 | f.close(); | 331 | f.close(); |
356 | } | 332 | } |
357 | QRsync::applyDiff( baseFile, deltaFile ); | 333 | QRsync::applyDiff( baseFile, deltaFile ); |
358 | #ifndef QT_NO_COP | 334 | #ifndef QT_NO_COP |
359 | QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); | 335 | QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); |
360 | e << baseFile; | 336 | e << baseFile; |
361 | #endif | 337 | #endif |
362 | } else if ( msg == "rdiffCleanup()" ) { | 338 | } else if ( msg == "rdiffCleanup()" ) { |
363 | mkdir( "/tmp/rdiff" ); | 339 | mkdir( "/tmp/rdiff" ); |
364 | QDir dir; | 340 | QDir dir; |
365 | dir.setPath( "/tmp/rdiff" ); | 341 | dir.setPath( "/tmp/rdiff" ); |
366 | QStringList entries = dir.entryList(); | 342 | QStringList entries = dir.entryList(); |
367 | for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) | 343 | for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) |
368 | dir.remove( *it ); | 344 | dir.remove( *it ); |
369 | } else if ( msg == "sendHandshakeInfo()" ) { | 345 | } else if ( msg == "sendHandshakeInfo()" ) { |
370 | QString home = getenv( "HOME" ); | 346 | QString home = getenv( "HOME" ); |
371 | #ifndef QT_NO_COP | 347 | #ifndef QT_NO_COP |
372 | QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); | 348 | QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); |
373 | e << home; | 349 | e << home; |
374 | int locked = (int) ServerApplication::screenLocked(); | 350 | int locked = (int) ServerApplication::screenLocked(); |
375 | e << locked; | 351 | e << locked; |
376 | #endif | 352 | #endif |
377 | 353 | ||
378 | } | 354 | } |
379 | /* | 355 | /* |
380 | * QtopiaDesktop relies on the major number | 356 | * QtopiaDesktop relies on the major number |
381 | * to start with 1. We're at 0.9 | 357 | * to start with 1. We're at 0.9 |
382 | * so wee need to fake at least 1.4 to be able | 358 | * so wee need to fake at least 1.4 to be able |
383 | * to sync with QtopiaDesktop1.6 | 359 | * to sync with QtopiaDesktop1.6 |
384 | */ | 360 | */ |
385 | else if ( msg == "sendVersionInfo()" ) { | 361 | else if ( msg == "sendVersionInfo()" ) { |
386 | QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); | 362 | QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); |
387 | /* ### FIXME Architecture ### */ | 363 | /* ### FIXME Architecture ### */ |
388 | e << QString::fromLatin1("1.7") << "Uncustomized Device"; | 364 | e << QString::fromLatin1("1.7") << "Uncustomized Device"; |
389 | } else if ( msg == "sendCardInfo()" ) { | 365 | } else if ( msg == "sendCardInfo()" ) { |
390 | #ifndef QT_NO_COP | 366 | #ifndef QT_NO_COP |
391 | QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); | 367 | QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); |
392 | #endif | 368 | #endif |
393 | storage->update(); | 369 | storage->update(); |
394 | const QList<FileSystem> &fs = storage->fileSystems(); | 370 | const QList<FileSystem> &fs = storage->fileSystems(); |
395 | QListIterator<FileSystem> it ( fs ); | 371 | QListIterator<FileSystem> it ( fs ); |
396 | QString s; | 372 | QString s; |
397 | QString homeDir = getenv("HOME"); | 373 | QString homeDir = getenv("HOME"); |
398 | QString homeFs, homeFsPath; | 374 | QString homeFs, homeFsPath; |
399 | for ( ; it.current(); ++it ) { | 375 | for ( ; it.current(); ++it ) { |
400 | int k4 = (*it)->blockSize()/256; | 376 | int k4 = (*it)->blockSize()/256; |
401 | if ( (*it)->isRemovable() ) { | 377 | if ( (*it)->isRemovable() ) { |
402 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr | 378 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr |
403 | + QString::number( (*it)->availBlocks() * k4/4 ) | 379 | + QString::number( (*it)->availBlocks() * k4/4 ) |
404 | + "K " + (*it)->options() + ";"; | 380 | + "K " + (*it)->options() + ";"; |
405 | } else if ( homeDir.contains( (*it)->path() ) && | 381 | } else if ( homeDir.contains( (*it)->path() ) && |
406 | (*it)->path().length() > homeFsPath.length() ) { | 382 | (*it)->path().length() > homeFsPath.length() ) { |
407 | homeFsPath = (*it)->path(); | 383 | homeFsPath = (*it)->path(); |
408 | homeFs = | 384 | homeFs = |
409 | (*it)->name() + "=" + homeDir + "/Documents " // No tr | 385 | (*it)->name() + "=" + homeDir + "/Documents " // No tr |
410 | + QString::number( (*it)->availBlocks() * k4/4 ) | 386 | + QString::number( (*it)->availBlocks() * k4/4 ) |
411 | + "K " + (*it)->options() + ";"; | 387 | + "K " + (*it)->options() + ";"; |
412 | } | 388 | } |
413 | } | 389 | } |
414 | if ( !homeFs.isEmpty() ) | 390 | if ( !homeFs.isEmpty() ) |
415 | s += homeFs; | 391 | s += homeFs; |
416 | 392 | ||
417 | #ifndef QT_NO_COP | 393 | #ifndef QT_NO_COP |
418 | e << s; | 394 | e << s; |
419 | #endif | 395 | #endif |
420 | } else if ( msg == "sendSyncDate(QString)" ) { | 396 | } else if ( msg == "sendSyncDate(QString)" ) { |
421 | QString app; | 397 | QString app; |
422 | stream >> app; | 398 | stream >> app; |
423 | Config cfg( "qpe" ); | 399 | Config cfg( "qpe" ); |
424 | cfg.setGroup("SyncDate"); | 400 | cfg.setGroup("SyncDate"); |
425 | #ifndef QT_NO_COP | 401 | #ifndef QT_NO_COP |
426 | QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); | 402 | QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); |
427 | e << app << cfg.readEntry( app ); | 403 | e << app << cfg.readEntry( app ); |
428 | #endif | 404 | #endif |
429 | //odebug << "QPE/System sendSyncDate for " << app.latin1() << ": response " | 405 | //odebug << "QPE/System sendSyncDate for " << app.latin1() << ": response " |
430 | // << cfg.readEntry( app ).latin1() << oendl; | 406 | // << cfg.readEntry( app ).latin1() << oendl; |
431 | } else if ( msg == "setSyncDate(QString,QString)" ) { | 407 | } else if ( msg == "setSyncDate(QString,QString)" ) { |
432 | QString app, date; | 408 | QString app, date; |
433 | stream >> app >> date; | 409 | stream >> app >> date; |
434 | Config cfg( "qpe" ); | 410 | Config cfg( "qpe" ); |
435 | cfg.setGroup("SyncDate"); | 411 | cfg.setGroup("SyncDate"); |
436 | cfg.writeEntry( app, date ); | 412 | cfg.writeEntry( app, date ); |
437 | //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; | 413 | //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; |
438 | } else if ( msg == "startSync(QString)" ) { | 414 | } else if ( msg == "startSync(QString)" ) { |
439 | QString what; | 415 | QString what; |
440 | stream >> what; | 416 | stream >> what; |
441 | delete syncDialog; | 417 | delete syncDialog; |
442 | syncDialog = new SyncDialog( this, what ); | 418 | syncDialog = new SyncDialog( this, what ); |
443 | syncDialog->show(); | 419 | syncDialog->show(); |
444 | connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); | 420 | connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); |
445 | } else if ( msg == "stopSync()") { | 421 | } else if ( msg == "stopSync()") { |
446 | delete syncDialog; | 422 | delete syncDialog; |
447 | syncDialog = 0; | 423 | syncDialog = 0; |
448 | } else if (msg == "restoreDone(QString)") { | 424 | } else if (msg == "restoreDone(QString)") { |
449 | docList->restoreDone(); | 425 | docList->restoreDone(); |
450 | } else if ( msg == "getAllDocLinks()" ) { | 426 | } else if ( msg == "getAllDocLinks()" ) { |
451 | docList->sendAllDocLinks(); | 427 | docList->sendAllDocLinks(); |
452 | } | 428 | } |
453 | #ifdef Q_WS_QWS | 429 | #ifdef Q_WS_QWS |
454 | else if ( msg == "setMouseProto(QString)" ) { | 430 | else if ( msg == "setMouseProto(QString)" ) { |
455 | QString mice; | 431 | QString mice; |
456 | stream >> mice; | 432 | stream >> mice; |
457 | setenv("QWS_MOUSE_PROTO",mice.latin1(),1); | 433 | setenv("QWS_MOUSE_PROTO",mice.latin1(),1); |
458 | qwsServer->openMouse(); | 434 | qwsServer->openMouse(); |
459 | } else if ( msg == "setKeyboard(QString)" ) { | 435 | } else if ( msg == "setKeyboard(QString)" ) { |
460 | QString kb; | 436 | QString kb; |
461 | stream >> kb; | 437 | stream >> kb; |
462 | setenv("QWS_KEYBOARD",kb.latin1(),1); | 438 | setenv("QWS_KEYBOARD",kb.latin1(),1); |
463 | qwsServer->openKeyboard(); | 439 | qwsServer->openKeyboard(); |
464 | 440 | ||
465 | } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { | 441 | } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { |
466 | int delay, period; | 442 | int delay, period; |
467 | stream >> delay >> period; | 443 | stream >> delay >> period; |
468 | qwsSetKeyboardAutoRepeat( delay, period ); | 444 | qwsSetKeyboardAutoRepeat( delay, period ); |
469 | Config cfg( "qpe" ); | 445 | Config cfg( "qpe" ); |
470 | cfg.setGroup("Keyboard"); | 446 | cfg.setGroup("Keyboard"); |
471 | cfg.writeEntry( "RepeatDelay", delay ); | 447 | cfg.writeEntry( "RepeatDelay", delay ); |
472 | cfg.writeEntry( "RepeatPeriod", period ); | 448 | cfg.writeEntry( "RepeatPeriod", period ); |
473 | } else if ( msg == "setKeyboardLayout(QString)" ) { | 449 | } else if ( msg == "setKeyboardLayout(QString)" ) { |
474 | QString kb; | 450 | QString kb; |
475 | stream >> kb; | 451 | stream >> kb; |
476 | setKeyboardLayout( kb ); | 452 | setKeyboardLayout( kb ); |
477 | Config cfg( "qpe" ); | 453 | Config cfg( "qpe" ); |
478 | cfg.setGroup("Keyboard"); | 454 | cfg.setGroup("Keyboard"); |
479 | cfg.writeEntry( "Layout", kb ); | 455 | cfg.writeEntry( "Layout", kb ); |
480 | } else if ( msg == "autoStart(QString)" ) { | 456 | } else if ( msg == "autoStart(QString)" ) { |
481 | QString appName; | 457 | QString appName; |
482 | stream >> appName; | 458 | stream >> appName; |
483 | Config cfg( "autostart" ); | 459 | Config cfg( "autostart" ); |
484 | cfg.setGroup( "AutoStart" ); | 460 | cfg.setGroup( "AutoStart" ); |
485 | if ( appName.compare("clear") == 0){ | 461 | if ( appName.compare("clear") == 0){ |
486 | cfg.writeEntry("Apps", ""); | 462 | cfg.writeEntry("Apps", ""); |
487 | } | 463 | } |
488 | } else if ( msg == "autoStart(QString,QString)" ) { | 464 | } else if ( msg == "autoStart(QString,QString)" ) { |
489 | QString modifier, appName; | 465 | QString modifier, appName; |
490 | stream >> modifier >> appName; | 466 | stream >> modifier >> appName; |
491 | Config cfg( "autostart" ); | 467 | Config cfg( "autostart" ); |
492 | cfg.setGroup( "AutoStart" ); | 468 | cfg.setGroup( "AutoStart" ); |
493 | if ( modifier.compare("add") == 0 ){ | 469 | if ( modifier.compare("add") == 0 ){ |
494 | // only add if appname is entered | 470 | // only add if appname is entered |
495 | if (!appName.isEmpty()) { | 471 | if (!appName.isEmpty()) { |
496 | cfg.writeEntry("Apps", appName); | 472 | cfg.writeEntry("Apps", appName); |
497 | } | 473 | } |
498 | } else if (modifier.compare("remove") == 0 ) { | 474 | } else if (modifier.compare("remove") == 0 ) { |
499 | // need to change for multiple entries | 475 | // need to change for multiple entries |
500 | // actually remove is right now simular to clear, but in future there | 476 | // actually remove is right now simular to clear, but in future there |
501 | // should be multiple apps in autostart possible. | 477 | // should be multiple apps in autostart possible. |
502 | QString checkName; | 478 | QString checkName; |
503 | checkName = cfg.readEntry("Apps", ""); | 479 | checkName = cfg.readEntry("Apps", ""); |
504 | if (checkName == appName) { | 480 | if (checkName == appName) { |
505 | cfg.writeEntry("Apps", ""); | 481 | cfg.writeEntry("Apps", ""); |
506 | } | 482 | } |
507 | } | 483 | } |
508 | // case the autostart feature should be delayed | 484 | // case the autostart feature should be delayed |
509 | } else if ( msg == "autoStart(QString,QString,QString)") { | 485 | } else if ( msg == "autoStart(QString,QString,QString)") { |
510 | QString modifier, appName, delay; | 486 | QString modifier, appName, delay; |
511 | stream >> modifier >> appName >> delay; | 487 | stream >> modifier >> appName >> delay; |
512 | Config cfg( "autostart" ); | 488 | Config cfg( "autostart" ); |
513 | 489 | ||
514 | cfg.setGroup( "AutoStart" ); | 490 | cfg.setGroup( "AutoStart" ); |
515 | if ( modifier.compare("add") == 0 ){ | 491 | if ( modifier.compare("add") == 0 ){ |
516 | // only add it appname is entered | 492 | // only add it appname is entered |
517 | if (!appName.isEmpty()) { | 493 | if (!appName.isEmpty()) { |
518 | cfg.writeEntry("Apps", appName); | 494 | cfg.writeEntry("Apps", appName); |
519 | cfg.writeEntry("Delay", delay); | 495 | cfg.writeEntry("Delay", delay); |
520 | } | 496 | } |
521 | } else { | 497 | } else { |
522 | } | 498 | } |
523 | } | 499 | } |
524 | #endif | 500 | #endif |
525 | } | 501 | } |
526 | 502 | ||
527 | void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) | 503 | void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) |
528 | { | 504 | { |
529 | QDataStream stream( data, IO_ReadOnly ); | 505 | QDataStream stream( data, IO_ReadOnly ); |
530 | 506 | ||
531 | if ( msg == "reloadApps()" ) { | 507 | if ( msg == "reloadApps()" ) { |
532 | docList->reloadAppLnks(); | 508 | docList->reloadAppLnks(); |
533 | } else if ( msg == "soundAlarm()" ) { | 509 | } else if ( msg == "soundAlarm()" ) { |
534 | ServerApplication::soundAlarm(); | 510 | ServerApplication::soundAlarm(); |
535 | } | 511 | } |
536 | else if ( msg == "setLed(int,bool)" ) { | 512 | else if ( msg == "setLed(int,bool)" ) { |
537 | int led, status; | 513 | int led, status; |
538 | stream >> led >> status; | 514 | stream >> led >> status; |
539 | 515 | ||
540 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); | 516 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); |
541 | if ( ll. count ( )) { | 517 | if ( ll. count ( )) { |
542 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; | 518 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; |
543 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); | 519 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); |
544 | 520 | ||
545 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); | 521 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); |
546 | } | 522 | } |
547 | } | 523 | } |
548 | } | 524 | } |
549 | 525 | ||
550 | void Server::cancelSync() | 526 | void Server::cancelSync() |
551 | { | 527 | { |
552 | #ifndef QT_NO_COP | 528 | #ifndef QT_NO_COP |
553 | QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); | 529 | QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); |
554 | #endif | 530 | #endif |
555 | delete syncDialog; | 531 | delete syncDialog; |
556 | syncDialog = 0; | 532 | syncDialog = 0; |
557 | } | 533 | } |
558 | 534 | ||
559 | bool Server::mkdir(const QString &localPath) | 535 | bool Server::mkdir(const QString &localPath) |
560 | { | 536 | { |
561 | QDir fullDir(localPath); | 537 | QDir fullDir(localPath); |
562 | if (fullDir.exists()) | 538 | if (fullDir.exists()) |
563 | return true; | 539 | return true; |
564 | 540 | ||
565 | // at this point the directory doesn't exist | 541 | // at this point the directory doesn't exist |
566 | // go through the directory tree and start creating the direcotories | 542 | // go through the directory tree and start creating the direcotories |
567 | // that don't exist; if we can't create the directories, return false | 543 | // that don't exist; if we can't create the directories, return false |
568 | 544 | ||
569 | QString dirSeps = "/"; | 545 | QString dirSeps = "/"; |
570 | int dirIndex = localPath.find(dirSeps); | 546 | int dirIndex = localPath.find(dirSeps); |
571 | QString checkedPath; | 547 | QString checkedPath; |
572 | 548 | ||
573 | // didn't find any seps; weird, use the cur dir instead | 549 | // didn't find any seps; weird, use the cur dir instead |
574 | if (dirIndex == -1) { | 550 | if (dirIndex == -1) { |
575 | //odebug << "No seperators found in path " << localPath << "" << oendl; | 551 | //odebug << "No seperators found in path " << localPath << "" << oendl; |
576 | checkedPath = QDir::currentDirPath(); | 552 | checkedPath = QDir::currentDirPath(); |
577 | } | 553 | } |
578 | 554 | ||
579 | while (checkedPath != localPath) { | 555 | while (checkedPath != localPath) { |
580 | // no more seperators found, use the local path | 556 | // no more seperators found, use the local path |
581 | if (dirIndex == -1) | 557 | if (dirIndex == -1) |
582 | checkedPath = localPath; | 558 | checkedPath = localPath; |
583 | else { | 559 | else { |
584 | // the next directory to check | 560 | // the next directory to check |
585 | checkedPath = localPath.left(dirIndex) + "/"; | 561 | checkedPath = localPath.left(dirIndex) + "/"; |
586 | // advance the iterator; the next dir seperator | 562 | // advance the iterator; the next dir seperator |
587 | dirIndex = localPath.find(dirSeps, dirIndex+1); | 563 | dirIndex = localPath.find(dirSeps, dirIndex+1); |
588 | } | 564 | } |
589 | 565 | ||
590 | QDir checkDir(checkedPath); | 566 | QDir checkDir(checkedPath); |
591 | if (!checkDir.exists()) { | 567 | if (!checkDir.exists()) { |
592 | //odebug << "mkdir making dir " << checkedPath << "" << oendl; | 568 | //odebug << "mkdir making dir " << checkedPath << "" << oendl; |
593 | 569 | ||
594 | if (!checkDir.mkdir(checkedPath)) { | 570 | if (!checkDir.mkdir(checkedPath)) { |
595 | odebug << "Unable to make directory " << checkedPath << "" << oendl; | 571 | odebug << "Unable to make directory " << checkedPath << "" << oendl; |
596 | return FALSE; | 572 | return FALSE; |
597 | } | 573 | } |
598 | } | 574 | } |
599 | 575 | ||
600 | } | 576 | } |
601 | return TRUE; | 577 | return TRUE; |
602 | } | 578 | } |
603 | 579 | ||
604 | void Server::styleChange( QStyle &s ) | 580 | void Server::styleChange( QStyle &s ) |
605 | { | 581 | { |
606 | QWidget::styleChange( s ); | 582 | QWidget::styleChange( s ); |
607 | } | 583 | } |
608 | 584 | ||
609 | void Server::startTransferServer() | 585 | void Server::startTransferServer() |
610 | { | 586 | { |
611 | if ( !qcopBridge ) { | 587 | if ( !qcopBridge ) { |
612 | // start qcop bridge server | 588 | // start qcop bridge server |
613 | qcopBridge = new QCopBridge( 4243 ); | 589 | qcopBridge = new QCopBridge( 4243 ); |
614 | if ( qcopBridge->ok() ) { | 590 | if ( qcopBridge->ok() ) { |
615 | // ... OK | 591 | // ... OK |
616 | connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), | 592 | connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), |
617 | this, SLOT(syncConnectionClosed(const QHostAddress&)) ); | 593 | this, SLOT(syncConnectionClosed(const QHostAddress&)) ); |
618 | } else { | 594 | } else { |
619 | delete qcopBridge; | 595 | delete qcopBridge; |
620 | qcopBridge = 0; | 596 | qcopBridge = 0; |
621 | } | 597 | } |
622 | } | 598 | } |
623 | if ( !transferServer ) { | 599 | if ( !transferServer ) { |
624 | // start transfer server | 600 | // start transfer server |
625 | transferServer = new TransferServer( 4242 ); | 601 | transferServer = new TransferServer( 4242 ); |
626 | if ( transferServer->ok() ) { | 602 | if ( transferServer->ok() ) { |
627 | // ... OK | 603 | // ... OK |
628 | } else { | 604 | } else { |
629 | delete transferServer; | 605 | delete transferServer; |
630 | transferServer = 0; | 606 | transferServer = 0; |
631 | } | 607 | } |
632 | } | 608 | } |
633 | if ( !transferServer || !qcopBridge ) | 609 | if ( !transferServer || !qcopBridge ) |
634 | tid_xfer = startTimer( 2000 ); | 610 | tid_xfer = startTimer( 2000 ); |
635 | } | 611 | } |
636 | 612 | ||
637 | void Server::timerEvent( QTimerEvent *e ) | 613 | void Server::timerEvent( QTimerEvent *e ) |
638 | { | 614 | { |
639 | if ( e->timerId() == tid_xfer ) { | 615 | if ( e->timerId() == tid_xfer ) { |
640 | killTimer( tid_xfer ); | 616 | killTimer( tid_xfer ); |
641 | tid_xfer = 0; | 617 | tid_xfer = 0; |
642 | startTransferServer(); | 618 | startTransferServer(); |
643 | } | 619 | } |
644 | /* ### FIXME today startin */ | 620 | /* ### FIXME today startin */ |
645 | #if 0 | 621 | #if 0 |
646 | else if ( e->timerId() == tid_today ) { | 622 | else if ( e->timerId() == tid_today ) { |
647 | QDate today = QDate::currentDate(); | 623 | QDate today = QDate::currentDate(); |
648 | if ( today != last_today_show ) { | 624 | if ( today != last_today_show ) { |
649 | last_today_show = today; | 625 | last_today_show = today; |
650 | Config cfg("today"); | 626 | Config cfg("today"); |
651 | cfg.setGroup("Start"); | 627 | cfg.setGroup("Start"); |
652 | #ifndef QPE_DEFAULT_TODAY_MODE | 628 | #ifndef QPE_DEFAULT_TODAY_MODE |
653 | #define QPE_DEFAULT_TODAY_MODE "Never" | 629 | #define QPE_DEFAULT_TODAY_MODE "Never" |
654 | #endif | 630 | #endif |
655 | if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { | 631 | if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { |
656 | QCopEnvelope env(Service::channel("today"),"raise()"); | 632 | QCopEnvelope env(Service::channel("today"),"raise()"); |
657 | } | 633 | } |
658 | } | 634 | } |
659 | } | 635 | } |
660 | #endif | 636 | #endif |
661 | } | 637 | } |
662 | 638 | ||
663 | void Server::terminateServers() | 639 | void Server::terminateServers() |
664 | { | 640 | { |
665 | delete transferServer; | 641 | delete transferServer; |
666 | delete qcopBridge; | 642 | delete qcopBridge; |
667 | transferServer = 0; | 643 | transferServer = 0; |
668 | qcopBridge = 0; | 644 | qcopBridge = 0; |
669 | } | 645 | } |
670 | 646 | ||
671 | void Server::syncConnectionClosed( const QHostAddress & ) | 647 | void Server::syncConnectionClosed( const QHostAddress & ) |
672 | { | 648 | { |
673 | odebug << "Lost sync connection" << oendl; | 649 | odebug << "Lost sync connection" << oendl; |
674 | delete syncDialog; | 650 | delete syncDialog; |
675 | syncDialog = 0; | 651 | syncDialog = 0; |
676 | } | 652 | } |
677 | 653 | ||
678 | void Server::pokeTimeMonitors() | 654 | void Server::pokeTimeMonitors() |
679 | { | 655 | { |
680 | #if 0 | 656 | #if 0 |
681 | // inform all TimeMonitors | 657 | // inform all TimeMonitors |
682 | QStrList tms = Service::channels("TimeMonitor"); | 658 | QStrList tms = Service::channels("TimeMonitor"); |
683 | for (const char* ch = tms.first(); ch; ch=tms.next()) { | 659 | for (const char* ch = tms.first(); ch; ch=tms.next()) { |
684 | QString t = getenv("TZ"); | 660 | QString t = getenv("TZ"); |
685 | QCopEnvelope e(ch, "timeChange(QString)"); | 661 | QCopEnvelope e(ch, "timeChange(QString)"); |
686 | e << t; | 662 | e << t; |
687 | } | 663 | } |
688 | #endif | 664 | #endif |
689 | } | 665 | } |
690 | 666 | ||
691 | void Server::applicationLaunched(int, const QString &app) | 667 | void Server::applicationLaunched(int, const QString &app) |
692 | { | 668 | { |
693 | serverGui->applicationStateChanged( app, ServerInterface::Launching ); | 669 | serverGui->applicationStateChanged( app, ServerInterface::Launching ); |
694 | } | 670 | } |
695 | 671 | ||
696 | void Server::applicationTerminated(int pid, const QString &app) | 672 | void Server::applicationTerminated(int pid, const QString &app) |
697 | { | 673 | { |
698 | serverGui->applicationStateChanged( app, ServerInterface::Terminated ); | 674 | serverGui->applicationStateChanged( app, ServerInterface::Terminated ); |
699 | #if 0 | 675 | #if 0 |
700 | tsmMonitor->applicationTerminated( pid ); | 676 | tsmMonitor->applicationTerminated( pid ); |
677 | #else | ||
678 | Q_UNUSED( pid ) | ||
701 | #endif | 679 | #endif |
702 | } | 680 | } |
703 | 681 | ||
704 | void Server::applicationConnected(const QString &app) | 682 | void Server::applicationConnected(const QString &app) |
705 | { | 683 | { |
706 | serverGui->applicationStateChanged( app, ServerInterface::Running ); | 684 | serverGui->applicationStateChanged( app, ServerInterface::Running ); |
707 | } | 685 | } |
708 | 686 | ||
709 | void Server::storageChanged() | 687 | void Server::storageChanged() |
710 | { | 688 | { |
711 | system( "opie-update-symlinks" ); | 689 | system( "opie-update-symlinks" ); |
712 | serverGui->storageChanged( storage->fileSystems() ); | 690 | serverGui->storageChanged( storage->fileSystems() ); |
713 | docList->storageChanged(); | 691 | docList->storageChanged(); |
714 | } | 692 | } |
715 | 693 | ||
716 | 694 | ||
717 | 695 | ||
718 | void Server::preloadApps() | 696 | void Server::preloadApps() |
719 | { | 697 | { |
720 | Config cfg("Launcher"); | 698 | Config cfg("Launcher"); |
721 | cfg.setGroup("Preload"); | 699 | cfg.setGroup("Preload"); |
722 | QStringList apps = cfg.readListEntry("Apps",','); | 700 | QStringList apps = cfg.readListEntry("Apps",','); |
723 | for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { | 701 | for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { |
724 | #ifndef QT_NO_COP | 702 | #ifndef QT_NO_COP |
725 | QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); | 703 | QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); |
726 | #endif | 704 | #endif |
727 | } | 705 | } |
728 | } | 706 | } |
729 | 707 | ||
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp index a2302d8..66cc788 100644 --- a/core/launcher/serverapp.cpp +++ b/core/launcher/serverapp.cpp | |||
@@ -1,847 +1,847 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2003 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 | 20 | ||
21 | #include "serverapp.h" | 21 | #include "serverapp.h" |
22 | #include "screensaver.h" | 22 | #include "screensaver.h" |
23 | 23 | ||
24 | /* OPIE */ | 24 | /* OPIE */ |
25 | #include <opie2/odebug.h> | 25 | #include <opie2/odebug.h> |
26 | #include <opie2/odevice.h> | 26 | #include <opie2/odevice.h> |
27 | #include <opie2/multiauthpassword.h> | 27 | #include <opie2/multiauthpassword.h> |
28 | 28 | ||
29 | #include <qtopia/config.h> | 29 | #include <qtopia/config.h> |
30 | #include <qtopia/power.h> | 30 | #include <qtopia/power.h> |
31 | 31 | ||
32 | #ifdef Q_WS_QWS | 32 | #ifdef Q_WS_QWS |
33 | #include <qtopia/qcopenvelope_qws.h> | 33 | #include <qtopia/qcopenvelope_qws.h> |
34 | #endif | 34 | #endif |
35 | #include <qtopia/global.h> | 35 | #include <qtopia/global.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #ifdef Q_WS_QWS | 39 | #ifdef Q_WS_QWS |
40 | #include <qgfx_qws.h> | 40 | #include <qgfx_qws.h> |
41 | #endif | 41 | #endif |
42 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qpainter.h> | 44 | #include <qpainter.h> |
45 | #include <qfile.h> | 45 | #include <qfile.h> |
46 | #include <qpixmapcache.h> | 46 | #include <qpixmapcache.h> |
47 | 47 | ||
48 | /* STD */ | 48 | /* STD */ |
49 | #ifdef Q_OS_WIN32 | 49 | #ifdef Q_OS_WIN32 |
50 | #include <io.h> | 50 | #include <io.h> |
51 | #include <process.h> | 51 | #include <process.h> |
52 | #else | 52 | #else |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #endif | 54 | #endif |
55 | #include <stdlib.h> | 55 | #include <stdlib.h> |
56 | 56 | ||
57 | static ServerApplication *serverApp = 0; | 57 | static ServerApplication *serverApp = 0; |
58 | static int loggedin=0; | 58 | static int loggedin=0; |
59 | 59 | ||
60 | QCopKeyRegister::QCopKeyRegister() | 60 | QCopKeyRegister::QCopKeyRegister() |
61 | : m_keyCode( 0 ) | 61 | : m_keyCode( 0 ) |
62 | { | 62 | { |
63 | } | 63 | } |
64 | 64 | ||
65 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) | 65 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) |
66 | :m_keyCode( k ), m_channel( c ), m_message( m ) | 66 | :m_keyCode( k ), m_channel( c ), m_message( m ) |
67 | { | 67 | { |
68 | } | 68 | } |
69 | 69 | ||
70 | int QCopKeyRegister::keyCode() const | 70 | int QCopKeyRegister::keyCode() const |
71 | { | 71 | { |
72 | return m_keyCode; | 72 | return m_keyCode; |
73 | } | 73 | } |
74 | 74 | ||
75 | QCString QCopKeyRegister::channel() const | 75 | QCString QCopKeyRegister::channel() const |
76 | { | 76 | { |
77 | return m_channel; | 77 | return m_channel; |
78 | } | 78 | } |
79 | 79 | ||
80 | QCString QCopKeyRegister::message() const | 80 | QCString QCopKeyRegister::message() const |
81 | { | 81 | { |
82 | return m_message; | 82 | return m_message; |
83 | } | 83 | } |
84 | 84 | ||
85 | bool QCopKeyRegister::send() | 85 | bool QCopKeyRegister::send() |
86 | { | 86 | { |
87 | if (m_channel.isNull() ) | 87 | if (m_channel.isNull() ) |
88 | return false; | 88 | return false; |
89 | 89 | ||
90 | QCopEnvelope( m_channel, m_message ); | 90 | QCopEnvelope( m_channel, m_message ); |
91 | 91 | ||
92 | return true; | 92 | return true; |
93 | } | 93 | } |
94 | 94 | ||
95 | //--------------------------------------------------------------------------- | 95 | //--------------------------------------------------------------------------- |
96 | 96 | ||
97 | /* | 97 | /* |
98 | Priority is number of alerts that are needed to pop up | 98 | Priority is number of alerts that are needed to pop up |
99 | alert. | 99 | alert. |
100 | */ | 100 | */ |
101 | class DesktopPowerAlerter : public QMessageBox | 101 | class DesktopPowerAlerter : public QMessageBox |
102 | { | 102 | { |
103 | Q_OBJECT | 103 | Q_OBJECT |
104 | public: | 104 | public: |
105 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 105 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
106 | : QMessageBox( tr("Battery Status"), tr("Low Battery"), | 106 | : QMessageBox( tr("Battery Status"), tr("Low Battery"), |
107 | QMessageBox::Critical, | 107 | QMessageBox::Critical, |
108 | QMessageBox::Ok | QMessageBox::Default, | 108 | QMessageBox::Ok | QMessageBox::Default, |
109 | QMessageBox::NoButton, QMessageBox::NoButton, | 109 | QMessageBox::NoButton, QMessageBox::NoButton, |
110 | parent, name, FALSE ) | 110 | parent, name, FALSE ) |
111 | { | 111 | { |
112 | currentPriority = INT_MAX; | 112 | currentPriority = INT_MAX; |
113 | alertCount = 0; | 113 | alertCount = 0; |
114 | } | 114 | } |
115 | 115 | ||
116 | void alert( const QString &text, int priority ); | 116 | void alert( const QString &text, int priority ); |
117 | void hideEvent( QHideEvent * ); | 117 | void hideEvent( QHideEvent * ); |
118 | private: | 118 | private: |
119 | int currentPriority; | 119 | int currentPriority; |
120 | int alertCount; | 120 | int alertCount; |
121 | }; | 121 | }; |
122 | 122 | ||
123 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 123 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
124 | { | 124 | { |
125 | alertCount++; | 125 | alertCount++; |
126 | if ( alertCount < priority ) | 126 | if ( alertCount < priority ) |
127 | return; | 127 | return; |
128 | if ( priority > currentPriority ) | 128 | if ( priority > currentPriority ) |
129 | return; | 129 | return; |
130 | currentPriority = priority; | 130 | currentPriority = priority; |
131 | setText( text ); | 131 | setText( text ); |
132 | show(); | 132 | show(); |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 136 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
137 | { | 137 | { |
138 | QMessageBox::hideEvent( e ); | 138 | QMessageBox::hideEvent( e ); |
139 | alertCount = 0; | 139 | alertCount = 0; |
140 | currentPriority = INT_MAX; | 140 | currentPriority = INT_MAX; |
141 | } | 141 | } |
142 | 142 | ||
143 | //--------------------------------------------------------------------------- | 143 | //--------------------------------------------------------------------------- |
144 | 144 | ||
145 | KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0) | 145 | KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0) |
146 | { | 146 | { |
147 | /* We don't do this cause it would interfere with ODevice */ | 147 | /* We don't do this cause it would interfere with ODevice */ |
148 | #if 0 | 148 | #if 0 |
149 | qwsServer->setKeyboardFilter(this); | 149 | qwsServer->setKeyboardFilter(this); |
150 | #endif | 150 | #endif |
151 | } | 151 | } |
152 | 152 | ||
153 | void KeyFilter::timerEvent(QTimerEvent* e) | 153 | void KeyFilter::timerEvent(QTimerEvent* e) |
154 | { | 154 | { |
155 | if ( e->timerId() == held_tid ) { | 155 | if ( e->timerId() == held_tid ) { |
156 | killTimer(held_tid); | 156 | killTimer(held_tid); |
157 | // button held | 157 | // button held |
158 | if ( heldButton ) { | 158 | if ( heldButton ) { |
159 | emit activate(heldButton, TRUE); | 159 | emit activate(heldButton, TRUE); |
160 | heldButton = 0; | 160 | heldButton = 0; |
161 | } | 161 | } |
162 | held_tid = 0; | 162 | held_tid = 0; |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | void KeyFilter::registerKey( const QCopKeyRegister& key ) | 166 | void KeyFilter::registerKey( const QCopKeyRegister& key ) |
167 | { | 167 | { |
168 | m_keys.insert( key.keyCode(), key ); | 168 | m_keys.insert( key.keyCode(), key ); |
169 | } | 169 | } |
170 | 170 | ||
171 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) | 171 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) |
172 | { | 172 | { |
173 | m_keys.remove( key.keyCode() ); | 173 | m_keys.remove( key.keyCode() ); |
174 | } | 174 | } |
175 | 175 | ||
176 | bool KeyFilter::keyRegistered( int key ) | 176 | bool KeyFilter::keyRegistered( int key ) |
177 | { | 177 | { |
178 | /* | 178 | /* |
179 | * Check if we've a key registered | 179 | * Check if we've a key registered |
180 | */ | 180 | */ |
181 | if ( !m_keys[key].send()) | 181 | if ( !m_keys[key].send()) |
182 | return false; | 182 | return false; |
183 | else | 183 | else |
184 | return true; | 184 | return true; |
185 | } | 185 | } |
186 | 186 | ||
187 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) | 187 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) |
188 | { | 188 | { |
189 | if ( !loggedin | 189 | if ( !loggedin |
190 | // Permitted keys | 190 | // Permitted keys |
191 | && keycode != Key_F34 // power | 191 | && keycode != Key_F34 // power |
192 | && keycode != Key_F30 // select | 192 | && keycode != Key_F30 // select |
193 | && keycode != Key_Enter | 193 | && keycode != Key_Enter |
194 | && keycode != Key_Return | 194 | && keycode != Key_Return |
195 | && keycode != Key_Space | 195 | && keycode != Key_Space |
196 | && keycode != Key_Left | 196 | && keycode != Key_Left |
197 | && keycode != Key_Right | 197 | && keycode != Key_Right |
198 | && keycode != Key_Up | 198 | && keycode != Key_Up |
199 | && keycode != Key_Down ) | 199 | && keycode != Key_Down ) |
200 | return TRUE; | 200 | return TRUE; |
201 | 201 | ||
202 | /* check if it was registered */ | 202 | /* check if it was registered */ |
203 | if (!db ) { | 203 | if (!db ) { |
204 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) | 204 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) |
205 | return true; | 205 | return true; |
206 | } else { | 206 | } else { |
207 | 207 | ||
208 | // First check to see if DeviceButtonManager knows something about this button: | 208 | // First check to see if DeviceButtonManager knows something about this button: |
209 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); | 209 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); |
210 | if (button && !autoRepeat) { | 210 | if (button && !autoRepeat) { |
211 | if ( held_tid ) { | 211 | if ( held_tid ) { |
212 | killTimer(held_tid); | 212 | killTimer(held_tid); |
213 | held_tid = 0; | 213 | held_tid = 0; |
214 | } | 214 | } |
215 | if ( button->heldAction().isNull() ) { | 215 | if ( button->heldAction().isNull() ) { |
216 | if ( press ) | 216 | if ( press ) |
217 | emit activate(button, FALSE); | 217 | emit activate(button, FALSE); |
218 | } else if ( press ) { | 218 | } else if ( press ) { |
219 | heldButton = button; | 219 | heldButton = button; |
220 | held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); | 220 | held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); |
221 | } else if ( heldButton ) { | 221 | } else if ( heldButton ) { |
222 | heldButton = 0; | 222 | heldButton = 0; |
223 | emit activate(button, FALSE); | 223 | emit activate(button, FALSE); |
224 | } | 224 | } |
225 | QWSServer::screenSaverActivate(FALSE); | 225 | QWSServer::screenSaverActivate(FALSE); |
226 | return TRUE; | 226 | return TRUE; |
227 | } | 227 | } |
228 | return false; | 228 | return false; |
229 | } | 229 | } |
230 | if ( keycode == HardKey_Suspend ) { | 230 | if ( keycode == HardKey_Suspend ) { |
231 | if ( press ) emit power(); | 231 | if ( press ) emit power(); |
232 | return TRUE; | 232 | return TRUE; |
233 | } | 233 | } |
234 | if ( keycode == HardKey_Backlight ) { | 234 | if ( keycode == HardKey_Backlight ) { |
235 | if ( press ) emit backlight(); | 235 | if ( press ) emit backlight(); |
236 | return TRUE; | 236 | return TRUE; |
237 | } | 237 | } |
238 | if ( keycode == Key_F32 ) { | 238 | if ( keycode == Key_F32 ) { |
239 | #ifndef QT_NO_COP | 239 | #ifndef QT_NO_COP |
240 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 240 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
241 | #endif | 241 | #endif |
242 | return TRUE; | 242 | return TRUE; |
243 | } | 243 | } |
244 | if ( keycode == Key_F31 ) { | 244 | if ( keycode == Key_F31 ) { |
245 | if ( press ) emit symbol(); | 245 | if ( press ) emit symbol(); |
246 | QWSServer::screenSaverActivate(FALSE); | 246 | QWSServer::screenSaverActivate(FALSE); |
247 | return TRUE; | 247 | return TRUE; |
248 | } | 248 | } |
249 | 249 | ||
250 | if ( keycode == Key_NumLock ) | 250 | if ( keycode == Key_NumLock ) |
251 | if ( press ) emit numLockStateToggle(); | 251 | if ( press ) emit numLockStateToggle(); |
252 | 252 | ||
253 | if ( keycode == Key_CapsLock ) | 253 | if ( keycode == Key_CapsLock ) |
254 | if ( press ) emit capsLockStateToggle(); | 254 | if ( press ) emit capsLockStateToggle(); |
255 | 255 | ||
256 | if ( serverApp ) | 256 | if ( serverApp ) |
257 | serverApp->keyClick(keycode,press,autoRepeat); | 257 | serverApp->keyClick(keycode,press,autoRepeat); |
258 | 258 | ||
259 | return FALSE; | 259 | return FALSE; |
260 | } | 260 | } |
261 | 261 | ||
262 | enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; | 262 | enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; |
263 | 263 | ||
264 | #if defined(QPE_HAVE_MEMALERTER) | 264 | #if defined(QPE_HAVE_MEMALERTER) |
265 | QPE_MEMALERTER_IMPL | 265 | QPE_MEMALERTER_IMPL |
266 | #endif | 266 | #endif |
267 | 267 | ||
268 | 268 | ||
269 | 269 | ||
270 | //--------------------------------------------------------------------------- | 270 | //--------------------------------------------------------------------------- |
271 | 271 | ||
272 | bool ServerApplication::doRestart = FALSE; | 272 | bool ServerApplication::doRestart = FALSE; |
273 | bool ServerApplication::allowRestart = TRUE; | 273 | bool ServerApplication::allowRestart = TRUE; |
274 | bool ServerApplication::ms_is_starting = TRUE; | 274 | bool ServerApplication::ms_is_starting = TRUE; |
275 | 275 | ||
276 | void ServerApplication::switchLCD( bool on ) | 276 | void ServerApplication::switchLCD( bool on ) |
277 | { | 277 | { |
278 | if ( !qApp ) | 278 | if ( !qApp ) |
279 | return; | 279 | return; |
280 | 280 | ||
281 | ServerApplication *dapp = ServerApplication::me() ; | 281 | ServerApplication *dapp = ServerApplication::me() ; |
282 | 282 | ||
283 | if ( !dapp-> m_screensaver ) | 283 | if ( !dapp-> m_screensaver ) |
284 | return; | 284 | return; |
285 | 285 | ||
286 | if ( on ) { | 286 | if ( on ) { |
287 | dapp-> m_screensaver-> setDisplayState ( true ); | 287 | dapp-> m_screensaver-> setDisplayState ( true ); |
288 | dapp-> m_screensaver-> setBacklight ( -3 ); | 288 | dapp-> m_screensaver-> setBacklight ( -3 ); |
289 | } else | 289 | } else |
290 | dapp-> m_screensaver-> setDisplayState ( false ); | 290 | dapp-> m_screensaver-> setDisplayState ( false ); |
291 | 291 | ||
292 | 292 | ||
293 | } | 293 | } |
294 | 294 | ||
295 | ServerApplication::ServerApplication( int& argc, char **argv, Type t ) | 295 | ServerApplication::ServerApplication( int& argc, char **argv, Type t ) |
296 | : QPEApplication( argc, argv, t ) | 296 | : QPEApplication( argc, argv, t ) |
297 | { | 297 | { |
298 | ms_is_starting = true; | 298 | ms_is_starting = true; |
299 | 299 | ||
300 | // We know we'll have lots of cached pixmaps due to App/DocLnks | 300 | // We know we'll have lots of cached pixmaps due to App/DocLnks |
301 | QPixmapCache::setCacheLimit(512); | 301 | QPixmapCache::setCacheLimit(512); |
302 | 302 | ||
303 | m_ps = new PowerStatus; | 303 | m_ps = new PowerStatus; |
304 | m_ps_last = new PowerStatus; | 304 | m_ps_last = new PowerStatus; |
305 | pa = new DesktopPowerAlerter( 0 ); | 305 | pa = new DesktopPowerAlerter( 0 ); |
306 | 306 | ||
307 | m_apm_timer = new QTimer( this ); | 307 | m_apm_timer = new QTimer( this ); |
308 | connect(m_apm_timer, SIGNAL( timeout() ), | 308 | connect(m_apm_timer, SIGNAL( timeout() ), |
309 | this, SLOT( apmTimeout() ) ); | 309 | this, SLOT( apmTimeout() ) ); |
310 | 310 | ||
311 | reloadPowerWarnSettings(); | 311 | reloadPowerWarnSettings(); |
312 | 312 | ||
313 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 313 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
314 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 314 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), |
315 | this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); | 315 | this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); |
316 | 316 | ||
317 | channel = new QCopChannel("QPE/Launcher", this ); | 317 | channel = new QCopChannel("QPE/Launcher", this ); |
318 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 318 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), |
319 | this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); | 319 | this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); |
320 | 320 | ||
321 | m_screensaver = new OpieScreenSaver(); | 321 | m_screensaver = new OpieScreenSaver(); |
322 | m_screensaver->setInterval( -1 ); | 322 | m_screensaver->setInterval( -1 ); |
323 | QWSServer::setScreenSaver( m_screensaver ); | 323 | QWSServer::setScreenSaver( m_screensaver ); |
324 | 324 | ||
325 | connect( qApp, SIGNAL( volumeChanged(bool) ), | 325 | connect( qApp, SIGNAL( volumeChanged(bool) ), |
326 | this, SLOT( rereadVolumes() ) ); | 326 | this, SLOT( rereadVolumes() ) ); |
327 | 327 | ||
328 | 328 | ||
329 | /* ### PluginLoader libqtopia SafeMode */ | 329 | /* ### PluginLoader libqtopia SafeMode */ |
330 | #if 0 | 330 | #if 0 |
331 | if ( PluginLoader::inSafeMode() ) | 331 | if ( PluginLoader::inSafeMode() ) |
332 | QTimer::singleShot(500, this, SLOT(showSafeMode()) ); | 332 | QTimer::singleShot(500, this, SLOT(showSafeMode()) ); |
333 | QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); | 333 | QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); |
334 | #endif | 334 | #endif |
335 | 335 | ||
336 | kf = new KeyFilter(this); | 336 | kf = new KeyFilter(this); |
337 | 337 | ||
338 | connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); | 338 | connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); |
339 | connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); | 339 | connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); |
340 | connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); | 340 | connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); |
341 | connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); | 341 | connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); |
342 | connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); | 342 | connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); |
343 | connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); | 343 | connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); |
344 | connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), | 344 | connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), |
345 | this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); | 345 | this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); |
346 | 346 | ||
347 | 347 | ||
348 | connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); | 348 | connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); |
349 | 349 | ||
350 | connect( this, SIGNAL(power() ), | 350 | connect( this, SIGNAL(power() ), |
351 | SLOT(togglePower() ) ); | 351 | SLOT(togglePower() ) ); |
352 | 352 | ||
353 | rereadVolumes(); | 353 | rereadVolumes(); |
354 | 354 | ||
355 | serverApp = this; | 355 | serverApp = this; |
356 | 356 | ||
357 | apmTimeout(); | 357 | apmTimeout(); |
358 | grabKeyboard(); | 358 | grabKeyboard(); |
359 | 359 | ||
360 | /* make sure the event filter is installed */ | 360 | /* make sure the event filter is installed */ /* std::limits<short>::max() when you've stdc++ */ |
361 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 ); | 361 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( SHRT_MAX ); |
362 | Q_CONST_UNUSED( but ) | 362 | Q_CONST_UNUSED( but ) |
363 | } | 363 | } |
364 | 364 | ||
365 | 365 | ||
366 | ServerApplication::~ServerApplication() | 366 | ServerApplication::~ServerApplication() |
367 | { | 367 | { |
368 | ungrabKeyboard(); | 368 | ungrabKeyboard(); |
369 | 369 | ||
370 | delete pa; | 370 | delete pa; |
371 | delete m_ps; | 371 | delete m_ps; |
372 | delete m_ps_last; | 372 | delete m_ps_last; |
373 | } | 373 | } |
374 | 374 | ||
375 | void ServerApplication::apmTimeout() | 375 | void ServerApplication::apmTimeout() |
376 | { | 376 | { |
377 | serverApp-> checkMemory( ); // in case no events are generated | 377 | serverApp-> checkMemory( ); // in case no events are generated |
378 | *m_ps_last = *m_ps; | 378 | *m_ps_last = *m_ps; |
379 | *m_ps = PowerStatusManager::readStatus(); | 379 | *m_ps = PowerStatusManager::readStatus(); |
380 | 380 | ||
381 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) | 381 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) |
382 | m_screensaver-> powerStatusChanged( *m_ps ); | 382 | m_screensaver-> powerStatusChanged( *m_ps ); |
383 | 383 | ||
384 | if ( m_ps->acStatus() == PowerStatus::Online ) { | 384 | if ( m_ps->acStatus() == PowerStatus::Online ) { |
385 | return; | 385 | return; |
386 | } | 386 | } |
387 | 387 | ||
388 | int bat = m_ps-> batteryPercentRemaining(); | 388 | int bat = m_ps-> batteryPercentRemaining(); |
389 | 389 | ||
390 | if ( bat < m_ps_last-> batteryPercentRemaining() ) { | 390 | if ( bat < m_ps_last-> batteryPercentRemaining() ) { |
391 | if ( bat <= m_powerCritical ) { | 391 | if ( bat <= m_powerCritical ) { |
392 | QMessageBox battlow( | 392 | QMessageBox battlow( |
393 | tr("WARNING"), | 393 | tr("WARNING"), |
394 | tr("<p>The battery level is critical!" | 394 | tr("<p>The battery level is critical!" |
395 | "<p>Keep power off until AC is restored"), | 395 | "<p>Keep power off until AC is restored"), |
396 | QMessageBox::Warning, | 396 | QMessageBox::Warning, |
397 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 397 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
398 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 398 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
399 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 399 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
400 | battlow.exec(); | 400 | battlow.exec(); |
401 | } else if ( bat <= m_powerVeryLow ) | 401 | } else if ( bat <= m_powerVeryLow ) |
402 | pa->alert( tr( "The battery is running very low. "), 2 ); | 402 | pa->alert( tr( "The battery is running very low. "), 2 ); |
403 | } | 403 | } |
404 | 404 | ||
405 | if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { | 405 | if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { |
406 | QMessageBox battlow( | 406 | QMessageBox battlow( |
407 | tr("WARNING"), | 407 | tr("WARNING"), |
408 | tr("<p>The Back-up battery is very low" | 408 | tr("<p>The Back-up battery is very low" |
409 | "<p>Please charge the back-up battery"), | 409 | "<p>Please charge the back-up battery"), |
410 | QMessageBox::Warning, | 410 | QMessageBox::Warning, |
411 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 411 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
412 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 412 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
413 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 413 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
414 | battlow.exec(); | 414 | battlow.exec(); |
415 | } | 415 | } |
416 | } | 416 | } |
417 | 417 | ||
418 | void ServerApplication::systemMessage( const QCString& msg, | 418 | void ServerApplication::systemMessage( const QCString& msg, |
419 | const QByteArray& data ) | 419 | const QByteArray& data ) |
420 | { | 420 | { |
421 | QDataStream stream ( data, IO_ReadOnly ); | 421 | QDataStream stream ( data, IO_ReadOnly ); |
422 | 422 | ||
423 | if ( msg == "setScreenSaverInterval(int)" ) { | 423 | if ( msg == "setScreenSaverInterval(int)" ) { |
424 | int time; | 424 | int time; |
425 | stream >> time; | 425 | stream >> time; |
426 | m_screensaver-> setInterval( time ); | 426 | m_screensaver-> setInterval( time ); |
427 | } | 427 | } |
428 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 428 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
429 | int t1, t2, t3; | 429 | int t1, t2, t3; |
430 | stream >> t1 >> t2 >> t3; | 430 | stream >> t1 >> t2 >> t3; |
431 | m_screensaver-> setIntervals( t1, t2, t3 ); | 431 | m_screensaver-> setIntervals( t1, t2, t3 ); |
432 | } | 432 | } |
433 | else if ( msg == "setBacklight(int)" ) { | 433 | else if ( msg == "setBacklight(int)" ) { |
434 | int bright; | 434 | int bright; |
435 | stream >> bright; | 435 | stream >> bright; |
436 | m_screensaver-> setBacklight( bright ); | 436 | m_screensaver-> setBacklight( bright ); |
437 | } | 437 | } |
438 | else if ( msg == "setScreenSaverMode(int)" ) { | 438 | else if ( msg == "setScreenSaverMode(int)" ) { |
439 | int mode; | 439 | int mode; |
440 | stream >> mode; | 440 | stream >> mode; |
441 | m_screensaver-> setMode ( mode ); | 441 | m_screensaver-> setMode ( mode ); |
442 | } | 442 | } |
443 | else if ( msg == "reloadPowerWarnSettings()" ) { | 443 | else if ( msg == "reloadPowerWarnSettings()" ) { |
444 | reloadPowerWarnSettings(); | 444 | reloadPowerWarnSettings(); |
445 | } | 445 | } |
446 | else if ( msg == "setDisplayState(int)" ) { | 446 | else if ( msg == "setDisplayState(int)" ) { |
447 | int state; | 447 | int state; |
448 | stream >> state; | 448 | stream >> state; |
449 | m_screensaver-> setDisplayState ( state != 0 ); | 449 | m_screensaver-> setDisplayState ( state != 0 ); |
450 | } | 450 | } |
451 | else if ( msg == "suspend()" ) { | 451 | else if ( msg == "suspend()" ) { |
452 | emit power(); | 452 | emit power(); |
453 | } | 453 | } |
454 | else if ( msg == "sendBusinessCard()" ) { | 454 | else if ( msg == "sendBusinessCard()" ) { |
455 | QString card = ::getenv ( "HOME" ); | 455 | QString card = ::getenv ( "HOME" ); |
456 | card += "/Applications/addressbook/businesscard.vcf"; | 456 | card += "/Applications/addressbook/businesscard.vcf"; |
457 | 457 | ||
458 | if ( QFile::exists( card ) ) { | 458 | if ( QFile::exists( card ) ) { |
459 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); | 459 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); |
460 | QString mimetype = "text/x-vCard"; | 460 | QString mimetype = "text/x-vCard"; |
461 | e << tr( "business card" ) << card << mimetype; | 461 | e << tr( "business card" ) << card << mimetype; |
462 | } | 462 | } |
463 | } | 463 | } |
464 | } | 464 | } |
465 | 465 | ||
466 | void ServerApplication::reloadPowerWarnSettings ( ) | 466 | void ServerApplication::reloadPowerWarnSettings ( ) |
467 | { | 467 | { |
468 | Config cfg ( "apm" ); | 468 | Config cfg ( "apm" ); |
469 | cfg. setGroup ( "Warnings" ); | 469 | cfg. setGroup ( "Warnings" ); |
470 | 470 | ||
471 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); | 471 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); |
472 | 472 | ||
473 | m_apm_timer-> stop ( ); | 473 | m_apm_timer-> stop ( ); |
474 | if ( iv ) | 474 | if ( iv ) |
475 | m_apm_timer-> start ( iv ); | 475 | m_apm_timer-> start ( iv ); |
476 | 476 | ||
477 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); | 477 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); |
478 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); | 478 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); |
479 | } | 479 | } |
480 | 480 | ||
481 | void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) | 481 | void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) |
482 | { | 482 | { |
483 | QDataStream stream ( data, IO_ReadOnly ); | 483 | QDataStream stream ( data, IO_ReadOnly ); |
484 | 484 | ||
485 | if ( msg == "deviceButton(int,int,int)" ) { | 485 | if ( msg == "deviceButton(int,int,int)" ) { |
486 | int keycode, press, autoRepeat; | 486 | int keycode, press, autoRepeat; |
487 | stream >> keycode >> press >> autoRepeat; | 487 | stream >> keycode >> press >> autoRepeat; |
488 | 488 | ||
489 | kf->checkButtonAction ( true, keycode, press, autoRepeat ); | 489 | kf->checkButtonAction ( true, keycode, press, autoRepeat ); |
490 | } | 490 | } |
491 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { | 491 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { |
492 | int k; | 492 | int k; |
493 | QCString c, m; | 493 | QCString c, m; |
494 | stream >> k >> c >> m; | 494 | stream >> k >> c >> m; |
495 | 495 | ||
496 | kf -> registerKey( QCopKeyRegister(k, c, m) ); | 496 | kf -> registerKey( QCopKeyRegister(k, c, m) ); |
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | bool ServerApplication::screenLocked() | 501 | bool ServerApplication::screenLocked() |
502 | { | 502 | { |
503 | return loggedin == 0; | 503 | return loggedin == 0; |
504 | } | 504 | } |
505 | 505 | ||
506 | void ServerApplication::login(bool at_poweron) | 506 | void ServerApplication::login(bool at_poweron) |
507 | { | 507 | { |
508 | if ( !loggedin ) { | 508 | if ( !loggedin ) { |
509 | Global::terminateBuiltin("calibrate"); // No tr | 509 | Global::terminateBuiltin("calibrate"); // No tr |
510 | Opie::Security::MultiauthPassword::authenticate(at_poweron); | 510 | Opie::Security::MultiauthPassword::authenticate(at_poweron); |
511 | loggedin=1; | 511 | loggedin=1; |
512 | #ifndef QT_NO_COP | 512 | #ifndef QT_NO_COP |
513 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 513 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
514 | #endif | 514 | #endif |
515 | } | 515 | } |
516 | } | 516 | } |
517 | 517 | ||
518 | #if defined(QPE_HAVE_TOGGLELIGHT) | 518 | #if defined(QPE_HAVE_TOGGLELIGHT) |
519 | #include <qtopia/config.h> | 519 | #include <qtopia/config.h> |
520 | 520 | ||
521 | #include <sys/ioctl.h> | 521 | #include <sys/ioctl.h> |
522 | #include <sys/types.h> | 522 | #include <sys/types.h> |
523 | #include <fcntl.h> | 523 | #include <fcntl.h> |
524 | #include <unistd.h> | 524 | #include <unistd.h> |
525 | #include <errno.h> | 525 | #include <errno.h> |
526 | #include <linux/ioctl.h> | 526 | #include <linux/ioctl.h> |
527 | #include <time.h> | 527 | #include <time.h> |
528 | #endif | 528 | #endif |
529 | 529 | ||
530 | namespace { | 530 | namespace { |
531 | void execAutoStart(const QDateTime& suspendTime ) { | 531 | void execAutoStart(const QDateTime& suspendTime ) { |
532 | QString appName; | 532 | QString appName; |
533 | int delay; | 533 | int delay; |
534 | QDateTime now = QDateTime::currentDateTime(); | 534 | QDateTime now = QDateTime::currentDateTime(); |
535 | 535 | ||
536 | Config cfg( "autostart" ); | 536 | Config cfg( "autostart" ); |
537 | cfg.setGroup( "AutoStart" ); | 537 | cfg.setGroup( "AutoStart" ); |
538 | appName = cfg.readEntry( "Apps", "" ); | 538 | appName = cfg.readEntry( "Apps", "" ); |
539 | delay = cfg.readNumEntry( "Delay", 0 ); | 539 | delay = cfg.readNumEntry( "Delay", 0 ); |
540 | 540 | ||
541 | // If the time between suspend and resume was longer then the | 541 | // If the time between suspend and resume was longer then the |
542 | // value saved as delay, start the app | 542 | // value saved as delay, start the app |
543 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | 543 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { |
544 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 544 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
545 | e << QString( appName ); | 545 | e << QString( appName ); |
546 | } | 546 | } |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | 550 | ||
551 | void ServerApplication::togglePower() | 551 | void ServerApplication::togglePower() |
552 | { | 552 | { |
553 | static bool excllock = false; | 553 | static bool excllock = false; |
554 | 554 | ||
555 | if ( excllock ) | 555 | if ( excllock ) |
556 | return ; | 556 | return ; |
557 | 557 | ||
558 | excllock = true; | 558 | excllock = true; |
559 | 559 | ||
560 | bool wasloggedin = loggedin; | 560 | bool wasloggedin = loggedin; |
561 | loggedin = 0; | 561 | loggedin = 0; |
562 | m_suspendTime = QDateTime::currentDateTime(); | 562 | m_suspendTime = QDateTime::currentDateTime(); |
563 | 563 | ||
564 | #ifdef QWS | 564 | #ifdef QWS |
565 | if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) { | 565 | if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) { |
566 | // Should use a big black window instead. | 566 | // Should use a big black window instead. |
567 | // But this would not show up fast enough | 567 | // But this would not show up fast enough |
568 | QGfx *g = qt_screen-> screenGfx ( ); | 568 | QGfx *g = qt_screen-> screenGfx ( ); |
569 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | 569 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); |
570 | delete g; | 570 | delete g; |
571 | } | 571 | } |
572 | #endif | 572 | #endif |
573 | 573 | ||
574 | ODevice::inst ( )-> suspend ( ); | 574 | ODevice::inst ( )-> suspend ( ); |
575 | 575 | ||
576 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call | 576 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call |
577 | QWSServer::screenSaverActivate ( false ); | 577 | QWSServer::screenSaverActivate ( false ); |
578 | 578 | ||
579 | { | 579 | { |
580 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | 580 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep |
581 | } | 581 | } |
582 | 582 | ||
583 | if ( wasloggedin ) | 583 | if ( wasloggedin ) |
584 | login ( true ); | 584 | login ( true ); |
585 | 585 | ||
586 | execAutoStart(m_suspendTime); | 586 | execAutoStart(m_suspendTime); |
587 | //qcopBridge->closeOpenConnections(); | 587 | //qcopBridge->closeOpenConnections(); |
588 | 588 | ||
589 | excllock = false; | 589 | excllock = false; |
590 | } | 590 | } |
591 | 591 | ||
592 | void ServerApplication::toggleLight() | 592 | void ServerApplication::toggleLight() |
593 | { | 593 | { |
594 | #ifndef QT_NO_COP | 594 | #ifndef QT_NO_COP |
595 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 595 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
596 | e << -2; // toggle | 596 | e << -2; // toggle |
597 | #endif | 597 | #endif |
598 | } | 598 | } |
599 | 599 | ||
600 | 600 | ||
601 | /* | 601 | /* |
602 | * We still listen to key events but handle them in | 602 | * We still listen to key events but handle them in |
603 | * a special class | 603 | * a special class |
604 | */ | 604 | */ |
605 | 605 | ||
606 | bool ServerApplication::eventFilter( QObject *o, QEvent *e) { | 606 | bool ServerApplication::eventFilter( QObject *o, QEvent *e) { |
607 | if ( e->type() != QEvent::KeyPress && | 607 | if ( e->type() != QEvent::KeyPress && |
608 | e->type() != QEvent::KeyRelease ) | 608 | e->type() != QEvent::KeyRelease ) |
609 | return QPEApplication::eventFilter( o, e ); | 609 | return QPEApplication::eventFilter( o, e ); |
610 | 610 | ||
611 | QKeyEvent *ke = static_cast<QKeyEvent*>( e ); | 611 | QKeyEvent *ke = static_cast<QKeyEvent*>( e ); |
612 | if ( kf->checkButtonAction( true, ke->key(), | 612 | if ( kf->checkButtonAction( true, ke->key(), |
613 | e->type() == QEvent::KeyPress, | 613 | e->type() == QEvent::KeyPress, |
614 | ke-> isAutoRepeat() )) | 614 | ke-> isAutoRepeat() )) |
615 | return true; | 615 | return true; |
616 | 616 | ||
617 | return QPEApplication::eventFilter( o, e ); | 617 | return QPEApplication::eventFilter( o, e ); |
618 | 618 | ||
619 | } | 619 | } |
620 | 620 | ||
621 | #ifdef Q_WS_QWS | 621 | #ifdef Q_WS_QWS |
622 | bool ServerApplication::qwsEventFilter( QWSEvent *e ) | 622 | bool ServerApplication::qwsEventFilter( QWSEvent *e ) |
623 | { | 623 | { |
624 | checkMemory(); | 624 | checkMemory(); |
625 | 625 | ||
626 | if ( e->type == QWSEvent::Mouse ) { | 626 | if ( e->type == QWSEvent::Mouse ) { |
627 | QWSMouseEvent *me = (QWSMouseEvent *)e; | 627 | QWSMouseEvent *me = (QWSMouseEvent *)e; |
628 | static bool up = TRUE; | 628 | static bool up = TRUE; |
629 | if ( me->simpleData.state&LeftButton ) { | 629 | if ( me->simpleData.state&LeftButton ) { |
630 | if ( up ) { | 630 | if ( up ) { |
631 | up = FALSE; | 631 | up = FALSE; |
632 | screenClick(TRUE); | 632 | screenClick(TRUE); |
633 | } | 633 | } |
634 | } else if ( !up ) { | 634 | } else if ( !up ) { |
635 | up = TRUE; | 635 | up = TRUE; |
636 | screenClick(FALSE); | 636 | screenClick(FALSE); |
637 | } | 637 | } |
638 | } else | 638 | } else |
639 | if ( e->type == QWSEvent::Key ) { | 639 | if ( e->type == QWSEvent::Key ) { |
640 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); | 640 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); |
641 | if ( kf->checkButtonAction( false, | 641 | if ( kf->checkButtonAction( false, |
642 | ke-> simpleData.keycode, | 642 | ke-> simpleData.keycode, |
643 | ke-> simpleData.is_press, | 643 | ke-> simpleData.is_press, |
644 | ke-> simpleData.is_auto_repeat ) ) | 644 | ke-> simpleData.is_auto_repeat ) ) |
645 | return true; | 645 | return true; |
646 | } | 646 | } |
647 | 647 | ||
648 | return QPEApplication::qwsEventFilter( e ); | 648 | return QPEApplication::qwsEventFilter( e ); |
649 | } | 649 | } |
650 | #endif | 650 | #endif |
651 | 651 | ||
652 | 652 | ||
653 | /* ### FIXME libqtopia Plugin Safe Mode */ | 653 | /* ### FIXME libqtopia Plugin Safe Mode */ |
654 | 654 | ||
655 | void ServerApplication::showSafeMode() | 655 | void ServerApplication::showSafeMode() |
656 | { | 656 | { |
657 | #if 0 | 657 | #if 0 |
658 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " | 658 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " |
659 | "and the system is now in Safe Mode. " | 659 | "and the system is now in Safe Mode. " |
660 | "Plugins are not loaded in Safe Mode. " | 660 | "Plugins are not loaded in Safe Mode. " |
661 | "You can use the Plugin Manager to " | 661 | "You can use the Plugin Manager to " |
662 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) | 662 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) |
663 | { | 663 | { |
664 | Global::execute( "pluginmanager" ); | 664 | Global::execute( "pluginmanager" ); |
665 | } | 665 | } |
666 | #endif | 666 | #endif |
667 | } | 667 | } |
668 | 668 | ||
669 | void ServerApplication::clearSafeMode() | 669 | void ServerApplication::clearSafeMode() |
670 | { | 670 | { |
671 | #if 0 | 671 | #if 0 |
672 | // If we've been running OK for a while then we won't bother going into | 672 | // If we've been running OK for a while then we won't bother going into |
673 | // safe mode immediately on the next crash. | 673 | // safe mode immediately on the next crash. |
674 | Config cfg( "PluginLoader" ); | 674 | Config cfg( "PluginLoader" ); |
675 | cfg.setGroup( "Global" ); | 675 | cfg.setGroup( "Global" ); |
676 | QString mode = cfg.readEntry( "Mode", "Normal" ); | 676 | QString mode = cfg.readEntry( "Mode", "Normal" ); |
677 | if ( mode == "MaybeSafe" ) { | 677 | if ( mode == "MaybeSafe" ) { |
678 | cfg.writeEntry( "Mode", "Normal" ); | 678 | cfg.writeEntry( "Mode", "Normal" ); |
679 | } | 679 | } |
680 | #endif | 680 | #endif |
681 | } | 681 | } |
682 | 682 | ||
683 | 683 | ||
684 | void ServerApplication::shutdown() | 684 | void ServerApplication::shutdown() |
685 | { | 685 | { |
686 | if ( type() != GuiServer ) | 686 | if ( type() != GuiServer ) |
687 | return; | 687 | return; |
688 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | 688 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); |
689 | connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), | 689 | connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), |
690 | this, SLOT(shutdown(ShutdownImpl::Type)) ); | 690 | this, SLOT(shutdown(ShutdownImpl::Type)) ); |
691 | QPEApplication::showWidget( sd ); | 691 | QPEApplication::showWidget( sd ); |
692 | } | 692 | } |
693 | 693 | ||
694 | void ServerApplication::shutdown( ShutdownImpl::Type t ) | 694 | void ServerApplication::shutdown( ShutdownImpl::Type t ) |
695 | { | 695 | { |
696 | char *opt = 0; | 696 | char *opt = 0; |
697 | 697 | ||
698 | switch ( t ) { | 698 | switch ( t ) { |
699 | case ShutdownImpl::ShutdownSystem: | 699 | case ShutdownImpl::ShutdownSystem: |
700 | opt = "-h"; | 700 | opt = "-h"; |
701 | // fall through | 701 | // fall through |
702 | case ShutdownImpl::RebootSystem: | 702 | case ShutdownImpl::RebootSystem: |
703 | if ( opt == 0 ) | 703 | if ( opt == 0 ) |
704 | opt = "-r"; | 704 | opt = "-r"; |
705 | 705 | ||
706 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) | 706 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) |
707 | perror("shutdown"); | 707 | perror("shutdown"); |
708 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); | 708 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); |
709 | 709 | ||
710 | break; | 710 | break; |
711 | case ShutdownImpl::RestartDesktop: | 711 | case ShutdownImpl::RestartDesktop: |
712 | restart(); | 712 | restart(); |
713 | break; | 713 | break; |
714 | case ShutdownImpl::TerminateDesktop: | 714 | case ShutdownImpl::TerminateDesktop: |
715 | prepareForTermination( FALSE ); | 715 | prepareForTermination( FALSE ); |
716 | 716 | ||
717 | // This is a workaround for a Qt bug | 717 | // This is a workaround for a Qt bug |
718 | // clipboard applet has to stop its poll timer, or Qt/E | 718 | // clipboard applet has to stop its poll timer, or Qt/E |
719 | // will hang on quit() right before it emits aboutToQuit() | 719 | // will hang on quit() right before it emits aboutToQuit() |
720 | emit aboutToQuit ( ); | 720 | emit aboutToQuit ( ); |
721 | 721 | ||
722 | quit(); | 722 | quit(); |
723 | break; | 723 | break; |
724 | } | 724 | } |
725 | } | 725 | } |
726 | 726 | ||
727 | void ServerApplication::restart() | 727 | void ServerApplication::restart() |
728 | { | 728 | { |
729 | if ( allowRestart ) { | 729 | if ( allowRestart ) { |
730 | 730 | ||
731 | /* | 731 | /* |
732 | * Applets and restart is a problem. Some applets delete | 732 | * Applets and restart is a problem. Some applets delete |
733 | * their widgets even if ownership gets transfered to the | 733 | * their widgets even if ownership gets transfered to the |
734 | * parent (Systray ) but deleting the applet may be unsafe | 734 | * parent (Systray ) but deleting the applet may be unsafe |
735 | * as well ( double deletion ). Some have topLevel widgets | 735 | * as well ( double deletion ). Some have topLevel widgets |
736 | * and when we dlclose and then delete the widget we will | 736 | * and when we dlclose and then delete the widget we will |
737 | * crash and an crash during restart is not nice | 737 | * crash and an crash during restart is not nice |
738 | */ | 738 | */ |
739 | #ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED | 739 | #ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED |
740 | /* same as above */ | 740 | /* same as above */ |
741 | emit aboutToQuit(); | 741 | emit aboutToQuit(); |
742 | prepareForTermination(TRUE); | 742 | prepareForTermination(TRUE); |
743 | doRestart = TRUE; | 743 | doRestart = TRUE; |
744 | quit(); | 744 | quit(); |
745 | #else | 745 | #else |
746 | prepareForTermination( true ); | 746 | prepareForTermination( true ); |
747 | for ( int fd = 3; fd < 100; fd++ ) | 747 | for ( int fd = 3; fd < 100; fd++ ) |
748 | close( fd ); | 748 | close( fd ); |
749 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); | 749 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); |
750 | exit( 1 ); | 750 | exit( 1 ); |
751 | #endif | 751 | #endif |
752 | } | 752 | } |
753 | } | 753 | } |
754 | 754 | ||
755 | void ServerApplication::rereadVolumes() | 755 | void ServerApplication::rereadVolumes() |
756 | { | 756 | { |
757 | Config cfg( "qpe" ); | 757 | Config cfg( "qpe" ); |
758 | cfg. setGroup ( "Volume" ); | 758 | cfg. setGroup ( "Volume" ); |
759 | 759 | ||
760 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); | 760 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); |
761 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); | 761 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); |
762 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); | 762 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); |
763 | } | 763 | } |
764 | 764 | ||
765 | 765 | ||
766 | void ServerApplication::checkMemory() | 766 | void ServerApplication::checkMemory() |
767 | { | 767 | { |
768 | #if defined(QPE_HAVE_MEMALERTER) | 768 | #if defined(QPE_HAVE_MEMALERTER) |
769 | static bool ignoreNormal=TRUE; | 769 | static bool ignoreNormal=TRUE; |
770 | static bool existingMessage=FALSE; | 770 | static bool existingMessage=FALSE; |
771 | 771 | ||
772 | if(existingMessage) | 772 | if(existingMessage) |
773 | return; // don't show a second message while still on first | 773 | return; // don't show a second message while still on first |
774 | 774 | ||
775 | existingMessage = TRUE; | 775 | existingMessage = TRUE; |
776 | switch ( memstate ) { | 776 | switch ( memstate ) { |
777 | case MemUnknown: | 777 | case MemUnknown: |
778 | break; | 778 | break; |
779 | case MemLow: | 779 | case MemLow: |
780 | memstate = MemUnknown; | 780 | memstate = MemUnknown; |
781 | if ( !recoverMemory() ) { | 781 | if ( !recoverMemory() ) { |
782 | QMessageBox::warning( 0 , tr("Memory Status"), | 782 | QMessageBox::warning( 0 , tr("Memory Status"), |
783 | tr("Memory Low\nPlease save data.") ); | 783 | tr("Memory Low\nPlease save data.") ); |
784 | ignoreNormal = FALSE; | 784 | ignoreNormal = FALSE; |
785 | } | 785 | } |
786 | break; | 786 | break; |
787 | case MemNormal: | 787 | case MemNormal: |
788 | memstate = MemUnknown; | 788 | memstate = MemUnknown; |
789 | if ( !ignoreNormal ) { | 789 | if ( !ignoreNormal ) { |
790 | ignoreNormal = TRUE; | 790 | ignoreNormal = TRUE; |
791 | QMessageBox::information ( 0 , tr("Memory Status"), | 791 | QMessageBox::information ( 0 , tr("Memory Status"), |
792 | "Memory OK" ); | 792 | "Memory OK" ); |
793 | } | 793 | } |
794 | break; | 794 | break; |
795 | case MemVeryLow: | 795 | case MemVeryLow: |
796 | memstate = MemUnknown; | 796 | memstate = MemUnknown; |
797 | QMessageBox::critical( 0 , tr("Memory Status"), | 797 | QMessageBox::critical( 0 , tr("Memory Status"), |
798 | tr("Critical Memory Shortage\n" | 798 | tr("Critical Memory Shortage\n" |
799 | "Please end this application\n" | 799 | "Please end this application\n" |
800 | "immediately.") ); | 800 | "immediately.") ); |
801 | recoverMemory(); | 801 | recoverMemory(); |
802 | } | 802 | } |
803 | existingMessage = FALSE; | 803 | existingMessage = FALSE; |
804 | #endif | 804 | #endif |
805 | } | 805 | } |
806 | 806 | ||
807 | bool ServerApplication::recoverMemory() | 807 | bool ServerApplication::recoverMemory() |
808 | { | 808 | { |
809 | return FALSE; | 809 | return FALSE; |
810 | } | 810 | } |
811 | 811 | ||
812 | void ServerApplication::keyClick(int , bool press, bool ) | 812 | void ServerApplication::keyClick(int , bool press, bool ) |
813 | { | 813 | { |
814 | if ( press && m_keyclick_sound ) | 814 | if ( press && m_keyclick_sound ) |
815 | ODevice::inst() -> playKeySound(); | 815 | ODevice::inst() -> playKeySound(); |
816 | 816 | ||
817 | } | 817 | } |
818 | 818 | ||
819 | void ServerApplication::screenClick(bool press) | 819 | void ServerApplication::screenClick(bool press) |
820 | { | 820 | { |
821 | if ( press && m_screentap_sound ) | 821 | if ( press && m_screentap_sound ) |
822 | ODevice::inst() -> playTouchSound(); | 822 | ODevice::inst() -> playTouchSound(); |
823 | } | 823 | } |
824 | 824 | ||
825 | void ServerApplication::soundAlarm() { | 825 | void ServerApplication::soundAlarm() { |
826 | if ( me ()->m_alarm_sound ) | 826 | if ( me ()->m_alarm_sound ) |
827 | ODevice::inst()->playAlarmSound(); | 827 | ODevice::inst()->playAlarmSound(); |
828 | } | 828 | } |
829 | 829 | ||
830 | ServerApplication *ServerApplication::me ( ) | 830 | ServerApplication *ServerApplication::me ( ) |
831 | { | 831 | { |
832 | return static_cast<ServerApplication*>( qApp ); | 832 | return static_cast<ServerApplication*>( qApp ); |
833 | } | 833 | } |
834 | 834 | ||
835 | bool ServerApplication::isStarting() | 835 | bool ServerApplication::isStarting() |
836 | { | 836 | { |
837 | return ms_is_starting; | 837 | return ms_is_starting; |
838 | } | 838 | } |
839 | 839 | ||
840 | int ServerApplication::exec() | 840 | int ServerApplication::exec() |
841 | { | 841 | { |
842 | ms_is_starting = true; | 842 | ms_is_starting = true; |
843 | odebug << "Serverapp - exec" << oendl; | 843 | odebug << "Serverapp - exec" << oendl; |
844 | return QPEApplication::exec(); | 844 | return QPEApplication::exec(); |
845 | } | 845 | } |
846 | 846 | ||
847 | #include "serverapp.moc" | 847 | #include "serverapp.moc" |