-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,1457 +1,1460 @@ | |||
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; |
600 | } | 603 | } |
601 | return mLinkFile; | 604 | return mLinkFile; |
602 | } | 605 | } |
603 | 606 | ||
604 | /*! | 607 | /*! |
605 | Copies \a copy. | 608 | Copies \a copy. |
606 | */ | 609 | */ |
607 | AppLnk::AppLnk( const AppLnk © ) | 610 | AppLnk::AppLnk( const AppLnk © ) |
608 | { | 611 | { |
609 | mName = copy.mName; | 612 | mName = copy.mName; |
610 | mPixmap = copy.mPixmap; | 613 | mPixmap = copy.mPixmap; |
611 | mBigPixmap = copy.mBigPixmap; | 614 | mBigPixmap = copy.mBigPixmap; |
612 | mExec = copy.mExec; | 615 | mExec = copy.mExec; |
613 | mType = copy.mType; | 616 | mType = copy.mType; |
614 | mRotation = copy.mRotation; | 617 | mRotation = copy.mRotation; |
615 | mComment = copy.mComment; | 618 | mComment = copy.mComment; |
616 | mFile = copy.mFile; | 619 | mFile = copy.mFile; |
617 | mLinkFile = copy.mLinkFile; | 620 | mLinkFile = copy.mLinkFile; |
618 | mIconFile = copy.mIconFile; | 621 | mIconFile = copy.mIconFile; |
619 | mMimeTypes = copy.mMimeTypes; | 622 | mMimeTypes = copy.mMimeTypes; |
620 | mMimeTypeIcons = copy.mMimeTypeIcons; | 623 | mMimeTypeIcons = copy.mMimeTypeIcons; |
621 | mId = 0; | 624 | mId = 0; |
622 | d = new AppLnkPrivate(); | 625 | d = new AppLnkPrivate(); |
623 | d->mCat = copy.d->mCat; | 626 | d->mCat = copy.d->mCat; |
624 | d->mCatList = copy.d->mCatList; | 627 | d->mCatList = copy.d->mCatList; |
625 | d->mPixmaps = copy.d->mPixmaps; | 628 | d->mPixmaps = copy.d->mPixmaps; |
626 | } | 629 | } |
627 | 630 | ||
628 | /*! | 631 | /*! |
629 | Destroys the AppLnk. Note that if the AppLnk is currently a member | 632 | Destroys the AppLnk. Note that if the AppLnk is currently a member |
630 | of an AppLnkSet, this will produce a run-time warning. | 633 | of an AppLnkSet, this will produce a run-time warning. |
631 | 634 | ||
632 | \sa AppLnkSet::add() AppLnkSet::remove() | 635 | \sa AppLnkSet::add() AppLnkSet::remove() |
633 | */ | 636 | */ |
634 | AppLnk::~AppLnk() | 637 | AppLnk::~AppLnk() |
635 | { | 638 | { |
636 | if ( mId ) | 639 | if ( mId ) |
637 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 640 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
638 | if ( d ) | 641 | if ( d ) |
639 | delete d; | 642 | delete d; |
640 | } | 643 | } |
641 | 644 | ||
642 | /*! | 645 | /*! |
643 | \overload | 646 | \overload |
644 | Executes the application associated with this AppLnk. | 647 | Executes the application associated with this AppLnk. |
645 | 648 | ||
646 | \sa exec() | 649 | \sa exec() |
647 | */ | 650 | */ |
648 | void AppLnk::execute() const | 651 | void AppLnk::execute() const |
649 | { | 652 | { |
650 | execute(QStringList()); | 653 | execute(QStringList()); |
651 | } | 654 | } |
652 | 655 | ||
653 | /*! | 656 | /*! |
654 | Executes the application associated with this AppLnk, with | 657 | Executes the application associated with this AppLnk, with |
655 | \a args as arguments. | 658 | \a args as arguments. |
656 | 659 | ||
657 | \sa exec() | 660 | \sa exec() |
658 | */ | 661 | */ |
659 | void AppLnk::execute(const QStringList& args) const | 662 | void AppLnk::execute(const QStringList& args) const |
660 | { | 663 | { |
661 | #ifdef Q_WS_QWS | 664 | #ifdef Q_WS_QWS |
662 | if ( !mRotation.isEmpty() ) { | 665 | if ( !mRotation.isEmpty() ) { |
663 | // ######## this will only work in the server | 666 | // ######## this will only work in the server |
664 | int rot = QPEApplication::defaultRotation(); | 667 | int rot = QPEApplication::defaultRotation(); |
665 | rot = (rot+mRotation.toInt())%360; | 668 | rot = (rot+mRotation.toInt())%360; |
666 | QCString old = getenv("QWS_DISPLAY"); | 669 | QCString old = getenv("QWS_DISPLAY"); |
667 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 670 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
668 | invoke(args); | 671 | invoke(args); |
669 | setenv("QWS_DISPLAY", old.data(), 1); | 672 | setenv("QWS_DISPLAY", old.data(), 1); |
670 | } else | 673 | } else |
671 | #endif | 674 | #endif |
672 | invoke(args); | 675 | invoke(args); |
673 | } | 676 | } |
674 | 677 | ||
675 | /*! | 678 | /*! |
676 | Invokes the application associated with this AppLnk, with | 679 | Invokes the application associated with this AppLnk, with |
677 | \a args as arguments. Rotation is not taken into account by | 680 | \a args as arguments. Rotation is not taken into account by |
678 | this function, so you should not call it directly. | 681 | this function, so you should not call it directly. |
679 | 682 | ||
680 | \sa execute() | 683 | \sa execute() |
681 | */ | 684 | */ |
682 | void AppLnk::invoke(const QStringList& args) const | 685 | void AppLnk::invoke(const QStringList& args) const |
683 | { | 686 | { |
684 | Global::execute( exec(), args[0] ); | 687 | Global::execute( exec(), args[0] ); |
685 | } | 688 | } |
686 | 689 | ||
687 | /*! | 690 | /*! |
688 | Sets the Exec property to \a exec. | 691 | Sets the Exec property to \a exec. |
689 | 692 | ||
690 | \sa exec() name() | 693 | \sa exec() name() |
691 | */ | 694 | */ |
692 | void AppLnk::setExec( const QString& exec ) | 695 | void AppLnk::setExec( const QString& exec ) |
693 | { | 696 | { |
694 | mExec = exec; | 697 | mExec = exec; |
695 | } | 698 | } |
696 | 699 | ||
697 | /*! | 700 | /*! |
698 | Sets the Name property to \a docname. | 701 | Sets the Name property to \a docname. |
699 | 702 | ||
700 | \sa name() | 703 | \sa name() |
701 | */ | 704 | */ |
702 | void AppLnk::setName( const QString& docname ) | 705 | void AppLnk::setName( const QString& docname ) |
703 | { | 706 | { |
704 | mName = docname; | 707 | mName = docname; |
705 | } | 708 | } |
706 | 709 | ||
707 | /*! | 710 | /*! |
708 | Sets the File property to \a filename. | 711 | Sets the File property to \a filename. |
709 | 712 | ||
710 | \sa file() name() | 713 | \sa file() name() |
711 | */ | 714 | */ |
712 | void AppLnk::setFile( const QString& filename ) | 715 | void AppLnk::setFile( const QString& filename ) |
713 | { | 716 | { |
714 | mFile = filename; | 717 | mFile = filename; |
715 | } | 718 | } |
716 | 719 | ||
717 | /*! | 720 | /*! |
718 | Sets the LinkFile property to \a filename. | 721 | Sets the LinkFile property to \a filename. |
719 | 722 | ||
720 | \sa linkFile() | 723 | \sa linkFile() |
721 | */ | 724 | */ |
722 | void AppLnk::setLinkFile( const QString& filename ) | 725 | void AppLnk::setLinkFile( const QString& filename ) |
723 | { | 726 | { |
724 | mLinkFile = filename; | 727 | mLinkFile = filename; |
725 | } | 728 | } |
726 | 729 | ||
727 | /*! | 730 | /*! |
728 | Sets the Comment property to \a comment. | 731 | Sets the Comment property to \a comment. |
729 | 732 | ||
730 | This text is displayed in the 'Details Dialog', for example if the | 733 | This text is displayed in the 'Details Dialog', for example if the |
731 | user uses the 'press-and-hold' gesture. | 734 | user uses the 'press-and-hold' gesture. |
732 | 735 | ||
733 | \sa comment() | 736 | \sa comment() |
734 | */ | 737 | */ |
735 | void AppLnk::setComment( const QString& comment ) | 738 | void AppLnk::setComment( const QString& comment ) |
736 | { | 739 | { |
737 | mComment = comment; | 740 | mComment = comment; |
738 | } | 741 | } |
739 | 742 | ||
740 | /*! | 743 | /*! |
741 | Sets the Type property to \a type. | 744 | Sets the Type property to \a type. |
742 | 745 | ||
743 | For applications, games and settings the type should be \c | 746 | For applications, games and settings the type should be \c |
744 | Application; for documents the type should be the document's MIME | 747 | Application; for documents the type should be the document's MIME |
745 | type. | 748 | type. |
746 | 749 | ||
747 | \sa type() | 750 | \sa type() |
748 | */ | 751 | */ |
749 | void AppLnk::setType( const QString& type ) | 752 | void AppLnk::setType( const QString& type ) |
750 | { | 753 | { |
751 | mType = type; | 754 | mType = type; |
752 | } | 755 | } |
753 | 756 | ||
754 | /*! | 757 | /*! |
755 | \fn QString AppLnk::icon() const | 758 | \fn QString AppLnk::icon() const |
756 | 759 | ||
757 | Returns the Icon property. | 760 | Returns the Icon property. |
758 | 761 | ||
759 | \sa setIcon() | 762 | \sa setIcon() |
760 | */ | 763 | */ |
761 | 764 | ||
762 | /*! | 765 | /*! |
763 | Sets the Icon property to \a iconname. This is the filename from | 766 | Sets the Icon property to \a iconname. This is the filename from |
764 | which the pixmap() and bigPixmap() are obtained. | 767 | which the pixmap() and bigPixmap() are obtained. |
765 | 768 | ||
766 | \sa icon() setSmallIconSize() setBigIconSize() | 769 | \sa icon() setSmallIconSize() setBigIconSize() |
767 | */ | 770 | */ |
768 | void AppLnk::setIcon( const QString& iconname ) | 771 | void AppLnk::setIcon( const QString& iconname ) |
769 | { | 772 | { |
770 | mIconFile = iconname; | 773 | mIconFile = iconname; |
771 | QImage unscaledIcon = Resource::loadImage( mIconFile ); | 774 | QImage unscaledIcon = Resource::loadImage( mIconFile ); |
772 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 775 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
773 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 776 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
774 | } | 777 | } |
775 | 778 | ||
776 | /*! | 779 | /*! |
777 | Sets the Categories property to \a c. | 780 | Sets the Categories property to \a c. |
778 | 781 | ||
779 | See the CategoryWidget for more details. | 782 | See the CategoryWidget for more details. |
780 | 783 | ||
781 | \sa categories() | 784 | \sa categories() |
782 | */ | 785 | */ |
783 | void AppLnk::setCategories( const QArray<int>& c ) | 786 | void AppLnk::setCategories( const QArray<int>& c ) |
784 | { | 787 | { |
785 | d->mCat = c; | 788 | d->mCat = c; |
786 | d->updateCatListFromArray(); | 789 | d->updateCatListFromArray(); |
787 | } | 790 | } |
788 | 791 | ||
789 | /*! | 792 | /*! |
790 | \fn QStringList AppLnk::mimeTypeIcons() const | 793 | \fn QStringList AppLnk::mimeTypeIcons() const |
791 | 794 | ||
792 | Returns the MimeTypeIcons property of the AppLnk. | 795 | Returns the MimeTypeIcons property of the AppLnk. |
793 | */ | 796 | */ |
794 | 797 | ||
795 | /*! | 798 | /*! |
796 | Attempts to ensure that the link file for this AppLnk exists, | 799 | Attempts to ensure that the link file for this AppLnk exists, |
797 | including creating any required directories. Returns TRUE if | 800 | including creating any required directories. Returns TRUE if |
798 | successful; otherwise returns FALSE. | 801 | successful; otherwise returns FALSE. |
799 | 802 | ||
800 | You should not need to use this function. | 803 | You should not need to use this function. |
801 | */ | 804 | */ |
802 | bool AppLnk::ensureLinkExists() const | 805 | bool AppLnk::ensureLinkExists() const |
803 | { | 806 | { |
804 | QString lf = linkFile(); | 807 | QString lf = linkFile(); |
805 | return prepareDirectories(lf); | 808 | return prepareDirectories(lf); |
806 | } | 809 | } |
807 | 810 | ||
808 | /*! | 811 | /*! |
809 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; | 812 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; |
810 | otherwise returns FALSE. | 813 | otherwise returns FALSE. |
811 | 814 | ||
812 | In addition, the "linkChanged(QString)" message is sent to the | 815 | In addition, the "linkChanged(QString)" message is sent to the |
813 | "QPE/System" \link qcop.html QCop\endlink channel. | 816 | "QPE/System" \link qcop.html QCop\endlink channel. |
814 | */ | 817 | */ |
815 | bool AppLnk::writeLink() const | 818 | bool AppLnk::writeLink() const |
816 | { | 819 | { |
817 | // Only re-writes settable parts | 820 | // Only re-writes settable parts |
818 | QString lf = linkFile(); | 821 | QString lf = linkFile(); |
819 | if ( !ensureLinkExists() ) | 822 | if ( !ensureLinkExists() ) |
820 | return FALSE; | 823 | return FALSE; |
821 | storeLink(); | 824 | storeLink(); |
822 | return TRUE; | 825 | return TRUE; |
823 | } | 826 | } |
824 | 827 | ||
825 | /*! | 828 | /*! |
826 | \internal | 829 | \internal |
827 | */ | 830 | */ |
828 | void AppLnk::storeLink() const | 831 | void AppLnk::storeLink() const |
829 | { | 832 | { |
830 | Config config( mLinkFile, Config::File ); | 833 | Config config( mLinkFile, Config::File ); |
831 | config.setGroup("Desktop Entry"); | 834 | config.setGroup("Desktop Entry"); |
832 | config.writeEntry("Name",mName); | 835 | config.writeEntry("Name",mName); |
833 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); | 836 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); |
834 | config.writeEntry("Type",type()); | 837 | config.writeEntry("Type",type()); |
835 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); | 838 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); |
836 | QString f = file(); | 839 | QString f = file(); |
837 | int i = 0; | 840 | int i = 0; |
838 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) | 841 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) |
839 | i++; | 842 | i++; |
840 | while ( i && f[i] != '/' ) | 843 | while ( i && f[i] != '/' ) |
841 | i--; | 844 | i--; |
842 | // simple case where in the same directory | 845 | // simple case where in the same directory |
843 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) | 846 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) |
844 | f = f.mid(i+1); | 847 | f = f.mid(i+1); |
845 | // ### could do relative ie ../../otherDocs/file.doc | 848 | // ### could do relative ie ../../otherDocs/file.doc |
846 | config.writeEntry("File",f); | 849 | config.writeEntry("File",f); |
847 | config.writeEntry( "Categories", d->mCatList, ';' ); | 850 | config.writeEntry( "Categories", d->mCatList, ';' ); |
848 | 851 | ||
849 | #ifndef QT_NO_COP | 852 | #ifndef QT_NO_COP |
850 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 853 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
851 | e << mLinkFile; | 854 | e << mLinkFile; |
852 | #endif | 855 | #endif |
853 | } | 856 | } |
854 | 857 | ||
855 | /*! | 858 | /*! |
856 | Sets the property named \a key to \a value. | 859 | Sets the property named \a key to \a value. |
857 | 860 | ||
858 | \sa property() | 861 | \sa property() |
859 | */ | 862 | */ |
860 | void AppLnk::setProperty(const QString& key, const QString& value) | 863 | void AppLnk::setProperty(const QString& key, const QString& value) |
861 | { | 864 | { |
862 | if ( ensureLinkExists() ) { | 865 | if ( ensureLinkExists() ) { |
863 | Config cfg(linkFile(), Config::File); | 866 | Config cfg(linkFile(), Config::File); |
864 | cfg.writeEntry(key,value); | 867 | cfg.writeEntry(key,value); |
865 | } | 868 | } |
866 | } | 869 | } |
867 | 870 | ||
868 | /*! | 871 | /*! |
869 | Returns the property named \a key. | 872 | Returns the property named \a key. |
870 | 873 | ||
871 | \sa setProperty() | 874 | \sa setProperty() |
872 | */ | 875 | */ |
873 | QString AppLnk::property(const QString& key) const | 876 | QString AppLnk::property(const QString& key) const |
874 | { | 877 | { |
875 | QString lf = linkFile(); | 878 | QString lf = linkFile(); |
876 | if ( !QFile::exists(lf) ) | 879 | if ( !QFile::exists(lf) ) |
877 | return QString::null; | 880 | return QString::null; |
878 | Config cfg(lf, Config::File); | 881 | Config cfg(lf, Config::File); |
879 | return cfg.readEntry(key); | 882 | return cfg.readEntry(key); |
880 | } | 883 | } |
881 | 884 | ||
882 | bool AppLnk::isPreloaded() const { | 885 | bool AppLnk::isPreloaded() const { |
883 | // Preload information is stored in the Launcher config in v1.5. | 886 | // Preload information is stored in the Launcher config in v1.5. |
884 | Config cfg("Launcher"); | 887 | Config cfg("Launcher"); |
885 | cfg.setGroup("Preload"); | 888 | cfg.setGroup("Preload"); |
886 | QStringList apps = cfg.readListEntry("Apps",','); | 889 | QStringList apps = cfg.readListEntry("Apps",','); |
887 | if (apps.contains(exec())) | 890 | if (apps.contains(exec())) |
888 | return true; | 891 | return true; |
889 | return false; | 892 | return false; |
890 | } | 893 | } |
891 | 894 | ||
892 | void AppLnk::setPreloaded(bool yesNo) { | 895 | void AppLnk::setPreloaded(bool yesNo) { |
893 | // Preload information is stored in the Launcher config in v1.5. | 896 | // Preload information is stored in the Launcher config in v1.5. |
894 | Config cfg("Launcher"); | 897 | Config cfg("Launcher"); |
895 | cfg.setGroup("Preload"); | 898 | cfg.setGroup("Preload"); |
896 | QStringList apps = cfg.readListEntry("Apps", ','); | 899 | QStringList apps = cfg.readListEntry("Apps", ','); |
897 | if (apps.contains(exec()) && !yesNo) | 900 | if (apps.contains(exec()) && !yesNo) |
898 | apps.remove(exec()); | 901 | apps.remove(exec()); |
899 | else if (yesNo && !apps.contains(exec())) | 902 | else if (yesNo && !apps.contains(exec())) |
900 | apps.append(exec()); | 903 | apps.append(exec()); |
901 | cfg.writeEntry("Apps", apps, ','); | 904 | cfg.writeEntry("Apps", apps, ','); |
902 | } | 905 | } |
903 | 906 | ||
904 | 907 | ||
905 | /*! | 908 | /*! |
906 | Deletes both the linkFile() and the file() associated with this AppLnk. | 909 | Deletes both the linkFile() and the file() associated with this AppLnk. |
907 | 910 | ||
908 | \sa removeLinkFile() | 911 | \sa removeLinkFile() |
909 | */ | 912 | */ |
910 | void AppLnk::removeFiles() | 913 | void AppLnk::removeFiles() |
911 | { | 914 | { |
912 | bool valid = isValid(); | 915 | bool valid = isValid(); |
913 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { | 916 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { |
914 | if ( QFile::remove(file()) ) { | 917 | if ( QFile::remove(file()) ) { |
915 | #ifndef QT_NO_COP | 918 | #ifndef QT_NO_COP |
916 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 919 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
917 | if ( linkFileKnown() ) | 920 | if ( linkFileKnown() ) |
918 | e << linkFile(); | 921 | e << linkFile(); |
919 | else | 922 | else |
920 | e << file(); | 923 | e << file(); |
921 | #endif | 924 | #endif |
922 | } else if ( valid ) { | 925 | } else if ( valid ) { |
923 | // restore link | 926 | // restore link |
924 | writeLink(); | 927 | writeLink(); |
925 | } | 928 | } |
926 | } | 929 | } |
927 | } | 930 | } |
928 | 931 | ||
929 | /*! | 932 | /*! |
930 | Deletes the linkFile(), leaving any file() untouched. | 933 | Deletes the linkFile(), leaving any file() untouched. |
931 | 934 | ||
932 | \sa removeFiles() | 935 | \sa removeFiles() |
933 | */ | 936 | */ |
934 | void AppLnk::removeLinkFile() | 937 | void AppLnk::removeLinkFile() |
935 | { | 938 | { |
936 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { | 939 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { |
937 | #ifndef QT_NO_COP | 940 | #ifndef QT_NO_COP |
938 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 941 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
939 | e << linkFile(); | 942 | e << linkFile(); |
940 | #endif | 943 | #endif |
941 | } | 944 | } |
942 | } | 945 | } |
943 | 946 | ||
944 | class AppLnkSetPrivate { | 947 | class AppLnkSetPrivate { |
945 | public: | 948 | public: |
946 | AppLnkSetPrivate() | 949 | AppLnkSetPrivate() |
947 | { | 950 | { |
948 | typPix.setAutoDelete(TRUE); | 951 | typPix.setAutoDelete(TRUE); |
949 | typPixBig.setAutoDelete(TRUE); | 952 | typPixBig.setAutoDelete(TRUE); |
950 | typName.setAutoDelete(TRUE); | 953 | typName.setAutoDelete(TRUE); |
951 | } | 954 | } |
952 | 955 | ||
953 | QDict<QPixmap> typPix; | 956 | QDict<QPixmap> typPix; |
954 | QDict<QPixmap> typPixBig; | 957 | QDict<QPixmap> typPixBig; |
955 | QDict<QString> typName; | 958 | QDict<QString> typName; |
956 | }; | 959 | }; |
957 | 960 | ||
958 | /*! | 961 | /*! |
959 | \class AppLnkSet applnk.h | 962 | \class AppLnkSet applnk.h |
960 | \brief The AppLnkSet class is a set of AppLnk objects. | 963 | \brief The AppLnkSet class is a set of AppLnk objects. |
961 | */ | 964 | */ |
962 | 965 | ||
963 | /*! | 966 | /*! |
964 | \fn QStringList AppLnkSet::types() const | 967 | \fn QStringList AppLnkSet::types() const |
965 | 968 | ||
966 | Returns the list of \link applnk.html#Types types\endlink in the set. | 969 | Returns the list of \link applnk.html#Types types\endlink in the set. |
967 | 970 | ||
968 | For applications, games and settings the type is \c Application; | 971 | For applications, games and settings the type is \c Application; |
969 | for documents the type is the document's MIME type. | 972 | for documents the type is the document's MIME type. |
970 | 973 | ||
971 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() | 974 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() |
972 | */ | 975 | */ |
973 | 976 | ||
974 | /*! | 977 | /*! |
975 | \fn const QList<AppLnk>& AppLnkSet::children() const | 978 | \fn const QList<AppLnk>& AppLnkSet::children() const |
976 | 979 | ||
977 | Returns the members of the set. | 980 | Returns the members of the set. |
978 | */ | 981 | */ |
979 | 982 | ||
980 | /*! | 983 | /*! |
981 | Constructs an empty AppLnkSet. | 984 | Constructs an empty AppLnkSet. |
982 | */ | 985 | */ |
983 | AppLnkSet::AppLnkSet() : | 986 | AppLnkSet::AppLnkSet() : |
984 | d(new AppLnkSetPrivate) | 987 | d(new AppLnkSetPrivate) |
985 | { | 988 | { |
986 | } | 989 | } |
987 | 990 | ||
988 | /*! | 991 | /*! |
989 | Constructs an AppLnkSet that contains AppLnk objects representing | 992 | Constructs an AppLnkSet that contains AppLnk objects representing |
990 | all the files in the given \a directory (and any subdirectories | 993 | all the files in the given \a directory (and any subdirectories |
991 | recursively). | 994 | recursively). |
992 | 995 | ||
993 | \omit | 996 | \omit |
994 | The directories may contain ".directory" files which override | 997 | The directories may contain ".directory" files which override |
995 | any AppLnk::type() values for AppLnk objects found in the directory. | 998 | any AppLnk::type() values for AppLnk objects found in the directory. |
996 | This allows simple localization of application types. | 999 | This allows simple localization of application types. |
997 | \endomit | 1000 | \endomit |
998 | */ | 1001 | */ |
999 | AppLnkSet::AppLnkSet( const QString &directory ) : | 1002 | AppLnkSet::AppLnkSet( const QString &directory ) : |
1000 | d(new AppLnkSetPrivate) | 1003 | d(new AppLnkSetPrivate) |
1001 | { | 1004 | { |
1002 | QDir dir( directory ); | 1005 | QDir dir( directory ); |
1003 | mFile = directory; | 1006 | mFile = directory; |
1004 | findChildren(directory,QString::null,QString::null); | 1007 | findChildren(directory,QString::null,QString::null); |
1005 | } | 1008 | } |
1006 | 1009 | ||
1007 | /*! | 1010 | /*! |
1008 | Detaches all AppLnk objects from the set. The set become empty and | 1011 | Detaches all AppLnk objects from the set. The set become empty and |
1009 | the caller becomes responsible for deleting the AppLnk objects. | 1012 | the caller becomes responsible for deleting the AppLnk objects. |
1010 | */ | 1013 | */ |
1011 | void AppLnkSet::detachChildren() | 1014 | void AppLnkSet::detachChildren() |
1012 | { | 1015 | { |
1013 | QListIterator<AppLnk> it( mApps ); | 1016 | QListIterator<AppLnk> it( mApps ); |
1014 | for ( ; it.current(); ) { | 1017 | for ( ; it.current(); ) { |
1015 | AppLnk* a = *it; | 1018 | AppLnk* a = *it; |
1016 | ++it; | 1019 | ++it; |
1017 | a->mId = 0; | 1020 | a->mId = 0; |
1018 | } | 1021 | } |
1019 | mApps.clear(); | 1022 | mApps.clear(); |
1020 | } | 1023 | } |
1021 | 1024 | ||
1022 | /*! | 1025 | /*! |
1023 | Destroys the set, deleting all the AppLnk objects it contains. | 1026 | Destroys the set, deleting all the AppLnk objects it contains. |
1024 | 1027 | ||
1025 | \sa detachChildren() | 1028 | \sa detachChildren() |
1026 | */ | 1029 | */ |
1027 | AppLnkSet::~AppLnkSet() | 1030 | AppLnkSet::~AppLnkSet() |
1028 | { | 1031 | { |
1029 | QListIterator<AppLnk> it( mApps ); | 1032 | QListIterator<AppLnk> it( mApps ); |
1030 | for ( ; it.current(); ) { | 1033 | for ( ; it.current(); ) { |
1031 | AppLnk* a = *it; | 1034 | AppLnk* a = *it; |
1032 | ++it; | 1035 | ++it; |
1033 | a->mId = 0; | 1036 | a->mId = 0; |
1034 | delete a; | 1037 | delete a; |
1035 | } | 1038 | } |
1036 | delete d; | 1039 | delete d; |
1037 | } | 1040 | } |
1038 | 1041 | ||
1039 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) | 1042 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) |
1040 | { | 1043 | { |
1041 | depth++; | 1044 | depth++; |
1042 | if ( depth > 10 ) | 1045 | if ( depth > 10 ) |
1043 | return; | 1046 | return; |
1044 | 1047 | ||
1045 | QDir dir( dr ); | 1048 | QDir dir( dr ); |
1046 | QString typNameLocal = typName; | 1049 | QString typNameLocal = typName; |
1047 | 1050 | ||
1048 | if ( dir.exists( ".directory" ) ) { | 1051 | if ( dir.exists( ".directory" ) ) { |
1049 | Config config( dr + "/.directory", Config::File ); | 1052 | Config config( dr + "/.directory", Config::File ); |
1050 | config.setGroup( "Desktop Entry" ); | 1053 | config.setGroup( "Desktop Entry" ); |
1051 | typNameLocal = config.readEntry( "Name", typNameLocal ); | 1054 | typNameLocal = config.readEntry( "Name", typNameLocal ); |
1052 | if ( !typ.isEmpty() ) { | 1055 | if ( !typ.isEmpty() ) { |
1053 | QString iconFile = config.readEntry( "Icon", "AppsIcon" ); | 1056 | QString iconFile = config.readEntry( "Icon", "AppsIcon" ); |
1054 | QImage unscaledIcon = Resource::loadImage( iconFile ); | 1057 | QImage unscaledIcon = Resource::loadImage( iconFile ); |
1055 | QPixmap pm, bpm; | 1058 | QPixmap pm, bpm; |
1056 | pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 1059 | pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
1057 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 1060 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
1058 | d->typPix.insert(typ, new QPixmap(pm)); | 1061 | d->typPix.insert(typ, new QPixmap(pm)); |
1059 | d->typPixBig.insert(typ, new QPixmap(bpm)); | 1062 | d->typPixBig.insert(typ, new QPixmap(bpm)); |
1060 | d->typName.insert(typ, new QString(typNameLocal)); | 1063 | d->typName.insert(typ, new QString(typNameLocal)); |
1061 | } | 1064 | } |
1062 | } | 1065 | } |
1063 | 1066 | ||
1064 | const QFileInfoList *list = dir.entryInfoList(); | 1067 | const QFileInfoList *list = dir.entryInfoList(); |
1065 | if ( list ) { | 1068 | if ( list ) { |
1066 | QFileInfo* fi; | 1069 | QFileInfo* fi; |
1067 | bool cadded=FALSE; | 1070 | bool cadded=FALSE; |
1068 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1071 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1069 | QString bn = fi->fileName(); | 1072 | QString bn = fi->fileName(); |
1070 | if ( bn[0] != '.' && bn != "CVS" ) { | 1073 | if ( bn[0] != '.' && bn != "CVS" ) { |
1071 | if ( fi->isDir() ) { | 1074 | if ( fi->isDir() ) { |
1072 | QString c = typ.isNull() ? bn : typ+"/"+bn; | 1075 | QString c = typ.isNull() ? bn : typ+"/"+bn; |
1073 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; | 1076 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; |
1074 | findChildren(fi->filePath(), c, d, depth ); | 1077 | findChildren(fi->filePath(), c, d, depth ); |
1075 | } else { | 1078 | } else { |
1076 | if ( fi->extension(FALSE) == "desktop" ) { | 1079 | if ( fi->extension(FALSE) == "desktop" ) { |
1077 | AppLnk* app = new AppLnk( fi->filePath() ); | 1080 | AppLnk* app = new AppLnk( fi->filePath() ); |
1078 | #ifdef QT_NO_QWS_MULTIPROCESS | 1081 | #ifdef QT_NO_QWS_MULTIPROCESS |
1079 | if ( !Global::isBuiltinCommand( app->exec() ) ) | 1082 | if ( !Global::isBuiltinCommand( app->exec() ) ) |
1080 | delete app; | 1083 | delete app; |
1081 | else | 1084 | else |
1082 | #endif | 1085 | #endif |
1083 | { | 1086 | { |
1084 | if ( !typ.isEmpty() ) { | 1087 | if ( !typ.isEmpty() ) { |
1085 | if ( !cadded ) { | 1088 | if ( !cadded ) { |
1086 | typs.append(typ); | 1089 | typs.append(typ); |
1087 | cadded = TRUE; | 1090 | cadded = TRUE; |
1088 | } | 1091 | } |
1089 | app->setType(typ); | 1092 | app->setType(typ); |
1090 | } | 1093 | } |
1091 | add(app); | 1094 | add(app); |
1092 | } | 1095 | } |
1093 | } | 1096 | } |
1094 | } | 1097 | } |
1095 | } | 1098 | } |
1096 | } | 1099 | } |
1097 | } | 1100 | } |
1098 | } | 1101 | } |
1099 | 1102 | ||
1100 | /*! | 1103 | /*! |
1101 | Adds AppLnk \a f to the set. The set takes responsibility for | 1104 | Adds AppLnk \a f to the set. The set takes responsibility for |
1102 | deleting \a f. | 1105 | deleting \a f. |
1103 | 1106 | ||
1104 | \sa remove() | 1107 | \sa remove() |
1105 | */ | 1108 | */ |
1106 | void AppLnkSet::add( AppLnk *f ) | 1109 | void AppLnkSet::add( AppLnk *f ) |
1107 | { | 1110 | { |
1108 | if ( f->mId == 0 ) { | 1111 | if ( f->mId == 0 ) { |
1109 | AppLnk::lastId++; | 1112 | AppLnk::lastId++; |
1110 | f->mId = AppLnk::lastId; | 1113 | f->mId = AppLnk::lastId; |
1111 | mApps.append( f ); | 1114 | mApps.append( f ); |
1112 | } else { | 1115 | } else { |
1113 | qWarning("Attempt to add an AppLnk twice"); | 1116 | qWarning("Attempt to add an AppLnk twice"); |
1114 | } | 1117 | } |
1115 | } | 1118 | } |
1116 | 1119 | ||
1117 | /*! | 1120 | /*! |
1118 | Removes AppLnk \a f to the set. The caller becomes responsible for | 1121 | Removes AppLnk \a f to the set. The caller becomes responsible for |
1119 | deleting \a f. Returns TRUE if \a f was in the set; otherwise | 1122 | deleting \a f. Returns TRUE if \a f was in the set; otherwise |
1120 | returns FALSE. | 1123 | returns FALSE. |
1121 | 1124 | ||
1122 | \sa add() | 1125 | \sa add() |
1123 | */ | 1126 | */ |
1124 | bool AppLnkSet::remove( AppLnk *f ) | 1127 | bool AppLnkSet::remove( AppLnk *f ) |
1125 | { | 1128 | { |
1126 | if ( mApps.remove( f ) ) { | 1129 | if ( mApps.remove( f ) ) { |
1127 | f->mId = 0; | 1130 | f->mId = 0; |
1128 | return TRUE; | 1131 | return TRUE; |
1129 | } | 1132 | } |
1130 | return FALSE; | 1133 | return FALSE; |
1131 | } | 1134 | } |
1132 | 1135 | ||
1133 | 1136 | ||
1134 | /*! | 1137 | /*! |
1135 | Returns the localized name for type \a t. | 1138 | Returns the localized name for type \a t. |
1136 | 1139 | ||
1137 | For applications, games and settings the type is \c Application; | 1140 | For applications, games and settings the type is \c Application; |
1138 | for documents the type is the document's MIME type. | 1141 | for documents the type is the document's MIME type. |
1139 | */ | 1142 | */ |
1140 | QString AppLnkSet::typeName( const QString& t ) const | 1143 | QString AppLnkSet::typeName( const QString& t ) const |
1141 | { | 1144 | { |
1142 | QString *st = d->typName.find(t); | 1145 | QString *st = d->typName.find(t); |
1143 | return st ? *st : QString::null; | 1146 | return st ? *st : QString::null; |
1144 | } | 1147 | } |
1145 | 1148 | ||
1146 | /*! | 1149 | /*! |
1147 | Returns the small pixmap associated with type \a t. | 1150 | Returns the small pixmap associated with type \a t. |
1148 | 1151 | ||
1149 | For applications, games and settings the type is \c Application; | 1152 | For applications, games and settings the type is \c Application; |
1150 | for documents the type is the document's MIME type. | 1153 | for documents the type is the document's MIME type. |
1151 | */ | 1154 | */ |
1152 | QPixmap AppLnkSet::typePixmap( const QString& t ) const | 1155 | QPixmap AppLnkSet::typePixmap( const QString& t ) const |
1153 | { | 1156 | { |
1154 | QPixmap *pm = d->typPix.find(t); | 1157 | QPixmap *pm = d->typPix.find(t); |
1155 | return pm ? *pm : QPixmap(); | 1158 | return pm ? *pm : QPixmap(); |
1156 | } | 1159 | } |
1157 | 1160 | ||
1158 | /*! | 1161 | /*! |
1159 | Returns the large pixmap associated with type \a t. | 1162 | Returns the large pixmap associated with type \a t. |
1160 | 1163 | ||
1161 | For applications, games and settings the type is \c Application; | 1164 | For applications, games and settings the type is \c Application; |
1162 | for documents the type is the document's MIME type. | 1165 | for documents the type is the document's MIME type. |
1163 | */ | 1166 | */ |
1164 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const | 1167 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const |
1165 | { | 1168 | { |
1166 | QPixmap *pm = d->typPixBig.find(t); | 1169 | QPixmap *pm = d->typPixBig.find(t); |
1167 | return pm ? *pm : QPixmap(); | 1170 | return pm ? *pm : QPixmap(); |
1168 | } | 1171 | } |
1169 | 1172 | ||
1170 | /*! | 1173 | /*! |
1171 | Returns the AppLnk with the given \a id. | 1174 | Returns the AppLnk with the given \a id. |
1172 | */ | 1175 | */ |
1173 | const AppLnk *AppLnkSet::find( int id ) const | 1176 | const AppLnk *AppLnkSet::find( int id ) const |
1174 | { | 1177 | { |
1175 | QListIterator<AppLnk> it( children() ); | 1178 | QListIterator<AppLnk> it( children() ); |
1176 | 1179 | ||
1177 | for ( ; it.current(); ++it ) { | 1180 | for ( ; it.current(); ++it ) { |
1178 | const AppLnk *app = it.current(); | 1181 | const AppLnk *app = it.current(); |
1179 | if ( app->id() == id ) | 1182 | if ( app->id() == id ) |
1180 | return app; | 1183 | return app; |
1181 | } | 1184 | } |
1182 | 1185 | ||
1183 | return 0; | 1186 | return 0; |
1184 | } | 1187 | } |
1185 | 1188 | ||
1186 | /*! | 1189 | /*! |
1187 | Returns the AppLnk with the given \a exec attribute. | 1190 | Returns the AppLnk with the given \a exec attribute. |
1188 | */ | 1191 | */ |
1189 | const AppLnk *AppLnkSet::findExec( const QString& exec ) const | 1192 | const AppLnk *AppLnkSet::findExec( const QString& exec ) const |
1190 | { | 1193 | { |
1191 | QListIterator<AppLnk> it( children() ); | 1194 | QListIterator<AppLnk> it( children() ); |
1192 | 1195 | ||
1193 | for ( ; it.current(); ++it ) { | 1196 | for ( ; it.current(); ++it ) { |
1194 | const AppLnk *app = it.current(); | 1197 | const AppLnk *app = it.current(); |
1195 | if ( app->exec() == exec ) | 1198 | if ( app->exec() == exec ) |
1196 | return app; | 1199 | return app; |
1197 | } | 1200 | } |
1198 | 1201 | ||
1199 | return 0; | 1202 | return 0; |
1200 | } | 1203 | } |
1201 | 1204 | ||
1202 | /*! | 1205 | /*! |
1203 | \class DocLnkSet applnk.h | 1206 | \class DocLnkSet applnk.h |
1204 | \brief The DocLnkSet class is a set of DocLnk objects. | 1207 | \brief The DocLnkSet class is a set of DocLnk objects. |
1205 | */ | 1208 | */ |
1206 | 1209 | ||
1207 | /*! | 1210 | /*! |
1208 | \fn const QList<DocLnk>& DocLnkSet::children() const | 1211 | \fn const QList<DocLnk>& DocLnkSet::children() const |
1209 | 1212 | ||
1210 | Returns the members of the set. | 1213 | Returns the members of the set. |
1211 | */ | 1214 | */ |
1212 | 1215 | ||
1213 | /*! | 1216 | /*! |
1214 | Constructs an empty DocLnkSet. | 1217 | Constructs an empty DocLnkSet. |
1215 | 1218 | ||
1216 | \sa appendFrom() | 1219 | \sa appendFrom() |
1217 | */ | 1220 | */ |
1218 | DocLnkSet::DocLnkSet() | 1221 | DocLnkSet::DocLnkSet() |
1219 | { | 1222 | { |
1220 | } | 1223 | } |
1221 | 1224 | ||
1222 | /*! | 1225 | /*! |
1223 | Constructs a DocLnkSet that contains DocLnk objects representing all | 1226 | Constructs a DocLnkSet that contains DocLnk objects representing all |
1224 | the files in the \a directory (and any subdirectories, recursively). | 1227 | the files in the \a directory (and any subdirectories, recursively). |
1225 | 1228 | ||
1226 | If \a mimefilter is not null, | 1229 | If \a mimefilter is not null, |
1227 | only documents with a MIME type matching \a mimefilter are selected. | 1230 | only documents with a MIME type matching \a mimefilter are selected. |
1228 | The value may contain multiple wild-card patterns separated by ";", | 1231 | The value may contain multiple wild-card patterns separated by ";", |
1229 | such as \c{*o/mpeg;audio/x-wav}. | 1232 | such as \c{*o/mpeg;audio/x-wav}. |
1230 | 1233 | ||
1231 | See also \link applnk.html#files-and-links Files and Links\endlink. | 1234 | See also \link applnk.html#files-and-links Files and Links\endlink. |
1232 | 1235 | ||
1233 | */ | 1236 | */ |
1234 | DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : | 1237 | DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : |
1235 | AppLnkSet() | 1238 | AppLnkSet() |
1236 | { | 1239 | { |
1237 | QDir dir( directory ); | 1240 | QDir dir( directory ); |
1238 | mFile = dir.dirName(); | 1241 | mFile = dir.dirName(); |
1239 | QDict<void> reference; | 1242 | QDict<void> reference; |
1240 | 1243 | ||
1241 | QStringList subFilter = QStringList::split(";", mimefilter); | 1244 | QStringList subFilter = QStringList::split(";", mimefilter); |
1242 | QValueList<QRegExp> mimeFilters; | 1245 | QValueList<QRegExp> mimeFilters; |
1243 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) | 1246 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) |
1244 | mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); | 1247 | mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); |
1245 | 1248 | ||
1246 | findChildren(directory, mimeFilters, reference); | 1249 | findChildren(directory, mimeFilters, reference); |
1247 | 1250 | ||
1248 | const QList<DocLnk> &list = children(); | 1251 | const QList<DocLnk> &list = children(); |
1249 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 1252 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
1250 | reference.remove( (*it)->file() ); | 1253 | reference.remove( (*it)->file() ); |
1251 | } | 1254 | } |
1252 | 1255 | ||
1253 | for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { | 1256 | for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { |
1254 | if ( dit.current() == (void*)2 ) { | 1257 | if ( dit.current() == (void*)2 ) { |
1255 | // Unreferenced, make an unwritten link | 1258 | // Unreferenced, make an unwritten link |
1256 | DocLnk* dl = new DocLnk; | 1259 | DocLnk* dl = new DocLnk; |
1257 | QFileInfo fi( dit.currentKey() ); | 1260 | QFileInfo fi( dit.currentKey() ); |
1258 | dl->setFile(fi.filePath()); | 1261 | dl->setFile(fi.filePath()); |
1259 | dl->setName(fi.baseName()); | 1262 | dl->setName(fi.baseName()); |
1260 | // #### default to current path? | 1263 | // #### default to current path? |
1261 | // dl->setCategories( ... ); | 1264 | // dl->setCategories( ... ); |
1262 | bool match = mimefilter.isNull(); | 1265 | bool match = mimefilter.isNull(); |
1263 | if ( !match ) | 1266 | if ( !match ) |
1264 | for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) | 1267 | for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) |
1265 | if ( (*it).match(dl->type()) >= 0 ) | 1268 | if ( (*it).match(dl->type()) >= 0 ) |
1266 | match = TRUE; | 1269 | match = TRUE; |
1267 | if ( match /* && dl->type() != "application/octet-stream" */ | 1270 | if ( match /* && dl->type() != "application/octet-stream" */ |
1268 | && !!dl->exec() ) | 1271 | && !!dl->exec() ) |
1269 | add(dl); | 1272 | add(dl); |
1270 | else | 1273 | else |
1271 | delete dl; | 1274 | delete dl; |
1272 | } | 1275 | } |
1273 | } | 1276 | } |
1274 | } | 1277 | } |
1275 | 1278 | ||
1276 | // other becomes empty | 1279 | // other becomes empty |
1277 | /*! | 1280 | /*! |
1278 | Transfers all DocLnk objects from \a other to this set. \a other becomes | 1281 | Transfers all DocLnk objects from \a other to this set. \a other becomes |
1279 | empty. | 1282 | empty. |
1280 | */ | 1283 | */ |
1281 | void DocLnkSet::appendFrom( DocLnkSet& other ) | 1284 | void DocLnkSet::appendFrom( DocLnkSet& other ) |
1282 | { | 1285 | { |
1283 | if ( &other == this ) | 1286 | if ( &other == this ) |
1284 | return; | 1287 | return; |
1285 | QListIterator<AppLnk> it( other.mApps ); | 1288 | QListIterator<AppLnk> it( other.mApps ); |
1286 | for ( ; it.current(); ) { | 1289 | for ( ; it.current(); ) { |
1287 | mApps.append(*it); | 1290 | mApps.append(*it); |
1288 | ++it; | 1291 | ++it; |
1289 | } | 1292 | } |
1290 | other.mApps.clear(); | 1293 | other.mApps.clear(); |
1291 | } | 1294 | } |
1292 | 1295 | ||
1293 | void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) | 1296 | void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) |
1294 | { | 1297 | { |
1295 | depth++; | 1298 | depth++; |
1296 | if ( depth > 10 ) | 1299 | if ( depth > 10 ) |
1297 | return; | 1300 | return; |
1298 | 1301 | ||
1299 | QDir dir( dr ); | 1302 | QDir dir( dr ); |
1300 | 1303 | ||
1301 | /* Opie got a different approach | 1304 | /* Opie got a different approach |
1302 | * I guess it's geek vs. consumer | 1305 | * I guess it's geek vs. consumer |
1303 | * in this case to be discussed | 1306 | * in this case to be discussed |
1304 | */ | 1307 | */ |
1305 | if ( dir.exists( ".Qtopia-ignore" ) ) | 1308 | if ( dir.exists( ".Qtopia-ignore" ) ) |
1306 | return; | 1309 | return; |
1307 | 1310 | ||
1308 | const QFileInfoList *list = dir.entryInfoList(); | 1311 | const QFileInfoList *list = dir.entryInfoList(); |
1309 | if ( list ) { | 1312 | if ( list ) { |
1310 | QFileInfo* fi; | 1313 | QFileInfo* fi; |
1311 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1314 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1312 | QString bn = fi->fileName(); | 1315 | QString bn = fi->fileName(); |
1313 | if ( bn[0] != '.' ) { | 1316 | if ( bn[0] != '.' ) { |
1314 | if ( fi->isDir() ) { | 1317 | if ( fi->isDir() ) { |
1315 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) | 1318 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) |
1316 | findChildren(fi->filePath(), mimeFilters, reference, depth); | 1319 | findChildren(fi->filePath(), mimeFilters, reference, depth); |
1317 | } else { | 1320 | } else { |
1318 | if ( fi->extension(FALSE) == "desktop" ) { | 1321 | if ( fi->extension(FALSE) == "desktop" ) { |
1319 | DocLnk* dl = new DocLnk( fi->filePath() ); | 1322 | DocLnk* dl = new DocLnk( fi->filePath() ); |
1320 | QFileInfo fi2(dl->file()); | 1323 | QFileInfo fi2(dl->file()); |
1321 | bool match = FALSE; | 1324 | bool match = FALSE; |
1322 | if ( !fi2.exists() ) { | 1325 | if ( !fi2.exists() ) { |
1323 | dir.remove( dl->file() ); | 1326 | dir.remove( dl->file() ); |
1324 | } | 1327 | } |
1325 | if ( mimeFilters.count() == 0 ) { | 1328 | if ( mimeFilters.count() == 0 ) { |
1326 | add( dl ); | 1329 | add( dl ); |
1327 | match = TRUE; | 1330 | match = TRUE; |
1328 | } else { | 1331 | } else { |
1329 | for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { | 1332 | for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { |
1330 | if ( (*it).match(dl->type()) >= 0 ) { | 1333 | if ( (*it).match(dl->type()) >= 0 ) { |
1331 | add(dl); | 1334 | add(dl); |
1332 | match = TRUE; | 1335 | match = TRUE; |
1333 | } | 1336 | } |
1334 | } | 1337 | } |
1335 | } | 1338 | } |
1336 | if ( !match ) | 1339 | if ( !match ) |
1337 | delete dl; | 1340 | delete dl; |
1338 | } else { | 1341 | } else { |
1339 | if ( !reference.find(fi->fileName()) ) | 1342 | if ( !reference.find(fi->fileName()) ) |
1340 | reference.insert(fi->filePath(), (void*)2); | 1343 | reference.insert(fi->filePath(), (void*)2); |
1341 | } | 1344 | } |
1342 | } | 1345 | } |
1343 | } | 1346 | } |
1344 | } | 1347 | } |
1345 | } | 1348 | } |
1346 | } | 1349 | } |
1347 | 1350 | ||
1348 | /*! | 1351 | /*! |
1349 | \class DocLnk applnk.h | 1352 | \class DocLnk applnk.h |
1350 | \brief The DocLnk class represents loaded document references. | 1353 | \brief The DocLnk class represents loaded document references. |
1351 | */ | 1354 | */ |
1352 | 1355 | ||
1353 | /*! | 1356 | /*! |
1354 | \fn DocLnk::DocLnk( const DocLnk &o ) | 1357 | \fn DocLnk::DocLnk( const DocLnk &o ) |
1355 | 1358 | ||
1356 | Copies \a o. | 1359 | Copies \a o. |
1357 | */ | 1360 | */ |
1358 | 1361 | ||
1359 | /*! | 1362 | /*! |
1360 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop | 1363 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop |
1361 | \a file for other files. | 1364 | \a file for other files. |
1362 | */ | 1365 | */ |
1363 | DocLnk::DocLnk( const QString &file ) : | 1366 | DocLnk::DocLnk( const QString &file ) : |
1364 | AppLnk(file) | 1367 | AppLnk(file) |
1365 | { | 1368 | { |
1366 | init(file); | 1369 | init(file); |
1367 | } | 1370 | } |
1368 | 1371 | ||
1369 | /*! | 1372 | /*! |
1370 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop | 1373 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop |
1371 | \a file for other files. If \a may_be_desktopfile is TRUE, then an | 1374 | \a file for other files. If \a may_be_desktopfile is TRUE, then an |
1372 | attempt is made to read \a file as a .desktop file; if that fails it | 1375 | attempt is made to read \a file as a .desktop file; if that fails it |
1373 | is read as a normal file. | 1376 | is read as a normal file. |
1374 | */ | 1377 | */ |
1375 | DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : | 1378 | DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : |
1376 | AppLnk(may_be_desktopfile ? file : QString::null) | 1379 | AppLnk(may_be_desktopfile ? file : QString::null) |
1377 | { | 1380 | { |
1378 | init(file); | 1381 | init(file); |
1379 | } | 1382 | } |
1380 | 1383 | ||
1381 | void DocLnk::init(const QString &file) | 1384 | void DocLnk::init(const QString &file) |
1382 | { | 1385 | { |
1383 | if ( isValid() ) { | 1386 | if ( isValid() ) { |
1384 | #ifndef FORCED_DIR_STRUCTURE_WAY | 1387 | #ifndef FORCED_DIR_STRUCTURE_WAY |
1385 | if ( mType.isNull() ) | 1388 | if ( mType.isNull() ) |
1386 | // try to infer it | 1389 | // try to infer it |
1387 | #endif | 1390 | #endif |
1388 | { | 1391 | { |
1389 | int s0 = file.findRev('/'); | 1392 | int s0 = file.findRev('/'); |
1390 | if ( s0 > 0 ) { | 1393 | if ( s0 > 0 ) { |
1391 | int s1 = file.findRev('/',s0-1); | 1394 | int s1 = file.findRev('/',s0-1); |
1392 | if ( s1 > 0 ) { | 1395 | if ( s1 > 0 ) { |
1393 | int s2 = file.findRev('/',s1-1); | 1396 | int s2 = file.findRev('/',s1-1); |
1394 | if ( s2 > 0 ) { | 1397 | if ( s2 > 0 ) { |
1395 | mType = file.mid(s2+1,s0-s2-1); | 1398 | mType = file.mid(s2+1,s0-s2-1); |
1396 | } | 1399 | } |
1397 | } | 1400 | } |
1398 | } | 1401 | } |
1399 | } | 1402 | } |
1400 | } else if ( QFile::exists(file) ) { | 1403 | } else if ( QFile::exists(file) ) { |
1401 | QString n = file; | 1404 | QString n = file; |
1402 | n.replace(QRegExp(".*/"),""); | 1405 | n.replace(QRegExp(".*/"),""); |
1403 | n.replace(QRegExp("\\..*"),""); | 1406 | n.replace(QRegExp("\\..*"),""); |
1404 | setName( n ); | 1407 | setName( n ); |
1405 | setFile( file ); | 1408 | setFile( file ); |
1406 | } | 1409 | } |
1407 | MimeType mt(mType); | 1410 | MimeType mt(mType); |
1408 | if( mt.application() ) | 1411 | if( mt.application() ) |
1409 | mExec = mt.application()->exec(); | 1412 | mExec = mt.application()->exec(); |
1410 | } | 1413 | } |
1411 | 1414 | ||
1412 | /*! | 1415 | /*! |
1413 | Constructs an invalid DocLnk. | 1416 | Constructs an invalid DocLnk. |
1414 | */ | 1417 | */ |
1415 | DocLnk::DocLnk() | 1418 | DocLnk::DocLnk() |
1416 | { | 1419 | { |
1417 | } | 1420 | } |
1418 | 1421 | ||
1419 | /*! | 1422 | /*! |
1420 | Destroys the DocLnk. Just like AppLnk objects, a run-time error | 1423 | Destroys the DocLnk. Just like AppLnk objects, a run-time error |
1421 | occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). | 1424 | occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). |
1422 | */ | 1425 | */ |
1423 | DocLnk::~DocLnk() | 1426 | DocLnk::~DocLnk() |
1424 | { | 1427 | { |
1425 | } | 1428 | } |
1426 | 1429 | ||
1427 | /*! | 1430 | /*! |
1428 | \reimp | 1431 | \reimp |
1429 | */ | 1432 | */ |
1430 | QString DocLnk::exec() const | 1433 | QString DocLnk::exec() const |
1431 | { | 1434 | { |
1432 | MimeType mt(type()); | 1435 | MimeType mt(type()); |
1433 | const AppLnk* app = mt.application(); | 1436 | const AppLnk* app = mt.application(); |
1434 | if ( app ) | 1437 | if ( app ) |
1435 | return app->exec(); | 1438 | return app->exec(); |
1436 | else | 1439 | else |
1437 | return QString::null; | 1440 | return QString::null; |
1438 | } | 1441 | } |
1439 | 1442 | ||
1440 | /*! | 1443 | /*! |
1441 | \reimp | 1444 | \reimp |
1442 | */ | 1445 | */ |
1443 | void DocLnk::invoke(const QStringList& args) const | 1446 | void DocLnk::invoke(const QStringList& args) const |
1444 | { | 1447 | { |
1445 | MimeType mt(type()); | 1448 | MimeType mt(type()); |
1446 | const AppLnk* app = mt.application(); | 1449 | const AppLnk* app = mt.application(); |
1447 | if ( app ) { | 1450 | if ( app ) { |
1448 | QStringList a = args; | 1451 | QStringList a = args; |
1449 | if ( linkFileKnown() && QFile::exists( linkFile() ) ) | 1452 | if ( linkFileKnown() && QFile::exists( linkFile() ) ) |
1450 | a.append(linkFile()); | 1453 | a.append(linkFile()); |
1451 | else | 1454 | else |
1452 | a.append(file()); | 1455 | a.append(file()); |
1453 | app->execute(a); | 1456 | app->execute(a); |
1454 | } | 1457 | } |
1455 | } | 1458 | } |
1456 | 1459 | ||
1457 | 1460 | ||