author | zecke <zecke> | 2002-10-16 01:09:22 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-16 01:09:22 (UTC) |
commit | 543e54de7170c606b6883ac4152567e7faf13182 (patch) (unidiff) | |
tree | 8a7d623e96cab0135a2f7cb11aa9f7491bfda9a2 /library/applnk.cpp | |
parent | 3e973543b77631d053a9616b5540966dbe51ab47 (diff) | |
download | opie-543e54de7170c606b6883ac4152567e7faf13182.zip opie-543e54de7170c606b6883ac4152567e7faf13182.tar.gz opie-543e54de7170c606b6883ac4152567e7faf13182.tar.bz2 |
Remove #ifdef QWS HELL
a Platform which is not supporting IPC compatible
to QCopChannel/Envelope is not of much use nowadays..
so be sure your platform is supporting it
-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 a56da5d..5763c62 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -1,429 +1,425 @@ | |||
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 | ||
31 | #include <qpe/qcopenvelope_qws.h> | 30 | #include <qpe/qcopenvelope_qws.h> |
32 | #endif | ||
33 | #include <qpe/global.h> | 31 | #include <qpe/global.h> |
34 | #include <qpe/mimetype.h> | 32 | #include <qpe/mimetype.h> |
35 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
36 | #include <qpe/storage.h> | 34 | #include <qpe/storage.h> |
37 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
38 | 36 | ||
39 | #include <qdict.h> | 37 | #include <qdict.h> |
40 | #include <qdir.h> | 38 | #include <qdir.h> |
41 | #include <qregexp.h> | 39 | #include <qregexp.h> |
42 | 40 | ||
43 | #ifdef Q_WS_QWS | ||
44 | #include <qgfx_qws.h> | 41 | #include <qgfx_qws.h> |
45 | #endif | ||
46 | 42 | ||
47 | #include <stdlib.h> | 43 | #include <stdlib.h> |
48 | 44 | ||
49 | int AppLnk::lastId = 5000; | 45 | int AppLnk::lastId = 5000; |
50 | 46 | ||
51 | static int smallSize = 14; | 47 | static int smallSize = 14; |
52 | static int bigSize = 32; | 48 | static int bigSize = 32; |
53 | 49 | ||
54 | static QString safeFileName(const QString& n) | 50 | static QString safeFileName(const QString& n) |
55 | { | 51 | { |
56 | QString safename=n; | 52 | QString safename=n; |
57 | safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); | 53 | safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); |
58 | safename.replace(QRegExp("^[^A-Za-z]*"),""); | 54 | safename.replace(QRegExp("^[^A-Za-z]*"),""); |
59 | if ( safename.isEmpty() ) | 55 | if ( safename.isEmpty() ) |
60 | safename = "_"; | 56 | safename = "_"; |
61 | return safename; | 57 | return safename; |
62 | } | 58 | } |
63 | 59 | ||
64 | static bool prepareDirectories(const QString& lf) | 60 | static bool prepareDirectories(const QString& lf) |
65 | { | 61 | { |
66 | if ( !QFile::exists(lf) ) { | 62 | if ( !QFile::exists(lf) ) { |
67 | // May need to create directories | 63 | // May need to create directories |
68 | QFileInfo fi(lf); | 64 | QFileInfo fi(lf); |
69 | if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) | 65 | if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) |
70 | return FALSE; | 66 | return FALSE; |
71 | } | 67 | } |
72 | return TRUE; | 68 | return TRUE; |
73 | } | 69 | } |
74 | 70 | ||
75 | class AppLnkPrivate | 71 | class AppLnkPrivate |
76 | { | 72 | { |
77 | public: | 73 | public: |
78 | /* the size of the Pixmap */ | 74 | /* the size of the Pixmap */ |
79 | enum Size {Normal = 0, Big }; | 75 | enum Size {Normal = 0, Big }; |
80 | AppLnkPrivate() { | 76 | AppLnkPrivate() { |
81 | /* we want one normal and one big item */ | 77 | /* we want one normal and one big item */ |
82 | 78 | ||
83 | QPixmap pix; | 79 | QPixmap pix; |
84 | mPixmaps.insert(0, pix ); | 80 | mPixmaps.insert(0, pix ); |
85 | mPixmaps.insert(1, pix); | 81 | mPixmaps.insert(1, pix); |
86 | } | 82 | } |
87 | 83 | ||
88 | QStringList mCatList; // always correct | 84 | QStringList mCatList; // always correct |
89 | QArray<int> mCat; // cached value; correct if not empty | 85 | QArray<int> mCat; // cached value; correct if not empty |
90 | QMap<int, QPixmap> mPixmaps; | 86 | QMap<int, QPixmap> mPixmaps; |
91 | 87 | ||
92 | void updateCatListFromArray() | 88 | void updateCatListFromArray() |
93 | { | 89 | { |
94 | Categories cat( 0 ); | 90 | Categories cat( 0 ); |
95 | cat.load( categoryFileName() ); | 91 | cat.load( categoryFileName() ); |
96 | mCatList = cat.labels("Document View",mCat); | 92 | mCatList = cat.labels("Document View",mCat); |
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 | /*! | 332 | /*! |
337 | Creates an invalid AppLnk. | 333 | Creates an invalid AppLnk. |
338 | 334 | ||
339 | \sa isValid() | 335 | \sa isValid() |
340 | */ | 336 | */ |
341 | AppLnk::AppLnk() | 337 | AppLnk::AppLnk() |
342 | { | 338 | { |
343 | mId = 0; | 339 | mId = 0; |
344 | d = new AppLnkPrivate(); | 340 | d = new AppLnkPrivate(); |
345 | } | 341 | } |
346 | 342 | ||
347 | /*! | 343 | /*! |
348 | Loads \a file (e.g. \e app.desktop) as an AppLnk. | 344 | Loads \a file (e.g. \e app.desktop) as an AppLnk. |
349 | 345 | ||
350 | \sa writeLink() | 346 | \sa writeLink() |
351 | */ | 347 | */ |
352 | AppLnk::AppLnk( const QString &file ) | 348 | AppLnk::AppLnk( const QString &file ) |
353 | { | 349 | { |
354 | QStringList sl; | 350 | QStringList sl; |
355 | d = new AppLnkPrivate(); | 351 | d = new AppLnkPrivate(); |
356 | if ( !file.isNull() ) { | 352 | if ( !file.isNull() ) { |
357 | Config config( file, Config::File ); | 353 | Config config( file, Config::File ); |
358 | 354 | ||
359 | if ( config.isValid() ) { | 355 | if ( config.isValid() ) { |
360 | config.setGroup( "Desktop Entry" ); | 356 | config.setGroup( "Desktop Entry" ); |
361 | 357 | ||
362 | mName = config.readEntry( "Name", file ); | 358 | mName = config.readEntry( "Name", file ); |
363 | mExec = config.readEntry( "Exec" ); | 359 | mExec = config.readEntry( "Exec" ); |
364 | mType = config.readEntry( "Type", QString::null ); | 360 | mType = config.readEntry( "Type", QString::null ); |
365 | mIconFile = config.readEntry( "Icon", QString::null ); | 361 | mIconFile = config.readEntry( "Icon", QString::null ); |
366 | mRotation = config.readEntry( "Rotation", "" ); | 362 | mRotation = config.readEntry( "Rotation", "" ); |
367 | mComment = config.readEntry( "Comment", QString::null ); | 363 | mComment = config.readEntry( "Comment", QString::null ); |
368 | // MIME types are case-insensitive. | 364 | // MIME types are case-insensitive. |
369 | mMimeTypes = config.readListEntry( "MimeType", ';' ); | 365 | mMimeTypes = config.readListEntry( "MimeType", ';' ); |
370 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) | 366 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) |
371 | *it = (*it).lower(); | 367 | *it = (*it).lower(); |
372 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); | 368 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); |
373 | mLinkFile = file; | 369 | mLinkFile = file; |
374 | mFile = config.readEntry("File", QString::null); | 370 | mFile = config.readEntry("File", QString::null); |
375 | if ( !mExec. isEmpty ( )) { | 371 | if ( !mExec. isEmpty ( )) { |
376 | mFile = QString::null; | 372 | mFile = QString::null; |
377 | } | 373 | } |
378 | else if ( mFile[0] != '/' ) { | 374 | else if ( mFile[0] != '/' ) { |
379 | int slash = file.findRev('/'); | 375 | int slash = file.findRev('/'); |
380 | if ( slash >= 0 ) { | 376 | if ( slash >= 0 ) { |
381 | mFile = file.left(slash) + '/' + mFile; | 377 | mFile = file.left(slash) + '/' + mFile; |
382 | } | 378 | } |
383 | } | 379 | } |
384 | d->mCatList = config.readListEntry("Categories", ';'); | 380 | d->mCatList = config.readListEntry("Categories", ';'); |
385 | if ( d->mCatList[0].toInt() < -1 ) { | 381 | if ( d->mCatList[0].toInt() < -1 ) { |
386 | // numeric cats in file! convert to text | 382 | // numeric cats in file! convert to text |
387 | Categories cat( 0 ); | 383 | Categories cat( 0 ); |
388 | cat.load( categoryFileName() ); | 384 | cat.load( categoryFileName() ); |
389 | d->mCat.resize( d->mCatList.count() ); | 385 | d->mCat.resize( d->mCatList.count() ); |
390 | int i; | 386 | int i; |
391 | QStringList::ConstIterator it; | 387 | QStringList::ConstIterator it; |
392 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); | 388 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); |
393 | ++it, i++ ) { | 389 | ++it, i++ ) { |
394 | bool number; | 390 | bool number; |
395 | int id = (*it).toInt( &number ); | 391 | int id = (*it).toInt( &number ); |
396 | if ( !number ) { | 392 | if ( !number ) { |
397 | // convert from text | 393 | // convert from text |
398 | id = cat.id( "Document View", *it ); | 394 | id = cat.id( "Document View", *it ); |
399 | if ( id == 0 ) | 395 | if ( id == 0 ) |
400 | id = cat.addCategory( "Document View", *it ); | 396 | id = cat.addCategory( "Document View", *it ); |
401 | } | 397 | } |
402 | d->mCat[i] = id; | 398 | d->mCat[i] = id; |
403 | } | 399 | } |
404 | d->updateCatListFromArray(); | 400 | d->updateCatListFromArray(); |
405 | } | 401 | } |
406 | } | 402 | } |
407 | } | 403 | } |
408 | mId = 0; | 404 | mId = 0; |
409 | } | 405 | } |
410 | 406 | ||
411 | AppLnk& AppLnk::operator=(const AppLnk ©) | 407 | AppLnk& AppLnk::operator=(const AppLnk ©) |
412 | { | 408 | { |
413 | if ( mId ) | 409 | if ( mId ) |
414 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 410 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
415 | if ( d ) | 411 | if ( d ) |
416 | delete d; | 412 | delete d; |
417 | 413 | ||
418 | 414 | ||
419 | mName = copy.mName; | 415 | mName = copy.mName; |
420 | 416 | ||
421 | /* remove for Qtopia 3.0 -zecke */ | 417 | /* remove for Qtopia 3.0 -zecke */ |
422 | mPixmap = copy.mPixmap; | 418 | mPixmap = copy.mPixmap; |
423 | mBigPixmap = copy.mBigPixmap; | 419 | mBigPixmap = copy.mBigPixmap; |
424 | 420 | ||
425 | mExec = copy.mExec; | 421 | mExec = copy.mExec; |
426 | mType = copy.mType; | 422 | mType = copy.mType; |
427 | mRotation = copy.mRotation; | 423 | mRotation = copy.mRotation; |
428 | mComment = copy.mComment; | 424 | mComment = copy.mComment; |
429 | mFile = copy.mFile; | 425 | mFile = copy.mFile; |