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