summaryrefslogtreecommitdiff
path: root/core/launcher/launcherview.cpp
Unidiff
Diffstat (limited to 'core/launcher/launcherview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp109
1 files changed, 79 insertions, 30 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index ff26133..c9efacb 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -23,48 +23,49 @@
23/* OPIE */ 23/* OPIE */
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <qtopia/qpeapplication.h> 25#include <qtopia/qpeapplication.h>
26#include <qtopia/private/categories.h> 26#include <qtopia/private/categories.h>
27#include <qtopia/categoryselect.h> 27#include <qtopia/categoryselect.h>
28#include <qtopia/mimetype.h> 28#include <qtopia/mimetype.h>
29#include <qtopia/resource.h> 29#include <qtopia/resource.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31 31
32#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
33 33
34/* QT */ 34/* QT */
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qfileinfo.h> 36#include <qfileinfo.h>
37#include <qiconview.h> 37#include <qiconview.h>
38#include <qobjectlist.h> 38#include <qobjectlist.h>
39 39
40 40
41// These define how the busy icon is animated and highlighted 41// These define how the busy icon is animated and highlighted
42#define BRIGHTEN_BUSY_ICON 42#define BRIGHTEN_BUSY_ICON
43//#define ALPHA_FADE_BUSY_ICON 43//#define ALPHA_FADE_BUSY_ICON
44//#define USE_ANIMATED_BUSY_ICON_OVERLAY 44//#define USE_ANIMATED_BUSY_ICON_OVERLAY
45#define BOUNCE_BUSY_ICON 45#define BOUNCE_BUSY_ICON
46 46
47typedef QMap<QString,QPixmap>::Iterator pixiter;
47 48
48class BgPixmap 49class BgPixmap
49{ 50{
50public: 51public:
51 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 52 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
52 QPixmap pm; 53 QPixmap pm;
53 int ref; 54 int ref;
54}; 55};
55 56
56 57
57static QMap<QString,BgPixmap*> *bgCache = 0; 58static QMap<QString,BgPixmap*> *bgCache = 0;
58 59
59static void cleanup_cache() 60static void cleanup_cache()
60{ 61{
61 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 62 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
62 while ( it != bgCache->end() ) { 63 while ( it != bgCache->end() ) {
63 QMap<QString,BgPixmap*>::Iterator curr = it; 64 QMap<QString,BgPixmap*>::Iterator curr = it;
64 ++it; 65 ++it;
65 delete (*curr); 66 delete (*curr);
66 bgCache->remove( curr ); 67 bgCache->remove( curr );
67 } 68 }
68 delete bgCache; 69 delete bgCache;
69 bgCache = 0; 70 bgCache = 0;
70} 71}
@@ -84,67 +85,69 @@ public:
84 85
85 AppLnk *appLnk() const { return app; } 86 AppLnk *appLnk() const { return app; }
86 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } 87 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; }
87 88
88 void animateIcon(); 89 void animateIcon();
89 void resetIcon(); 90 void resetIcon();
90 bool isEyeImage()const{return m_EyeImage;} 91 bool isEyeImage()const{return m_EyeImage;}
91 92
92 virtual int compare ( QIconViewItem * i ) const; 93 virtual int compare ( QIconViewItem * i ) const;
93 void paintItem( QPainter *p, const QColorGroup &cg ); 94 void paintItem( QPainter *p, const QColorGroup &cg );
94 95
95 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 96 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
96 void setEyePixmap(const QPixmap&aIcon); 97 void setEyePixmap(const QPixmap&aIcon);
97 virtual QPixmap*pixmap()const; 98 virtual QPixmap*pixmap()const;
98 99
99protected: 100protected:
100 bool isBigIcon; 101 bool isBigIcon;
101 int iteration; 102 int iteration;
102 AppLnk* app; 103 AppLnk* app;
103 104
104private: 105private:
105 void paintAnimatedIcon( QPainter *p ); 106 void paintAnimatedIcon( QPainter *p );
106 BusyIndicatorType busyType; 107 BusyIndicatorType busyType;
107 int psize; 108 int psize;
108 QPixmap m_iPixmap;
109 bool m_EyeImage; 109 bool m_EyeImage;
110 iconstate_t m_EyeImageSet; 110 iconstate_t m_EyeImageSet;
111}; 111};
112 112
113LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) 113LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon )
114 : QIconViewItem( parent, applnk->name(), 114 : QIconViewItem( parent, applnk->name(),
115 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), 115 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
116 isBigIcon( bigIcon ), 116 isBigIcon( bigIcon ),
117 iteration(0), 117 iteration(0),
118 app(applnk), // Takes ownership 118 app(applnk), // Takes ownership
119 psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ), 119 psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ),
120 m_iPixmap(),
121 m_EyeImage(false), 120 m_EyeImage(false),
122 m_EyeImageSet(BASE_ICON) 121 m_EyeImageSet(BASE_ICON)
123{ 122{
124 if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) { 123 if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) {
125 m_EyeImage = true; 124 m_EyeImage = true;
126 m_iPixmap = (bigIcon ? applnk->bigPixmap():applnk->pixmap()); 125 QMap<QString,QPixmap>::Iterator it = LauncherIconView::sm_EyeCache->find(applnk->file());
126 if (it != LauncherIconView::sm_EyeCache->end()) {
127 m_EyeImageSet = EYE_ICON;
128 setPixmap(*it);
129 }
127 } 130 }
128} 131}
129 132
130LauncherItem::~LauncherItem() 133LauncherItem::~LauncherItem()
131{ 134{
132 LauncherIconView* liv = (LauncherIconView*)iconView(); 135 LauncherIconView* liv = (LauncherIconView*)iconView();
133 if ( liv->busyItem() == this ) 136 if ( liv->busyItem() == this )
134 liv->setBusy(FALSE); 137 liv->setBusy(FALSE);
135 delete app; 138 delete app;
136} 139}
137 140
138QPixmap*LauncherItem::pixmap()const 141QPixmap*LauncherItem::pixmap()const
139{ 142{
140 if (m_EyeImage && m_EyeImageSet == BASE_ICON) { 143 if (m_EyeImage && m_EyeImageSet == BASE_ICON) {
141 LauncherIconView* liv = (LauncherIconView*)iconView(); 144 LauncherIconView* liv = (LauncherIconView*)iconView();
142 liv->requestEyePix(this); 145 liv->requestEyePix(this);
143 } 146 }
144 return QIconViewItem::pixmap(); 147 return QIconViewItem::pixmap();
145} 148}
146 149
147int LauncherItem::compare ( QIconViewItem * i ) const 150int LauncherItem::compare ( QIconViewItem * i ) const
148{ 151{
149 LauncherIconView* view = (LauncherIconView*)iconView(); 152 LauncherIconView* view = (LauncherIconView*)iconView();
150 return view->compare(app,((LauncherItem *)i)->appLnk()); 153 return view->compare(app,((LauncherItem *)i)->appLnk());
@@ -192,102 +195,118 @@ void LauncherItem::paintAnimatedIcon( QPainter *p )
192#ifdef BOUNCE_BUSY_ICON 195#ifdef BOUNCE_BUSY_ICON
193 if ( busyType == BIT_Animated ) { 196 if ( busyType == BIT_Animated ) {
194 bounceY = 4 - ((iteration+2)%8); 197 bounceY = 4 - ((iteration+2)%8);
195 bounceY = bounceY < 0 ? -bounceY : bounceY; 198 bounceY = bounceY < 0 ? -bounceY : bounceY;
196 } 199 }
197#endif 200#endif
198 p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); 201 p2.drawPixmap( x1, y1 + bounceY, *pixmap() );
199#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 202#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
200 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); 203 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h );
201#else 204#else
202 Q_UNUSED( pic ) 205 Q_UNUSED( pic )
203#endif 206#endif
204 p->drawPixmap( x1, y1, dblBuf ); 207 p->drawPixmap( x1, y1, dblBuf );
205} 208}
206 209
207void LauncherItem::animateIcon() 210void LauncherItem::animateIcon()
208{ 211{
209 LauncherIconView* liv = (LauncherIconView*)iconView(); 212 LauncherIconView* liv = (LauncherIconView*)iconView();
210 213
211 if ( liv->busyItem() != this || !app ) 214 if ( liv->busyItem() != this || !app )
212 return; 215 return;
213 216
214 // Highlight the icon 217 // Highlight the icon
215 if ( iteration == 0 ) { 218 if ( iteration == 0 ) {
216 QPixmap src = (isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap())); 219 QPixmap src;
220 pixiter it;
221 if (isEyeImage() && (it=LauncherIconView::sm_EyeCache->find(appLnk()->file()))!=LauncherIconView::sm_EyeCache->end()) {
222 src = (*it);
223 } else {
224 src = ((isBigIcon ? app->bigPixmap() : app->pixmap()));
225 }
217 QImage img = src.convertToImage(); 226 QImage img = src.convertToImage();
218 QRgb *rgb; 227 QRgb *rgb;
219 int count; 228 int count;
220 if ( img.depth() == 32 ) { 229 if ( img.depth() == 32 ) {
221 rgb = (QRgb*)img.bits(); 230 rgb = (QRgb*)img.bits();
222 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 231 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
223 } else { 232 } else {
224 rgb = img.colorTable(); 233 rgb = img.colorTable();
225 count = img.numColors(); 234 count = img.numColors();
226 } 235 }
227 for ( int r = 0; r < count; r++, rgb++ ) { 236 for ( int r = 0; r < count; r++, rgb++ ) {
228#if defined(BRIGHTEN_BUSY_ICON) 237#if defined(BRIGHTEN_BUSY_ICON)
229 QColor c(*rgb); 238 QColor c(*rgb);
230 int h, s, v; 239 int h, s, v;
231 c.hsv(&h,&s,&v); 240 c.hsv(&h,&s,&v);
232 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); 241 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255));
233 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); 242 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb));
234#elif defined(ALPHA_FADE_BUSY_ICON) 243#elif defined(ALPHA_FADE_BUSY_ICON)
235 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); 244 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2);
236#endif 245#endif
237 } 246 }
238 src.convertFromImage( img ); 247 src.convertFromImage( img );
239 setPixmap( src ); 248 setPixmap( src );
240 } 249 }
241 250
242 iteration++; 251 iteration++;
243 252
244 // Paint animation overlay 253 // Paint animation overlay
245 QPainter p( liv->viewport() ); 254 QPainter p( liv->viewport() );
246 paintAnimatedIcon( &p ); 255 paintAnimatedIcon( &p );
247} 256}
248 257
249void LauncherItem::resetIcon() 258void LauncherItem::resetIcon()
250{ 259{
251 iteration = 0; 260 iteration = 0;
252 setPixmap((isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap()))); 261 if (isEyeImage()) {
262 QMap<QString,QPixmap>::Iterator it = LauncherIconView::sm_EyeCache->find(appLnk()->file());
263 if (it != LauncherIconView::sm_EyeCache->end()) {
264 setPixmap(*it);
265 return;
266 }
267 }
268 setPixmap(isBigIcon ? app->bigPixmap() : app->pixmap());
253} 269}
254 270
255void LauncherItem::setEyePixmap(const QPixmap&aIcon) 271void LauncherItem::setEyePixmap(const QPixmap&aIcon)
256{ 272{
257 if (!isEyeImage()) return; 273 if (!isEyeImage()) return;
258 m_iPixmap = aIcon;
259 setPixmap(aIcon); 274 setPixmap(aIcon);
260 m_EyeImageSet = EYE_ICON; 275 m_EyeImageSet = EYE_ICON;
261} 276}
262 277
263//=========================================================================== 278//===========================================================================
264// Implemantation of LauncherIconview start 279// Implemantation of LauncherIconview start
265//=========================================================================== 280//===========================================================================
281
282QMap<QString,QPixmap>* LauncherIconView::sm_EyeCache=0;
283
266LauncherIconView::LauncherIconView( QWidget* parent, const char* name ) 284LauncherIconView::LauncherIconView( QWidget* parent, const char* name )
267 : QIconView(parent,name),tf(""),cf(0),bsy(0),busyTimer(0),bigIcns(TRUE),bgColor(white) 285 : QIconView(parent,name),tf(""),cf(0),bsy(0),busyTimer(0),bigIcns(TRUE),bgColor(white)
268{ 286{
269 m_EyeCallBack = 0; 287 m_EyeCallBack = 0;
288 if (!sm_EyeCache) sm_EyeCache = new QMap<QString,QPixmap>();
270 sortmeth = Name; 289 sortmeth = Name;
271 hidden.setAutoDelete(TRUE); 290 hidden.setAutoDelete(TRUE);
272 ike = FALSE; 291 ike = FALSE;
273 calculateGrid( Bottom ); 292 calculateGrid( Bottom );
274 connect(&m_eyeTimer,SIGNAL(timeout()),this,SLOT(stopEyeTimer())); 293 connect(&m_eyeTimer,SIGNAL(timeout()),this,SLOT(stopEyeTimer()));
275} 294}
276 295
277LauncherIconView::~LauncherIconView() 296LauncherIconView::~LauncherIconView()
278{ 297{
279 odebug << "LauncherIconView::~LauncherIconView()" << oendl; 298 odebug << "LauncherIconView::~LauncherIconView()" << oendl;
280#if 0 // debuggery 299#if 0 // debuggery
281 QListIterator<AppLnk> it(hidden); 300 QListIterator<AppLnk> it(hidden);
282 AppLnk* l; 301 AppLnk* l;
283 while ((l=it.current())) { 302 while ((l=it.current())) {
284 ++it; 303 ++it;
285 //odebug << "" << l << ": hidden (should remove)" << oendl; 304 //odebug << "" << l << ": hidden (should remove)" << oendl;
286 } 305 }
287#endif 306#endif
288} 307}
289 308
290int LauncherIconView::compare(const AppLnk* a, const AppLnk* b) 309int LauncherIconView::compare(const AppLnk* a, const AppLnk* b)
291{ 310{
292 switch (sortmeth) { 311 switch (sortmeth) {
293 case Name: 312 case Name:
@@ -411,185 +430,207 @@ QStringList LauncherIconView::mimeTypes() const
411 ++it; 430 ++it;
412 } 431 }
413 r.sort(); 432 r.sort();
414 return r; 433 return r;
415} 434}
416 435
417LauncherItem*LauncherIconView::findDocItem(const QString&fname) 436LauncherItem*LauncherIconView::findDocItem(const QString&fname)
418{ 437{
419 LauncherItem* item = (LauncherItem*)firstItem(); 438 LauncherItem* item = (LauncherItem*)firstItem();
420 while (item) { 439 while (item) {
421 if (item->appLnk()->file()==fname) { 440 if (item->appLnk()->file()==fname) {
422 break; 441 break;
423 } 442 }
424 item = (LauncherItem*)item->nextItem(); 443 item = (LauncherItem*)item->nextItem();
425 } 444 }
426 return item; 445 return item;
427} 446}
428 447
429void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile,int width) 448void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile,int width)
430{ 449{
431 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); 450 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
432 if (s!=width) return; 451 if (s!=width) return;
433 LauncherItem*item = findDocItem(aFile); 452 LauncherItem*item = findDocItem(aFile);
434 if (!item||!item->isEyeImage()) return; 453 if (!item||!item->isEyeImage()) return;
454 (*sm_EyeCache)[aFile]=aPixmap;
435 item->setEyePixmap(aPixmap); 455 item->setEyePixmap(aPixmap);
436} 456}
437 457
438void LauncherIconView::checkCallback() 458void LauncherIconView::checkCallback()
439{ 459{
440 if (!m_EyeCallBack) { 460 if (!m_EyeCallBack) {
441 m_EyeCallBack = new LauncherThumbReceiver(); 461 m_EyeCallBack = new LauncherThumbReceiver();
442 connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)), 462 connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)),
443 this,SLOT(setEyePixmap(const QPixmap&,const QString&,int))); 463 this,SLOT(setEyePixmap(const QPixmap&,const QString&,int)));
444 m_eyeTimer.changeInterval(600000);
445 } 464 }
465 m_eyeTimer.changeInterval(600000);
446} 466}
447 467
448void LauncherIconView::addCheckItem(AppLnk* app) 468void LauncherIconView::addCheckItem(AppLnk* app)
449{ 469{
450 LauncherItem*item = new LauncherItem( this, app, bigIcns ); 470 LauncherItem*item = new LauncherItem( this, app, bigIcns );
451 if (item->isEyeImage()) { 471 if (item->isEyeImage()) {
452 checkCallback(); 472 checkCallback();
453 } 473 }
454} 474}
455 475
456void LauncherIconView::requestEyePix(const LauncherItem*item) 476void LauncherIconView::requestEyePix(const LauncherItem*item)
457{ 477{
458 if (!item) return; 478 if (!item) return;
459 if (item->isEyeImage()) { 479 if (item->isEyeImage()) {
460 checkCallback(); 480 checkCallback();
461 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); 481 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
462 m_EyeCallBack->requestThumb(item->appLnk()->file(),s,s); 482 m_EyeCallBack->requestThumb(item->appLnk()->file(),s,s);
463 } 483 }
464} 484}
465 485
466void LauncherIconView::stopEyeTimer() 486void LauncherIconView::stopEyeTimer()
467{ 487{
468 if (m_EyeCallBack) { 488 if (m_EyeCallBack) {
489 disconnect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)),
490 this,SLOT(setEyePixmap(const QPixmap&,const QString&,int)));
469 delete m_EyeCallBack; 491 delete m_EyeCallBack;
470 m_EyeCallBack=0; 492 m_EyeCallBack=0;
471 } 493 }
472 m_eyeTimer.stop(); 494 m_eyeTimer.stop();
473} 495}
474 496
475void LauncherIconView::addItem(AppLnk* app, bool resort)
476{
477 addCatsAndMimes(app);
478 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
479 && (cf == 0 || app->categories().contains(cf)
480 || cf == -1 && app->categories().count() == 0 ) ) {
481 addCheckItem(app);
482 } else {
483 hidden.append(app);
484 }
485 if ( resort ){
486 sort();
487 }
488}
489
490void LauncherIconView::updateCategoriesAndMimeTypes() 497void LauncherIconView::updateCategoriesAndMimeTypes()
491{ 498{
492 mimes.clear(); 499 mimes.clear();
493 cats.clear(); 500 cats.clear();
494 LauncherItem* item = (LauncherItem*)firstItem(); 501 LauncherItem* item = (LauncherItem*)firstItem();
495 while (item) { 502 while (item) {
496 addCatsAndMimes(item->appLnk()); 503 addCatsAndMimes(item->appLnk());
497 item = (LauncherItem*)item->nextItem(); 504 item = (LauncherItem*)item->nextItem();
498 } 505 }
499 QListIterator<AppLnk> it(hidden); 506 QListIterator<AppLnk> it(hidden);
500 AppLnk* l; 507 AppLnk* l;
501 while ((l=it.current())) { 508 while ((l=it.current())) {
502 addCatsAndMimes(l); 509 addCatsAndMimes(l);
503 ++it; 510 ++it;
504 } 511 }
505} 512}
506 513
507void LauncherIconView::hideOrShowItems(bool resort) 514void LauncherIconView::hideOrShowItems(bool resort)
508{ 515{
509 viewport()->setUpdatesEnabled( FALSE ); 516 viewport()->setUpdatesEnabled( FALSE );
510 hidden.setAutoDelete(FALSE); 517 hidden.setAutoDelete(FALSE);
511 QList<AppLnk> links=hidden; 518 QList<AppLnk> links=hidden;
512 hidden.clear(); 519 hidden.clear();
513 hidden.setAutoDelete(TRUE); 520 hidden.setAutoDelete(TRUE);
514 LauncherItem* item = (LauncherItem*)firstItem(); 521 LauncherItem* item = (LauncherItem*)firstItem();
515 while (item) { 522 while (item) {
516 links.append(item->takeAppLnk()); 523 links.append(item->takeAppLnk());
517 item = (LauncherItem*)item->nextItem(); 524 item = (LauncherItem*)item->nextItem();
518 } 525 }
519 clear(); 526 clear();
520 QListIterator<AppLnk> it(links); 527 QListIterator<AppLnk> it(links);
521 AppLnk* l; 528 AppLnk* l;
522 while ((l=it.current())) { 529 while ((l=it.current())) {
523 addItem(l,FALSE); 530 addItem(l,FALSE);
524 ++it; 531 ++it;
525 } 532 }
526 if ( resort && !autoArrange() ) 533 if ( resort && !autoArrange() )
527 sort(); 534 sort();
528 viewport()->setUpdatesEnabled( TRUE ); 535 viewport()->setUpdatesEnabled( TRUE );
529} 536}
530 537
531bool LauncherIconView::removeLink(const QString& linkfile) 538bool LauncherIconView::removeLink(const QString& linkfile,bool removeCache)
532{ 539{
533 LauncherItem* item = (LauncherItem*)firstItem(); 540 LauncherItem* item = (LauncherItem*)firstItem();
534 AppLnk* l; 541 AppLnk* l;
535 bool did = FALSE; 542 bool did = FALSE;
536 DocLnk dl(linkfile); 543 DocLnk dl(linkfile);
537 while (item) { 544 while (item) {
538 l = item->appLnk(); 545 l = item->appLnk();
539 LauncherItem *nextItem = (LauncherItem *)item->nextItem(); 546 LauncherItem *nextItem = (LauncherItem *)item->nextItem();
540 if ( l->linkFileKnown() && l->linkFile() == linkfile || l->fileKnown() && 547 if ( l->linkFileKnown() && l->linkFile() == linkfile || l->fileKnown() &&
541 ( l->file() == linkfile || dl.isValid() && dl.file() == l->file() ) ) { 548 ( l->file() == linkfile || dl.isValid() && dl.file() == l->file() ) ) {
549 if (removeCache) sm_EyeCache->remove(l->file());
542 delete item; 550 delete item;
543 did = TRUE; 551 did = TRUE;
544 } 552 }
545 item = nextItem; 553 item = nextItem;
546 } 554 }
547 QListIterator<AppLnk> it(hidden); 555 QListIterator<AppLnk> it(hidden);
548 while ((l=it.current())) { 556 while ((l=it.current())) {
549 ++it; 557 ++it;
550 if ( l->linkFileKnown() && l->linkFile() == linkfile 558 if ( l->linkFileKnown() && l->linkFile() == linkfile
551 || l->file() == linkfile 559 || l->file() == linkfile
552 || dl.isValid() && dl.file() == l->file() ) { 560 || dl.isValid() && dl.file() == l->file() ) {
553 hidden.removeRef(l); 561 hidden.removeRef(l);
554 did = TRUE; 562 did = TRUE;
555 } 563 }
556 } 564 }
557 return did; 565 return did;
558} 566}
559 567
568void LauncherIconView::addItem(AppLnk* app, bool resort)
569{
570 addCatsAndMimes(app);
571 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
572 && (cf == 0 || app->categories().contains(cf)
573 || cf == -1 && app->categories().count() == 0 ) ) {
574 addCheckItem(app);
575 } else {
576 hidden.append(app);
577 }
578 if ( resort ){
579 sort();
580 }
581}
582
583void LauncherIconView::changeItem(const AppLnk&old,AppLnk*nlink)
584{
585 QString oldfile = old.file();
586 QString newfile = nlink->file();
587
588 if (newfile != oldfile) {
589 QMap<QString,QPixmap>::Iterator it = sm_EyeCache->find(oldfile);
590 if (it != sm_EyeCache->end()) {
591 (*sm_EyeCache)[newfile]=(*it);
592 }
593 removeLink(old.linkFile());
594 } else {
595 removeLink(old.linkFile(),false);
596 }
597 addItem(nlink,false);
598}
599
560void LauncherIconView::timerEvent( QTimerEvent *te ) 600void LauncherIconView::timerEvent( QTimerEvent *te )
561{ 601{
562 if ( te->timerId() == busyTimer ) { 602 if ( te->timerId() == busyTimer ) {
563 if ( bsy ) 603 if ( bsy )
564 bsy->animateIcon(); 604 bsy->animateIcon();
565 } else { 605 } else {
566 QIconView::timerEvent( te ); 606 QIconView::timerEvent( te );
567 } 607 }
568} 608}
569 609
570void LauncherIconView::setBigIcons( bool bi ) 610void LauncherIconView::setBigIcons( bool bi )
571{ 611{
612 sm_EyeCache->clear();
572 bigIcns = bi; 613 bigIcns = bi;
573#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 614#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
574 busyPix.resize(0,0); 615 busyPix.resize(0,0);
575#endif 616#endif
576} 617}
577 618
578QIconViewItem* LauncherIconView::busyItem() const 619QIconViewItem* LauncherIconView::busyItem() const
579{ 620{
580 return bsy; 621 return bsy;
581} 622}
582 623
583void LauncherIconView::setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 624void LauncherIconView::setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
584 625
585void LauncherIconView::calculateGrid( ItemTextPos pos ) 626void LauncherIconView::calculateGrid( ItemTextPos pos )
586{ 627{
587 int dw = QApplication::desktop()->width(); 628 int dw = QApplication::desktop()->width();
588 int viewerWidth = dw-style().scrollBarExtent().width(); 629 int viewerWidth = dw-style().scrollBarExtent().width();
589 if ( pos == Bottom ) { 630 if ( pos == Bottom ) {
590 int cols = 3; 631 int cols = 3;
591 if ( viewerWidth <= 200 ) 632 if ( viewerWidth <= 200 )
592 cols = 2; 633 cols = 2;
593 else if ( viewerWidth >= 400 ) 634 else if ( viewerWidth >= 400 )
594 cols = viewerWidth/96; 635 cols = viewerWidth/96;
595 setSpacing( 4 ); 636 setSpacing( 4 );
@@ -735,50 +776,53 @@ void LauncherView::updateTools()
735 if ( app ) 776 if ( app )
736 t = app->name(); 777 t = app->name();
737 else 778 else
738 t = t.mid(12); 779 t = t.mid(12);
739 } else { 780 } else {
740 t[0] = t[0].upper(); 781 t[0] = t[0].upper();
741 } 782 }
742 types += t; 783 types += t;
743 } 784 }
744 types << tr("All types"); 785 types << tr("All types");
745 prev = typemb->currentText(); 786 prev = typemb->currentText();
746 typemb->clear(); 787 typemb->clear();
747 typemb->insertStringList(types); 788 typemb->insertStringList(types);
748 for (int i=0; i<typemb->count(); i++) { 789 for (int i=0; i<typemb->count(); i++) {
749 if ( typemb->text(i) == prev ) { 790 if ( typemb->text(i) == prev ) {
750 typemb->setCurrentItem(i); 791 typemb->setCurrentItem(i);
751 break; 792 break;
752 } 793 }
753 } 794 }
754 if ( prev.isNull() ) { 795 if ( prev.isNull() ) {
755 typemb->setCurrentItem(typemb->count()-1); 796 typemb->setCurrentItem(typemb->count()-1);
756 } 797 }
757 798
758 int pcat = catmb ? catmb->currentCategory() : -2; 799 int pcat = catmb ? catmb->currentCategory() : -2;
759 if ( !catmb ) 800 if ( !catmb ) {
760 catmb = new CategorySelect(tools); 801 catmb = new CategorySelect(tools);
802 } else if (pcat!=-2) {
803
804 }
761 Categories cats( 0 ); 805 Categories cats( 0 );
762 cats.load( categoryFileName() ); 806 cats.load( categoryFileName() );
763 QArray<int> vl( 0 ); 807 QArray<int> vl( 0 );
764 catmb->setCategories( vl, "Document View", // No tr 808 catmb->setCategories( vl, "Document View", // No tr
765 tr("Document View") ); 809 tr("Document View") );
766 catmb->setRemoveCategoryEdit( TRUE ); 810 catmb->setRemoveCategoryEdit( TRUE );
767 catmb->setAllCategories( TRUE ); 811 catmb->setAllCategories( TRUE );
768 catmb->setCurrentCategory(pcat); 812 catmb->setCurrentCategory(pcat);
769 813
770 // if type has changed we need to redisplay 814 // if type has changed we need to redisplay
771 if ( typemb->currentText() != prev ) 815 if ( typemb->currentText() != prev )
772 showType( typemb->currentItem() ); 816 showType( typemb->currentItem() );
773 817
774 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); 818 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
775 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 819 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
776} 820}
777 821
778void LauncherView::sortBy(int s) 822void LauncherView::sortBy(int s)
779{ 823{
780 icons->setSortMethod((LauncherIconView::SortMethod)s); 824 icons->setSortMethod((LauncherIconView::SortMethod)s);
781} 825}
782 826
783void LauncherView::showType(int t) 827void LauncherView::showType(int t)
784{ 828{
@@ -999,97 +1043,102 @@ void LauncherView::selectionChanged()
999 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1043 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
1000 if ( icons->inKeyEvent() ) // not for mouse press 1044 if ( icons->inKeyEvent() ) // not for mouse press
1001 emit clicked( appLnk ); 1045 emit clicked( appLnk );
1002 item->setSelected(FALSE); 1046 item->setSelected(FALSE);
1003 } 1047 }
1004} 1048}
1005 1049
1006void LauncherView::returnPressed( QIconViewItem *item ) 1050void LauncherView::returnPressed( QIconViewItem *item )
1007{ 1051{
1008 if ( item ) { 1052 if ( item ) {
1009 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1053 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
1010 emit clicked( appLnk ); 1054 emit clicked( appLnk );
1011 } 1055 }
1012} 1056}
1013 1057
1014void LauncherView::itemClicked( int btn, QIconViewItem *item ) 1058void LauncherView::itemClicked( int btn, QIconViewItem *item )
1015{ 1059{
1016 if ( item ) { 1060 if ( item ) {
1017 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1061 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
1018 if ( btn == LeftButton ) { 1062 if ( btn == LeftButton ) {
1019 // Make sure it's the item we execute that gets highlighted 1063 // Make sure it's the item we execute that gets highlighted
1020 icons->setCurrentItem( item ); 1064 icons->setCurrentItem( item );
1021 emit clicked( appLnk ); 1065 emit clicked( appLnk );
1022 } 1066 }
1023 item->setSelected(FALSE); 1067 item->setSelected(FALSE);
1024 } 1068 }
1025} 1069}
1026 1070
1027void LauncherView::itemPressed( int btn, QIconViewItem *item ) 1071void LauncherView::itemPressed( int btn, QIconViewItem *item )
1028{ 1072{
1029 if ( item ) { 1073 if ( item ) {
1030 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1074 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
1031 if ( btn == RightButton ) 1075 if ( btn == RightButton )
1032 emit rightPressed( appLnk ); 1076 emit rightPressed( appLnk );
1033 else if ( btn == ShiftButton ) 1077 else if ( btn == ShiftButton )
1034 emit rightPressed( appLnk ); 1078 emit rightPressed( appLnk );
1035 item->setSelected(FALSE); 1079 item->setSelected(FALSE);
1036 } 1080 }
1037} 1081}
1038 1082
1039void LauncherView::removeAllItems() 1083void LauncherView::removeAllItems()
1040{ 1084{
1041 odebug << "LauncherView::removeAllItems()" << oendl; 1085 odebug << "LauncherView::removeAllItems()" << oendl;
1042 icons->clear(); 1086 icons->clear();
1043} 1087}
1044 1088
1045bool LauncherView::removeLink(const QString& linkfile) 1089bool LauncherView::removeLink(const QString& linkfile)
1046{ 1090{
1047 return icons->removeLink(linkfile); 1091 return icons->removeLink(linkfile);
1048} 1092}
1049 1093
1094void LauncherView::addItem(AppLnk* app, bool resort)
1095{
1096 icons->addItem(app,resort);
1097}
1098
1099void LauncherView::changeItem(const AppLnk&old,AppLnk*nlink)
1100{
1101 icons->changeItem(old,nlink);
1102}
1103
1050void LauncherView::setSortEnabled( bool v ) 1104void LauncherView::setSortEnabled( bool v )
1051{ 1105{
1052 icons->setSorting( v ); 1106 icons->setSorting( v );
1053 if ( v ) 1107 if ( v )
1054 sort(); 1108 sort();
1055} 1109}
1056 1110
1057void LauncherView::setUpdatesEnabled( bool u ) 1111void LauncherView::setUpdatesEnabled( bool u )
1058{ 1112{
1059 icons->setUpdatesEnabled( u ); 1113 icons->setUpdatesEnabled( u );
1060} 1114}
1061 1115
1062void LauncherView::sort() 1116void LauncherView::sort()
1063{ 1117{
1064 icons->sort(); 1118 icons->sort();
1065} 1119}
1066 1120
1067void LauncherView::addItem(AppLnk* app, bool resort)
1068{
1069 icons->addItem(app,resort);
1070}
1071
1072void LauncherView::paletteChange( const QPalette &p ) 1121void LauncherView::paletteChange( const QPalette &p )
1073{ 1122{
1074 icons->unsetPalette(); 1123 icons->unsetPalette();
1075 QVBox::paletteChange( p ); 1124 QVBox::paletteChange( p );
1076 if ( bgType == Ruled ) 1125 if ( bgType == Ruled )
1077 setBackgroundType( Ruled, QString::null ); 1126 setBackgroundType( Ruled, QString::null );
1078 QColorGroup cg = icons->colorGroup(); 1127 QColorGroup cg = icons->colorGroup();
1079 cg.setColor( QColorGroup::Text, textCol ); 1128 cg.setColor( QColorGroup::Text, textCol );
1080 icons->setPalette( QPalette(cg,cg,cg) ); 1129 icons->setPalette( QPalette(cg,cg,cg) );
1081} 1130}
1082 1131
1083void LauncherView::fontChanged(const QFont&) 1132void LauncherView::fontChanged(const QFont&)
1084{ 1133{
1085 odebug << "LauncherView::fontChanged()" << oendl; 1134 odebug << "LauncherView::fontChanged()" << oendl;
1086 icons->hideOrShowItems( FALSE ); 1135 icons->hideOrShowItems( FALSE );
1087} 1136}
1088 1137
1089void LauncherView::relayout(void) 1138void LauncherView::relayout(void)
1090{ 1139{
1091 icons->hideOrShowItems(FALSE); 1140 icons->hideOrShowItems(FALSE);
1092} 1141}
1093 1142
1094void LauncherView::flushBgCache() 1143void LauncherView::flushBgCache()
1095{ 1144{