summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 5daaeff..33717bc 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -4,302 +4,309 @@
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#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qpe/qpedebug.h> 25#include <qpe/qpedebug.h>
26#include <qpe/categories.h> 26#include <qpe/categories.h>
27#include <qpe/categoryselect.h> 27#include <qpe/categoryselect.h>
28#include <qpe/menubutton.h> 28#include <qpe/menubutton.h>
29#include <qpe/mimetype.h> 29#include <qpe/mimetype.h>
30#include <qpe/resource.h> 30#include <qpe/resource.h>
31#include <qpe/qpetoolbar.h> 31#include <qpe/qpetoolbar.h>
32//#include <qtopia/private/palmtoprecord.h> 32//#include <qtopia/private/palmtoprecord.h>
33 33
34#include <qtimer.h> 34#include <qtimer.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qdict.h> 36#include <qdict.h>
37#include <qfile.h> 37#include <qfile.h>
38#include <qfileinfo.h> 38#include <qfileinfo.h>
39#include <qhbox.h> 39#include <qhbox.h>
40#include <qiconview.h> 40#include <qiconview.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qregexp.h> 42#include <qregexp.h>
43#include <qtoolbutton.h> 43#include <qtoolbutton.h>
44#include <qimage.h> 44#include <qimage.h>
45 45
46 46
47class BgPixmap 47class BgPixmap
48{ 48{
49public: 49public:
50 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 50 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
51 QPixmap pm; 51 QPixmap pm;
52 int ref; 52 int ref;
53}; 53};
54 54
55static QMap<QString,BgPixmap*> *bgCache = 0; 55static QMap<QString,BgPixmap*> *bgCache = 0;
56 56
57class LauncherIconView : public QIconView { 57class LauncherIconView : public QIconView {
58public: 58public:
59 LauncherIconView( QWidget* parent, const char* name=0 ) : 59 LauncherIconView( QWidget* parent, const char* name=0 ) :
60 QIconView(parent,name), 60 QIconView(parent,name),
61 tf(""), 61 tf(""),
62 cf(0), 62 cf(0),
63 bsy(0), 63 bsy(0),
64 bigIcns(TRUE), 64 bigIcns(TRUE),
65 bgColor(white) 65 bgColor(white)
66 { 66 {
67 sortmeth = Name; 67 sortmeth = Name;
68 hidden.setAutoDelete(TRUE); 68 hidden.setAutoDelete(TRUE);
69 ike = FALSE; 69 ike = FALSE;
70 busytimer = 0; 70 busytimer = 0;
71 calculateGrid( Bottom ); 71 calculateGrid( Bottom );
72 } 72 }
73 73
74 ~LauncherIconView() 74 ~LauncherIconView()
75 { 75 {
76#if 0 // debuggery 76#if 0 // debuggery
77 QListIterator<AppLnk> it(hidden); 77 QListIterator<AppLnk> it(hidden);
78 AppLnk* l; 78 AppLnk* l;
79 while ((l=it.current())) { 79 while ((l=it.current())) {
80 ++it; 80 ++it;
81 //qDebug("%p: hidden (should remove)",l); 81 //qDebug("%p: hidden (should remove)",l);
82 } 82 }
83#endif 83#endif
84 } 84 }
85 85
86 QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; } 86 QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; }
87 QIconViewItem* busyItem() const { return bsy; } 87 QIconViewItem* busyItem() const { return bsy; }
88 void setBigIcons( bool bi ) { bigIcns = bi; } 88 void setBigIcons( bool bi ) { bigIcns = bi; }
89 89
90 void updateCategoriesAndMimeTypes(); 90 void updateCategoriesAndMimeTypes();
91 91
92 void doAutoScroll() 92 void doAutoScroll()
93 { 93 {
94 // We don't want rubberbanding (yet) 94 // We don't want rubberbanding (yet)
95 } 95 }
96 96
97 void setBusy(bool on) 97 void setBusy(bool on)
98 { 98 {
99 QIconViewItem *c = on ? currentItem() : 0; 99 QIconViewItem *c = on ? currentItem() : 0;
100 qDebug ( "set busy %d -> %s", on, c ? c-> text ().latin1() : "(null)" );
101
100 if ( bsy != c ) { 102 if ( bsy != c ) {
101 if ( bsy ) 103 QIconViewItem *oldbsy = bsy;
102 bsy-> repaint ( );
103 bsy = c; 104 bsy = c;
104 105
106 if ( oldbsy )
107 oldbsy-> repaint ( );
108
105 if ( bsy ) { 109 if ( bsy ) {
106 busystate = 5; 110 QPixmap *src = bsy-> QIconViewItem::pixmap();
107 for ( int i = 0; i <= 5; i++ ) 111 for ( int i = 0; i <= 5; i++ ) {
108 bpm [i] = QPixmap ( );
109 timerEvent ( 0 );
110 busytimer = startTimer ( 150 );
111 }
112 else
113 killTimer ( busytimer );
114 }
115 }
116
117 virtual void timerEvent ( QTimerEvent *te )
118 {
119 if ( !te || ( te-> timerId ( ) == busytimer )) {
120 if ( bsy ) {
121 if ( bpm [::abs(busystate)]. isNull ( )) {
122 QPixmap *src = bsy-> QIconViewItem::pixmap();
123 QImage img = src->convertToImage(); 112 QImage img = src->convertToImage();
124 QRgb* rgb; 113 QRgb* rgb;
125 int count; 114 int count;
126 if ( img.depth() == 32 ) { 115 if ( img.depth() == 32 ) {
127 rgb = (QRgb*)img.bits(); 116 rgb = (QRgb*)img.bits();
128 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 117 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
129 } else { 118 } else {
130 rgb = img.colorTable(); 119 rgb = img.colorTable();
131 count = img.numColors(); 120 count = img.numColors();
132 } 121 }
133 int rc, gc, bc; 122 int rc, gc, bc;
134 int bs = ::abs ( busystate * 10 ) + 25; 123 int bs = ::abs ( i * 10 ) + 25;
135 colorGroup().highlight().rgb( &rc, &gc, &bc ); 124 colorGroup().highlight().rgb( &rc, &gc, &bc );
136 rc = rc * bs / 100; 125 rc = rc * bs / 100;
137 gc = gc * bs / 100; 126 gc = gc * bs / 100;
138 bc = bc * bs / 100; 127 bc = bc * bs / 100;
139 128
140 for ( int r = 0; r < count; r++, rgb++ ) { 129 for ( int r = 0; r < count; r++, rgb++ ) {
141 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; 130 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
142 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; 131 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
143 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; 132 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
144 int ai = qAlpha ( *rgb ); 133 int ai = qAlpha ( *rgb );
145 *rgb = qRgba ( ri, gi, bi, ai ); 134 *rgb = qRgba ( ri, gi, bi, ai );
146 } 135 }
147 136
148 bpm [::abs(busystate)].convertFromImage( img ); 137 bpm [i].convertFromImage( img );
149 } 138 }
150 bsy-> repaint ( ); 139 busystate = 0;
140 if ( busytimer )
141 killTimer ( busytimer );
142 timerEvent ( 0 );
143 busytimer = startTimer ( 180 );
144 }
145 else {
146 killTimer ( busytimer );
147 busytimer = 0;
148 }
149 }
150 }
151 151
152 virtual void timerEvent ( QTimerEvent *te )
153 {
154 if ( !te || ( te-> timerId ( ) == busytimer )) {
155 if ( bsy ) {
152 busystate++; 156 busystate++;
153 if ( busystate > 5 ) 157 if ( busystate > 5 )
154 busystate = -4; 158 busystate = -4;
159
160 bsy-> repaint ( );
155 } 161 }
156 } 162 }
157 } 163 }
158 164
159 bool inKeyEvent() const { return ike; } 165 bool inKeyEvent() const { return ike; }
160 void keyPressEvent(QKeyEvent* e) 166 void keyPressEvent(QKeyEvent* e)
161 { 167 {
162 ike = TRUE; 168 ike = TRUE;
163 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) 169 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
164 returnPressed(currentItem()); 170 returnPressed(currentItem());
165 QIconView::keyPressEvent(e); 171 QIconView::keyPressEvent(e);
166 ike = FALSE; 172 ike = FALSE;
167 } 173 }
168 174
169 void addItem(AppLnk* app, bool resort=TRUE); 175 void addItem(AppLnk* app, bool resort=TRUE);
170 bool removeLink(const QString& linkfile); 176 bool removeLink(const QString& linkfile);
171 177
172 QStringList mimeTypes() const; 178 QStringList mimeTypes() const;
173 QStringList categories() const; 179 QStringList categories() const;
174 180
175 void clear() 181 void clear()
176 { 182 {
177 mimes.clear(); 183 mimes.clear();
178 cats.clear(); 184 cats.clear();
179 QIconView::clear(); 185 QIconView::clear();
180 hidden.clear(); 186 hidden.clear();
181 } 187 }
182 188
183 void addCatsAndMimes(AppLnk* app) 189 void addCatsAndMimes(AppLnk* app)
184 { 190 {
185 // QStringList c = app->categories(); 191 // QStringList c = app->categories();
186 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 192 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
187 // cats.replace(*cit,(void*)1); 193 // cats.replace(*cit,(void*)1);
188 // } 194 // }
189 QString maj=app->type(); 195 QString maj=app->type();
190 int sl=maj.find('/'); 196 int sl=maj.find('/');
191 if (sl>=0) { 197 if (sl>=0) {
192 QString k; 198 QString k;
193 k = maj.left(12) == "application/" ? maj : maj.left(sl); 199 k = maj.left(12) == "application/" ? maj : maj.left(sl);
194 mimes.replace(k,(void*)1); 200 mimes.replace(k,(void*)1);
195 } 201 }
196 } 202 }
197 203
198 void setBackgroundPixmap( const QPixmap &pm ) { 204 void setBackgroundPixmap( const QPixmap &pm ) {
199 bgPixmap = pm; 205 bgPixmap = pm;
200 } 206 }
201 207
202 void setBackgroundColor( const QColor &c ) { 208 void setBackgroundColor( const QColor &c ) {
203 bgColor = c; 209 bgColor = c;
204 } 210 }
205 211
206 void drawBackground( QPainter *p, const QRect &r ) 212 void drawBackground( QPainter *p, const QRect &r )
207 { 213 {
208 if ( !bgPixmap.isNull() ) { 214 if ( !bgPixmap.isNull() ) {
209 p->drawTiledPixmap( r, bgPixmap, 215 p-> fillRect ( r, bgColor );
216 p->drawTiledPixmap( r, bgPixmap,
210 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 217 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
211 (r.y() + contentsY()) % bgPixmap.height() ) ); 218 (r.y() + contentsY()) % bgPixmap.height() ) );
212 } else { 219 } else {
213 p->fillRect( r, bgColor ); 220 p->fillRect( r, bgColor );
214 } 221 }
215 } 222 }
216 223
217 void setItemTextPos( ItemTextPos pos ) 224 void setItemTextPos( ItemTextPos pos )
218 { 225 {
219 calculateGrid( pos ); 226 calculateGrid( pos );
220 QIconView::setItemTextPos( pos ); 227 QIconView::setItemTextPos( pos );
221 } 228 }
222 229
223 void hideOrShowItems(bool resort); 230 void hideOrShowItems(bool resort);
224 231
225 void setTypeFilter(const QString& typefilter, bool resort) 232 void setTypeFilter(const QString& typefilter, bool resort)
226 { 233 {
227 tf = QRegExp(typefilter,FALSE,TRUE); 234 tf = QRegExp(typefilter,FALSE,TRUE);
228 hideOrShowItems(resort); 235 hideOrShowItems(resort);
229 } 236 }
230 237
231 void setCategoryFilter( int catfilter, bool resort ) 238 void setCategoryFilter( int catfilter, bool resort )
232 { 239 {
233 Categories cat; 240 Categories cat;
234 cat.load( categoryFileName() ); 241 cat.load( categoryFileName() );
235 QString str; 242 QString str;
236 if ( catfilter == -2 ) 243 if ( catfilter == -2 )
237 cf = 0; 244 cf = 0;
238 else 245 else
239 cf = catfilter; 246 cf = catfilter;
240 hideOrShowItems(resort); 247 hideOrShowItems(resort);
241 } 248 }
242 249
243 enum SortMethod { Name, Date, Type }; 250 enum SortMethod { Name, Date, Type };
244 251
245 void setSortMethod( SortMethod m ) 252 void setSortMethod( SortMethod m )
246 { 253 {
247 if ( sortmeth != m ) { 254 if ( sortmeth != m ) {
248 sortmeth = m; 255 sortmeth = m;
249 sort(); 256 sort();
250 } 257 }
251 } 258 }
252 259
253 int compare(const AppLnk* a, const AppLnk* b) 260 int compare(const AppLnk* a, const AppLnk* b)
254 { 261 {
255 switch (sortmeth) { 262 switch (sortmeth) {
256 case Name: 263 case Name:
257 return a->name().compare(b->name()); 264 return a->name().compare(b->name());
258 case Date: { 265 case Date: {
259 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 266 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
260 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 267 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
261 return fa.lastModified().secsTo(fb.lastModified()); 268 return fa.lastModified().secsTo(fb.lastModified());
262 } 269 }
263 case Type: 270 case Type:
264 return a->type().compare(b->type()); 271 return a->type().compare(b->type());
265 } 272 }
266 return 0; 273 return 0;
267 } 274 }
268 275
269 QString getAllDocLinkInfo() const; 276 QString getAllDocLinkInfo() const;
270 277
271protected: 278protected:
272 279
273 void styleChange( QStyle &old ) 280 void styleChange( QStyle &old )
274 { 281 {
275 QIconView::styleChange( old ); 282 QIconView::styleChange( old );
276 calculateGrid( itemTextPos() ); 283 calculateGrid( itemTextPos() );
277 } 284 }
278 285
279 void calculateGrid( ItemTextPos pos ) 286 void calculateGrid( ItemTextPos pos )
280 { 287 {
281 int dw = QApplication::desktop()->width(); 288 int dw = QApplication::desktop()->width();
282 int viewerWidth = dw-style().scrollBarExtent().width(); 289 int viewerWidth = dw-style().scrollBarExtent().width();
283 if ( pos == Bottom ) { 290 if ( pos == Bottom ) {
284 int cols = 3; 291 int cols = 3;
285 if ( viewerWidth <= 200 ) 292 if ( viewerWidth <= 200 )
286 cols = 2; 293 cols = 2;
287 else if ( viewerWidth >= 400 ) 294 else if ( viewerWidth >= 400 )
288 cols = viewerWidth/96; 295 cols = viewerWidth/96;
289 setSpacing( 4 ); 296 setSpacing( 4 );
290 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 297 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
291 setGridY( fontMetrics().height()*2+24 ); 298 setGridY( fontMetrics().height()*2+24 );
292 } else { 299 } else {
293 int cols = 2; 300 int cols = 2;
294 if ( viewerWidth < 150 ) 301 if ( viewerWidth < 150 )
295 cols = 1; 302 cols = 1;
296 else if ( viewerWidth >= 400 ) 303 else if ( viewerWidth >= 400 )
297 cols = viewerWidth/150; 304 cols = viewerWidth/150;
298 setSpacing( 2 ); 305 setSpacing( 2 );
299 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 306 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
300 setGridY( fontMetrics().height()+2 ); 307 setGridY( fontMetrics().height()+2 );
301 } 308 }
302 } 309 }
303 310
304private: 311private:
305 QList<AppLnk> hidden; 312 QList<AppLnk> hidden;