summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
Unidiff
Diffstat (limited to 'library/applnk.cpp') (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 5185b5f..778ccab 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,1122 +1,1122 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 22
23#include "applnk.h" 23#include "applnk.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/categories.h> 26#include <qpe/categories.h>
27#include <qpe/categoryselect.h> 27#include <qpe/categoryselect.h>
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/global.h> 29#include <qpe/global.h>
30#include <qpe/mimetype.h> 30#include <qpe/mimetype.h>
31#include <qpe/config.h> 31#include <qpe/config.h>
32#include <qpe/storage.h> 32#include <qpe/storage.h>
33#include <qpe/resource.h> 33#include <qpe/resource.h>
34 34
35#include <qdict.h> 35#include <qdict.h>
36#include <qdir.h> 36#include <qdir.h>
37#include <qregexp.h> 37#include <qregexp.h>
38 38
39#ifdef Q_WS_QWS 39#ifdef Q_WS_QWS
40#include <qgfx_qws.h> 40#include <qgfx_qws.h>
41#endif 41#endif
42 42
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45int AppLnk::lastId = 5000; 45int AppLnk::lastId = 5000;
46 46
47static int smallSize = 14; 47static int smallSize = 14;
48static int bigSize = 32; 48static int bigSize = 32;
49 49
50static QString safeFileName(const QString& n) 50static QString safeFileName(const QString& n)
51{ 51{
52 QString safename=n; 52 QString safename=n;
53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); // Njaard says this is broken 53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); // Njaard says this is broken
54 safename.replace(QRegExp("^[^A-Za-z]*"),""); 54 safename.replace(QRegExp("^[^A-Za-z]*"),"");
55 if ( safename.isEmpty() ) 55 if ( safename.isEmpty() )
56 safename = "_"; 56 safename = "_";
57 return safename; 57 return safename;
58} 58}
59 59
60static bool prepareDirectories(const QString& lf) 60static bool prepareDirectories(const QString& lf)
61{ 61{
62 if ( !QFile::exists(lf) ) { 62 if ( !QFile::exists(lf) ) {
63 // May need to create directories 63 // May need to create directories
64 QFileInfo fi(lf); 64 QFileInfo fi(lf);
65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
66 return FALSE; 66 return FALSE;
67 } 67 }
68 return TRUE; 68 return TRUE;
69} 69}
70 70
71class AppLnkPrivate 71class AppLnkPrivate
72{ 72{
73public: 73public:
74 QArray<int> mCat; 74 QArray<int> mCat;
75}; 75};
76 76
77/*! 77/*!
78 \class AppLnk applnk.h 78 \class AppLnk applnk.h
79 \brief The AppLnk class represents an application available on the system. 79 \brief The AppLnk class represents an application available on the system.
80 80
81 Information about applications are stored in Qtopia as ".desktop" files. 81 Information about applications are stored in Qtopia as ".desktop" files.
82 When read, these files are stored as AppLnk objects. 82 When read, these files are stored as AppLnk objects.
83*/ 83*/
84 84
85/*! 85/*!
86 Sets the size used for small icons to \a small pixels. 86 Sets the size used for small icons to \a small pixels.
87 Only affects AppLnk objects created after the call. 87 Only affects AppLnk objects created after the call.
88*/ 88*/
89void AppLnk::setSmallIconSize(int small) 89void AppLnk::setSmallIconSize(int small)
90{ 90{
91 smallSize = small; 91 smallSize = small;
92} 92}
93 93
94/*! 94/*!
95 Returns the size used for small icons. 95 Returns the size used for small icons.
96*/ 96*/
97int AppLnk::smallIconSize() 97int AppLnk::smallIconSize()
98{ 98{
99 return smallSize; 99 return smallSize;
100} 100}
101 101
102 102
103/*! 103/*!
104 Sets the size used for large icons to \a big pixels. 104 Sets the size used for large icons to \a big pixels.
105 Only affects AppLnk objects created after the call. 105 Only affects AppLnk objects created after the call.
106*/ 106*/
107void AppLnk::setBigIconSize(int big) 107void AppLnk::setBigIconSize(int big)
108{ 108{
109 bigSize = big; 109 bigSize = big;
110} 110}
111 111
112/*! 112/*!
113 Returns the size used for large icons. 113 Returns the size used for large icons.
114*/ 114*/
115int AppLnk::bigIconSize() 115int AppLnk::bigIconSize()
116{ 116{
117 return bigSize; 117 return bigSize;
118} 118}
119 119
120 120
121/*! 121/*!
122 \fn QString AppLnk::name() const 122 \fn QString AppLnk::name() const
123 123
124 Returns the Name property. 124 Returns the Name property.
125*/ 125*/
126/*! 126/*!
127 \fn QString AppLnk::exec() const 127 \fn QString AppLnk::exec() const
128 128
129 Returns the Exec property. This is the executable program associated 129 Returns the Exec property. This is the executable program associated
130 with the AppLnk. 130 with the AppLnk.
131*/ 131*/
132/*! 132/*!
133 \fn QString AppLnk::rotation() const 133 \fn QString AppLnk::rotation() const
134 134
135 Returns the Rotation property. 135 Returns the Rotation property.
136*/ 136*/
137/*! 137/*!
138 \fn QString AppLnk::comment() const 138 \fn QString AppLnk::comment() const
139 139
140 Returns the Comment property. 140 Returns the Comment property.
141*/ 141*/
142/*! 142/*!
143 \fn QStringList AppLnk::mimeTypes() const 143 \fn QStringList AppLnk::mimeTypes() const
144 144
145 Returns the MimeTypes property. This is the list of MIME types 145 Returns the MimeTypes property. This is the list of MIME types
146 that the application can view or edit. 146 that the application can view or edit.
147*/ 147*/
148/*! 148/*!
149 \fn const QArray<int>& AppLnk::categories() const 149 \fn const QArray<int>& AppLnk::categories() const
150 150
151 Returns the Categories property. 151 Returns the Categories property.
152*/ 152*/
153 153
154const QArray<int>& AppLnk::categories() const 154const QArray<int>& AppLnk::categories() const
155{ 155{
156 return d->mCat; 156 return d->mCat;
157} 157}
158 158
159/*! 159/*!
160 \fn int AppLnk::id() const 160 \fn int AppLnk::id() const
161 161
162 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, 162 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet,
163 this value is 0, otherwise it is a value that is unique for the 163 this value is 0, otherwise it is a value that is unique for the
164 duration of the current process. 164 duration of the current process.
165*/ 165*/
166 166
167/*! 167/*!
168 \fn bool AppLnk::isValid() const 168 \fn bool AppLnk::isValid() const
169 169
170 Returns whether this AppLnk is valid. 170 Returns whether this AppLnk is valid.
171*/ 171*/
172 172
173/*! 173/*!
174 Creates an invalid AppLnk. 174 Creates an invalid AppLnk.
175 175
176 \sa isValid() 176 \sa isValid()
177*/ 177*/
178AppLnk::AppLnk() 178AppLnk::AppLnk()
179{ 179{
180 mId = 0; 180 mId = 0;
181 d = new AppLnkPrivate(); 181 d = new AppLnkPrivate();
182} 182}
183 183
184/*! 184/*!
185 Loads \a file as an AppLnk. 185 Loads \a file as an AppLnk.
186*/ 186*/
187AppLnk::AppLnk( const QString &file ) 187AppLnk::AppLnk( const QString &file )
188{ 188{
189 QStringList sl; 189 QStringList sl;
190 d = new AppLnkPrivate(); 190 d = new AppLnkPrivate();
191 if ( !file.isNull() ) { 191 if ( !file.isNull() ) {
192 Config config( file, Config::File ); 192 Config config( file, Config::File );
193 193
194 if ( config.isValid() ) { 194 if ( config.isValid() ) {
195 config.setGroup( "Desktop Entry" ); 195 config.setGroup( "Desktop Entry" );
196 196
197 mName = config.readEntry( "Name", file ); 197 mName = config.readEntry( "Name", file );
198 mExec = config.readEntry( "Exec" ); 198 mExec = config.readEntry( "Exec" );
199 mType = config.readEntry( "Type", QString::null ); 199 mType = config.readEntry( "Type", QString::null );
200 mIconFile = config.readEntry( "Icon", QString::null ); 200 mIconFile = config.readEntry( "Icon", QString::null );
201 mRotation = config.readEntry( "Rotation", "" ); 201 mRotation = config.readEntry( "Rotation", "" );
202 mComment = config.readEntry( "Comment", QString::null ); 202 mComment = config.readEntry( "Comment", QString::null );
203 mMimeTypes = config.readListEntry( "MimeType", ';' ); 203 mMimeTypes = config.readListEntry( "MimeType", ';' );
204 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 204 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
205 mLinkFile = file; 205 mLinkFile = file;
206 mFile = config.readEntry("File", QString::null); 206 mFile = config.readEntry("File", QString::null);
207 sl = config.readListEntry("Categories", ';'); 207 sl = config.readListEntry("Categories", ';');
208 } 208 }
209 } 209 }
210 // let's try our darndest to create categories... 210 // let's try our darndest to create categories...
211 Categories cat( 0 ); 211 Categories cat( 0 );
212 cat.load( categoryFileName() ); 212 cat.load( categoryFileName() );
213 d->mCat.resize( sl.count() ); 213 d->mCat.resize( sl.count() );
214 int i; 214 int i;
215 QStringList::Iterator it; 215 QStringList::Iterator it;
216 for ( i = 0, it = sl.begin(); it != sl.end(); 216 for ( i = 0, it = sl.begin(); it != sl.end();
217 ++it, i++ ) { 217 ++it, i++ ) {
218 218
219 bool number; 219 bool number;
220 int id = (*it).toInt( &number ); 220 int id = (*it).toInt( &number );
221 if ( !number ) { 221 if ( !number ) {
222 // convert from old school... 222 // convert from old school...
223 id = cat.id( "Document Viewer", *it ); 223 id = cat.id( "Document Viewer", *it );
224 if ( id == 0 ) 224 if ( id == 0 )
225 id = cat.addCategory( "Document Viewer", *it ); 225 id = cat.addCategory( "Document Viewer", *it );
226 } 226 }
227 d->mCat[i] = id; 227 d->mCat[i] = id;
228 } 228 }
229 mId = 0; 229 mId = 0;
230} 230}
231 231
232/*! 232/*!
233 Returns a small pixmap associated with the application. 233 Returns a small pixmap associated with the application.
234*/ 234*/
235const QPixmap& AppLnk::pixmap() const 235const QPixmap& AppLnk::pixmap() const
236{ 236{
237 if ( mPixmap.isNull() ) { 237 if ( mPixmap.isNull() ) {
238 AppLnk* that = (AppLnk*)this; 238 AppLnk* that = (AppLnk*)this;
239 if ( mIconFile.isEmpty() ) { 239 if ( mIconFile.isEmpty() ) {
240 MimeType mt(type()); 240 MimeType mt(type());
241 that->mPixmap = mt.pixmap(); 241 that->mPixmap = mt.pixmap();
242 if ( that->mPixmap.isNull() ) 242 if ( that->mPixmap.isNull() )
243 that->mPixmap = Resource::loadPixmap("UnknownDocument-14"); 243 that->mPixmap = Resource::loadPixmap("UnknownDocument-14");
244 return that->mPixmap; 244 return that->mPixmap;
245 } 245 }
246 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 246 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
247 that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 247 that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
248 that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 248 that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
249 return that->mPixmap; 249 return that->mPixmap;
250 } 250 }
251 return mPixmap; 251 return mPixmap;
252} 252}
253 253
254/*! 254/*!
255 Returns a large pixmap associated with the application. 255 Returns a large pixmap associated with the application.
256*/ 256*/
257const QPixmap& AppLnk::bigPixmap() const 257const QPixmap& AppLnk::bigPixmap() const
258{ 258{
259 if ( mBigPixmap.isNull() ) { 259 if ( mBigPixmap.isNull() ) {
260 AppLnk* that = (AppLnk*)this; 260 AppLnk* that = (AppLnk*)this;
261 if ( mIconFile.isEmpty() ) { 261 if ( mIconFile.isEmpty() ) {
262 MimeType mt(type()); 262 MimeType mt(type());
263 that->mBigPixmap = mt.bigPixmap(); 263 that->mBigPixmap = mt.bigPixmap();
264 if ( that->mBigPixmap.isNull() ) 264 if ( that->mBigPixmap.isNull() )
265 that->mBigPixmap = Resource::loadPixmap("UnknownDocument"); 265 that->mBigPixmap = Resource::loadPixmap("UnknownDocument");
266 return that->mBigPixmap; 266 return that->mBigPixmap;
267 } 267 }
268 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 268 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
269 that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 269 that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
270 that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 270 that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
271 return that->mBigPixmap; 271 return that->mBigPixmap;
272 } 272 }
273 return mBigPixmap; 273 return mBigPixmap;
274} 274}
275 275
276/*! 276/*!
277 Returns the type of the application. 277 Returns the type of the application.
278*/ 278*/
279QString AppLnk::type() const 279QString AppLnk::type() const
280{ 280{
281 if ( mType.isNull() ) { 281 if ( mType.isNull() ) {
282 AppLnk* that = (AppLnk*)this; 282 AppLnk* that = (AppLnk*)this;
283 MimeType mt(file()); 283 MimeType mt(file());
284 that->mType = mt.id(); 284 that->mType = mt.id();
285 return that->mType; 285 return that->mType;
286 } 286 }
287 return mType; 287 return mType;
288} 288}
289 289
290/*! 290/*!
291 Returns the file associated with the AppLnk. 291 Returns the file associated with the AppLnk.
292 292
293 \sa exec() 293 \sa exec()
294*/ 294*/
295QString AppLnk::file() const 295QString AppLnk::file() const
296{ 296{
297 if ( mFile.isNull() ) { 297 if ( mFile.isNull() ) {
298 AppLnk* that = (AppLnk*)this; // copy? 298 AppLnk* that = (AppLnk*)this; // copy?
299 QString ext = MimeType(mType).extension(); 299 QString ext = MimeType(mType).extension();
300 if ( !ext.isEmpty() ) 300 if ( !ext.isEmpty() )
301 ext = "." + ext; 301 ext = "." + ext;
302 if ( !mLinkFile.isEmpty() ) { 302 if ( !mLinkFile.isEmpty() ) {
303 that->mFile = 303 that->mFile =
304 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 304 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
305 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 305 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
306 } else if ( mType.contains('/') ) { 306 } else if ( mType.contains('/') ) {
307 that->mFile = 307 that->mFile =
308 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 308 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
309 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists 309 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists
310 int n=1; 310 int n=1;
311 qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() ); 311 qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() );
312 QString nn; 312 QString nn;
313 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 313 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
314 || QFile::exists(nn+".desktop")) 314 || QFile::exists(nn+".desktop"))
315 n++; 315 n++;
316 that->mFile = nn; 316 that->mFile = nn;
317 qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() ); 317 qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() );
318 } 318 }
319 that->mLinkFile = that->mFile+".desktop"; 319 that->mLinkFile = that->mFile+".desktop";
320 that->mFile += ext; 320 that->mFile += ext;
321 } 321 }
322 prepareDirectories(that->mFile); 322 prepareDirectories(that->mFile);
323 QFile f(that->mFile); 323 QFile f(that->mFile);
324 if ( !f.open(IO_WriteOnly) ) 324 if ( !f.open(IO_WriteOnly) )
325 that->mFile = QString::null; 325 that->mFile = QString::null;
326 return that->mFile; 326 return that->mFile;
327 } 327 }
328 return mFile; 328 return mFile;
329} 329}
330 330
331/*! 331/*!
332 Returns the desktop file coresponding to this AppLnk. 332 Returns the desktop file coresponding to this AppLnk.
333 333
334 \sa file(), exec() 334 \sa file(), exec()
335*/ 335*/
336QString AppLnk::linkFile() const 336QString AppLnk::linkFile() const
337{ 337{
338 if ( mLinkFile.isNull() ) { 338 if ( mLinkFile.isNull() ) {
339 AppLnk* that = (AppLnk*)this; 339 AppLnk* that = (AppLnk*)this;
340 if ( type().contains('/') ) { 340 if ( type().contains('/') ) {
341 StorageInfo storage; 341 StorageInfo storage;
342 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 342 const FileSystem *fs = storage.fileSystemOf( that->mFile );
343 if ( fs && fs->isRemovable() ) { 343 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs" ) ) {
344 that->mLinkFile = fs->path(); 344 that->mLinkFile = fs->path();
345 } else 345 } else
346 that->mLinkFile = getenv( "HOME" ); 346 that->mLinkFile = getenv( "HOME" );
347 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 347 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
348 if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file 348 if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file
349 int n=1; 349 int n=1;
350 QString nn; 350 QString nn;
351 AppLnk lnk( that->mLinkFile+".desktop" ); 351 AppLnk lnk( that->mLinkFile+".desktop" );
352 if(that->file() != lnk.file() ){ 352 if(that->file() != lnk.file() ){
353 qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() ); 353 qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() );
354 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){ 354 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){
355 n++; 355 n++;
356 AppLnk lnk(nn ); // just to be sure 356 AppLnk lnk(nn ); // just to be sure
357 if(lnk.file() ==that->file() ){ 357 if(lnk.file() ==that->file() ){
358 break; 358 break;
359 } 359 }
360 } 360 }
361 that->mLinkFile = nn; 361 that->mLinkFile = nn;
362 } 362 }
363 } 363 }
364 that->mLinkFile += ".desktop"; 364 that->mLinkFile += ".desktop";
365 qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() ); 365 qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() );
366 storeLink(); 366 storeLink();
367 } 367 }
368 return that->mLinkFile; 368 return that->mLinkFile;
369 } 369 }
370 return mLinkFile; 370 return mLinkFile;
371} 371}
372 372
373/*! 373/*!
374 Copies \a copy. 374 Copies \a copy.
375*/ 375*/
376AppLnk::AppLnk( const AppLnk &copy ) 376AppLnk::AppLnk( const AppLnk &copy )
377{ 377{
378 mName = copy.mName; 378 mName = copy.mName;
379 mPixmap = copy.mPixmap; 379 mPixmap = copy.mPixmap;
380 mBigPixmap = copy.mBigPixmap; 380 mBigPixmap = copy.mBigPixmap;
381 mExec = copy.mExec; 381 mExec = copy.mExec;
382 mType = copy.mType; 382 mType = copy.mType;
383 mRotation = copy.mRotation; 383 mRotation = copy.mRotation;
384 mComment = copy.mComment; 384 mComment = copy.mComment;
385 mFile = copy.mFile; 385 mFile = copy.mFile;
386 mLinkFile = copy.mLinkFile; 386 mLinkFile = copy.mLinkFile;
387 mIconFile = copy.mIconFile; 387 mIconFile = copy.mIconFile;
388 mMimeTypes = copy.mMimeTypes; 388 mMimeTypes = copy.mMimeTypes;
389 mMimeTypeIcons = copy.mMimeTypeIcons; 389 mMimeTypeIcons = copy.mMimeTypeIcons;
390 mId = 0; 390 mId = 0;
391 d = new AppLnkPrivate(); 391 d = new AppLnkPrivate();
392 d->mCat = copy.d->mCat; 392 d->mCat = copy.d->mCat;
393} 393}
394 394
395/*! 395/*!
396 Destroys the AppLnk. Note that if the AppLnk is current a member of 396 Destroys the AppLnk. Note that if the AppLnk is current a member of
397 an AppLnkSet, this will produce a run-time warning. 397 an AppLnkSet, this will produce a run-time warning.
398 398
399 \sa AppLnkSet::add(), AppLnkSet::remove() 399 \sa AppLnkSet::add(), AppLnkSet::remove()
400*/ 400*/
401AppLnk::~AppLnk() 401AppLnk::~AppLnk()
402{ 402{
403 if ( mId ) 403 if ( mId )
404 qWarning("Deleting AppLnk that is in an AppLnkSet"); 404 qWarning("Deleting AppLnk that is in an AppLnkSet");
405 if ( d ) 405 if ( d )
406 delete d; 406 delete d;
407} 407}
408 408
409/*! 409/*!
410 Executes the application associated with this AppLnk. 410 Executes the application associated with this AppLnk.
411*/ 411*/
412void AppLnk::execute() const 412void AppLnk::execute() const
413{ 413{
414 execute(QStringList()); 414 execute(QStringList());
415} 415}
416 416
417/*! 417/*!
418 Executes the application associated with this AppLnk, with 418 Executes the application associated with this AppLnk, with
419 \a args as arguments. 419 \a args as arguments.
420*/ 420*/
421void AppLnk::execute(const QStringList& args) const 421void AppLnk::execute(const QStringList& args) const
422{ 422{
423#ifdef Q_WS_QWS 423#ifdef Q_WS_QWS
424 if ( !mRotation.isEmpty() ) { 424 if ( !mRotation.isEmpty() ) {
425 // ######## this will only work in the server 425 // ######## this will only work in the server
426 int rot = QPEApplication::defaultRotation(); 426 int rot = QPEApplication::defaultRotation();
427 rot = (rot+mRotation.toInt())%360; 427 rot = (rot+mRotation.toInt())%360;
428 QCString old = getenv("QWS_DISPLAY"); 428 QCString old = getenv("QWS_DISPLAY");
429 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 429 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
430 invoke(args); 430 invoke(args);
431 setenv("QWS_DISPLAY", old.data(), 1); 431 setenv("QWS_DISPLAY", old.data(), 1);
432 } else 432 } else
433#endif 433#endif
434 invoke(args); 434 invoke(args);
435} 435}
436 436
437/*! 437/*!
438 Invokes the application associated with this AppLnk, with 438 Invokes the application associated with this AppLnk, with
439 \a args as arguments. Rotation is not taken into account by 439 \a args as arguments. Rotation is not taken into account by
440 this function, you should not call it directly. 440 this function, you should not call it directly.
441 441
442 \sa execute() 442 \sa execute()
443*/ 443*/
444void AppLnk::invoke(const QStringList& args) const 444void AppLnk::invoke(const QStringList& args) const
445{ 445{
446 Global::execute( exec(), args[0] ); 446 Global::execute( exec(), args[0] );
447} 447}
448 448
449/*! 449/*!
450 Sets the Exec property to \a exec. 450 Sets the Exec property to \a exec.
451 451
452 \sa exec() 452 \sa exec()
453*/ 453*/
454void AppLnk::setExec( const QString& exec ) 454void AppLnk::setExec( const QString& exec )
455{ 455{
456 mExec = exec; 456 mExec = exec;
457} 457}
458 458
459/*! 459/*!
460 Sets the Name property to \a docname. 460 Sets the Name property to \a docname.
461 461
462 \sa name() 462 \sa name()
463*/ 463*/
464void AppLnk::setName( const QString& docname ) 464void AppLnk::setName( const QString& docname )
465{ 465{
466 mName = docname; 466 mName = docname;
467} 467}
468 468
469/*! 469/*!
470 Sets the File property to \a filename. 470 Sets the File property to \a filename.
471 471
472 \sa file() 472 \sa file()
473*/ 473*/
474void AppLnk::setFile( const QString& filename ) 474void AppLnk::setFile( const QString& filename )
475{ 475{
476 mFile = filename; 476 mFile = filename;
477} 477}
478 478
479/*! 479/*!
480 Sets the LinkFile property to \a filename. 480 Sets the LinkFile property to \a filename.
481 481
482 \sa linkFile() 482 \sa linkFile()
483*/ 483*/
484void AppLnk::setLinkFile( const QString& filename ) 484void AppLnk::setLinkFile( const QString& filename )
485{ 485{
486 mLinkFile = filename; 486 mLinkFile = filename;
487} 487}
488 488
489/*! 489/*!
490 Sets the Comment property to \a comment. 490 Sets the Comment property to \a comment.
491 491
492 \sa comment() 492 \sa comment()
493*/ 493*/
494void AppLnk::setComment( const QString& comment ) 494void AppLnk::setComment( const QString& comment )
495{ 495{
496 mComment = comment; 496 mComment = comment;
497} 497}
498 498
499/*! 499/*!
500 Sets the Type property to \a type. 500 Sets the Type property to \a type.
501 501
502 \sa type() 502 \sa type()
503*/ 503*/
504void AppLnk::setType( const QString& type ) 504void AppLnk::setType( const QString& type )
505{ 505{
506 mType = type; 506 mType = type;
507} 507}
508 508
509/*! 509/*!
510 Sets the Icon property to \a iconname. 510 Sets the Icon property to \a iconname.
511 511
512 \sa pixmap(), bigPixmap() 512 \sa pixmap(), bigPixmap()
513*/ 513*/
514void AppLnk::setIcon( const QString& iconname ) 514void AppLnk::setIcon( const QString& iconname )
515{ 515{
516 mIconFile = iconname; 516 mIconFile = iconname;
517 QImage unscaledIcon = Resource::loadImage( mIconFile ); 517 QImage unscaledIcon = Resource::loadImage( mIconFile );
518 mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 518 mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
519 mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 519 mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
520} 520}
521 521
522/*! 522/*!
523 Sets the Categories property to \a c. 523 Sets the Categories property to \a c.
524 524
525 \sa categories() 525 \sa categories()
526*/ 526*/
527void AppLnk::setCategories( const QArray<int>& c ) 527void AppLnk::setCategories( const QArray<int>& c )
528{ 528{
529 d->mCat = c; 529 d->mCat = c;
530} 530}
531 531
532/*! 532/*!
533 \fn QStringList AppLnk::mimeTypeIcons() const 533 \fn QStringList AppLnk::mimeTypeIcons() const
534 534
535 Returns the MimeTypeIcons property of the AppLnk. 535 Returns the MimeTypeIcons property of the AppLnk.
536*/ 536*/
537 537
538/*! 538/*!
539 Attempts to ensure that the link file for this AppLnk exists, including 539 Attempts to ensure that the link file for this AppLnk exists, including
540 creating any required directories. Returns TRUE if successful. 540 creating any required directories. Returns TRUE if successful.
541*/ 541*/
542bool AppLnk::ensureLinkExists() const 542bool AppLnk::ensureLinkExists() const
543{ 543{
544 QString lf = linkFile(); 544 QString lf = linkFile();
545 return prepareDirectories(lf); 545 return prepareDirectories(lf);
546} 546}
547 547
548/*! 548/*!
549 Commits the AppLnk to disk. Returns whether the operation succeeded. 549 Commits the AppLnk to disk. Returns whether the operation succeeded.
550 550
551 The "linkChanged(QString)" message is sent to the 551 The "linkChanged(QString)" message is sent to the
552 "QPE/System" QCop channel as a result. 552 "QPE/System" QCop channel as a result.
553*/ 553*/
554bool AppLnk::writeLink() const 554bool AppLnk::writeLink() const
555{ 555{
556 // Only re-writes settable parts 556 // Only re-writes settable parts
557 QString lf = linkFile(); 557 QString lf = linkFile();
558 if ( !ensureLinkExists() ) 558 if ( !ensureLinkExists() )
559 return FALSE; 559 return FALSE;
560 storeLink(); 560 storeLink();
561 return TRUE; 561 return TRUE;
562} 562}
563 563
564void AppLnk::storeLink() const 564void AppLnk::storeLink() const
565{ 565{
566 Config config( mLinkFile, Config::File ); 566 Config config( mLinkFile, Config::File );
567 config.setGroup("Desktop Entry"); 567 config.setGroup("Desktop Entry");
568 config.writeEntry("Name",mName); 568 config.writeEntry("Name",mName);
569 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 569 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
570 config.writeEntry("Type",type()); 570 config.writeEntry("Type",type());
571 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 571 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
572 config.writeEntry("File",file()); 572 config.writeEntry("File",file());
573 // write out the id... 573 // write out the id...
574 int i; 574 int i;
575 QStringList sl; 575 QStringList sl;
576 for ( i = 0; i < int(d->mCat.count()); i++ ) { 576 for ( i = 0; i < int(d->mCat.count()); i++ ) {
577 sl.append( QString::number( d->mCat[i] ) ); 577 sl.append( QString::number( d->mCat[i] ) );
578 } 578 }
579 config.writeEntry( "Categories", sl, ';' ); 579 config.writeEntry( "Categories", sl, ';' );
580 580
581 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 581 QCopEnvelope e("QPE/System", "linkChanged(QString)");
582 e << mLinkFile; 582 e << mLinkFile;
583} 583}
584 584
585/*! 585/*!
586 Sets the property named \a key to \a value. 586 Sets the property named \a key to \a value.
587*/ 587*/
588void AppLnk::setProperty(const QString& key, const QString& value) 588void AppLnk::setProperty(const QString& key, const QString& value)
589{ 589{
590 if ( ensureLinkExists() ) { 590 if ( ensureLinkExists() ) {
591 Config cfg(linkFile(), Config::File); 591 Config cfg(linkFile(), Config::File);
592 cfg.writeEntry(key,value); 592 cfg.writeEntry(key,value);
593 } 593 }
594} 594}
595 595
596/*! 596/*!
597 Returns the property named \a key. 597 Returns the property named \a key.
598*/ 598*/
599QString AppLnk::property(const QString& key) const 599QString AppLnk::property(const QString& key) const
600{ 600{
601 QString lf = linkFile(); 601 QString lf = linkFile();
602 if ( !QFile::exists(lf) ) 602 if ( !QFile::exists(lf) )
603 return QString::null; 603 return QString::null;
604 Config cfg(lf, Config::File); 604 Config cfg(lf, Config::File);
605 return cfg.readEntry(key); 605 return cfg.readEntry(key);
606} 606}
607 607
608 608
609/*! 609/*!
610 Deletes both the linkFile() and file() associated with this AppLnk. 610 Deletes both the linkFile() and file() associated with this AppLnk.
611*/ 611*/
612void AppLnk::removeFiles() 612void AppLnk::removeFiles()
613{ 613{
614 bool valid = isValid(); 614 bool valid = isValid();
615 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 615 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
616 if ( QFile::remove(file()) ) { 616 if ( QFile::remove(file()) ) {
617 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 617 QCopEnvelope e("QPE/System", "linkChanged(QString)");
618 if ( linkFileKnown() ) 618 if ( linkFileKnown() )
619 e << linkFile(); 619 e << linkFile();
620 else 620 else
621 e << file(); 621 e << file();
622 } else if ( valid ) { 622 } else if ( valid ) {
623 // restore link 623 // restore link
624 writeLink(); 624 writeLink();
625 } 625 }
626 } 626 }
627} 627}
628 628
629/*! 629/*!
630 Delete the linkFile(), leaving any file() untouched. 630 Delete the linkFile(), leaving any file() untouched.
631*/ 631*/
632void AppLnk::removeLinkFile() 632void AppLnk::removeLinkFile()
633{ 633{
634 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 634 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
635 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 635 QCopEnvelope e("QPE/System", "linkChanged(QString)");
636 e << linkFile(); 636 e << linkFile();
637 } 637 }
638} 638}
639 639
640class AppLnkSetPrivate { 640class AppLnkSetPrivate {
641public: 641public:
642 AppLnkSetPrivate() 642 AppLnkSetPrivate()
643 { 643 {
644 typPix.setAutoDelete(TRUE); 644 typPix.setAutoDelete(TRUE);
645 typPixBig.setAutoDelete(TRUE); 645 typPixBig.setAutoDelete(TRUE);
646 typName.setAutoDelete(TRUE); 646 typName.setAutoDelete(TRUE);
647 } 647 }
648 648
649 QDict<QPixmap> typPix; 649 QDict<QPixmap> typPix;
650 QDict<QPixmap> typPixBig; 650 QDict<QPixmap> typPixBig;
651 QDict<QString> typName; 651 QDict<QString> typName;
652}; 652};
653 653
654/*! 654/*!
655 \class AppLnkSet applnk.h 655 \class AppLnkSet applnk.h
656 \brief The AppLnkSet class is a set of AppLnk objects. 656 \brief The AppLnkSet class is a set of AppLnk objects.
657*/ 657*/
658 658
659/*! 659/*!
660 \fn QStringList AppLnkSet::types() const 660 \fn QStringList AppLnkSet::types() const
661 661
662 Returns the list of types in the set. 662 Returns the list of types in the set.
663 663
664 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() 664 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
665*/ 665*/
666 666
667/*! 667/*!
668 \fn const QList<AppLnk>& AppLnkSet::children() const 668 \fn const QList<AppLnk>& AppLnkSet::children() const
669 669
670 Returns the members of the set. 670 Returns the members of the set.
671*/ 671*/
672 672
673/*! 673/*!
674 Constructs an empty AppLnkSet. 674 Constructs an empty AppLnkSet.
675*/ 675*/
676AppLnkSet::AppLnkSet() : 676AppLnkSet::AppLnkSet() :
677 d(new AppLnkSetPrivate) 677 d(new AppLnkSetPrivate)
678{ 678{
679} 679}
680 680
681/*! 681/*!
682 Constructs an AppLnkSet that contains AppLnk objects representing 682 Constructs an AppLnkSet that contains AppLnk objects representing
683 all the files in a \a directory (recursively). 683 all the files in a \a directory (recursively).
684 684
685 The directories may contain ".directory" files which overrides 685 The directories may contain ".directory" files which overrides
686 any AppLnk::type() value of AppLnk objects found in the directory. 686 any AppLnk::type() value of AppLnk objects found in the directory.
687 This allows simple localization of application types. 687 This allows simple localization of application types.
688*/ 688*/
689AppLnkSet::AppLnkSet( const QString &directory ) : 689AppLnkSet::AppLnkSet( const QString &directory ) :
690 d(new AppLnkSetPrivate) 690 d(new AppLnkSetPrivate)
691{ 691{
692 QDir dir( directory ); 692 QDir dir( directory );
693 mFile = directory; 693 mFile = directory;
694 findChildren(directory,QString::null,QString::null); 694 findChildren(directory,QString::null,QString::null);
695} 695}
696 696
697/*! 697/*!
698 Detaches all AppLnk objects from the set. The set become empty 698 Detaches all AppLnk objects from the set. The set become empty
699 and the call becomes responsible for deleting the AppLnk objects. 699 and the call becomes responsible for deleting the AppLnk objects.
700*/ 700*/
701void AppLnkSet::detachChildren() 701void AppLnkSet::detachChildren()
702{ 702{
703 QListIterator<AppLnk> it( mApps ); 703 QListIterator<AppLnk> it( mApps );
704 for ( ; it.current(); ) { 704 for ( ; it.current(); ) {
705 AppLnk* a = *it; 705 AppLnk* a = *it;
706 ++it; 706 ++it;
707 a->mId = 0; 707 a->mId = 0;
708 } 708 }
709 mApps.clear(); 709 mApps.clear();
710} 710}
711 711
712/*! 712/*!
713 Destroys the set, deleting all AppLnk objects it contains. 713 Destroys the set, deleting all AppLnk objects it contains.
714 714
715 \sa detachChildren() 715 \sa detachChildren()
716*/ 716*/
717AppLnkSet::~AppLnkSet() 717AppLnkSet::~AppLnkSet()
718{ 718{
719 QListIterator<AppLnk> it( mApps ); 719 QListIterator<AppLnk> it( mApps );
720 for ( ; it.current(); ) { 720 for ( ; it.current(); ) {
721 AppLnk* a = *it; 721 AppLnk* a = *it;
722 ++it; 722 ++it;
723 a->mId = 0; 723 a->mId = 0;
724 delete a; 724 delete a;
725 } 725 }
726 delete d; 726 delete d;
727} 727}
728 728
729void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) 729void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
730{ 730{
731 depth++; 731 depth++;
732 if ( depth > 10 ) 732 if ( depth > 10 )
733 return; 733 return;
734 734
735 QDir dir( dr ); 735 QDir dir( dr );
736 QString typNameLocal = typName; 736 QString typNameLocal = typName;
737 737
738 if ( dir.exists( ".directory" ) ) { 738 if ( dir.exists( ".directory" ) ) {
739 Config config( dr + "/.directory", Config::File ); 739 Config config( dr + "/.directory", Config::File );
740 config.setGroup( "Desktop Entry" ); 740 config.setGroup( "Desktop Entry" );
741 typNameLocal = config.readEntry( "Name", typNameLocal ); 741 typNameLocal = config.readEntry( "Name", typNameLocal );
742 if ( !typ.isEmpty() ) { 742 if ( !typ.isEmpty() ) {
743 QString iconFile = config.readEntry( "Icon", "AppsIcon" ); 743 QString iconFile = config.readEntry( "Icon", "AppsIcon" );
744 QImage unscaledIcon = Resource::loadImage( iconFile ); 744 QImage unscaledIcon = Resource::loadImage( iconFile );
745 QPixmap pm, bpm; 745 QPixmap pm, bpm;
746 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 746 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
747 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 747 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
748 d->typPix.insert(typ, new QPixmap(pm)); 748 d->typPix.insert(typ, new QPixmap(pm));
749 d->typPixBig.insert(typ, new QPixmap(bpm)); 749 d->typPixBig.insert(typ, new QPixmap(bpm));
750 d->typName.insert(typ, new QString(typNameLocal)); 750 d->typName.insert(typ, new QString(typNameLocal));
751 } 751 }
752 } 752 }
753 753
754 const QFileInfoList *list = dir.entryInfoList(); 754 const QFileInfoList *list = dir.entryInfoList();
755 if ( list ) { 755 if ( list ) {
756 QFileInfo* fi; 756 QFileInfo* fi;
757 bool cadded=FALSE; 757 bool cadded=FALSE;
758 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 758 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
759 QString bn = fi->fileName(); 759 QString bn = fi->fileName();
760 if ( bn[0] != '.' && bn != "CVS" ) { 760 if ( bn[0] != '.' && bn != "CVS" ) {
761 if ( fi->isDir() ) { 761 if ( fi->isDir() ) {
762 QString c = typ.isNull() ? bn : typ+"/"+bn; 762 QString c = typ.isNull() ? bn : typ+"/"+bn;
763 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; 763 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
764 findChildren(fi->filePath(), c, d, depth ); 764 findChildren(fi->filePath(), c, d, depth );
765 } else { 765 } else {
766 if ( fi->extension(FALSE) == "desktop" ) { 766 if ( fi->extension(FALSE) == "desktop" ) {
767 AppLnk* app = new AppLnk( fi->filePath() ); 767 AppLnk* app = new AppLnk( fi->filePath() );
768#ifdef QT_NO_QWS_MULTIPROCESS 768#ifdef QT_NO_QWS_MULTIPROCESS
769 if ( !Global::isBuiltinCommand( app->exec() ) ) 769 if ( !Global::isBuiltinCommand( app->exec() ) )
770 delete app; 770 delete app;
771 else 771 else
772#endif 772#endif
773 { 773 {
774 if ( !typ.isEmpty() ) { 774 if ( !typ.isEmpty() ) {
775 if ( !cadded ) { 775 if ( !cadded ) {
776 typs.append(typ); 776 typs.append(typ);
777 cadded = TRUE; 777 cadded = TRUE;
778 } 778 }
779 app->setType(typ); 779 app->setType(typ);
780 } 780 }
781 add(app); 781 add(app);
782 } 782 }
783 } 783 }
784 } 784 }
785 } 785 }
786 } 786 }
787 } 787 }
788} 788}
789 789
790/*! 790/*!
791 Adds \a f to the set. The set takes over responsibility for deleting \a f. 791 Adds \a f to the set. The set takes over responsibility for deleting \a f.
792 792
793 \sa remove() 793 \sa remove()
794*/ 794*/
795void AppLnkSet::add( AppLnk *f ) 795void AppLnkSet::add( AppLnk *f )
796{ 796{
797 if ( f->mId == 0 ) { 797 if ( f->mId == 0 ) {
798 AppLnk::lastId++; 798 AppLnk::lastId++;
799 f->mId = AppLnk::lastId; 799 f->mId = AppLnk::lastId;
800 mApps.append( f ); 800 mApps.append( f );
801 } else { 801 } else {
802 qWarning("Attempt to add an AppLnk twice"); 802 qWarning("Attempt to add an AppLnk twice");
803 } 803 }
804} 804}
805 805
806/*! 806/*!
807 Removes \a f to the set, returning whether \a f was in the set. 807 Removes \a f to the set, returning whether \a f was in the set.
808 The caller becomes responsible for deleting \a f. 808 The caller becomes responsible for deleting \a f.
809 809
810 \sa add() 810 \sa add()
811*/ 811*/
812bool AppLnkSet::remove( AppLnk *f ) 812bool AppLnkSet::remove( AppLnk *f )
813{ 813{
814 if ( mApps.remove( f ) ) { 814 if ( mApps.remove( f ) ) {
815 f->mId = 0; 815 f->mId = 0;
816 return TRUE; 816 return TRUE;
817 } 817 }
818 return FALSE; 818 return FALSE;
819} 819}
820 820
821/*! 821/*!
822 Returns the localized name for type \a t. 822 Returns the localized name for type \a t.
823*/ 823*/
824QString AppLnkSet::typeName( const QString& t ) const 824QString AppLnkSet::typeName( const QString& t ) const
825{ 825{
826 QString *st = d->typName.find(t); 826 QString *st = d->typName.find(t);
827 return st ? *st : QString::null; 827 return st ? *st : QString::null;
828} 828}
829 829
830/*! 830/*!
831 Returns the small pixmap associated with type \a t. 831 Returns the small pixmap associated with type \a t.
832*/ 832*/
833QPixmap AppLnkSet::typePixmap( const QString& t ) const 833QPixmap AppLnkSet::typePixmap( const QString& t ) const
834{ 834{
835 QPixmap *pm = d->typPix.find(t); 835 QPixmap *pm = d->typPix.find(t);
836 return pm ? *pm : QPixmap(); 836 return pm ? *pm : QPixmap();
837} 837}
838 838
839/*! 839/*!
840 Returns the large pixmap associated with type \a t. 840 Returns the large pixmap associated with type \a t.
841*/ 841*/
842QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const 842QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
843{ 843{
844 QPixmap *pm = d->typPixBig.find(t); 844 QPixmap *pm = d->typPixBig.find(t);
845 return pm ? *pm : QPixmap(); 845 return pm ? *pm : QPixmap();
846} 846}
847 847
848/*! 848/*!
849 Returns the AppLnk with the given \a id. 849 Returns the AppLnk with the given \a id.
850*/ 850*/
851const AppLnk *AppLnkSet::find( int id ) const 851const AppLnk *AppLnkSet::find( int id ) const
852{ 852{
853 QListIterator<AppLnk> it( children() ); 853 QListIterator<AppLnk> it( children() );
854 854
855 for ( ; it.current(); ++it ) { 855 for ( ; it.current(); ++it ) {
856 const AppLnk *app = it.current(); 856 const AppLnk *app = it.current();
857 if ( app->id() == id ) 857 if ( app->id() == id )
858 return app; 858 return app;
859 } 859 }
860 860
861 return 0; 861 return 0;
862} 862}
863 863
864/*! 864/*!
865 Returns the AppLnk with the given \a exec attribute. 865 Returns the AppLnk with the given \a exec attribute.
866*/ 866*/
867const AppLnk *AppLnkSet::findExec( const QString& exec ) const 867const AppLnk *AppLnkSet::findExec( const QString& exec ) const
868{ 868{
869 QListIterator<AppLnk> it( children() ); 869 QListIterator<AppLnk> it( children() );
870 870
871 for ( ; it.current(); ++it ) { 871 for ( ; it.current(); ++it ) {
872 const AppLnk *app = it.current(); 872 const AppLnk *app = it.current();
873 if ( app->exec() == exec ) 873 if ( app->exec() == exec )
874 return app; 874 return app;
875 } 875 }
876 876
877 return 0; 877 return 0;
878} 878}
879 879
880/*! 880/*!
881 \class DocLnkSet applnk.h 881 \class DocLnkSet applnk.h
882 \brief The DocLnkSet class is a set of DocLnk objects. 882 \brief The DocLnkSet class is a set of DocLnk objects.
883*/ 883*/
884 884
885/*! 885/*!
886 \fn const QList<DocLnk>& DocLnkSet::children() const 886 \fn const QList<DocLnk>& DocLnkSet::children() const
887 887
888 Returns the members of the set. 888 Returns the members of the set.
889*/ 889*/
890 890
891/*! 891/*!
892 Constructs an empty DocLnkSet. 892 Constructs an empty DocLnkSet.
893 893
894 \sa appendFrom() 894 \sa appendFrom()
895*/ 895*/
896DocLnkSet::DocLnkSet() 896DocLnkSet::DocLnkSet()
897{ 897{
898} 898}
899 899
900/*! 900/*!
901 Constructs an DocLnkSet that contains DocLnk objects representing 901 Constructs an DocLnkSet that contains DocLnk objects representing
902 all the files in a \a directory (recursively). 902 all the files in a \a directory (recursively).
903 903
904 If \a mimefilter is not null, 904 If \a mimefilter is not null,
905 only documents with a MIME type matching \a mimefilter are selected. 905 only documents with a MIME type matching \a mimefilter are selected.
906 The value may contain multiple wild-card patterns separated by ";", 906 The value may contain multiple wild-card patterns separated by ";",
907 such as "*o/mpeg;audio/x-wav". 907 such as "*o/mpeg;audio/x-wav".
908*/ 908*/
909DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : 909DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
910 AppLnkSet() 910 AppLnkSet()
911{ 911{
912 QDir dir( directory ); 912 QDir dir( directory );
913 mFile = dir.dirName(); 913 mFile = dir.dirName();
914 QDict<void> reference; 914 QDict<void> reference;
915 915
916 QStringList subFilter = QStringList::split(";", mimefilter); 916 QStringList subFilter = QStringList::split(";", mimefilter);
917 QValueList<QRegExp> mimeFilters; 917 QValueList<QRegExp> mimeFilters;
918 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) 918 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
919 mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 919 mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
920 920
921 findChildren(directory, mimeFilters, reference); 921 findChildren(directory, mimeFilters, reference);
922 922
923 const QList<DocLnk> &list = children(); 923 const QList<DocLnk> &list = children();
924 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 924 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
925 reference.remove( (*it)->file() ); 925 reference.remove( (*it)->file() );
926 } 926 }
927 927
928 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { 928 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
929 if ( dit.current() == (void*)2 ) { 929 if ( dit.current() == (void*)2 ) {
930 // Unreferenced, make an unwritten link 930 // Unreferenced, make an unwritten link
931 DocLnk* dl = new DocLnk; 931 DocLnk* dl = new DocLnk;
932 QFileInfo fi( dit.currentKey() ); 932 QFileInfo fi( dit.currentKey() );
933 dl->setFile(fi.filePath()); 933 dl->setFile(fi.filePath());
934 dl->setName(fi.baseName()); 934 dl->setName(fi.baseName());
935 // #### default to current path? 935 // #### default to current path?
936 // dl->setCategories( ... ); 936 // dl->setCategories( ... );
937 bool match = mimefilter.isNull(); 937 bool match = mimefilter.isNull();
938 if ( !match ) 938 if ( !match )
939 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) 939 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
940 if ( (*it).match(dl->type()) >= 0 ) 940 if ( (*it).match(dl->type()) >= 0 )
941 match = TRUE; 941 match = TRUE;
942 if ( match /* && dl->type() != "application/octet-stream" */ 942 if ( match /* && dl->type() != "application/octet-stream" */
943 && !!dl->exec() ) 943 && !!dl->exec() )
944 add(dl); 944 add(dl);
945 else 945 else
946 delete dl; 946 delete dl;
947 } 947 }
948 } 948 }
949} 949}
950 950
951// other becomes empty 951// other becomes empty
952/*! 952/*!
953 Transfers all DocLnk objects from \a other to this set. \a other becomes 953 Transfers all DocLnk objects from \a other to this set. \a other becomes
954 empty. 954 empty.
955*/ 955*/
956void DocLnkSet::appendFrom( DocLnkSet& other ) 956void DocLnkSet::appendFrom( DocLnkSet& other )
957{ 957{
958 if ( &other == this ) 958 if ( &other == this )
959 return; 959 return;
960 QListIterator<AppLnk> it( other.mApps ); 960 QListIterator<AppLnk> it( other.mApps );
961 for ( ; it.current(); ) { 961 for ( ; it.current(); ) {
962 mApps.append(*it); 962 mApps.append(*it);
963 ++it; 963 ++it;
964 } 964 }
965 other.mApps.clear(); 965 other.mApps.clear();
966} 966}
967 967
968void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) 968void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
969{ 969{
970 depth++; 970 depth++;
971 if ( depth > 10 ) 971 if ( depth > 10 )
972 return; 972 return;
973 973
974 QDir dir( dr ); 974 QDir dir( dr );
975 975
976 const QFileInfoList *list = dir.entryInfoList(); 976 const QFileInfoList *list = dir.entryInfoList();
977 if ( list ) { 977 if ( list ) {
978 QFileInfo* fi; 978 QFileInfo* fi;
979 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 979 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
980 QString bn = fi->fileName(); 980 QString bn = fi->fileName();
981 if ( bn[0] != '.' && bn != "CVS" ) { 981 if ( bn[0] != '.' && bn != "CVS" ) {
982 if ( fi->isDir() ) { 982 if ( fi->isDir() ) {
983 findChildren(fi->filePath(), mimeFilters, reference, depth); 983 findChildren(fi->filePath(), mimeFilters, reference, depth);
984 } else { 984 } else {
985 if ( fi->extension(FALSE) == "desktop" ) { 985 if ( fi->extension(FALSE) == "desktop" ) {
986 DocLnk* dl = new DocLnk( fi->filePath() ); 986 DocLnk* dl = new DocLnk( fi->filePath() );
987 QFileInfo fi2(dl->file()); 987 QFileInfo fi2(dl->file());
988 bool match = FALSE; 988 bool match = FALSE;
989 if ( !fi2.exists() ) { 989 if ( !fi2.exists() ) {
990 dir.remove( dl->file() ); 990 dir.remove( dl->file() );
991 } 991 }
992 if ( mimeFilters.count() == 0 ) { 992 if ( mimeFilters.count() == 0 ) {
993 add( dl ); 993 add( dl );
994 match = TRUE; 994 match = TRUE;
995 } else { 995 } else {
996 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { 996 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
997 if ( (*it).match(dl->type()) >= 0 ) { 997 if ( (*it).match(dl->type()) >= 0 ) {
998 add(dl); 998 add(dl);
999 match = TRUE; 999 match = TRUE;
1000 } 1000 }
1001 } 1001 }
1002 } 1002 }
1003 if ( !match ) 1003 if ( !match )
1004 delete dl; 1004 delete dl;
1005 } else { 1005 } else {
1006 if ( !reference.find(fi->fileName()) ) 1006 if ( !reference.find(fi->fileName()) )
1007 reference.insert(fi->filePath(), (void*)2); 1007 reference.insert(fi->filePath(), (void*)2);
1008 } 1008 }
1009 } 1009 }
1010 } 1010 }
1011 } 1011 }
1012 } 1012 }
1013} 1013}
1014 1014
1015/*! 1015/*!
1016 \class DocLnk applnk.h 1016 \class DocLnk applnk.h
1017 \brief The DocLnk class represents loaded document references. 1017 \brief The DocLnk class represents loaded document references.
1018*/ 1018*/
1019 1019
1020/*! 1020/*!
1021 \fn DocLnk::DocLnk( const DocLnk &o ) 1021 \fn DocLnk::DocLnk( const DocLnk &o )
1022 1022
1023 Copies \a o. 1023 Copies \a o.
1024*/ 1024*/
1025 1025
1026/*! 1026/*!
1027 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1027 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1028 \a file for other files. 1028 \a file for other files.
1029*/ 1029*/
1030DocLnk::DocLnk( const QString &file ) : 1030DocLnk::DocLnk( const QString &file ) :
1031 AppLnk(file) 1031 AppLnk(file)
1032{ 1032{
1033 init(file); 1033 init(file);
1034} 1034}
1035 1035
1036/*! 1036/*!
1037 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1037 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1038 \a file for other files. If \a may_be_desktopfile is TRUE, then \a file 1038 \a file for other files. If \a may_be_desktopfile is TRUE, then \a file
1039 is first attempted to be read as a .desktop file. 1039 is first attempted to be read as a .desktop file.
1040*/ 1040*/
1041DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : 1041DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) :
1042 AppLnk(may_be_desktopfile ? file : QString::null) 1042 AppLnk(may_be_desktopfile ? file : QString::null)
1043{ 1043{
1044 init(file); 1044 init(file);
1045} 1045}
1046 1046
1047void DocLnk::init(const QString &file) 1047void DocLnk::init(const QString &file)
1048{ 1048{
1049 if ( isValid() ) { 1049 if ( isValid() ) {
1050#ifndef FORCED_DIR_STRUCTURE_WAY 1050#ifndef FORCED_DIR_STRUCTURE_WAY
1051 if ( mType.isNull() ) 1051 if ( mType.isNull() )
1052 // try to infer it 1052 // try to infer it
1053#endif 1053#endif
1054 { 1054 {
1055 int s0 = file.findRev('/'); 1055 int s0 = file.findRev('/');
1056 if ( s0 > 0 ) { 1056 if ( s0 > 0 ) {
1057 int s1 = file.findRev('/',s0-1); 1057 int s1 = file.findRev('/',s0-1);
1058 if ( s1 > 0 ) { 1058 if ( s1 > 0 ) {
1059 int s2 = file.findRev('/',s1-1); 1059 int s2 = file.findRev('/',s1-1);
1060 if ( s2 > 0 ) { 1060 if ( s2 > 0 ) {
1061 mType = file.mid(s2+1,s0-s2-1); 1061 mType = file.mid(s2+1,s0-s2-1);
1062 } 1062 }
1063 } 1063 }
1064 } 1064 }
1065 } 1065 }
1066 } else if ( QFile::exists(file) ) { 1066 } else if ( QFile::exists(file) ) {
1067 QString n = file; 1067 QString n = file;
1068 n.replace(QRegExp("\\..*"),""); 1068 n.replace(QRegExp("\\..*"),"");
1069 n.replace(QRegExp(".*/"),""); 1069 n.replace(QRegExp(".*/"),"");
1070 setName( n ); 1070 setName( n );
1071 setFile( file ); 1071 setFile( file );
1072 } 1072 }
1073 MimeType mt(mType); 1073 MimeType mt(mType);
1074 if( mt.application() ) 1074 if( mt.application() )
1075 mExec = mt.application()->exec(); 1075 mExec = mt.application()->exec();
1076} 1076}
1077 1077
1078/*! 1078/*!
1079 Constructs an invalid DocLnk. 1079 Constructs an invalid DocLnk.
1080*/ 1080*/
1081DocLnk::DocLnk() 1081DocLnk::DocLnk()
1082{ 1082{
1083} 1083}
1084 1084
1085/*! 1085/*!
1086 Destroys the DocLnk. As with AppLnk objects, a run-time error 1086 Destroys the DocLnk. As with AppLnk objects, a run-time error
1087 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). 1087 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet).
1088*/ 1088*/
1089DocLnk::~DocLnk() 1089DocLnk::~DocLnk()
1090{ 1090{
1091} 1091}
1092 1092
1093/*! 1093/*!
1094 \reimp 1094 \reimp
1095*/ 1095*/
1096QString DocLnk::exec() const 1096QString DocLnk::exec() const
1097{ 1097{
1098 MimeType mt(type()); 1098 MimeType mt(type());
1099 const AppLnk* app = mt.application(); 1099 const AppLnk* app = mt.application();
1100 if ( app ) 1100 if ( app )
1101 return app->exec(); 1101 return app->exec();
1102 else 1102 else
1103 return QString::null; 1103 return QString::null;
1104} 1104}
1105 1105
1106/*! 1106/*!
1107 \reimp 1107 \reimp
1108*/ 1108*/
1109void DocLnk::invoke(const QStringList& args) const 1109void DocLnk::invoke(const QStringList& args) const
1110{ 1110{
1111 MimeType mt(type()); 1111 MimeType mt(type());
1112 const AppLnk* app = mt.application(); 1112 const AppLnk* app = mt.application();
1113 if ( app ) { 1113 if ( app ) {
1114 QStringList a = args; 1114 QStringList a = args;
1115 if ( linkFileKnown() && QFile::exists( linkFile() ) ) 1115 if ( linkFileKnown() && QFile::exists( linkFile() ) )
1116 a.append(linkFile()); 1116 a.append(linkFile());
1117 else 1117 else
1118 a.append(file()); 1118 a.append(file());
1119 app->execute(a); 1119 app->execute(a);
1120 } 1120 }
1121} 1121}
1122 1122