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