summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-09-29 23:08:59 (UTC)
committer harlekin <harlekin>2002-09-29 23:08:59 (UTC)
commitb53db7a5a334fdd53bd86e8b50587f1dae41cfba (patch) (unidiff)
treea2a24eea2bebefdbb02302ad57c0c0cbf425683e
parenta54430dbebd980109afdf604c7bfc9b0e15c4fdb (diff)
downloadopie-b53db7a5a334fdd53bd86e8b50587f1dae41cfba.zip
opie-b53db7a5a334fdd53bd86e8b50587f1dae41cfba.tar.gz
opie-b53db7a5a334fdd53bd86e8b50587f1dae41cfba.tar.bz2
temporary workarround to prevent high cpuloads after first app is launched
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 9f86136..dbcb0d7 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,300 +1,302 @@
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#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; } 86 QPixmap* busyPixmap() const { return (QPixmap*)&bpm; }
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 if ( bsy != c ) { 100 if ( bsy != c ) {
101 if ( bsy ) 101 if ( bsy )
102 bsy-> repaint ( ); 102 bsy-> repaint ( );
103 bsy = c; 103 bsy = c;
104 104
105 if ( bsy ) { 105 if ( bsy ) {
106 busytimer = startTimer ( 150 ); 106 busytimer = startTimer ( 150 );
107 busystate = 50; 107 busystate = 50;
108 startTimer ( 0 ); 108 // not sure what this startTimer is for, maybe i am just to tired. But
109 // currently that causes 100% cpuload on app launch
110 //startTimer ( 0 );
109 } 111 }
110 else 112 else
111 killTimer ( busytimer ); 113 killTimer ( busytimer );
112 } 114 }
113 } 115 }
114 116
115 virtual void timerEvent ( QTimerEvent *te ) 117 virtual void timerEvent ( QTimerEvent *te )
116 { 118 {
117 if ( !te || ( te-> timerId ( ) == busytimer )) { 119 if ( !te || ( te-> timerId ( ) == busytimer )) {
118 if ( bsy ) { 120 if ( bsy ) {
119 QPixmap *src = bsy-> QIconViewItem::pixmap(); 121 QPixmap *src = bsy-> QIconViewItem::pixmap();
120 QImage img = src->convertToImage(); 122 QImage img = src->convertToImage();
121 QRgb* rgb; 123 QRgb* rgb;
122 int count; 124 int count;
123 if ( img.depth() == 32 ) { 125 if ( img.depth() == 32 ) {
124 rgb = (QRgb*)img.bits(); 126 rgb = (QRgb*)img.bits();
125 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 127 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
126 } else { 128 } else {
127 rgb = img.colorTable(); 129 rgb = img.colorTable();
128 count = img.numColors(); 130 count = img.numColors();
129 } 131 }
130 int rc, gc, bc; 132 int rc, gc, bc;
131 int bs = ::abs ( busystate ) + 25; 133 int bs = ::abs ( busystate ) + 25;
132 colorGroup().highlight().rgb( &rc, &gc, &bc ); 134 colorGroup().highlight().rgb( &rc, &gc, &bc );
133 rc = rc * bs / 100; 135 rc = rc * bs / 100;
134 gc = gc * bs / 100; 136 gc = gc * bs / 100;
135 bc = bc * bs / 100; 137 bc = bc * bs / 100;
136 138
137 for ( int r = 0; r < count; r++, rgb++ ) { 139 for ( int r = 0; r < count; r++, rgb++ ) {
138 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; 140 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
139 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; 141 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
140 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; 142 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
141 int ai = qAlpha ( *rgb ); 143 int ai = qAlpha ( *rgb );
142 *rgb = qRgba ( ri, gi, bi, ai ); 144 *rgb = qRgba ( ri, gi, bi, ai );
143 } 145 }
144 146
145 bpm.convertFromImage( img ); 147 bpm.convertFromImage( img );
146 148
147 bsy-> repaint ( ); 149 bsy-> repaint ( );
148 150
149 busystate += 10; 151 busystate += 10;
150 if ( busystate > 50 ) 152 if ( busystate > 50 )
151 busystate = -40; 153 busystate = -40;
152 } 154 }
153 } 155 }
154 } 156 }
155 157
156 bool inKeyEvent() const { return ike; } 158 bool inKeyEvent() const { return ike; }
157 void keyPressEvent(QKeyEvent* e) 159 void keyPressEvent(QKeyEvent* e)
158 { 160 {
159 ike = TRUE; 161 ike = TRUE;
160 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) 162 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
161 returnPressed(currentItem()); 163 returnPressed(currentItem());
162 QIconView::keyPressEvent(e); 164 QIconView::keyPressEvent(e);
163 ike = FALSE; 165 ike = FALSE;
164 } 166 }
165 167
166 void addItem(AppLnk* app, bool resort=TRUE); 168 void addItem(AppLnk* app, bool resort=TRUE);
167 bool removeLink(const QString& linkfile); 169 bool removeLink(const QString& linkfile);
168 170
169 QStringList mimeTypes() const; 171 QStringList mimeTypes() const;
170 QStringList categories() const; 172 QStringList categories() const;
171 173
172 void clear() 174 void clear()
173 { 175 {
174 mimes.clear(); 176 mimes.clear();
175 cats.clear(); 177 cats.clear();
176 QIconView::clear(); 178 QIconView::clear();
177 hidden.clear(); 179 hidden.clear();
178 } 180 }
179 181
180 void addCatsAndMimes(AppLnk* app) 182 void addCatsAndMimes(AppLnk* app)
181 { 183 {
182 // QStringList c = app->categories(); 184 // QStringList c = app->categories();
183 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 185 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
184 // cats.replace(*cit,(void*)1); 186 // cats.replace(*cit,(void*)1);
185 // } 187 // }
186 QString maj=app->type(); 188 QString maj=app->type();
187 int sl=maj.find('/'); 189 int sl=maj.find('/');
188 if (sl>=0) { 190 if (sl>=0) {
189 QString k; 191 QString k;
190 k = maj.left(12) == "application/" ? maj : maj.left(sl); 192 k = maj.left(12) == "application/" ? maj : maj.left(sl);
191 mimes.replace(k,(void*)1); 193 mimes.replace(k,(void*)1);
192 } 194 }
193 } 195 }
194 196
195 void setBackgroundPixmap( const QPixmap &pm ) { 197 void setBackgroundPixmap( const QPixmap &pm ) {
196 bgPixmap = pm; 198 bgPixmap = pm;
197 } 199 }
198 200
199 void setBackgroundColor( const QColor &c ) { 201 void setBackgroundColor( const QColor &c ) {
200 bgColor = c; 202 bgColor = c;
201 } 203 }
202 204
203 void drawBackground( QPainter *p, const QRect &r ) 205 void drawBackground( QPainter *p, const QRect &r )
204 { 206 {
205 if ( !bgPixmap.isNull() ) { 207 if ( !bgPixmap.isNull() ) {
206 p->drawTiledPixmap( r, bgPixmap, 208 p->drawTiledPixmap( r, bgPixmap,
207 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 209 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
208 (r.y() + contentsY()) % bgPixmap.height() ) ); 210 (r.y() + contentsY()) % bgPixmap.height() ) );
209 } else { 211 } else {
210 p->fillRect( r, bgColor ); 212 p->fillRect( r, bgColor );
211 } 213 }
212 } 214 }
213 215
214 void setItemTextPos( ItemTextPos pos ) 216 void setItemTextPos( ItemTextPos pos )
215 { 217 {
216 calculateGrid( pos ); 218 calculateGrid( pos );
217 QIconView::setItemTextPos( pos ); 219 QIconView::setItemTextPos( pos );
218 } 220 }
219 221
220 void hideOrShowItems(bool resort); 222 void hideOrShowItems(bool resort);
221 223
222 void setTypeFilter(const QString& typefilter, bool resort) 224 void setTypeFilter(const QString& typefilter, bool resort)
223 { 225 {
224 tf = QRegExp(typefilter,FALSE,TRUE); 226 tf = QRegExp(typefilter,FALSE,TRUE);
225 hideOrShowItems(resort); 227 hideOrShowItems(resort);
226 } 228 }
227 229
228 void setCategoryFilter( int catfilter, bool resort ) 230 void setCategoryFilter( int catfilter, bool resort )
229 { 231 {
230 Categories cat; 232 Categories cat;
231 cat.load( categoryFileName() ); 233 cat.load( categoryFileName() );
232 QString str; 234 QString str;
233 if ( catfilter == -2 ) 235 if ( catfilter == -2 )
234 cf = 0; 236 cf = 0;
235 else 237 else
236 cf = catfilter; 238 cf = catfilter;
237 hideOrShowItems(resort); 239 hideOrShowItems(resort);
238 } 240 }
239 241
240 enum SortMethod { Name, Date, Type }; 242 enum SortMethod { Name, Date, Type };
241 243
242 void setSortMethod( SortMethod m ) 244 void setSortMethod( SortMethod m )
243 { 245 {
244 if ( sortmeth != m ) { 246 if ( sortmeth != m ) {
245 sortmeth = m; 247 sortmeth = m;
246 sort(); 248 sort();
247 } 249 }
248 } 250 }
249 251
250 int compare(const AppLnk* a, const AppLnk* b) 252 int compare(const AppLnk* a, const AppLnk* b)
251 { 253 {
252 switch (sortmeth) { 254 switch (sortmeth) {
253 case Name: 255 case Name:
254 return a->name().compare(b->name()); 256 return a->name().compare(b->name());
255 case Date: { 257 case Date: {
256 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 258 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
257 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 259 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
258 return fa.lastModified().secsTo(fb.lastModified()); 260 return fa.lastModified().secsTo(fb.lastModified());
259 } 261 }
260 case Type: 262 case Type:
261 return a->type().compare(b->type()); 263 return a->type().compare(b->type());
262 } 264 }
263 return 0; 265 return 0;
264 } 266 }
265 267
266 QString getAllDocLinkInfo() const; 268 QString getAllDocLinkInfo() const;
267 269
268protected: 270protected:
269 271
270 void styleChange( QStyle &old ) 272 void styleChange( QStyle &old )
271 { 273 {
272 QIconView::styleChange( old ); 274 QIconView::styleChange( old );
273 calculateGrid( itemTextPos() ); 275 calculateGrid( itemTextPos() );
274 } 276 }
275 277
276 void calculateGrid( ItemTextPos pos ) 278 void calculateGrid( ItemTextPos pos )
277 { 279 {
278 int dw = QApplication::desktop()->width(); 280 int dw = QApplication::desktop()->width();
279 int viewerWidth = dw-style().scrollBarExtent().width(); 281 int viewerWidth = dw-style().scrollBarExtent().width();
280 if ( pos == Bottom ) { 282 if ( pos == Bottom ) {
281 int cols = 3; 283 int cols = 3;
282 if ( viewerWidth <= 200 ) 284 if ( viewerWidth <= 200 )
283 cols = 2; 285 cols = 2;
284 else if ( viewerWidth >= 400 ) 286 else if ( viewerWidth >= 400 )
285 cols = viewerWidth/96; 287 cols = viewerWidth/96;
286 setSpacing( 4 ); 288 setSpacing( 4 );
287 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 289 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
288 setGridY( fontMetrics().height()*2+24 ); 290 setGridY( fontMetrics().height()*2+24 );
289 } else { 291 } else {
290 int cols = 2; 292 int cols = 2;
291 if ( viewerWidth < 150 ) 293 if ( viewerWidth < 150 )
292 cols = 1; 294 cols = 1;
293 else if ( viewerWidth >= 400 ) 295 else if ( viewerWidth >= 400 )
294 cols = viewerWidth/150; 296 cols = viewerWidth/150;
295 setSpacing( 2 ); 297 setSpacing( 2 );
296 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 298 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
297 setGridY( fontMetrics().height()+2 ); 299 setGridY( fontMetrics().height()+2 );
298 } 300 }
299 } 301 }
300 302