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