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