summaryrefslogtreecommitdiff
authorzecke <zecke>2003-02-11 17:26:51 (UTC)
committer zecke <zecke>2003-02-11 17:26:51 (UTC)
commit99ccdda218112cfb0f7371fa05d7a696b8da1c40 (patch) (unidiff)
tree64d46b22de7acbccbc2ee73c406be7645ff693c3
parentdf37010a49dfa9624c9600e4ed838ec7aade1b31 (diff)
downloadopie-99ccdda218112cfb0f7371fa05d7a696b8da1c40.zip
opie-99ccdda218112cfb0f7371fa05d7a696b8da1c40.tar.gz
opie-99ccdda218112cfb0f7371fa05d7a696b8da1c40.tar.bz2
fix bug 0000591
AppLnk does not need to reload all labels but it needs to reload the names for the ids in mCat
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,220 +1,224 @@
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
189 \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
190 \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
191 \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
192 \row \i \l exec() \i \l setExec() \i executable's filename 196 \row \i \l exec() \i \l setExec() \i executable's filename
193 \row \i \l file() \i \e none \i document's filename 197 \row \i \l file() \i \e none \i document's filename
194 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename 198 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename
195 \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
196 \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}
197 \row \i \l fileKnown() \i \e none \i see \link 201 \row \i \l fileKnown() \i \e none \i see \link
198#files-and-links Files and Links\endlink above 202#files-and-links Files and Links\endlink above
199 \row \i \l linkFileKnown() \i \e none \i see \link 203 \row \i \l linkFileKnown() \i \e none \i see \link
200#files-and-links Files and Links\endlink above 204#files-and-links Files and Links\endlink above
201 \row \i \l property() \i \l setProperty()\i any AppLnk property 205 \row \i \l property() \i \l setProperty()\i any AppLnk property
202 can be retrieved or set (if writeable) using these 206 can be retrieved or set (if writeable) using these
203 \endtable 207 \endtable
204 208
205 To save an AppLnk to disk use writeLink(). To execute the 209 To save an AppLnk to disk use writeLink(). To execute the
206 application that the AppLnk object refers to, use execute(). 210 application that the AppLnk object refers to, use execute().
207 211
208 AppLnk's can be deleted from disk using removeLinkFile(). To 212 AppLnk's can be deleted from disk using removeLinkFile(). To
209 remove both the link and the application's executable use 213 remove both the link and the application's executable use
210 removeFiles(). 214 removeFiles().
211 215
212 Icon sizes can be globally changed (but only for AppLnk objects 216 Icon sizes can be globally changed (but only for AppLnk objects
213 created after the calls) with setSmallIconSize() and 217 created after the calls) with setSmallIconSize() and
214 setBigIconSize(). 218 setBigIconSize().
215 219
216 \ingroup qtopiaemb 220 \ingroup qtopiaemb
217*/ 221*/
218 222
219/*! 223/*!
220 Sets the size used for small icons to \a small pixels. 224 Sets the size used for small icons to \a small pixels.
@@ -281,256 +285,257 @@ int AppLnk::bigIconSize()
281/*! 285/*!
282 \fn QString AppLnk::rotation() const 286 \fn QString AppLnk::rotation() const
283 287
284 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
285 degrees. 289 degrees.
286*/ 290*/
287/*! 291/*!
288 \fn QString AppLnk::comment() const 292 \fn QString AppLnk::comment() const
289 293
290 Returns the Comment property. 294 Returns the Comment property.
291 295
292 \sa setComment() 296 \sa setComment()
293*/ 297*/
294/*! 298/*!
295 \fn QStringList AppLnk::mimeTypes() const 299 \fn QStringList AppLnk::mimeTypes() const
296 300
297 Returns the MimeTypes property. This is the list of MIME types 301 Returns the MimeTypes property. This is the list of MIME types
298 that the application can view or edit. 302 that the application can view or edit.
299*/ 303*/
300/*! 304/*!
301 \fn const QArray<int>& AppLnk::categories() const 305 \fn const QArray<int>& AppLnk::categories() const
302 306
303 Returns the Categories property. 307 Returns the Categories property.
304 308
305 See the CategoryWidget for more details. 309 See the CategoryWidget for more details.
306 310
307 \sa setCategories() 311 \sa setCategories()
308*/ 312*/
309 313
310const QArray<int>& AppLnk::categories() const 314const QArray<int>& AppLnk::categories() const
311{ 315{
312 d->ensureCatArray(); 316 d->ensureCatArray();
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;
505 QString f = file(); 510 QString f = file();
506 if ( !f.isNull() ) { 511 if ( !f.isNull() ) {
507 MimeType mt(f); 512 MimeType mt(f);
508 that->mType = mt.id(); 513 that->mType = mt.id();
509 return that->mType; 514 return that->mType;
510 } 515 }
511 } 516 }
512 return mType; 517 return mType;
513} 518}
514 519
515/*! 520/*!
516 Returns the file associated with the AppLnk. 521 Returns the file associated with the AppLnk.
517 522
518 \sa exec() name() 523 \sa exec() name()
519*/ 524*/
520QString AppLnk::file() const 525QString AppLnk::file() const
521{ 526{
522 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 527 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
523 AppLnk* that = (AppLnk*)this; 528 AppLnk* that = (AppLnk*)this;
524 QString ext = MimeType(mType).extension(); 529 QString ext = MimeType(mType).extension();
525 if ( !ext.isEmpty() ) 530 if ( !ext.isEmpty() )
526 ext = "." + ext; 531 ext = "." + ext;
527 if ( !mLinkFile.isEmpty() ) { 532 if ( !mLinkFile.isEmpty() ) {
528 that->mFile = 533 that->mFile =
529 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 534 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
530 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 535 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
531 qDebug("mFile now == %s", mFile.latin1()); 536 qDebug("mFile now == %s", mFile.latin1());
532 } else if ( mType.contains('/') ) { 537 } else if ( mType.contains('/') ) {
533 that->mFile = 538 that->mFile =
534 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 539 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
535 /* 540 /*
536 * A file with the same name or a .desktop file already exists 541 * A file with the same name or a .desktop file already exists
@@ -725,257 +730,257 @@ void AppLnk::setName( const QString& docname )
725 \sa file() name() 730 \sa file() name()
726*/ 731*/
727void AppLnk::setFile( const QString& filename ) 732void AppLnk::setFile( const QString& filename )
728{ 733{
729 mFile = filename; 734 mFile = filename;
730} 735}
731 736
732/*! 737/*!
733 Sets the LinkFile property to \a filename. 738 Sets the LinkFile property to \a filename.
734 739
735 \sa linkFile() 740 \sa linkFile()
736*/ 741*/
737void AppLnk::setLinkFile( const QString& filename ) 742void AppLnk::setLinkFile( const QString& filename )
738{ 743{
739 mLinkFile = filename; 744 mLinkFile = filename;
740} 745}
741 746
742/*! 747/*!
743 Sets the Comment property to \a comment. 748 Sets the Comment property to \a comment.
744 749
745 This text is displayed in the 'Details Dialog', for example if the 750 This text is displayed in the 'Details Dialog', for example if the
746 user uses the 'press-and-hold' gesture. 751 user uses the 'press-and-hold' gesture.
747 752
748 \sa comment() 753 \sa comment()
749*/ 754*/
750void AppLnk::setComment( const QString& comment ) 755void AppLnk::setComment( const QString& comment )
751{ 756{
752 mComment = comment; 757 mComment = comment;
753} 758}
754 759
755/*! 760/*!
756 Sets the Type property to \a type. 761 Sets the Type property to \a type.
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.
950 955
951 \sa removeFiles() 956 \sa removeFiles()
952*/ 957*/
953void AppLnk::removeLinkFile() 958void AppLnk::removeLinkFile()
954{ 959{
955 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 960 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
956#ifndef QT_NO_COP 961#ifndef QT_NO_COP
957 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 962 QCopEnvelope e("QPE/System", "linkChanged(QString)");
958 e << linkFile(); 963 e << linkFile();
959#endif 964#endif
960 } 965 }
961} 966}
962 967
963class AppLnkSetPrivate { 968class AppLnkSetPrivate {
964public: 969public:
965 AppLnkSetPrivate() 970 AppLnkSetPrivate()
966 { 971 {
967 typPix.setAutoDelete(TRUE); 972 typPix.setAutoDelete(TRUE);
968 typPixBig.setAutoDelete(TRUE); 973 typPixBig.setAutoDelete(TRUE);
969 typName.setAutoDelete(TRUE); 974 typName.setAutoDelete(TRUE);
970 } 975 }
971 976
972 QDict<QPixmap> typPix; 977 QDict<QPixmap> typPix;
973 QDict<QPixmap> typPixBig; 978 QDict<QPixmap> typPixBig;
974 QDict<QString> typName; 979 QDict<QString> typName;
975}; 980};
976 981
977/*! 982/*!
978 \class AppLnkSet applnk.h 983 \class AppLnkSet applnk.h
979 \brief The AppLnkSet class is a set of AppLnk objects. 984 \brief The AppLnkSet class is a set of AppLnk objects.
980*/ 985*/
981 986