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