summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
authorzecke <zecke>2003-04-16 10:57:59 (UTC)
committer zecke <zecke>2003-04-16 10:57:59 (UTC)
commiteeb29547890a2d162de66d7d5b98d3840a7e2d79 (patch) (unidiff)
tree973c6de7aae2fd5ba368efb87fa24234f0e12aa3 /library/applnk.cpp
parentdfa2d294b3af09bf3757a3c2294a925093e72fc6 (diff)
downloadopie-eeb29547890a2d162de66d7d5b98d3840a7e2d79.zip
opie-eeb29547890a2d162de66d7d5b98d3840a7e2d79.tar.gz
opie-eeb29547890a2d162de66d7d5b98d3840a7e2d79.tar.bz2
Fix API docu
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 35822dd..00030e8 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -79,513 +79,529 @@ public:
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 // we need to update the names for the mCat... to mCatList 92 // we need to update the names for the mCat... to mCatList
93 mCatList.clear(); 93 mCatList.clear();
94 for (uint i = 0; i < mCat.count(); i++ ) 94 for (uint i = 0; i < mCat.count(); i++ )
95 mCatList << cat.label("Document View", mCat[i] ); 95 mCatList << cat.label("Document View", mCat[i] );
96 96
97 } 97 }
98 98
99 void setCatArrayDirty() 99 void setCatArrayDirty()
100 { 100 {
101 mCat.resize(0); 101 mCat.resize(0);
102 } 102 }
103 103
104 void ensureCatArray() 104 void ensureCatArray()
105 { 105 {
106 if ( mCat.count() > 0 || mCatList.count()==0 ) 106 if ( mCat.count() > 0 || mCatList.count()==0 )
107 return; 107 return;
108 108
109 Categories cat( 0 ); 109 Categories cat( 0 );
110 cat.load( categoryFileName() ); 110 cat.load( categoryFileName() );
111 mCat.resize( mCatList.count() ); 111 mCat.resize( mCatList.count() );
112 int i; 112 int i;
113 QStringList::ConstIterator it; 113 QStringList::ConstIterator it;
114 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 114 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
115 ++it, i++ ) { 115 ++it, i++ ) {
116 116
117 bool number; 117 bool number;
118 int id = (*it).toInt( &number ); 118 int id = (*it).toInt( &number );
119 if ( !number ) { 119 if ( !number ) {
120 id = cat.id( "Document View", *it ); 120 id = cat.id( "Document View", *it );
121 if ( id == 0 ) 121 if ( id == 0 )
122 id = cat.addCategory( "Document View", *it ); 122 id = cat.addCategory( "Document View", *it );
123 } 123 }
124 mCat[i] = id; 124 mCat[i] = id;
125 } 125 }
126 } 126 }
127}; 127};
128 128
129/*! 129/*!
130 \class AppLnk applnk.h 130 \class AppLnk applnk.h
131 \brief The AppLnk class represents an application available on the system. 131 \brief The AppLnk class represents an application available on the system.
132 132
133 Every Qtopia application \e app has a corresponding \e app.desktop 133 Every Qtopia application \e app has a corresponding \e app.desktop
134 file. When one of these files is read its data is stored as an 134 file. When one of these files is read its data is stored as an
135 AppLnk object. 135 AppLnk object.
136 136
137 The AppLnk class introduces some Qtopia-specific concepts, and 137 The AppLnk class introduces some Qtopia-specific concepts, and
138 provides a variety of functions, as described in the following 138 provides a variety of functions, as described in the following
139 sections. 139 sections.
140 \tableofcontents 140 \tableofcontents
141 141
142 \target Types 142 \target Types
143 \section1 Types 143 \section1 Types
144 144
145 Every AppLnk object has a \e type. For applications, games and 145 Every AppLnk object has a \e type. For applications, games and
146 settings the type is \c Application; for documents the 146 settings the type is \c Application; for documents the
147 type is the document's MIME type. 147 type is the document's MIME type.
148 148
149 \target files-and-links 149 \target files-and-links
150 \section1 Files and Links 150 \section1 Files and Links
151 151
152 When you create an AppLnk (or more likely, a \link doclnk.html 152 When you create an AppLnk (or more likely, a \link doclnk.html
153 DocLnk\endlink), you don't deal directly with filenames in the 153 DocLnk\endlink), you don't deal directly with filenames in the
154 filesystem. Instead you do this: 154 filesystem. Instead you do this:
155 \code 155 \code
156 DocLnk d; 156 DocLnk d;
157 d.setType("text/plain"); 157 d.setType("text/plain");
158 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 158 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
159 \endcode 159 \endcode
160 At this point, the file() and linkFile() are unknown. Normally 160 At this point, the file() and linkFile() are unknown. Normally
161 this is uninteresting, and the names become automatically known, 161 this is uninteresting, and the names become automatically known,
162 and more importantly, becomes reserved, when you ask what they are: 162 and more importantly, becomes reserved, when you ask what they are:
163 163
164 \code 164 \code
165 QString fn = d.file(); 165 QString fn = d.file();
166 \endcode 166 \endcode
167 This invents a filename, and creates the file on disk (an empty 167 This invents a filename, and creates the file on disk (an empty
168 reservation file) to prevent the name being used by another 168 reservation file) to prevent the name being used by another
169 application. 169 application.
170 170
171 In some circumstances, you don't want to create the file if it 171 In some circumstances, you don't want to create the file if it
172 doesn't already exist (e.g. in the Document tab, some of the \link 172 doesn't already exist (e.g. in the Document tab, some of the \link
173 doclnk.html DocLnk\endlink objects represented by icons are 173 doclnk.html DocLnk\endlink objects represented by icons are
174 DocLnk's created just for that view - they don't have 174 DocLnk's created just for that view - they don't have
175 corresponding \c .desktop files. To avoid littering empty 175 corresponding \c .desktop files. To avoid littering empty
176 reservation files around, we check in a few places to see whether 176 reservation files around, we check in a few places to see whether
177 the file really needs to exist). 177 the file really needs to exist).
178 178
179 \section1 Functionality 179 \section1 Functionality
180 180
181 AppLnk objects are created by calling the constructor with the 181 AppLnk objects are created by calling the constructor with the
182 name of a \e .desktop file. The object can be checked for validity 182 name of a \e .desktop file. The object can be checked for validity
183 using isValid(). 183 using isValid().
184 184
185 The following functions are used to set or retrieve information 185 The following functions are used to set or retrieve information
186 about the application: 186 about the application:
187 \table 187 \table
188 \header \i Get Function \i Set Function \i Short Description 188 \header \i Get Function \i Set Function \i Short Description
189 \row \i \l name() \i \l setName() \i application's name 189 \row \i \l name() \i \l setName() \i application's name
190 \row \i \l pixmap() \i \e none \i application's icon 190 \row \i \l pixmap() \i \e none \i application's icon
191 \row \i \l bigPixmap() \i \e none \i application's large icon 191 \row \i \l bigPixmap() \i \e none \i application's large icon
192 \row \i \e none \i setIcon() \i sets the icon's filename 192 \row \i \e none \i setIcon() \i sets the icon's filename
193 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above 193 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
194 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees 194 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
195 \row \i \l comment() \i \l setComment() \i text for the Details dialog 195 \row \i \l comment() \i \l setComment() \i text for the Details dialog
196 \row \i \l exec() \i \l setExec() \i executable's filename 196 \row \i \l exec() \i \l setExec() \i executable's filename
197 \row \i \l file() \i \e none \i document's filename 197 \row \i \l file() \i \e none \i document's filename
198 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename 198 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename
199 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit 199 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
200 \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions} 200 \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions}
201 \row \i \l fileKnown() \i \e none \i see \link 201 \row \i \l fileKnown() \i \e none \i see \link
202#files-and-links Files and Links\endlink above 202#files-and-links Files and Links\endlink above
203 \row \i \l linkFileKnown() \i \e none \i see \link 203 \row \i \l linkFileKnown() \i \e none \i see \link
204#files-and-links Files and Links\endlink above 204#files-and-links Files and Links\endlink above
205 \row \i \l property() \i \l setProperty()\i any AppLnk property 205 \row \i \l property() \i \l setProperty()\i any AppLnk property
206 can be retrieved or set (if writeable) using these 206 can be retrieved or set (if writeable) using these
207 \endtable 207 \endtable
208 208
209 To save an AppLnk to disk use writeLink(). To execute the 209 To save an AppLnk to disk use writeLink(). To execute the
210 application that the AppLnk object refers to, use execute(). 210 application that the AppLnk object refers to, use execute().
211 211
212 AppLnk's can be deleted from disk using removeLinkFile(). To 212 AppLnk's can be deleted from disk using removeLinkFile(). To
213 remove both the link and the application's executable use 213 remove both the link and the application's executable use
214 removeFiles(). 214 removeFiles().
215 215
216 Icon sizes can be globally changed (but only for AppLnk objects 216 Icon sizes can be globally changed (but only for AppLnk objects
217 created after the calls) with setSmallIconSize() and 217 created after the calls) with setSmallIconSize() and
218 setBigIconSize(). 218 setBigIconSize().
219 219
220 \ingroup qtopiaemb 220 \ingroup qtopiaemb
221*/ 221*/
222 222
223/*! 223/*!
224 Sets the size used for small icons to \a small pixels. 224 Sets the size used for small icons to \a small pixels.
225 Only affects AppLnk objects created after the call. 225 Only affects AppLnk objects created after the call.
226 226
227 \sa smallIconSize() setIcon() 227 \sa smallIconSize() setIcon()
228*/ 228*/
229void AppLnk::setSmallIconSize(int small) 229void AppLnk::setSmallIconSize(int small)
230{ 230{
231 smallSize = small; 231 smallSize = small;
232} 232}
233 233
234/*! 234/*!
235 Returns the size used for small icons. 235 Returns the size used for small icons.
236 236
237 \sa setSmallIconSize() setIcon() 237 \sa setSmallIconSize() setIcon()
238*/ 238*/
239int AppLnk::smallIconSize() 239int AppLnk::smallIconSize()
240{ 240{
241 return smallSize; 241 return smallSize;
242} 242}
243 243
244 244
245/*! 245/*!
246 Sets the size used for large icons to \a big pixels. 246 Sets the size used for large icons to \a big pixels.
247 Only affects AppLnk objects created after the call. 247 Only affects AppLnk objects created after the call.
248 248
249 \sa bigIconSize() setIcon() 249 \sa bigIconSize() setIcon()
250*/ 250*/
251void AppLnk::setBigIconSize(int big) 251void AppLnk::setBigIconSize(int big)
252{ 252{
253 bigSize = big; 253 bigSize = big;
254} 254}
255 255
256/*! 256/*!
257 Returns the size used for large icons. 257 Returns the size used for large icons.
258 258
259 \sa setBigIconSize() setIcon() 259 \sa setBigIconSize() setIcon()
260*/ 260*/
261int AppLnk::bigIconSize() 261int AppLnk::bigIconSize()
262{ 262{
263 return bigSize; 263 return bigSize;
264} 264}
265 265
266 266
267/*! 267/*!
268 \fn QString AppLnk::name() const 268 \fn QString AppLnk::name() const
269 269
270 Returns the Name property. This is the user-visible name for the 270 Returns the Name property. This is the user-visible name for the
271 document or application, not the filename. 271 document or application, not the filename.
272 272
273 See \link #files-and-links Files and Links\endlink. 273 See \link #files-and-links Files and Links\endlink.
274 274
275 \sa setName() 275 \sa setName()
276*/ 276*/
277/*! 277/*!
278 \fn QString AppLnk::exec() const 278 \fn QString AppLnk::exec() const
279 279
280 Returns the Exec property. This is the name of the executable 280 Returns the Exec property. This is the name of the executable
281 program associated with the AppLnk. 281 program associated with the AppLnk.
282 282
283 \sa setExec() 283 \sa setExec()
284*/ 284*/
285/*! 285/*!
286 \fn QString AppLnk::rotation() const 286 \fn QString AppLnk::rotation() const
287 287
288 Returns the Rotation property. The value is 0, 90, 180 or 270 288 Returns the Rotation property. The value is 0, 90, 180 or 270
289 degrees. 289 degrees.
290*/ 290*/
291/*! 291/*!
292 \fn QString AppLnk::comment() const 292 \fn QString AppLnk::comment() const
293 293
294 Returns the Comment property. 294 Returns the Comment property.
295 295
296 \sa setComment() 296 \sa setComment()
297*/ 297*/
298/*! 298/*!
299 \fn QStringList AppLnk::mimeTypes() const 299 \fn QStringList AppLnk::mimeTypes() const
300 300
301 Returns the MimeTypes property. This is the list of MIME types 301 Returns the MimeTypes property. This is the list of MIME types
302 that the application can view or edit. 302 that the application can view or edit.
303*/ 303*/
304/*! 304/*!
305 \fn const QArray<int>& AppLnk::categories() const 305 \fn const QArray<int>& AppLnk::categories() const
306 306
307 Returns the Categories property. 307 Returns the Categories property.
308 308
309 See the CategoryWidget for more details. 309 See the CategoryWidget for more details.
310 310
311 \sa setCategories() 311 \sa setCategories()
312*/ 312*/
313 313
314const QArray<int>& AppLnk::categories() const 314const QArray<int>& AppLnk::categories() const
315{ 315{
316 d->ensureCatArray(); 316 d->ensureCatArray();
317 return d->mCat; 317 return d->mCat;
318} 318}
319 319
320/*! 320/*!
321 \fn int AppLnk::id() const 321 \fn int AppLnk::id() const
322 322
323 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, 323 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet,
324 this value is 0, otherwise it is a value that is unique for the 324 this value is 0, otherwise it is a value that is unique for the
325 duration of the current process. 325 duration of the current process.
326 326
327 \sa AppLnkSet::find() 327 \sa AppLnkSet::find()
328*/ 328*/
329 329
330/*! 330/*!
331 \fn bool AppLnk::isValid() const 331 \fn bool AppLnk::isValid() const
332 332
333 Returns TRUE if this AppLnk is valid; otherwise returns FALSE. 333 Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
334*/ 334*/
335/*!
336 \fn bool AppLnk::fileKnown() const
337
338 If the with the AppLnk associated file is not equal to QString::null
339*/
340/*!
341 \fn bool AppLnk::linkFileKnown()const
342
343 The filename of the AppLnk
335 344
345*/
346/*!
347 \fn void AppLnk::setRotation( const QString& )
348
349 The default rotation of the associated application. This
350 function is included inline for binary compatible issues
351*/
336/*! 352/*!
337 Creates an invalid AppLnk. 353 Creates an invalid AppLnk.
338 354
339 \sa isValid() 355 \sa isValid()
340*/ 356*/
341AppLnk::AppLnk() 357AppLnk::AppLnk()
342{ 358{
343 mId = 0; 359 mId = 0;
344 d = new AppLnkPrivate(); 360 d = new AppLnkPrivate();
345} 361}
346 362
347/*! 363/*!
348 Loads \a file (e.g. \e app.desktop) as an AppLnk. 364 Loads \a file (e.g. \e app.desktop) as an AppLnk.
349 365
350 \sa writeLink() 366 \sa writeLink()
351*/ 367*/
352AppLnk::AppLnk( const QString &file ) 368AppLnk::AppLnk( const QString &file )
353{ 369{
354 QStringList sl; 370 QStringList sl;
355 d = new AppLnkPrivate(); 371 d = new AppLnkPrivate();
356 if ( !file.isNull() ) { 372 if ( !file.isNull() ) {
357 Config config( file, Config::File ); 373 Config config( file, Config::File );
358 374
359 if ( config.isValid() ) { 375 if ( config.isValid() ) {
360 config.setGroup( "Desktop Entry" ); 376 config.setGroup( "Desktop Entry" );
361 377
362 mName = config.readEntry( "Name", file ); 378 mName = config.readEntry( "Name", file );
363 mExec = config.readEntry( "Exec" ); 379 mExec = config.readEntry( "Exec" );
364 mType = config.readEntry( "Type", QString::null ); 380 mType = config.readEntry( "Type", QString::null );
365 mIconFile = config.readEntry( "Icon", QString::null ); 381 mIconFile = config.readEntry( "Icon", QString::null );
366 mRotation = config.readEntry( "Rotation", "" ); 382 mRotation = config.readEntry( "Rotation", "" );
367 mComment = config.readEntry( "Comment", QString::null ); 383 mComment = config.readEntry( "Comment", QString::null );
368 // MIME types are case-insensitive. 384 // MIME types are case-insensitive.
369 mMimeTypes = config.readListEntry( "MimeType", ';' ); 385 mMimeTypes = config.readListEntry( "MimeType", ';' );
370 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 386 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
371 *it = (*it).lower(); 387 *it = (*it).lower();
372 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 388 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
373 mLinkFile = file; 389 mLinkFile = file;
374 mFile = config.readEntry("File", QString::null); 390 mFile = config.readEntry("File", QString::null);
375 if ( !mExec. isEmpty ( )) { 391 if ( !mExec. isEmpty ( )) {
376 mFile = QString::null; 392 mFile = QString::null;
377 } 393 }
378 else if ( mFile[0] != '/' ) { 394 else if ( mFile[0] != '/' ) {
379 int slash = file.findRev('/'); 395 int slash = file.findRev('/');
380 if ( slash >= 0 ) { 396 if ( slash >= 0 ) {
381 mFile = file.left(slash) + '/' + mFile; 397 mFile = file.left(slash) + '/' + mFile;
382 } 398 }
383 } 399 }
384 d->mCatList = config.readListEntry("Categories", ';'); 400 d->mCatList = config.readListEntry("Categories", ';');
385 if ( d->mCatList[0].toInt() < -1 ) { 401 if ( d->mCatList[0].toInt() < -1 ) {
386 // numeric cats in file! convert to text 402 // numeric cats in file! convert to text
387 Categories cat( 0 ); 403 Categories cat( 0 );
388 cat.load( categoryFileName() ); 404 cat.load( categoryFileName() );
389 d->mCat.resize( d->mCatList.count() ); 405 d->mCat.resize( d->mCatList.count() );
390 int i; 406 int i;
391 QStringList::ConstIterator it; 407 QStringList::ConstIterator it;
392 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 408 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
393 ++it, i++ ) { 409 ++it, i++ ) {
394 bool number; 410 bool number;
395 int id = (*it).toInt( &number ); 411 int id = (*it).toInt( &number );
396 if ( !number ) { 412 if ( !number ) {
397 // convert from text 413 // convert from text
398 id = cat.id( "Document View", *it ); 414 id = cat.id( "Document View", *it );
399 if ( id == 0 ) 415 if ( id == 0 )
400 id = cat.addCategory( "Document View", *it ); 416 id = cat.addCategory( "Document View", *it );
401 } 417 }
402 d->mCat[i] = id; 418 d->mCat[i] = id;
403 } 419 }
404 d->updateCatListFromArray(); 420 d->updateCatListFromArray();
405 } 421 }
406 } 422 }
407 } 423 }
408 mId = 0; 424 mId = 0;
409} 425}
410 426
411AppLnk& AppLnk::operator=(const AppLnk &copy) 427AppLnk& AppLnk::operator=(const AppLnk &copy)
412{ 428{
413 if ( this == &copy ) return *this; 429 if ( this == &copy ) return *this;
414 if ( mId ) 430 if ( mId )
415 qWarning("Deleting AppLnk that is in an AppLnkSet"); 431 qWarning("Deleting AppLnk that is in an AppLnkSet");
416 if ( d ) 432 if ( d )
417 delete d; 433 delete d;
418 434
419 435
420 mName = copy.mName; 436 mName = copy.mName;
421 437
422 /* remove for Qtopia 3.0 -zecke */ 438 /* remove for Qtopia 3.0 -zecke */
423 mPixmap = copy.mPixmap; 439 mPixmap = copy.mPixmap;
424 mBigPixmap = copy.mBigPixmap; 440 mBigPixmap = copy.mBigPixmap;
425 441
426 mExec = copy.mExec; 442 mExec = copy.mExec;
427 mType = copy.mType; 443 mType = copy.mType;
428 mRotation = copy.mRotation; 444 mRotation = copy.mRotation;
429 mComment = copy.mComment; 445 mComment = copy.mComment;
430 mFile = copy.mFile; 446 mFile = copy.mFile;
431 mLinkFile = copy.mLinkFile; 447 mLinkFile = copy.mLinkFile;
432 mIconFile = copy.mIconFile; 448 mIconFile = copy.mIconFile;
433 mMimeTypes = copy.mMimeTypes; 449 mMimeTypes = copy.mMimeTypes;
434 mMimeTypeIcons = copy.mMimeTypeIcons; 450 mMimeTypeIcons = copy.mMimeTypeIcons;
435 mId = 0; 451 mId = 0;
436 d = new AppLnkPrivate(); 452 d = new AppLnkPrivate();
437 d->mCat = copy.d->mCat; 453 d->mCat = copy.d->mCat;
438 d->mCatList = copy.d->mCatList; 454 d->mCatList = copy.d->mCatList;
439 d->mPixmaps = copy.d->mPixmaps; 455 d->mPixmaps = copy.d->mPixmaps;
440 456
441 return *this; 457 return *this;
442} 458}
443/*! 459/*!
444 protected internally to share code 460 protected internally to share code
445 should I document that at all? 461 should I document that at all?
446 I don't know the TT style for that 462 I don't know the TT style for that
447*/ 463*/
448const QPixmap& AppLnk::pixmap( int pos, int size ) const { 464const QPixmap& AppLnk::pixmap( int pos, int size ) const {
449 if ( d->mPixmaps[pos].isNull() ) { 465 if ( d->mPixmaps[pos].isNull() ) {
450 AppLnk* that = (AppLnk*)this; 466 AppLnk* that = (AppLnk*)this;
451 if ( mIconFile.isEmpty() ) { 467 if ( mIconFile.isEmpty() ) {
452 MimeType mt(type()); 468 MimeType mt(type());
453 that->d->mPixmaps[pos] = mt.pixmap(); 469 that->d->mPixmaps[pos] = mt.pixmap();
454 if ( that->d->mPixmaps[pos].isNull() ) 470 if ( that->d->mPixmaps[pos].isNull() )
455 that->d->mPixmaps[pos].convertFromImage( 471 that->d->mPixmaps[pos].convertFromImage(
456 Resource::loadImage("UnknownDocument") 472 Resource::loadImage("UnknownDocument")
457 .smoothScale( size, size ) ); 473 .smoothScale( size, size ) );
458 return that->d->mPixmaps[pos]; 474 return that->d->mPixmaps[pos];
459 } 475 }
460 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 476 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
461 if ( unscaledIcon.isNull() ) { 477 if ( unscaledIcon.isNull() ) {
462 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 478 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
463 that->d->mPixmaps[pos].convertFromImage( 479 that->d->mPixmaps[pos].convertFromImage(
464 Resource::loadImage("UnknownDocument") 480 Resource::loadImage("UnknownDocument")
465 .smoothScale( size, size ) ); 481 .smoothScale( size, size ) );
466 } else { 482 } else {
467 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 483 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
468 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 484 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
469 } 485 }
470 return that->d->mPixmaps[pos]; 486 return that->d->mPixmaps[pos];
471 } 487 }
472 return d->mPixmaps[pos]; 488 return d->mPixmaps[pos];
473} 489}
474 490
475/*! 491/*!
476 Returns a small pixmap associated with the application. 492 Returns a small pixmap associated with the application.
477 493
478 \sa bigPixmap() setIcon() 494 \sa bigPixmap() setIcon()
479*/ 495*/
480const QPixmap& AppLnk::pixmap() const 496const QPixmap& AppLnk::pixmap() const
481{ 497{
482 if ( d->mPixmaps[0].isNull() ) { 498 if ( d->mPixmaps[0].isNull() ) {
483 return pixmap(AppLnkPrivate::Normal, smallSize ); 499 return pixmap(AppLnkPrivate::Normal, smallSize );
484 } 500 }
485 return d->mPixmaps[0]; 501 return d->mPixmaps[0];
486} 502}
487 503
488/*! 504/*!
489 Returns a large pixmap associated with the application. 505 Returns a large pixmap associated with the application.
490 506
491 \sa pixmap() setIcon() 507 \sa pixmap() setIcon()
492*/ 508*/
493const QPixmap& AppLnk::bigPixmap() const 509const QPixmap& AppLnk::bigPixmap() const
494{ 510{
495 if ( d->mPixmaps[1].isNull() ) { 511 if ( d->mPixmaps[1].isNull() ) {
496 return pixmap( AppLnkPrivate::Big, bigSize ); 512 return pixmap( AppLnkPrivate::Big, bigSize );
497 } 513 }
498 return d->mPixmaps[1]; 514 return d->mPixmaps[1];
499} 515}
500 516
501/*! 517/*!
502 Returns the type of the AppLnk. For applications, games and 518 Returns the type of the AppLnk. For applications, games and
503 settings the type is \c Application; for documents the type is the 519 settings the type is \c Application; for documents the type is the
504 document's MIME type. 520 document's MIME type.
505*/ 521*/
506QString AppLnk::type() const 522QString AppLnk::type() const
507{ 523{
508 if ( mType.isNull() ) { 524 if ( mType.isNull() ) {
509 AppLnk* that = (AppLnk*)this; 525 AppLnk* that = (AppLnk*)this;
510 QString f = file(); 526 QString f = file();
511 if ( !f.isNull() ) { 527 if ( !f.isNull() ) {
512 MimeType mt(f); 528 MimeType mt(f);
513 that->mType = mt.id(); 529 that->mType = mt.id();
514 return that->mType; 530 return that->mType;
515 } 531 }
516 } 532 }
517 return mType; 533 return mType;
518} 534}
519 535
520/*! 536/*!
521 Returns the file associated with the AppLnk. 537 Returns the file associated with the AppLnk.
522 538
523 \sa exec() name() 539 \sa exec() name()
524*/ 540*/
525QString AppLnk::file() const 541QString AppLnk::file() const
526{ 542{
527 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 543 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
528 AppLnk* that = (AppLnk*)this; 544 AppLnk* that = (AppLnk*)this;
529 QString ext = MimeType(mType).extension(); 545 QString ext = MimeType(mType).extension();
530 if ( !ext.isEmpty() ) 546 if ( !ext.isEmpty() )
531 ext = "." + ext; 547 ext = "." + ext;
532 if ( !mLinkFile.isEmpty() ) { 548 if ( !mLinkFile.isEmpty() ) {
533 that->mFile = 549 that->mFile =
534 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 550 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
535 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 551 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
536 qDebug("mFile now == %s", mFile.latin1()); 552 qDebug("mFile now == %s", mFile.latin1());
537 } else if ( mType.contains('/') ) { 553 } else if ( mType.contains('/') ) {
538 that->mFile = 554 that->mFile =
539 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 555 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
540 /* 556 /*
541 * A file with the same name or a .desktop file already exists 557 * A file with the same name or a .desktop file already exists
542 */ 558 */
543 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { 559 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
544 int n=1; 560 int n=1;
545 QString nn; 561 QString nn;
546 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 562 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
547 || QFile::exists(nn+".desktop")) 563 || QFile::exists(nn+".desktop"))
548 n++; 564 n++;
549 that->mFile = nn; 565 that->mFile = nn;
550 } 566 }
551 that->mLinkFile = that->mFile+".desktop"; 567 that->mLinkFile = that->mFile+".desktop";
552 that->mFile += ext; 568 that->mFile += ext;
553 } 569 }
554 prepareDirectories(that->mFile); 570 prepareDirectories(that->mFile);
555 if ( !that->mFile.isEmpty() ) { 571 if ( !that->mFile.isEmpty() ) {
556 QFile f(that->mFile); 572 QFile f(that->mFile);
557 if ( !f.open(IO_WriteOnly) ) 573 if ( !f.open(IO_WriteOnly) )
558 that->mFile = QString::null; 574 that->mFile = QString::null;
559 return that->mFile; 575 return that->mFile;
560 } 576 }
561 } 577 }
562 return mFile; 578 return mFile;
563} 579}
564 580
565/*! 581/*!
566 Returns the desktop file corresponding to this AppLnk. 582 Returns the desktop file corresponding to this AppLnk.
567 583
568 \sa file() exec() name() 584 \sa file() exec() name()
569*/ 585*/
570QString AppLnk::linkFile() const 586QString AppLnk::linkFile() const
571{ 587{
572 if ( mLinkFile.isNull() ) { 588 if ( mLinkFile.isNull() ) {
573 AppLnk* that = (AppLnk*)this; 589 AppLnk* that = (AppLnk*)this;
574 if ( type().contains('/') ) { 590 if ( type().contains('/') ) {
575 StorageInfo storage; 591 StorageInfo storage;
576 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 592 const FileSystem *fs = storage.fileSystemOf( that->mFile );
577 /* tmpfs + and ramfs are available too but not removable 593 /* tmpfs + and ramfs are available too but not removable
578 * either we fix storage or add this 594 * either we fix storage or add this
579 */ 595 */
580 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { 596 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
581 that->mLinkFile = fs->path(); 597 that->mLinkFile = fs->path();
582 } else 598 } else
583 that->mLinkFile = getenv( "HOME" ); 599 that->mLinkFile = getenv( "HOME" );
584 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 600 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
585 601
586 /* the desktop file exists make sure we don't point to the same file */ 602 /* the desktop file exists make sure we don't point to the same file */
587 if ( QFile::exists(that->mLinkFile+".desktop") ) { 603 if ( QFile::exists(that->mLinkFile+".desktop") ) {
588 AppLnk lnk( that->mLinkFile + ".desktop" ); 604 AppLnk lnk( that->mLinkFile + ".desktop" );
589 605
590 /* the linked is different */ 606 /* the linked is different */
591 if(that->file() != lnk.file() ) { 607 if(that->file() != lnk.file() ) {