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