author | sandman <sandman> | 2002-09-30 10:12:36 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-30 10:12:36 (UTC) |
commit | ece83520d6bf5c481275a3d4a8e792749119fa08 (patch) (unidiff) | |
tree | eb1c8bfdc013a3aca46c4feaa2ff50e38e5d632b | |
parent | a999acbcd1b8bc1715f2ad2dda6acedf423b89ea (diff) | |
download | opie-ece83520d6bf5c481275a3d4a8e792749119fa08.zip opie-ece83520d6bf5c481275a3d4a8e792749119fa08.tar.gz opie-ece83520d6bf5c481275a3d4a8e792749119fa08.tar.bz2 |
Optimizations for the new busy indicator:
- QPixmaps are buffered now
- real fix for the startTimer 100% cpu-load bug (was a typo)
-rw-r--r-- | core/launcher/launcherview.cpp | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index dbcb0d7..5daaeff 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp | |||
@@ -1,893 +1,894 @@ | |||
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 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qpe/qpedebug.h> | 25 | #include <qpe/qpedebug.h> |
26 | #include <qpe/categories.h> | 26 | #include <qpe/categories.h> |
27 | #include <qpe/categoryselect.h> | 27 | #include <qpe/categoryselect.h> |
28 | #include <qpe/menubutton.h> | 28 | #include <qpe/menubutton.h> |
29 | #include <qpe/mimetype.h> | 29 | #include <qpe/mimetype.h> |
30 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
31 | #include <qpe/qpetoolbar.h> | 31 | #include <qpe/qpetoolbar.h> |
32 | //#include <qtopia/private/palmtoprecord.h> | 32 | //#include <qtopia/private/palmtoprecord.h> |
33 | 33 | ||
34 | #include <qtimer.h> | 34 | #include <qtimer.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qdict.h> | 36 | #include <qdict.h> |
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qfileinfo.h> | 38 | #include <qfileinfo.h> |
39 | #include <qhbox.h> | 39 | #include <qhbox.h> |
40 | #include <qiconview.h> | 40 | #include <qiconview.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | #include <qregexp.h> | 42 | #include <qregexp.h> |
43 | #include <qtoolbutton.h> | 43 | #include <qtoolbutton.h> |
44 | #include <qimage.h> | 44 | #include <qimage.h> |
45 | 45 | ||
46 | 46 | ||
47 | class BgPixmap | 47 | class BgPixmap |
48 | { | 48 | { |
49 | public: | 49 | public: |
50 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} | 50 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} |
51 | QPixmap pm; | 51 | QPixmap pm; |
52 | int ref; | 52 | int ref; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | static QMap<QString,BgPixmap*> *bgCache = 0; | 55 | static QMap<QString,BgPixmap*> *bgCache = 0; |
56 | 56 | ||
57 | class LauncherIconView : public QIconView { | 57 | class LauncherIconView : public QIconView { |
58 | public: | 58 | public: |
59 | LauncherIconView( QWidget* parent, const char* name=0 ) : | 59 | LauncherIconView( QWidget* parent, const char* name=0 ) : |
60 | QIconView(parent,name), | 60 | QIconView(parent,name), |
61 | tf(""), | 61 | tf(""), |
62 | cf(0), | 62 | cf(0), |
63 | bsy(0), | 63 | bsy(0), |
64 | bigIcns(TRUE), | 64 | bigIcns(TRUE), |
65 | bgColor(white) | 65 | bgColor(white) |
66 | { | 66 | { |
67 | sortmeth = Name; | 67 | sortmeth = Name; |
68 | hidden.setAutoDelete(TRUE); | 68 | hidden.setAutoDelete(TRUE); |
69 | ike = FALSE; | 69 | ike = FALSE; |
70 | busytimer = 0; | 70 | busytimer = 0; |
71 | calculateGrid( Bottom ); | 71 | calculateGrid( Bottom ); |
72 | } | 72 | } |
73 | 73 | ||
74 | ~LauncherIconView() | 74 | ~LauncherIconView() |
75 | { | 75 | { |
76 | #if 0 // debuggery | 76 | #if 0 // debuggery |
77 | QListIterator<AppLnk> it(hidden); | 77 | QListIterator<AppLnk> it(hidden); |
78 | AppLnk* l; | 78 | AppLnk* l; |
79 | while ((l=it.current())) { | 79 | while ((l=it.current())) { |
80 | ++it; | 80 | ++it; |
81 | //qDebug("%p: hidden (should remove)",l); | 81 | //qDebug("%p: hidden (should remove)",l); |
82 | } | 82 | } |
83 | #endif | 83 | #endif |
84 | } | 84 | } |
85 | 85 | ||
86 | QPixmap* busyPixmap() const { return (QPixmap*)&bpm; } | 86 | QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; } |
87 | QIconViewItem* busyItem() const { return bsy; } | 87 | QIconViewItem* busyItem() const { return bsy; } |
88 | void setBigIcons( bool bi ) { bigIcns = bi; } | 88 | void setBigIcons( bool bi ) { bigIcns = bi; } |
89 | 89 | ||
90 | void updateCategoriesAndMimeTypes(); | 90 | void updateCategoriesAndMimeTypes(); |
91 | 91 | ||
92 | void doAutoScroll() | 92 | void doAutoScroll() |
93 | { | 93 | { |
94 | // We don't want rubberbanding (yet) | 94 | // We don't want rubberbanding (yet) |
95 | } | 95 | } |
96 | 96 | ||
97 | void setBusy(bool on) | 97 | void setBusy(bool on) |
98 | { | 98 | { |
99 | QIconViewItem *c = on ? currentItem() : 0; | 99 | QIconViewItem *c = on ? currentItem() : 0; |
100 | if ( bsy != c ) { | 100 | if ( bsy != c ) { |
101 | if ( bsy ) | 101 | if ( bsy ) |
102 | bsy-> repaint ( ); | 102 | bsy-> repaint ( ); |
103 | bsy = c; | 103 | bsy = c; |
104 | 104 | ||
105 | if ( bsy ) { | 105 | if ( bsy ) { |
106 | busystate = 5; | ||
107 | for ( int i = 0; i <= 5; i++ ) | ||
108 | bpm [i] = QPixmap ( ); | ||
109 | timerEvent ( 0 ); | ||
106 | busytimer = startTimer ( 150 ); | 110 | busytimer = startTimer ( 150 ); |
107 | busystate = 50; | ||
108 | // not sure what this startTimer is for, maybe i am just to tired. But | ||
109 | // currently that causes 100% cpuload on app launch | ||
110 | //startTimer ( 0 ); | ||
111 | } | 111 | } |
112 | else | 112 | else |
113 | killTimer ( busytimer ); | 113 | killTimer ( busytimer ); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | virtual void timerEvent ( QTimerEvent *te ) | 117 | virtual void timerEvent ( QTimerEvent *te ) |
118 | { | 118 | { |
119 | if ( !te || ( te-> timerId ( ) == busytimer )) { | 119 | if ( !te || ( te-> timerId ( ) == busytimer )) { |
120 | if ( bsy ) { | 120 | if ( bsy ) { |
121 | QPixmap *src = bsy-> QIconViewItem::pixmap(); | 121 | if ( bpm [::abs(busystate)]. isNull ( )) { |
122 | QImage img = src->convertToImage(); | 122 | QPixmap *src = bsy-> QIconViewItem::pixmap(); |
123 | QRgb* rgb; | 123 | QImage img = src->convertToImage(); |
124 | int count; | 124 | QRgb* rgb; |
125 | if ( img.depth() == 32 ) { | 125 | int count; |
126 | rgb = (QRgb*)img.bits(); | 126 | if ( img.depth() == 32 ) { |
127 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); | 127 | rgb = (QRgb*)img.bits(); |
128 | } else { | 128 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); |
129 | rgb = img.colorTable(); | 129 | } else { |
130 | count = img.numColors(); | 130 | rgb = img.colorTable(); |
131 | } | 131 | count = img.numColors(); |
132 | int rc, gc, bc; | 132 | } |
133 | int bs = ::abs ( busystate ) + 25; | 133 | int rc, gc, bc; |
134 | colorGroup().highlight().rgb( &rc, &gc, &bc ); | 134 | int bs = ::abs ( busystate * 10 ) + 25; |
135 | rc = rc * bs / 100; | 135 | colorGroup().highlight().rgb( &rc, &gc, &bc ); |
136 | gc = gc * bs / 100; | 136 | rc = rc * bs / 100; |
137 | bc = bc * bs / 100; | 137 | gc = gc * bs / 100; |
138 | bc = bc * bs / 100; | ||
138 | 139 | ||
139 | for ( int r = 0; r < count; r++, rgb++ ) { | 140 | for ( int r = 0; r < count; r++, rgb++ ) { |
140 | int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; | 141 | int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; |
141 | int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; | 142 | int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; |
142 | int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; | 143 | int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; |
143 | int ai = qAlpha ( *rgb ); | 144 | int ai = qAlpha ( *rgb ); |
144 | *rgb = qRgba ( ri, gi, bi, ai ); | 145 | *rgb = qRgba ( ri, gi, bi, ai ); |
146 | } | ||
147 | |||
148 | bpm [::abs(busystate)].convertFromImage( img ); | ||
145 | } | 149 | } |
146 | |||
147 | bpm.convertFromImage( img ); | ||
148 | |||
149 | bsy-> repaint ( ); | 150 | bsy-> repaint ( ); |
150 | 151 | ||
151 | busystate += 10; | 152 | busystate++; |
152 | if ( busystate > 50 ) | 153 | if ( busystate > 5 ) |
153 | busystate = -40; | 154 | busystate = -4; |
154 | } | 155 | } |
155 | } | 156 | } |
156 | } | 157 | } |
157 | 158 | ||
158 | bool inKeyEvent() const { return ike; } | 159 | bool inKeyEvent() const { return ike; } |
159 | void keyPressEvent(QKeyEvent* e) | 160 | void keyPressEvent(QKeyEvent* e) |
160 | { | 161 | { |
161 | ike = TRUE; | 162 | ike = TRUE; |
162 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) | 163 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) |
163 | returnPressed(currentItem()); | 164 | returnPressed(currentItem()); |
164 | QIconView::keyPressEvent(e); | 165 | QIconView::keyPressEvent(e); |
165 | ike = FALSE; | 166 | ike = FALSE; |
166 | } | 167 | } |
167 | 168 | ||
168 | void addItem(AppLnk* app, bool resort=TRUE); | 169 | void addItem(AppLnk* app, bool resort=TRUE); |
169 | bool removeLink(const QString& linkfile); | 170 | bool removeLink(const QString& linkfile); |
170 | 171 | ||
171 | QStringList mimeTypes() const; | 172 | QStringList mimeTypes() const; |
172 | QStringList categories() const; | 173 | QStringList categories() const; |
173 | 174 | ||
174 | void clear() | 175 | void clear() |
175 | { | 176 | { |
176 | mimes.clear(); | 177 | mimes.clear(); |
177 | cats.clear(); | 178 | cats.clear(); |
178 | QIconView::clear(); | 179 | QIconView::clear(); |
179 | hidden.clear(); | 180 | hidden.clear(); |
180 | } | 181 | } |
181 | 182 | ||
182 | void addCatsAndMimes(AppLnk* app) | 183 | void addCatsAndMimes(AppLnk* app) |
183 | { | 184 | { |
184 | // QStringList c = app->categories(); | 185 | // QStringList c = app->categories(); |
185 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { | 186 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { |
186 | // cats.replace(*cit,(void*)1); | 187 | // cats.replace(*cit,(void*)1); |
187 | // } | 188 | // } |
188 | QString maj=app->type(); | 189 | QString maj=app->type(); |
189 | int sl=maj.find('/'); | 190 | int sl=maj.find('/'); |
190 | if (sl>=0) { | 191 | if (sl>=0) { |
191 | QString k; | 192 | QString k; |
192 | k = maj.left(12) == "application/" ? maj : maj.left(sl); | 193 | k = maj.left(12) == "application/" ? maj : maj.left(sl); |
193 | mimes.replace(k,(void*)1); | 194 | mimes.replace(k,(void*)1); |
194 | } | 195 | } |
195 | } | 196 | } |
196 | 197 | ||
197 | void setBackgroundPixmap( const QPixmap &pm ) { | 198 | void setBackgroundPixmap( const QPixmap &pm ) { |
198 | bgPixmap = pm; | 199 | bgPixmap = pm; |
199 | } | 200 | } |
200 | 201 | ||
201 | void setBackgroundColor( const QColor &c ) { | 202 | void setBackgroundColor( const QColor &c ) { |
202 | bgColor = c; | 203 | bgColor = c; |
203 | } | 204 | } |
204 | 205 | ||
205 | void drawBackground( QPainter *p, const QRect &r ) | 206 | void drawBackground( QPainter *p, const QRect &r ) |
206 | { | 207 | { |
207 | if ( !bgPixmap.isNull() ) { | 208 | if ( !bgPixmap.isNull() ) { |
208 | p->drawTiledPixmap( r, bgPixmap, | 209 | p->drawTiledPixmap( r, bgPixmap, |
209 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), | 210 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), |
210 | (r.y() + contentsY()) % bgPixmap.height() ) ); | 211 | (r.y() + contentsY()) % bgPixmap.height() ) ); |
211 | } else { | 212 | } else { |
212 | p->fillRect( r, bgColor ); | 213 | p->fillRect( r, bgColor ); |
213 | } | 214 | } |
214 | } | 215 | } |
215 | 216 | ||
216 | void setItemTextPos( ItemTextPos pos ) | 217 | void setItemTextPos( ItemTextPos pos ) |
217 | { | 218 | { |
218 | calculateGrid( pos ); | 219 | calculateGrid( pos ); |
219 | QIconView::setItemTextPos( pos ); | 220 | QIconView::setItemTextPos( pos ); |
220 | } | 221 | } |
221 | 222 | ||
222 | void hideOrShowItems(bool resort); | 223 | void hideOrShowItems(bool resort); |
223 | 224 | ||
224 | void setTypeFilter(const QString& typefilter, bool resort) | 225 | void setTypeFilter(const QString& typefilter, bool resort) |
225 | { | 226 | { |
226 | tf = QRegExp(typefilter,FALSE,TRUE); | 227 | tf = QRegExp(typefilter,FALSE,TRUE); |
227 | hideOrShowItems(resort); | 228 | hideOrShowItems(resort); |
228 | } | 229 | } |
229 | 230 | ||
230 | void setCategoryFilter( int catfilter, bool resort ) | 231 | void setCategoryFilter( int catfilter, bool resort ) |
231 | { | 232 | { |
232 | Categories cat; | 233 | Categories cat; |
233 | cat.load( categoryFileName() ); | 234 | cat.load( categoryFileName() ); |
234 | QString str; | 235 | QString str; |
235 | if ( catfilter == -2 ) | 236 | if ( catfilter == -2 ) |
236 | cf = 0; | 237 | cf = 0; |
237 | else | 238 | else |
238 | cf = catfilter; | 239 | cf = catfilter; |
239 | hideOrShowItems(resort); | 240 | hideOrShowItems(resort); |
240 | } | 241 | } |
241 | 242 | ||
242 | enum SortMethod { Name, Date, Type }; | 243 | enum SortMethod { Name, Date, Type }; |
243 | 244 | ||
244 | void setSortMethod( SortMethod m ) | 245 | void setSortMethod( SortMethod m ) |
245 | { | 246 | { |
246 | if ( sortmeth != m ) { | 247 | if ( sortmeth != m ) { |
247 | sortmeth = m; | 248 | sortmeth = m; |
248 | sort(); | 249 | sort(); |
249 | } | 250 | } |
250 | } | 251 | } |
251 | 252 | ||
252 | int compare(const AppLnk* a, const AppLnk* b) | 253 | int compare(const AppLnk* a, const AppLnk* b) |
253 | { | 254 | { |
254 | switch (sortmeth) { | 255 | switch (sortmeth) { |
255 | case Name: | 256 | case Name: |
256 | return a->name().compare(b->name()); | 257 | return a->name().compare(b->name()); |
257 | case Date: { | 258 | case Date: { |
258 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); | 259 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); |
259 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); | 260 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); |
260 | return fa.lastModified().secsTo(fb.lastModified()); | 261 | return fa.lastModified().secsTo(fb.lastModified()); |
261 | } | 262 | } |
262 | case Type: | 263 | case Type: |
263 | return a->type().compare(b->type()); | 264 | return a->type().compare(b->type()); |
264 | } | 265 | } |
265 | return 0; | 266 | return 0; |
266 | } | 267 | } |
267 | 268 | ||
268 | QString getAllDocLinkInfo() const; | 269 | QString getAllDocLinkInfo() const; |
269 | 270 | ||
270 | protected: | 271 | protected: |
271 | 272 | ||
272 | void styleChange( QStyle &old ) | 273 | void styleChange( QStyle &old ) |
273 | { | 274 | { |
274 | QIconView::styleChange( old ); | 275 | QIconView::styleChange( old ); |
275 | calculateGrid( itemTextPos() ); | 276 | calculateGrid( itemTextPos() ); |
276 | } | 277 | } |
277 | 278 | ||
278 | void calculateGrid( ItemTextPos pos ) | 279 | void calculateGrid( ItemTextPos pos ) |
279 | { | 280 | { |
280 | int dw = QApplication::desktop()->width(); | 281 | int dw = QApplication::desktop()->width(); |
281 | int viewerWidth = dw-style().scrollBarExtent().width(); | 282 | int viewerWidth = dw-style().scrollBarExtent().width(); |
282 | if ( pos == Bottom ) { | 283 | if ( pos == Bottom ) { |
283 | int cols = 3; | 284 | int cols = 3; |
284 | if ( viewerWidth <= 200 ) | 285 | if ( viewerWidth <= 200 ) |
285 | cols = 2; | 286 | cols = 2; |
286 | else if ( viewerWidth >= 400 ) | 287 | else if ( viewerWidth >= 400 ) |
287 | cols = viewerWidth/96; | 288 | cols = viewerWidth/96; |
288 | setSpacing( 4 ); | 289 | setSpacing( 4 ); |
289 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 290 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
290 | setGridY( fontMetrics().height()*2+24 ); | 291 | setGridY( fontMetrics().height()*2+24 ); |
291 | } else { | 292 | } else { |
292 | int cols = 2; | 293 | int cols = 2; |
293 | if ( viewerWidth < 150 ) | 294 | if ( viewerWidth < 150 ) |
294 | cols = 1; | 295 | cols = 1; |
295 | else if ( viewerWidth >= 400 ) | 296 | else if ( viewerWidth >= 400 ) |
296 | cols = viewerWidth/150; | 297 | cols = viewerWidth/150; |
297 | setSpacing( 2 ); | 298 | setSpacing( 2 ); |
298 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 299 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
299 | setGridY( fontMetrics().height()+2 ); | 300 | setGridY( fontMetrics().height()+2 ); |
300 | } | 301 | } |
301 | } | 302 | } |
302 | 303 | ||
303 | private: | 304 | private: |
304 | QList<AppLnk> hidden; | 305 | QList<AppLnk> hidden; |
305 | QDict<void> mimes; | 306 | QDict<void> mimes; |
306 | QDict<void> cats; | 307 | QDict<void> cats; |
307 | SortMethod sortmeth; | 308 | SortMethod sortmeth; |
308 | QRegExp tf; | 309 | QRegExp tf; |
309 | int cf; | 310 | int cf; |
310 | QIconViewItem* bsy; | 311 | QIconViewItem* bsy; |
311 | bool ike; | 312 | bool ike; |
312 | bool bigIcns; | 313 | bool bigIcns; |
313 | QPixmap bgPixmap; | 314 | QPixmap bgPixmap; |
314 | QPixmap bpm; | 315 | QPixmap bpm [6]; |
315 | QColor bgColor; | 316 | QColor bgColor; |
316 | int busytimer; | 317 | int busytimer; |
317 | int busystate; | 318 | int busystate; |
318 | }; | 319 | }; |
319 | 320 | ||
320 | 321 | ||
321 | bool LauncherView::bsy=FALSE; | 322 | bool LauncherView::bsy=FALSE; |
322 | 323 | ||
323 | void LauncherView::setBusy(bool on) | 324 | void LauncherView::setBusy(bool on) |
324 | { | 325 | { |
325 | icons->setBusy(on); | 326 | icons->setBusy(on); |
326 | } | 327 | } |
327 | 328 | ||
328 | class LauncherItem : public QIconViewItem | 329 | class LauncherItem : public QIconViewItem |
329 | { | 330 | { |
330 | public: | 331 | public: |
331 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); | 332 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); |
332 | ~LauncherItem() | 333 | ~LauncherItem() |
333 | { | 334 | { |
334 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 335 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
335 | if ( liv->busyItem() == this ) | 336 | if ( liv->busyItem() == this ) |
336 | liv->setBusy(FALSE); | 337 | liv->setBusy(FALSE); |
337 | delete app; | 338 | delete app; |
338 | } | 339 | } |
339 | 340 | ||
340 | AppLnk* appLnk() const { return app; } | 341 | AppLnk* appLnk() const { return app; } |
341 | AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } | 342 | AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } |
342 | 343 | ||
343 | virtual int compare ( QIconViewItem * i ) const; | 344 | virtual int compare ( QIconViewItem * i ) const; |
344 | 345 | ||
345 | void paintItem( QPainter *p, const QColorGroup &cg ) | 346 | void paintItem( QPainter *p, const QColorGroup &cg ) |
346 | { | 347 | { |
347 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 348 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
348 | QBrush oldBrush( liv->itemTextBackground() ); | 349 | QBrush oldBrush( liv->itemTextBackground() ); |
349 | QColorGroup mycg( cg ); | 350 | QColorGroup mycg( cg ); |
350 | if ( liv->currentItem() == this ) { | 351 | if ( liv->currentItem() == this ) { |
351 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); | 352 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); |
352 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); | 353 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); |
353 | } | 354 | } |
354 | QIconViewItem::paintItem(p,mycg); | 355 | QIconViewItem::paintItem(p,mycg); |
355 | if ( liv->currentItem() == this ) | 356 | if ( liv->currentItem() == this ) |
356 | liv->setItemTextBackground( oldBrush ); | 357 | liv->setItemTextBackground( oldBrush ); |
357 | } | 358 | } |
358 | 359 | ||
359 | virtual QPixmap* pixmap () const | 360 | virtual QPixmap* pixmap () const |
360 | { | 361 | { |
361 | const LauncherIconView* liv = (LauncherIconView*)iconView(); | 362 | const LauncherIconView* liv = (LauncherIconView*)iconView(); |
362 | if ( (const LauncherItem *)liv->busyItem() == this ) | 363 | if ( (const LauncherItem *)liv->busyItem() == this ) |
363 | return liv->busyPixmap(); | 364 | return liv->busyPixmap(); |
364 | return QIconViewItem::pixmap(); | 365 | return QIconViewItem::pixmap(); |
365 | } | 366 | } |
366 | 367 | ||
367 | protected: | 368 | protected: |
368 | AppLnk* app; | 369 | AppLnk* app; |
369 | }; | 370 | }; |
370 | 371 | ||
371 | 372 | ||
372 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) | 373 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) |
373 | : QIconViewItem( parent, applnk->name(), | 374 | : QIconViewItem( parent, applnk->name(), |
374 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), | 375 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), |
375 | app(applnk) // Takes ownership | 376 | app(applnk) // Takes ownership |
376 | { | 377 | { |
377 | } | 378 | } |
378 | 379 | ||
379 | int LauncherItem::compare ( QIconViewItem * i ) const | 380 | int LauncherItem::compare ( QIconViewItem * i ) const |
380 | { | 381 | { |
381 | LauncherIconView* view = (LauncherIconView*)iconView(); | 382 | LauncherIconView* view = (LauncherIconView*)iconView(); |
382 | return view->compare(app,((LauncherItem *)i)->appLnk()); | 383 | return view->compare(app,((LauncherItem *)i)->appLnk()); |
383 | } | 384 | } |
384 | 385 | ||
385 | QStringList LauncherIconView::mimeTypes() const | 386 | QStringList LauncherIconView::mimeTypes() const |
386 | { | 387 | { |
387 | QStringList r; | 388 | QStringList r; |
388 | QDictIterator<void> it(mimes); | 389 | QDictIterator<void> it(mimes); |
389 | while (it.current()) { | 390 | while (it.current()) { |
390 | r.append(it.currentKey()); | 391 | r.append(it.currentKey()); |
391 | ++it; | 392 | ++it; |
392 | } | 393 | } |
393 | r.sort(); | 394 | r.sort(); |
394 | return r; | 395 | return r; |
395 | } | 396 | } |
396 | 397 | ||
397 | void LauncherIconView::addItem(AppLnk* app, bool resort) | 398 | void LauncherIconView::addItem(AppLnk* app, bool resort) |
398 | { | 399 | { |
399 | addCatsAndMimes(app); | 400 | addCatsAndMimes(app); |
400 | 401 | ||
401 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) | 402 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) |
402 | && (cf == 0 || app->categories().contains(cf) | 403 | && (cf == 0 || app->categories().contains(cf) |
403 | || cf == -1 && app->categories().count() == 0 ) ) | 404 | || cf == -1 && app->categories().count() == 0 ) ) |
404 | (void) new LauncherItem( this, app, bigIcns ); | 405 | (void) new LauncherItem( this, app, bigIcns ); |
405 | else | 406 | else |
406 | hidden.append(app); | 407 | hidden.append(app); |
407 | if ( resort ) | 408 | if ( resort ) |
408 | sort(); | 409 | sort(); |
409 | } | 410 | } |
410 | 411 | ||
411 | void LauncherIconView::updateCategoriesAndMimeTypes() | 412 | void LauncherIconView::updateCategoriesAndMimeTypes() |
412 | { | 413 | { |
413 | mimes.clear(); | 414 | mimes.clear(); |
414 | cats.clear(); | 415 | cats.clear(); |
415 | LauncherItem* item = (LauncherItem*)firstItem(); | 416 | LauncherItem* item = (LauncherItem*)firstItem(); |
416 | while (item) { | 417 | while (item) { |
417 | addCatsAndMimes(item->appLnk()); | 418 | addCatsAndMimes(item->appLnk()); |
418 | item = (LauncherItem*)item->nextItem(); | 419 | item = (LauncherItem*)item->nextItem(); |
419 | } | 420 | } |
420 | QListIterator<AppLnk> it(hidden); | 421 | QListIterator<AppLnk> it(hidden); |
421 | AppLnk* l; | 422 | AppLnk* l; |
422 | while ((l=it.current())) { | 423 | while ((l=it.current())) { |
423 | addCatsAndMimes(l); | 424 | addCatsAndMimes(l); |
424 | ++it; | 425 | ++it; |
425 | } | 426 | } |
426 | } | 427 | } |
427 | 428 | ||
428 | void LauncherIconView::hideOrShowItems(bool resort) | 429 | void LauncherIconView::hideOrShowItems(bool resort) |
429 | { | 430 | { |
430 | hidden.setAutoDelete(FALSE); | 431 | hidden.setAutoDelete(FALSE); |
431 | QList<AppLnk> links=hidden; | 432 | QList<AppLnk> links=hidden; |
432 | hidden.clear(); | 433 | hidden.clear(); |
433 | hidden.setAutoDelete(TRUE); | 434 | hidden.setAutoDelete(TRUE); |
434 | LauncherItem* item = (LauncherItem*)firstItem(); | 435 | LauncherItem* item = (LauncherItem*)firstItem(); |
435 | while (item) { | 436 | while (item) { |
436 | links.append(item->takeAppLnk()); | 437 | links.append(item->takeAppLnk()); |
437 | item = (LauncherItem*)item->nextItem(); | 438 | item = (LauncherItem*)item->nextItem(); |
438 | } | 439 | } |
439 | viewport()->setUpdatesEnabled( FALSE ); | 440 | viewport()->setUpdatesEnabled( FALSE ); |
440 | clear(); | 441 | clear(); |
441 | QListIterator<AppLnk> it(links); | 442 | QListIterator<AppLnk> it(links); |
442 | AppLnk* l; | 443 | AppLnk* l; |
443 | while ((l=it.current())) { | 444 | while ((l=it.current())) { |
444 | addItem(l,FALSE); | 445 | addItem(l,FALSE); |
445 | ++it; | 446 | ++it; |
446 | } | 447 | } |
447 | viewport()->setUpdatesEnabled( TRUE ); | 448 | viewport()->setUpdatesEnabled( TRUE ); |
448 | if ( resort && !autoArrange() ) | 449 | if ( resort && !autoArrange() ) |
449 | sort(); | 450 | sort(); |
450 | } | 451 | } |
451 | 452 | ||
452 | bool LauncherIconView::removeLink(const QString& linkfile) | 453 | bool LauncherIconView::removeLink(const QString& linkfile) |
453 | { | 454 | { |
454 | LauncherItem* item = (LauncherItem*)firstItem(); | 455 | LauncherItem* item = (LauncherItem*)firstItem(); |
455 | AppLnk* l; | 456 | AppLnk* l; |
456 | bool did = FALSE; | 457 | bool did = FALSE; |
457 | DocLnk dl(linkfile); | 458 | DocLnk dl(linkfile); |
458 | while (item) { | 459 | while (item) { |
459 | l = item->appLnk(); | 460 | l = item->appLnk(); |
460 | if ( l->linkFileKnown() && l->linkFile() == linkfile | 461 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
461 | || l->fileKnown() && ( | 462 | || l->fileKnown() && ( |
462 | l->file() == linkfile | 463 | l->file() == linkfile |
463 | || dl.isValid() && dl.file() == l->file() ) ) { | 464 | || dl.isValid() && dl.file() == l->file() ) ) { |
464 | delete item; | 465 | delete item; |
465 | did = TRUE; | 466 | did = TRUE; |
466 | } | 467 | } |
467 | item = (LauncherItem*)item->nextItem(); | 468 | item = (LauncherItem*)item->nextItem(); |
468 | } | 469 | } |
469 | QListIterator<AppLnk> it(hidden); | 470 | QListIterator<AppLnk> it(hidden); |
470 | while ((l=it.current())) { | 471 | while ((l=it.current())) { |
471 | ++it; | 472 | ++it; |
472 | if ( l->linkFileKnown() && l->linkFile() == linkfile | 473 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
473 | || l->file() == linkfile | 474 | || l->file() == linkfile |
474 | || dl.isValid() && dl.file() == l->file() ) { | 475 | || dl.isValid() && dl.file() == l->file() ) { |
475 | hidden.removeRef(l); | 476 | hidden.removeRef(l); |
476 | did = TRUE; | 477 | did = TRUE; |
477 | } | 478 | } |
478 | } | 479 | } |
479 | return did; | 480 | return did; |
480 | } | 481 | } |
481 | 482 | ||
482 | static QString docLinkInfo(const Categories& cats, DocLnk* doc) | 483 | static QString docLinkInfo(const Categories& cats, DocLnk* doc) |
483 | { | 484 | { |
484 | QString contents; | 485 | QString contents; |
485 | 486 | ||
486 | QFileInfo fi( doc->file() ); | 487 | QFileInfo fi( doc->file() ); |
487 | if ( !fi.exists() ) | 488 | if ( !fi.exists() ) |
488 | return contents; | 489 | return contents; |
489 | 490 | ||
490 | if ( doc->linkFileKnown() ) { | 491 | if ( doc->linkFileKnown() ) { |
491 | QString lfn = doc->linkFile(); | 492 | QString lfn = doc->linkFile(); |
492 | QFile f( lfn ); | 493 | QFile f( lfn ); |
493 | if ( f.open( IO_ReadOnly ) ) { | 494 | if ( f.open( IO_ReadOnly ) ) { |
494 | QTextStream ts( &f ); | 495 | QTextStream ts( &f ); |
495 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | 496 | ts.setEncoding( QTextStream::UnicodeUTF8 ); |
496 | contents += ts.read(); | 497 | contents += ts.read(); |
497 | f.close(); | 498 | f.close(); |
498 | goto calcsize; | 499 | goto calcsize; |
499 | } | 500 | } |
500 | } | 501 | } |
501 | 502 | ||
502 | contents += "[Desktop Entry]\n"; | 503 | contents += "[Desktop Entry]\n"; |
503 | contents += "Categories = " // No tr | 504 | contents += "Categories = " // No tr |
504 | + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr | 505 | + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr |
505 | contents += "File = "+doc->file()+"\n"; // No tr | 506 | contents += "File = "+doc->file()+"\n"; // No tr |
506 | contents += "Name = "+doc->name()+"\n"; // No tr | 507 | contents += "Name = "+doc->name()+"\n"; // No tr |
507 | contents += "Type = "+doc->type()+"\n"; // No tr | 508 | contents += "Type = "+doc->type()+"\n"; // No tr |
508 | 509 | ||
509 | calcsize: | 510 | calcsize: |
510 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | 511 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr |
511 | return contents; | 512 | return contents; |
512 | } | 513 | } |
513 | 514 | ||
514 | QString LauncherIconView::getAllDocLinkInfo() const | 515 | QString LauncherIconView::getAllDocLinkInfo() const |
515 | { | 516 | { |
516 | QString contents; | 517 | QString contents; |
517 | LauncherItem* item = (LauncherItem*)firstItem(); | 518 | LauncherItem* item = (LauncherItem*)firstItem(); |
518 | Categories cats; | 519 | Categories cats; |
519 | while (item) { | 520 | while (item) { |
520 | DocLnk* doc = (DocLnk*)item->appLnk(); | 521 | DocLnk* doc = (DocLnk*)item->appLnk(); |
521 | contents += docLinkInfo(cats,doc); | 522 | contents += docLinkInfo(cats,doc); |
522 | item = (LauncherItem*)item->nextItem(); | 523 | item = (LauncherItem*)item->nextItem(); |
523 | } | 524 | } |
524 | QListIterator<AppLnk> it(hidden); | 525 | QListIterator<AppLnk> it(hidden); |
525 | DocLnk* doc; | 526 | DocLnk* doc; |
526 | while ((doc=(DocLnk*)it.current())) { | 527 | while ((doc=(DocLnk*)it.current())) { |
527 | contents += docLinkInfo(cats,doc); | 528 | contents += docLinkInfo(cats,doc); |
528 | ++it; | 529 | ++it; |
529 | } | 530 | } |
530 | return contents; | 531 | return contents; |
531 | } | 532 | } |
532 | 533 | ||
533 | //=========================================================================== | 534 | //=========================================================================== |
534 | 535 | ||
535 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) | 536 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) |
536 | : QVBox( parent, name, fl ) | 537 | : QVBox( parent, name, fl ) |
537 | { | 538 | { |
538 | icons = new LauncherIconView( this ); | 539 | icons = new LauncherIconView( this ); |
539 | setFocusProxy(icons); | 540 | setFocusProxy(icons); |
540 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); | 541 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); |
541 | 542 | ||
542 | icons->setItemsMovable( FALSE ); | 543 | icons->setItemsMovable( FALSE ); |
543 | icons->setAutoArrange( TRUE ); | 544 | icons->setAutoArrange( TRUE ); |
544 | icons->setSorting( TRUE ); | 545 | icons->setSorting( TRUE ); |
545 | icons->setFrameStyle( QFrame::NoFrame ); | 546 | icons->setFrameStyle( QFrame::NoFrame ); |
546 | icons->setMargin( 0 ); | 547 | icons->setMargin( 0 ); |
547 | icons->setSelectionMode( QIconView::NoSelection ); | 548 | icons->setSelectionMode( QIconView::NoSelection ); |
548 | icons->setBackgroundMode( PaletteBase ); | 549 | icons->setBackgroundMode( PaletteBase ); |
549 | icons->setResizeMode( QIconView::Fixed ); | 550 | icons->setResizeMode( QIconView::Fixed ); |
550 | vmode = (ViewMode)-1; | 551 | vmode = (ViewMode)-1; |
551 | setViewMode( Icon ); | 552 | setViewMode( Icon ); |
552 | 553 | ||
553 | connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), | 554 | connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), |
554 | SLOT(itemClicked(int, QIconViewItem *)) ); | 555 | SLOT(itemClicked(int, QIconViewItem *)) ); |
555 | connect( icons, SIGNAL(selectionChanged()), | 556 | connect( icons, SIGNAL(selectionChanged()), |
556 | SLOT(selectionChanged()) ); | 557 | SLOT(selectionChanged()) ); |
557 | connect( icons, SIGNAL(returnPressed(QIconViewItem *)), | 558 | connect( icons, SIGNAL(returnPressed(QIconViewItem *)), |
558 | SLOT(returnPressed(QIconViewItem *)) ); | 559 | SLOT(returnPressed(QIconViewItem *)) ); |
559 | connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), | 560 | connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), |
560 | SLOT(itemPressed(int, QIconViewItem *)) ); | 561 | SLOT(itemPressed(int, QIconViewItem *)) ); |
561 | 562 | ||
562 | tools = 0; | 563 | tools = 0; |
563 | setBackgroundType( Ruled, QString::null ); | 564 | setBackgroundType( Ruled, QString::null ); |
564 | } | 565 | } |
565 | 566 | ||
566 | LauncherView::~LauncherView() | 567 | LauncherView::~LauncherView() |
567 | { | 568 | { |
568 | } | 569 | } |
569 | 570 | ||
570 | void LauncherView::setToolsEnabled(bool y) | 571 | void LauncherView::setToolsEnabled(bool y) |
571 | { | 572 | { |
572 | if ( !y != !tools ) { | 573 | if ( !y != !tools ) { |
573 | if ( y ) { | 574 | if ( y ) { |
574 | tools = new QHBox(this); | 575 | tools = new QHBox(this); |
575 | 576 | ||
576 | // Type filter | 577 | // Type filter |
577 | typemb = new QComboBox(tools); | 578 | typemb = new QComboBox(tools); |
578 | 579 | ||
579 | // Category filter | 580 | // Category filter |
580 | catmb = new CategorySelect(tools); | 581 | catmb = new CategorySelect(tools); |
581 | 582 | ||
582 | updateTools(); | 583 | updateTools(); |
583 | tools->show(); | 584 | tools->show(); |
584 | } else { | 585 | } else { |
585 | delete tools; | 586 | delete tools; |
586 | tools = 0; | 587 | tools = 0; |
587 | } | 588 | } |
588 | } | 589 | } |
589 | } | 590 | } |
590 | 591 | ||
591 | void LauncherView::updateTools() | 592 | void LauncherView::updateTools() |
592 | { | 593 | { |
593 | disconnect( typemb, SIGNAL(activated(int)), | 594 | disconnect( typemb, SIGNAL(activated(int)), |
594 | this, SLOT(showType(int)) ); | 595 | this, SLOT(showType(int)) ); |
595 | disconnect( catmb, SIGNAL(signalSelected(int)), | 596 | disconnect( catmb, SIGNAL(signalSelected(int)), |
596 | this, SLOT(showCategory(int)) ); | 597 | this, SLOT(showCategory(int)) ); |
597 | 598 | ||
598 | icons->updateCategoriesAndMimeTypes(); | 599 | icons->updateCategoriesAndMimeTypes(); |
599 | 600 | ||
600 | QString prev; | 601 | QString prev; |
601 | 602 | ||
602 | // Type filter | 603 | // Type filter |
603 | QStringList types; | 604 | QStringList types; |
604 | typelist = icons->mimeTypes(); | 605 | typelist = icons->mimeTypes(); |
605 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { | 606 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { |
606 | QString t = *it; | 607 | QString t = *it; |
607 | if ( t.left(12) == "application/" ) { | 608 | if ( t.left(12) == "application/" ) { |
608 | MimeType mt(t); | 609 | MimeType mt(t); |
609 | const AppLnk* app = mt.application(); | 610 | const AppLnk* app = mt.application(); |
610 | if ( app ) | 611 | if ( app ) |
611 | t = app->name(); | 612 | t = app->name(); |
612 | else | 613 | else |
613 | t = t.mid(12); | 614 | t = t.mid(12); |
614 | } else { | 615 | } else { |
615 | t[0] = t[0].upper(); | 616 | t[0] = t[0].upper(); |
616 | } | 617 | } |
617 | types += tr("%1 files").arg(t); | 618 | types += tr("%1 files").arg(t); |
618 | } | 619 | } |
619 | types << tr("All types of file"); | 620 | types << tr("All types of file"); |
620 | prev = typemb->currentText(); | 621 | prev = typemb->currentText(); |
621 | typemb->clear(); | 622 | typemb->clear(); |
622 | typemb->insertStringList(types); | 623 | typemb->insertStringList(types); |
623 | for (int i=0; i<typemb->count(); i++) { | 624 | for (int i=0; i<typemb->count(); i++) { |
624 | if ( typemb->text(i) == prev ) { | 625 | if ( typemb->text(i) == prev ) { |
625 | typemb->setCurrentItem(i); | 626 | typemb->setCurrentItem(i); |
626 | break; | 627 | break; |
627 | } | 628 | } |
628 | } | 629 | } |
629 | if ( prev.isNull() ) | 630 | if ( prev.isNull() ) |
630 | typemb->setCurrentItem(typemb->count()-1); | 631 | typemb->setCurrentItem(typemb->count()-1); |
631 | 632 | ||
632 | Categories cats( 0 ); | 633 | Categories cats( 0 ); |
633 | cats.load( categoryFileName() ); | 634 | cats.load( categoryFileName() ); |
634 | QArray<int> vl( 0 ); | 635 | QArray<int> vl( 0 ); |
635 | catmb->setCategories( vl, "Document View", // No tr | 636 | catmb->setCategories( vl, "Document View", // No tr |
636 | tr("Document View") ); | 637 | tr("Document View") ); |
637 | catmb->setRemoveCategoryEdit( TRUE ); | 638 | catmb->setRemoveCategoryEdit( TRUE ); |
638 | catmb->setAllCategories( TRUE ); | 639 | catmb->setAllCategories( TRUE ); |
639 | 640 | ||
640 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); | 641 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); |
641 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); | 642 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); |
642 | } | 643 | } |
643 | 644 | ||
644 | void LauncherView::sortBy(int s) | 645 | void LauncherView::sortBy(int s) |
645 | { | 646 | { |
646 | icons->setSortMethod((LauncherIconView::SortMethod)s); | 647 | icons->setSortMethod((LauncherIconView::SortMethod)s); |
647 | } | 648 | } |
648 | 649 | ||
649 | void LauncherView::showType(int t) | 650 | void LauncherView::showType(int t) |
650 | { | 651 | { |
651 | if ( t >= (int)typelist.count() ) { | 652 | if ( t >= (int)typelist.count() ) { |
652 | icons->setTypeFilter("",TRUE); | 653 | icons->setTypeFilter("",TRUE); |
653 | } else { | 654 | } else { |
654 | QString ty = typelist[t]; | 655 | QString ty = typelist[t]; |
655 | if ( !ty.contains('/') ) | 656 | if ( !ty.contains('/') ) |
656 | ty += "/*"; | 657 | ty += "/*"; |
657 | icons->setTypeFilter(ty,TRUE); | 658 | icons->setTypeFilter(ty,TRUE); |
658 | } | 659 | } |
659 | } | 660 | } |
660 | 661 | ||
661 | void LauncherView::showCategory( int c ) | 662 | void LauncherView::showCategory( int c ) |
662 | { | 663 | { |
663 | icons->setCategoryFilter( c, TRUE ); | 664 | icons->setCategoryFilter( c, TRUE ); |
664 | } | 665 | } |
665 | 666 | ||
666 | void LauncherView::setViewMode( ViewMode m ) | 667 | void LauncherView::setViewMode( ViewMode m ) |
667 | { | 668 | { |
668 | if ( vmode != m ) { | 669 | if ( vmode != m ) { |
669 | bool bigIcons = m == Icon; | 670 | bool bigIcons = m == Icon; |
670 | icons->viewport()->setUpdatesEnabled( FALSE ); | 671 | icons->viewport()->setUpdatesEnabled( FALSE ); |
671 | icons->setBigIcons( bigIcons ); | 672 | icons->setBigIcons( bigIcons ); |
672 | switch ( m ) { | 673 | switch ( m ) { |
673 | case List: | 674 | case List: |
674 | icons->setItemTextPos( QIconView::Right ); | 675 | icons->setItemTextPos( QIconView::Right ); |
675 | break; | 676 | break; |
676 | case Icon: | 677 | case Icon: |
677 | icons->setItemTextPos( QIconView::Bottom ); | 678 | icons->setItemTextPos( QIconView::Bottom ); |
678 | break; | 679 | break; |
679 | } | 680 | } |
680 | icons->hideOrShowItems( FALSE ); | 681 | icons->hideOrShowItems( FALSE ); |
681 | icons->viewport()->setUpdatesEnabled( TRUE ); | 682 | icons->viewport()->setUpdatesEnabled( TRUE ); |
682 | vmode = m; | 683 | vmode = m; |
683 | } | 684 | } |
684 | } | 685 | } |
685 | 686 | ||
686 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) | 687 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) |
687 | { | 688 | { |
688 | if ( !bgCache ) | 689 | if ( !bgCache ) |
689 | bgCache = new QMap<QString,BgPixmap*>; | 690 | bgCache = new QMap<QString,BgPixmap*>; |
690 | if ( bgCache->contains( bgName ) ) | 691 | if ( bgCache->contains( bgName ) ) |
691 | (*bgCache)[bgName]->ref--; | 692 | (*bgCache)[bgName]->ref--; |
692 | 693 | ||
693 | switch ( t ) { | 694 | switch ( t ) { |
694 | case Ruled: { | 695 | case Ruled: { |
695 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr | 696 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr |
696 | QPixmap bg; | 697 | QPixmap bg; |
697 | if ( bgCache->contains( bgName ) ) { | 698 | if ( bgCache->contains( bgName ) ) { |
698 | (*bgCache)[bgName]->ref++; | 699 | (*bgCache)[bgName]->ref++; |
699 | bg = (*bgCache)[bgName]->pm; | 700 | bg = (*bgCache)[bgName]->pm; |
700 | } else { | 701 | } else { |
701 | bg.resize( width(), 9 ); | 702 | bg.resize( width(), 9 ); |
702 | QPainter painter( &bg ); | 703 | QPainter painter( &bg ); |
703 | for ( int i = 0; i < 3; i++ ) { | 704 | for ( int i = 0; i < 3; i++ ) { |
704 | painter.setPen( white ); | 705 | painter.setPen( white ); |
705 | painter.drawLine( 0, i*3, width()-1, i*3 ); | 706 | painter.drawLine( 0, i*3, width()-1, i*3 ); |
706 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); | 707 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); |
707 | painter.setPen( colorGroup().background().light(105) ); | 708 | painter.setPen( colorGroup().background().light(105) ); |
708 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); | 709 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); |
709 | } | 710 | } |
710 | painter.end(); | 711 | painter.end(); |
711 | bgCache->insert( bgName, new BgPixmap(bg) ); | 712 | bgCache->insert( bgName, new BgPixmap(bg) ); |
712 | } | 713 | } |
713 | icons->setBackgroundPixmap( bg ); | 714 | icons->setBackgroundPixmap( bg ); |
714 | break; | 715 | break; |
715 | } | 716 | } |
716 | 717 | ||
717 | case SolidColor: | 718 | case SolidColor: |
718 | icons->setBackgroundPixmap( QPixmap() ); | 719 | icons->setBackgroundPixmap( QPixmap() ); |
719 | if ( val.isEmpty() ) { | 720 | if ( val.isEmpty() ) { |
720 | icons->setBackgroundColor( colorGroup().base() ); | 721 | icons->setBackgroundColor( colorGroup().base() ); |
721 | } else { | 722 | } else { |
722 | icons->setBackgroundColor( val ); | 723 | icons->setBackgroundColor( val ); |
723 | } | 724 | } |
724 | bgName = ""; | 725 | bgName = ""; |
725 | break; | 726 | break; |
726 | 727 | ||
727 | case Image: | 728 | case Image: |
728 | bgName = val; | 729 | bgName = val; |
729 | if ( bgCache->contains( bgName ) ) { | 730 | if ( bgCache->contains( bgName ) ) { |
730 | (*bgCache)[bgName]->ref++; | 731 | (*bgCache)[bgName]->ref++; |
731 | icons->setBackgroundPixmap( (*bgCache)[bgName]->pm ); | 732 | icons->setBackgroundPixmap( (*bgCache)[bgName]->pm ); |
732 | } else { | 733 | } else { |
733 | qDebug( "Loading image: %s", val.latin1() ); | 734 | qDebug( "Loading image: %s", val.latin1() ); |
734 | QPixmap bg( Resource::loadPixmap( val ) ); | 735 | QPixmap bg( Resource::loadPixmap( val ) ); |
735 | if ( bg.isNull() ) { | 736 | if ( bg.isNull() ) { |
736 | QImageIO imgio; | 737 | QImageIO imgio; |
737 | imgio.setFileName( bgName ); | 738 | imgio.setFileName( bgName ); |
738 | QSize ds = qApp->desktop()->size(); | 739 | QSize ds = qApp->desktop()->size(); |
739 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr | 740 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr |
740 | imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() ); | 741 | imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() ); |
741 | imgio.read(); | 742 | imgio.read(); |
742 | bg = imgio.image(); | 743 | bg = imgio.image(); |
743 | } | 744 | } |
744 | bgCache->insert( bgName, new BgPixmap(bg) ); | 745 | bgCache->insert( bgName, new BgPixmap(bg) ); |
745 | icons->setBackgroundPixmap( bg ); | 746 | icons->setBackgroundPixmap( bg ); |
746 | } | 747 | } |
747 | break; | 748 | break; |
748 | } | 749 | } |
749 | 750 | ||
750 | // remove unreferenced backgrounds. | 751 | // remove unreferenced backgrounds. |
751 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | 752 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); |
752 | while ( it != bgCache->end() ) { | 753 | while ( it != bgCache->end() ) { |
753 | QMap<QString,BgPixmap*>::Iterator curr = it; | 754 | QMap<QString,BgPixmap*>::Iterator curr = it; |
754 | ++it; | 755 | ++it; |
755 | if ( (*curr)->ref == 0 ) { | 756 | if ( (*curr)->ref == 0 ) { |
756 | delete (*curr); | 757 | delete (*curr); |
757 | bgCache->remove( curr ); | 758 | bgCache->remove( curr ); |
758 | } | 759 | } |
759 | } | 760 | } |
760 | 761 | ||
761 | bgType = t; | 762 | bgType = t; |
762 | icons->viewport()->update(); | 763 | icons->viewport()->update(); |
763 | } | 764 | } |
764 | 765 | ||
765 | void LauncherView::setTextColor( const QColor &tc ) | 766 | void LauncherView::setTextColor( const QColor &tc ) |
766 | { | 767 | { |
767 | textCol = tc; | 768 | textCol = tc; |
768 | QColorGroup cg = icons->colorGroup(); | 769 | QColorGroup cg = icons->colorGroup(); |
769 | cg.setColor( QColorGroup::Text, tc ); | 770 | cg.setColor( QColorGroup::Text, tc ); |
770 | icons->setPalette( QPalette(cg,cg,cg) ); | 771 | icons->setPalette( QPalette(cg,cg,cg) ); |
771 | icons->viewport()->update(); | 772 | icons->viewport()->update(); |
772 | } | 773 | } |
773 | 774 | ||
774 | void LauncherView::setViewFont( const QFont &f ) | 775 | void LauncherView::setViewFont( const QFont &f ) |
775 | { | 776 | { |
776 | icons->setFont( f ); | 777 | icons->setFont( f ); |
777 | } | 778 | } |
778 | 779 | ||
779 | void LauncherView::resizeEvent(QResizeEvent *e) | 780 | void LauncherView::resizeEvent(QResizeEvent *e) |
780 | { | 781 | { |
781 | QVBox::resizeEvent( e ); | 782 | QVBox::resizeEvent( e ); |
782 | if ( e->size().width() != e->oldSize().width() ) | 783 | if ( e->size().width() != e->oldSize().width() ) |
783 | sort(); | 784 | sort(); |
784 | } | 785 | } |
785 | 786 | ||
786 | void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) | 787 | void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) |
787 | { | 788 | { |
788 | icons->clear(); | 789 | icons->clear(); |
789 | internalPopulate( folder, typefilter ); | 790 | internalPopulate( folder, typefilter ); |
790 | } | 791 | } |
791 | 792 | ||
792 | QString LauncherView::getAllDocLinkInfo() const | 793 | QString LauncherView::getAllDocLinkInfo() const |
793 | { | 794 | { |
794 | return icons->getAllDocLinkInfo(); | 795 | return icons->getAllDocLinkInfo(); |
795 | } | 796 | } |
796 | 797 | ||
797 | void LauncherView::selectionChanged() | 798 | void LauncherView::selectionChanged() |
798 | { | 799 | { |
799 | QIconViewItem* item = icons->currentItem(); | 800 | QIconViewItem* item = icons->currentItem(); |
800 | if ( item && item->isSelected() ) { | 801 | if ( item && item->isSelected() ) { |
801 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 802 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
802 | if ( icons->inKeyEvent() ) // not for mouse press | 803 | if ( icons->inKeyEvent() ) // not for mouse press |
803 | emit clicked( appLnk ); | 804 | emit clicked( appLnk ); |
804 | item->setSelected(FALSE); | 805 | item->setSelected(FALSE); |
805 | } | 806 | } |
806 | } | 807 | } |
807 | 808 | ||
808 | void LauncherView::returnPressed( QIconViewItem *item ) | 809 | void LauncherView::returnPressed( QIconViewItem *item ) |
809 | { | 810 | { |
810 | if ( item ) { | 811 | if ( item ) { |
811 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 812 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
812 | emit clicked( appLnk ); | 813 | emit clicked( appLnk ); |
813 | } | 814 | } |
814 | } | 815 | } |
815 | 816 | ||
816 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) | 817 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) |
817 | { | 818 | { |
818 | if ( item ) { | 819 | if ( item ) { |
819 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 820 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
820 | if ( btn == LeftButton ) { | 821 | if ( btn == LeftButton ) { |
821 | // Make sure it's the item we execute that gets highlighted | 822 | // Make sure it's the item we execute that gets highlighted |
822 | icons->setCurrentItem( item ); | 823 | icons->setCurrentItem( item ); |
823 | emit clicked( appLnk ); | 824 | emit clicked( appLnk ); |
824 | } | 825 | } |
825 | item->setSelected(FALSE); | 826 | item->setSelected(FALSE); |
826 | } | 827 | } |
827 | } | 828 | } |
828 | 829 | ||
829 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) | 830 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) |
830 | { | 831 | { |
831 | if ( item ) { | 832 | if ( item ) { |
832 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 833 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
833 | if ( btn == RightButton ) | 834 | if ( btn == RightButton ) |
834 | emit rightPressed( appLnk ); | 835 | emit rightPressed( appLnk ); |
835 | /* | 836 | /* |
836 | else if ( btn == LeftButton ) | 837 | else if ( btn == LeftButton ) |
837 | emit clicked( appLnk ); | 838 | emit clicked( appLnk ); |
838 | */ | 839 | */ |
839 | item->setSelected(FALSE); | 840 | item->setSelected(FALSE); |
840 | } | 841 | } |
841 | } | 842 | } |
842 | 843 | ||
843 | void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) | 844 | void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) |
844 | { | 845 | { |
845 | QListIterator<AppLnk> it( folder->children() ); | 846 | QListIterator<AppLnk> it( folder->children() ); |
846 | icons->setTypeFilter(typefilter,FALSE); | 847 | icons->setTypeFilter(typefilter,FALSE); |
847 | 848 | ||
848 | while ( it.current() ) { | 849 | while ( it.current() ) { |
849 | // show only the icons for existing files | 850 | // show only the icons for existing files |
850 | if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) { | 851 | if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) { |
851 | icons->addItem(*it,FALSE); | 852 | icons->addItem(*it,FALSE); |
852 | } | 853 | } |
853 | else { | 854 | else { |
854 | //maybe insert some .desktop file deletion code later | 855 | //maybe insert some .desktop file deletion code later |
855 | //maybe dir specific | 856 | //maybe dir specific |
856 | } | 857 | } |
857 | ++it; | 858 | ++it; |
858 | } | 859 | } |
859 | 860 | ||
860 | icons->sort(); | 861 | icons->sort(); |
861 | } | 862 | } |
862 | 863 | ||
863 | bool LauncherView::removeLink(const QString& linkfile) | 864 | bool LauncherView::removeLink(const QString& linkfile) |
864 | { | 865 | { |
865 | return icons->removeLink(linkfile); | 866 | return icons->removeLink(linkfile); |
866 | } | 867 | } |
867 | 868 | ||
868 | void LauncherView::sort() | 869 | void LauncherView::sort() |
869 | { | 870 | { |
870 | icons->sort(); | 871 | icons->sort(); |
871 | } | 872 | } |
872 | 873 | ||
873 | void LauncherView::addItem(AppLnk* app, bool resort) | 874 | void LauncherView::addItem(AppLnk* app, bool resort) |
874 | { | 875 | { |
875 | icons->addItem(app,resort); | 876 | icons->addItem(app,resort); |
876 | } | 877 | } |
877 | 878 | ||
878 | void LauncherView::setFileSystems(const QList<FileSystem> &) | 879 | void LauncherView::setFileSystems(const QList<FileSystem> &) |
879 | { | 880 | { |
880 | // ### does nothing now... | 881 | // ### does nothing now... |
881 | } | 882 | } |
882 | 883 | ||
883 | void LauncherView::paletteChange( const QPalette &p ) | 884 | void LauncherView::paletteChange( const QPalette &p ) |
884 | { | 885 | { |
885 | icons->unsetPalette(); | 886 | icons->unsetPalette(); |
886 | QVBox::paletteChange( p ); | 887 | QVBox::paletteChange( p ); |
887 | if ( bgType == Ruled ) | 888 | if ( bgType == Ruled ) |
888 | setBackgroundType( Ruled, QString::null ); | 889 | setBackgroundType( Ruled, QString::null ); |
889 | QColorGroup cg = icons->colorGroup(); | 890 | QColorGroup cg = icons->colorGroup(); |
890 | cg.setColor( QColorGroup::Text, textCol ); | 891 | cg.setColor( QColorGroup::Text, textCol ); |
891 | icons->setPalette( QPalette(cg,cg,cg) ); | 892 | icons->setPalette( QPalette(cg,cg,cg) ); |
892 | } | 893 | } |
893 | 894 | ||