summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index e8741a2..7b20fdc 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,603 +1,612 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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/resource.h> 29#include <qpe/resource.h>
30#include <qpe/qpetoolbar.h> 30#include <qpe/qpetoolbar.h>
31 31
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qdict.h> 33#include <qdict.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qhbox.h> 36#include <qhbox.h>
37#include <qiconview.h> 37#include <qiconview.h>
38#include <qpainter.h> 38#include <qpainter.h>
39#include <qregexp.h> 39#include <qregexp.h>
40#include <qtoolbutton.h> 40#include <qtoolbutton.h>
41 41
42class LauncherIconView : public QIconView { 42class LauncherIconView : public QIconView {
43public: 43public:
44 LauncherIconView( QWidget* parent, const char* name=0 ) : 44 LauncherIconView( QWidget* parent, const char* name=0 ) :
45 QIconView(parent,name), 45 QIconView(parent,name),
46 tf(""), 46 tf(""),
47 cf(0), 47 cf(0),
48 bsy(0) 48 bsy(0)
49 { 49 {
50 sortmeth = Name; 50 sortmeth = Name;
51 hidden.setAutoDelete(TRUE); 51 hidden.setAutoDelete(TRUE);
52 ike = FALSE; 52 ike = FALSE;
53 } 53 }
54 54
55 ~LauncherIconView() 55 ~LauncherIconView()
56 { 56 {
57#if 0 // debuggery 57#if 0 // debuggery
58 QListIterator<AppLnk> it(hidden); 58 QListIterator<AppLnk> it(hidden);
59 AppLnk* l; 59 AppLnk* l;
60 while ((l=it.current())) { 60 while ((l=it.current())) {
61 ++it; 61 ++it;
62 //qDebug("%p: hidden (should remove)",l); 62 //qDebug("%p: hidden (should remove)",l);
63 } 63 }
64#endif 64#endif
65 } 65 }
66 66
67 QIconViewItem* busyItem() const { return bsy; } 67 QIconViewItem* busyItem() const { return bsy; }
68 68
69 void updateCategoriesAndMimeTypes(); 69 void updateCategoriesAndMimeTypes();
70 70
71 void doAutoScroll() 71 void doAutoScroll()
72 { 72 {
73 // We don't want rubberbanding (yet) 73 // We don't want rubberbanding (yet)
74 } 74 }
75 75
76 void setBusy(bool on) 76 void setBusy(bool on)
77 { 77 {
78 QIconViewItem *c = on ? currentItem() : 0; 78 QIconViewItem *c = on ? currentItem() : 0;
79 if ( bsy != c ) { 79 if ( bsy != c ) {
80 QIconViewItem* o = bsy; 80 QIconViewItem* o = bsy;
81 bsy = c; 81 bsy = c;
82 if ( o ) o->repaint(); 82 if ( o ) o->repaint();
83 if ( c ) c->repaint(); 83 if ( c ) c->repaint();
84 } 84 }
85 } 85 }
86 86
87 bool inKeyEvent() const { return ike; } 87 bool inKeyEvent() const { return ike; }
88 void keyPressEvent(QKeyEvent* e) 88 void keyPressEvent(QKeyEvent* e)
89 { 89 {
90 ike = TRUE; 90 ike = TRUE;
91 if ( e->key() == Key_F33 ) { 91 if ( e->key() == Key_F33 ) {
92 // "OK" button 92 // "OK" button
93 returnPressed(currentItem()); 93 returnPressed(currentItem());
94 } 94 }
95 QIconView::keyPressEvent(e); 95 QIconView::keyPressEvent(e);
96 ike = FALSE; 96 ike = FALSE;
97 } 97 }
98 98
99 void addItem(AppLnk* app, bool resort=TRUE); 99 void addItem(AppLnk* app, bool resort=TRUE);
100 bool removeLink(const QString& linkfile); 100 bool removeLink(const QString& linkfile);
101 101
102 QStringList mimeTypes() const; 102 QStringList mimeTypes() const;
103 QStringList categories() const; 103 QStringList categories() const;
104 104
105 void clear() 105 void clear()
106 { 106 {
107 mimes.clear(); 107 mimes.clear();
108 cats.clear(); 108 cats.clear();
109 QIconView::clear(); 109 QIconView::clear();
110 hidden.clear(); 110 hidden.clear();
111 } 111 }
112 112
113 void addCatsAndMimes(AppLnk* app) 113 void addCatsAndMimes(AppLnk* app)
114 { 114 {
115 // QStringList c = app->categories(); 115 // QStringList c = app->categories();
116 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 116 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
117 // cats.replace(*cit,(void*)1); 117 // cats.replace(*cit,(void*)1);
118 // } 118 // }
119 QString maj=app->type(); 119 QString maj=app->type();
120 int sl=maj.find('/'); 120 int sl=maj.find('/');
121 if (sl>=0) { 121 if (sl>=0) {
122 QString k = maj.left(sl); 122 QString k = maj.left(sl);
123 mimes.replace(k,(void*)1); 123 mimes.replace(k,(void*)1);
124 } 124 }
125 } 125 }
126 126
127 void drawBackground( QPainter *p, const QRect &r ) 127 void drawBackground( QPainter *p, const QRect &r )
128 { 128 {
129 int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0; 129 int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0;
130 //int backgroundMode = 2; 130 //int backgroundMode = 2;
131 131
132 if ( backgroundMode == 1 ) { 132 if ( backgroundMode == 1 ) {
133 133
134 // Double buffer the background 134 // Double buffer the background
135 static QPixmap *bg = NULL; 135 static QPixmap *bg = NULL;
136 static QColor bgColor; 136 static QColor bgColor;
137 137
138 if ( (bg == NULL) || (bgColor != colorGroup().button()) ) { 138 if ( (bg == NULL) || (bgColor != colorGroup().button()) ) {
139 // Create a new background double buffer 139 // Create a new background double buffer
140 if (bg == NULL) 140 if (bg == NULL)
141 bg = new QPixmap( width(), height() ); 141 bg = new QPixmap( width(), height() );
142 bgColor = colorGroup().button(); 142 bgColor = colorGroup().button();
143 QPainter painter( bg ); 143 QPainter painter( bg );
144 144
145 painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110)); 145 painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110));
146 146
147 // Overlay the Qtopia logo in the center 147 // Overlay the Qtopia logo in the center
148 QImage logo = Resource::loadImage( "qpe-background" ); 148 QImage logo = Resource::loadImage( "qpe-background" );
149 if ( !logo.isNull() ) 149 if ( !logo.isNull() )
150 painter.drawImage( (width() - logo.width()) / 2, 150 painter.drawImage( (width() - logo.width()) / 2,
151 (height() - logo.height()) / 2, logo ); 151 (height() - logo.height()) / 2, logo );
152 } 152 }
153 153
154 // Draw the double buffer to the widget (it is tiled for when the icon view is large) 154 // Draw the double buffer to the widget (it is tiled for when the icon view is large)
155 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), 155 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(),
156 (r.y() + contentsY()) % bg->height() ) ); 156 (r.y() + contentsY()) % bg->height() ) );
157 } else if ( backgroundMode == 2 ) { 157 } else if ( backgroundMode == 2 ) {
158 static QPixmap *bg = 0; 158 static QPixmap *bg = 0;
159 static QColor bgColor; 159 static QColor bgColor;
160 if ( !bg || (bgColor != colorGroup().background()) ) { 160 if ( !bg || (bgColor != colorGroup().background()) ) {
161 bgColor = colorGroup().background(); 161 bgColor = colorGroup().background();
162 bg = new QPixmap( width(), 9 ); 162 bg = new QPixmap( width(), 9 );
163 QPainter painter( bg ); 163 QPainter painter( bg );
164 for ( int i = 0; i < 3; i++ ) { 164 for ( int i = 0; i < 3; i++ ) {
165 painter.setPen( colorGroup().background().light(130) ); 165 painter.setPen( colorGroup().background().light(130) );
166 painter.drawLine( 0, i*3, width()-1, i*3 ); 166 painter.drawLine( 0, i*3, width()-1, i*3 );
167 painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); 167 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
168 painter.setPen( colorGroup().background().light(105) ); 168 painter.setPen( colorGroup().background().light(105) );
169 painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); 169 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
170 } 170 }
171 } 171 }
172 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), 172 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(),
173 (r.y() + contentsY()) % bg->height() ) ); 173 (r.y() + contentsY()) % bg->height() ) );
174 } else { 174 } else {
175 p->fillRect( r, QBrush( colorGroup().background().light(110) ) ); 175 p->fillRect( r, QBrush( colorGroup().background().light(110) ) );
176 } 176 }
177 } 177 }
178 178
179 void hideOrShowItems(bool resort); 179 void hideOrShowItems(bool resort);
180 180
181 void setTypeFilter(const QString& typefilter, bool resort) 181 void setTypeFilter(const QString& typefilter, bool resort)
182 { 182 {
183 tf = QRegExp(typefilter,FALSE,TRUE); 183 tf = QRegExp(typefilter,FALSE,TRUE);
184 hideOrShowItems(resort); 184 hideOrShowItems(resort);
185 } 185 }
186 186
187 void setCategoryFilter( int catfilter, bool resort ) 187 void setCategoryFilter( int catfilter, bool resort )
188 { 188 {
189 Categories cat; 189 Categories cat;
190 cat.load( categoryFileName() ); 190 cat.load( categoryFileName() );
191 QString str; 191 QString str;
192 if ( catfilter == -2 ) 192 if ( catfilter == -2 )
193 cf = 0; 193 cf = 0;
194 else 194 else
195 cf = catfilter; 195 cf = catfilter;
196 hideOrShowItems(resort); 196 hideOrShowItems(resort);
197 } 197 }
198 198
199 enum SortMethod { Name, Date, Type }; 199 enum SortMethod { Name, Date, Type };
200 200
201 void setSortMethod( SortMethod m ) 201 void setSortMethod( SortMethod m )
202 { 202 {
203 if ( sortmeth != m ) { 203 if ( sortmeth != m ) {
204 sortmeth = m; 204 sortmeth = m;
205 sort(); 205 sort();
206 } 206 }
207 } 207 }
208 208
209 int compare(const AppLnk* a, const AppLnk* b) 209 int compare(const AppLnk* a, const AppLnk* b)
210 { 210 {
211 switch (sortmeth) { 211 switch (sortmeth) {
212 case Name: 212 case Name:
213 return a->name().compare(b->name()); 213 return a->name().compare(b->name());
214 case Date: { 214 case Date: {
215 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 215 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
216 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 216 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
217 return fa.lastModified().secsTo(fb.lastModified()); 217 return fa.lastModified().secsTo(fb.lastModified());
218 } 218 }
219 case Type: 219 case Type:
220 return a->type().compare(b->type()); 220 return a->type().compare(b->type());
221 } 221 }
222 return 0; 222 return 0;
223 } 223 }
224 224
225protected: 225protected:
226 226
227 void styleChange( QStyle &old ) 227 void styleChange( QStyle &old )
228 { 228 {
229 QIconView::styleChange( old ); 229 QIconView::styleChange( old );
230 //### duplicated code from LauncherView constructor 230 //### duplicated code from LauncherView constructor
231 int dw = QApplication::desktop()->width(); 231 int dw = QApplication::desktop()->width();
232 setGridX( (dw-13-style().scrollBarExtent().width())/3 ); // tweaked for 8pt+dw=176 and 10pt+dw=240 232 setGridX( (dw-13-style().scrollBarExtent().width())/3 ); // tweaked for 8pt+dw=176 and 10pt+dw=240
233 } 233 }
234 234
235private: 235private:
236 QList<AppLnk> hidden; 236 QList<AppLnk> hidden;
237 QDict<void> mimes; 237 QDict<void> mimes;
238 QDict<void> cats; 238 QDict<void> cats;
239 SortMethod sortmeth; 239 SortMethod sortmeth;
240 QRegExp tf; 240 QRegExp tf;
241 int cf; 241 int cf;
242 QIconViewItem* bsy; 242 QIconViewItem* bsy;
243 bool ike; 243 bool ike;
244 244
245}; 245};
246 246
247 247
248bool LauncherView::bsy=FALSE; 248bool LauncherView::bsy=FALSE;
249 249
250void LauncherView::setBusy(bool on) 250void LauncherView::setBusy(bool on)
251{ 251{
252 icons->setBusy(on); 252 icons->setBusy(on);
253} 253}
254 254
255class LauncherItem : public QIconViewItem 255class LauncherItem : public QIconViewItem
256{ 256{
257public: 257public:
258 LauncherItem( QIconView *parent, AppLnk* applnk ); 258 LauncherItem( QIconView *parent, AppLnk* applnk );
259 ~LauncherItem() 259 ~LauncherItem()
260 { 260 {
261 LauncherIconView* liv = (LauncherIconView*)iconView(); 261 LauncherIconView* liv = (LauncherIconView*)iconView();
262 if ( liv->busyItem() == this ) 262 if ( liv->busyItem() == this )
263 liv->setBusy(FALSE); 263 liv->setBusy(FALSE);
264 delete app; 264 delete app;
265 } 265 }
266 266
267 AppLnk* appLnk() const { return app; } 267 AppLnk* appLnk() const { return app; }
268 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } 268 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; }
269 269
270 virtual int compare ( QIconViewItem * i ) const; 270 virtual int compare ( QIconViewItem * i ) const;
271 271
272 void paintItem( QPainter *p, const QColorGroup &cg ) 272 void paintItem( QPainter *p, const QColorGroup &cg )
273 { 273 {
274 LauncherIconView* liv = (LauncherIconView*)iconView(); 274 LauncherIconView* liv = (LauncherIconView*)iconView();
275 QBrush oldBrush( liv->itemTextBackground() ); 275 QBrush oldBrush( liv->itemTextBackground() );
276 QColorGroup mycg( cg ); 276 QColorGroup mycg( cg );
277 if ( liv->currentItem() == this ) { 277 if ( liv->currentItem() == this ) {
278 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 278 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
279 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 279 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
280 } 280 }
281 QIconViewItem::paintItem(p,mycg); 281 QIconViewItem::paintItem(p,mycg);
282 if ( liv->currentItem() == this ) 282 if ( liv->currentItem() == this )
283 liv->setItemTextBackground( oldBrush ); 283 liv->setItemTextBackground( oldBrush );
284 if ( liv->busyItem() == this ) { 284 if ( liv->busyItem() == this ) {
285 static QPixmap* busypm=0; 285 static QPixmap* busypm=0;
286 if ( !busypm ) 286 if ( !busypm )
287 busypm = new QPixmap(Resource::loadPixmap("launching")); 287 busypm = new QPixmap(Resource::loadPixmap("launching"));
288 p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm); 288 p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm);
289 } 289 }
290 } 290 }
291 291
292protected: 292protected:
293 AppLnk* app; 293 AppLnk* app;
294}; 294};
295 295
296 296
297LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk ) 297LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk )
298 : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ), 298 : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ),
299 app(applnk) // Takes ownership 299 app(applnk) // Takes ownership
300{ 300{
301} 301}
302 302
303int LauncherItem::compare ( QIconViewItem * i ) const 303int LauncherItem::compare ( QIconViewItem * i ) const
304{ 304{
305 LauncherIconView* view = (LauncherIconView*)iconView(); 305 LauncherIconView* view = (LauncherIconView*)iconView();
306 return view->compare(app,((LauncherItem *)i)->appLnk()); 306 return view->compare(app,((LauncherItem *)i)->appLnk());
307} 307}
308 308
309QStringList LauncherIconView::mimeTypes() const 309QStringList LauncherIconView::mimeTypes() const
310{ 310{
311 QStringList r; 311 QStringList r;
312 QDictIterator<void> it(mimes); 312 QDictIterator<void> it(mimes);
313 while (it.current()) { 313 while (it.current()) {
314 r.append(it.currentKey()); 314 r.append(it.currentKey());
315 ++it; 315 ++it;
316 } 316 }
317 r.sort(); 317 r.sort();
318 return r; 318 return r;
319} 319}
320 320
321void LauncherIconView::addItem(AppLnk* app, bool resort) 321void LauncherIconView::addItem(AppLnk* app, bool resort)
322{ 322{
323 addCatsAndMimes(app); 323 addCatsAndMimes(app);
324 324
325 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 325 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
326 && (cf == 0 || app->categories().contains(cf) 326 && (cf == 0 || app->categories().contains(cf)
327 || cf == -1 && app->categories().count() == 0 ) ) 327 || cf == -1 && app->categories().count() == 0 ) )
328 (void) new LauncherItem( this, app ); 328 (void) new LauncherItem( this, app );
329 else 329 else
330 hidden.append(app); 330 hidden.append(app);
331 if ( resort ) 331 if ( resort )
332 sort(); 332 sort();
333} 333}
334 334
335void LauncherIconView::updateCategoriesAndMimeTypes() 335void LauncherIconView::updateCategoriesAndMimeTypes()
336{ 336{
337 mimes.clear(); 337 mimes.clear();
338 cats.clear(); 338 cats.clear();
339 LauncherItem* item = (LauncherItem*)firstItem(); 339 LauncherItem* item = (LauncherItem*)firstItem();
340 while (item) { 340 while (item) {
341 addCatsAndMimes(item->appLnk()); 341 addCatsAndMimes(item->appLnk());
342 item = (LauncherItem*)item->nextItem(); 342 item = (LauncherItem*)item->nextItem();
343 } 343 }
344 QListIterator<AppLnk> it(hidden); 344 QListIterator<AppLnk> it(hidden);
345 AppLnk* l; 345 AppLnk* l;
346 while ((l=it.current())) { 346 while ((l=it.current())) {
347 addCatsAndMimes(l); 347 addCatsAndMimes(l);
348 ++it; 348 ++it;
349 } 349 }
350} 350}
351 351
352void LauncherIconView::hideOrShowItems(bool resort) 352void LauncherIconView::hideOrShowItems(bool resort)
353{ 353{
354 hidden.setAutoDelete(FALSE); 354 hidden.setAutoDelete(FALSE);
355 QList<AppLnk> links=hidden; 355 QList<AppLnk> links=hidden;
356 hidden.clear(); 356 hidden.clear();
357 hidden.setAutoDelete(TRUE); 357 hidden.setAutoDelete(TRUE);
358 LauncherItem* item = (LauncherItem*)firstItem(); 358 LauncherItem* item = (LauncherItem*)firstItem();
359 while (item) { 359 while (item) {
360 links.append(item->takeAppLnk()); 360 links.append(item->takeAppLnk());
361 item = (LauncherItem*)item->nextItem(); 361 item = (LauncherItem*)item->nextItem();
362 } 362 }
363 bool oldAutoArrange = autoArrange(); 363 bool oldAutoArrange = autoArrange();
364 setAutoArrange( FALSE ); 364 setAutoArrange( FALSE );
365 clear(); 365 clear();
366 QListIterator<AppLnk> it(links); 366 QListIterator<AppLnk> it(links);
367 AppLnk* l; 367 AppLnk* l;
368 while ((l=it.current())) { 368 while ((l=it.current())) {
369 addItem(l,FALSE); 369 addItem(l,FALSE);
370 ++it; 370 ++it;
371 } 371 }
372 if ( resort ) 372 if ( resort )
373 sort(); 373 sort();
374 setAutoArrange( oldAutoArrange ); 374 setAutoArrange( oldAutoArrange );
375} 375}
376 376
377bool LauncherIconView::removeLink(const QString& linkfile) 377bool LauncherIconView::removeLink(const QString& linkfile)
378{ 378{
379 LauncherItem* item = (LauncherItem*)firstItem(); 379 LauncherItem* item = (LauncherItem*)firstItem();
380 AppLnk* l; 380 AppLnk* l;
381 bool did = FALSE; 381 bool did = FALSE;
382 DocLnk dl(linkfile); 382 DocLnk dl(linkfile);
383 while (item) { 383 while (item) {
384 l = item->appLnk(); 384 l = item->appLnk();
385 if ( l->linkFileKnown() && l->linkFile() == linkfile || l->file() == linkfile 385 if ( l->linkFileKnown() && l->linkFile() == linkfile || l->file() == linkfile
386 || dl.isValid() && dl.file() == l->file() ) { 386 || dl.isValid() && dl.file() == l->file() ) {
387 delete item; 387 delete item;
388 did = TRUE; 388 did = TRUE;
389 } 389 }
390 item = (LauncherItem*)item->nextItem(); 390 item = (LauncherItem*)item->nextItem();
391 } 391 }
392 QListIterator<AppLnk> it(hidden); 392 QListIterator<AppLnk> it(hidden);
393 while ((l=it.current())) { 393 while ((l=it.current())) {
394 ++it; 394 ++it;
395 if ( l->linkFileKnown() && l->linkFile() == linkfile 395 if ( l->linkFileKnown() && l->linkFile() == linkfile
396 || l->file() == linkfile 396 || l->file() == linkfile
397 || dl.isValid() && dl.file() == l->file() ) { 397 || dl.isValid() && dl.file() == l->file() ) {
398 hidden.removeRef(l); 398 hidden.removeRef(l);
399 did = TRUE; 399 did = TRUE;
400 } 400 }
401 } 401 }
402 return did; 402 return did;
403} 403}
404 404
405LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) 405LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
406 : QVBox( parent, name, fl ) 406 : QVBox( parent, name, fl )
407{ 407{
408 icons = new LauncherIconView( this ); 408 icons = new LauncherIconView( this );
409 setFocusProxy(icons); 409 setFocusProxy(icons);
410 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); 410 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );
411 411
412 int dw = QApplication::desktop()->width(); 412 int dw = QApplication::desktop()->width();
413 icons->setItemsMovable( FALSE ); 413 icons->setItemsMovable( FALSE );
414 icons->setAutoArrange( TRUE ); 414 icons->setAutoArrange( TRUE );
415 icons->setSorting( TRUE ); 415 icons->setSorting( TRUE );
416 icons->setGridX( (dw-13-style().scrollBarExtent().width())/3 ); // tweaked for 8pt+dw=176 and 10pt+dw=240 416 icons->setGridX( (dw-13-style().scrollBarExtent().width())/3 ); // tweaked for 8pt+dw=176 and 10pt+dw=240
417 icons->setGridY( fontMetrics().height()*2+24 ); 417 icons->setGridY( fontMetrics().height()*2+24 );
418 icons->setFrameStyle( QFrame::NoFrame ); 418 icons->setFrameStyle( QFrame::NoFrame );
419 icons->setSpacing( 4 ); 419 icons->setSpacing( 4 );
420 icons->setMargin( 0 ); 420 icons->setMargin( 0 );
421 icons->setSelectionMode( QIconView::Multi ); 421 icons->setSelectionMode( QIconView::Multi );
422 icons->setBackgroundMode( PaletteBase ); 422 icons->setBackgroundMode( PaletteBase );
423 423
424 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), 424 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)),
425 SLOT(itemClicked(int, QIconViewItem *)) ); 425 SLOT(itemClicked(int, QIconViewItem *)) );
426 connect( icons, SIGNAL(selectionChanged()), 426 connect( icons, SIGNAL(selectionChanged()),
427 SLOT(selectionChanged()) ); 427 SLOT(selectionChanged()) );
428 connect( icons, SIGNAL(returnPressed(QIconViewItem *)), 428 connect( icons, SIGNAL(returnPressed(QIconViewItem *)),
429 SLOT(returnPressed(QIconViewItem *)) ); 429 SLOT(returnPressed(QIconViewItem *)) );
430 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), 430 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)),
431 SLOT(itemPressed(int, QIconViewItem *)) ); 431 SLOT(itemPressed(int, QIconViewItem *)) );
432 432
433 tools = 0; 433 tools = 0;
434} 434}
435 435
436LauncherView::~LauncherView() 436LauncherView::~LauncherView()
437{ 437{
438} 438}
439 439
440void LauncherView::setToolsEnabled(bool y) 440void LauncherView::setToolsEnabled(bool y)
441{ 441{
442 if ( !y != !tools ) { 442 if ( !y != !tools ) {
443 if ( y ) { 443 if ( y ) {
444 tools = new QHBox(this); 444 tools = new QHBox(this);
445 445
446 // Type filter 446 // Type filter
447 typemb = new MenuButton(tools); 447 typemb = new MenuButton(tools);
448 typemb->setLabel(tr("Type: %1")); 448 typemb->setLabel(tr("Type: %1"));
449 449
450 // Category filter 450 // Category filter
451 catmb = new CategorySelect(tools); 451 catmb = new CategorySelect(tools);
452 452
453 updateTools(); 453 updateTools();
454 tools->show(); 454 tools->show();
455 } else { 455 } else {
456 delete tools; 456 delete tools;
457 tools = 0; 457 tools = 0;
458 } 458 }
459 } 459 }
460} 460}
461 461
462void LauncherView::updateTools() 462void LauncherView::updateTools()
463{ 463{
464 disconnect( typemb, SIGNAL(selected(const QString&)), 464 disconnect( typemb, SIGNAL(selected(const QString&)),
465 this, SLOT(showType(const QString&)) ); 465 this, SLOT(showType(const QString&)) );
466 disconnect( catmb, SIGNAL(signalSelected(int)), 466 disconnect( catmb, SIGNAL(signalSelected(int)),
467 this, SLOT(showCategory(int)) ); 467 this, SLOT(showCategory(int)) );
468 468
469 icons->updateCategoriesAndMimeTypes(); 469 icons->updateCategoriesAndMimeTypes();
470 470
471 QString prev; 471 QString prev;
472 472
473 // Type filter 473 // Type filter
474 QStringList types; 474 QStringList types;
475 types << tr("All"); 475 types << tr("All");
476 types << "--"; 476 types << "--";
477 types += icons->mimeTypes(); 477 types += icons->mimeTypes();
478 prev = typemb->currentText(); 478 prev = typemb->currentText();
479 typemb->clear(); 479 typemb->clear();
480 typemb->insertItems(types); 480 typemb->insertItems(types);
481 typemb->select(prev); 481 typemb->select(prev);
482 482
483 Categories cats( 0 ); 483 Categories cats( 0 );
484 cats.load( categoryFileName() ); 484 cats.load( categoryFileName() );
485 QArray<int> vl( 0 ); 485 QArray<int> vl( 0 );
486 catmb->setCategories( vl, "Document View", tr("Document View") ); 486 catmb->setCategories( vl, "Document View", tr("Document View") );
487 catmb->setRemoveCategoryEdit( TRUE ); 487 catmb->setRemoveCategoryEdit( TRUE );
488 catmb->setAllCategories( TRUE ); 488 catmb->setAllCategories( TRUE );
489 489
490 connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); 490 connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&)));
491 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 491 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
492} 492}
493 493
494void LauncherView::sortBy(int s) 494void LauncherView::sortBy(int s)
495{ 495{
496 icons->setSortMethod((LauncherIconView::SortMethod)s); 496 icons->setSortMethod((LauncherIconView::SortMethod)s);
497} 497}
498 498
499void LauncherView::showType(const QString& t) 499void LauncherView::showType(const QString& t)
500{ 500{
501 if ( t == tr("All") ) { 501 if ( t == tr("All") ) {
502 icons->setTypeFilter("",TRUE); 502 icons->setTypeFilter("",TRUE);
503 } else { 503 } else {
504 icons->setTypeFilter(t+"/*",TRUE); 504 icons->setTypeFilter(t+"/*",TRUE);
505 } 505 }
506} 506}
507 507
508void LauncherView::showCategory( int c ) 508void LauncherView::showCategory( int c )
509{ 509{
510 icons->setCategoryFilter( c, TRUE ); 510 icons->setCategoryFilter( c, TRUE );
511} 511}
512 512
513void LauncherView::resizeEvent(QResizeEvent *e) 513void LauncherView::resizeEvent(QResizeEvent *e)
514{ 514{
515 QVBox::resizeEvent( e ); 515 QVBox::resizeEvent( e );
516 if ( e->size().width() != e->oldSize().width() ) 516 if ( e->size().width() != e->oldSize().width() )
517 sort(); 517 sort();
518} 518}
519 519
520void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) 520void LauncherView::populate( AppLnkSet *folder, const QString& typefilter )
521{ 521{
522 icons->clear(); 522 icons->clear();
523 internalPopulate( folder, typefilter ); 523 internalPopulate( folder, typefilter );
524} 524}
525 525
526void LauncherView::selectionChanged() 526void LauncherView::selectionChanged()
527{ 527{
528 QIconViewItem* item = icons->currentItem(); 528 QIconViewItem* item = icons->currentItem();
529 if ( item && item->isSelected() ) { 529 if ( item && item->isSelected() ) {
530 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 530 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
531 if ( icons->inKeyEvent() ) // not for mouse press 531 if ( icons->inKeyEvent() ) // not for mouse press
532 emit clicked( appLnk ); 532 emit clicked( appLnk );
533 item->setSelected(FALSE); 533 item->setSelected(FALSE);
534 } 534 }
535} 535}
536 536
537void LauncherView::returnPressed( QIconViewItem *item ) 537void LauncherView::returnPressed( QIconViewItem *item )
538{ 538{
539 if ( item ) { 539 if ( item ) {
540 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 540 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
541 emit clicked( appLnk ); 541 emit clicked( appLnk );
542 } 542 }
543} 543}
544 544
545void LauncherView::itemClicked( int btn, QIconViewItem *item ) 545void LauncherView::itemClicked( int btn, QIconViewItem *item )
546{ 546{
547 if ( item ) { 547 if ( item ) {
548 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 548 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
549 if ( btn == LeftButton ) { 549 if ( btn == LeftButton ) {
550 // Make sure it's the item we execute that gets highlighted 550 // Make sure it's the item we execute that gets highlighted
551 icons->setCurrentItem( item ); 551 icons->setCurrentItem( item );
552 emit clicked( appLnk ); 552 emit clicked( appLnk );
553 } 553 }
554 item->setSelected(FALSE); 554 item->setSelected(FALSE);
555 } 555 }
556} 556}
557 557
558void LauncherView::itemPressed( int btn, QIconViewItem *item ) 558void LauncherView::itemPressed( int btn, QIconViewItem *item )
559{ 559{
560 if ( item ) { 560 if ( item ) {
561 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 561 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
562 if ( btn == RightButton ) 562 if ( btn == RightButton )
563 emit rightPressed( appLnk ); 563 emit rightPressed( appLnk );
564/* 564/*
565 else if ( btn == LeftButton ) 565 else if ( btn == LeftButton )
566 emit clicked( appLnk ); 566 emit clicked( appLnk );
567*/ 567*/
568 item->setSelected(FALSE); 568 item->setSelected(FALSE);
569 } 569 }
570} 570}
571 571
572void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) 572void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter )
573{ 573{
574 QListIterator<AppLnk> it( folder->children() ); 574 QListIterator<AppLnk> it( folder->children() );
575 icons->setTypeFilter(typefilter,FALSE); 575 icons->setTypeFilter(typefilter,FALSE);
576 576
577 while ( it.current() ) { 577 while ( it.current() ) {
578 icons->addItem(*it,FALSE); 578 // show only the icons for existing files
579 if (!QFile(it.current()->file()).exists() )
580 {
581 //maybe insert some .desktop file deletion code later
582 //maybe dir specific
583 }
584 else
585 {
586 icons->addItem(*it,FALSE);
587 }
579 ++it; 588 ++it;
580 } 589 }
581 590
582 icons->sort(); 591 icons->sort();
583} 592}
584 593
585bool LauncherView::removeLink(const QString& linkfile) 594bool LauncherView::removeLink(const QString& linkfile)
586{ 595{
587 return icons->removeLink(linkfile); 596 return icons->removeLink(linkfile);
588} 597}
589 598
590void LauncherView::sort() 599void LauncherView::sort()
591{ 600{
592 icons->sort(); 601 icons->sort();
593} 602}
594 603
595void LauncherView::addItem(AppLnk* app, bool resort) 604void LauncherView::addItem(AppLnk* app, bool resort)
596{ 605{
597 icons->addItem(app,resort); 606 icons->addItem(app,resort);
598} 607}
599 608
600void LauncherView::setFileSystems(const QList<FileSystem> &) 609void LauncherView::setFileSystems(const QList<FileSystem> &)
601{ 610{
602 // ### does nothing now... 611 // ### does nothing now...
603} 612}