summaryrefslogtreecommitdiff
path: root/core/launcher/launcherview.cpp
Unidiff
Diffstat (limited to 'core/launcher/launcherview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp470
1 files changed, 351 insertions, 119 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index c54a00f..047fe45 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,7 +1,7 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of 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
@@ -23,14 +23,16 @@
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>
27#include <qpe/categories.h> 26#include <qpe/categories.h>
28#include <qpe/categoryselect.h> 27#include <qpe/categoryselect.h>
29#include <qpe/menubutton.h> 28#include <qpe/menubutton.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 33
33#include <qtimer.h> 34#include <qtimer.h>
35#include <qtextstream.h>
34#include <qdict.h> 36#include <qdict.h>
35#include <qfile.h> 37#include <qfile.h>
36#include <qfileinfo.h> 38#include <qfileinfo.h>
@@ -39,26 +41,33 @@
39#include <qpainter.h> 41#include <qpainter.h>
40#include <qregexp.h> 42#include <qregexp.h>
41#include <qtoolbutton.h> 43#include <qtoolbutton.h>
44#include <qimage.h>
42 45
43class LauncherIconView : public QIconView { 46
47class BgPixmap
48{
44public: 49public:
45 QColor iconText; 50 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
46 QColor background; 51 QPixmap pm;
52 int ref;
53};
47 54
55static QMap<QString,BgPixmap*> *bgCache = 0;
56
57class LauncherIconView : public QIconView {
58public:
48 LauncherIconView( QWidget* parent, const char* name=0 ) : 59 LauncherIconView( QWidget* parent, const char* name=0 ) :
49 QIconView(parent,name), 60 QIconView(parent,name),
50 tf(""), 61 tf(""),
51 cf(0), 62 cf(0),
52 bsy(0) 63 bsy(0),
64 bigIcns(TRUE),
65 bgColor(white)
53 { 66 {
54 sortmeth = Name; 67 sortmeth = Name;
55 hidden.setAutoDelete(TRUE); 68 hidden.setAutoDelete(TRUE);
56 ike = FALSE; 69 ike = FALSE;
57 70 calculateGrid( Bottom );
58 Config config( "qpe" );
59 config.setGroup( "Appearance" );
60 iconText = QColor( config.readEntry( "LauncherIconText", "#000000" ) );
61 background = QColor( config.readEntry( "LauncherBackground", "#FFFFFF" ) );
62 } 71 }
63 72
64 ~LauncherIconView() 73 ~LauncherIconView()
@@ -73,7 +82,9 @@ public:
73#endif 82#endif
74 } 83 }
75 84
85 QPixmap* busyPixmap() const { return (QPixmap*)&bpm; }
76 QIconViewItem* busyItem() const { return bsy; } 86 QIconViewItem* busyItem() const { return bsy; }
87 void setBigIcons( bool bi ) { bigIcns = bi; }
77 88
78 void updateCategoriesAndMimeTypes(); 89 void updateCategoriesAndMimeTypes();
79 90
@@ -86,6 +97,31 @@ public:
86 { 97 {
87 QIconViewItem *c = on ? currentItem() : 0; 98 QIconViewItem *c = on ? currentItem() : 0;
88 if ( bsy != c ) { 99 if ( bsy != c ) {
100 if ( c ) {
101 QPixmap *src = c->pixmap();
102 QImage img = src->convertToImage();
103 QRgb* rgb;
104 int count;
105 if ( img.depth() == 32 ) {
106 rgb = (QRgb*)img.bits();
107 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
108 } else {
109 rgb = img.colorTable();
110 count = img.numColors();
111 }
112 int rc, gc, bc;
113 colorGroup().highlight().rgb( &rc, &gc, &bc );
114 int ri, gi, bi;
115 for ( int r = 0; r < count; r++, rgb++ ) {
116 int ri = (rc+qRed(*rgb))/2;
117 int gi = (gc+qGreen(*rgb))/2;
118 int bi = (bc+qBlue(*rgb))/2;
119 int ai = qAlpha(*rgb);
120 *rgb = qRgba(ri,gi,bi,ai);
121 }
122
123 bpm.convertFromImage( img );
124 }
89 QIconViewItem* o = bsy; 125 QIconViewItem* o = bsy;
90 bsy = c; 126 bsy = c;
91 if ( o ) o->repaint(); 127 if ( o ) o->repaint();
@@ -97,10 +133,8 @@ public:
97 void keyPressEvent(QKeyEvent* e) 133 void keyPressEvent(QKeyEvent* e)
98 { 134 {
99 ike = TRUE; 135 ike = TRUE;
100 if ( e->key() == Key_F33 ) { 136 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
101 // "OK" button
102 returnPressed(currentItem()); 137 returnPressed(currentItem());
103 }
104 QIconView::keyPressEvent(e); 138 QIconView::keyPressEvent(e);
105 ike = FALSE; 139 ike = FALSE;
106 } 140 }
@@ -128,70 +162,35 @@ public:
128 QString maj=app->type(); 162 QString maj=app->type();
129 int sl=maj.find('/'); 163 int sl=maj.find('/');
130 if (sl>=0) { 164 if (sl>=0) {
131 QString k = maj.left(sl); 165 QString k;
166 k = maj.left(12) == "application/" ? maj : maj.left(sl);
132 mimes.replace(k,(void*)1); 167 mimes.replace(k,(void*)1);
133 } 168 }
134 } 169 }
135 170
171 void setBackgroundPixmap( const QPixmap &pm ) {
172 bgPixmap = pm;
173 }
174
175 void setBackgroundColor( const QColor &c ) {
176 bgColor = c;
177 }
178
136 void drawBackground( QPainter *p, const QRect &r ) 179 void drawBackground( QPainter *p, const QRect &r )
137 { 180 {
138 Config config("qpe"); 181 if ( !bgPixmap.isNull() ) {
139 config.setGroup("Appearance"); 182 p->drawTiledPixmap( r, bgPixmap,
140 QString backgroundImage = config.readEntry("BackgroundImage","launcher/opie-background"); 183 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
141 // if (backgroundImage.isNull()) backgroundImage="launcher/opie-background"; 184 (r.y() + contentsY()) % bgPixmap.height() ) );
142 int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0;
143 //int backgroundMode = 2;
144
145 if ( backgroundMode == 1 ) {
146
147 // Double buffer the background
148 static QPixmap *bg = NULL;
149 static QColor bgColor;
150
151 if ( (bg == NULL) || (bgColor != colorGroup().button()) ) {
152 // Create a new background double buffer
153 if (bg == NULL)
154 bg = new QPixmap( width(), height() );
155 bgColor = colorGroup().button();
156 QPainter painter( bg );
157
158// painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110));
159 painter.fillRect( QRect( 0, 0, width(), height() ), background);
160 // Overlay the Qtopia logo in the center
161 QImage logo;
162 if (QFile::exists(backgroundImage)) {
163 logo = QImage(backgroundImage);
164 } else { 185 } else {
165 logo = Resource::loadImage(backgroundImage ); 186 p->fillRect( r, bgColor );
166 }
167 if ( !logo.isNull() && config.readBoolEntry( "UseBackgroundImage", TRUE ) )
168 painter.drawImage( (width() - logo.width()) / 2,
169 (height() - logo.height()) / 2, logo );
170 }
171
172 // Draw the double buffer to the widget (it is tiled for when the icon view is large)
173 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(),
174 (r.y() + contentsY()) % bg->height() ) );
175 } else if ( backgroundMode == 2 ) {
176 static QPixmap *bg = 0;
177 static QColor bgColor;
178 if ( !bg || (bgColor != colorGroup().background()) ) {
179 bgColor = colorGroup().background();
180 bg = new QPixmap( width(), 9 );
181 QPainter painter( bg );
182 for ( int i = 0; i < 3; i++ ) {
183 painter.setPen( colorGroup().background().light(130) );
184 painter.drawLine( 0, i*3, width()-1, i*3 );
185 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
186 painter.setPen( colorGroup().background().light(105) );
187 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
188 }
189 } 187 }
190 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(),
191 (r.y() + contentsY()) % bg->height() ) );
192 } else {
193 p->fillRect( r, QBrush( colorGroup().background().light(110) ) );
194 } 188 }
189
190 void setItemTextPos( ItemTextPos pos )
191 {
192 calculateGrid( pos );
193 QIconView::setItemTextPos( pos );
195 } 194 }
196 195
197 void hideOrShowItems(bool resort); 196 void hideOrShowItems(bool resort);
@@ -240,14 +239,39 @@ public:
240 return 0; 239 return 0;
241 } 240 }
242 241
242 QString getAllDocLinkInfo() const;
243
243protected: 244protected:
244 245
245 void styleChange( QStyle &old ) 246 void styleChange( QStyle &old )
246 { 247 {
247 QIconView::styleChange( old ); 248 QIconView::styleChange( old );
248 //### duplicated code from LauncherView constructor 249 calculateGrid( itemTextPos() );
250 }
251
252 void calculateGrid( ItemTextPos pos )
253 {
249 int dw = QApplication::desktop()->width(); 254 int dw = QApplication::desktop()->width();
250 setGridX( (dw-13-style().scrollBarExtent().width())/ (dw/80) ); // tweaked for 8pt+dw=176 and 10pt+dw=240 255 int viewerWidth = dw-style().scrollBarExtent().width();
256 if ( pos == Bottom ) {
257 int cols = 3;
258 if ( viewerWidth <= 200 )
259 cols = 2;
260 else if ( viewerWidth >= 400 )
261 cols = viewerWidth/96;
262 setSpacing( 4 );
263 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
264 setGridY( fontMetrics().height()*2+24 );
265 } else {
266 int cols = 2;
267 if ( viewerWidth < 150 )
268 cols = 1;
269 else if ( viewerWidth >= 400 )
270 cols = viewerWidth/150;
271 setSpacing( 2 );
272 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
273 setGridY( fontMetrics().height()+2 );
274 }
251 } 275 }
252 276
253private: 277private:
@@ -259,7 +283,10 @@ private:
259 int cf; 283 int cf;
260 QIconViewItem* bsy; 284 QIconViewItem* bsy;
261 bool ike; 285 bool ike;
262 286 bool bigIcns;
287 QPixmap bgPixmap;
288 QPixmap bpm;
289 QColor bgColor;
263}; 290};
264 291
265 292
@@ -273,7 +300,7 @@ void LauncherView::setBusy(bool on)
273class LauncherItem : public QIconViewItem 300class LauncherItem : public QIconViewItem
274{ 301{
275public: 302public:
276 LauncherItem( QIconView *parent, AppLnk* applnk ); 303 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
277 ~LauncherItem() 304 ~LauncherItem()
278 { 305 {
279 LauncherIconView* liv = (LauncherIconView*)iconView(); 306 LauncherIconView* liv = (LauncherIconView*)iconView();
@@ -296,19 +323,17 @@ public:
296 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 323 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
297 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 324 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
298 } 325 }
299 else {
300 mycg.setColor( QColorGroup::Text, liv->iconText );
301 }
302
303 QIconViewItem::paintItem(p,mycg); 326 QIconViewItem::paintItem(p,mycg);
304 if ( liv->currentItem() == this ) 327 if ( liv->currentItem() == this )
305 liv->setItemTextBackground( oldBrush ); 328 liv->setItemTextBackground( oldBrush );
306 if ( liv->busyItem() == this ) {
307 static QPixmap* busypm=0;
308 if ( !busypm )
309 busypm = new QPixmap(Resource::loadPixmap("launching"));
310 p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm);
311 } 329 }
330
331 virtual QPixmap* pixmap () const
332 {
333 const LauncherIconView* liv = (LauncherIconView*)iconView();
334 if ( (const LauncherItem *)liv->busyItem() == this )
335 return liv->busyPixmap();
336 return QIconViewItem::pixmap();
312 } 337 }
313 338
314protected: 339protected:
@@ -316,8 +341,9 @@ protected:
316}; 341};
317 342
318 343
319LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk ) 344LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon )
320 : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ), 345 : QIconViewItem( parent, applnk->name(),
346 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
321 app(applnk) // Takes ownership 347 app(applnk) // Takes ownership
322{ 348{
323} 349}
@@ -347,7 +373,7 @@ void LauncherIconView::addItem(AppLnk* app, bool resort)
347 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 373 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
348 && (cf == 0 || app->categories().contains(cf) 374 && (cf == 0 || app->categories().contains(cf)
349 || cf == -1 && app->categories().count() == 0 ) ) 375 || cf == -1 && app->categories().count() == 0 ) )
350 (void) new LauncherItem( this, app ); 376 (void) new LauncherItem( this, app, bigIcns );
351 else 377 else
352 hidden.append(app); 378 hidden.append(app);
353 if ( resort ) 379 if ( resort )
@@ -382,8 +408,7 @@ void LauncherIconView::hideOrShowItems(bool resort)
382 links.append(item->takeAppLnk()); 408 links.append(item->takeAppLnk());
383 item = (LauncherItem*)item->nextItem(); 409 item = (LauncherItem*)item->nextItem();
384 } 410 }
385 bool oldAutoArrange = autoArrange(); 411 viewport()->setUpdatesEnabled( FALSE );
386 setAutoArrange( FALSE );
387 clear(); 412 clear();
388 QListIterator<AppLnk> it(links); 413 QListIterator<AppLnk> it(links);
389 AppLnk* l; 414 AppLnk* l;
@@ -391,9 +416,9 @@ void LauncherIconView::hideOrShowItems(bool resort)
391 addItem(l,FALSE); 416 addItem(l,FALSE);
392 ++it; 417 ++it;
393 } 418 }
394 if ( resort ) 419 viewport()->setUpdatesEnabled( TRUE );
420 if ( resort && !autoArrange() )
395 sort(); 421 sort();
396 setAutoArrange( oldAutoArrange );
397} 422}
398 423
399bool LauncherIconView::removeLink(const QString& linkfile) 424bool LauncherIconView::removeLink(const QString& linkfile)
@@ -404,7 +429,10 @@ bool LauncherIconView::removeLink(const QString& linkfile)
404 DocLnk dl(linkfile); 429 DocLnk dl(linkfile);
405 while (item) { 430 while (item) {
406 l = item->appLnk(); 431 l = item->appLnk();
407 if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { 432 if ( l->linkFileKnown() && l->linkFile() == linkfile
433 || l->fileKnown() && (
434 l->file() == linkfile
435 || dl.isValid() && dl.file() == l->file() ) ) {
408 delete item; 436 delete item;
409 did = TRUE; 437 did = TRUE;
410 } 438 }
@@ -413,7 +441,9 @@ bool LauncherIconView::removeLink(const QString& linkfile)
413 QListIterator<AppLnk> it(hidden); 441 QListIterator<AppLnk> it(hidden);
414 while ((l=it.current())) { 442 while ((l=it.current())) {
415 ++it; 443 ++it;
416 if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { 444 if ( l->linkFileKnown() && l->linkFile() == linkfile
445 || l->file() == linkfile
446 || dl.isValid() && dl.file() == l->file() ) {
417 hidden.removeRef(l); 447 hidden.removeRef(l);
418 did = TRUE; 448 did = TRUE;
419 } 449 }
@@ -421,6 +451,59 @@ bool LauncherIconView::removeLink(const QString& linkfile)
421 return did; 451 return did;
422} 452}
423 453
454static QString docLinkInfo(const Categories& cats, DocLnk* doc)
455{
456 QString contents;
457
458 QFileInfo fi( doc->file() );
459 if ( !fi.exists() )
460 return contents;
461
462 if ( doc->linkFileKnown() ) {
463 QString lfn = doc->linkFile();
464 QFile f( lfn );
465 if ( f.open( IO_ReadOnly ) ) {
466 QTextStream ts( &f );
467 ts.setEncoding( QTextStream::UnicodeUTF8 );
468 contents += ts.read();
469 f.close();
470 goto calcsize;
471 }
472 }
473
474 contents += "[Desktop Entry]\n";
475 contents += "Categories = " // No tr
476 + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr
477 contents += "File = "+doc->file()+"\n"; // No tr
478 contents += "Name = "+doc->name()+"\n"; // No tr
479 contents += "Type = "+doc->type()+"\n"; // No tr
480
481calcsize:
482 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
483 return contents;
484}
485
486QString LauncherIconView::getAllDocLinkInfo() const
487{
488 QString contents;
489 LauncherItem* item = (LauncherItem*)firstItem();
490 Categories cats;
491 while (item) {
492 DocLnk* doc = (DocLnk*)item->appLnk();
493 contents += docLinkInfo(cats,doc);
494 item = (LauncherItem*)item->nextItem();
495 }
496 QListIterator<AppLnk> it(hidden);
497 DocLnk* doc;
498 while ((doc=(DocLnk*)it.current())) {
499 contents += docLinkInfo(cats,doc);
500 ++it;
501 }
502 return contents;
503}
504
505//===========================================================================
506
424LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) 507LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
425 : QVBox( parent, name, fl ) 508 : QVBox( parent, name, fl )
426{ 509{
@@ -428,17 +511,16 @@ LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
428 setFocusProxy(icons); 511 setFocusProxy(icons);
429 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); 512 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );
430 513
431 int dw = QApplication::desktop()->width();
432 icons->setItemsMovable( FALSE ); 514 icons->setItemsMovable( FALSE );
433 icons->setAutoArrange( TRUE ); 515 icons->setAutoArrange( TRUE );
434 icons->setSorting( TRUE ); 516 icons->setSorting( TRUE );
435 icons->setGridX( (dw-13-style().scrollBarExtent().width())/ (dw/80) ); // tweaked for 8pt+dw=176 and 10pt+dw=240
436 icons->setGridY( fontMetrics().height()*2+24 );
437 icons->setFrameStyle( QFrame::NoFrame ); 517 icons->setFrameStyle( QFrame::NoFrame );
438 icons->setSpacing( 4 );
439 icons->setMargin( 0 ); 518 icons->setMargin( 0 );
440 icons->setSelectionMode( QIconView::Multi ); 519 icons->setSelectionMode( QIconView::NoSelection );
441 icons->setBackgroundMode( PaletteBase ); 520 icons->setBackgroundMode( PaletteBase );
521 icons->setResizeMode( QIconView::Fixed );
522 vmode = (ViewMode)-1;
523 setViewMode( Icon );
442 524
443 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), 525 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)),
444 SLOT(itemClicked(int, QIconViewItem *)) ); 526 SLOT(itemClicked(int, QIconViewItem *)) );
@@ -450,6 +532,7 @@ LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
450 SLOT(itemPressed(int, QIconViewItem *)) ); 532 SLOT(itemPressed(int, QIconViewItem *)) );
451 533
452 tools = 0; 534 tools = 0;
535 setBackgroundType( Ruled, QString::null );
453} 536}
454 537
455LauncherView::~LauncherView() 538LauncherView::~LauncherView()
@@ -463,13 +546,10 @@ void LauncherView::setToolsEnabled(bool y)
463 tools = new QHBox(this); 546 tools = new QHBox(this);
464 547
465 // Type filter 548 // Type filter
466 typemb = new MenuButton(tools); 549 typemb = new QComboBox(tools);
467 typemb->setLabel(tr("Type: %1"));
468 typemb->setFixedHeight ( 20 );
469 550
470 // Category filter 551 // Category filter
471 catmb = new CategorySelect(tools); 552 catmb = new CategorySelect(tools);
472 catmb->setFixedHeight ( 20 );
473 553
474 updateTools(); 554 updateTools();
475 tools->show(); 555 tools->show();
@@ -482,8 +562,8 @@ void LauncherView::setToolsEnabled(bool y)
482 562
483void LauncherView::updateTools() 563void LauncherView::updateTools()
484{ 564{
485 disconnect( typemb, SIGNAL(selected(const QString&)), 565 disconnect( typemb, SIGNAL(activated(int)),
486 this, SLOT(showType(const QString&)) ); 566 this, SLOT(showType(int)) );
487 disconnect( catmb, SIGNAL(signalSelected(int)), 567 disconnect( catmb, SIGNAL(signalSelected(int)),
488 this, SLOT(showCategory(int)) ); 568 this, SLOT(showCategory(int)) );
489 569
@@ -493,22 +573,43 @@ void LauncherView::updateTools()
493 573
494 // Type filter 574 // Type filter
495 QStringList types; 575 QStringList types;
496 types << tr("All"); 576 typelist = icons->mimeTypes();
497 types << "--"; 577 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) {
498 types += icons->mimeTypes(); 578 QString t = *it;
579 if ( t.left(12) == "application/" ) {
580 MimeType mt(t);
581 const AppLnk* app = mt.application();
582 if ( app )
583 t = app->name();
584 else
585 t = t.mid(12);
586 } else {
587 t[0] = t[0].upper();
588 }
589 types += tr("%1 files").arg(t);
590 }
591 types << tr("All types of file");
499 prev = typemb->currentText(); 592 prev = typemb->currentText();
500 typemb->clear(); 593 typemb->clear();
501 typemb->insertItems(types); 594 typemb->insertStringList(types);
502 typemb->select(prev); 595 for (int i=0; i<typemb->count(); i++) {
596 if ( typemb->text(i) == prev ) {
597 typemb->setCurrentItem(i);
598 break;
599 }
600 }
601 if ( prev.isNull() )
602 typemb->setCurrentItem(typemb->count()-1);
503 603
504 Categories cats( 0 ); 604 Categories cats( 0 );
505 cats.load( categoryFileName() ); 605 cats.load( categoryFileName() );
506 QArray<int> vl( 0 ); 606 QArray<int> vl( 0 );
507 catmb->setCategories( vl, "Document View", tr("Document View") ); 607 catmb->setCategories( vl, "Document View", // No tr
608 tr("Document View") );
508 catmb->setRemoveCategoryEdit( TRUE ); 609 catmb->setRemoveCategoryEdit( TRUE );
509 catmb->setAllCategories( TRUE ); 610 catmb->setAllCategories( TRUE );
510 611
511 connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); 612 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
512 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 613 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
513} 614}
514 615
@@ -517,12 +618,15 @@ void LauncherView::sortBy(int s)
517 icons->setSortMethod((LauncherIconView::SortMethod)s); 618 icons->setSortMethod((LauncherIconView::SortMethod)s);
518} 619}
519 620
520void LauncherView::showType(const QString& t) 621void LauncherView::showType(int t)
521{ 622{
522 if ( t == tr("All") ) { 623 if ( t >= (int)typelist.count() ) {
523 icons->setTypeFilter("",TRUE); 624 icons->setTypeFilter("",TRUE);
524 } else { 625 } else {
525 icons->setTypeFilter(t+"/*",TRUE); 626 QString ty = typelist[t];
627 if ( !ty.contains('/') )
628 ty += "/*";
629 icons->setTypeFilter(ty,TRUE);
526 } 630 }
527} 631}
528 632
@@ -531,6 +635,119 @@ void LauncherView::showCategory( int c )
531 icons->setCategoryFilter( c, TRUE ); 635 icons->setCategoryFilter( c, TRUE );
532} 636}
533 637
638void LauncherView::setViewMode( ViewMode m )
639{
640 if ( vmode != m ) {
641 bool bigIcons = m == Icon;
642 icons->viewport()->setUpdatesEnabled( FALSE );
643 icons->setBigIcons( bigIcons );
644 switch ( m ) {
645 case List:
646 icons->setItemTextPos( QIconView::Right );
647 break;
648 case Icon:
649 icons->setItemTextPos( QIconView::Bottom );
650 break;
651 }
652 icons->hideOrShowItems( FALSE );
653 icons->viewport()->setUpdatesEnabled( TRUE );
654 vmode = m;
655 }
656}
657
658void LauncherView::setBackgroundType( BackgroundType t, const QString &val )
659{
660 if ( !bgCache )
661 bgCache = new QMap<QString,BgPixmap*>;
662 if ( bgCache->contains( bgName ) )
663 (*bgCache)[bgName]->ref--;
664
665 switch ( t ) {
666 case Ruled: {
667 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr
668 QPixmap bg;
669 if ( bgCache->contains( bgName ) ) {
670 (*bgCache)[bgName]->ref++;
671 bg = (*bgCache)[bgName]->pm;
672 } else {
673 bg.resize( width(), 9 );
674 QPainter painter( &bg );
675 for ( int i = 0; i < 3; i++ ) {
676 painter.setPen( white );
677 painter.drawLine( 0, i*3, width()-1, i*3 );
678 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
679 painter.setPen( colorGroup().background().light(105) );
680 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
681 }
682 painter.end();
683 bgCache->insert( bgName, new BgPixmap(bg) );
684 }
685 icons->setBackgroundPixmap( bg );
686 break;
687 }
688
689 case SolidColor:
690 icons->setBackgroundPixmap( QPixmap() );
691 if ( val.isEmpty() ) {
692 icons->setBackgroundColor( colorGroup().base() );
693 } else {
694 icons->setBackgroundColor( val );
695 }
696 bgName = "";
697 break;
698
699 case Image:
700 bgName = val;
701 if ( bgCache->contains( bgName ) ) {
702 (*bgCache)[bgName]->ref++;
703 icons->setBackgroundPixmap( (*bgCache)[bgName]->pm );
704 } else {
705 qDebug( "Loading image: %s", val.latin1() );
706 QPixmap bg( Resource::loadPixmap( "wallpaper/" + val ) );
707 if ( bg.isNull() ) {
708 QImageIO imgio;
709 imgio.setFileName( bgName );
710 QSize ds = qApp->desktop()->size();
711 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr
712 imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() );
713 imgio.read();
714 bg = imgio.image();
715 }
716 bgCache->insert( bgName, new BgPixmap(bg) );
717 icons->setBackgroundPixmap( bg );
718 }
719 break;
720 }
721
722 // remove unreferenced backgrounds.
723 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
724 while ( it != bgCache->end() ) {
725 QMap<QString,BgPixmap*>::Iterator curr = it;
726 ++it;
727 if ( (*curr)->ref == 0 ) {
728 delete (*curr);
729 bgCache->remove( curr );
730 }
731 }
732
733 bgType = t;
734 icons->viewport()->update();
735}
736
737void LauncherView::setTextColor( const QColor &tc )
738{
739 textCol = tc;
740 QColorGroup cg = icons->colorGroup();
741 cg.setColor( QColorGroup::Text, tc );
742 icons->setPalette( QPalette(cg,cg,cg) );
743 icons->viewport()->update();
744}
745
746void LauncherView::setViewFont( const QFont &f )
747{
748 icons->setFont( f );
749}
750
534void LauncherView::resizeEvent(QResizeEvent *e) 751void LauncherView::resizeEvent(QResizeEvent *e)
535{ 752{
536 QVBox::resizeEvent( e ); 753 QVBox::resizeEvent( e );
@@ -544,6 +761,11 @@ void LauncherView::populate( AppLnkSet *folder, const QString& typefilter )
544 internalPopulate( folder, typefilter ); 761 internalPopulate( folder, typefilter );
545} 762}
546 763
764QString LauncherView::getAllDocLinkInfo() const
765{
766 return icons->getAllDocLinkInfo();
767}
768
547void LauncherView::selectionChanged() 769void LauncherView::selectionChanged()
548{ 770{
549 QIconViewItem* item = icons->currentItem(); 771 QIconViewItem* item = icons->currentItem();
@@ -597,15 +819,13 @@ void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilte
597 819
598 while ( it.current() ) { 820 while ( it.current() ) {
599 // show only the icons for existing files 821 // show only the icons for existing files
600 if (!QFile(it.current()->file()).exists() & it.current()->file().left(4) != "http") 822 if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) {
601 { 823 icons->addItem(*it,FALSE);
824 }
825 else {
602 //maybe insert some .desktop file deletion code later 826 //maybe insert some .desktop file deletion code later
603 //maybe dir specific 827 //maybe dir specific
604 } 828 }
605 else
606 {
607 icons->addItem(*it,FALSE);
608 }
609 ++it; 829 ++it;
610 } 830 }
611 831
@@ -631,3 +851,15 @@ void LauncherView::setFileSystems(const QList<FileSystem> &)
631{ 851{
632 // ### does nothing now... 852 // ### does nothing now...
633} 853}
854
855void LauncherView::paletteChange( const QPalette &p )
856{
857 icons->unsetPalette();
858 QVBox::paletteChange( p );
859 if ( bgType == Ruled )
860 setBackgroundType( Ruled, QString::null );
861 QColorGroup cg = icons->colorGroup();
862 cg.setColor( QColorGroup::Text, textCol );
863 icons->setPalette( QPalette(cg,cg,cg) );
864}
865