summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 5763c62..35822dd 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,188 +1,192 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#define QTOPIA_INTERNAL_APPLNKASSIGN 23#define QTOPIA_INTERNAL_APPLNKASSIGN
24 24
25#include "applnk.h" 25#include "applnk.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/categories.h> 28#include <qpe/categories.h>
29#include <qpe/categoryselect.h> 29#include <qpe/categoryselect.h>
30#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
31#include <qpe/global.h> 31#include <qpe/global.h>
32#include <qpe/mimetype.h> 32#include <qpe/mimetype.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/storage.h> 34#include <qpe/storage.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36 36
37#include <qdict.h> 37#include <qdict.h>
38#include <qdir.h> 38#include <qdir.h>
39#include <qregexp.h> 39#include <qregexp.h>
40 40
41#include <qgfx_qws.h> 41#include <qgfx_qws.h>
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.]"),"_"); 53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
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 /* the size of the Pixmap */ 74 /* the size of the Pixmap */
75 enum Size {Normal = 0, Big }; 75 enum Size {Normal = 0, Big };
76 AppLnkPrivate() { 76 AppLnkPrivate() {
77 /* we want one normal and one big item */ 77 /* we want one normal and one big item */
78 78
79 QPixmap pix; 79 QPixmap pix;
80 mPixmaps.insert(0, pix ); 80 mPixmaps.insert(0, pix );
81 mPixmaps.insert(1, pix); 81 mPixmaps.insert(1, pix);
82 } 82 }
83 83
84 QStringList mCatList; // always correct 84 QStringList mCatList; // always correct
85 QArray<int> mCat; // cached value; correct if not empty 85 QArray<int> mCat; // cached value; correct if not empty
86 QMap<int, QPixmap> mPixmaps; 86 QMap<int, QPixmap> mPixmaps;
87 87
88 void updateCatListFromArray() 88 void updateCatListFromArray()
89 { 89 {
90 Categories cat( 0 ); 90 Categories cat( 0 );
91 cat.load( categoryFileName() ); 91 cat.load( categoryFileName() );
92 mCatList = cat.labels("Document View",mCat); 92 // we need to update the names for the mCat... to mCatList
93 mCatList.clear();
94 for (uint i = 0; i < mCat.count(); i++ )
95 mCatList << cat.label("Document View", mCat[i] );
96
93 } 97 }
94 98
95 void setCatArrayDirty() 99 void setCatArrayDirty()
96 { 100 {
97 mCat.resize(0); 101 mCat.resize(0);
98 } 102 }
99 103
100 void ensureCatArray() 104 void ensureCatArray()
101 { 105 {
102 if ( mCat.count() > 0 || mCatList.count()==0 ) 106 if ( mCat.count() > 0 || mCatList.count()==0 )
103 return; 107 return;
104 108
105 Categories cat( 0 ); 109 Categories cat( 0 );
106 cat.load( categoryFileName() ); 110 cat.load( categoryFileName() );
107 mCat.resize( mCatList.count() ); 111 mCat.resize( mCatList.count() );
108 int i; 112 int i;
109 QStringList::ConstIterator it; 113 QStringList::ConstIterator it;
110 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 114 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
111 ++it, i++ ) { 115 ++it, i++ ) {
112 116
113 bool number; 117 bool number;
114 int id = (*it).toInt( &number ); 118 int id = (*it).toInt( &number );
115 if ( !number ) { 119 if ( !number ) {
116 id = cat.id( "Document View", *it ); 120 id = cat.id( "Document View", *it );
117 if ( id == 0 ) 121 if ( id == 0 )
118 id = cat.addCategory( "Document View", *it ); 122 id = cat.addCategory( "Document View", *it );
119 } 123 }
120 mCat[i] = id; 124 mCat[i] = id;
121 } 125 }
122 } 126 }
123}; 127};
124 128
125/*! 129/*!
126 \class AppLnk applnk.h 130 \class AppLnk applnk.h
127 \brief The AppLnk class represents an application available on the system. 131 \brief The AppLnk class represents an application available on the system.
128 132
129 Every Qtopia application \e app has a corresponding \e app.desktop 133 Every Qtopia application \e app has a corresponding \e app.desktop
130 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
131 AppLnk object. 135 AppLnk object.
132 136
133 The AppLnk class introduces some Qtopia-specific concepts, and 137 The AppLnk class introduces some Qtopia-specific concepts, and
134 provides a variety of functions, as described in the following 138 provides a variety of functions, as described in the following
135 sections. 139 sections.
136 \tableofcontents 140 \tableofcontents
137 141
138 \target Types 142 \target Types
139 \section1 Types 143 \section1 Types
140 144
141 Every AppLnk object has a \e type. For applications, games and 145 Every AppLnk object has a \e type. For applications, games and
142 settings the type is \c Application; for documents the 146 settings the type is \c Application; for documents the
143 type is the document's MIME type. 147 type is the document's MIME type.
144 148
145 \target files-and-links 149 \target files-and-links
146 \section1 Files and Links 150 \section1 Files and Links
147 151
148 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
149 DocLnk\endlink), you don't deal directly with filenames in the 153 DocLnk\endlink), you don't deal directly with filenames in the
150 filesystem. Instead you do this: 154 filesystem. Instead you do this:
151 \code 155 \code
152 DocLnk d; 156 DocLnk d;
153 d.setType("text/plain"); 157 d.setType("text/plain");
154 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 158 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
155 \endcode 159 \endcode
156 At this point, the file() and linkFile() are unknown. Normally 160 At this point, the file() and linkFile() are unknown. Normally
157 this is uninteresting, and the names become automatically known, 161 this is uninteresting, and the names become automatically known,
158 and more importantly, becomes reserved, when you ask what they are: 162 and more importantly, becomes reserved, when you ask what they are:
159 163
160 \code 164 \code
161 QString fn = d.file(); 165 QString fn = d.file();
162 \endcode 166 \endcode
163 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
164 reservation file) to prevent the name being used by another 168 reservation file) to prevent the name being used by another
165 application. 169 application.
166 170
167 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
168 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
169 doclnk.html DocLnk\endlink objects represented by icons are 173 doclnk.html DocLnk\endlink objects represented by icons are
170 DocLnk's created just for that view - they don't have 174 DocLnk's created just for that view - they don't have
171 corresponding \c .desktop files. To avoid littering empty 175 corresponding \c .desktop files. To avoid littering empty
172 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
173 the file really needs to exist). 177 the file really needs to exist).
174 178
175 \section1 Functionality 179 \section1 Functionality
176 180
177 AppLnk objects are created by calling the constructor with the 181 AppLnk objects are created by calling the constructor with the
178 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
179 using isValid(). 183 using isValid().
180 184
181 The following functions are used to set or retrieve information 185 The following functions are used to set or retrieve information
182 about the application: 186 about the application:
183 \table 187 \table
184 \header \i Get Function \i Set Function \i Short Description 188 \header \i Get Function \i Set Function \i Short Description
185 \row \i \l name() \i \l setName() \i application's name 189 \row \i \l name() \i \l setName() \i application's name
186 \row \i \l pixmap() \i \e none \i application's icon 190 \row \i \l pixmap() \i \e none \i application's icon
187 \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
188 \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
@@ -313,192 +317,193 @@ const QArray<int>& AppLnk::categories() const
313 return d->mCat; 317 return d->mCat;
314} 318}
315 319
316/*! 320/*!
317 \fn int AppLnk::id() const 321 \fn int AppLnk::id() const
318 322
319 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,
320 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
321 duration of the current process. 325 duration of the current process.
322 326
323 \sa AppLnkSet::find() 327 \sa AppLnkSet::find()
324*/ 328*/
325 329
326/*! 330/*!
327 \fn bool AppLnk::isValid() const 331 \fn bool AppLnk::isValid() const
328 332
329 Returns TRUE if this AppLnk is valid; otherwise returns FALSE. 333 Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
330*/ 334*/
331 335
332/*! 336/*!
333 Creates an invalid AppLnk. 337 Creates an invalid AppLnk.
334 338
335 \sa isValid() 339 \sa isValid()
336*/ 340*/
337AppLnk::AppLnk() 341AppLnk::AppLnk()
338{ 342{
339 mId = 0; 343 mId = 0;
340 d = new AppLnkPrivate(); 344 d = new AppLnkPrivate();
341} 345}
342 346
343/*! 347/*!
344 Loads \a file (e.g. \e app.desktop) as an AppLnk. 348 Loads \a file (e.g. \e app.desktop) as an AppLnk.
345 349
346 \sa writeLink() 350 \sa writeLink()
347*/ 351*/
348AppLnk::AppLnk( const QString &file ) 352AppLnk::AppLnk( const QString &file )
349{ 353{
350 QStringList sl; 354 QStringList sl;
351 d = new AppLnkPrivate(); 355 d = new AppLnkPrivate();
352 if ( !file.isNull() ) { 356 if ( !file.isNull() ) {
353 Config config( file, Config::File ); 357 Config config( file, Config::File );
354 358
355 if ( config.isValid() ) { 359 if ( config.isValid() ) {
356 config.setGroup( "Desktop Entry" ); 360 config.setGroup( "Desktop Entry" );
357 361
358 mName = config.readEntry( "Name", file ); 362 mName = config.readEntry( "Name", file );
359 mExec = config.readEntry( "Exec" ); 363 mExec = config.readEntry( "Exec" );
360 mType = config.readEntry( "Type", QString::null ); 364 mType = config.readEntry( "Type", QString::null );
361 mIconFile = config.readEntry( "Icon", QString::null ); 365 mIconFile = config.readEntry( "Icon", QString::null );
362 mRotation = config.readEntry( "Rotation", "" ); 366 mRotation = config.readEntry( "Rotation", "" );
363 mComment = config.readEntry( "Comment", QString::null ); 367 mComment = config.readEntry( "Comment", QString::null );
364 // MIME types are case-insensitive. 368 // MIME types are case-insensitive.
365 mMimeTypes = config.readListEntry( "MimeType", ';' ); 369 mMimeTypes = config.readListEntry( "MimeType", ';' );
366 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 370 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
367 *it = (*it).lower(); 371 *it = (*it).lower();
368 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 372 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
369 mLinkFile = file; 373 mLinkFile = file;
370 mFile = config.readEntry("File", QString::null); 374 mFile = config.readEntry("File", QString::null);
371 if ( !mExec. isEmpty ( )) { 375 if ( !mExec. isEmpty ( )) {
372 mFile = QString::null; 376 mFile = QString::null;
373 } 377 }
374 else if ( mFile[0] != '/' ) { 378 else if ( mFile[0] != '/' ) {
375 int slash = file.findRev('/'); 379 int slash = file.findRev('/');
376 if ( slash >= 0 ) { 380 if ( slash >= 0 ) {
377 mFile = file.left(slash) + '/' + mFile; 381 mFile = file.left(slash) + '/' + mFile;
378 } 382 }
379 } 383 }
380 d->mCatList = config.readListEntry("Categories", ';'); 384 d->mCatList = config.readListEntry("Categories", ';');
381 if ( d->mCatList[0].toInt() < -1 ) { 385 if ( d->mCatList[0].toInt() < -1 ) {
382 // numeric cats in file! convert to text 386 // numeric cats in file! convert to text
383 Categories cat( 0 ); 387 Categories cat( 0 );
384 cat.load( categoryFileName() ); 388 cat.load( categoryFileName() );
385 d->mCat.resize( d->mCatList.count() ); 389 d->mCat.resize( d->mCatList.count() );
386 int i; 390 int i;
387 QStringList::ConstIterator it; 391 QStringList::ConstIterator it;
388 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 392 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
389 ++it, i++ ) { 393 ++it, i++ ) {
390 bool number; 394 bool number;
391 int id = (*it).toInt( &number ); 395 int id = (*it).toInt( &number );
392 if ( !number ) { 396 if ( !number ) {
393 // convert from text 397 // convert from text
394 id = cat.id( "Document View", *it ); 398 id = cat.id( "Document View", *it );
395 if ( id == 0 ) 399 if ( id == 0 )
396 id = cat.addCategory( "Document View", *it ); 400 id = cat.addCategory( "Document View", *it );
397 } 401 }
398 d->mCat[i] = id; 402 d->mCat[i] = id;
399 } 403 }
400 d->updateCatListFromArray(); 404 d->updateCatListFromArray();
401 } 405 }
402 } 406 }
403 } 407 }
404 mId = 0; 408 mId = 0;
405} 409}
406 410
407AppLnk& AppLnk::operator=(const AppLnk &copy) 411AppLnk& AppLnk::operator=(const AppLnk &copy)
408{ 412{
413 if ( this == &copy ) return *this;
409 if ( mId ) 414 if ( mId )
410 qWarning("Deleting AppLnk that is in an AppLnkSet"); 415 qWarning("Deleting AppLnk that is in an AppLnkSet");
411 if ( d ) 416 if ( d )
412 delete d; 417 delete d;
413 418
414 419
415 mName = copy.mName; 420 mName = copy.mName;
416 421
417 /* remove for Qtopia 3.0 -zecke */ 422 /* remove for Qtopia 3.0 -zecke */
418 mPixmap = copy.mPixmap; 423 mPixmap = copy.mPixmap;
419 mBigPixmap = copy.mBigPixmap; 424 mBigPixmap = copy.mBigPixmap;
420 425
421 mExec = copy.mExec; 426 mExec = copy.mExec;
422 mType = copy.mType; 427 mType = copy.mType;
423 mRotation = copy.mRotation; 428 mRotation = copy.mRotation;
424 mComment = copy.mComment; 429 mComment = copy.mComment;
425 mFile = copy.mFile; 430 mFile = copy.mFile;
426 mLinkFile = copy.mLinkFile; 431 mLinkFile = copy.mLinkFile;
427 mIconFile = copy.mIconFile; 432 mIconFile = copy.mIconFile;
428 mMimeTypes = copy.mMimeTypes; 433 mMimeTypes = copy.mMimeTypes;
429 mMimeTypeIcons = copy.mMimeTypeIcons; 434 mMimeTypeIcons = copy.mMimeTypeIcons;
430 mId = 0; 435 mId = 0;
431 d = new AppLnkPrivate(); 436 d = new AppLnkPrivate();
432 d->mCat = copy.d->mCat; 437 d->mCat = copy.d->mCat;
433 d->mCatList = copy.d->mCatList; 438 d->mCatList = copy.d->mCatList;
434 d->mPixmaps = copy.d->mPixmaps; 439 d->mPixmaps = copy.d->mPixmaps;
435 440
436 return *this; 441 return *this;
437} 442}
438/*! 443/*!
439 protected internally to share code 444 protected internally to share code
440 should I document that at all? 445 should I document that at all?
441 I don't know the TT style for that 446 I don't know the TT style for that
442*/ 447*/
443const QPixmap& AppLnk::pixmap( int pos, int size ) const { 448const QPixmap& AppLnk::pixmap( int pos, int size ) const {
444 if ( d->mPixmaps[pos].isNull() ) { 449 if ( d->mPixmaps[pos].isNull() ) {
445 AppLnk* that = (AppLnk*)this; 450 AppLnk* that = (AppLnk*)this;
446 if ( mIconFile.isEmpty() ) { 451 if ( mIconFile.isEmpty() ) {
447 MimeType mt(type()); 452 MimeType mt(type());
448 that->d->mPixmaps[pos] = mt.pixmap(); 453 that->d->mPixmaps[pos] = mt.pixmap();
449 if ( that->d->mPixmaps[pos].isNull() ) 454 if ( that->d->mPixmaps[pos].isNull() )
450 that->d->mPixmaps[pos].convertFromImage( 455 that->d->mPixmaps[pos].convertFromImage(
451 Resource::loadImage("UnknownDocument") 456 Resource::loadImage("UnknownDocument")
452 .smoothScale( size, size ) ); 457 .smoothScale( size, size ) );
453 return that->d->mPixmaps[pos]; 458 return that->d->mPixmaps[pos];
454 } 459 }
455 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 460 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
456 if ( unscaledIcon.isNull() ) { 461 if ( unscaledIcon.isNull() ) {
457 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 462 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
458 that->d->mPixmaps[pos].convertFromImage( 463 that->d->mPixmaps[pos].convertFromImage(
459 Resource::loadImage("UnknownDocument") 464 Resource::loadImage("UnknownDocument")
460 .smoothScale( size, size ) ); 465 .smoothScale( size, size ) );
461 } else { 466 } else {
462 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 467 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
463 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 468 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
464 } 469 }
465 return that->d->mPixmaps[pos]; 470 return that->d->mPixmaps[pos];
466 } 471 }
467 return d->mPixmaps[pos]; 472 return d->mPixmaps[pos];
468} 473}
469 474
470/*! 475/*!
471 Returns a small pixmap associated with the application. 476 Returns a small pixmap associated with the application.
472 477
473 \sa bigPixmap() setIcon() 478 \sa bigPixmap() setIcon()
474*/ 479*/
475const QPixmap& AppLnk::pixmap() const 480const QPixmap& AppLnk::pixmap() const
476{ 481{
477 if ( d->mPixmaps[0].isNull() ) { 482 if ( d->mPixmaps[0].isNull() ) {
478 return pixmap(AppLnkPrivate::Normal, smallSize ); 483 return pixmap(AppLnkPrivate::Normal, smallSize );
479 } 484 }
480 return d->mPixmaps[0]; 485 return d->mPixmaps[0];
481} 486}
482 487
483/*! 488/*!
484 Returns a large pixmap associated with the application. 489 Returns a large pixmap associated with the application.
485 490
486 \sa pixmap() setIcon() 491 \sa pixmap() setIcon()
487*/ 492*/
488const QPixmap& AppLnk::bigPixmap() const 493const QPixmap& AppLnk::bigPixmap() const
489{ 494{
490 if ( d->mPixmaps[1].isNull() ) { 495 if ( d->mPixmaps[1].isNull() ) {
491 return pixmap( AppLnkPrivate::Big, bigSize ); 496 return pixmap( AppLnkPrivate::Big, bigSize );
492 } 497 }
493 return d->mPixmaps[1]; 498 return d->mPixmaps[1];
494} 499}
495 500
496/*! 501/*!
497 Returns the type of the AppLnk. For applications, games and 502 Returns the type of the AppLnk. For applications, games and
498 settings the type is \c Application; for documents the type is the 503 settings the type is \c Application; for documents the type is the
499 document's MIME type. 504 document's MIME type.
500*/ 505*/
501QString AppLnk::type() const 506QString AppLnk::type() const
502{ 507{
503 if ( mType.isNull() ) { 508 if ( mType.isNull() ) {
504 AppLnk* that = (AppLnk*)this; 509 AppLnk* that = (AppLnk*)this;
@@ -757,193 +762,193 @@ void AppLnk::setComment( const QString& comment )
757 762
758 For applications, games and settings the type should be \c 763 For applications, games and settings the type should be \c
759 Application; for documents the type should be the document's MIME 764 Application; for documents the type should be the document's MIME
760 type. 765 type.
761 766
762 \sa type() 767 \sa type()
763*/ 768*/
764void AppLnk::setType( const QString& type ) 769void AppLnk::setType( const QString& type )
765{ 770{
766 mType = type; 771 mType = type;
767} 772}
768 773
769/*! 774/*!
770 \fn QString AppLnk::icon() const 775 \fn QString AppLnk::icon() const
771 776
772 Returns the Icon property. 777 Returns the Icon property.
773 778
774 \sa setIcon() 779 \sa setIcon()
775*/ 780*/
776 781
777/*! 782/*!
778 Sets the Icon property to \a iconname. This is the filename from 783 Sets the Icon property to \a iconname. This is the filename from
779 which the pixmap() and bigPixmap() are obtained. 784 which the pixmap() and bigPixmap() are obtained.
780 785
781 \sa icon() setSmallIconSize() setBigIconSize() 786 \sa icon() setSmallIconSize() setBigIconSize()
782*/ 787*/
783void AppLnk::setIcon( const QString& iconname ) 788void AppLnk::setIcon( const QString& iconname )
784{ 789{
785 mIconFile = iconname; 790 mIconFile = iconname;
786 QImage unscaledIcon = Resource::loadImage( mIconFile ); 791 QImage unscaledIcon = Resource::loadImage( mIconFile );
787 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 792 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
788 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 793 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
789} 794}
790 795
791/*! 796/*!
792 Sets the Categories property to \a c. 797 Sets the Categories property to \a c.
793 798
794 See the CategoryWidget for more details. 799 See the CategoryWidget for more details.
795 800
796 \sa categories() 801 \sa categories()
797*/ 802*/
798void AppLnk::setCategories( const QArray<int>& c ) 803void AppLnk::setCategories( const QArray<int>& c )
799{ 804{
800 d->mCat = c; 805 d->mCat = c;
801 d->updateCatListFromArray(); 806 d->updateCatListFromArray();
802} 807}
803 808
804/*! 809/*!
805 \fn QStringList AppLnk::mimeTypeIcons() const 810 \fn QStringList AppLnk::mimeTypeIcons() const
806 811
807 Returns the MimeTypeIcons property of the AppLnk. 812 Returns the MimeTypeIcons property of the AppLnk.
808*/ 813*/
809 814
810/*! 815/*!
811 Attempts to ensure that the link file for this AppLnk exists, 816 Attempts to ensure that the link file for this AppLnk exists,
812 including creating any required directories. Returns TRUE if 817 including creating any required directories. Returns TRUE if
813 successful; otherwise returns FALSE. 818 successful; otherwise returns FALSE.
814 819
815 You should not need to use this function. 820 You should not need to use this function.
816*/ 821*/
817bool AppLnk::ensureLinkExists() const 822bool AppLnk::ensureLinkExists() const
818{ 823{
819 QString lf = linkFile(); 824 QString lf = linkFile();
820 return prepareDirectories(lf); 825 return prepareDirectories(lf);
821} 826}
822 827
823/*! 828/*!
824 Commits the AppLnk to disk. Returns TRUE if the operation succeeded; 829 Commits the AppLnk to disk. Returns TRUE if the operation succeeded;
825 otherwise returns FALSE. 830 otherwise returns FALSE.
826 831
827 In addition, the "linkChanged(QString)" message is sent to the 832 In addition, the "linkChanged(QString)" message is sent to the
828 "QPE/System" \link qcop.html QCop\endlink channel. 833 "QPE/System" \link qcop.html QCop\endlink channel.
829*/ 834*/
830bool AppLnk::writeLink() const 835bool AppLnk::writeLink() const
831{ 836{
832 // Only re-writes settable parts 837 // Only re-writes settable parts
833 QString lf = linkFile(); 838 QString lf = linkFile();
834 if ( !ensureLinkExists() ) 839 if ( !ensureLinkExists() )
835 return FALSE; 840 return FALSE;
836 storeLink(); 841 storeLink();
837 return TRUE; 842 return TRUE;
838} 843}
839 844
840/*! 845/*!
841 \internal 846 \internal
842*/ 847*/
843void AppLnk::storeLink() const 848void AppLnk::storeLink() const
844{ 849{
845 Config config( mLinkFile, Config::File ); 850 Config config( mLinkFile, Config::File );
846 config.setGroup("Desktop Entry"); 851 config.setGroup("Desktop Entry");
847 config.writeEntry("Name",mName); 852 config.writeEntry("Name",mName);
848 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 853 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
849 config.writeEntry("Type",type()); 854 config.writeEntry("Type",type());
850 if(!rotation().isEmpty()) 855 if(!rotation().isEmpty())
851 config.writeEntry("Rotation",rotation()); 856 config.writeEntry("Rotation",rotation());
852 else 857 else
853 config.removeEntry("Rotation"); 858 config.removeEntry("Rotation");
854 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 859 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
855 QString f = file(); 860 QString f = file();
856 int i = 0; 861 int i = 0;
857 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) 862 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
858 i++; 863 i++;
859 while ( i && f[i] != '/' ) 864 while ( i && f[i] != '/' )
860 i--; 865 i--;
861 // simple case where in the same directory 866 // simple case where in the same directory
862 if ( mLinkFile.find( '/', i + 1 ) < 0 ) 867 if ( mLinkFile.find( '/', i + 1 ) < 0 )
863 f = f.mid(i+1); 868 f = f.mid(i+1);
864 // ### could do relative ie ../../otherDocs/file.doc 869 // ### could do relative ie ../../otherDocs/file.doc
865 config.writeEntry("File",f); 870 config.writeEntry("File",f);
866 config.writeEntry( "Categories", d->mCatList, ';' ); 871 config.writeEntry( "Categories", d->mCatList, ';' );
867 872
868#ifndef QT_NO_COP 873#ifndef QT_NO_COP
869 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 874 QCopEnvelope e("QPE/System", "linkChanged(QString)");
870 e << mLinkFile; 875 e << mLinkFile;
871#endif 876#endif
872} 877}
873 878
874/*! 879/*!
875 Sets the property named \a key to \a value. 880 Sets the property named \a key to \a value.
876 881
877 \sa property() 882 \sa property()
878*/ 883*/
879void AppLnk::setProperty(const QString& key, const QString& value) 884void AppLnk::setProperty(const QString& key, const QString& value)
880{ 885{
881 if ( ensureLinkExists() ) { 886 if ( ensureLinkExists() ) {
882 Config cfg(linkFile(), Config::File); 887 Config cfg(linkFile(), Config::File);
883 cfg.writeEntry(key,value); 888 cfg.writeEntry(key,value);
884 } 889 }
885} 890}
886 891
887/*! 892/*!
888 Returns the property named \a key. 893 Returns the property named \a key.
889 894
890 \sa setProperty() 895 \sa setProperty()
891*/ 896*/
892QString AppLnk::property(const QString& key) const 897QString AppLnk::property(const QString& key) const
893{ 898{
894 QString lf = linkFile(); 899 QString lf = linkFile();
895 if ( !QFile::exists(lf) ) 900 if ( !QFile::exists(lf) )
896 return QString::null; 901 return QString::null;
897 Config cfg(lf, Config::File); 902 Config cfg(lf, Config::File);
898 return cfg.readEntry(key); 903 return cfg.readEntry(key);
899} 904}
900 905
901bool AppLnk::isPreloaded() const { 906bool AppLnk::isPreloaded() const {
902 // Preload information is stored in the Launcher config in v1.5. 907 // Preload information is stored in the Launcher config in v1.5.
903 Config cfg("Launcher"); 908 Config cfg("Launcher");
904 cfg.setGroup("Preload"); 909 cfg.setGroup("Preload");
905 QStringList apps = cfg.readListEntry("Apps",','); 910 QStringList apps = cfg.readListEntry("Apps",',');
906 if (apps.contains(exec())) 911 if (apps.contains(exec()))
907 return true; 912 return true;
908 return false; 913 return false;
909} 914}
910 915
911void AppLnk::setPreloaded(bool yesNo) { 916void AppLnk::setPreloaded(bool yesNo) {
912 // Preload information is stored in the Launcher config in v1.5. 917 // Preload information is stored in the Launcher config in v1.5.
913 Config cfg("Launcher"); 918 Config cfg("Launcher");
914 cfg.setGroup("Preload"); 919 cfg.setGroup("Preload");
915 QStringList apps = cfg.readListEntry("Apps", ','); 920 QStringList apps = cfg.readListEntry("Apps", ',');
916 if (apps.contains(exec()) && !yesNo) 921 if (apps.contains(exec()) && !yesNo)
917 apps.remove(exec()); 922 apps.remove(exec());
918 else if (yesNo && !apps.contains(exec())) 923 else if (yesNo && !apps.contains(exec()))
919 apps.append(exec()); 924 apps.append(exec());
920 cfg.writeEntry("Apps", apps, ','); 925 cfg.writeEntry("Apps", apps, ',');
921} 926}
922 927
923 928
924/*! 929/*!
925 Deletes both the linkFile() and the file() associated with this AppLnk. 930 Deletes both the linkFile() and the file() associated with this AppLnk.
926 931
927 \sa removeLinkFile() 932 \sa removeLinkFile()
928*/ 933*/
929void AppLnk::removeFiles() 934void AppLnk::removeFiles()
930{ 935{
931 bool valid = isValid(); 936 bool valid = isValid();
932 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 937 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
933 if ( QFile::remove(file()) ) { 938 if ( QFile::remove(file()) ) {
934#ifndef QT_NO_COP 939#ifndef QT_NO_COP
935 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 940 QCopEnvelope e("QPE/System", "linkChanged(QString)");
936 if ( linkFileKnown() ) 941 if ( linkFileKnown() )
937 e << linkFile(); 942 e << linkFile();
938 else 943 else
939 e << file(); 944 e << file();
940#endif 945#endif
941 } else if ( valid ) { 946 } else if ( valid ) {
942 // restore link 947 // restore link
943 writeLink(); 948 writeLink();
944 } 949 }
945 } 950 }
946} 951}
947 952
948/*! 953/*!
949 Deletes the linkFile(), leaving any file() untouched. 954 Deletes the linkFile(), leaving any file() untouched.