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