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