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