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