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,492 +1,494 @@
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 );