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