author | zecke <zecke> | 2002-09-10 14:21:14 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-10 14:21:14 (UTC) |
commit | 8b59b498892b0e345d977ccd520087b660a91437 (patch) (unidiff) | |
tree | 4b9fef30cc51cce8e50c072038d15d8e10b29fb2 /library | |
parent | 4aad041a733e2478ff29330e1544e5fefcfb5cde (diff) | |
download | opie-8b59b498892b0e345d977ccd520087b660a91437.zip opie-8b59b498892b0e345d977ccd520087b660a91437.tar.gz opie-8b59b498892b0e345d977ccd520087b660a91437.tar.bz2 |
AppLnk fix QArray -> QMAp
-rw-r--r-- | library/applnk.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 298581a..41b3008 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -1,599 +1,602 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_MIMEEXT | 21 | #define QTOPIA_INTERNAL_MIMEEXT |
22 | #define QTOPIA_INTERNAL_PRELOADACCESS | 22 | #define QTOPIA_INTERNAL_PRELOADACCESS |
23 | #define QTOPIA_INTERNAL_APPLNKASSIGN | 23 | #define QTOPIA_INTERNAL_APPLNKASSIGN |
24 | 24 | ||
25 | #include "applnk.h" | 25 | #include "applnk.h" |
26 | 26 | ||
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #include <qpe/categories.h> | 28 | #include <qpe/categories.h> |
29 | #include <qpe/categoryselect.h> | 29 | #include <qpe/categoryselect.h> |
30 | #ifdef QWS | 30 | #ifdef QWS |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | #endif | 32 | #endif |
33 | #include <qpe/global.h> | 33 | #include <qpe/global.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | #include <qpe/storage.h> | 36 | #include <qpe/storage.h> |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | 38 | ||
39 | #include <qdict.h> | 39 | #include <qdict.h> |
40 | #include <qdir.h> | 40 | #include <qdir.h> |
41 | #include <qregexp.h> | 41 | #include <qregexp.h> |
42 | 42 | ||
43 | #ifdef Q_WS_QWS | 43 | #ifdef Q_WS_QWS |
44 | #include <qgfx_qws.h> | 44 | #include <qgfx_qws.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | 48 | ||
49 | int AppLnk::lastId = 5000; | 49 | int AppLnk::lastId = 5000; |
50 | 50 | ||
51 | static int smallSize = 14; | 51 | static int smallSize = 14; |
52 | static int bigSize = 32; | 52 | static int bigSize = 32; |
53 | 53 | ||
54 | static QString safeFileName(const QString& n) | 54 | static QString safeFileName(const QString& n) |
55 | { | 55 | { |
56 | QString safename=n; | 56 | QString safename=n; |
57 | safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); | 57 | safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); |
58 | safename.replace(QRegExp("^[^A-Za-z]*"),""); | 58 | safename.replace(QRegExp("^[^A-Za-z]*"),""); |
59 | if ( safename.isEmpty() ) | 59 | if ( safename.isEmpty() ) |
60 | safename = "_"; | 60 | safename = "_"; |
61 | return safename; | 61 | return safename; |
62 | } | 62 | } |
63 | 63 | ||
64 | static bool prepareDirectories(const QString& lf) | 64 | static bool prepareDirectories(const QString& lf) |
65 | { | 65 | { |
66 | if ( !QFile::exists(lf) ) { | 66 | if ( !QFile::exists(lf) ) { |
67 | // May need to create directories | 67 | // May need to create directories |
68 | QFileInfo fi(lf); | 68 | QFileInfo fi(lf); |
69 | if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) | 69 | if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) |
70 | return FALSE; | 70 | return FALSE; |
71 | } | 71 | } |
72 | return TRUE; | 72 | return TRUE; |
73 | } | 73 | } |
74 | 74 | ||
75 | class AppLnkPrivate | 75 | class AppLnkPrivate |
76 | { | 76 | { |
77 | public: | 77 | public: |
78 | /* the size of the Pixmap */ | 78 | /* the size of the Pixmap */ |
79 | enum Size {Normal = 0, Big }; | 79 | enum Size {Normal = 0, Big }; |
80 | AppLnkPrivate() { | 80 | AppLnkPrivate() { |
81 | /* we want one normal and one big item */ | 81 | /* we want one normal and one big item */ |
82 | mPixmaps = QArray<QPixmap>(2); | 82 | |
83 | QPixmap pix; | ||
84 | mPixmaps.insert(0, pix ); | ||
85 | mPixmaps.insert(1, pix); | ||
83 | } | 86 | } |
84 | 87 | ||
85 | QStringList mCatList; // always correct | 88 | QStringList mCatList; // always correct |
86 | QArray<int> mCat; // cached value; correct if not empty | 89 | QArray<int> mCat; // cached value; correct if not empty |
87 | QArray<QPixmap> mPixmaps; | 90 | QMap<int, QPixmap> mPixmaps; |
88 | 91 | ||
89 | void updateCatListFromArray() | 92 | void updateCatListFromArray() |
90 | { | 93 | { |
91 | Categories cat( 0 ); | 94 | Categories cat( 0 ); |
92 | cat.load( categoryFileName() ); | 95 | cat.load( categoryFileName() ); |
93 | mCatList = cat.labels("Document View",mCat); | 96 | mCatList = cat.labels("Document View",mCat); |
94 | } | 97 | } |
95 | 98 | ||
96 | void setCatArrayDirty() | 99 | void setCatArrayDirty() |
97 | { | 100 | { |
98 | mCat.resize(0); | 101 | mCat.resize(0); |
99 | } | 102 | } |
100 | 103 | ||
101 | void ensureCatArray() | 104 | void ensureCatArray() |
102 | { | 105 | { |
103 | if ( mCat.count() > 0 || mCatList.count()==0 ) | 106 | if ( mCat.count() > 0 || mCatList.count()==0 ) |
104 | return; | 107 | return; |
105 | 108 | ||
106 | Categories cat( 0 ); | 109 | Categories cat( 0 ); |
107 | cat.load( categoryFileName() ); | 110 | cat.load( categoryFileName() ); |
108 | mCat.resize( mCatList.count() ); | 111 | mCat.resize( mCatList.count() ); |
109 | int i; | 112 | int i; |
110 | QStringList::ConstIterator it; | 113 | QStringList::ConstIterator it; |
111 | for ( i = 0, it = mCatList.begin(); it != mCatList.end(); | 114 | for ( i = 0, it = mCatList.begin(); it != mCatList.end(); |
112 | ++it, i++ ) { | 115 | ++it, i++ ) { |
113 | 116 | ||
114 | bool number; | 117 | bool number; |
115 | int id = (*it).toInt( &number ); | 118 | int id = (*it).toInt( &number ); |
116 | if ( !number ) { | 119 | if ( !number ) { |
117 | id = cat.id( "Document View", *it ); | 120 | id = cat.id( "Document View", *it ); |
118 | if ( id == 0 ) | 121 | if ( id == 0 ) |
119 | id = cat.addCategory( "Document View", *it ); | 122 | id = cat.addCategory( "Document View", *it ); |
120 | } | 123 | } |
121 | mCat[i] = id; | 124 | mCat[i] = id; |
122 | } | 125 | } |
123 | } | 126 | } |
124 | }; | 127 | }; |
125 | 128 | ||
126 | /*! | 129 | /*! |
127 | \class AppLnk applnk.h | 130 | \class AppLnk applnk.h |
128 | \brief The AppLnk class represents an application available on the system. | 131 | \brief The AppLnk class represents an application available on the system. |
129 | 132 | ||
130 | Every Qtopia application \e app has a corresponding \e app.desktop | 133 | Every Qtopia application \e app has a corresponding \e app.desktop |
131 | file. When one of these files is read its data is stored as an | 134 | file. When one of these files is read its data is stored as an |
132 | AppLnk object. | 135 | AppLnk object. |
133 | 136 | ||
134 | The AppLnk class introduces some Qtopia-specific concepts, and | 137 | The AppLnk class introduces some Qtopia-specific concepts, and |
135 | provides a variety of functions, as described in the following | 138 | provides a variety of functions, as described in the following |
136 | sections. | 139 | sections. |
137 | \tableofcontents | 140 | \tableofcontents |
138 | 141 | ||
139 | \target Types | 142 | \target Types |
140 | \section1 Types | 143 | \section1 Types |
141 | 144 | ||
142 | Every AppLnk object has a \e type. For applications, games and | 145 | Every AppLnk object has a \e type. For applications, games and |
143 | settings the type is \c Application; for documents the | 146 | settings the type is \c Application; for documents the |
144 | type is the document's MIME type. | 147 | type is the document's MIME type. |
145 | 148 | ||
146 | \target files-and-links | 149 | \target files-and-links |
147 | \section1 Files and Links | 150 | \section1 Files and Links |
148 | 151 | ||
149 | When you create an AppLnk (or more likely, a \link doclnk.html | 152 | When you create an AppLnk (or more likely, a \link doclnk.html |
150 | DocLnk\endlink), you don't deal directly with filenames in the | 153 | DocLnk\endlink), you don't deal directly with filenames in the |
151 | filesystem. Instead you do this: | 154 | filesystem. Instead you do this: |
152 | \code | 155 | \code |
153 | DocLnk d; | 156 | DocLnk d; |
154 | d.setType("text/plain"); | 157 | d.setType("text/plain"); |
155 | d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. | 158 | d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. |
156 | \endcode | 159 | \endcode |
157 | At this point, the file() and linkFile() are unknown. Normally | 160 | At this point, the file() and linkFile() are unknown. Normally |
158 | this is uninteresting, and the names become automatically known, | 161 | this is uninteresting, and the names become automatically known, |
159 | and more importantly, becomes reserved, when you ask what they are: | 162 | and more importantly, becomes reserved, when you ask what they are: |
160 | 163 | ||
161 | \code | 164 | \code |
162 | QString fn = d.file(); | 165 | QString fn = d.file(); |
163 | \endcode | 166 | \endcode |
164 | This invents a filename, and creates the file on disk (an empty | 167 | This invents a filename, and creates the file on disk (an empty |
165 | reservation file) to prevent the name being used by another | 168 | reservation file) to prevent the name being used by another |
166 | application. | 169 | application. |
167 | 170 | ||
168 | In some circumstances, you don't want to create the file if it | 171 | In some circumstances, you don't want to create the file if it |
169 | doesn't already exist (e.g. in the Document tab, some of the \link | 172 | doesn't already exist (e.g. in the Document tab, some of the \link |
170 | doclnk.html DocLnk\endlink objects represented by icons are | 173 | doclnk.html DocLnk\endlink objects represented by icons are |
171 | DocLnk's created just for that view - they don't have | 174 | DocLnk's created just for that view - they don't have |
172 | corresponding \c .desktop files. To avoid littering empty | 175 | corresponding \c .desktop files. To avoid littering empty |
173 | reservation files around, we check in a few places to see whether | 176 | reservation files around, we check in a few places to see whether |
174 | the file really needs to exist). | 177 | the file really needs to exist). |
175 | 178 | ||
176 | \section1 Functionality | 179 | \section1 Functionality |
177 | 180 | ||
178 | AppLnk objects are created by calling the constructor with the | 181 | AppLnk objects are created by calling the constructor with the |
179 | name of a \e .desktop file. The object can be checked for validity | 182 | name of a \e .desktop file. The object can be checked for validity |
180 | using isValid(). | 183 | using isValid(). |
181 | 184 | ||
182 | The following functions are used to set or retrieve information | 185 | The following functions are used to set or retrieve information |
183 | about the application: | 186 | about the application: |
184 | \table | 187 | \table |
185 | \header \i Get Function \i Set Function \i Short Description | 188 | \header \i Get Function \i Set Function \i Short Description |
186 | \row \i \l name() \i \l setName() \i application's name | 189 | \row \i \l name() \i \l setName() \i application's name |
187 | \row \i \l pixmap() \i \e none \i application's icon | 190 | \row \i \l pixmap() \i \e none \i application's icon |
188 | \row \i \l bigPixmap() \i \e none \i application's large icon | 191 | \row \i \l bigPixmap() \i \e none \i application's large icon |
189 | \row \i \e none \i setIcon() \i sets the icon's filename | 192 | \row \i \e none \i setIcon() \i sets the icon's filename |
190 | \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above | 193 | \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above |
191 | \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees | 194 | \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees |
192 | \row \i \l comment() \i \l setComment() \i text for the Details dialog | 195 | \row \i \l comment() \i \l setComment() \i text for the Details dialog |
193 | \row \i \l exec() \i \l setExec() \i executable's filename | 196 | \row \i \l exec() \i \l setExec() \i executable's filename |
194 | \row \i \l file() \i \e none \i document's filename | 197 | \row \i \l file() \i \e none \i document's filename |
195 | \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename | 198 | \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename |
196 | \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit | 199 | \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit |
197 | \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions} | 200 | \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions} |
198 | \row \i \l fileKnown() \i \e none \i see \link | 201 | \row \i \l fileKnown() \i \e none \i see \link |
199 | #files-and-links Files and Links\endlink above | 202 | #files-and-links Files and Links\endlink above |
200 | \row \i \l linkFileKnown() \i \e none \i see \link | 203 | \row \i \l linkFileKnown() \i \e none \i see \link |
201 | #files-and-links Files and Links\endlink above | 204 | #files-and-links Files and Links\endlink above |
202 | \row \i \l property() \i \l setProperty()\i any AppLnk property | 205 | \row \i \l property() \i \l setProperty()\i any AppLnk property |
203 | can be retrieved or set (if writeable) using these | 206 | can be retrieved or set (if writeable) using these |
204 | \endtable | 207 | \endtable |
205 | 208 | ||
206 | To save an AppLnk to disk use writeLink(). To execute the | 209 | To save an AppLnk to disk use writeLink(). To execute the |
207 | application that the AppLnk object refers to, use execute(). | 210 | application that the AppLnk object refers to, use execute(). |
208 | 211 | ||
209 | AppLnk's can be deleted from disk using removeLinkFile(). To | 212 | AppLnk's can be deleted from disk using removeLinkFile(). To |
210 | remove both the link and the application's executable use | 213 | remove both the link and the application's executable use |
211 | removeFiles(). | 214 | removeFiles(). |
212 | 215 | ||
213 | Icon sizes can be globally changed (but only for AppLnk objects | 216 | Icon sizes can be globally changed (but only for AppLnk objects |
214 | created after the calls) with setSmallIconSize() and | 217 | created after the calls) with setSmallIconSize() and |
215 | setBigIconSize(). | 218 | setBigIconSize(). |
216 | 219 | ||
217 | \ingroup qtopiaemb | 220 | \ingroup qtopiaemb |
218 | */ | 221 | */ |
219 | 222 | ||
220 | /*! | 223 | /*! |
221 | Sets the size used for small icons to \a small pixels. | 224 | Sets the size used for small icons to \a small pixels. |
222 | Only affects AppLnk objects created after the call. | 225 | Only affects AppLnk objects created after the call. |
223 | 226 | ||
224 | \sa smallIconSize() setIcon() | 227 | \sa smallIconSize() setIcon() |
225 | */ | 228 | */ |
226 | void AppLnk::setSmallIconSize(int small) | 229 | void AppLnk::setSmallIconSize(int small) |
227 | { | 230 | { |
228 | smallSize = small; | 231 | smallSize = small; |
229 | } | 232 | } |
230 | 233 | ||
231 | /*! | 234 | /*! |
232 | Returns the size used for small icons. | 235 | Returns the size used for small icons. |
233 | 236 | ||
234 | \sa setSmallIconSize() setIcon() | 237 | \sa setSmallIconSize() setIcon() |
235 | */ | 238 | */ |
236 | int AppLnk::smallIconSize() | 239 | int AppLnk::smallIconSize() |
237 | { | 240 | { |
238 | return smallSize; | 241 | return smallSize; |
239 | } | 242 | } |
240 | 243 | ||
241 | 244 | ||
242 | /*! | 245 | /*! |
243 | Sets the size used for large icons to \a big pixels. | 246 | Sets the size used for large icons to \a big pixels. |
244 | Only affects AppLnk objects created after the call. | 247 | Only affects AppLnk objects created after the call. |
245 | 248 | ||
246 | \sa bigIconSize() setIcon() | 249 | \sa bigIconSize() setIcon() |
247 | */ | 250 | */ |
248 | void AppLnk::setBigIconSize(int big) | 251 | void AppLnk::setBigIconSize(int big) |
249 | { | 252 | { |
250 | bigSize = big; | 253 | bigSize = big; |
251 | } | 254 | } |
252 | 255 | ||
253 | /*! | 256 | /*! |
254 | Returns the size used for large icons. | 257 | Returns the size used for large icons. |
255 | 258 | ||
256 | \sa setBigIconSize() setIcon() | 259 | \sa setBigIconSize() setIcon() |
257 | */ | 260 | */ |
258 | int AppLnk::bigIconSize() | 261 | int AppLnk::bigIconSize() |
259 | { | 262 | { |
260 | return bigSize; | 263 | return bigSize; |
261 | } | 264 | } |
262 | 265 | ||
263 | 266 | ||
264 | /*! | 267 | /*! |
265 | \fn QString AppLnk::name() const | 268 | \fn QString AppLnk::name() const |
266 | 269 | ||
267 | Returns the Name property. This is the user-visible name for the | 270 | Returns the Name property. This is the user-visible name for the |
268 | document or application, not the filename. | 271 | document or application, not the filename. |
269 | 272 | ||
270 | See \link #files-and-links Files and Links\endlink. | 273 | See \link #files-and-links Files and Links\endlink. |
271 | 274 | ||
272 | \sa setName() | 275 | \sa setName() |
273 | */ | 276 | */ |
274 | /*! | 277 | /*! |
275 | \fn QString AppLnk::exec() const | 278 | \fn QString AppLnk::exec() const |
276 | 279 | ||
277 | Returns the Exec property. This is the name of the executable | 280 | Returns the Exec property. This is the name of the executable |
278 | program associated with the AppLnk. | 281 | program associated with the AppLnk. |
279 | 282 | ||
280 | \sa setExec() | 283 | \sa setExec() |
281 | */ | 284 | */ |
282 | /*! | 285 | /*! |
283 | \fn QString AppLnk::rotation() const | 286 | \fn QString AppLnk::rotation() const |
284 | 287 | ||
285 | Returns the Rotation property. The value is 0, 90, 180 or 270 | 288 | Returns the Rotation property. The value is 0, 90, 180 or 270 |
286 | degrees. | 289 | degrees. |
287 | */ | 290 | */ |
288 | /*! | 291 | /*! |
289 | \fn QString AppLnk::comment() const | 292 | \fn QString AppLnk::comment() const |
290 | 293 | ||
291 | Returns the Comment property. | 294 | Returns the Comment property. |
292 | 295 | ||
293 | \sa setComment() | 296 | \sa setComment() |
294 | */ | 297 | */ |
295 | /*! | 298 | /*! |
296 | \fn QStringList AppLnk::mimeTypes() const | 299 | \fn QStringList AppLnk::mimeTypes() const |
297 | 300 | ||
298 | Returns the MimeTypes property. This is the list of MIME types | 301 | Returns the MimeTypes property. This is the list of MIME types |
299 | that the application can view or edit. | 302 | that the application can view or edit. |
300 | */ | 303 | */ |
301 | /*! | 304 | /*! |
302 | \fn const QArray<int>& AppLnk::categories() const | 305 | \fn const QArray<int>& AppLnk::categories() const |
303 | 306 | ||
304 | Returns the Categories property. | 307 | Returns the Categories property. |
305 | 308 | ||
306 | See the CategoryWidget for more details. | 309 | See the CategoryWidget for more details. |
307 | 310 | ||
308 | \sa setCategories() | 311 | \sa setCategories() |
309 | */ | 312 | */ |
310 | 313 | ||
311 | const QArray<int>& AppLnk::categories() const | 314 | const QArray<int>& AppLnk::categories() const |
312 | { | 315 | { |
313 | d->ensureCatArray(); | 316 | d->ensureCatArray(); |
314 | return d->mCat; | 317 | return d->mCat; |
315 | } | 318 | } |
316 | 319 | ||
317 | /*! | 320 | /*! |
318 | \fn int AppLnk::id() const | 321 | \fn int AppLnk::id() const |
319 | 322 | ||
320 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, | 323 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, |
321 | this value is 0, otherwise it is a value that is unique for the | 324 | this value is 0, otherwise it is a value that is unique for the |
322 | duration of the current process. | 325 | duration of the current process. |
323 | 326 | ||
324 | \sa AppLnkSet::find() | 327 | \sa AppLnkSet::find() |
325 | */ | 328 | */ |
326 | 329 | ||
327 | /*! | 330 | /*! |
328 | \fn bool AppLnk::isValid() const | 331 | \fn bool AppLnk::isValid() const |
329 | 332 | ||
330 | Returns TRUE if this AppLnk is valid; otherwise returns FALSE. | 333 | Returns TRUE if this AppLnk is valid; otherwise returns FALSE. |
331 | */ | 334 | */ |
332 | 335 | ||
333 | /*! | 336 | /*! |
334 | Creates an invalid AppLnk. | 337 | Creates an invalid AppLnk. |
335 | 338 | ||
336 | \sa isValid() | 339 | \sa isValid() |
337 | */ | 340 | */ |
338 | AppLnk::AppLnk() | 341 | AppLnk::AppLnk() |
339 | { | 342 | { |
340 | mId = 0; | 343 | mId = 0; |
341 | d = new AppLnkPrivate(); | 344 | d = new AppLnkPrivate(); |
342 | } | 345 | } |
343 | 346 | ||
344 | /*! | 347 | /*! |
345 | Loads \a file (e.g. \e app.desktop) as an AppLnk. | 348 | Loads \a file (e.g. \e app.desktop) as an AppLnk. |
346 | 349 | ||
347 | \sa writeLink() | 350 | \sa writeLink() |
348 | */ | 351 | */ |
349 | AppLnk::AppLnk( const QString &file ) | 352 | AppLnk::AppLnk( const QString &file ) |
350 | { | 353 | { |
351 | QStringList sl; | 354 | QStringList sl; |
352 | d = new AppLnkPrivate(); | 355 | d = new AppLnkPrivate(); |
353 | if ( !file.isNull() ) { | 356 | if ( !file.isNull() ) { |
354 | Config config( file, Config::File ); | 357 | Config config( file, Config::File ); |
355 | 358 | ||
356 | if ( config.isValid() ) { | 359 | if ( config.isValid() ) { |
357 | config.setGroup( "Desktop Entry" ); | 360 | config.setGroup( "Desktop Entry" ); |
358 | 361 | ||
359 | mName = config.readEntry( "Name", file ); | 362 | mName = config.readEntry( "Name", file ); |
360 | mExec = config.readEntry( "Exec" ); | 363 | mExec = config.readEntry( "Exec" ); |
361 | mType = config.readEntry( "Type", QString::null ); | 364 | mType = config.readEntry( "Type", QString::null ); |
362 | mIconFile = config.readEntry( "Icon", QString::null ); | 365 | mIconFile = config.readEntry( "Icon", QString::null ); |
363 | mRotation = config.readEntry( "Rotation", "" ); | 366 | mRotation = config.readEntry( "Rotation", "" ); |
364 | mComment = config.readEntry( "Comment", QString::null ); | 367 | mComment = config.readEntry( "Comment", QString::null ); |
365 | // MIME types are case-insensitive. | 368 | // MIME types are case-insensitive. |
366 | mMimeTypes = config.readListEntry( "MimeType", ';' ); | 369 | mMimeTypes = config.readListEntry( "MimeType", ';' ); |
367 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) | 370 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) |
368 | *it = (*it).lower(); | 371 | *it = (*it).lower(); |
369 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); | 372 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); |
370 | mLinkFile = file; | 373 | mLinkFile = file; |
371 | mFile = config.readEntry("File", QString::null); | 374 | mFile = config.readEntry("File", QString::null); |
372 | if ( mFile[0] != '/' ) { | 375 | if ( mFile[0] != '/' ) { |
373 | int slash = file.findRev('/'); | 376 | int slash = file.findRev('/'); |
374 | if ( slash >= 0 ) { | 377 | if ( slash >= 0 ) { |
375 | mFile = file.left(slash) + '/' + mFile; | 378 | mFile = file.left(slash) + '/' + mFile; |
376 | } | 379 | } |
377 | } | 380 | } |
378 | d->mCatList = config.readListEntry("Categories", ';'); | 381 | d->mCatList = config.readListEntry("Categories", ';'); |
379 | if ( d->mCatList[0].toInt() < -1 ) { | 382 | if ( d->mCatList[0].toInt() < -1 ) { |
380 | // numeric cats in file! convert to text | 383 | // numeric cats in file! convert to text |
381 | Categories cat( 0 ); | 384 | Categories cat( 0 ); |
382 | cat.load( categoryFileName() ); | 385 | cat.load( categoryFileName() ); |
383 | d->mCat.resize( d->mCatList.count() ); | 386 | d->mCat.resize( d->mCatList.count() ); |
384 | int i; | 387 | int i; |
385 | QStringList::ConstIterator it; | 388 | QStringList::ConstIterator it; |
386 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); | 389 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); |
387 | ++it, i++ ) { | 390 | ++it, i++ ) { |
388 | bool number; | 391 | bool number; |
389 | int id = (*it).toInt( &number ); | 392 | int id = (*it).toInt( &number ); |
390 | if ( !number ) { | 393 | if ( !number ) { |
391 | // convert from text | 394 | // convert from text |
392 | id = cat.id( "Document View", *it ); | 395 | id = cat.id( "Document View", *it ); |
393 | if ( id == 0 ) | 396 | if ( id == 0 ) |
394 | id = cat.addCategory( "Document View", *it ); | 397 | id = cat.addCategory( "Document View", *it ); |
395 | } | 398 | } |
396 | d->mCat[i] = id; | 399 | d->mCat[i] = id; |
397 | } | 400 | } |
398 | d->updateCatListFromArray(); | 401 | d->updateCatListFromArray(); |
399 | } | 402 | } |
400 | } | 403 | } |
401 | } | 404 | } |
402 | mId = 0; | 405 | mId = 0; |
403 | } | 406 | } |
404 | 407 | ||
405 | AppLnk& AppLnk::operator=(const AppLnk ©) | 408 | AppLnk& AppLnk::operator=(const AppLnk ©) |
406 | { | 409 | { |
407 | if ( mId ) | 410 | if ( mId ) |
408 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 411 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
409 | if ( d ) | 412 | if ( d ) |
410 | delete d; | 413 | delete d; |
411 | 414 | ||
412 | 415 | ||
413 | mName = copy.mName; | 416 | mName = copy.mName; |
414 | 417 | ||
415 | /* remove for Qtopia 3.0 -zecke */ | 418 | /* remove for Qtopia 3.0 -zecke */ |
416 | mPixmap = copy.mPixmap; | 419 | mPixmap = copy.mPixmap; |
417 | mBigPixmap = copy.mBigPixmap; | 420 | mBigPixmap = copy.mBigPixmap; |
418 | 421 | ||
419 | mExec = copy.mExec; | 422 | mExec = copy.mExec; |
420 | mType = copy.mType; | 423 | mType = copy.mType; |
421 | mRotation = copy.mRotation; | 424 | mRotation = copy.mRotation; |
422 | mComment = copy.mComment; | 425 | mComment = copy.mComment; |
423 | mFile = copy.mFile; | 426 | mFile = copy.mFile; |
424 | mLinkFile = copy.mLinkFile; | 427 | mLinkFile = copy.mLinkFile; |
425 | mIconFile = copy.mIconFile; | 428 | mIconFile = copy.mIconFile; |
426 | mMimeTypes = copy.mMimeTypes; | 429 | mMimeTypes = copy.mMimeTypes; |
427 | mMimeTypeIcons = copy.mMimeTypeIcons; | 430 | mMimeTypeIcons = copy.mMimeTypeIcons; |
428 | mId = 0; | 431 | mId = 0; |
429 | d = new AppLnkPrivate(); | 432 | d = new AppLnkPrivate(); |
430 | d->mCat = copy.d->mCat; | 433 | d->mCat = copy.d->mCat; |
431 | d->mCatList = copy.d->mCatList; | 434 | d->mCatList = copy.d->mCatList; |
432 | d->mPixmaps = copy.d->mPixmaps; | 435 | d->mPixmaps = copy.d->mPixmaps; |
433 | 436 | ||
434 | return *this; | 437 | return *this; |
435 | } | 438 | } |
436 | /*! | 439 | /*! |
437 | protected internally to share code | 440 | protected internally to share code |
438 | should I document that at all? | 441 | should I document that at all? |
439 | I don't know the TT style for that | 442 | I don't know the TT style for that |
440 | */ | 443 | */ |
441 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { | 444 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { |
442 | if ( d->mPixmaps[pos].isNull() ) { | 445 | if ( d->mPixmaps[pos].isNull() ) { |
443 | AppLnk* that = (AppLnk*)this; | 446 | AppLnk* that = (AppLnk*)this; |
444 | if ( mIconFile.isEmpty() ) { | 447 | if ( mIconFile.isEmpty() ) { |
445 | MimeType mt(type()); | 448 | MimeType mt(type()); |
446 | that->d->mPixmaps[pos] = mt.pixmap(); | 449 | that->d->mPixmaps[pos] = mt.pixmap(); |
447 | if ( that->d->mPixmaps[pos].isNull() ) | 450 | if ( that->d->mPixmaps[pos].isNull() ) |
448 | that->d->mPixmaps[pos].convertFromImage( | 451 | that->d->mPixmaps[pos].convertFromImage( |
449 | Resource::loadImage("UnknownDocument") | 452 | Resource::loadImage("UnknownDocument") |
450 | .smoothScale( size, size ) ); | 453 | .smoothScale( size, size ) ); |
451 | return that->d->mPixmaps[pos]; | 454 | return that->d->mPixmaps[pos]; |
452 | } | 455 | } |
453 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); | 456 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); |
454 | if ( unscaledIcon.isNull() ) { | 457 | if ( unscaledIcon.isNull() ) { |
455 | qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); | 458 | qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); |
456 | that->d->mPixmaps[pos].convertFromImage( | 459 | that->d->mPixmaps[pos].convertFromImage( |
457 | Resource::loadImage("UnknownDocument") | 460 | Resource::loadImage("UnknownDocument") |
458 | .smoothScale( size, size ) ); | 461 | .smoothScale( size, size ) ); |
459 | } else { | 462 | } else { |
460 | that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 463 | that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
461 | that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 464 | that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
462 | } | 465 | } |
463 | return that->d->mPixmaps[0]; | 466 | return that->d->mPixmaps[0]; |
464 | } | 467 | } |
465 | return mPixmap; | 468 | return mPixmap; |
466 | } | 469 | } |
467 | 470 | ||
468 | /*! | 471 | /*! |
469 | Returns a small pixmap associated with the application. | 472 | Returns a small pixmap associated with the application. |
470 | 473 | ||
471 | \sa bigPixmap() setIcon() | 474 | \sa bigPixmap() setIcon() |
472 | */ | 475 | */ |
473 | const QPixmap& AppLnk::pixmap() const | 476 | const QPixmap& AppLnk::pixmap() const |
474 | { | 477 | { |
475 | if ( d->mPixmaps[0].isNull() ) { | 478 | if ( d->mPixmaps[0].isNull() ) { |
476 | return pixmap(AppLnkPrivate::Normal, smallSize ); | 479 | return pixmap(AppLnkPrivate::Normal, smallSize ); |
477 | } | 480 | } |
478 | return d->mPixmaps[0]; | 481 | return d->mPixmaps[0]; |
479 | } | 482 | } |
480 | 483 | ||
481 | /*! | 484 | /*! |
482 | Returns a large pixmap associated with the application. | 485 | Returns a large pixmap associated with the application. |
483 | 486 | ||
484 | \sa pixmap() setIcon() | 487 | \sa pixmap() setIcon() |
485 | */ | 488 | */ |
486 | const QPixmap& AppLnk::bigPixmap() const | 489 | const QPixmap& AppLnk::bigPixmap() const |
487 | { | 490 | { |
488 | if ( d->mPixmaps[1].isNull() ) { | 491 | if ( d->mPixmaps[1].isNull() ) { |
489 | return pixmap( AppLnkPrivate::Big, bigSize ); | 492 | return pixmap( AppLnkPrivate::Big, bigSize ); |
490 | } | 493 | } |
491 | return mBigPixmap; | 494 | return mBigPixmap; |
492 | } | 495 | } |
493 | 496 | ||
494 | /*! | 497 | /*! |
495 | Returns the type of the AppLnk. For applications, games and | 498 | Returns the type of the AppLnk. For applications, games and |
496 | settings the type is \c Application; for documents the type is the | 499 | settings the type is \c Application; for documents the type is the |
497 | document's MIME type. | 500 | document's MIME type. |
498 | */ | 501 | */ |
499 | QString AppLnk::type() const | 502 | QString AppLnk::type() const |
500 | { | 503 | { |
501 | if ( mType.isNull() ) { | 504 | if ( mType.isNull() ) { |
502 | AppLnk* that = (AppLnk*)this; | 505 | AppLnk* that = (AppLnk*)this; |
503 | QString f = file(); | 506 | QString f = file(); |
504 | if ( !f.isNull() ) { | 507 | if ( !f.isNull() ) { |
505 | MimeType mt(f); | 508 | MimeType mt(f); |
506 | that->mType = mt.id(); | 509 | that->mType = mt.id(); |
507 | return that->mType; | 510 | return that->mType; |
508 | } | 511 | } |
509 | } | 512 | } |
510 | return mType; | 513 | return mType; |
511 | } | 514 | } |
512 | 515 | ||
513 | /*! | 516 | /*! |
514 | Returns the file associated with the AppLnk. | 517 | Returns the file associated with the AppLnk. |
515 | 518 | ||
516 | \sa exec() name() | 519 | \sa exec() name() |
517 | */ | 520 | */ |
518 | QString AppLnk::file() const | 521 | QString AppLnk::file() const |
519 | { | 522 | { |
520 | if ( mFile.isNull() ) { | 523 | if ( mFile.isNull() ) { |
521 | AppLnk* that = (AppLnk*)this; | 524 | AppLnk* that = (AppLnk*)this; |
522 | QString ext = MimeType(mType).extension(); | 525 | QString ext = MimeType(mType).extension(); |
523 | if ( !ext.isEmpty() ) | 526 | if ( !ext.isEmpty() ) |
524 | ext = "." + ext; | 527 | ext = "." + ext; |
525 | if ( !mLinkFile.isEmpty() ) { | 528 | if ( !mLinkFile.isEmpty() ) { |
526 | that->mFile = | 529 | that->mFile = |
527 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") | 530 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") |
528 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; | 531 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; |
529 | } else if ( mType.contains('/') ) { | 532 | } else if ( mType.contains('/') ) { |
530 | that->mFile = | 533 | that->mFile = |
531 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); | 534 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); |
532 | /* | 535 | /* |
533 | * A file with the same name or a .desktop file already exists | 536 | * A file with the same name or a .desktop file already exists |
534 | */ | 537 | */ |
535 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { | 538 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { |
536 | int n=1; | 539 | int n=1; |
537 | QString nn; | 540 | QString nn; |
538 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) | 541 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) |
539 | || QFile::exists(nn+".desktop")) | 542 | || QFile::exists(nn+".desktop")) |
540 | n++; | 543 | n++; |
541 | that->mFile = nn; | 544 | that->mFile = nn; |
542 | } | 545 | } |
543 | that->mLinkFile = that->mFile+".desktop"; | 546 | that->mLinkFile = that->mFile+".desktop"; |
544 | that->mFile += ext; | 547 | that->mFile += ext; |
545 | } | 548 | } |
546 | prepareDirectories(that->mFile); | 549 | prepareDirectories(that->mFile); |
547 | if ( !that->mFile.isEmpty() ) { | 550 | if ( !that->mFile.isEmpty() ) { |
548 | QFile f(that->mFile); | 551 | QFile f(that->mFile); |
549 | if ( !f.open(IO_WriteOnly) ) | 552 | if ( !f.open(IO_WriteOnly) ) |
550 | that->mFile = QString::null; | 553 | that->mFile = QString::null; |
551 | return that->mFile; | 554 | return that->mFile; |
552 | } | 555 | } |
553 | } | 556 | } |
554 | return mFile; | 557 | return mFile; |
555 | } | 558 | } |
556 | 559 | ||
557 | /*! | 560 | /*! |
558 | Returns the desktop file corresponding to this AppLnk. | 561 | Returns the desktop file corresponding to this AppLnk. |
559 | 562 | ||
560 | \sa file() exec() name() | 563 | \sa file() exec() name() |
561 | */ | 564 | */ |
562 | QString AppLnk::linkFile() const | 565 | QString AppLnk::linkFile() const |
563 | { | 566 | { |
564 | if ( mLinkFile.isNull() ) { | 567 | if ( mLinkFile.isNull() ) { |
565 | AppLnk* that = (AppLnk*)this; | 568 | AppLnk* that = (AppLnk*)this; |
566 | if ( type().contains('/') ) { | 569 | if ( type().contains('/') ) { |
567 | StorageInfo storage; | 570 | StorageInfo storage; |
568 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); | 571 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); |
569 | /* tmpfs + and ramfs are available too but not removable | 572 | /* tmpfs + and ramfs are available too but not removable |
570 | * either we fix storage or add this | 573 | * either we fix storage or add this |
571 | */ | 574 | */ |
572 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { | 575 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { |
573 | that->mLinkFile = fs->path(); | 576 | that->mLinkFile = fs->path(); |
574 | } else | 577 | } else |
575 | that->mLinkFile = getenv( "HOME" ); | 578 | that->mLinkFile = getenv( "HOME" ); |
576 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); | 579 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); |
577 | 580 | ||
578 | /* the desktop file exists make sure we don't point to the same file */ | 581 | /* the desktop file exists make sure we don't point to the same file */ |
579 | if ( QFile::exists(that->mLinkFile+".desktop") ) { | 582 | if ( QFile::exists(that->mLinkFile+".desktop") ) { |
580 | AppLnk lnk( that->mLinkFile + ".desktop" ); | 583 | AppLnk lnk( that->mLinkFile + ".desktop" ); |
581 | 584 | ||
582 | /* the linked is different */ | 585 | /* the linked is different */ |
583 | if(that->file() != lnk.file() ) { | 586 | if(that->file() != lnk.file() ) { |
584 | int n = 1; | 587 | int n = 1; |
585 | QString nn; | 588 | QString nn; |
586 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { | 589 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { |
587 | n++; | 590 | n++; |
588 | /* just to be sure */ | 591 | /* just to be sure */ |
589 | AppLnk lnk(nn ); | 592 | AppLnk lnk(nn ); |
590 | if (lnk.file() == that->file() ) | 593 | if (lnk.file() == that->file() ) |
591 | break; | 594 | break; |
592 | } | 595 | } |
593 | that->mLinkFile = nn; | 596 | that->mLinkFile = nn; |
594 | } | 597 | } |
595 | } | 598 | } |
596 | that->mLinkFile += ".desktop"; | 599 | that->mLinkFile += ".desktop"; |
597 | storeLink(); | 600 | storeLink(); |
598 | } | 601 | } |
599 | return that->mLinkFile; | 602 | return that->mLinkFile; |