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