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 8763eb2..9c60f1a 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,1497 +1,1493 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#define QTOPIA_INTERNAL_APPLNKASSIGN 23#define QTOPIA_INTERNAL_APPLNKASSIGN
24 24
25#include "applnk.h" 25#include "applnk.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/categories.h> 28#include <qpe/categories.h>
29#include <qpe/categoryselect.h> 29#include <qpe/categoryselect.h>
30#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
31#include <qpe/global.h>
32#include <qpe/mimetype.h> 31#include <qpe/mimetype.h>
33#include <qpe/config.h> 32#include <qpe/config.h>
34#include <qpe/storage.h> 33#include <qpe/storage.h>
35#include <qpe/resource.h> 34#include <qpe/resource.h>
36 35
37#include <qdict.h>
38#include <qdir.h> 36#include <qdir.h>
39#include <qregexp.h>
40 37
41#include <qgfx_qws.h>
42 38
43#include <stdlib.h> 39#include <stdlib.h>
44 40
45int AppLnk::lastId = 5000; 41int AppLnk::lastId = 5000;
46 42
47static int smallSize = 14; 43static int smallSize = 14;
48static int bigSize = 32; 44static int bigSize = 32;
49 45
50static QString safeFileName(const QString& n) 46static QString safeFileName(const QString& n)
51{ 47{
52 QString safename=n; 48 QString safename=n;
53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 49 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
54 safename.replace(QRegExp("^[^A-Za-z]*"),""); 50 safename.replace(QRegExp("^[^A-Za-z]*"),"");
55 if ( safename.isEmpty() ) 51 if ( safename.isEmpty() )
56 safename = "_"; 52 safename = "_";
57 return safename; 53 return safename;
58} 54}
59 55
60static bool prepareDirectories(const QString& lf) 56static bool prepareDirectories(const QString& lf)
61{ 57{
62 if ( !QFile::exists(lf) ) { 58 if ( !QFile::exists(lf) ) {
63 // May need to create directories 59 // May need to create directories
64 QFileInfo fi(lf); 60 QFileInfo fi(lf);
65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 61 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
66 return FALSE; 62 return FALSE;
67 } 63 }
68 return TRUE; 64 return TRUE;
69} 65}
70 66
71class AppLnkPrivate 67class AppLnkPrivate
72{ 68{
73public: 69public:
74 /* the size of the Pixmap */ 70 /* the size of the Pixmap */
75 enum Size {Normal = 0, Big }; 71 enum Size {Normal = 0, Big };
76 AppLnkPrivate() { 72 AppLnkPrivate() {
77 /* we want one normal and one big item */ 73 /* we want one normal and one big item */
78 74
79 QPixmap pix; 75 QPixmap pix;
80 mPixmaps.insert(0, pix ); 76 mPixmaps.insert(0, pix );
81 mPixmaps.insert(1, pix); 77 mPixmaps.insert(1, pix);
82 } 78 }
83 79
84 QStringList mCatList; // always correct 80 QStringList mCatList; // always correct
85 QArray<int> mCat; // cached value; correct if not empty 81 QArray<int> mCat; // cached value; correct if not empty
86 QMap<int, QPixmap> mPixmaps; 82 QMap<int, QPixmap> mPixmaps;
87 83
88 void updateCatListFromArray() 84 void updateCatListFromArray()
89 { 85 {
90 Categories cat( 0 ); 86 Categories cat( 0 );
91 cat.load( categoryFileName() ); 87 cat.load( categoryFileName() );
92 // we need to update the names for the mCat... to mCatList 88 // we need to update the names for the mCat... to mCatList
93 mCatList.clear(); 89 mCatList.clear();
94 for (uint i = 0; i < mCat.count(); i++ ) 90 for (uint i = 0; i < mCat.count(); i++ )
95 mCatList << cat.label("Document View", mCat[i] ); 91 mCatList << cat.label("Document View", mCat[i] );
96 92
97 } 93 }
98 94
99 void setCatArrayDirty() 95 void setCatArrayDirty()
100 { 96 {
101 mCat.resize(0); 97 mCat.resize(0);
102 } 98 }
103 99
104 void ensureCatArray() 100 void ensureCatArray()
105 { 101 {
106 if ( mCat.count() > 0 || mCatList.count()==0 ) 102 if ( mCat.count() > 0 || mCatList.count()==0 )
107 return; 103 return;
108 104
109 Categories cat( 0 ); 105 Categories cat( 0 );
110 cat.load( categoryFileName() ); 106 cat.load( categoryFileName() );
111 mCat.resize( mCatList.count() ); 107 mCat.resize( mCatList.count() );
112 int i; 108 int i;
113 QStringList::ConstIterator it; 109 QStringList::ConstIterator it;
114 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 110 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
115 ++it, i++ ) { 111 ++it, i++ ) {
116 112
117 bool number; 113 bool number;
118 int id = (*it).toInt( &number ); 114 int id = (*it).toInt( &number );
119 if ( !number ) { 115 if ( !number ) {
120 id = cat.id( "Document View", *it ); 116 id = cat.id( "Document View", *it );
121 if ( id == 0 ) 117 if ( id == 0 )
122 id = cat.addCategory( "Document View", *it ); 118 id = cat.addCategory( "Document View", *it );
123 } 119 }
124 mCat[i] = id; 120 mCat[i] = id;
125 } 121 }
126 } 122 }
127}; 123};
128 124
129/*! 125/*!
130 \class AppLnk applnk.h 126 \class AppLnk applnk.h
131 \brief The AppLnk class represents an application available on the system. 127 \brief The AppLnk class represents an application available on the system.
132 128
133 Every Qtopia application \e app has a corresponding \e app.desktop 129 Every Qtopia application \e app has a corresponding \e app.desktop
134 file. When one of these files is read its data is stored as an 130 file. When one of these files is read its data is stored as an
135 AppLnk object. 131 AppLnk object.
136 132
137 The AppLnk class introduces some Qtopia-specific concepts, and 133 The AppLnk class introduces some Qtopia-specific concepts, and
138 provides a variety of functions, as described in the following 134 provides a variety of functions, as described in the following
139 sections. 135 sections.
140 \tableofcontents 136 \tableofcontents
141 137
142 \target Types 138 \target Types
143 \section1 Types 139 \section1 Types
144 140
145 Every AppLnk object has a \e type. For applications, games and 141 Every AppLnk object has a \e type. For applications, games and
146 settings the type is \c Application; for documents the 142 settings the type is \c Application; for documents the
147 type is the document's MIME type. 143 type is the document's MIME type.
148 144
149 \target files-and-links 145 \target files-and-links
150 \section1 Files and Links 146 \section1 Files and Links
151 147
152 When you create an AppLnk (or more likely, a \link doclnk.html 148 When you create an AppLnk (or more likely, a \link doclnk.html
153 DocLnk\endlink), you don't deal directly with filenames in the 149 DocLnk\endlink), you don't deal directly with filenames in the
154 filesystem. Instead you do this: 150 filesystem. Instead you do this:
155 \code 151 \code
156 DocLnk d; 152 DocLnk d;
157 d.setType("text/plain"); 153 d.setType("text/plain");
158 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 154 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
159 \endcode 155 \endcode
160 At this point, the file() and linkFile() are unknown. Normally 156 At this point, the file() and linkFile() are unknown. Normally
161 this is uninteresting, and the names become automatically known, 157 this is uninteresting, and the names become automatically known,
162 and more importantly, becomes reserved, when you ask what they are: 158 and more importantly, becomes reserved, when you ask what they are:
163 159
164 \code 160 \code
165 QString fn = d.file(); 161 QString fn = d.file();
166 \endcode 162 \endcode
167 This invents a filename, and creates the file on disk (an empty 163 This invents a filename, and creates the file on disk (an empty
168 reservation file) to prevent the name being used by another 164 reservation file) to prevent the name being used by another
169 application. 165 application.
170 166
171 In some circumstances, you don't want to create the file if it 167 In some circumstances, you don't want to create the file if it
172 doesn't already exist (e.g. in the Document tab, some of the \link 168 doesn't already exist (e.g. in the Document tab, some of the \link
173 doclnk.html DocLnk\endlink objects represented by icons are 169 doclnk.html DocLnk\endlink objects represented by icons are
174 DocLnk's created just for that view - they don't have 170 DocLnk's created just for that view - they don't have
175 corresponding \c .desktop files. To avoid littering empty 171 corresponding \c .desktop files. To avoid littering empty
176 reservation files around, we check in a few places to see whether 172 reservation files around, we check in a few places to see whether
177 the file really needs to exist). 173 the file really needs to exist).
178 174
179 \section1 Functionality 175 \section1 Functionality
180 176
181 AppLnk objects are created by calling the constructor with the 177 AppLnk objects are created by calling the constructor with the
182 name of a \e .desktop file. The object can be checked for validity 178 name of a \e .desktop file. The object can be checked for validity
183 using isValid(). 179 using isValid().
184 180
185 The following functions are used to set or retrieve information 181 The following functions are used to set or retrieve information
186 about the application: 182 about the application:
187 \table 183 \table
188 \header \i Get Function \i Set Function \i Short Description 184 \header \i Get Function \i Set Function \i Short Description
189 \row \i \l name() \i \l setName() \i application's name 185 \row \i \l name() \i \l setName() \i application's name
190 \row \i \l pixmap() \i \e none \i application's icon 186 \row \i \l pixmap() \i \e none \i application's icon
191 \row \i \l bigPixmap() \i \e none \i application's large icon 187 \row \i \l bigPixmap() \i \e none \i application's large icon
192 \row \i \e none \i setIcon() \i sets the icon's filename 188 \row \i \e none \i setIcon() \i sets the icon's filename
193 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above 189 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
194 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees 190 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
195 \row \i \l comment() \i \l setComment() \i text for the Details dialog 191 \row \i \l comment() \i \l setComment() \i text for the Details dialog
196 \row \i \l exec() \i \l setExec() \i executable's filename 192 \row \i \l exec() \i \l setExec() \i executable's filename
197 \row \i \l file() \i \e none \i document's filename 193 \row \i \l file() \i \e none \i document's filename
198 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename 194 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename
199 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit 195 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
200 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions} 196 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions}
201 \row \i \l fileKnown() \i \e none \i see \link 197 \row \i \l fileKnown() \i \e none \i see \link
202#files-and-links Files and Links\endlink above 198#files-and-links Files and Links\endlink above
203 \row \i \l linkFileKnown() \i \e none \i see \link 199 \row \i \l linkFileKnown() \i \e none \i see \link
204#files-and-links Files and Links\endlink above 200#files-and-links Files and Links\endlink above
205 \row \i \l property() \i \l setProperty() \i any AppLnk property 201 \row \i \l property() \i \l setProperty() \i any AppLnk property
206 can be retrieved or set (if writeable) using these 202 can be retrieved or set (if writeable) using these
207 \endtable 203 \endtable
208 204
209 To save an AppLnk to disk use writeLink(). To execute the 205 To save an AppLnk to disk use writeLink(). To execute the
210 application that the AppLnk object refers to, use execute(). 206 application that the AppLnk object refers to, use execute().
211 207
212 AppLnk's can be deleted from disk using removeLinkFile(). To 208 AppLnk's can be deleted from disk using removeLinkFile(). To
213 remove both the link and the application's executable use 209 remove both the link and the application's executable use
214 removeFiles(). 210 removeFiles().
215 211
216 Icon sizes can be globally changed (but only for AppLnk objects 212 Icon sizes can be globally changed (but only for AppLnk objects
217 created after the calls) with setSmallIconSize() and 213 created after the calls) with setSmallIconSize() and
218 setBigIconSize(). 214 setBigIconSize().
219 215
220 \ingroup qtopiaemb 216 \ingroup qtopiaemb
221*/ 217*/
222 218
223/*! 219/*!
224 Sets the size used for small icons to \a small pixels. 220 Sets the size used for small icons to \a small pixels.
225 Only affects AppLnk objects created after the call. 221 Only affects AppLnk objects created after the call.
226 222
227 \sa smallIconSize() setIcon() 223 \sa smallIconSize() setIcon()
228*/ 224*/
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 \fn bool AppLnk::fileKnown() const 332 \fn bool AppLnk::fileKnown() const
337 333
338 If the with the AppLnk associated file is not equal to QString::null 334 If the with the AppLnk associated file is not equal to QString::null
339*/ 335*/
340/*! 336/*!
341 \fn bool AppLnk::linkFileKnown()const 337 \fn bool AppLnk::linkFileKnown()const
342 338
343 The filename of the AppLnk 339 The filename of the AppLnk
344 340
345*/ 341*/
346/*! 342/*!
347 \fn void AppLnk::setRotation( const QString& ) 343 \fn void AppLnk::setRotation( const QString& )
348 344
349 The default rotation of the associated application. This 345 The default rotation of the associated application. This
350 function is included inline for binary compatible issues 346 function is included inline for binary compatible issues
351*/ 347*/
352/*! 348/*!
353 Creates an invalid AppLnk. 349 Creates an invalid AppLnk.
354 350
355 \sa isValid() 351 \sa isValid()
356*/ 352*/
357AppLnk::AppLnk() 353AppLnk::AppLnk()
358{ 354{
359 mId = 0; 355 mId = 0;
360 d = new AppLnkPrivate(); 356 d = new AppLnkPrivate();
361} 357}
362 358
363/*! 359/*!
364 Loads \a file (e.g. \e app.desktop) as an AppLnk. 360 Loads \a file (e.g. \e app.desktop) as an AppLnk.
365 361
366 \sa writeLink() 362 \sa writeLink()
367*/ 363*/
368AppLnk::AppLnk( const QString &file ) 364AppLnk::AppLnk( const QString &file )
369{ 365{
370 QStringList sl; 366 QStringList sl;
371 d = new AppLnkPrivate(); 367 d = new AppLnkPrivate();
372 if ( !file.isNull() ) { 368 if ( !file.isNull() ) {
373 Config config( file, Config::File ); 369 Config config( file, Config::File );
374 370
375 if ( config.isValid() ) { 371 if ( config.isValid() ) {
376 config.setGroup( "Desktop Entry" ); 372 config.setGroup( "Desktop Entry" );
377 373
378 mName = config.readEntry( "Name", file ); 374 mName = config.readEntry( "Name", file );
379 mExec = config.readEntry( "Exec" ); 375 mExec = config.readEntry( "Exec" );
380 mType = config.readEntry( "Type", QString::null ); 376 mType = config.readEntry( "Type", QString::null );
381 mIconFile = config.readEntry( "Icon", QString::null ); 377 mIconFile = config.readEntry( "Icon", QString::null );
382 mRotation = config.readEntry( "Rotation", "" ); 378 mRotation = config.readEntry( "Rotation", "" );
383 mComment = config.readEntry( "Comment", QString::null ); 379 mComment = config.readEntry( "Comment", QString::null );
384 // MIME types are case-insensitive. 380 // MIME types are case-insensitive.
385 mMimeTypes = config.readListEntry( "MimeType", ';' ); 381 mMimeTypes = config.readListEntry( "MimeType", ';' );
386 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 382 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
387 *it = (*it).lower(); 383 *it = (*it).lower();
388 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 384 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
389 mLinkFile = file; 385 mLinkFile = file;
390 mFile = config.readEntry("File", QString::null); 386 mFile = config.readEntry("File", QString::null);
391 if ( !mExec. isEmpty ( )) { 387 if ( !mExec. isEmpty ( )) {
392 mFile = QString::null; 388 mFile = QString::null;
393 } 389 }
394 else if ( mFile[0] != '/' ) { 390 else if ( mFile[0] != '/' ) {
395 int slash = file.findRev('/'); 391 int slash = file.findRev('/');
396 if ( slash >= 0 ) { 392 if ( slash >= 0 ) {
397 mFile = file.left(slash) + '/' + mFile; 393 mFile = file.left(slash) + '/' + mFile;
398 } 394 }
399 } 395 }
400 d->mCatList = config.readListEntry("Categories", ';'); 396 d->mCatList = config.readListEntry("Categories", ';');
401 if ( d->mCatList[0].toInt() < -1 ) { 397 if ( d->mCatList[0].toInt() < -1 ) {
402 // numeric cats in file! convert to text 398 // numeric cats in file! convert to text
403 Categories cat( 0 ); 399 Categories cat( 0 );
404 cat.load( categoryFileName() ); 400 cat.load( categoryFileName() );
405 d->mCat.resize( d->mCatList.count() ); 401 d->mCat.resize( d->mCatList.count() );
406 int i; 402 int i;
407 QStringList::ConstIterator it; 403 QStringList::ConstIterator it;
408 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 404 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
409 ++it, i++ ) { 405 ++it, i++ ) {
410 bool number; 406 bool number;
411 int id = (*it).toInt( &number ); 407 int id = (*it).toInt( &number );
412 if ( !number ) { 408 if ( !number ) {
413 // convert from text 409 // convert from text
414 id = cat.id( "Document View", *it ); 410 id = cat.id( "Document View", *it );
415 if ( id == 0 ) 411 if ( id == 0 )
416 id = cat.addCategory( "Document View", *it ); 412 id = cat.addCategory( "Document View", *it );
417 } 413 }
418 d->mCat[i] = id; 414 d->mCat[i] = id;
419 } 415 }
420 d->updateCatListFromArray(); 416 d->updateCatListFromArray();
421 } 417 }
422 } 418 }
423 } 419 }
424 mId = 0; 420 mId = 0;
425} 421}
426 422
427AppLnk& AppLnk::operator=(const AppLnk &copy) 423AppLnk& AppLnk::operator=(const AppLnk &copy)
428{ 424{
429 if ( this == &copy ) return *this; 425 if ( this == &copy ) return *this;
430 if ( mId ) 426 if ( mId )
431 qWarning("Deleting AppLnk that is in an AppLnkSet"); 427 qWarning("Deleting AppLnk that is in an AppLnkSet");
432 if ( d ) 428 if ( d )
433 delete d; 429 delete d;
434 430
435 431
436 mName = copy.mName; 432 mName = copy.mName;
437 433
438 /* remove for Qtopia 3.0 -zecke */ 434 /* remove for Qtopia 3.0 -zecke */
439 mPixmap = copy.mPixmap; 435 mPixmap = copy.mPixmap;
440 mBigPixmap = copy.mBigPixmap; 436 mBigPixmap = copy.mBigPixmap;
441 437
442 mExec = copy.mExec; 438 mExec = copy.mExec;
443 mType = copy.mType; 439 mType = copy.mType;
444 mRotation = copy.mRotation; 440 mRotation = copy.mRotation;
445 mComment = copy.mComment; 441 mComment = copy.mComment;
446 mFile = copy.mFile; 442 mFile = copy.mFile;
447 mLinkFile = copy.mLinkFile; 443 mLinkFile = copy.mLinkFile;
448 mIconFile = copy.mIconFile; 444 mIconFile = copy.mIconFile;
449 mMimeTypes = copy.mMimeTypes; 445 mMimeTypes = copy.mMimeTypes;
450 mMimeTypeIcons = copy.mMimeTypeIcons; 446 mMimeTypeIcons = copy.mMimeTypeIcons;
451 mId = 0; 447 mId = 0;
452 d = new AppLnkPrivate(); 448 d = new AppLnkPrivate();
453 d->mCat = copy.d->mCat; 449 d->mCat = copy.d->mCat;
454 d->mCatList = copy.d->mCatList; 450 d->mCatList = copy.d->mCatList;
455 d->mPixmaps = copy.d->mPixmaps; 451 d->mPixmaps = copy.d->mPixmaps;
456 452
457 return *this; 453 return *this;
458} 454}
459/*! 455/*!
460 protected internally to share code 456 protected internally to share code
461 should I document that at all? 457 should I document that at all?
462 I don't know the TT style for that 458 I don't know the TT style for that
463*/ 459*/
464const QPixmap& AppLnk::pixmap( int pos, int size ) const { 460const QPixmap& AppLnk::pixmap( int pos, int size ) const {
465 if ( d->mPixmaps[pos].isNull() ) { 461 if ( d->mPixmaps[pos].isNull() ) {
466 AppLnk* that = (AppLnk*)this; 462 AppLnk* that = (AppLnk*)this;
467 if ( mIconFile.isEmpty() ) { 463 if ( mIconFile.isEmpty() ) {
468 MimeType mt(type()); 464 MimeType mt(type());
469 that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); 465 that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap();
470 if ( that->d->mPixmaps[pos].isNull() ) 466 if ( that->d->mPixmaps[pos].isNull() )
471 that->d->mPixmaps[pos].convertFromImage( 467 that->d->mPixmaps[pos].convertFromImage(
472 Resource::loadImage("UnknownDocument") 468 Resource::loadImage("UnknownDocument")
473 .smoothScale( size, size ) ); 469 .smoothScale( size, size ) );
474 return that->d->mPixmaps[pos]; 470 return that->d->mPixmaps[pos];
475 } 471 }
476 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 472 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
477 if ( unscaledIcon.isNull() ) { 473 if ( unscaledIcon.isNull() ) {
478 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 474 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
479 that->d->mPixmaps[pos].convertFromImage( 475 that->d->mPixmaps[pos].convertFromImage(
480 Resource::loadImage("UnknownDocument") 476 Resource::loadImage("UnknownDocument")
481 .smoothScale( size, size ) ); 477 .smoothScale( size, size ) );
482 } else { 478 } else {
483 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 479 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
484 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 480 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
485 } 481 }
486 return that->d->mPixmaps[pos]; 482 return that->d->mPixmaps[pos];
487 } 483 }
488 return d->mPixmaps[pos]; 484 return d->mPixmaps[pos];
489} 485}
490 486
491/*! 487/*!
492 Returns a small pixmap associated with the application. 488 Returns a small pixmap associated with the application.
493 489
494 \sa bigPixmap() setIcon() 490 \sa bigPixmap() setIcon()
495*/ 491*/
496const QPixmap& AppLnk::pixmap() const 492const QPixmap& AppLnk::pixmap() const
497{ 493{
498 if ( d->mPixmaps[0].isNull() ) { 494 if ( d->mPixmaps[0].isNull() ) {
499 return pixmap(AppLnkPrivate::Normal, smallSize ); 495 return pixmap(AppLnkPrivate::Normal, smallSize );
500 } 496 }
501 return d->mPixmaps[0]; 497 return d->mPixmaps[0];
502} 498}
503 499
504/*! 500/*!
505 Returns a large pixmap associated with the application. 501 Returns a large pixmap associated with the application.
506 502
507 \sa pixmap() setIcon() 503 \sa pixmap() setIcon()
508*/ 504*/
509const QPixmap& AppLnk::bigPixmap() const 505const QPixmap& AppLnk::bigPixmap() const
510{ 506{
511 if ( d->mPixmaps[1].isNull() ) { 507 if ( d->mPixmaps[1].isNull() ) {
512 return pixmap( AppLnkPrivate::Big, bigSize ); 508 return pixmap( AppLnkPrivate::Big, bigSize );
513 } 509 }
514 return d->mPixmaps[1]; 510 return d->mPixmaps[1];
515} 511}
516 512
517/*! 513/*!
518 Returns the type of the AppLnk. For applications, games and 514 Returns the type of the AppLnk. For applications, games and
519 settings the type is \c Application; for documents the type is the 515 settings the type is \c Application; for documents the type is the
520 document's MIME type. 516 document's MIME type.
521*/ 517*/
522QString AppLnk::type() const 518QString AppLnk::type() const
523{ 519{
524 if ( mType.isNull() ) { 520 if ( mType.isNull() ) {
525 AppLnk* that = (AppLnk*)this; 521 AppLnk* that = (AppLnk*)this;
526 QString f = file(); 522 QString f = file();
527 if ( !f.isNull() ) { 523 if ( !f.isNull() ) {
528 MimeType mt(f); 524 MimeType mt(f);
529 that->mType = mt.id(); 525 that->mType = mt.id();
530 return that->mType; 526 return that->mType;
531 } 527 }
532 } 528 }
533 return mType; 529 return mType;
534} 530}
535 531
536/*! 532/*!
537 Returns the file associated with the AppLnk. 533 Returns the file associated with the AppLnk.
538 534
539 \sa exec() name() 535 \sa exec() name()
540*/ 536*/
541QString AppLnk::file() const 537QString AppLnk::file() const
542{ 538{
543 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 539 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
544 AppLnk* that = (AppLnk*)this; 540 AppLnk* that = (AppLnk*)this;
545 QString ext = MimeType(mType).extension(); 541 QString ext = MimeType(mType).extension();
546 if ( !ext.isEmpty() ) 542 if ( !ext.isEmpty() )
547 ext = "." + ext; 543 ext = "." + ext;
548 if ( !mLinkFile.isEmpty() ) { 544 if ( !mLinkFile.isEmpty() ) {
549 that->mFile = 545 that->mFile =
550 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 546 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
551 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 547 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
552 qDebug("mFile now == %s", mFile.latin1()); 548 qDebug("mFile now == %s", mFile.latin1());
553 } else if ( mType.contains('/') ) { 549 } else if ( mType.contains('/') ) {
554 that->mFile = 550 that->mFile =
555 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 551 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
556 /* 552 /*
557 * A file with the same name or a .desktop file already exists 553 * A file with the same name or a .desktop file already exists
558 */ 554 */
559 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { 555 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
560 int n=1; 556 int n=1;
561 QString nn; 557 QString nn;
562 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 558 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
563 || QFile::exists(nn+".desktop")) 559 || QFile::exists(nn+".desktop"))
564 n++; 560 n++;
565 that->mFile = nn; 561 that->mFile = nn;
566 } 562 }
567 that->mLinkFile = that->mFile+".desktop"; 563 that->mLinkFile = that->mFile+".desktop";
568 that->mFile += ext; 564 that->mFile += ext;
569 } 565 }
570 prepareDirectories(that->mFile); 566 prepareDirectories(that->mFile);
571 if ( !that->mFile.isEmpty() ) { 567 if ( !that->mFile.isEmpty() ) {
572 QFile f(that->mFile); 568 QFile f(that->mFile);
573 if ( !f.open(IO_WriteOnly) ) 569 if ( !f.open(IO_WriteOnly) )
574 that->mFile = QString::null; 570 that->mFile = QString::null;
575 return that->mFile; 571 return that->mFile;
576 } 572 }
577 } 573 }
578 return mFile; 574 return mFile;
579} 575}
580 576
581/*! 577/*!
582 Returns the desktop file corresponding to this AppLnk. 578 Returns the desktop file corresponding to this AppLnk.
583 579
584 \sa file() exec() name() 580 \sa file() exec() name()
585*/ 581*/
586QString AppLnk::linkFile() const 582QString AppLnk::linkFile() const
587{ 583{
588 if ( mLinkFile.isNull() ) { 584 if ( mLinkFile.isNull() ) {
589 AppLnk* that = (AppLnk*)this; 585 AppLnk* that = (AppLnk*)this;
590 if ( type().contains('/') ) { 586 if ( type().contains('/') ) {
591 StorageInfo storage; 587 StorageInfo storage;
592 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 588 const FileSystem *fs = storage.fileSystemOf( that->mFile );
593 /* tmpfs + and ramfs are available too but not removable 589 /* tmpfs + and ramfs are available too but not removable
594 * either we fix storage or add this 590 * either we fix storage or add this
595 */ 591 */
596 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { 592 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
597 that->mLinkFile = fs->path(); 593 that->mLinkFile = fs->path();
598 } else 594 } else
599 that->mLinkFile = getenv( "HOME" ); 595 that->mLinkFile = getenv( "HOME" );
600 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 596 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
601 597
602 /* the desktop file exists make sure we don't point to the same file */ 598 /* the desktop file exists make sure we don't point to the same file */
603 if ( QFile::exists(that->mLinkFile+".desktop") ) { 599 if ( QFile::exists(that->mLinkFile+".desktop") ) {
604 AppLnk lnk( that->mLinkFile + ".desktop" ); 600 AppLnk lnk( that->mLinkFile + ".desktop" );
605 601
606 /* the linked is different */ 602 /* the linked is different */
607 if(that->file() != lnk.file() ) { 603 if(that->file() != lnk.file() ) {
608 int n = 1; 604 int n = 1;
609 QString nn; 605 QString nn;
610 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { 606 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) {
611 n++; 607 n++;
612 /* just to be sure */ 608 /* just to be sure */
613 AppLnk lnk(nn ); 609 AppLnk lnk(nn );
614 if (lnk.file() == that->file() ) 610 if (lnk.file() == that->file() )
615 break; 611 break;
616 } 612 }
617 that->mLinkFile = nn; 613 that->mLinkFile = nn;
618 } 614 }
619 } 615 }
620 that->mLinkFile += ".desktop"; 616 that->mLinkFile += ".desktop";
621 storeLink(); 617 storeLink();
622 } 618 }
623 return that->mLinkFile; 619 return that->mLinkFile;
624 } 620 }
625 return mLinkFile; 621 return mLinkFile;
626} 622}
627 623
628/*! 624/*!
629 Copies \a copy. 625 Copies \a copy.
630*/ 626*/
631AppLnk::AppLnk( const AppLnk &copy ) 627AppLnk::AppLnk( const AppLnk &copy )
632{ 628{
633 mName = copy.mName; 629 mName = copy.mName;
634 mPixmap = copy.mPixmap; 630 mPixmap = copy.mPixmap;
635 mBigPixmap = copy.mBigPixmap; 631 mBigPixmap = copy.mBigPixmap;
636 mExec = copy.mExec; 632 mExec = copy.mExec;
637 mType = copy.mType; 633 mType = copy.mType;
638 mRotation = copy.mRotation; 634 mRotation = copy.mRotation;
639 mComment = copy.mComment; 635 mComment = copy.mComment;
640 mFile = copy.mFile; 636 mFile = copy.mFile;
641 mLinkFile = copy.mLinkFile; 637 mLinkFile = copy.mLinkFile;
642 mIconFile = copy.mIconFile; 638 mIconFile = copy.mIconFile;
643 mMimeTypes = copy.mMimeTypes; 639 mMimeTypes = copy.mMimeTypes;
644 mMimeTypeIcons = copy.mMimeTypeIcons; 640 mMimeTypeIcons = copy.mMimeTypeIcons;
645 mId = 0; 641 mId = 0;
646 d = new AppLnkPrivate(); 642 d = new AppLnkPrivate();
647 d->mCat = copy.d->mCat; 643 d->mCat = copy.d->mCat;
648 d->mCatList = copy.d->mCatList; 644 d->mCatList = copy.d->mCatList;
649 d->mPixmaps = copy.d->mPixmaps; 645 d->mPixmaps = copy.d->mPixmaps;
650} 646}
651 647
652/*! 648/*!
653 Destroys the AppLnk. Note that if the AppLnk is currently a member 649 Destroys the AppLnk. Note that if the AppLnk is currently a member
654 of an AppLnkSet, this will produce a run-time warning. 650 of an AppLnkSet, this will produce a run-time warning.
655 651
656 \sa AppLnkSet::add() AppLnkSet::remove() 652 \sa AppLnkSet::add() AppLnkSet::remove()
657*/ 653*/
658AppLnk::~AppLnk() 654AppLnk::~AppLnk()
659{ 655{
660 if ( mId ) 656 if ( mId )
661 qWarning("Deleting AppLnk that is in an AppLnkSet"); 657 qWarning("Deleting AppLnk that is in an AppLnkSet");
662 if ( d ) 658 if ( d )
663 delete d; 659 delete d;
664} 660}
665 661
666/*! 662/*!
667 \overload 663 \overload
668 Executes the application associated with this AppLnk. 664 Executes the application associated with this AppLnk.
669 665
670 \sa exec() 666 \sa exec()
671*/ 667*/
672void AppLnk::execute() const 668void AppLnk::execute() const
673{ 669{
674 execute(QStringList()); 670 execute(QStringList());
675} 671}
676 672
677/*! 673/*!
678 Executes the application associated with this AppLnk, with 674 Executes the application associated with this AppLnk, with
679 \a args as arguments. 675 \a args as arguments.
680 676
681 \sa exec() 677 \sa exec()
682*/ 678*/
683void AppLnk::execute(const QStringList& args) const 679void AppLnk::execute(const QStringList& args) const
684{ 680{
685#ifdef Q_WS_QWS 681#ifdef Q_WS_QWS
686 if ( !mRotation.isEmpty() ) { 682 if ( !mRotation.isEmpty() ) {
687 // ######## this will only work in the server 683 // ######## this will only work in the server
688 int rot = QPEApplication::defaultRotation(); 684 int rot = QPEApplication::defaultRotation();
689 rot = (rot+mRotation.toInt())%360; 685 rot = (rot+mRotation.toInt())%360;
690 QCString old = getenv("QWS_DISPLAY"); 686 QCString old = getenv("QWS_DISPLAY");
691 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 687 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
692 invoke(args); 688 invoke(args);
693 setenv("QWS_DISPLAY", old.data(), 1); 689 setenv("QWS_DISPLAY", old.data(), 1);
694 } else 690 } else
695#endif 691#endif
696 invoke(args); 692 invoke(args);
697} 693}
698 694
699/*! 695/*!
700 Invokes the application associated with this AppLnk, with 696 Invokes the application associated with this AppLnk, with
701 \a args as arguments. Rotation is not taken into account by 697 \a args as arguments. Rotation is not taken into account by
702 this function, so you should not call it directly. 698 this function, so you should not call it directly.
703 699
704 \sa execute() 700 \sa execute()
705*/ 701*/
706void AppLnk::invoke(const QStringList& args) const 702void AppLnk::invoke(const QStringList& args) const
707{ 703{
708 Global::execute( exec(), args[0] ); 704 Global::execute( exec(), args[0] );
709} 705}
710 706
711/*! 707/*!
712 Sets the Exec property to \a exec. 708 Sets the Exec property to \a exec.
713 709
714 \sa exec() name() 710 \sa exec() name()
715*/ 711*/
716void AppLnk::setExec( const QString& exec ) 712void AppLnk::setExec( const QString& exec )
717{ 713{
718 mExec = exec; 714 mExec = exec;
719} 715}
720 716
721#if 0 // this was inlined for better BC 717#if 0 // this was inlined for better BC
722/*! 718/*!
723 Sets the Rotation property to \a rot. 719 Sets the Rotation property to \a rot.
724 720
725 \sa rotation() 721 \sa rotation()
726*/ 722*/
727void AppLnk::setRotation ( const QString &rot ) 723void AppLnk::setRotation ( const QString &rot )
728{ 724{
729 mRotation = rot; 725 mRotation = rot;
730} 726}
731#endif 727#endif
732 728
733/*! 729/*!
734 Sets the Name property to \a docname. 730 Sets the Name property to \a docname.
735 731
736 \sa name() 732 \sa name()
737*/ 733*/
738void AppLnk::setName( const QString& docname ) 734void AppLnk::setName( const QString& docname )
739{ 735{
740 mName = docname; 736 mName = docname;
741} 737}
742 738
743/*! 739/*!
744 Sets the File property to \a filename. 740 Sets the File property to \a filename.
745 741
746 \sa file() name() 742 \sa file() name()
747*/ 743*/
748void AppLnk::setFile( const QString& filename ) 744void AppLnk::setFile( const QString& filename )
749{ 745{
750 mFile = filename; 746 mFile = filename;
751} 747}
752 748
753/*! 749/*!
754 Sets the LinkFile property to \a filename. 750 Sets the LinkFile property to \a filename.
755 751
756 \sa linkFile() 752 \sa linkFile()
757*/ 753*/
758void AppLnk::setLinkFile( const QString& filename ) 754void AppLnk::setLinkFile( const QString& filename )
759{ 755{
760 mLinkFile = filename; 756 mLinkFile = filename;
761} 757}
762 758
763/*! 759/*!
764 Sets the Comment property to \a comment. 760 Sets the Comment property to \a comment.
765 761
766 This text is displayed in the 'Details Dialog', for example if the 762 This text is displayed in the 'Details Dialog', for example if the
767 user uses the 'press-and-hold' gesture. 763 user uses the 'press-and-hold' gesture.
768 764
769 \sa comment() 765 \sa comment()
770*/ 766*/
771void AppLnk::setComment( const QString& comment ) 767void AppLnk::setComment( const QString& comment )
772{ 768{
773 mComment = comment; 769 mComment = comment;
774} 770}
775 771
776/*! 772/*!
777 Sets the Type property to \a type. 773 Sets the Type property to \a type.
778 774
779 For applications, games and settings the type should be \c 775 For applications, games and settings the type should be \c
780 Application; for documents the type should be the document's MIME 776 Application; for documents the type should be the document's MIME
781 type. 777 type.
782 778
783 \sa type() 779 \sa type()
784*/ 780*/
785void AppLnk::setType( const QString& type ) 781void AppLnk::setType( const QString& type )
786{ 782{
787 mType = type; 783 mType = type;
788} 784}
789 785
790/*! 786/*!
791 \fn QString AppLnk::icon() const 787 \fn QString AppLnk::icon() const
792 788
793 Returns the Icon property. 789 Returns the Icon property.
794 790
795 \sa setIcon() 791 \sa setIcon()
796*/ 792*/
797 793
798/*! 794/*!
799 Sets the Icon property to \a iconname. This is the filename from 795 Sets the Icon property to \a iconname. This is the filename from
800 which the pixmap() and bigPixmap() are obtained. 796 which the pixmap() and bigPixmap() are obtained.
801 797
802 \sa icon() setSmallIconSize() setBigIconSize() 798 \sa icon() setSmallIconSize() setBigIconSize()
803*/ 799*/
804void AppLnk::setIcon( const QString& iconname ) 800void AppLnk::setIcon( const QString& iconname )
805{ 801{
806 mIconFile = iconname; 802 mIconFile = iconname;
807 QImage unscaledIcon = Resource::loadImage( mIconFile ); 803 QImage unscaledIcon = Resource::loadImage( mIconFile );
808 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 804 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
809 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 805 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
810} 806}
811 807
812/*! 808/*!
813 Sets the Categories property to \a c. 809 Sets the Categories property to \a c.
814 810
815 See the CategoryWidget for more details. 811 See the CategoryWidget for more details.
816 812
817 \sa categories() 813 \sa categories()
818*/ 814*/
819void AppLnk::setCategories( const QArray<int>& c ) 815void AppLnk::setCategories( const QArray<int>& c )
820{ 816{
821 d->mCat = c; 817 d->mCat = c;
822 d->updateCatListFromArray(); 818 d->updateCatListFromArray();
823} 819}
824 820
825/*! 821/*!
826 \fn QStringList AppLnk::mimeTypeIcons() const 822 \fn QStringList AppLnk::mimeTypeIcons() const
827 823
828 Returns the MimeTypeIcons property of the AppLnk. 824 Returns the MimeTypeIcons property of the AppLnk.
829*/ 825*/
830 826
831/*! 827/*!
832 Attempts to ensure that the link file for this AppLnk exists, 828 Attempts to ensure that the link file for this AppLnk exists,
833 including creating any required directories. Returns TRUE if 829 including creating any required directories. Returns TRUE if
834 successful; otherwise returns FALSE. 830 successful; otherwise returns FALSE.
835 831
836 You should not need to use this function. 832 You should not need to use this function.
837*/ 833*/
838bool AppLnk::ensureLinkExists() const 834bool AppLnk::ensureLinkExists() const
839{ 835{
840 QString lf = linkFile(); 836 QString lf = linkFile();
841 return prepareDirectories(lf); 837 return prepareDirectories(lf);
842} 838}
843 839
844/*! 840/*!
845 Commits the AppLnk to disk. Returns TRUE if the operation succeeded; 841 Commits the AppLnk to disk. Returns TRUE if the operation succeeded;
846 otherwise returns FALSE. 842 otherwise returns FALSE.
847 843
848 In addition, the "linkChanged(QString)" message is sent to the 844 In addition, the "linkChanged(QString)" message is sent to the
849 "QPE/System" \link qcop.html QCop\endlink channel. 845 "QPE/System" \link qcop.html QCop\endlink channel.
850*/ 846*/
851bool AppLnk::writeLink() const 847bool AppLnk::writeLink() const
852{ 848{
853 // Only re-writes settable parts 849 // Only re-writes settable parts
854 QString lf = linkFile(); 850 QString lf = linkFile();
855 if ( !ensureLinkExists() ) 851 if ( !ensureLinkExists() )
856 return FALSE; 852 return FALSE;
857 storeLink(); 853 storeLink();
858 return TRUE; 854 return TRUE;
859} 855}
860 856
861/*! 857/*!
862 \internal 858 \internal
863*/ 859*/
864void AppLnk::storeLink() const 860void AppLnk::storeLink() const
865{ 861{
866 Config config( mLinkFile, Config::File ); 862 Config config( mLinkFile, Config::File );
867 config.setGroup("Desktop Entry"); 863 config.setGroup("Desktop Entry");
868 config.writeEntry("Name",mName); 864 config.writeEntry("Name",mName);
869 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 865 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
870 config.writeEntry("Type",type()); 866 config.writeEntry("Type",type());
871 if(!rotation().isEmpty()) 867 if(!rotation().isEmpty())
872 config.writeEntry("Rotation",rotation()); 868 config.writeEntry("Rotation",rotation());
873 else 869 else
874 config.removeEntry("Rotation"); 870 config.removeEntry("Rotation");
875 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 871 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
876 QString f = file(); 872 QString f = file();
877 int i = 0; 873 int i = 0;
878 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) 874 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
879 i++; 875 i++;
880 while ( i && f[i] != '/' ) 876 while ( i && f[i] != '/' )
881 i--; 877 i--;
882 // simple case where in the same directory 878 // simple case where in the same directory
883 if ( mLinkFile.find( '/', i + 1 ) < 0 ) 879 if ( mLinkFile.find( '/', i + 1 ) < 0 )
884 f = f.mid(i+1); 880 f = f.mid(i+1);
885 // ### could do relative ie ../../otherDocs/file.doc 881 // ### could do relative ie ../../otherDocs/file.doc
886 config.writeEntry("File",f); 882 config.writeEntry("File",f);
887 config.writeEntry( "Categories", d->mCatList, ';' ); 883 config.writeEntry( "Categories", d->mCatList, ';' );
888 884
889#ifndef QT_NO_COP 885#ifndef QT_NO_COP
890 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 886 QCopEnvelope e("QPE/System", "linkChanged(QString)");
891 e << mLinkFile; 887 e << mLinkFile;
892#endif 888#endif
893} 889}
894 890
895/*! 891/*!
896 Sets the property named \a key to \a value. 892 Sets the property named \a key to \a value.
897 893
898 \sa property() 894 \sa property()
899*/ 895*/
900void AppLnk::setProperty(const QString& key, const QString& value) 896void AppLnk::setProperty(const QString& key, const QString& value)
901{ 897{
902 if ( ensureLinkExists() ) { 898 if ( ensureLinkExists() ) {
903 Config cfg(linkFile(), Config::File); 899 Config cfg(linkFile(), Config::File);
904 cfg.writeEntry(key,value); 900 cfg.writeEntry(key,value);
905 } 901 }
906} 902}
907 903
908/*! 904/*!
909 Returns the property named \a key. 905 Returns the property named \a key.
910 906
911 \sa setProperty() 907 \sa setProperty()
912*/ 908*/
913QString AppLnk::property(const QString& key) const 909QString AppLnk::property(const QString& key) const
914{ 910{
915 QString lf = linkFile(); 911 QString lf = linkFile();
916 if ( !QFile::exists(lf) ) 912 if ( !QFile::exists(lf) )
917 return QString::null; 913 return QString::null;
918 Config cfg(lf, Config::File); 914 Config cfg(lf, Config::File);
919 return cfg.readEntry(key); 915 return cfg.readEntry(key);
920} 916}
921 917
922bool AppLnk::isPreloaded() const { 918bool AppLnk::isPreloaded() const {
923 // Preload information is stored in the Launcher config in v1.5. 919 // Preload information is stored in the Launcher config in v1.5.
924 Config cfg("Launcher"); 920 Config cfg("Launcher");
925 cfg.setGroup("Preload"); 921 cfg.setGroup("Preload");
926 QStringList apps = cfg.readListEntry("Apps",','); 922 QStringList apps = cfg.readListEntry("Apps",',');
927 if (apps.contains(exec())) 923 if (apps.contains(exec()))
928 return true; 924 return true;
929 return false; 925 return false;
930} 926}
931 927
932void AppLnk::setPreloaded(bool yesNo) { 928void AppLnk::setPreloaded(bool yesNo) {
933 // Preload information is stored in the Launcher config in v1.5. 929 // Preload information is stored in the Launcher config in v1.5.
934 Config cfg("Launcher"); 930 Config cfg("Launcher");
935 cfg.setGroup("Preload"); 931 cfg.setGroup("Preload");
936 QStringList apps = cfg.readListEntry("Apps", ','); 932 QStringList apps = cfg.readListEntry("Apps", ',');
937 if (apps.contains(exec()) && !yesNo) 933 if (apps.contains(exec()) && !yesNo)
938 apps.remove(exec()); 934 apps.remove(exec());
939 else if (yesNo && !apps.contains(exec())) 935 else if (yesNo && !apps.contains(exec()))
940 apps.append(exec()); 936 apps.append(exec());
941 cfg.writeEntry("Apps", apps, ','); 937 cfg.writeEntry("Apps", apps, ',');
942} 938}
943 939
944 940
945/*! 941/*!
946 Deletes both the linkFile() and the file() associated with this AppLnk. 942 Deletes both the linkFile() and the file() associated with this AppLnk.
947 943
948 \sa removeLinkFile() 944 \sa removeLinkFile()
949*/ 945*/
950void AppLnk::removeFiles() 946void AppLnk::removeFiles()
951{ 947{
952 bool valid = isValid(); 948 bool valid = isValid();
953 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 949 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
954 if ( QFile::remove(file()) ) { 950 if ( QFile::remove(file()) ) {
955#ifndef QT_NO_COP 951#ifndef QT_NO_COP
956 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 952 QCopEnvelope e("QPE/System", "linkChanged(QString)");
957 if ( linkFileKnown() ) 953 if ( linkFileKnown() )
958 e << linkFile(); 954 e << linkFile();
959 else 955 else
960 e << file(); 956 e << file();
961#endif 957#endif
962 } else if ( valid ) { 958 } else if ( valid ) {
963 // restore link 959 // restore link
964 writeLink(); 960 writeLink();
965 } 961 }
966 } 962 }
967} 963}
968 964
969/*! 965/*!
970 Deletes the linkFile(), leaving any file() untouched. 966 Deletes the linkFile(), leaving any file() untouched.
971 967
972 \sa removeFiles() 968 \sa removeFiles()
973*/ 969*/
974void AppLnk::removeLinkFile() 970void AppLnk::removeLinkFile()
975{ 971{
976 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 972 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
977#ifndef QT_NO_COP 973#ifndef QT_NO_COP
978 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 974 QCopEnvelope e("QPE/System", "linkChanged(QString)");
979 e << linkFile(); 975 e << linkFile();
980#endif 976#endif
981 } 977 }
982} 978}
983 979
984class AppLnkSetPrivate { 980class AppLnkSetPrivate {
985public: 981public:
986 AppLnkSetPrivate() 982 AppLnkSetPrivate()
987 { 983 {
988 typPix.setAutoDelete(TRUE); 984 typPix.setAutoDelete(TRUE);
989 typPixBig.setAutoDelete(TRUE); 985 typPixBig.setAutoDelete(TRUE);
990 typName.setAutoDelete(TRUE); 986 typName.setAutoDelete(TRUE);
991 } 987 }
992 988
993 QDict<QPixmap> typPix; 989 QDict<QPixmap> typPix;
994 QDict<QPixmap> typPixBig; 990 QDict<QPixmap> typPixBig;
995 QDict<QString> typName; 991 QDict<QString> typName;
996}; 992};
997 993
998/*! 994/*!
999 \class AppLnkSet applnk.h 995 \class AppLnkSet applnk.h
1000 \brief The AppLnkSet class is a set of AppLnk objects. 996 \brief The AppLnkSet class is a set of AppLnk objects.
1001*/ 997*/
1002 998
1003/*! 999/*!
1004 \fn QStringList AppLnkSet::types() const 1000 \fn QStringList AppLnkSet::types() const
1005 1001
1006 Returns the list of \link applnk.html#Types types\endlink in the set. 1002 Returns the list of \link applnk.html#Types types\endlink in the set.
1007 1003
1008 For applications, games and settings the type is \c Application; 1004 For applications, games and settings the type is \c Application;
1009 for documents the type is the document's MIME type. 1005 for documents the type is the document's MIME type.
1010 1006
1011 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() 1007 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
1012*/ 1008*/
1013 1009
1014/*! 1010/*!
1015 \fn const QList<AppLnk>& AppLnkSet::children() const 1011 \fn const QList<AppLnk>& AppLnkSet::children() const
1016 1012
1017 Returns the members of the set. 1013 Returns the members of the set.
1018*/ 1014*/
1019 1015
1020/*! 1016/*!
1021 Constructs an empty AppLnkSet. 1017 Constructs an empty AppLnkSet.
1022*/ 1018*/
1023AppLnkSet::AppLnkSet() : 1019AppLnkSet::AppLnkSet() :
1024 d(new AppLnkSetPrivate) 1020 d(new AppLnkSetPrivate)
1025{ 1021{
1026} 1022}
1027 1023
1028/*! 1024/*!
1029 Constructs an AppLnkSet that contains AppLnk objects representing 1025 Constructs an AppLnkSet that contains AppLnk objects representing
1030 all the files in the given \a directory (and any subdirectories 1026 all the files in the given \a directory (and any subdirectories
1031 recursively). 1027 recursively).
1032 1028
1033 \omit 1029 \omit
1034 The directories may contain ".directory" files which override 1030 The directories may contain ".directory" files which override
1035 any AppLnk::type() values for AppLnk objects found in the directory. 1031 any AppLnk::type() values for AppLnk objects found in the directory.
1036 This allows simple localization of application types. 1032 This allows simple localization of application types.
1037 \endomit 1033 \endomit
1038*/ 1034*/
1039AppLnkSet::AppLnkSet( const QString &directory ) : 1035AppLnkSet::AppLnkSet( const QString &directory ) :
1040 d(new AppLnkSetPrivate) 1036 d(new AppLnkSetPrivate)
1041{ 1037{
1042 QDir dir( directory ); 1038 QDir dir( directory );
1043 mFile = directory; 1039 mFile = directory;
1044 findChildren(directory,QString::null,QString::null); 1040 findChildren(directory,QString::null,QString::null);
1045} 1041}
1046 1042
1047/*! 1043/*!
1048 Detaches all AppLnk objects from the set. The set become empty and 1044 Detaches all AppLnk objects from the set. The set become empty and
1049 the caller becomes responsible for deleting the AppLnk objects. 1045 the caller becomes responsible for deleting the AppLnk objects.
1050*/ 1046*/
1051void AppLnkSet::detachChildren() 1047void AppLnkSet::detachChildren()
1052{ 1048{
1053 QListIterator<AppLnk> it( mApps ); 1049 QListIterator<AppLnk> it( mApps );
1054 for ( ; it.current(); ) { 1050 for ( ; it.current(); ) {
1055 AppLnk* a = *it; 1051 AppLnk* a = *it;
1056 ++it; 1052 ++it;
1057 a->mId = 0; 1053 a->mId = 0;
1058 } 1054 }
1059 mApps.clear(); 1055 mApps.clear();
1060} 1056}
1061 1057
1062/*! 1058/*!
1063 Destroys the set, deleting all the AppLnk objects it contains. 1059 Destroys the set, deleting all the AppLnk objects it contains.
1064 1060
1065 \sa detachChildren() 1061 \sa detachChildren()
1066*/ 1062*/
1067AppLnkSet::~AppLnkSet() 1063AppLnkSet::~AppLnkSet()
1068{ 1064{
1069 QListIterator<AppLnk> it( mApps ); 1065 QListIterator<AppLnk> it( mApps );
1070 for ( ; it.current(); ) { 1066 for ( ; it.current(); ) {
1071 AppLnk* a = *it; 1067 AppLnk* a = *it;
1072 ++it; 1068 ++it;
1073 a->mId = 0; 1069 a->mId = 0;
1074 delete a; 1070 delete a;
1075 } 1071 }
1076 delete d; 1072 delete d;
1077} 1073}
1078 1074
1079void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) 1075void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
1080{ 1076{
1081 depth++; 1077 depth++;
1082 if ( depth > 10 ) 1078 if ( depth > 10 )
1083 return; 1079 return;
1084 1080
1085 QDir dir( dr ); 1081 QDir dir( dr );
1086 QString typNameLocal = typName; 1082 QString typNameLocal = typName;
1087 1083
1088 if ( dir.exists( ".directory" ) ) { 1084 if ( dir.exists( ".directory" ) ) {
1089 Config config( dr + "/.directory", Config::File ); 1085 Config config( dr + "/.directory", Config::File );
1090 config.setGroup( "Desktop Entry" ); 1086 config.setGroup( "Desktop Entry" );
1091 typNameLocal = config.readEntry( "Name", typNameLocal ); 1087 typNameLocal = config.readEntry( "Name", typNameLocal );
1092 if ( !typ.isEmpty() ) { 1088 if ( !typ.isEmpty() ) {
1093 QString iconFile = config.readEntry( "Icon", "AppsIcon" ); 1089 QString iconFile = config.readEntry( "Icon", "AppsIcon" );
1094 QImage unscaledIcon = Resource::loadImage( iconFile ); 1090 QImage unscaledIcon = Resource::loadImage( iconFile );
1095 QPixmap pm, bpm; 1091 QPixmap pm, bpm;
1096 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 1092 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
1097 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 1093 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
1098 d->typPix.insert(typ, new QPixmap(pm)); 1094 d->typPix.insert(typ, new QPixmap(pm));
1099 d->typPixBig.insert(typ, new QPixmap(bpm)); 1095 d->typPixBig.insert(typ, new QPixmap(bpm));
1100 d->typName.insert(typ, new QString(typNameLocal)); 1096 d->typName.insert(typ, new QString(typNameLocal));
1101 } 1097 }
1102 } 1098 }
1103 1099
1104 const QFileInfoList *list = dir.entryInfoList(); 1100 const QFileInfoList *list = dir.entryInfoList();
1105 if ( list ) { 1101 if ( list ) {
1106 QFileInfo* fi; 1102 QFileInfo* fi;
1107 bool cadded=FALSE; 1103 bool cadded=FALSE;
1108 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1104 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1109 QString bn = fi->fileName(); 1105 QString bn = fi->fileName();
1110// qDebug("findChildren "+bn); 1106// qDebug("findChildren "+bn);
1111 if ( bn[0] != '.' && bn != "CVS" ) { 1107 if ( bn[0] != '.' && bn != "CVS" ) {
1112 if ( fi->isDir() ) { 1108 if ( fi->isDir() ) {
1113 QString c = typ.isNull() ? bn : typ+"/"+bn; 1109 QString c = typ.isNull() ? bn : typ+"/"+bn;
1114 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; 1110 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
1115 findChildren(fi->filePath(), c, d, depth ); 1111 findChildren(fi->filePath(), c, d, depth );
1116 } else { 1112 } else {
1117 if ( fi->extension(FALSE) == "desktop" ) { 1113 if ( fi->extension(FALSE) == "desktop" ) {
1118 AppLnk* app = new AppLnk( fi->filePath() ); 1114 AppLnk* app = new AppLnk( fi->filePath() );
1119#ifdef QT_NO_QWS_MULTIPROCESS 1115#ifdef QT_NO_QWS_MULTIPROCESS
1120 if ( !Global::isBuiltinCommand( app->exec() ) ) 1116 if ( !Global::isBuiltinCommand( app->exec() ) )
1121 delete app; 1117 delete app;
1122 else 1118 else
1123#endif 1119#endif
1124 { 1120 {
1125 if ( !typ.isEmpty() ) { 1121 if ( !typ.isEmpty() ) {
1126 if ( !cadded ) { 1122 if ( !cadded ) {
1127 typs.append(typ); 1123 typs.append(typ);
1128 cadded = TRUE; 1124 cadded = TRUE;
1129 } 1125 }
1130 app->setType(typ); 1126 app->setType(typ);
1131 } 1127 }
1132 add(app); 1128 add(app);
1133 } 1129 }
1134 } 1130 }
1135 } 1131 }
1136 } 1132 }
1137 } 1133 }
1138 } 1134 }
1139} 1135}
1140 1136
1141/*! 1137/*!
1142 Adds AppLnk \a f to the set. The set takes responsibility for 1138 Adds AppLnk \a f to the set. The set takes responsibility for
1143 deleting \a f. 1139 deleting \a f.
1144 1140
1145 \sa remove() 1141 \sa remove()
1146*/ 1142*/
1147void AppLnkSet::add( AppLnk *f ) 1143void AppLnkSet::add( AppLnk *f )
1148{ 1144{
1149 if ( f->mId == 0 ) { 1145 if ( f->mId == 0 ) {
1150 AppLnk::lastId++; 1146 AppLnk::lastId++;
1151 f->mId = AppLnk::lastId; 1147 f->mId = AppLnk::lastId;
1152 mApps.append( f ); 1148 mApps.append( f );
1153 } else { 1149 } else {
1154 qWarning("Attempt to add an AppLnk twice"); 1150 qWarning("Attempt to add an AppLnk twice");
1155 } 1151 }
1156} 1152}
1157 1153
1158/*! 1154/*!
1159 Removes AppLnk \a f to the set. The caller becomes responsible for 1155 Removes AppLnk \a f to the set. The caller becomes responsible for
1160 deleting \a f. Returns TRUE if \a f was in the set; otherwise 1156 deleting \a f. Returns TRUE if \a f was in the set; otherwise
1161 returns FALSE. 1157 returns FALSE.
1162 1158
1163 \sa add() 1159 \sa add()
1164*/ 1160*/
1165bool AppLnkSet::remove( AppLnk *f ) 1161bool AppLnkSet::remove( AppLnk *f )
1166{ 1162{
1167 if ( mApps.remove( f ) ) { 1163 if ( mApps.remove( f ) ) {
1168 f->mId = 0; 1164 f->mId = 0;
1169 return TRUE; 1165 return TRUE;
1170 } 1166 }
1171 return FALSE; 1167 return FALSE;
1172} 1168}
1173 1169
1174 1170
1175/*! 1171/*!
1176 Returns the localized name for type \a t. 1172 Returns the localized name for type \a t.
1177 1173
1178 For applications, games and settings the type is \c Application; 1174 For applications, games and settings the type is \c Application;
1179 for documents the type is the document's MIME type. 1175 for documents the type is the document's MIME type.
1180*/ 1176*/
1181QString AppLnkSet::typeName( const QString& t ) const 1177QString AppLnkSet::typeName( const QString& t ) const
1182{ 1178{
1183 QString *st = d->typName.find(t); 1179 QString *st = d->typName.find(t);
1184 return st ? *st : QString::null; 1180 return st ? *st : QString::null;
1185} 1181}
1186 1182
1187/*! 1183/*!
1188 Returns the small pixmap associated with type \a t. 1184 Returns the small pixmap associated with type \a t.
1189 1185
1190 For applications, games and settings the type is \c Application; 1186 For applications, games and settings the type is \c Application;
1191 for documents the type is the document's MIME type. 1187 for documents the type is the document's MIME type.
1192*/ 1188*/
1193QPixmap AppLnkSet::typePixmap( const QString& t ) const 1189QPixmap AppLnkSet::typePixmap( const QString& t ) const
1194{ 1190{
1195 QPixmap *pm = d->typPix.find(t); 1191 QPixmap *pm = d->typPix.find(t);
1196 return pm ? *pm : QPixmap(); 1192 return pm ? *pm : QPixmap();
1197} 1193}
1198 1194
1199/*! 1195/*!
1200 Returns the large pixmap associated with type \a t. 1196 Returns the large pixmap associated with type \a t.
1201 1197
1202 For applications, games and settings the type is \c Application; 1198 For applications, games and settings the type is \c Application;
1203 for documents the type is the document's MIME type. 1199 for documents the type is the document's MIME type.
1204*/ 1200*/
1205QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const 1201QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
1206{ 1202{
1207 QPixmap *pm = d->typPixBig.find(t); 1203 QPixmap *pm = d->typPixBig.find(t);
1208 return pm ? *pm : QPixmap(); 1204 return pm ? *pm : QPixmap();
1209} 1205}
1210 1206
1211/*! 1207/*!
1212 Returns the AppLnk with the given \a id. 1208 Returns the AppLnk with the given \a id.
1213*/ 1209*/
1214const AppLnk *AppLnkSet::find( int id ) const 1210const AppLnk *AppLnkSet::find( int id ) const
1215{ 1211{
1216 QListIterator<AppLnk> it( children() ); 1212 QListIterator<AppLnk> it( children() );
1217 1213
1218 for ( ; it.current(); ++it ) { 1214 for ( ; it.current(); ++it ) {
1219 const AppLnk *app = it.current(); 1215 const AppLnk *app = it.current();
1220 if ( app->id() == id ) 1216 if ( app->id() == id )
1221 return app; 1217 return app;
1222 } 1218 }
1223 1219
1224 return 0; 1220 return 0;
1225} 1221}
1226 1222
1227/*! 1223/*!
1228 Returns the AppLnk with the given \a exec attribute. 1224 Returns the AppLnk with the given \a exec attribute.
1229*/ 1225*/
1230const AppLnk *AppLnkSet::findExec( const QString& exec ) const 1226const AppLnk *AppLnkSet::findExec( const QString& exec ) const
1231{ 1227{
1232 QListIterator<AppLnk> it( children() ); 1228 QListIterator<AppLnk> it( children() );
1233 1229
1234 for ( ; it.current(); ++it ) { 1230 for ( ; it.current(); ++it ) {
1235 const AppLnk *app = it.current(); 1231 const AppLnk *app = it.current();
1236 if ( app->exec() == exec ) 1232 if ( app->exec() == exec )
1237 return app; 1233 return app;
1238 } 1234 }
1239 1235
1240 return 0; 1236 return 0;
1241} 1237}
1242 1238
1243/*! 1239/*!
1244 \class DocLnkSet applnk.h 1240 \class DocLnkSet applnk.h
1245 \brief The DocLnkSet class is a set of DocLnk objects. 1241 \brief The DocLnkSet class is a set of DocLnk objects.
1246*/ 1242*/
1247 1243
1248/*! 1244/*!
1249 \fn const QList<DocLnk>& DocLnkSet::children() const 1245 \fn const QList<DocLnk>& DocLnkSet::children() const
1250 1246
1251 Returns the members of the set. 1247 Returns the members of the set.
1252*/ 1248*/
1253 1249
1254/*! 1250/*!
1255 Constructs an empty DocLnkSet. 1251 Constructs an empty DocLnkSet.
1256 1252
1257 \sa appendFrom() 1253 \sa appendFrom()
1258*/ 1254*/
1259DocLnkSet::DocLnkSet() 1255DocLnkSet::DocLnkSet()
1260{ 1256{
1261} 1257}
1262 1258
1263/*! 1259/*!
1264 Constructs a DocLnkSet that contains DocLnk objects representing all 1260 Constructs a DocLnkSet that contains DocLnk objects representing all
1265 the files in the \a directory (and any subdirectories, recursively). 1261 the files in the \a directory (and any subdirectories, recursively).
1266 1262
1267 If \a mimefilter is not null, 1263 If \a mimefilter is not null,
1268 only documents with a MIME type matching \a mimefilter are selected. 1264 only documents with a MIME type matching \a mimefilter are selected.
1269 The value may contain multiple wild-card patterns separated by ";", 1265 The value may contain multiple wild-card patterns separated by ";",
1270 such as \c{*o/mpeg;audio/x-wav}. 1266 such as \c{*o/mpeg;audio/x-wav}.
1271 1267
1272 See also \link applnk.html#files-and-links Files and Links\endlink. 1268 See also \link applnk.html#files-and-links Files and Links\endlink.
1273 1269
1274*/ 1270*/
1275DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : 1271DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
1276 AppLnkSet() 1272 AppLnkSet()
1277{ 1273{
1278 QDir dir( directory ); 1274 QDir dir( directory );
1279 mFile = dir.dirName(); 1275 mFile = dir.dirName();
1280 QDict<void> reference; 1276 QDict<void> reference;
1281 1277
1282 QStringList subFilter = QStringList::split(";", mimefilter); 1278 QStringList subFilter = QStringList::split(";", mimefilter);
1283 QValueList<QRegExp> mimeFilters; 1279 QValueList<QRegExp> mimeFilters;
1284 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) 1280 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
1285 mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 1281 mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
1286 1282
1287 findChildren(directory, mimeFilters, reference); 1283 findChildren(directory, mimeFilters, reference);
1288 1284
1289 const QList<DocLnk> &list = children(); 1285 const QList<DocLnk> &list = children();
1290 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 1286 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
1291 reference.remove( (*it)->file() ); 1287 reference.remove( (*it)->file() );
1292 } 1288 }
1293 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { 1289 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
1294 if ( dit.current() == (void*)2 ) { 1290 if ( dit.current() == (void*)2 ) {
1295 // Unreferenced, make an unwritten link 1291 // Unreferenced, make an unwritten link
1296 DocLnk* dl = new DocLnk; 1292 DocLnk* dl = new DocLnk;
1297 QFileInfo fi( dit.currentKey() ); 1293 QFileInfo fi( dit.currentKey() );
1298 dl->setFile(fi.filePath()); 1294 dl->setFile(fi.filePath());
1299 dl->setName(fi.baseName()); 1295 dl->setName(fi.baseName());
1300 // #### default to current path? 1296 // #### default to current path?
1301 // dl->setCategories( ... ); 1297 // dl->setCategories( ... );
1302 bool match = mimefilter.isNull(); 1298 bool match = mimefilter.isNull();
1303 if ( !match ) 1299 if ( !match )
1304 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) 1300 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
1305 if ( (*it).match(dl->type()) >= 0 ) 1301 if ( (*it).match(dl->type()) >= 0 )
1306 match = TRUE; 1302 match = TRUE;
1307 if ( match /* && dl->type() != "application/octet-stream" */ 1303 if ( match /* && dl->type() != "application/octet-stream" */
1308 && !!dl->exec() ) 1304 && !!dl->exec() )
1309 add(dl); 1305 add(dl);
1310 else 1306 else
1311 delete dl; 1307 delete dl;
1312 } 1308 }
1313 } 1309 }
1314} 1310}
1315 1311
1316// other becomes empty 1312// other becomes empty
1317/*! 1313/*!
1318 Transfers all DocLnk objects from \a other to this set. \a other becomes 1314 Transfers all DocLnk objects from \a other to this set. \a other becomes
1319 empty. 1315 empty.
1320*/ 1316*/
1321void DocLnkSet::appendFrom( DocLnkSet& other ) 1317void DocLnkSet::appendFrom( DocLnkSet& other )
1322{ 1318{
1323 if ( &other == this ) 1319 if ( &other == this )
1324 return; 1320 return;
1325 QListIterator<AppLnk> it( other.mApps ); 1321 QListIterator<AppLnk> it( other.mApps );
1326 for ( ; it.current(); ) { 1322 for ( ; it.current(); ) {
1327 mApps.append(*it); 1323 mApps.append(*it);
1328 ++it; 1324 ++it;
1329 } 1325 }
1330 other.mApps.clear(); 1326 other.mApps.clear();
1331} 1327}
1332 1328
1333void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) 1329void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
1334{ 1330{
1335 depth++; 1331 depth++;
1336 if ( depth > 10 ) 1332 if ( depth > 10 )
1337 return; 1333 return;
1338 1334
1339 QDir dir( dr ); 1335 QDir dir( dr );
1340 1336
1341 /* Opie got a different approach 1337 /* Opie got a different approach
1342 * I guess it's geek vs. consumer 1338 * I guess it's geek vs. consumer
1343 * in this case to be discussed 1339 * in this case to be discussed
1344 */ 1340 */
1345 if ( dir.exists( ".Qtopia-ignore" ) ) 1341 if ( dir.exists( ".Qtopia-ignore" ) )
1346 return; 1342 return;
1347 1343
1348 const QFileInfoList *list = dir.entryInfoList(); 1344 const QFileInfoList *list = dir.entryInfoList();
1349 if ( list ) { 1345 if ( list ) {
1350 QFileInfo* fi; 1346 QFileInfo* fi;
1351 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1347 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1352 QString bn = fi->fileName(); 1348 QString bn = fi->fileName();
1353 if ( bn[0] != '.' ) { 1349 if ( bn[0] != '.' ) {
1354 if ( fi->isDir() ) { 1350 if ( fi->isDir() ) {
1355 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) 1351 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
1356 findChildren(fi->filePath(), mimeFilters, reference, depth); 1352 findChildren(fi->filePath(), mimeFilters, reference, depth);
1357 } else { 1353 } else {
1358 if ( fi->extension(FALSE) == "desktop" ) { 1354 if ( fi->extension(FALSE) == "desktop" ) {
1359 DocLnk* dl = new DocLnk( fi->filePath() ); 1355 DocLnk* dl = new DocLnk( fi->filePath() );
1360 QFileInfo fi2(dl->file()); 1356 QFileInfo fi2(dl->file());
1361 bool match = FALSE; 1357 bool match = FALSE;
1362 if ( !fi2.exists() ) { 1358 if ( !fi2.exists() ) {
1363 dir.remove( dl->file() ); 1359 dir.remove( dl->file() );
1364 } 1360 }
1365 if ( mimeFilters.count() == 0 ) { 1361 if ( mimeFilters.count() == 0 ) {
1366 add( dl ); 1362 add( dl );
1367 match = TRUE; 1363 match = TRUE;
1368 } else { 1364 } else {
1369 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { 1365 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
1370 if ( (*it).match(dl->type()) >= 0 ) { 1366 if ( (*it).match(dl->type()) >= 0 ) {
1371 add(dl); 1367 add(dl);
1372 match = TRUE; 1368 match = TRUE;
1373 } 1369 }
1374 } 1370 }
1375 } 1371 }
1376 if ( !match ) 1372 if ( !match )
1377 delete dl; 1373 delete dl;
1378 } else { 1374 } else {
1379 if ( !reference.find(fi->fileName()) ) 1375 if ( !reference.find(fi->fileName()) )
1380 reference.insert(fi->filePath(), (void*)2); 1376 reference.insert(fi->filePath(), (void*)2);
1381 } 1377 }
1382 } 1378 }
1383 } 1379 }
1384 } 1380 }
1385 } 1381 }
1386} 1382}
1387 1383
1388/*! 1384/*!
1389 \class DocLnk applnk.h 1385 \class DocLnk applnk.h
1390 \brief The DocLnk class represents loaded document references. 1386 \brief The DocLnk class represents loaded document references.
1391*/ 1387*/
1392 1388
1393/*! 1389/*!
1394 \fn DocLnk::DocLnk( const DocLnk &o ) 1390 \fn DocLnk::DocLnk( const DocLnk &o )
1395 1391
1396 Copies \a o. 1392 Copies \a o.
1397*/ 1393*/
1398 1394
1399/*! 1395/*!
1400 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1396 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1401 \a file for other files. 1397 \a file for other files.
1402*/ 1398*/
1403DocLnk::DocLnk( const QString &file ) : 1399DocLnk::DocLnk( const QString &file ) :
1404 AppLnk(file) 1400 AppLnk(file)
1405{ 1401{
1406 init(file); 1402 init(file);
1407} 1403}
1408 1404
1409/*! 1405/*!
1410 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1406 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1411 \a file for other files. If \a may_be_desktopfile is TRUE, then an 1407 \a file for other files. If \a may_be_desktopfile is TRUE, then an
1412 attempt is made to read \a file as a .desktop file; if that fails it 1408 attempt is made to read \a file as a .desktop file; if that fails it
1413 is read as a normal file. 1409 is read as a normal file.
1414*/ 1410*/
1415DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : 1411DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) :
1416 AppLnk(may_be_desktopfile ? file : QString::null) 1412 AppLnk(may_be_desktopfile ? file : QString::null)
1417{ 1413{
1418 init(file); 1414 init(file);
1419} 1415}
1420 1416
1421void DocLnk::init(const QString &file) 1417void DocLnk::init(const QString &file)
1422{ 1418{
1423 if ( isValid() ) { 1419 if ( isValid() ) {
1424#ifndef FORCED_DIR_STRUCTURE_WAY 1420#ifndef FORCED_DIR_STRUCTURE_WAY
1425 if ( mType.isNull() ) 1421 if ( mType.isNull() )
1426 // try to infer it 1422 // try to infer it
1427#endif 1423#endif
1428 { 1424 {
1429 int s0 = file.findRev('/'); 1425 int s0 = file.findRev('/');
1430 if ( s0 > 0 ) { 1426 if ( s0 > 0 ) {
1431 int s1 = file.findRev('/',s0-1); 1427 int s1 = file.findRev('/',s0-1);
1432 if ( s1 > 0 ) { 1428 if ( s1 > 0 ) {
1433 int s2 = file.findRev('/',s1-1); 1429 int s2 = file.findRev('/',s1-1);
1434 if ( s2 > 0 ) { 1430 if ( s2 > 0 ) {
1435 mType = file.mid(s2+1,s0-s2-1); 1431 mType = file.mid(s2+1,s0-s2-1);
1436 } 1432 }
1437 } 1433 }
1438 } 1434 }
1439 } 1435 }
1440 } else if ( QFile::exists(file) ) { 1436 } else if ( QFile::exists(file) ) {
1441 QString n = file; 1437 QString n = file;
1442 n.replace(QRegExp(".*/"),""); 1438 n.replace(QRegExp(".*/"),"");
1443 n.replace(QRegExp("\\..*"),""); 1439 n.replace(QRegExp("\\..*"),"");
1444 setName( n ); 1440 setName( n );
1445 setFile( file ); 1441 setFile( file );
1446 } 1442 }
1447 MimeType mt(mType); 1443 MimeType mt(mType);
1448 if( mt.application() ) 1444 if( mt.application() )
1449 mExec = mt.application()->exec(); 1445 mExec = mt.application()->exec();
1450} 1446}
1451 1447
1452/*! 1448/*!
1453 Constructs an invalid DocLnk. 1449 Constructs an invalid DocLnk.
1454*/ 1450*/
1455DocLnk::DocLnk() 1451DocLnk::DocLnk()
1456{ 1452{
1457} 1453}
1458 1454
1459/*! 1455/*!
1460 Destroys the DocLnk. Just like AppLnk objects, a run-time error 1456 Destroys the DocLnk. Just like AppLnk objects, a run-time error
1461 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). 1457 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet).
1462*/ 1458*/
1463DocLnk::~DocLnk() 1459DocLnk::~DocLnk()
1464{ 1460{
1465} 1461}
1466 1462
1467/*! 1463/*!
1468 \reimp 1464 \reimp
1469*/ 1465*/
1470QString DocLnk::exec() const 1466QString DocLnk::exec() const
1471{ 1467{
1472 MimeType mt(type()); 1468 MimeType mt(type());
1473 const AppLnk* app = mt.application(); 1469 const AppLnk* app = mt.application();
1474 if ( app ) 1470 if ( app )
1475 return app->exec(); 1471 return app->exec();
1476 else 1472 else
1477 return QString::null; 1473 return QString::null;
1478} 1474}
1479 1475
1480/*! 1476/*!
1481 \reimp 1477 \reimp
1482*/ 1478*/
1483void DocLnk::invoke(const QStringList& args) const 1479void DocLnk::invoke(const QStringList& args) const
1484{ 1480{
1485 MimeType mt(type()); 1481 MimeType mt(type());
1486 const AppLnk* app = mt.application(); 1482 const AppLnk* app = mt.application();
1487 if ( app ) { 1483 if ( app ) {
1488 QStringList a = args; 1484 QStringList a = args;
1489 if ( linkFileKnown() && QFile::exists( linkFile() ) ) 1485 if ( linkFileKnown() && QFile::exists( linkFile() ) )
1490 a.append(linkFile()); 1486 a.append(linkFile());
1491 else 1487 else
1492 a.append(file()); 1488 a.append(file());
1493 app->execute(a); 1489 app->execute(a);
1494 } 1490 }
1495} 1491}
1496 1492
1497 1493