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