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