summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp28
-rw-r--r--core/launcher/launcherview.h22
2 files changed, 33 insertions, 17 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 506c11e..42704ba 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,1148 +1,1174 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "launcherview.h" 21#include "launcherview.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <qtopia/qpeapplication.h> 25#include <qtopia/qpeapplication.h>
26#include <qtopia/private/categories.h> 26#include <qtopia/private/categories.h>
27#include <qtopia/categoryselect.h> 27#include <qtopia/categoryselect.h>
28#include <qtopia/mimetype.h> 28#include <qtopia/mimetype.h>
29#include <qtopia/resource.h> 29#include <qtopia/resource.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31 31
32#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
33 33
34/* QT */ 34/* QT */
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qfileinfo.h> 36#include <qfileinfo.h>
37#include <qiconview.h> 37#include <qiconview.h>
38#include <qobjectlist.h> 38#include <qobjectlist.h>
39 39
40 40
41// These define how the busy icon is animated and highlighted 41// These define how the busy icon is animated and highlighted
42#define BRIGHTEN_BUSY_ICON 42#define BRIGHTEN_BUSY_ICON
43//#define ALPHA_FADE_BUSY_ICON 43//#define ALPHA_FADE_BUSY_ICON
44//#define USE_ANIMATED_BUSY_ICON_OVERLAY 44//#define USE_ANIMATED_BUSY_ICON_OVERLAY
45#define BOUNCE_BUSY_ICON 45#define BOUNCE_BUSY_ICON
46 46
47 47
48class BgPixmap 48class BgPixmap
49{ 49{
50public: 50public:
51 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 51 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
52 QPixmap pm; 52 QPixmap pm;
53 int ref; 53 int ref;
54}; 54};
55 55
56 56
57static QMap<QString,BgPixmap*> *bgCache = 0; 57static QMap<QString,BgPixmap*> *bgCache = 0;
58 58
59static void cleanup_cache() 59static void cleanup_cache()
60{ 60{
61 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 61 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
62 while ( it != bgCache->end() ) { 62 while ( it != bgCache->end() ) {
63 QMap<QString,BgPixmap*>::Iterator curr = it; 63 QMap<QString,BgPixmap*>::Iterator curr = it;
64 ++it; 64 ++it;
65 delete (*curr); 65 delete (*curr);
66 bgCache->remove( curr ); 66 bgCache->remove( curr );
67 } 67 }
68 delete bgCache; 68 delete bgCache;
69 bgCache = 0; 69 bgCache = 0;
70} 70}
71 71
72 72
73class LauncherItem : public QIconViewItem 73class LauncherItem : public QIconViewItem
74{ 74{
75public: 75public:
76 enum iconstate_t { 76 enum iconstate_t {
77 BASE_ICON, 77 BASE_ICON,
78 WAITING_ICON, 78 WAITING_ICON,
79 EYE_ICON 79 EYE_ICON
80 }; 80 };
81 81
82 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); 82 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
83 ~LauncherItem(); 83 ~LauncherItem();
84 84
85 AppLnk *appLnk() const { return app; } 85 AppLnk *appLnk() const { return app; }
86 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } 86 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; }
87 87
88 void animateIcon(); 88 void animateIcon();
89 void resetIcon(); 89 void resetIcon();
90 bool isEyeImage()const{return m_EyeImage;} 90 bool isEyeImage()const{return m_EyeImage;}
91 91
92 virtual int compare ( QIconViewItem * i ) const; 92 virtual int compare ( QIconViewItem * i ) const;
93 void paintItem( QPainter *p, const QColorGroup &cg ); 93 void paintItem( QPainter *p, const QColorGroup &cg );
94 94
95 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 95 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
96 void setEyePixmap(const QPixmap&aIcon); 96 void setEyePixmap(const QPixmap&aIcon);
97 virtual QPixmap*pixmap()const; 97 virtual QPixmap*pixmap()const;
98 98
99protected: 99protected:
100 bool isBigIcon; 100 bool isBigIcon;
101 int iteration; 101 int iteration;
102 AppLnk* app; 102 AppLnk* app;
103 103
104private: 104private:
105 void paintAnimatedIcon( QPainter *p ); 105 void paintAnimatedIcon( QPainter *p );
106 BusyIndicatorType busyType; 106 BusyIndicatorType busyType;
107 int psize; 107 int psize;
108 QPixmap m_iPixmap; 108 QPixmap m_iPixmap;
109 bool m_EyeImage; 109 bool m_EyeImage;
110 iconstate_t m_EyeImageSet; 110 iconstate_t m_EyeImageSet;
111}; 111};
112 112
113LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) 113LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon )
114 : QIconViewItem( parent, applnk->name(), 114 : QIconViewItem( parent, applnk->name(),
115 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), 115 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
116 isBigIcon( bigIcon ), 116 isBigIcon( bigIcon ),
117 iteration(0), 117 iteration(0),
118 app(applnk), // Takes ownership 118 app(applnk), // Takes ownership
119 psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ), 119 psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ),
120 m_iPixmap(), 120 m_iPixmap(),
121 m_EyeImage(false), 121 m_EyeImage(false),
122 m_EyeImageSet(BASE_ICON) 122 m_EyeImageSet(BASE_ICON)
123{ 123{
124 if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) { 124 if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) {
125 m_EyeImage = true; 125 m_EyeImage = true;
126 m_iPixmap = (bigIcon ? applnk->bigPixmap():applnk->pixmap()); 126 m_iPixmap = (bigIcon ? applnk->bigPixmap():applnk->pixmap());
127 } 127 }
128} 128}
129 129
130LauncherItem::~LauncherItem() 130LauncherItem::~LauncherItem()
131{ 131{
132 LauncherIconView* liv = (LauncherIconView*)iconView(); 132 LauncherIconView* liv = (LauncherIconView*)iconView();
133 if ( liv->busyItem() == this ) 133 if ( liv->busyItem() == this )
134 liv->setBusy(FALSE); 134 liv->setBusy(FALSE);
135 delete app; 135 delete app;
136} 136}
137 137
138QPixmap*LauncherItem::pixmap()const 138QPixmap*LauncherItem::pixmap()const
139{ 139{
140 if (m_EyeImage && m_EyeImageSet == BASE_ICON) { 140 if (m_EyeImage && m_EyeImageSet == BASE_ICON) {
141 LauncherIconView* liv = (LauncherIconView*)iconView(); 141 LauncherIconView* liv = (LauncherIconView*)iconView();
142 liv->requestEyePix(this); 142 liv->requestEyePix(this);
143 } 143 }
144 return QIconViewItem::pixmap(); 144 return QIconViewItem::pixmap();
145} 145}
146 146
147int LauncherItem::compare ( QIconViewItem * i ) const 147int LauncherItem::compare ( QIconViewItem * i ) const
148{ 148{
149 LauncherIconView* view = (LauncherIconView*)iconView(); 149 LauncherIconView* view = (LauncherIconView*)iconView();
150 return view->compare(app,((LauncherItem *)i)->appLnk()); 150 return view->compare(app,((LauncherItem *)i)->appLnk());
151} 151}
152 152
153void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) 153void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg )
154{ 154{
155 LauncherIconView* liv = (LauncherIconView*)iconView(); 155 LauncherIconView* liv = (LauncherIconView*)iconView();
156 QBrush oldBrush( liv->itemTextBackground() ); 156 QBrush oldBrush( liv->itemTextBackground() );
157 QColorGroup mycg( cg ); 157 QColorGroup mycg( cg );
158 if ( liv->currentItem() == this ) { 158 if ( liv->currentItem() == this ) {
159 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 159 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
160 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 160 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
161 } 161 }
162 162
163 QIconViewItem::paintItem(p,mycg); 163 QIconViewItem::paintItem(p,mycg);
164 164
165 // Paint animation overlay 165 // Paint animation overlay
166 if ( liv->busyItem() == this ) 166 if ( liv->busyItem() == this )
167 paintAnimatedIcon(p); 167 paintAnimatedIcon(p);
168 168
169 if ( liv->currentItem() == this ) 169 if ( liv->currentItem() == this )
170 liv->setItemTextBackground( oldBrush ); 170 liv->setItemTextBackground( oldBrush );
171} 171}
172 172
173void LauncherItem::paintAnimatedIcon( QPainter *p ) 173void LauncherItem::paintAnimatedIcon( QPainter *p )
174{ 174{
175 LauncherIconView* liv = (LauncherIconView*)iconView(); 175 LauncherIconView* liv = (LauncherIconView*)iconView();
176 int pic = iteration % 16; 176 int pic = iteration % 16;
177 int w = pixmap()->width(), h = pixmap()->height(); 177 int w = pixmap()->width(), h = pixmap()->height();
178 QPixmap dblBuf( w, h + 4 ); 178 QPixmap dblBuf( w, h + 4 );
179 QPainter p2( &dblBuf ); 179 QPainter p2( &dblBuf );
180 int x1, y1; 180 int x1, y1;
181 if ( liv->itemTextPos() == QIconView::Bottom ) { 181 if ( liv->itemTextPos() == QIconView::Bottom ) {
182 x1 = x() + (width() - w) / 2 - liv->contentsX(); 182 x1 = x() + (width() - w) / 2 - liv->contentsX();
183 y1 = y() - liv->contentsY(); 183 y1 = y() - liv->contentsY();
184 } else { 184 } else {
185 x1 = x() - liv->contentsX(); 185 x1 = x() - liv->contentsX();
186 y1 = y() + (height() - h) / 2 - liv->contentsY(); 186 y1 = y() + (height() - h) / 2 - liv->contentsY();
187 } 187 }
188 y1 -= 2; 188 y1 -= 2;
189 p2.translate(-x1,-y1); 189 p2.translate(-x1,-y1);
190 liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); 190 liv->drawBackground( &p2, QRect(x1,y1,w,h+4) );
191 int bounceY = 2; 191 int bounceY = 2;
192#ifdef BOUNCE_BUSY_ICON 192#ifdef BOUNCE_BUSY_ICON
193 if ( busyType == BIT_Animated ) { 193 if ( busyType == BIT_Animated ) {
194 bounceY = 4 - ((iteration+2)%8); 194 bounceY = 4 - ((iteration+2)%8);
195 bounceY = bounceY < 0 ? -bounceY : bounceY; 195 bounceY = bounceY < 0 ? -bounceY : bounceY;
196 } 196 }
197#endif 197#endif
198 p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); 198 p2.drawPixmap( x1, y1 + bounceY, *pixmap() );
199#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 199#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
200 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); 200 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h );
201#else 201#else
202 Q_UNUSED( pic ) 202 Q_UNUSED( pic )
203#endif 203#endif
204 p->drawPixmap( x1, y1, dblBuf ); 204 p->drawPixmap( x1, y1, dblBuf );
205} 205}
206 206
207void LauncherItem::animateIcon() 207void LauncherItem::animateIcon()
208{ 208{
209 LauncherIconView* liv = (LauncherIconView*)iconView(); 209 LauncherIconView* liv = (LauncherIconView*)iconView();
210 210
211 if ( liv->busyItem() != this || !app ) 211 if ( liv->busyItem() != this || !app )
212 return; 212 return;
213 213
214 // Highlight the icon 214 // Highlight the icon
215 if ( iteration == 0 ) { 215 if ( iteration == 0 ) {
216 QPixmap src = (isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap())); 216 QPixmap src = (isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap()));
217 QImage img = src.convertToImage(); 217 QImage img = src.convertToImage();
218 QRgb *rgb; 218 QRgb *rgb;
219 int count; 219 int count;
220 if ( img.depth() == 32 ) { 220 if ( img.depth() == 32 ) {
221 rgb = (QRgb*)img.bits(); 221 rgb = (QRgb*)img.bits();
222 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 222 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
223 } else { 223 } else {
224 rgb = img.colorTable(); 224 rgb = img.colorTable();
225 count = img.numColors(); 225 count = img.numColors();
226 } 226 }
227 for ( int r = 0; r < count; r++, rgb++ ) { 227 for ( int r = 0; r < count; r++, rgb++ ) {
228#if defined(BRIGHTEN_BUSY_ICON) 228#if defined(BRIGHTEN_BUSY_ICON)
229 QColor c(*rgb); 229 QColor c(*rgb);
230 int h, s, v; 230 int h, s, v;
231 c.hsv(&h,&s,&v); 231 c.hsv(&h,&s,&v);
232 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); 232 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255));
233 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); 233 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb));
234#elif defined(ALPHA_FADE_BUSY_ICON) 234#elif defined(ALPHA_FADE_BUSY_ICON)
235 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); 235 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2);
236#endif 236#endif
237 } 237 }
238 src.convertFromImage( img ); 238 src.convertFromImage( img );
239 setPixmap( src ); 239 setPixmap( src );
240 } 240 }
241 241
242 iteration++; 242 iteration++;
243 243
244 // Paint animation overlay 244 // Paint animation overlay
245 QPainter p( liv->viewport() ); 245 QPainter p( liv->viewport() );
246 paintAnimatedIcon( &p ); 246 paintAnimatedIcon( &p );
247} 247}
248 248
249void LauncherItem::resetIcon() 249void LauncherItem::resetIcon()
250{ 250{
251 iteration = 0; 251 iteration = 0;
252 setPixmap((isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap()))); 252 setPixmap((isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap())));
253} 253}
254 254
255void LauncherItem::setEyePixmap(const QPixmap&aIcon) 255void LauncherItem::setEyePixmap(const QPixmap&aIcon)
256{ 256{
257 if (!isEyeImage()) return; 257 if (!isEyeImage()) return;
258 m_iPixmap = aIcon; 258 m_iPixmap = aIcon;
259 setPixmap(aIcon); 259 setPixmap(aIcon);
260 m_EyeImageSet = EYE_ICON; 260 m_EyeImageSet = EYE_ICON;
261} 261}
262 262
263//=========================================================================== 263//===========================================================================
264// Implemantation of LauncherIconview start 264// Implemantation of LauncherIconview start
265//=========================================================================== 265//===========================================================================
266LauncherIconView::LauncherIconView( QWidget* parent, const char* name ) 266LauncherIconView::LauncherIconView( QWidget* parent, const char* name )
267 : QIconView(parent,name),tf(""),cf(0),bsy(0),busyTimer(0),bigIcns(TRUE),bgColor(white) 267 : QIconView(parent,name),tf(""),cf(0),bsy(0),busyTimer(0),bigIcns(TRUE),bgColor(white)
268{ 268{
269 m_EyeCallBack = 0; 269 m_EyeCallBack = 0;
270 sortmeth = Name; 270 sortmeth = Name;
271 hidden.setAutoDelete(TRUE); 271 hidden.setAutoDelete(TRUE);
272 ike = FALSE; 272 ike = FALSE;
273 calculateGrid( Bottom ); 273 calculateGrid( Bottom );
274 connect(&m_eyeTimer,SIGNAL(timeout()),this,SLOT(stopEyeTimer()));
274} 275}
275 276
276LauncherIconView::~LauncherIconView() 277LauncherIconView::~LauncherIconView()
277{ 278{
278#if 0 // debuggery 279#if 0 // debuggery
279 QListIterator<AppLnk> it(hidden); 280 QListIterator<AppLnk> it(hidden);
280 AppLnk* l; 281 AppLnk* l;
281 while ((l=it.current())) { 282 while ((l=it.current())) {
282 ++it; 283 ++it;
283 //odebug << "" << l << ": hidden (should remove)" << oendl; 284 //odebug << "" << l << ": hidden (should remove)" << oendl;
284 } 285 }
285#endif 286#endif
286} 287}
287 288
288int LauncherIconView::compare(const AppLnk* a, const AppLnk* b) 289int LauncherIconView::compare(const AppLnk* a, const AppLnk* b)
289{ 290{
290 switch (sortmeth) { 291 switch (sortmeth) {
291 case Name: 292 case Name:
292 return a->name().lower().compare(b->name().lower()); 293 return a->name().lower().compare(b->name().lower());
293 case Date: { 294 case Date: {
294 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 295 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
295 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 296 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
296 return fa.lastModified().secsTo(fb.lastModified()); 297 return fa.lastModified().secsTo(fb.lastModified());
297 } 298 }
298 case Type: 299 case Type:
299 return a->type().compare(b->type()); 300 return a->type().compare(b->type());
300 } 301 }
301 return 0; 302 return 0;
302} 303}
303 304
304void LauncherIconView::setSortMethod( SortMethod m ) 305void LauncherIconView::setSortMethod( SortMethod m )
305{ 306{
306 if ( sortmeth != m ) { 307 if ( sortmeth != m ) {
307 sortmeth = m; 308 sortmeth = m;
308 sort(); 309 sort();
309 } 310 }
310} 311}
311 312
312void LauncherIconView::setCategoryFilter( int catfilter, bool resort ) 313void LauncherIconView::setCategoryFilter( int catfilter, bool resort )
313{ 314{
314 Categories cat; 315 Categories cat;
315 cat.load( categoryFileName() ); 316 cat.load( categoryFileName() );
316 QString str; 317 QString str;
317 if ( catfilter == -2 ) 318 if ( catfilter == -2 )
318 cf = 0; 319 cf = 0;
319 else 320 else
320 cf = catfilter; 321 cf = catfilter;
321 hideOrShowItems(resort); 322 hideOrShowItems(resort);
322} 323}
323 324
324void LauncherIconView::setTypeFilter(const QString& typefilter, bool resort) 325void LauncherIconView::setTypeFilter(const QString& typefilter, bool resort)
325{ 326{
326 tf = QRegExp(typefilter,FALSE,TRUE); 327 tf = QRegExp(typefilter,FALSE,TRUE);
327 hideOrShowItems(resort); 328 hideOrShowItems(resort);
328} 329}
329 330
330void LauncherIconView::setItemTextPos( ItemTextPos pos ) 331void LauncherIconView::setItemTextPos( ItemTextPos pos )
331{ 332{
332 calculateGrid( pos ); 333 calculateGrid( pos );
333 QIconView::setItemTextPos( pos ); 334 QIconView::setItemTextPos( pos );
334} 335}
335 336
336void LauncherIconView::drawBackground( QPainter *p, const QRect &r ) 337void LauncherIconView::drawBackground( QPainter *p, const QRect &r )
337{ 338{
338 if ( !bgPixmap.isNull() ) { 339 if ( !bgPixmap.isNull() ) {
339 p->drawTiledPixmap( r, bgPixmap, 340 p->drawTiledPixmap( r, bgPixmap,
340 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 341 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
341 (r.y() + contentsY()) % bgPixmap.height() ) ); 342 (r.y() + contentsY()) % bgPixmap.height() ) );
342 } else { 343 } else {
343 p->fillRect( r, bgColor ); 344 p->fillRect( r, bgColor );
344 } 345 }
345} 346}
346 347
347void LauncherIconView::addCatsAndMimes(AppLnk* app) 348void LauncherIconView::addCatsAndMimes(AppLnk* app)
348 { 349 {
349 // QStringList c = app->categories(); 350 // QStringList c = app->categories();
350 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 351 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
351 // cats.replace(*cit,(void*)1); 352 // cats.replace(*cit,(void*)1);
352 // } 353 // }
353 QString maj=app->type(); 354 QString maj=app->type();
354 int sl=maj.find('/'); 355 int sl=maj.find('/');
355 if (sl>=0) { 356 if (sl>=0) {
356 QString k; 357 QString k;
357 k = maj.left(12) == "application/" ? maj : maj.left(sl); 358 k = maj.left(12) == "application/" ? maj : maj.left(sl);
358 mimes.replace(k,(void*)1); 359 mimes.replace(k,(void*)1);
359 } 360 }
360} 361}
361 362
362void LauncherIconView::setBusy(bool on) 363void LauncherIconView::setBusy(bool on)
363{ 364{
364#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 365#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
365 if ( busyPix.isNull() ) { 366 if ( busyPix.isNull() ) {
366 int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); 367 int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
367 busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); 368 busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) );
368 } 369 }
369#endif 370#endif
370 371
371 if ( on ) { 372 if ( on ) {
372 busyTimer = startTimer( 100 ); 373 busyTimer = startTimer( 100 );
373 } else { 374 } else {
374 if ( busyTimer ) { 375 if ( busyTimer ) {
375 killTimer( busyTimer ); 376 killTimer( busyTimer );
376 busyTimer = 0; 377 busyTimer = 0;
377 } 378 }
378 } 379 }
379 380
380 LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; 381 LauncherItem *c = on ? (LauncherItem*)currentItem() : 0;
381 382
382 if ( bsy != c ) { 383 if ( bsy != c ) {
383 LauncherItem *oldBusy = bsy; 384 LauncherItem *oldBusy = bsy;
384 bsy = c; 385 bsy = c;
385 if ( oldBusy ) { 386 if ( oldBusy ) {
386 oldBusy->resetIcon(); 387 oldBusy->resetIcon();
387 } 388 }
388 if ( bsy ) { 389 if ( bsy ) {
389 bsy->setBusyIndicatorType( busyType ) ; 390 bsy->setBusyIndicatorType( busyType ) ;
390 bsy->animateIcon(); 391 bsy->animateIcon();
391 } 392 }
392 } 393 }
393} 394}
394 395
395void LauncherIconView::clear() 396void LauncherIconView::clear()
396{ 397{
397 mimes.clear(); 398 mimes.clear();
398 cats.clear(); 399 cats.clear();
399 QIconView::clear(); 400 QIconView::clear();
400 hidden.clear(); 401 hidden.clear();
401} 402}
402 403
403QStringList LauncherIconView::mimeTypes() const 404QStringList LauncherIconView::mimeTypes() const
404{ 405{
405 QStringList r; 406 QStringList r;
406 QDictIterator<void> it(mimes); 407 QDictIterator<void> it(mimes);
407 while (it.current()) { 408 while (it.current()) {
408 r.append(it.currentKey()); 409 r.append(it.currentKey());
409 ++it; 410 ++it;
410 } 411 }
411 r.sort(); 412 r.sort();
412 return r; 413 return r;
413} 414}
414 415
415LauncherItem*LauncherIconView::findDocItem(const QString&fname) 416LauncherItem*LauncherIconView::findDocItem(const QString&fname)
416{ 417{
417 LauncherItem* item = (LauncherItem*)firstItem(); 418 LauncherItem* item = (LauncherItem*)firstItem();
418 while (item) { 419 while (item) {
419 if (item->appLnk()->file()==fname) { 420 if (item->appLnk()->file()==fname) {
420 break; 421 break;
421 } 422 }
422 item = (LauncherItem*)item->nextItem(); 423 item = (LauncherItem*)item->nextItem();
423 } 424 }
424 return item; 425 return item;
425} 426}
426 427
427void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile,int width) 428void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile,int width)
428{ 429{
429 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); 430 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
430 if (s!=width) return; 431 if (s!=width) return;
431 LauncherItem*item = findDocItem(aFile); 432 LauncherItem*item = findDocItem(aFile);
432 if (!item||!item->isEyeImage()) return; 433 if (!item||!item->isEyeImage()) return;
433 item->setEyePixmap(aPixmap); 434 item->setEyePixmap(aPixmap);
434} 435}
435 436
436void LauncherIconView::checkCallback() 437void LauncherIconView::checkCallback()
437{ 438{
438 if (m_EyeCallBack) { 439 if (m_EyeCallBack) {
439 return; 440 return;
440 } 441 }
441 m_EyeCallBack = new LauncherThumbReceiver(); 442 m_EyeCallBack = new LauncherThumbReceiver();
442 connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)), 443 connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)),
443 this,SLOT(setEyePixmap(const QPixmap&,const QString&,int))); 444 this,SLOT(setEyePixmap(const QPixmap&,const QString&,int)));
444} 445}
445 446
446void LauncherIconView::addCheckItem(AppLnk* app) 447void LauncherIconView::addCheckItem(AppLnk* app)
447{ 448{
448 LauncherItem*item = new LauncherItem( this, app, bigIcns ); 449 LauncherItem*item = new LauncherItem( this, app, bigIcns );
449 if (item->isEyeImage()) { 450 if (item->isEyeImage()) {
450 checkCallback(); 451 checkCallback();
451 } 452 }
452} 453}
453 454
454void LauncherIconView::requestEyePix(const LauncherItem*item) 455void LauncherIconView::requestEyePix(const LauncherItem*item)
455{ 456{
456 if (!item) return; 457 if (!item) return;
457 if (item->isEyeImage()) { 458 if (item->isEyeImage()) {
459 m_eyeTimer.changeInterval(600000);
458 checkCallback(); 460 checkCallback();
459 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); 461 int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
460 m_EyeCallBack->requestThumb(item->appLnk()->file(),s,s); 462 m_EyeCallBack->requestThumb(item->appLnk()->file(),s,s);
461 } 463 }
462} 464}
463 465
466void LauncherIconView::stopEyeTimer()
467{
468 odebug << "Launcherview: delete opie-eye handle" << oendl;
469 if (m_EyeCallBack) {
470 delete m_EyeCallBack;
471 m_EyeCallBack=0;
472 }
473 m_eyeTimer.stop();
474}
475
464void LauncherIconView::addItem(AppLnk* app, bool resort) 476void LauncherIconView::addItem(AppLnk* app, bool resort)
465{ 477{
466 addCatsAndMimes(app); 478 addCatsAndMimes(app);
467 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 479 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
468 && (cf == 0 || app->categories().contains(cf) 480 && (cf == 0 || app->categories().contains(cf)
469 || cf == -1 && app->categories().count() == 0 ) ) { 481 || cf == -1 && app->categories().count() == 0 ) ) {
470 addCheckItem(app); 482 addCheckItem(app);
471 } else { 483 } else {
472 hidden.append(app); 484 hidden.append(app);
473 } 485 }
474 if ( resort ){ 486 if ( resort ){
475 sort(); 487 sort();
476 } 488 }
477} 489}
478 490
479void LauncherIconView::updateCategoriesAndMimeTypes() 491void LauncherIconView::updateCategoriesAndMimeTypes()
480{ 492{
481 mimes.clear(); 493 mimes.clear();
482 cats.clear(); 494 cats.clear();
483 LauncherItem* item = (LauncherItem*)firstItem(); 495 LauncherItem* item = (LauncherItem*)firstItem();
484 while (item) { 496 while (item) {
485 addCatsAndMimes(item->appLnk()); 497 addCatsAndMimes(item->appLnk());
486 item = (LauncherItem*)item->nextItem(); 498 item = (LauncherItem*)item->nextItem();
487 } 499 }
488 QListIterator<AppLnk> it(hidden); 500 QListIterator<AppLnk> it(hidden);
489 AppLnk* l; 501 AppLnk* l;
490 while ((l=it.current())) { 502 while ((l=it.current())) {
491 addCatsAndMimes(l); 503 addCatsAndMimes(l);
492 ++it; 504 ++it;
493 } 505 }
494} 506}
495 507
496void LauncherIconView::hideOrShowItems(bool resort) 508void LauncherIconView::hideOrShowItems(bool resort)
497{ 509{
498 viewport()->setUpdatesEnabled( FALSE ); 510 viewport()->setUpdatesEnabled( FALSE );
499 hidden.setAutoDelete(FALSE); 511 hidden.setAutoDelete(FALSE);
500 QList<AppLnk> links=hidden; 512 QList<AppLnk> links=hidden;
501 hidden.clear(); 513 hidden.clear();
502 hidden.setAutoDelete(TRUE); 514 hidden.setAutoDelete(TRUE);
503 LauncherItem* item = (LauncherItem*)firstItem(); 515 LauncherItem* item = (LauncherItem*)firstItem();
504 while (item) { 516 while (item) {
505 links.append(item->takeAppLnk()); 517 links.append(item->takeAppLnk());
506 item = (LauncherItem*)item->nextItem(); 518 item = (LauncherItem*)item->nextItem();
507 } 519 }
508 clear(); 520 clear();
509 QListIterator<AppLnk> it(links); 521 QListIterator<AppLnk> it(links);
510 AppLnk* l; 522 AppLnk* l;
511 while ((l=it.current())) { 523 while ((l=it.current())) {
512 addItem(l,FALSE); 524 addItem(l,FALSE);
513 ++it; 525 ++it;
514 } 526 }
515 if ( resort && !autoArrange() ) 527 if ( resort && !autoArrange() )
516 sort(); 528 sort();
517 viewport()->setUpdatesEnabled( TRUE ); 529 viewport()->setUpdatesEnabled( TRUE );
518} 530}
519 531
520bool LauncherIconView::removeLink(const QString& linkfile) 532bool LauncherIconView::removeLink(const QString& linkfile)
521{ 533{
522 LauncherItem* item = (LauncherItem*)firstItem(); 534 LauncherItem* item = (LauncherItem*)firstItem();
523 AppLnk* l; 535 AppLnk* l;
524 bool did = FALSE; 536 bool did = FALSE;
525 DocLnk dl(linkfile); 537 DocLnk dl(linkfile);
526 while (item) { 538 while (item) {
527 l = item->appLnk(); 539 l = item->appLnk();
528 LauncherItem *nextItem = (LauncherItem *)item->nextItem(); 540 LauncherItem *nextItem = (LauncherItem *)item->nextItem();
529 if ( l->linkFileKnown() && l->linkFile() == linkfile || l->fileKnown() && 541 if ( l->linkFileKnown() && l->linkFile() == linkfile || l->fileKnown() &&
530 ( l->file() == linkfile || dl.isValid() && dl.file() == l->file() ) ) { 542 ( l->file() == linkfile || dl.isValid() && dl.file() == l->file() ) ) {
531 delete item; 543 delete item;
532 did = TRUE; 544 did = TRUE;
533 } 545 }
534 item = nextItem; 546 item = nextItem;
535 } 547 }
536 QListIterator<AppLnk> it(hidden); 548 QListIterator<AppLnk> it(hidden);
537 while ((l=it.current())) { 549 while ((l=it.current())) {
538 ++it; 550 ++it;
539 if ( l->linkFileKnown() && l->linkFile() == linkfile 551 if ( l->linkFileKnown() && l->linkFile() == linkfile
540 || l->file() == linkfile 552 || l->file() == linkfile
541 || dl.isValid() && dl.file() == l->file() ) { 553 || dl.isValid() && dl.file() == l->file() ) {
542 hidden.removeRef(l); 554 hidden.removeRef(l);
543 did = TRUE; 555 did = TRUE;
544 } 556 }
545 } 557 }
546 return did; 558 return did;
547} 559}
548 560
549void LauncherIconView::timerEvent( QTimerEvent *te ) 561void LauncherIconView::timerEvent( QTimerEvent *te )
550{ 562{
551 if ( te->timerId() == busyTimer ) { 563 if ( te->timerId() == busyTimer ) {
552 if ( bsy ) 564 if ( bsy )
553 bsy->animateIcon(); 565 bsy->animateIcon();
554 } else { 566 } else {
555 QIconView::timerEvent( te ); 567 QIconView::timerEvent( te );
556 } 568 }
557} 569}
558 570
559void LauncherIconView::setBigIcons( bool bi ) 571void LauncherIconView::setBigIcons( bool bi )
560{ 572{
561 bigIcns = bi; 573 bigIcns = bi;
562#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 574#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
563 busyPix.resize(0,0); 575 busyPix.resize(0,0);
564#endif 576#endif
565} 577}
566 578
567QIconViewItem* LauncherIconView::busyItem() const 579QIconViewItem* LauncherIconView::busyItem() const
568{ 580{
569 return bsy; 581 return bsy;
570} 582}
571 583
572void LauncherIconView::setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 584void LauncherIconView::setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
573 585
574void LauncherIconView::calculateGrid( ItemTextPos pos ) 586void LauncherIconView::calculateGrid( ItemTextPos pos )
575{ 587{
576 int dw = QApplication::desktop()->width(); 588 int dw = QApplication::desktop()->width();
577 int viewerWidth = dw-style().scrollBarExtent().width(); 589 int viewerWidth = dw-style().scrollBarExtent().width();
578 if ( pos == Bottom ) { 590 if ( pos == Bottom ) {
579 int cols = 3; 591 int cols = 3;
580 if ( viewerWidth <= 200 ) 592 if ( viewerWidth <= 200 )
581 cols = 2; 593 cols = 2;
582 else if ( viewerWidth >= 400 ) 594 else if ( viewerWidth >= 400 )
583 cols = viewerWidth/96; 595 cols = viewerWidth/96;
584 setSpacing( 4 ); 596 setSpacing( 4 );
585 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 597 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
586 setGridY( fontMetrics().height()*2+24 ); 598 setGridY( fontMetrics().height()*2+24 );
587 } else { 599 } else {
588 int cols = 2; 600 int cols = 2;
589 if ( viewerWidth < 150 ) 601 if ( viewerWidth < 150 )
590 cols = 1; 602 cols = 1;
591 else if ( viewerWidth >= 400 ) 603 else if ( viewerWidth >= 400 )
592 cols = viewerWidth/150; 604 cols = viewerWidth/150;
593 setSpacing( 2 ); 605 setSpacing( 2 );
594 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 606 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
595 setGridY( fontMetrics().height()+2 ); 607 setGridY( fontMetrics().height()+2 );
596 } 608 }
597} 609}
598 610
599void LauncherIconView::styleChange( QStyle &old ) 611void LauncherIconView::styleChange( QStyle &old )
600{ 612{
601 QIconView::styleChange( old ); 613 QIconView::styleChange( old );
602 calculateGrid( itemTextPos() ); 614 calculateGrid( itemTextPos() );
603} 615}
616
617void LauncherIconView::keyPressEvent(QKeyEvent* e)
618{
619 ike = TRUE;
620 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) {
621 if ( (e->state() & ShiftButton) )
622 emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() );
623 else
624 returnPressed(currentItem());
625 }
626
627 QIconView::keyPressEvent(e);
628 ike = FALSE;
629}
630
604//=========================================================================== 631//===========================================================================
605// Implemantation of LauncherIconview end 632// Implemantation of LauncherIconview end
606//=========================================================================== 633//===========================================================================
607 634
608 635
609//=========================================================================== 636//===========================================================================
610LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) 637LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
611 : QVBox( parent, name, fl ) 638 : QVBox( parent, name, fl )
612{ 639{
613 catmb = 0; 640 catmb = 0;
614 icons = new LauncherIconView( this ); 641 icons = new LauncherIconView( this );
615 setFocusProxy(icons); 642 setFocusProxy(icons);
616 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); 643 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );
617 644
618 icons->setItemsMovable( FALSE ); 645 icons->setItemsMovable( FALSE );
619 icons->setAutoArrange( TRUE ); 646 icons->setAutoArrange( TRUE );
620 icons->setSorting( TRUE ); 647 icons->setSorting( TRUE );
621 icons->setFrameStyle( QFrame::NoFrame ); 648 icons->setFrameStyle( QFrame::NoFrame );
622 icons->setMargin( 0 ); 649 icons->setMargin( 0 );
623 icons->setSelectionMode( QIconView::NoSelection ); 650 icons->setSelectionMode( QIconView::NoSelection );
624 icons->setBackgroundMode( PaletteBase ); 651 icons->setBackgroundMode( PaletteBase );
625 icons->setResizeMode( QIconView::Fixed ); 652 icons->setResizeMode( QIconView::Fixed );
626 vmode = (ViewMode)-1; 653 vmode = (ViewMode)-1;
627 setViewMode( Icon ); 654 setViewMode( Icon );
628 655
629 connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)), 656 connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)),
630 SLOT(itemClicked(int,QIconViewItem*)) ); 657 SLOT(itemClicked(int,QIconViewItem*)) );
631 connect( icons, SIGNAL(selectionChanged()), 658 connect( icons, SIGNAL(selectionChanged()),
632 SLOT(selectionChanged()) ); 659 SLOT(selectionChanged()) );
633 connect( icons, SIGNAL(returnPressed(QIconViewItem*)), 660 connect( icons, SIGNAL(returnPressed(QIconViewItem*)),
634 SLOT(returnPressed(QIconViewItem*)) ); 661 SLOT(returnPressed(QIconViewItem*)) );
635 connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)), 662 connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)),
636 SLOT(itemPressed(int,QIconViewItem*)) ); 663 SLOT(itemPressed(int,QIconViewItem*)) );
637 664
638 tools = 0; 665 tools = 0;
639 setBackgroundType( Ruled, QString::null ); 666 setBackgroundType( Ruled, QString::null );
640} 667}
641 668
642LauncherView::~LauncherView() 669LauncherView::~LauncherView()
643{ 670{
644 if ( bgCache && bgCache->contains( bgName ) ) 671 if ( bgCache && bgCache->contains( bgName ) )
645 (*bgCache)[bgName]->ref--; 672 (*bgCache)[bgName]->ref--;
646} 673}
647 674
648 675
649bool LauncherView::bsy=FALSE; 676bool LauncherView::bsy=FALSE;
650 677
651void LauncherView::setBusy(bool on) 678void LauncherView::setBusy(bool on)
652{ 679{
653 icons->setBusy(on); 680 icons->setBusy(on);
654} 681}
655 682
656void LauncherView::setBusyIndicatorType( const QString& type ) { 683void LauncherView::setBusyIndicatorType( const QString& type ) {
657 if ( type. lower ( ) == "animated" ) 684 if ( type. lower ( ) == "animated" )
658 icons->setBusyIndicatorType( BIT_Animated ) ; 685 icons->setBusyIndicatorType( BIT_Animated ) ;
659 else 686 else
660 icons->setBusyIndicatorType( BIT_Normal ) ; 687 icons->setBusyIndicatorType( BIT_Normal ) ;
661} 688}
662 689
663void LauncherView::hideIcons() 690void LauncherView::hideIcons()
664{ 691{
665 icons->hide(); 692 icons->hide();
666} 693}
667 694
668void LauncherView::setToolsEnabled(bool y) 695void LauncherView::setToolsEnabled(bool y)
669{ 696{
670 if ( !y != !tools ) { 697 if ( !y != !tools ) {
671 if ( y ) { 698 if ( y ) {
672 tools = new QHBox(this); 699 tools = new QHBox(this);
673 700
674 // Type filter 701 // Type filter
675 typemb = new QComboBox(tools); 702 typemb = new QComboBox(tools);
676 QSizePolicy p = typemb->sizePolicy(); 703 QSizePolicy p = typemb->sizePolicy();
677 p.setHorData(QSizePolicy::Expanding); 704 p.setHorData(QSizePolicy::Expanding);
678 typemb->setSizePolicy(p); 705 typemb->setSizePolicy(p);
679 706
680 // Category filter 707 // Category filter
681 updateTools(); 708 updateTools();
682 tools->show(); 709 tools->show();
683 710
684 } else { 711 } else {
685 delete tools; 712 delete tools;
686 tools = 0; 713 tools = 0;
687 } 714 }
688 } 715 }
689} 716}
690 717
691void LauncherView::updateTools() 718void LauncherView::updateTools()
692{ 719{
693 disconnect( typemb, SIGNAL(activated(int)), 720 disconnect( typemb, SIGNAL(activated(int)),
694 this, SLOT(showType(int)) ); 721 this, SLOT(showType(int)) );
695 if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), 722 if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)),
696 this, SLOT(showCategory(int)) ); 723 this, SLOT(showCategory(int)) );
697 724
698 // ### I want to remove this 725 // ### I want to remove this
699 icons->updateCategoriesAndMimeTypes(); 726 icons->updateCategoriesAndMimeTypes();
700 727
701 QString prev; 728 QString prev;
702 729
703 // Type filter 730 // Type filter
704 QStringList types; 731 QStringList types;
705 typelist = icons->mimeTypes(); 732 typelist = icons->mimeTypes();
706 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { 733 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) {
707 QString t = *it; 734 QString t = *it;
708 if ( t.left(12) == "application/" ) { 735 if ( t.left(12) == "application/" ) {
709 MimeType mt(t); 736 MimeType mt(t);
710 const AppLnk* app = mt.application(); 737 const AppLnk* app = mt.application();
711 if ( app ) 738 if ( app )
712 t = app->name(); 739 t = app->name();
713 else 740 else
714 t = t.mid(12); 741 t = t.mid(12);
715 } else { 742 } else {
716 t[0] = t[0].upper(); 743 t[0] = t[0].upper();
717 } 744 }
718 types += t; 745 types += t;
719 } 746 }
720 types << tr("All types"); 747 types << tr("All types");
721 prev = typemb->currentText(); 748 prev = typemb->currentText();
722 typemb->clear(); 749 typemb->clear();
723 typemb->insertStringList(types); 750 typemb->insertStringList(types);
724 for (int i=0; i<typemb->count(); i++) { 751 for (int i=0; i<typemb->count(); i++) {
725 if ( typemb->text(i) == prev ) { 752 if ( typemb->text(i) == prev ) {
726 typemb->setCurrentItem(i); 753 typemb->setCurrentItem(i);
727 break; 754 break;
728 } 755 }
729 } 756 }
730 if ( prev.isNull() ) 757 if ( prev.isNull() )
731 typemb->setCurrentItem(typemb->count()-1); 758 typemb->setCurrentItem(typemb->count()-1);
732 759
733 int pcat = catmb ? catmb->currentCategory() : -2; 760 int pcat = catmb ? catmb->currentCategory() : -2;
734 if ( !catmb ) 761 if ( !catmb )
735 catmb = new CategorySelect(tools); 762 catmb = new CategorySelect(tools);
736 Categories cats( 0 ); 763 Categories cats( 0 );
737 cats.load( categoryFileName() ); 764 cats.load( categoryFileName() );
738 QArray<int> vl( 0 ); 765 QArray<int> vl( 0 );
739 catmb->setCategories( vl, "Document View", // No tr 766 catmb->setCategories( vl, "Document View", // No tr
740 tr("Document View") ); 767 tr("Document View") );
741 catmb->setRemoveCategoryEdit( TRUE ); 768 catmb->setRemoveCategoryEdit( TRUE );
742 catmb->setAllCategories( TRUE ); 769 catmb->setAllCategories( TRUE );
743 catmb->setCurrentCategory(pcat); 770 catmb->setCurrentCategory(pcat);
744 771
745 // if type has changed we need to redisplay 772 // if type has changed we need to redisplay
746 if ( typemb->currentText() != prev ) 773 if ( typemb->currentText() != prev )
747 showType( typemb->currentItem() ); 774 showType( typemb->currentItem() );
748 775
749 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); 776 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
750 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 777 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
751} 778}
752 779
753void LauncherView::sortBy(int s) 780void LauncherView::sortBy(int s)
754{ 781{
755 icons->setSortMethod((LauncherIconView::SortMethod)s); 782 icons->setSortMethod((LauncherIconView::SortMethod)s);
756} 783}
757 784
758void LauncherView::showType(int t) 785void LauncherView::showType(int t)
759{ 786{
760 if ( t >= (int)typelist.count() ) { 787 if ( t >= (int)typelist.count() ) {
761 icons->setTypeFilter("",TRUE); 788 icons->setTypeFilter("",TRUE);
762 } else { 789 } else {
763 QString ty = typelist[t]; 790 QString ty = typelist[t];
764 if ( !ty.contains('/') ) 791 if ( !ty.contains('/') )
765 ty += "/*"; 792 ty += "/*";
766 icons->setTypeFilter(ty,TRUE); 793 icons->setTypeFilter(ty,TRUE);
767 } 794 }
768} 795}
769 796
770void LauncherView::showCategory( int c ) 797void LauncherView::showCategory( int c )
771{ 798{
772 icons->setCategoryFilter( c, TRUE ); 799 icons->setCategoryFilter( c, TRUE );
773} 800}
774 801
775void LauncherView::setViewMode( ViewMode m ) 802void LauncherView::setViewMode( ViewMode m )
776{ 803{
777 if ( vmode != m ) { 804 if ( vmode != m ) {
778 bool bigIcons = m == Icon; 805 bool bigIcons = m == Icon;
779 icons->viewport()->setUpdatesEnabled( FALSE ); 806 icons->viewport()->setUpdatesEnabled( FALSE );
780 icons->setBigIcons( bigIcons ); 807 icons->setBigIcons( bigIcons );
781 switch ( m ) { 808 switch ( m ) {
782 case List: 809 case List:
783 icons->setItemTextPos( QIconView::Right ); 810 icons->setItemTextPos( QIconView::Right );
784 break; 811 break;
785 case Icon: 812 case Icon:
786 icons->setItemTextPos( QIconView::Bottom ); 813 icons->setItemTextPos( QIconView::Bottom );
787 break; 814 break;
788 } 815 }
789 icons->hideOrShowItems( FALSE ); 816 icons->hideOrShowItems( FALSE );
790 icons->viewport()->setUpdatesEnabled( TRUE ); 817 icons->viewport()->setUpdatesEnabled( TRUE );
791 vmode = m; 818 vmode = m;
792 } 819 }
793} 820}
794 821
795// 822//
796// User images may require scaling. 823// User images may require scaling.
797// 824//
798QImage LauncherView::loadBackgroundImage(QString &bgName) 825QImage LauncherView::loadBackgroundImage(QString &bgName)
799{ 826{
800 QImageIO imgio; 827 QImageIO imgio;
801 QSize ds = qApp->desktop()->size(); // should be launcher, not desktop 828 QSize ds = qApp->desktop()->size(); // should be launcher, not desktop
802 bool further_scaling = TRUE; 829 bool further_scaling = TRUE;
803 830
804 imgio.setFileName( bgName ); 831 imgio.setFileName( bgName );
805 imgio.setParameters("GetHeaderInformation"); 832 imgio.setParameters("GetHeaderInformation");
806 833
807 if (imgio.read() == FALSE) { 834 if (imgio.read() == FALSE) {
808 return imgio.image(); 835 return imgio.image();
809 } 836 }
810 837
811 if (imgio.image().width() < ds.width() && 838 if (imgio.image().width() < ds.width() &&
812 imgio.image().height() < ds.height()) { 839 imgio.image().height() < ds.height()) {
813 further_scaling = FALSE; 840 further_scaling = FALSE;
814 } 841 }
815 842
816 if (!imgio.image().bits()) { 843 if (!imgio.image().bits()) {
817 // 844 //
818 // Scale and load. Note we don't scale up. 845 // Scale and load. Note we don't scale up.
819 // 846 //
820 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr 847 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr
821 imgio.setParameters(further_scaling ? 848 imgio.setParameters(further_scaling ?
822 param.arg(ds.width()).arg(ds.height()).latin1() : 849 param.arg(ds.width()).arg(ds.height()).latin1() :
823 ""); 850 "");
824 imgio.read(); 851 imgio.read();
825 } else { 852 } else {
826 if (further_scaling) { 853 if (further_scaling) {
827 int t1 = imgio.image().width() * ds.height(); 854 int t1 = imgio.image().width() * ds.height();
828 int t2 = imgio.image().height() * ds.width(); 855 int t2 = imgio.image().height() * ds.width();
829 int dsth = ds.height(); 856 int dsth = ds.height();
830 int dstw = ds.width(); 857 int dstw = ds.width();
831 858
832 if (t1 > t2) { 859 if (t1 > t2) {
833 dsth = t2 / imgio.image().width(); 860 dsth = t2 / imgio.image().width();
834 } else { 861 } else {
835 dstw = t1 / imgio.image().height(); 862 dstw = t1 / imgio.image().height();
836 } 863 }
837 864
838 // 865 //
839 // Loader didn't scale for us. Do it manually. 866 // Loader didn't scale for us. Do it manually.
840 // 867 //
841 return imgio.image().smoothScale(dstw, dsth); 868 return imgio.image().smoothScale(dstw, dsth);
842 } 869 }
843 } 870 }
844 871
845 return imgio.image(); 872 return imgio.image();
846} 873}
847 874
848void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) 875void LauncherView::setBackgroundType( BackgroundType t, const QString &val )
849{ 876{
850 if ( !bgCache ) { 877 if ( !bgCache ) {
851 bgCache = new QMap<QString,BgPixmap*>; 878 bgCache = new QMap<QString,BgPixmap*>;
852 qAddPostRoutine( cleanup_cache ); 879 qAddPostRoutine( cleanup_cache );
853 } 880 }
854 881
855 if ( bgCache->contains( bgName ) ) 882 if ( bgCache->contains( bgName ) )
856 (*bgCache)[bgName]->ref--; 883 (*bgCache)[bgName]->ref--;
857 bgName = ""; 884 bgName = "";
858 885
859 QPixmap bg; 886 QPixmap bg;
860 887
861 switch ( t ) { 888 switch ( t ) {
862 case Ruled: { 889 case Ruled: {
863 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr 890 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr
864 if ( bgCache->contains( bgName ) ) { 891 if ( bgCache->contains( bgName ) ) {
865 (*bgCache)[bgName]->ref++; 892 (*bgCache)[bgName]->ref++;
866 bg = (*bgCache)[bgName]->pm; 893 bg = (*bgCache)[bgName]->pm;
867 } else { 894 } else {
868 bg.resize( width(), 9 ); 895 bg.resize( width(), 9 );
869 QPainter painter( &bg ); 896 QPainter painter( &bg );
870 for ( int i = 0; i < 3; i++ ) { 897 for ( int i = 0; i < 3; i++ ) {
871 painter.setPen( white ); 898 painter.setPen( white );
872 painter.drawLine( 0, i*3, width()-1, i*3 ); 899 painter.drawLine( 0, i*3, width()-1, i*3 );
873 painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); 900 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
874 painter.setPen( colorGroup().background().light(105) ); 901 painter.setPen( colorGroup().background().light(105) );
875 painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); 902 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
876 } 903 }
877 painter.end(); 904 painter.end();
878 bgCache->insert( bgName, new BgPixmap(bg) ); 905 bgCache->insert( bgName, new BgPixmap(bg) );
879 } 906 }
880 break; 907 break;
881 } 908 }
882 909
883 case Image: 910 case Image:
884 if (!val.isEmpty()) { 911 if (!val.isEmpty()) {
885 bgName = val; 912 bgName = val;
886 if ( bgCache->contains( bgName ) ) { 913 if ( bgCache->contains( bgName ) ) {
887 (*bgCache)[bgName]->ref++; 914 (*bgCache)[bgName]->ref++;
888 bg = (*bgCache)[bgName]->pm; 915 bg = (*bgCache)[bgName]->pm;
889 } else { 916 } else {
890 QString imgFile = bgName; 917 QString imgFile = bgName;
891 bool tile = FALSE; 918 bool tile = FALSE;
892 if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { 919 if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) {
893 imgFile = Resource::findPixmap( imgFile ); 920 imgFile = Resource::findPixmap( imgFile );
894 tile = TRUE; 921 tile = TRUE;
895 } 922 }
896 QImage img = loadBackgroundImage(imgFile); 923 QImage img = loadBackgroundImage(imgFile);
897 924
898 925
899 if ( img.depth() == 1 ) 926 if ( img.depth() == 1 )
900 img = img.convertDepth(8); 927 img = img.convertDepth(8);
901 img.setAlphaBuffer(FALSE); 928 img.setAlphaBuffer(FALSE);
902 bg.convertFromImage(img); 929 bg.convertFromImage(img);
903 bgCache->insert( bgName, new BgPixmap(bg) ); 930 bgCache->insert( bgName, new BgPixmap(bg) );
904 } 931 }
905 } 932 }
906 break; 933 break;
907 934
908 case SolidColor: 935 case SolidColor:
909 default: 936 default:
910 break; 937 break;
911 } 938 }
912 939
913 const QObjectList *list = queryList( "QWidget", 0, FALSE ); 940 const QObjectList *list = queryList( "QWidget", 0, FALSE );
914 QObject *obj; 941 QObject *obj;
915 for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { 942 for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) {
916 if ( obj->isWidgetType() ) { 943 if ( obj->isWidgetType() ) {
917 QWidget *w = (QWidget*)obj; 944 QWidget *w = (QWidget*)obj;
918 w->setBackgroundPixmap( bg ); 945 w->setBackgroundPixmap( bg );
919 if ( bgName.isEmpty() ) { 946 if ( bgName.isEmpty() ) {
920 // Solid Color 947 // Solid Color
921 if ( val.isEmpty() ) 948 if ( val.isEmpty() )
922 w->setBackgroundColor( colorGroup().base() ); 949 w->setBackgroundColor( colorGroup().base() );
923 else 950 else
924 w->setBackgroundColor( val ); 951 w->setBackgroundColor( val );
925 } else { 952 } else {
926 // Ruled or Image pixmap 953 // Ruled or Image pixmap
927 w->setBackgroundOrigin( ParentOrigin ); 954 w->setBackgroundOrigin( ParentOrigin );
928 } 955 }
929 } 956 }
930 } 957 }
931 delete list; 958 delete list;
932 959
933 bgType = t; 960 bgType = t;
934 icons->viewport()->update(); 961 icons->viewport()->update();
935 962
936 QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); 963 QTimer::singleShot( 1000, this, SLOT(flushBgCache()) );
937} 964}
938 965
939void LauncherView::setTextColor( const QColor &tc ) 966void LauncherView::setTextColor( const QColor &tc )
940{ 967{
941 textCol = tc; 968 textCol = tc;
942 QColorGroup cg = icons->colorGroup(); 969 QColorGroup cg = icons->colorGroup();
943 cg.setColor( QColorGroup::Text, tc ); 970 cg.setColor( QColorGroup::Text, tc );
944 icons->setPalette( QPalette(cg,cg,cg) ); 971 icons->setPalette( QPalette(cg,cg,cg) );
945 icons->viewport()->update(); 972 icons->viewport()->update();
946} 973}
947 974
948void LauncherView::setViewFont( const QFont &f ) 975void LauncherView::setViewFont( const QFont &f )
949{ 976{
950 icons->setFont( f ); 977 icons->setFont( f );
951 icons->hideOrShowItems( FALSE ); 978 icons->hideOrShowItems( FALSE );
952} 979}
953 980
954void LauncherView::clearViewFont() 981void LauncherView::clearViewFont()
955{ 982{
956 icons->unsetFont(); 983 icons->unsetFont();
957 icons->hideOrShowItems( FALSE ); 984 icons->hideOrShowItems( FALSE );
958} 985}
959 986
960void LauncherView::resizeEvent(QResizeEvent *e) 987void LauncherView::resizeEvent(QResizeEvent *e)
961{ 988{
962// qDebug("LauncherView resize event"); 989// qDebug("LauncherView resize event");
963 QVBox::resizeEvent( e ); 990 QVBox::resizeEvent( e );
964// commented out for launcherview and qt/e 2.3.8 problems, probably needs real fixing somewhere... 991// commented out for launcherview and qt/e 2.3.8 problems, probably needs real fixing somewhere...
965// if ( e->size().width() != e->oldSize().width() ) 992// if ( e->size().width() != e->oldSize().width() )
966 sort(); 993 sort();
967} 994}
968 995
969void LauncherView::selectionChanged() 996void LauncherView::selectionChanged()
970{ 997{
971 QIconViewItem* item = icons->currentItem(); 998 QIconViewItem* item = icons->currentItem();
972 if ( item && item->isSelected() ) { 999 if ( item && item->isSelected() ) {
973 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1000 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
974 if ( icons->inKeyEvent() ) // not for mouse press 1001 if ( icons->inKeyEvent() ) // not for mouse press
975 emit clicked( appLnk ); 1002 emit clicked( appLnk );
976 item->setSelected(FALSE); 1003 item->setSelected(FALSE);
977 } 1004 }
978} 1005}
979 1006
980void LauncherView::returnPressed( QIconViewItem *item ) 1007void LauncherView::returnPressed( QIconViewItem *item )
981{ 1008{
982 if ( item ) { 1009 if ( item ) {
983 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1010 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
984 emit clicked( appLnk ); 1011 emit clicked( appLnk );
985 } 1012 }
986} 1013}
987 1014
988void LauncherView::itemClicked( int btn, QIconViewItem *item ) 1015void LauncherView::itemClicked( int btn, QIconViewItem *item )
989{ 1016{
990 if ( item ) { 1017 if ( item ) {
991 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1018 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
992 if ( btn == LeftButton ) { 1019 if ( btn == LeftButton ) {
993 // Make sure it's the item we execute that gets highlighted 1020 // Make sure it's the item we execute that gets highlighted
994 icons->setCurrentItem( item ); 1021 icons->setCurrentItem( item );
995 emit clicked( appLnk ); 1022 emit clicked( appLnk );
996 } 1023 }
997 item->setSelected(FALSE); 1024 item->setSelected(FALSE);
998 } 1025 }
999} 1026}
1000 1027
1001void LauncherView::itemPressed( int btn, QIconViewItem *item ) 1028void LauncherView::itemPressed( int btn, QIconViewItem *item )
1002{ 1029{
1003 if ( item ) { 1030 if ( item ) {
1004 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 1031 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
1005 if ( btn == RightButton ) 1032 if ( btn == RightButton )
1006 emit rightPressed( appLnk ); 1033 emit rightPressed( appLnk );
1007 else if ( btn == ShiftButton ) 1034 else if ( btn == ShiftButton )
1008 emit rightPressed( appLnk ); 1035 emit rightPressed( appLnk );
1009 item->setSelected(FALSE); 1036 item->setSelected(FALSE);
1010 } 1037 }
1011} 1038}
1012 1039
1013void LauncherView::removeAllItems() 1040void LauncherView::removeAllItems()
1014{ 1041{
1015 icons->clear(); 1042 icons->clear();
1016} 1043}
1017 1044
1018bool LauncherView::removeLink(const QString& linkfile) 1045bool LauncherView::removeLink(const QString& linkfile)
1019{ 1046{
1020 return icons->removeLink(linkfile); 1047 return icons->removeLink(linkfile);
1021} 1048}
1022 1049
1023void LauncherView::setSortEnabled( bool v ) 1050void LauncherView::setSortEnabled( bool v )
1024{ 1051{
1025 icons->setSorting( v ); 1052 icons->setSorting( v );
1026 if ( v ) 1053 if ( v )
1027 sort(); 1054 sort();
1028} 1055}
1029 1056
1030void LauncherView::setUpdatesEnabled( bool u ) 1057void LauncherView::setUpdatesEnabled( bool u )
1031{ 1058{
1032 icons->setUpdatesEnabled( u ); 1059 icons->setUpdatesEnabled( u );
1033} 1060}
1034 1061
1035void LauncherView::sort() 1062void LauncherView::sort()
1036{ 1063{
1037 icons->sort(); 1064 icons->sort();
1038} 1065}
1039 1066
1040void LauncherView::addItem(AppLnk* app, bool resort) 1067void LauncherView::addItem(AppLnk* app, bool resort)
1041{ 1068{
1042 icons->addItem(app,resort); 1069 icons->addItem(app,resort);
1043} 1070}
1044 1071
1045void LauncherView::paletteChange( const QPalette &p ) 1072void LauncherView::paletteChange( const QPalette &p )
1046{ 1073{
1047 icons->unsetPalette(); 1074 icons->unsetPalette();
1048 QVBox::paletteChange( p ); 1075 QVBox::paletteChange( p );
1049 if ( bgType == Ruled ) 1076 if ( bgType == Ruled )
1050 setBackgroundType( Ruled, QString::null ); 1077 setBackgroundType( Ruled, QString::null );
1051 QColorGroup cg = icons->colorGroup(); 1078 QColorGroup cg = icons->colorGroup();
1052 cg.setColor( QColorGroup::Text, textCol ); 1079 cg.setColor( QColorGroup::Text, textCol );
1053 icons->setPalette( QPalette(cg,cg,cg) ); 1080 icons->setPalette( QPalette(cg,cg,cg) );
1054} 1081}
1055 1082
1056void LauncherView::fontChanged(const QFont&) 1083void LauncherView::fontChanged(const QFont&)
1057{ 1084{
1058 odebug << "LauncherView::fontChanged()" << oendl; 1085 odebug << "LauncherView::fontChanged()" << oendl;
1059 icons->hideOrShowItems( FALSE ); 1086 icons->hideOrShowItems( FALSE );
1060} 1087}
1061 1088
1062void LauncherView::relayout(void) 1089void LauncherView::relayout(void)
1063{ 1090{
1064 icons->hideOrShowItems(FALSE); 1091 icons->hideOrShowItems(FALSE);
1065} 1092}
1066 1093
1067void LauncherView::flushBgCache() 1094void LauncherView::flushBgCache()
1068{ 1095{
1069 if ( !bgCache ) 1096 if ( !bgCache )
1070 return; 1097 return;
1071 // remove unreferenced backgrounds. 1098 // remove unreferenced backgrounds.
1072 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 1099 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
1073 while ( it != bgCache->end() ) { 1100 while ( it != bgCache->end() ) {
1074 QMap<QString,BgPixmap*>::Iterator curr = it; 1101 QMap<QString,BgPixmap*>::Iterator curr = it;
1075 ++it; 1102 ++it;
1076 if ( (*curr)->ref == 0 ) { 1103 if ( (*curr)->ref == 0 ) {
1077 delete (*curr); 1104 delete (*curr);
1078 bgCache->remove( curr ); 1105 bgCache->remove( curr );
1079 } 1106 }
1080 } 1107 }
1081} 1108}
1082 1109
1083/* 1110/*
1084 * Launcherthumbnail handling for image files 1111 * Launcherthumbnail handling for image files
1085 */ 1112 */
1086 1113
1087/* special image handling - based on opie eye */ 1114/* special image handling - based on opie eye */
1088QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) { 1115QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) {
1089 s >> inf.file >> inf.pixmap >> inf.width >> inf.height; 1116 s >> inf.file >> inf.pixmap >> inf.width >> inf.height;
1090 return s; 1117 return s;
1091} 1118}
1092 1119
1093QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) { 1120QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) {
1094 return s << inf.file << inf.width << inf.height; 1121 return s << inf.file << inf.width << inf.height;
1095} 1122}
1096 1123
1097LauncherThumbReceiver::LauncherThumbReceiver() 1124LauncherThumbReceiver::LauncherThumbReceiver()
1098 :QObject() 1125 :QObject()
1099{ 1126{
1100 QCopChannel * chan = new QCopChannel( "QPE/opie-eye",this ); 1127 QCopChannel * chan = new QCopChannel( "QPE/opie-eye",this );
1101 connect(chan, SIGNAL(received(const QCString&,const QByteArray&)), 1128 connect(chan, SIGNAL(received(const QCString&,const QByteArray&)),
1102 this, SLOT(recieve(const QCString&,const QByteArray&)) ); 1129 this, SLOT(recieve(const QCString&,const QByteArray&)) );
1103 1130
1104 { 1131 {
1105 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); 1132 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
1106 } 1133 }
1107} 1134}
1108 1135
1109LauncherThumbReceiver::~LauncherThumbReceiver() 1136LauncherThumbReceiver::~LauncherThumbReceiver()
1110{ 1137{
1111 { 1138 {
1112 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); 1139 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
1113 } 1140 }
1114} 1141}
1115 1142
1116void LauncherThumbReceiver::recieve( const QCString&str, const QByteArray&at ) 1143void LauncherThumbReceiver::recieve( const QCString&str, const QByteArray&at )
1117{ 1144{
1118 PixmapInfos pixinfos; 1145 PixmapInfos pixinfos;
1119 QDataStream stream( at, IO_ReadOnly ); 1146 QDataStream stream( at, IO_ReadOnly );
1120 1147
1121 /* we are just interested in thumbmails */ 1148 /* we are just interested in thumbmails */
1122 if ( str == "pixmapsHandled(PixmapList)" ) 1149 if ( str == "pixmapsHandled(PixmapList)" )
1123 stream >> pixinfos; 1150 stream >> pixinfos;
1124 1151
1125 for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it ) { 1152 for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it ) {
1126 odebug << "Pixinfos: " << (*it).file << " - " << (*it).width << oendl;
1127 emit sig_Thumbnail((*it).pixmap,(*it).file,(*it).width); 1153 emit sig_Thumbnail((*it).pixmap,(*it).file,(*it).width);
1128 } 1154 }
1129} 1155}
1130 1156
1131void LauncherThumbReceiver::requestThumb(const QString&file,int width,int height) 1157void LauncherThumbReceiver::requestThumb(const QString&file,int width,int height)
1132{ 1158{
1133 PixmapInfo rItem; 1159 PixmapInfo rItem;
1134 rItem.file = file; 1160 rItem.file = file;
1135 rItem.width = width; 1161 rItem.width = width;
1136 rItem.height = height; 1162 rItem.height = height;
1137 m_inThumbNail.append(rItem); 1163 m_inThumbNail.append(rItem);
1138 QTimer::singleShot(0, this, SLOT(sendRequest())); 1164 QTimer::singleShot(0, this, SLOT(sendRequest()));
1139} 1165}
1140 1166
1141void LauncherThumbReceiver::sendRequest() 1167void LauncherThumbReceiver::sendRequest()
1142{ 1168{
1143 if (m_inThumbNail.count()>0) { 1169 if (m_inThumbNail.count()>0) {
1144 QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" ); 1170 QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" );
1145 env << m_inThumbNail; 1171 env << m_inThumbNail;
1146 m_inThumbNail.clear(); 1172 m_inThumbNail.clear();
1147 } 1173 }
1148} 1174}
diff --git a/core/launcher/launcherview.h b/core/launcher/launcherview.h
index 0be9a1f..ebb1362 100644
--- a/core/launcher/launcherview.h
+++ b/core/launcher/launcherview.h
@@ -1,254 +1,244 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef LAUNCHERVIEW_H 20#ifndef LAUNCHERVIEW_H
21#define LAUNCHERVIEW_H 21#define LAUNCHERVIEW_H
22 22
23#include <qtopia/storage.h> 23#include <qtopia/storage.h>
24#include <qtopia/applnk.h> 24#include <qtopia/applnk.h>
25 25
26#include <qvbox.h> 26#include <qvbox.h>
27#include <qiconview.h> 27#include <qiconview.h>
28#include <qtimer.h>
28 29
29class CategorySelect; 30class CategorySelect;
30class LauncherIconView; 31class LauncherIconView;
31class LauncherItem; 32class LauncherItem;
32class QIconViewItem; 33class QIconViewItem;
33class QLabel; 34class QLabel;
34class QWidgetStack; 35class QWidgetStack;
35class MenuButton; 36class MenuButton;
36class QComboBox; 37class QComboBox;
37 38
38 39
39 40
40enum BusyIndicatorType { 41enum BusyIndicatorType {
41 BIT_Normal = 0, 42 BIT_Normal = 0,
42 BIT_Animated 43 BIT_Animated
43}; 44};
44 45
45class LauncherView : public QVBox 46class LauncherView : public QVBox
46{ 47{
47 Q_OBJECT 48 Q_OBJECT
48 49
49public: 50public:
50 LauncherView( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 51 LauncherView( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
51 ~LauncherView(); 52 ~LauncherView();
52 53
53 void hideIcons(); 54 void hideIcons();
54 55
55 bool removeLink(const QString& linkfile); 56 bool removeLink(const QString& linkfile);
56 void addItem(AppLnk* app, bool resort=TRUE); 57 void addItem(AppLnk* app, bool resort=TRUE);
57 void removeAllItems(); 58 void removeAllItems();
58 void setSortEnabled(bool); 59 void setSortEnabled(bool);
59 void setUpdatesEnabled(bool); 60 void setUpdatesEnabled(bool);
60 void sort(); 61 void sort();
61 62
62 void setToolsEnabled(bool); 63 void setToolsEnabled(bool);
63 void updateTools(); 64 void updateTools();
64 65
65 void setBusy(bool); 66 void setBusy(bool);
66 void setBusyIndicatorType( const QString& ); 67 void setBusyIndicatorType( const QString& );
67 68
68 enum ViewMode { Icon, List }; 69 enum ViewMode { Icon, List };
69 void setViewMode( ViewMode m ); 70 void setViewMode( ViewMode m );
70 ViewMode viewMode() const { return vmode; } 71 ViewMode viewMode() const { return vmode; }
71 72
72 enum BackgroundType { Ruled, SolidColor, Image }; 73 enum BackgroundType { Ruled, SolidColor, Image };
73 void setBackgroundType( BackgroundType t, const QString & ); 74 void setBackgroundType( BackgroundType t, const QString & );
74 BackgroundType backgroundType() const { return bgType; } 75 BackgroundType backgroundType() const { return bgType; }
75 76
76 void setTextColor( const QColor & ); 77 void setTextColor( const QColor & );
77 QColor textColor() const { return textCol; } 78 QColor textColor() const { return textCol; }
78 79
79 void setViewFont( const QFont & ); 80 void setViewFont( const QFont & );
80 void clearViewFont(); 81 void clearViewFont();
81 82
82 void relayout(void); 83 void relayout(void);
83 84
84signals: 85signals:
85 void clicked( const AppLnk * ); 86 void clicked( const AppLnk * );
86 void rightPressed( AppLnk * ); 87 void rightPressed( AppLnk * );
87 88
88protected slots: 89protected slots:
89 void selectionChanged(); 90 void selectionChanged();
90 void returnPressed( QIconViewItem *item ); 91 void returnPressed( QIconViewItem *item );
91 void itemClicked( int, QIconViewItem * ); 92 void itemClicked( int, QIconViewItem * );
92 void itemPressed( int, QIconViewItem * ); 93 void itemPressed( int, QIconViewItem * );
93 void sortBy(int); 94 void sortBy(int);
94 void showType(int); 95 void showType(int);
95 void showCategory( int ); 96 void showCategory( int );
96 void resizeEvent(QResizeEvent *); 97 void resizeEvent(QResizeEvent *);
97 void flushBgCache(); 98 void flushBgCache();
98 99
99protected: 100protected:
100 void paletteChange( const QPalette & ); 101 void paletteChange( const QPalette & );
101 102
102 void fontChanged(const QFont &); 103 void fontChanged(const QFont &);
103 104
104private: 105private:
105 static bool bsy; 106 static bool bsy;
106 QWidget* tools; 107 QWidget* tools;
107 LauncherIconView* icons; 108 LauncherIconView* icons;
108 QComboBox *typemb; 109 QComboBox *typemb;
109 QStringList typelist; 110 QStringList typelist;
110 CategorySelect *catmb; 111 CategorySelect *catmb;
111 ViewMode vmode; 112 ViewMode vmode;
112 BackgroundType bgType; 113 BackgroundType bgType;
113 QString bgName; 114 QString bgName;
114 QColor textCol; 115 QColor textCol;
115 116
116 QImage loadBackgroundImage(QString &fname); 117 QImage loadBackgroundImage(QString &fname);
117 118
118}; 119};
119 120
120/* from opie-eye */ 121/* from opie-eye */
121struct PixmapInfo { 122struct PixmapInfo {
122 PixmapInfo() : width( -1 ), height( -1 ) {} 123 PixmapInfo() : width( -1 ), height( -1 ) {}
123 bool operator==( const PixmapInfo& r ) { 124 bool operator==( const PixmapInfo& r ) {
124 if ( width != r.width ) return false; 125 if ( width != r.width ) return false;
125 if ( height != r.height ) return false; 126 if ( height != r.height ) return false;
126 if ( file != r.file ) return false; 127 if ( file != r.file ) return false;
127 return true; 128 return true;
128 } 129 }
129 int width, height; 130 int width, height;
130 QString file; 131 QString file;
131 QPixmap pixmap; 132 QPixmap pixmap;
132}; 133};
133 134
134class LauncherThumbReceiver:public QObject 135class LauncherThumbReceiver:public QObject
135{ 136{
136 Q_OBJECT 137 Q_OBJECT
137 typedef QValueList<PixmapInfo> PixmapInfos; 138 typedef QValueList<PixmapInfo> PixmapInfos;
138public: 139public:
139 LauncherThumbReceiver(); 140 LauncherThumbReceiver();
140 ~LauncherThumbReceiver(); 141 ~LauncherThumbReceiver();
141 void requestThumb(const QString&file,int width,int height); 142 void requestThumb(const QString&file,int width,int height);
142 143
143public slots: 144public slots:
144 void recieve( const QCString&, const QByteArray& ); 145 void recieve( const QCString&, const QByteArray& );
145protected slots: 146protected slots:
146 virtual void sendRequest(); 147 virtual void sendRequest();
147 148
148signals: 149signals:
149 void sig_Thumbnail(const QPixmap&,const QString&,int); 150 void sig_Thumbnail(const QPixmap&,const QString&,int);
150 151
151protected: 152protected:
152 PixmapInfos m_inThumbNail; 153 PixmapInfos m_inThumbNail;
153}; 154};
154 155
155class LauncherIconView : public QIconView { 156class LauncherIconView : public QIconView {
156 Q_OBJECT 157 Q_OBJECT
157public: 158public:
158 LauncherIconView( QWidget* parent, const char* name=0 ); 159 LauncherIconView( QWidget* parent, const char* name=0 );
159 ~LauncherIconView(); 160 ~LauncherIconView();
160 QIconViewItem* busyItem() const; 161 QIconViewItem* busyItem() const;
161 162
162#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 163#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
163 QPixmap busyPixmap() const { return busyPix; } 164 QPixmap busyPixmap() const { return busyPix; }
164#endif 165#endif
165 void setBigIcons( bool bi ); 166 void setBigIcons( bool bi );
166 void updateCategoriesAndMimeTypes(); 167 void updateCategoriesAndMimeTypes();
167 void setBusyIndicatorType ( BusyIndicatorType t ); 168 void setBusyIndicatorType ( BusyIndicatorType t );
168 void doAutoScroll() 169 void doAutoScroll()
169 { 170 {
170 // We don't want rubberbanding (yet) 171 // We don't want rubberbanding (yet)
171 } 172 }
172 173
173 void setBusy(bool on); 174 void setBusy(bool on);
174 bool inKeyEvent() const { return ike; } 175 bool inKeyEvent() const { return ike; }
175 176
176 void keyPressEvent(QKeyEvent* e)
177 {
178 ike = TRUE;
179 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) {
180 if ( (e->state() & ShiftButton) )
181 emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() );
182 else
183 returnPressed(currentItem());
184 }
185
186 QIconView::keyPressEvent(e);
187 ike = FALSE;
188 }
189
190 void addItem(AppLnk* app, bool resort=TRUE); 177 void addItem(AppLnk* app, bool resort=TRUE);
191 bool removeLink(const QString& linkfile); 178 bool removeLink(const QString& linkfile);
192 179
193 QStringList mimeTypes() const; 180 QStringList mimeTypes() const;
194 QStringList categories() const; 181 QStringList categories() const;
195 void clear(); 182 void clear();
196 void addCatsAndMimes(AppLnk* app); 183 void addCatsAndMimes(AppLnk* app);
197 184
198 void setBackgroundOrigin( QWidget::BackgroundOrigin ) {} 185 void setBackgroundOrigin( QWidget::BackgroundOrigin ) {}
199 186
200 void setBackgroundPixmap( const QPixmap &pm ) { 187 void setBackgroundPixmap( const QPixmap &pm ) {
201 bgPixmap = pm; 188 bgPixmap = pm;
202 } 189 }
203 190
204 void setBackgroundColor( const QColor &c ) { 191 void setBackgroundColor( const QColor &c ) {
205 bgColor = c; 192 bgColor = c;
206 } 193 }
207 194
208 void drawBackground( QPainter *p, const QRect &r ); 195 void drawBackground( QPainter *p, const QRect &r );
209 void setItemTextPos( ItemTextPos pos ); 196 void setItemTextPos( ItemTextPos pos );
210 void hideOrShowItems(bool resort); 197 void hideOrShowItems(bool resort);
211 198
212 void setTypeFilter(const QString& typefilter, bool resort); 199 void setTypeFilter(const QString& typefilter, bool resort);
213 void setCategoryFilter( int catfilter, bool resort ); 200 void setCategoryFilter( int catfilter, bool resort );
214 201
215 enum SortMethod { Name, Date, Type }; 202 enum SortMethod { Name, Date, Type };
216 203
217 void setSortMethod( SortMethod m ); 204 void setSortMethod( SortMethod m );
218 int compare(const AppLnk* a, const AppLnk* b); 205 int compare(const AppLnk* a, const AppLnk* b);
219 void requestEyePix(const LauncherItem*which); 206 void requestEyePix(const LauncherItem*which);
220 207
221protected: 208protected:
222 void timerEvent( QTimerEvent *te ); 209 virtual void timerEvent( QTimerEvent *te );
223 void styleChange( QStyle &old ); 210 void styleChange( QStyle &old );
224 void calculateGrid( ItemTextPos pos ); 211 void calculateGrid( ItemTextPos pos );
225 void focusInEvent( QFocusEvent * ) {} 212 void focusInEvent( QFocusEvent * ) {}
226 void focusOutEvent( QFocusEvent * ) {} 213 void focusOutEvent( QFocusEvent * ) {}
227 LauncherItem*findDocItem(const QString&); 214 LauncherItem*findDocItem(const QString&);
228 void addCheckItem(AppLnk* app); 215 void addCheckItem(AppLnk* app);
229 void checkCallback(); 216 void checkCallback();
217 virtual void keyPressEvent(QKeyEvent* e);
230 218
231protected slots: 219protected slots:
232 void setEyePixmap(const QPixmap&,const QString&,int width); 220 void setEyePixmap(const QPixmap&,const QString&,int width);
221 void stopEyeTimer();
233 222
234private: 223private:
235 QList<AppLnk> hidden; 224 QList<AppLnk> hidden;
236 QDict<void> mimes; 225 QDict<void> mimes;
237 QDict<void> cats; 226 QDict<void> cats;
238 SortMethod sortmeth; 227 SortMethod sortmeth;
239 QRegExp tf; 228 QRegExp tf;
240 int cf; 229 int cf;
241 LauncherItem* bsy; 230 LauncherItem* bsy;
242 int busyTimer; 231 int busyTimer;
243 bool ike; 232 bool ike;
244 bool bigIcns; 233 bool bigIcns;
245 QPixmap bgPixmap; 234 QPixmap bgPixmap;
246 QColor bgColor; 235 QColor bgColor;
247 LauncherThumbReceiver*m_EyeCallBack; 236 LauncherThumbReceiver*m_EyeCallBack;
248#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 237#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
249 QPixmap busyPix; 238 QPixmap busyPix;
250#endif 239#endif
251 BusyIndicatorType busyType; 240 BusyIndicatorType busyType;
241 QTimer m_eyeTimer;
252}; 242};
253 243
254#endif // LAUNCHERVIEW_H 244#endif // LAUNCHERVIEW_H