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