author | zecke <zecke> | 2005-02-23 22:59:25 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-02-23 22:59:25 (UTC) |
commit | 729a178d1da1b8f80e4b1f6b0fc2c6a4cd15a403 (patch) (unidiff) | |
tree | 968a422532f4596d2ab5530127e28cd948776778 | |
parent | 9e2e6d962e1e2d3e5c17641d9a9b21a5906bd262 (diff) | |
download | opie-729a178d1da1b8f80e4b1f6b0fc2c6a4cd15a403.zip opie-729a178d1da1b8f80e4b1f6b0fc2c6a4cd15a403.tar.gz opie-729a178d1da1b8f80e4b1f6b0fc2c6a4cd15a403.tar.bz2 |
Fix crappy indenting on the methods I'm about to touch. Even TT fixed it...
-rw-r--r-- | library/applnk.cpp | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 80f2c62..c82d3b9 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -207,1178 +207,1180 @@ public: | |||
207 | application that the AppLnk object refers to, use execute(). | 207 | application that the AppLnk object refers to, use execute(). |
208 | 208 | ||
209 | AppLnk's can be deleted from disk using removeLinkFile(). To | 209 | AppLnk's can be deleted from disk using removeLinkFile(). To |
210 | remove both the link and the application's executable use | 210 | remove both the link and the application's executable use |
211 | removeFiles(). | 211 | removeFiles(). |
212 | 212 | ||
213 | Icon sizes can be globally changed (but only for AppLnk objects | 213 | Icon sizes can be globally changed (but only for AppLnk objects |
214 | created after the calls) with setSmallIconSize() and | 214 | created after the calls) with setSmallIconSize() and |
215 | setBigIconSize(). | 215 | setBigIconSize(). |
216 | 216 | ||
217 | \ingroup qtopiaemb | 217 | \ingroup qtopiaemb |
218 | */ | 218 | */ |
219 | 219 | ||
220 | /*! | 220 | /*! |
221 | Sets the size used for small icons to \a small pixels. | 221 | Sets the size used for small icons to \a small pixels. |
222 | Only affects AppLnk objects created after the call. | 222 | Only affects AppLnk objects created after the call. |
223 | 223 | ||
224 | \sa smallIconSize() setIcon() | 224 | \sa smallIconSize() setIcon() |
225 | */ | 225 | */ |
226 | void AppLnk::setSmallIconSize(int small) | 226 | void AppLnk::setSmallIconSize(int small) |
227 | { | 227 | { |
228 | smallSize = small; | 228 | smallSize = small; |
229 | } | 229 | } |
230 | 230 | ||
231 | /*! | 231 | /*! |
232 | Returns the size used for small icons. | 232 | Returns the size used for small icons. |
233 | 233 | ||
234 | \sa setSmallIconSize() setIcon() | 234 | \sa setSmallIconSize() setIcon() |
235 | */ | 235 | */ |
236 | int AppLnk::smallIconSize() | 236 | int AppLnk::smallIconSize() |
237 | { | 237 | { |
238 | return smallSize; | 238 | return smallSize; |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | /*! | 242 | /*! |
243 | Sets the size used for large icons to \a big pixels. | 243 | Sets the size used for large icons to \a big pixels. |
244 | Only affects AppLnk objects created after the call. | 244 | Only affects AppLnk objects created after the call. |
245 | 245 | ||
246 | \sa bigIconSize() setIcon() | 246 | \sa bigIconSize() setIcon() |
247 | */ | 247 | */ |
248 | void AppLnk::setBigIconSize(int big) | 248 | void AppLnk::setBigIconSize(int big) |
249 | { | 249 | { |
250 | bigSize = big; | 250 | bigSize = big; |
251 | } | 251 | } |
252 | 252 | ||
253 | /*! | 253 | /*! |
254 | Returns the size used for large icons. | 254 | Returns the size used for large icons. |
255 | 255 | ||
256 | \sa setBigIconSize() setIcon() | 256 | \sa setBigIconSize() setIcon() |
257 | */ | 257 | */ |
258 | int AppLnk::bigIconSize() | 258 | int AppLnk::bigIconSize() |
259 | { | 259 | { |
260 | return bigSize; | 260 | return bigSize; |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | /*! | 264 | /*! |
265 | \fn QString AppLnk::name() const | 265 | \fn QString AppLnk::name() const |
266 | 266 | ||
267 | Returns the Name property. This is the user-visible name for the | 267 | Returns the Name property. This is the user-visible name for the |
268 | document or application, not the filename. | 268 | document or application, not the filename. |
269 | 269 | ||
270 | See \link #files-and-links Files and Links\endlink. | 270 | See \link #files-and-links Files and Links\endlink. |
271 | 271 | ||
272 | \sa setName() | 272 | \sa setName() |
273 | */ | 273 | */ |
274 | /*! | 274 | /*! |
275 | \fn QString AppLnk::exec() const | 275 | \fn QString AppLnk::exec() const |
276 | 276 | ||
277 | Returns the Exec property. This is the name of the executable | 277 | Returns the Exec property. This is the name of the executable |
278 | program associated with the AppLnk. | 278 | program associated with the AppLnk. |
279 | 279 | ||
280 | \sa setExec() | 280 | \sa setExec() |
281 | */ | 281 | */ |
282 | /*! | 282 | /*! |
283 | \fn QString AppLnk::rotation() const | 283 | \fn QString AppLnk::rotation() const |
284 | 284 | ||
285 | Returns the Rotation property. The value is 0, 90, 180 or 270 | 285 | Returns the Rotation property. The value is 0, 90, 180 or 270 |
286 | degrees. | 286 | degrees. |
287 | */ | 287 | */ |
288 | /*! | 288 | /*! |
289 | \fn QString AppLnk::comment() const | 289 | \fn QString AppLnk::comment() const |
290 | 290 | ||
291 | Returns the Comment property. | 291 | Returns the Comment property. |
292 | 292 | ||
293 | \sa setComment() | 293 | \sa setComment() |
294 | */ | 294 | */ |
295 | /*! | 295 | /*! |
296 | \fn QStringList AppLnk::mimeTypes() const | 296 | \fn QStringList AppLnk::mimeTypes() const |
297 | 297 | ||
298 | Returns the MimeTypes property. This is the list of MIME types | 298 | Returns the MimeTypes property. This is the list of MIME types |
299 | that the application can view or edit. | 299 | that the application can view or edit. |
300 | */ | 300 | */ |
301 | /*! | 301 | /*! |
302 | \fn const QArray<int>& AppLnk::categories() const | 302 | \fn const QArray<int>& AppLnk::categories() const |
303 | 303 | ||
304 | Returns the Categories property. | 304 | Returns the Categories property. |
305 | 305 | ||
306 | See the CategoryWidget for more details. | 306 | See the CategoryWidget for more details. |
307 | 307 | ||
308 | \sa setCategories() | 308 | \sa setCategories() |
309 | */ | 309 | */ |
310 | 310 | ||
311 | const QArray<int>& AppLnk::categories() const | 311 | const QArray<int>& AppLnk::categories() const |
312 | { | 312 | { |
313 | d->ensureCatArray(); | 313 | d->ensureCatArray(); |
314 | return d->mCat; | 314 | return d->mCat; |
315 | } | 315 | } |
316 | 316 | ||
317 | /*! | 317 | /*! |
318 | \fn int AppLnk::id() const | 318 | \fn int AppLnk::id() const |
319 | 319 | ||
320 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, | 320 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, |
321 | this value is 0, otherwise it is a value that is unique for the | 321 | this value is 0, otherwise it is a value that is unique for the |
322 | duration of the current process. | 322 | duration of the current process. |
323 | 323 | ||
324 | \sa AppLnkSet::find() | 324 | \sa AppLnkSet::find() |
325 | */ | 325 | */ |
326 | 326 | ||
327 | /*! | 327 | /*! |
328 | \fn bool AppLnk::isValid() const | 328 | \fn bool AppLnk::isValid() const |
329 | 329 | ||
330 | Returns TRUE if this AppLnk is valid; otherwise returns FALSE. | 330 | Returns TRUE if this AppLnk is valid; otherwise returns FALSE. |
331 | */ | 331 | */ |
332 | /*! | 332 | /*! |
333 | \fn bool AppLnk::fileKnown() const | 333 | \fn bool AppLnk::fileKnown() const |
334 | 334 | ||
335 | If the with the AppLnk associated file is not equal to QString::null | 335 | If the with the AppLnk associated file is not equal to QString::null |
336 | */ | 336 | */ |
337 | /*! | 337 | /*! |
338 | \fn bool AppLnk::linkFileKnown()const | 338 | \fn bool AppLnk::linkFileKnown()const |
339 | 339 | ||
340 | The filename of the AppLnk | 340 | The filename of the AppLnk |
341 | 341 | ||
342 | */ | 342 | */ |
343 | /*! | 343 | /*! |
344 | \fn void AppLnk::setRotation( const QString& ) | 344 | \fn void AppLnk::setRotation( const QString& ) |
345 | 345 | ||
346 | The default rotation of the associated application. This | 346 | The default rotation of the associated application. This |
347 | function is included inline for binary compatible issues | 347 | function is included inline for binary compatible issues |
348 | */ | 348 | */ |
349 | /*! | 349 | /*! |
350 | Creates an invalid AppLnk. | 350 | Creates an invalid AppLnk. |
351 | 351 | ||
352 | \sa isValid() | 352 | \sa isValid() |
353 | */ | 353 | */ |
354 | AppLnk::AppLnk() | 354 | AppLnk::AppLnk() |
355 | { | 355 | { |
356 | mId = 0; | 356 | mId = 0; |
357 | d = new AppLnkPrivate(); | 357 | d = new AppLnkPrivate(); |
358 | } | 358 | } |
359 | 359 | ||
360 | /*! | 360 | /*! |
361 | Loads \a file (e.g. \e app.desktop) as an AppLnk. | 361 | Loads \a file (e.g. \e app.desktop) as an AppLnk. |
362 | 362 | ||
363 | \sa writeLink() | 363 | \sa writeLink() |
364 | */ | 364 | */ |
365 | AppLnk::AppLnk( const QString &file ) | 365 | AppLnk::AppLnk( const QString &file ) |
366 | { | 366 | { |
367 | QStringList sl; | 367 | QStringList sl; |
368 | d = new AppLnkPrivate(); | 368 | d = new AppLnkPrivate(); |
369 | if ( !file.isNull() ) { | 369 | if ( !file.isNull() ) { |
370 | Config config( file, Config::File ); | 370 | Config config( file, Config::File ); |
371 | 371 | ||
372 | if ( config.isValid() ) { | 372 | if ( config.isValid() ) { |
373 | config.setGroup( "Desktop Entry" ); | 373 | config.setGroup( "Desktop Entry" ); |
374 | 374 | ||
375 | mName = config.readEntry( "Name", file ); | 375 | mName = config.readEntry( "Name", file ); |
376 | mExec = config.readEntry( "Exec" ); | 376 | mExec = config.readEntry( "Exec" ); |
377 | mType = config.readEntry( "Type", QString::null ); | 377 | mType = config.readEntry( "Type", QString::null ); |
378 | mIconFile = config.readEntry( "Icon", QString::null ); | 378 | mIconFile = config.readEntry( "Icon", QString::null ); |
379 | mRotation = config.readEntry( "Rotation", "" ); | 379 | mRotation = config.readEntry( "Rotation", "" ); |
380 | mComment = config.readEntry( "Comment", QString::null ); | 380 | mComment = config.readEntry( "Comment", QString::null ); |
381 | // MIME types are case-insensitive. | 381 | // MIME types are case-insensitive. |
382 | mMimeTypes = config.readListEntry( "MimeType", ';' ); | 382 | mMimeTypes = config.readListEntry( "MimeType", ';' ); |
383 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) | 383 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) |
384 | *it = (*it).lower(); | 384 | *it = (*it).lower(); |
385 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); | 385 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); |
386 | mLinkFile = file; | 386 | mLinkFile = file; |
387 | mFile = config.readEntry("File", QString::null); | 387 | mFile = config.readEntry("File", QString::null); |
388 | if ( !mExec. isEmpty ( )) { | 388 | if ( !mExec. isEmpty ( )) { |
389 | mFile = QString::null; | 389 | mFile = QString::null; |
390 | } | 390 | } |
391 | else if ( mFile[0] != '/' ) { | 391 | else if ( mFile[0] != '/' ) { |
392 | int slash = file.findRev('/'); | 392 | int slash = file.findRev('/'); |
393 | if ( slash >= 0 ) { | 393 | if ( slash >= 0 ) { |
394 | mFile = file.left(slash) + '/' + mFile; | 394 | mFile = file.left(slash) + '/' + mFile; |
395 | } | 395 | } |
396 | } | 396 | } |
397 | d->mCatList = config.readListEntry("Categories", ';'); | 397 | d->mCatList = config.readListEntry("Categories", ';'); |
398 | if ( d->mCatList[0].toInt() < -1 ) { | 398 | if ( d->mCatList[0].toInt() < -1 ) { |
399 | // numeric cats in file! convert to text | 399 | // numeric cats in file! convert to text |
400 | Categories cat( 0 ); | 400 | Categories cat( 0 ); |
401 | cat.load( categoryFileName() ); | 401 | cat.load( categoryFileName() ); |
402 | d->mCat.resize( d->mCatList.count() ); | 402 | d->mCat.resize( d->mCatList.count() ); |
403 | int i; | 403 | int i; |
404 | QStringList::ConstIterator it; | 404 | QStringList::ConstIterator it; |
405 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); | 405 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); |
406 | ++it, i++ ) { | 406 | ++it, i++ ) { |
407 | bool number; | 407 | bool number; |
408 | int id = (*it).toInt( &number ); | 408 | int id = (*it).toInt( &number ); |
409 | if ( !number ) { | 409 | if ( !number ) { |
410 | // convert from text | 410 | // convert from text |
411 | id = cat.id( "Document View", *it ); | 411 | id = cat.id( "Document View", *it ); |
412 | if ( id == 0 ) | 412 | if ( id == 0 ) |
413 | id = cat.addCategory( "Document View", *it ); | 413 | id = cat.addCategory( "Document View", *it ); |
414 | } | 414 | } |
415 | d->mCat[i] = id; | 415 | d->mCat[i] = id; |
416 | } | 416 | } |
417 | d->updateCatListFromArray(); | 417 | d->updateCatListFromArray(); |
418 | } | 418 | } |
419 | } | 419 | } |
420 | } | 420 | } |
421 | mId = 0; | 421 | mId = 0; |
422 | } | 422 | } |
423 | 423 | ||
424 | AppLnk& AppLnk::operator=(const AppLnk ©) | 424 | AppLnk& AppLnk::operator=(const AppLnk ©) |
425 | { | 425 | { |
426 | if ( this == © ) return *this; | 426 | if ( this == © ) return *this; |
427 | if ( mId ) | 427 | if ( mId ) |
428 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 428 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
429 | if ( d ) | 429 | if ( d ) |
430 | delete d; | 430 | delete d; |
431 | 431 | ||
432 | 432 | ||
433 | mName = copy.mName; | 433 | mName = copy.mName; |
434 | 434 | ||
435 | /* remove for Qtopia 3.0 -zecke */ | 435 | /* remove for Qtopia 3.0 -zecke */ |
436 | mPixmap = copy.mPixmap; | 436 | mPixmap = copy.mPixmap; |
437 | mBigPixmap = copy.mBigPixmap; | 437 | mBigPixmap = copy.mBigPixmap; |
438 | 438 | ||
439 | mExec = copy.mExec; | 439 | mExec = copy.mExec; |
440 | mType = copy.mType; | 440 | mType = copy.mType; |
441 | mRotation = copy.mRotation; | 441 | mRotation = copy.mRotation; |
442 | mComment = copy.mComment; | 442 | mComment = copy.mComment; |
443 | mFile = copy.mFile; | 443 | mFile = copy.mFile; |
444 | mLinkFile = copy.mLinkFile; | 444 | mLinkFile = copy.mLinkFile; |
445 | mIconFile = copy.mIconFile; | 445 | mIconFile = copy.mIconFile; |
446 | mMimeTypes = copy.mMimeTypes; | 446 | mMimeTypes = copy.mMimeTypes; |
447 | mMimeTypeIcons = copy.mMimeTypeIcons; | 447 | mMimeTypeIcons = copy.mMimeTypeIcons; |
448 | mId = 0; | 448 | mId = 0; |
449 | d = new AppLnkPrivate(); | 449 | d = new AppLnkPrivate(); |
450 | d->mCat = copy.d->mCat; | 450 | d->mCat = copy.d->mCat; |
451 | d->mCatList = copy.d->mCatList; | 451 | d->mCatList = copy.d->mCatList; |
452 | d->mPixmaps = copy.d->mPixmaps; | 452 | d->mPixmaps = copy.d->mPixmaps; |
453 | 453 | ||
454 | return *this; | 454 | return *this; |
455 | } | 455 | } |
456 | /*! | 456 | /*! |
457 | protected internally to share code | 457 | protected internally to share code |
458 | should I document that at all? | 458 | should I document that at all? |
459 | I don't know the TT style for that | 459 | I don't know the TT style for that |
460 | */ | 460 | */ |
461 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { | 461 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { |
462 | if ( d->mPixmaps[pos].isNull() ) { | 462 | if ( d->mPixmaps[pos].isNull() ) { |
463 | AppLnk* that = (AppLnk*)this; | 463 | AppLnk* that = (AppLnk*)this; |
464 | if ( mIconFile.isEmpty() ) { | 464 | if ( mIconFile.isEmpty() ) { |
465 | MimeType mt(type()); | 465 | MimeType mt(type()); |
466 | that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); | 466 | that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); |
467 | if ( that->d->mPixmaps[pos].isNull() ) | 467 | if ( that->d->mPixmaps[pos].isNull() ) |
468 | that->d->mPixmaps[pos].convertFromImage( | 468 | that->d->mPixmaps[pos].convertFromImage( |
469 | Resource::loadImage("UnknownDocument") | 469 | Resource::loadImage("UnknownDocument") |
470 | .smoothScale( size, size ) ); | 470 | .smoothScale( size, size ) ); |
471 | return that->d->mPixmaps[pos]; | 471 | return that->d->mPixmaps[pos]; |
472 | } | 472 | } |
473 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); | 473 | |
474 | if ( unscaledIcon.isNull() ) { | 474 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); |
475 | // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); | 475 | if ( unscaledIcon.isNull() ) { |
476 | that->d->mPixmaps[pos].convertFromImage( | 476 | // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); |
477 | Resource::loadImage("UnknownDocument") | 477 | that->d->mPixmaps[pos].convertFromImage( |
478 | .smoothScale( size, size ) ); | 478 | Resource::loadImage("UnknownDocument") |
479 | } else { | 479 | .smoothScale( size, size ) ); |
480 | that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 480 | } else { |
481 | that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 481 | that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
482 | } | 482 | that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
483 | return that->d->mPixmaps[pos]; | 483 | } |
484 | return that->d->mPixmaps[pos]; | ||
484 | } | 485 | } |
486 | |||
485 | return d->mPixmaps[pos]; | 487 | return d->mPixmaps[pos]; |
486 | } | 488 | } |
487 | 489 | ||
488 | /*! | 490 | /*! |
489 | Returns a small pixmap associated with the application. | 491 | Returns a small pixmap associated with the application. |
490 | 492 | ||
491 | \sa bigPixmap() setIcon() | 493 | \sa bigPixmap() setIcon() |
492 | */ | 494 | */ |
493 | const QPixmap& AppLnk::pixmap() const | 495 | const QPixmap& AppLnk::pixmap() const |
494 | { | 496 | { |
495 | if ( d->mPixmaps[0].isNull() ) { | 497 | if ( d->mPixmaps[0].isNull() ) { |
496 | return pixmap(AppLnkPrivate::Normal, smallSize ); | 498 | return pixmap(AppLnkPrivate::Normal, smallSize ); |
497 | } | 499 | } |
498 | return d->mPixmaps[0]; | 500 | return d->mPixmaps[0]; |
499 | } | 501 | } |
500 | 502 | ||
501 | /*! | 503 | /*! |
502 | Returns a large pixmap associated with the application. | 504 | Returns a large pixmap associated with the application. |
503 | 505 | ||
504 | \sa pixmap() setIcon() | 506 | \sa pixmap() setIcon() |
505 | */ | 507 | */ |
506 | const QPixmap& AppLnk::bigPixmap() const | 508 | const QPixmap& AppLnk::bigPixmap() const |
507 | { | 509 | { |
508 | if ( d->mPixmaps[1].isNull() ) { | 510 | if ( d->mPixmaps[1].isNull() ) { |
509 | return pixmap( AppLnkPrivate::Big, bigSize ); | 511 | return pixmap( AppLnkPrivate::Big, bigSize ); |
510 | } | 512 | } |
511 | return d->mPixmaps[1]; | 513 | return d->mPixmaps[1]; |
512 | } | 514 | } |
513 | 515 | ||
514 | /*! | 516 | /*! |
515 | Returns the type of the AppLnk. For applications, games and | 517 | Returns the type of the AppLnk. For applications, games and |
516 | settings the type is \c Application; for documents the type is the | 518 | settings the type is \c Application; for documents the type is the |
517 | document's MIME type. | 519 | document's MIME type. |
518 | */ | 520 | */ |
519 | QString AppLnk::type() const | 521 | QString AppLnk::type() const |
520 | { | 522 | { |
521 | if ( mType.isNull() ) { | 523 | if ( mType.isNull() ) { |
522 | AppLnk* that = (AppLnk*)this; | 524 | AppLnk* that = (AppLnk*)this; |
523 | QString f = file(); | 525 | QString f = file(); |
524 | if ( !f.isNull() ) { | 526 | if ( !f.isNull() ) { |
525 | MimeType mt(f); | 527 | MimeType mt(f); |
526 | that->mType = mt.id(); | 528 | that->mType = mt.id(); |
527 | return that->mType; | 529 | return that->mType; |
528 | } | 530 | } |
529 | } | 531 | } |
530 | return mType; | 532 | return mType; |
531 | } | 533 | } |
532 | 534 | ||
533 | /*! | 535 | /*! |
534 | Returns the file associated with the AppLnk. | 536 | Returns the file associated with the AppLnk. |
535 | 537 | ||
536 | \sa exec() name() | 538 | \sa exec() name() |
537 | */ | 539 | */ |
538 | QString AppLnk::file() const | 540 | QString AppLnk::file() const |
539 | { | 541 | { |
540 | if ( mExec.isEmpty ( ) && mFile.isNull() ) { | 542 | if ( mExec.isEmpty ( ) && mFile.isNull() ) { |
541 | AppLnk* that = (AppLnk*)this; | 543 | AppLnk* that = (AppLnk*)this; |
542 | QString ext = MimeType(mType).extension(); | 544 | QString ext = MimeType(mType).extension(); |
543 | if ( !ext.isEmpty() ) | 545 | if ( !ext.isEmpty() ) |
544 | ext = "." + ext; | 546 | ext = "." + ext; |
545 | if ( !mLinkFile.isEmpty() ) { | 547 | if ( !mLinkFile.isEmpty() ) { |
546 | that->mFile = | 548 | that->mFile = |
547 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") | 549 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") |
548 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; | 550 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; |
549 | qDebug("mFile now == %s", mFile.latin1()); | 551 | qDebug("mFile now == %s", mFile.latin1()); |
550 | } else if ( mType.contains('/') ) { | 552 | } else if ( mType.contains('/') ) { |
551 | that->mFile = | 553 | that->mFile = |
552 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); | 554 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); |
553 | /* | 555 | /* |
554 | * A file with the same name or a .desktop file already exists | 556 | * A file with the same name or a .desktop file already exists |
555 | */ | 557 | */ |
556 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { | 558 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { |
557 | int n=1; | 559 | int n=1; |
558 | QString nn; | 560 | QString nn; |
559 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) | 561 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) |
560 | || QFile::exists(nn+".desktop")) | 562 | || QFile::exists(nn+".desktop")) |
561 | n++; | 563 | n++; |
562 | that->mFile = nn; | 564 | that->mFile = nn; |
563 | } | 565 | } |
564 | that->mLinkFile = that->mFile+".desktop"; | 566 | that->mLinkFile = that->mFile+".desktop"; |
565 | that->mFile += ext; | 567 | that->mFile += ext; |
566 | } | 568 | } |
567 | prepareDirectories(that->mFile); | 569 | prepareDirectories(that->mFile); |
568 | if ( !that->mFile.isEmpty() ) { | 570 | if ( !that->mFile.isEmpty() ) { |
569 | QFile f(that->mFile); | 571 | QFile f(that->mFile); |
570 | if ( !f.open(IO_WriteOnly) ) | 572 | if ( !f.open(IO_WriteOnly) ) |
571 | that->mFile = QString::null; | 573 | that->mFile = QString::null; |
572 | return that->mFile; | 574 | return that->mFile; |
573 | } | 575 | } |
574 | } | 576 | } |
575 | return mFile; | 577 | return mFile; |
576 | } | 578 | } |
577 | 579 | ||
578 | /*! | 580 | /*! |
579 | Returns the desktop file corresponding to this AppLnk. | 581 | Returns the desktop file corresponding to this AppLnk. |
580 | 582 | ||
581 | \sa file() exec() name() | 583 | \sa file() exec() name() |
582 | */ | 584 | */ |
583 | QString AppLnk::linkFile() const | 585 | QString AppLnk::linkFile() const |
584 | { | 586 | { |
585 | if ( mLinkFile.isNull() ) { | 587 | if ( mLinkFile.isNull() ) { |
586 | AppLnk* that = (AppLnk*)this; | 588 | AppLnk* that = (AppLnk*)this; |
587 | if ( type().contains('/') ) { | 589 | if ( type().contains('/') ) { |
588 | StorageInfo storage; | 590 | StorageInfo storage; |
589 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); | 591 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); |
590 | /* tmpfs + and ramfs are available too but not removable | 592 | /* tmpfs + and ramfs are available too but not removable |
591 | * either we fix storage or add this | 593 | * either we fix storage or add this |
592 | */ | 594 | */ |
593 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { | 595 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { |
594 | that->mLinkFile = fs->path(); | 596 | that->mLinkFile = fs->path(); |
595 | } else | 597 | } else |
596 | that->mLinkFile = getenv( "HOME" ); | 598 | that->mLinkFile = getenv( "HOME" ); |
597 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); | 599 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); |
598 | 600 | ||
599 | /* the desktop file exists make sure we don't point to the same file */ | 601 | /* the desktop file exists make sure we don't point to the same file */ |
600 | if ( QFile::exists(that->mLinkFile+".desktop") ) { | 602 | if ( QFile::exists(that->mLinkFile+".desktop") ) { |
601 | AppLnk lnk( that->mLinkFile + ".desktop" ); | 603 | AppLnk lnk( that->mLinkFile + ".desktop" ); |
602 | 604 | ||
603 | /* the linked is different */ | 605 | /* the linked is different */ |
604 | if(that->file() != lnk.file() ) { | 606 | if(that->file() != lnk.file() ) { |
605 | int n = 1; | 607 | int n = 1; |
606 | QString nn; | 608 | QString nn; |
607 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { | 609 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { |
608 | n++; | 610 | n++; |
609 | /* just to be sure */ | 611 | /* just to be sure */ |
610 | AppLnk lnk(nn ); | 612 | AppLnk lnk(nn ); |
611 | if (lnk.file() == that->file() ) | 613 | if (lnk.file() == that->file() ) |
612 | break; | 614 | break; |
613 | } | 615 | } |
614 | that->mLinkFile = nn; | 616 | that->mLinkFile = nn; |
615 | } | 617 | } |
616 | } | 618 | } |
617 | that->mLinkFile += ".desktop"; | 619 | that->mLinkFile += ".desktop"; |
618 | storeLink(); | 620 | storeLink(); |
619 | } | 621 | } |
620 | return that->mLinkFile; | 622 | return that->mLinkFile; |
621 | } | 623 | } |
622 | return mLinkFile; | 624 | return mLinkFile; |
623 | } | 625 | } |
624 | 626 | ||
625 | /*! | 627 | /*! |
626 | Copies \a copy. | 628 | Copies \a copy. |
627 | */ | 629 | */ |
628 | AppLnk::AppLnk( const AppLnk © ) | 630 | AppLnk::AppLnk( const AppLnk © ) |
629 | { | 631 | { |
630 | mName = copy.mName; | 632 | mName = copy.mName; |
631 | mPixmap = copy.mPixmap; | 633 | mPixmap = copy.mPixmap; |
632 | mBigPixmap = copy.mBigPixmap; | 634 | mBigPixmap = copy.mBigPixmap; |
633 | mExec = copy.mExec; | 635 | mExec = copy.mExec; |
634 | mType = copy.mType; | 636 | mType = copy.mType; |
635 | mRotation = copy.mRotation; | 637 | mRotation = copy.mRotation; |
636 | mComment = copy.mComment; | 638 | mComment = copy.mComment; |
637 | mFile = copy.mFile; | 639 | mFile = copy.mFile; |
638 | mLinkFile = copy.mLinkFile; | 640 | mLinkFile = copy.mLinkFile; |
639 | mIconFile = copy.mIconFile; | 641 | mIconFile = copy.mIconFile; |
640 | mMimeTypes = copy.mMimeTypes; | 642 | mMimeTypes = copy.mMimeTypes; |
641 | mMimeTypeIcons = copy.mMimeTypeIcons; | 643 | mMimeTypeIcons = copy.mMimeTypeIcons; |
642 | mId = 0; | 644 | mId = 0; |
643 | d = new AppLnkPrivate(); | 645 | d = new AppLnkPrivate(); |
644 | d->mCat = copy.d->mCat; | 646 | d->mCat = copy.d->mCat; |
645 | d->mCatList = copy.d->mCatList; | 647 | d->mCatList = copy.d->mCatList; |
646 | d->mPixmaps = copy.d->mPixmaps; | 648 | d->mPixmaps = copy.d->mPixmaps; |
647 | } | 649 | } |
648 | 650 | ||
649 | /*! | 651 | /*! |
650 | Destroys the AppLnk. Note that if the AppLnk is currently a member | 652 | Destroys the AppLnk. Note that if the AppLnk is currently a member |
651 | of an AppLnkSet, this will produce a run-time warning. | 653 | of an AppLnkSet, this will produce a run-time warning. |
652 | 654 | ||
653 | \sa AppLnkSet::add() AppLnkSet::remove() | 655 | \sa AppLnkSet::add() AppLnkSet::remove() |
654 | */ | 656 | */ |
655 | AppLnk::~AppLnk() | 657 | AppLnk::~AppLnk() |
656 | { | 658 | { |
657 | if ( mId ) | 659 | if ( mId ) |
658 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 660 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
659 | if ( d ) | 661 | if ( d ) |
660 | delete d; | 662 | delete d; |
661 | } | 663 | } |
662 | 664 | ||
663 | /*! | 665 | /*! |
664 | \overload | 666 | \overload |
665 | Executes the application associated with this AppLnk. | 667 | Executes the application associated with this AppLnk. |
666 | 668 | ||
667 | \sa exec() | 669 | \sa exec() |
668 | */ | 670 | */ |
669 | void AppLnk::execute() const | 671 | void AppLnk::execute() const |
670 | { | 672 | { |
671 | execute( QStringList::split( ' ', property( "Arguments" ) ) ); | 673 | execute( QStringList::split( ' ', property( "Arguments" ) ) ); |
672 | } | 674 | } |
673 | 675 | ||
674 | /*! | 676 | /*! |
675 | Executes the application associated with this AppLnk, with | 677 | Executes the application associated with this AppLnk, with |
676 | \a args as arguments. | 678 | \a args as arguments. |
677 | 679 | ||
678 | \sa exec() | 680 | \sa exec() |
679 | */ | 681 | */ |
680 | void AppLnk::execute(const QStringList& args) const | 682 | void AppLnk::execute(const QStringList& args) const |
681 | { | 683 | { |
682 | #ifdef Q_WS_QWS | 684 | #ifdef Q_WS_QWS |
683 | if ( !mRotation.isEmpty() ) { | 685 | if ( !mRotation.isEmpty() ) { |
684 | // ######## this will only work in the server | 686 | // ######## this will only work in the server |
685 | int rot = QPEApplication::defaultRotation(); | 687 | int rot = QPEApplication::defaultRotation(); |
686 | rot = (rot+mRotation.toInt())%360; | 688 | rot = (rot+mRotation.toInt())%360; |
687 | QCString old = getenv("QWS_DISPLAY"); | 689 | QCString old = getenv("QWS_DISPLAY"); |
688 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 690 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
689 | invoke(args); | 691 | invoke(args); |
690 | setenv("QWS_DISPLAY", old.data(), 1); | 692 | setenv("QWS_DISPLAY", old.data(), 1); |
691 | } else | 693 | } else |
692 | #endif | 694 | #endif |
693 | invoke(args); | 695 | invoke(args); |
694 | } | 696 | } |
695 | 697 | ||
696 | /*! | 698 | /*! |
697 | Invokes the application associated with this AppLnk, with | 699 | Invokes the application associated with this AppLnk, with |
698 | \a args as arguments. Rotation is not taken into account by | 700 | \a args as arguments. Rotation is not taken into account by |
699 | this function, so you should not call it directly. | 701 | this function, so you should not call it directly. |
700 | 702 | ||
701 | \sa execute() | 703 | \sa execute() |
702 | */ | 704 | */ |
703 | void AppLnk::invoke(const QStringList& args) const | 705 | void AppLnk::invoke(const QStringList& args) const |
704 | { | 706 | { |
705 | if ( property( "Arguments" ).isEmpty() ) | 707 | if ( property( "Arguments" ).isEmpty() ) |
706 | Global::execute( exec(), args[0] ); | 708 | Global::execute( exec(), args[0] ); |
707 | else | 709 | else |
708 | Global::execute( exec(), args.join( " " ) ); | 710 | Global::execute( exec(), args.join( " " ) ); |
709 | } | 711 | } |
710 | 712 | ||
711 | /*! | 713 | /*! |
712 | Sets the Exec property to \a exec. | 714 | Sets the Exec property to \a exec. |
713 | 715 | ||
714 | \sa exec() name() | 716 | \sa exec() name() |
715 | */ | 717 | */ |
716 | void AppLnk::setExec( const QString& exec ) | 718 | void AppLnk::setExec( const QString& exec ) |
717 | { | 719 | { |
718 | mExec = exec; | 720 | mExec = exec; |
719 | } | 721 | } |
720 | 722 | ||
721 | #if 0 // this was inlined for better BC | 723 | #if 0 // this was inlined for better BC |
722 | /*! | 724 | /*! |
723 | Sets the Rotation property to \a rot. | 725 | Sets the Rotation property to \a rot. |
724 | 726 | ||
725 | \sa rotation() | 727 | \sa rotation() |
726 | */ | 728 | */ |
727 | void AppLnk::setRotation ( const QString &rot ) | 729 | void AppLnk::setRotation ( const QString &rot ) |
728 | { | 730 | { |
729 | mRotation = rot; | 731 | mRotation = rot; |
730 | } | 732 | } |
731 | #endif | 733 | #endif |
732 | 734 | ||
733 | /*! | 735 | /*! |
734 | Sets the Name property to \a docname. | 736 | Sets the Name property to \a docname. |
735 | 737 | ||
736 | \sa name() | 738 | \sa name() |
737 | */ | 739 | */ |
738 | void AppLnk::setName( const QString& docname ) | 740 | void AppLnk::setName( const QString& docname ) |
739 | { | 741 | { |
740 | mName = docname; | 742 | mName = docname; |
741 | } | 743 | } |
742 | 744 | ||
743 | /*! | 745 | /*! |
744 | Sets the File property to \a filename. | 746 | Sets the File property to \a filename. |
745 | 747 | ||
746 | \sa file() name() | 748 | \sa file() name() |
747 | */ | 749 | */ |
748 | void AppLnk::setFile( const QString& filename ) | 750 | void AppLnk::setFile( const QString& filename ) |
749 | { | 751 | { |
750 | mFile = filename; | 752 | mFile = filename; |
751 | } | 753 | } |
752 | 754 | ||
753 | /*! | 755 | /*! |
754 | Sets the LinkFile property to \a filename. | 756 | Sets the LinkFile property to \a filename. |
755 | 757 | ||
756 | \sa linkFile() | 758 | \sa linkFile() |
757 | */ | 759 | */ |
758 | void AppLnk::setLinkFile( const QString& filename ) | 760 | void AppLnk::setLinkFile( const QString& filename ) |
759 | { | 761 | { |
760 | mLinkFile = filename; | 762 | mLinkFile = filename; |
761 | } | 763 | } |
762 | 764 | ||
763 | /*! | 765 | /*! |
764 | Sets the Comment property to \a comment. | 766 | Sets the Comment property to \a comment. |
765 | 767 | ||
766 | This text is displayed in the 'Details Dialog', for example if the | 768 | This text is displayed in the 'Details Dialog', for example if the |
767 | user uses the 'press-and-hold' gesture. | 769 | user uses the 'press-and-hold' gesture. |
768 | 770 | ||
769 | \sa comment() | 771 | \sa comment() |
770 | */ | 772 | */ |
771 | void AppLnk::setComment( const QString& comment ) | 773 | void AppLnk::setComment( const QString& comment ) |
772 | { | 774 | { |
773 | mComment = comment; | 775 | mComment = comment; |
774 | } | 776 | } |
775 | 777 | ||
776 | /*! | 778 | /*! |
777 | Sets the Type property to \a type. | 779 | Sets the Type property to \a type. |
778 | 780 | ||
779 | For applications, games and settings the type should be \c | 781 | For applications, games and settings the type should be \c |
780 | Application; for documents the type should be the document's MIME | 782 | Application; for documents the type should be the document's MIME |
781 | type. | 783 | type. |
782 | 784 | ||
783 | \sa type() | 785 | \sa type() |
784 | */ | 786 | */ |
785 | void AppLnk::setType( const QString& type ) | 787 | void AppLnk::setType( const QString& type ) |
786 | { | 788 | { |
787 | mType = type; | 789 | mType = type; |
788 | } | 790 | } |
789 | 791 | ||
790 | /*! | 792 | /*! |
791 | \fn QString AppLnk::icon() const | 793 | \fn QString AppLnk::icon() const |
792 | 794 | ||
793 | Returns the Icon property. | 795 | Returns the Icon property. |
794 | 796 | ||
795 | \sa setIcon() | 797 | \sa setIcon() |
796 | */ | 798 | */ |
797 | 799 | ||
798 | /*! | 800 | /*! |
799 | Sets the Icon property to \a iconname. This is the filename from | 801 | Sets the Icon property to \a iconname. This is the filename from |
800 | which the pixmap() and bigPixmap() are obtained. | 802 | which the pixmap() and bigPixmap() are obtained. |
801 | 803 | ||
802 | \sa icon() setSmallIconSize() setBigIconSize() | 804 | \sa icon() setSmallIconSize() setBigIconSize() |
803 | */ | 805 | */ |
804 | void AppLnk::setIcon( const QString& iconname ) | 806 | void AppLnk::setIcon( const QString& iconname ) |
805 | { | 807 | { |
806 | mIconFile = iconname; | 808 | mIconFile = iconname; |
807 | QImage unscaledIcon = Resource::loadImage( mIconFile ); | 809 | QImage unscaledIcon = Resource::loadImage( mIconFile ); |
808 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 810 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
809 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 811 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
810 | } | 812 | } |
811 | 813 | ||
812 | /*! | 814 | /*! |
813 | Sets the Categories property to \a c. | 815 | Sets the Categories property to \a c. |
814 | 816 | ||
815 | See the CategoryWidget for more details. | 817 | See the CategoryWidget for more details. |
816 | 818 | ||
817 | \sa categories() | 819 | \sa categories() |
818 | */ | 820 | */ |
819 | void AppLnk::setCategories( const QArray<int>& c ) | 821 | void AppLnk::setCategories( const QArray<int>& c ) |
820 | { | 822 | { |
821 | d->mCat = c; | 823 | d->mCat = c; |
822 | d->updateCatListFromArray(); | 824 | d->updateCatListFromArray(); |
823 | } | 825 | } |
824 | 826 | ||
825 | /*! | 827 | /*! |
826 | \fn QStringList AppLnk::mimeTypeIcons() const | 828 | \fn QStringList AppLnk::mimeTypeIcons() const |
827 | 829 | ||
828 | Returns the MimeTypeIcons property of the AppLnk. | 830 | Returns the MimeTypeIcons property of the AppLnk. |
829 | */ | 831 | */ |
830 | 832 | ||
831 | /*! | 833 | /*! |
832 | Attempts to ensure that the link file for this AppLnk exists, | 834 | Attempts to ensure that the link file for this AppLnk exists, |
833 | including creating any required directories. Returns TRUE if | 835 | including creating any required directories. Returns TRUE if |
834 | successful; otherwise returns FALSE. | 836 | successful; otherwise returns FALSE. |
835 | 837 | ||
836 | You should not need to use this function. | 838 | You should not need to use this function. |
837 | */ | 839 | */ |
838 | bool AppLnk::ensureLinkExists() const | 840 | bool AppLnk::ensureLinkExists() const |
839 | { | 841 | { |
840 | QString lf = linkFile(); | 842 | QString lf = linkFile(); |
841 | return prepareDirectories(lf); | 843 | return prepareDirectories(lf); |
842 | } | 844 | } |
843 | 845 | ||
844 | /*! | 846 | /*! |
845 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; | 847 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; |
846 | otherwise returns FALSE. | 848 | otherwise returns FALSE. |
847 | 849 | ||
848 | In addition, the "linkChanged(QString)" message is sent to the | 850 | In addition, the "linkChanged(QString)" message is sent to the |
849 | "QPE/System" \link qcop.html QCop\endlink channel. | 851 | "QPE/System" \link qcop.html QCop\endlink channel. |
850 | */ | 852 | */ |
851 | bool AppLnk::writeLink() const | 853 | bool AppLnk::writeLink() const |
852 | { | 854 | { |
853 | // Only re-writes settable parts | 855 | // Only re-writes settable parts |
854 | QString lf = linkFile(); | 856 | QString lf = linkFile(); |
855 | if ( !ensureLinkExists() ) | 857 | if ( !ensureLinkExists() ) |
856 | return FALSE; | 858 | return FALSE; |
857 | storeLink(); | 859 | storeLink(); |
858 | return TRUE; | 860 | return TRUE; |
859 | } | 861 | } |
860 | 862 | ||
861 | /*! | 863 | /*! |
862 | \internal | 864 | \internal |
863 | */ | 865 | */ |
864 | void AppLnk::storeLink() const | 866 | void AppLnk::storeLink() const |
865 | { | 867 | { |
866 | Config config( mLinkFile, Config::File ); | 868 | Config config( mLinkFile, Config::File ); |
867 | config.setGroup("Desktop Entry"); | 869 | config.setGroup("Desktop Entry"); |
868 | config.writeEntry("Name",mName); | 870 | config.writeEntry("Name",mName); |
869 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); | 871 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); |
870 | config.writeEntry("Type",type()); | 872 | config.writeEntry("Type",type()); |
871 | if(!rotation().isEmpty()) | 873 | if(!rotation().isEmpty()) |
872 | config.writeEntry("Rotation",rotation()); | 874 | config.writeEntry("Rotation",rotation()); |
873 | else | 875 | else |
874 | config.removeEntry("Rotation"); | 876 | config.removeEntry("Rotation"); |
875 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); | 877 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); |
876 | QString f = file(); | 878 | QString f = file(); |
877 | int i = 0; | 879 | int i = 0; |
878 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) | 880 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) |
879 | i++; | 881 | i++; |
880 | while ( i && f[i] != '/' ) | 882 | while ( i && f[i] != '/' ) |
881 | i--; | 883 | i--; |
882 | // simple case where in the same directory | 884 | // simple case where in the same directory |
883 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) | 885 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) |
884 | f = f.mid(i+1); | 886 | f = f.mid(i+1); |
885 | // ### could do relative ie ../../otherDocs/file.doc | 887 | // ### could do relative ie ../../otherDocs/file.doc |
886 | config.writeEntry("File",f); | 888 | config.writeEntry("File",f); |
887 | config.writeEntry( "Categories", d->mCatList, ';' ); | 889 | config.writeEntry( "Categories", d->mCatList, ';' ); |
888 | 890 | ||
889 | #ifndef QT_NO_COP | 891 | #ifndef QT_NO_COP |
890 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 892 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
891 | e << mLinkFile; | 893 | e << mLinkFile; |
892 | #endif | 894 | #endif |
893 | } | 895 | } |
894 | 896 | ||
895 | /*! | 897 | /*! |
896 | Sets the property named \a key to \a value. | 898 | Sets the property named \a key to \a value. |
897 | 899 | ||
898 | \sa property() | 900 | \sa property() |
899 | */ | 901 | */ |
900 | void AppLnk::setProperty(const QString& key, const QString& value) | 902 | void AppLnk::setProperty(const QString& key, const QString& value) |
901 | { | 903 | { |
902 | if ( ensureLinkExists() ) { | 904 | if ( ensureLinkExists() ) { |
903 | Config cfg(linkFile(), Config::File); | 905 | Config cfg(linkFile(), Config::File); |
904 | cfg.writeEntry(key,value); | 906 | cfg.writeEntry(key,value); |
905 | } | 907 | } |
906 | } | 908 | } |
907 | 909 | ||
908 | /*! | 910 | /*! |
909 | Returns the property named \a key. | 911 | Returns the property named \a key. |
910 | 912 | ||
911 | \sa setProperty() | 913 | \sa setProperty() |
912 | */ | 914 | */ |
913 | QString AppLnk::property(const QString& key) const | 915 | QString AppLnk::property(const QString& key) const |
914 | { | 916 | { |
915 | QString lf = linkFile(); | 917 | QString lf = linkFile(); |
916 | if ( !QFile::exists(lf) ) | 918 | if ( !QFile::exists(lf) ) |
917 | return QString::null; | 919 | return QString::null; |
918 | Config cfg(lf, Config::File); | 920 | Config cfg(lf, Config::File); |
919 | return cfg.readEntry(key); | 921 | return cfg.readEntry(key); |
920 | } | 922 | } |
921 | 923 | ||
922 | bool AppLnk::isPreloaded() const { | 924 | bool AppLnk::isPreloaded() const { |
923 | // Preload information is stored in the Launcher config in v1.5. | 925 | // Preload information is stored in the Launcher config in v1.5. |
924 | Config cfg("Launcher"); | 926 | Config cfg("Launcher"); |
925 | cfg.setGroup("Preload"); | 927 | cfg.setGroup("Preload"); |
926 | QStringList apps = cfg.readListEntry("Apps",','); | 928 | QStringList apps = cfg.readListEntry("Apps",','); |
927 | if (apps.contains(exec())) | 929 | if (apps.contains(exec())) |
928 | return true; | 930 | return true; |
929 | return false; | 931 | return false; |
930 | } | 932 | } |
931 | 933 | ||
932 | void AppLnk::setPreloaded(bool yesNo) { | 934 | void AppLnk::setPreloaded(bool yesNo) { |
933 | // Preload information is stored in the Launcher config in v1.5. | 935 | // Preload information is stored in the Launcher config in v1.5. |
934 | Config cfg("Launcher"); | 936 | Config cfg("Launcher"); |
935 | cfg.setGroup("Preload"); | 937 | cfg.setGroup("Preload"); |
936 | QStringList apps = cfg.readListEntry("Apps", ','); | 938 | QStringList apps = cfg.readListEntry("Apps", ','); |
937 | if (apps.contains(exec()) && !yesNo) | 939 | if (apps.contains(exec()) && !yesNo) |
938 | apps.remove(exec()); | 940 | apps.remove(exec()); |
939 | else if (yesNo && !apps.contains(exec())) | 941 | else if (yesNo && !apps.contains(exec())) |
940 | apps.append(exec()); | 942 | apps.append(exec()); |
941 | cfg.writeEntry("Apps", apps, ','); | 943 | cfg.writeEntry("Apps", apps, ','); |
942 | } | 944 | } |
943 | 945 | ||
944 | 946 | ||
945 | /*! | 947 | /*! |
946 | Deletes both the linkFile() and the file() associated with this AppLnk. | 948 | Deletes both the linkFile() and the file() associated with this AppLnk. |
947 | 949 | ||
948 | \sa removeLinkFile() | 950 | \sa removeLinkFile() |
949 | */ | 951 | */ |
950 | void AppLnk::removeFiles() | 952 | void AppLnk::removeFiles() |
951 | { | 953 | { |
952 | bool valid = isValid(); | 954 | bool valid = isValid(); |
953 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { | 955 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { |
954 | if ( QFile::remove(file()) ) { | 956 | if ( QFile::remove(file()) ) { |
955 | #ifndef QT_NO_COP | 957 | #ifndef QT_NO_COP |
956 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 958 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
957 | if ( linkFileKnown() ) | 959 | if ( linkFileKnown() ) |
958 | e << linkFile(); | 960 | e << linkFile(); |
959 | else | 961 | else |
960 | e << file(); | 962 | e << file(); |
961 | #endif | 963 | #endif |
962 | } else if ( valid ) { | 964 | } else if ( valid ) { |
963 | // restore link | 965 | // restore link |
964 | writeLink(); | 966 | writeLink(); |
965 | } | 967 | } |
966 | } | 968 | } |
967 | } | 969 | } |
968 | 970 | ||
969 | /*! | 971 | /*! |
970 | Deletes the linkFile(), leaving any file() untouched. | 972 | Deletes the linkFile(), leaving any file() untouched. |
971 | 973 | ||
972 | \sa removeFiles() | 974 | \sa removeFiles() |
973 | */ | 975 | */ |
974 | void AppLnk::removeLinkFile() | 976 | void AppLnk::removeLinkFile() |
975 | { | 977 | { |
976 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { | 978 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { |
977 | #ifndef QT_NO_COP | 979 | #ifndef QT_NO_COP |
978 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 980 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
979 | e << linkFile(); | 981 | e << linkFile(); |
980 | #endif | 982 | #endif |
981 | } | 983 | } |
982 | } | 984 | } |
983 | 985 | ||
984 | class AppLnkImagePrivate { | 986 | class AppLnkImagePrivate { |
985 | public : | 987 | public : |
986 | AppLnkImagePrivate( const QString & ImageName ) { | 988 | AppLnkImagePrivate( const QString & ImageName ) { |
987 | IconName = ImageName; | 989 | IconName = ImageName; |
988 | Small = 0; | 990 | Small = 0; |
989 | Big = 0; | 991 | Big = 0; |
990 | } | 992 | } |
991 | ~AppLnkImagePrivate( ) { | 993 | ~AppLnkImagePrivate( ) { |
992 | if ( Small ) delete Small; | 994 | if ( Small ) delete Small; |
993 | if ( Big ) delete Big; | 995 | if ( Big ) delete Big; |
994 | } | 996 | } |
995 | 997 | ||
996 | inline QPixmap * small( void ) { | 998 | inline QPixmap * small( void ) { |
997 | if( ! Small ) { | 999 | if( ! Small ) { |
998 | QImage unscaledIcon = Resource::loadImage( IconName ); | 1000 | QImage unscaledIcon = Resource::loadImage( IconName ); |
999 | // works as long as smallSize remains static | 1001 | // works as long as smallSize remains static |
1000 | Small = new QPixmap(); | 1002 | Small = new QPixmap(); |
1001 | Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 1003 | Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
1002 | } | 1004 | } |
1003 | return Small; | 1005 | return Small; |
1004 | } | 1006 | } |
1005 | 1007 | ||
1006 | inline QPixmap * big( void ) { | 1008 | inline QPixmap * big( void ) { |
1007 | if( ! Big ) { | 1009 | if( ! Big ) { |
1008 | QImage unscaledIcon = Resource::loadImage( IconName ); | 1010 | QImage unscaledIcon = Resource::loadImage( IconName ); |
1009 | // works as long as bigSize remains static | 1011 | // works as long as bigSize remains static |
1010 | Big = new QPixmap(); | 1012 | Big = new QPixmap(); |
1011 | Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 1013 | Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
1012 | } | 1014 | } |
1013 | return Big; | 1015 | return Big; |
1014 | } | 1016 | } |
1015 | 1017 | ||
1016 | QString IconName; | 1018 | QString IconName; |
1017 | QPixmap * Small; | 1019 | QPixmap * Small; |
1018 | QPixmap * Big; | 1020 | QPixmap * Big; |
1019 | }; | 1021 | }; |
1020 | 1022 | ||
1021 | class AppLnkSetPrivate { | 1023 | class AppLnkSetPrivate { |
1022 | public: | 1024 | public: |
1023 | AppLnkSetPrivate() | 1025 | AppLnkSetPrivate() |
1024 | { | 1026 | { |
1025 | typPix.setAutoDelete(TRUE); | 1027 | typPix.setAutoDelete(TRUE); |
1026 | typName.setAutoDelete(TRUE); | 1028 | typName.setAutoDelete(TRUE); |
1027 | } | 1029 | } |
1028 | 1030 | ||
1029 | QDict<AppLnkImagePrivate> typPix; | 1031 | QDict<AppLnkImagePrivate> typPix; |
1030 | QDict<QString> typName; | 1032 | QDict<QString> typName; |
1031 | }; | 1033 | }; |
1032 | 1034 | ||
1033 | /*! | 1035 | /*! |
1034 | \class AppLnkSet applnk.h | 1036 | \class AppLnkSet applnk.h |
1035 | \brief The AppLnkSet class is a set of AppLnk objects. | 1037 | \brief The AppLnkSet class is a set of AppLnk objects. |
1036 | */ | 1038 | */ |
1037 | 1039 | ||
1038 | /*! | 1040 | /*! |
1039 | \fn QStringList AppLnkSet::types() const | 1041 | \fn QStringList AppLnkSet::types() const |
1040 | 1042 | ||
1041 | Returns the list of \link applnk.html#Types types\endlink in the set. | 1043 | Returns the list of \link applnk.html#Types types\endlink in the set. |
1042 | 1044 | ||
1043 | For applications, games and settings the type is \c Application; | 1045 | For applications, games and settings the type is \c Application; |
1044 | for documents the type is the document's MIME type. | 1046 | for documents the type is the document's MIME type. |
1045 | 1047 | ||
1046 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() | 1048 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() |
1047 | */ | 1049 | */ |
1048 | 1050 | ||
1049 | /*! | 1051 | /*! |
1050 | \fn const QList<AppLnk>& AppLnkSet::children() const | 1052 | \fn const QList<AppLnk>& AppLnkSet::children() const |
1051 | 1053 | ||
1052 | Returns the members of the set. | 1054 | Returns the members of the set. |
1053 | */ | 1055 | */ |
1054 | 1056 | ||
1055 | /*! | 1057 | /*! |
1056 | Constructs an empty AppLnkSet. | 1058 | Constructs an empty AppLnkSet. |
1057 | */ | 1059 | */ |
1058 | AppLnkSet::AppLnkSet() : | 1060 | AppLnkSet::AppLnkSet() : |
1059 | d(new AppLnkSetPrivate) | 1061 | d(new AppLnkSetPrivate) |
1060 | { | 1062 | { |
1061 | } | 1063 | } |
1062 | 1064 | ||
1063 | /*! | 1065 | /*! |
1064 | Constructs an AppLnkSet that contains AppLnk objects representing | 1066 | Constructs an AppLnkSet that contains AppLnk objects representing |
1065 | all the files in the given \a directory (and any subdirectories | 1067 | all the files in the given \a directory (and any subdirectories |
1066 | recursively). | 1068 | recursively). |
1067 | 1069 | ||
1068 | \omit | 1070 | \omit |
1069 | The directories may contain ".directory" files which override | 1071 | The directories may contain ".directory" files which override |
1070 | any AppLnk::type() values for AppLnk objects found in the directory. | 1072 | any AppLnk::type() values for AppLnk objects found in the directory. |
1071 | This allows simple localization of application types. | 1073 | This allows simple localization of application types. |
1072 | \endomit | 1074 | \endomit |
1073 | */ | 1075 | */ |
1074 | AppLnkSet::AppLnkSet( const QString &directory ) : | 1076 | AppLnkSet::AppLnkSet( const QString &directory ) : |
1075 | d(new AppLnkSetPrivate) | 1077 | d(new AppLnkSetPrivate) |
1076 | { | 1078 | { |
1077 | QDir dir( directory ); | 1079 | QDir dir( directory ); |
1078 | mFile = directory; | 1080 | mFile = directory; |
1079 | findChildren(directory,QString::null,QString::null); | 1081 | findChildren(directory,QString::null,QString::null); |
1080 | } | 1082 | } |
1081 | 1083 | ||
1082 | /*! | 1084 | /*! |
1083 | Detaches all AppLnk objects from the set. The set become empty and | 1085 | Detaches all AppLnk objects from the set. The set become empty and |
1084 | the caller becomes responsible for deleting the AppLnk objects. | 1086 | the caller becomes responsible for deleting the AppLnk objects. |
1085 | */ | 1087 | */ |
1086 | void AppLnkSet::detachChildren() | 1088 | void AppLnkSet::detachChildren() |
1087 | { | 1089 | { |
1088 | QListIterator<AppLnk> it( mApps ); | 1090 | QListIterator<AppLnk> it( mApps ); |
1089 | for ( ; it.current(); ) { | 1091 | for ( ; it.current(); ) { |
1090 | AppLnk* a = *it; | 1092 | AppLnk* a = *it; |
1091 | ++it; | 1093 | ++it; |
1092 | a->mId = 0; | 1094 | a->mId = 0; |
1093 | } | 1095 | } |
1094 | mApps.clear(); | 1096 | mApps.clear(); |
1095 | } | 1097 | } |
1096 | 1098 | ||
1097 | /*! | 1099 | /*! |
1098 | Destroys the set, deleting all the AppLnk objects it contains. | 1100 | Destroys the set, deleting all the AppLnk objects it contains. |
1099 | 1101 | ||
1100 | \sa detachChildren() | 1102 | \sa detachChildren() |
1101 | */ | 1103 | */ |
1102 | AppLnkSet::~AppLnkSet() | 1104 | AppLnkSet::~AppLnkSet() |
1103 | { | 1105 | { |
1104 | QListIterator<AppLnk> it( mApps ); | 1106 | QListIterator<AppLnk> it( mApps ); |
1105 | for ( ; it.current(); ) { | 1107 | for ( ; it.current(); ) { |
1106 | AppLnk* a = *it; | 1108 | AppLnk* a = *it; |
1107 | ++it; | 1109 | ++it; |
1108 | a->mId = 0; | 1110 | a->mId = 0; |
1109 | delete a; | 1111 | delete a; |
1110 | } | 1112 | } |
1111 | delete d; | 1113 | delete d; |
1112 | } | 1114 | } |
1113 | 1115 | ||
1114 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) | 1116 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) |
1115 | { | 1117 | { |
1116 | depth++; | 1118 | depth++; |
1117 | if ( depth > 10 ) | 1119 | if ( depth > 10 ) |
1118 | return; | 1120 | return; |
1119 | 1121 | ||
1120 | QDir dir( dr ); | 1122 | QDir dir( dr ); |
1121 | QString typNameLocal = typName; | 1123 | QString typNameLocal = typName; |
1122 | 1124 | ||
1123 | if ( dir.exists( ".directory" ) ) { | 1125 | if ( dir.exists( ".directory" ) ) { |
1124 | Config config( dr + "/.directory", Config::File ); | 1126 | Config config( dr + "/.directory", Config::File ); |
1125 | config.setGroup( "Desktop Entry" ); | 1127 | config.setGroup( "Desktop Entry" ); |
1126 | typNameLocal = config.readEntry( "Name", typNameLocal ); | 1128 | typNameLocal = config.readEntry( "Name", typNameLocal ); |
1127 | if ( !typ.isEmpty() ) { | 1129 | if ( !typ.isEmpty() ) { |
1128 | d->typPix.insert( typ, | 1130 | d->typPix.insert( typ, |
1129 | new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) ) | 1131 | new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) ) |
1130 | ); | 1132 | ); |
1131 | d->typName.insert(typ, new QString(typNameLocal)); | 1133 | d->typName.insert(typ, new QString(typNameLocal)); |
1132 | 1134 | ||
1133 | } | 1135 | } |
1134 | } | 1136 | } |
1135 | 1137 | ||
1136 | const QFileInfoList *list = dir.entryInfoList(); | 1138 | const QFileInfoList *list = dir.entryInfoList(); |
1137 | if ( list ) { | 1139 | if ( list ) { |
1138 | QFileInfo* fi; | 1140 | QFileInfo* fi; |
1139 | bool cadded=FALSE; | 1141 | bool cadded=FALSE; |
1140 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1142 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1141 | QString bn = fi->fileName(); | 1143 | QString bn = fi->fileName(); |
1142 | // qDebug("findChildren "+bn); | 1144 | // qDebug("findChildren "+bn); |
1143 | if ( bn[0] != '.' && bn != "CVS" ) { | 1145 | if ( bn[0] != '.' && bn != "CVS" ) { |
1144 | if ( fi->isDir() ) { | 1146 | if ( fi->isDir() ) { |
1145 | QString c = typ.isNull() ? bn : typ+"/"+bn; | 1147 | QString c = typ.isNull() ? bn : typ+"/"+bn; |
1146 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; | 1148 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; |
1147 | findChildren(fi->filePath(), c, d, depth ); | 1149 | findChildren(fi->filePath(), c, d, depth ); |
1148 | } else { | 1150 | } else { |
1149 | if ( fi->extension(FALSE) == "desktop" ) { | 1151 | if ( fi->extension(FALSE) == "desktop" ) { |
1150 | AppLnk* app = new AppLnk( fi->filePath() ); | 1152 | AppLnk* app = new AppLnk( fi->filePath() ); |
1151 | #ifdef QT_NO_QWS_MULTIPROCESS | 1153 | #ifdef QT_NO_QWS_MULTIPROCESS |
1152 | if ( !Global::isBuiltinCommand( app->exec() ) ) | 1154 | if ( !Global::isBuiltinCommand( app->exec() ) ) |
1153 | delete app; | 1155 | delete app; |
1154 | else | 1156 | else |
1155 | #endif | 1157 | #endif |
1156 | { | 1158 | { |
1157 | if ( !typ.isEmpty() ) { | 1159 | if ( !typ.isEmpty() ) { |
1158 | if ( !cadded ) { | 1160 | if ( !cadded ) { |
1159 | typs.append(typ); | 1161 | typs.append(typ); |
1160 | cadded = TRUE; | 1162 | cadded = TRUE; |
1161 | } | 1163 | } |
1162 | app->setType(typ); | 1164 | app->setType(typ); |
1163 | } | 1165 | } |
1164 | add(app); | 1166 | add(app); |
1165 | } | 1167 | } |
1166 | } | 1168 | } |
1167 | } | 1169 | } |
1168 | } | 1170 | } |
1169 | } | 1171 | } |
1170 | } | 1172 | } |
1171 | } | 1173 | } |
1172 | 1174 | ||
1173 | /*! | 1175 | /*! |
1174 | Adds AppLnk \a f to the set. The set takes responsibility for | 1176 | Adds AppLnk \a f to the set. The set takes responsibility for |
1175 | deleting \a f. | 1177 | deleting \a f. |
1176 | 1178 | ||
1177 | \sa remove() | 1179 | \sa remove() |
1178 | */ | 1180 | */ |
1179 | void AppLnkSet::add( AppLnk *f ) | 1181 | void AppLnkSet::add( AppLnk *f ) |
1180 | { | 1182 | { |
1181 | if ( f->mId == 0 ) { | 1183 | if ( f->mId == 0 ) { |
1182 | AppLnk::lastId++; | 1184 | AppLnk::lastId++; |
1183 | f->mId = AppLnk::lastId; | 1185 | f->mId = AppLnk::lastId; |
1184 | mApps.append( f ); | 1186 | mApps.append( f ); |
1185 | } else { | 1187 | } else { |
1186 | qWarning("Attempt to add an AppLnk twice"); | 1188 | qWarning("Attempt to add an AppLnk twice"); |
1187 | } | 1189 | } |
1188 | } | 1190 | } |
1189 | 1191 | ||
1190 | /*! | 1192 | /*! |
1191 | Removes AppLnk \a f to the set. The caller becomes responsible for | 1193 | Removes AppLnk \a f to the set. The caller becomes responsible for |
1192 | deleting \a f. Returns TRUE if \a f was in the set; otherwise | 1194 | deleting \a f. Returns TRUE if \a f was in the set; otherwise |
1193 | returns FALSE. | 1195 | returns FALSE. |
1194 | 1196 | ||
1195 | \sa add() | 1197 | \sa add() |
1196 | */ | 1198 | */ |
1197 | bool AppLnkSet::remove( AppLnk *f ) | 1199 | bool AppLnkSet::remove( AppLnk *f ) |
1198 | { | 1200 | { |
1199 | if ( mApps.remove( f ) ) { | 1201 | if ( mApps.remove( f ) ) { |
1200 | f->mId = 0; | 1202 | f->mId = 0; |
1201 | return TRUE; | 1203 | return TRUE; |
1202 | } | 1204 | } |
1203 | return FALSE; | 1205 | return FALSE; |
1204 | } | 1206 | } |
1205 | 1207 | ||
1206 | 1208 | ||
1207 | /*! | 1209 | /*! |
1208 | Returns the localized name for type \a t. | 1210 | Returns the localized name for type \a t. |
1209 | 1211 | ||
1210 | For applications, games and settings the type is \c Application; | 1212 | For applications, games and settings the type is \c Application; |
1211 | for documents the type is the document's MIME type. | 1213 | for documents the type is the document's MIME type. |
1212 | */ | 1214 | */ |
1213 | QString AppLnkSet::typeName( const QString& t ) const | 1215 | QString AppLnkSet::typeName( const QString& t ) const |
1214 | { | 1216 | { |
1215 | QString *st = d->typName.find(t); | 1217 | QString *st = d->typName.find(t); |
1216 | return st ? *st : QString::null; | 1218 | return st ? *st : QString::null; |
1217 | } | 1219 | } |
1218 | 1220 | ||
1219 | /*! | 1221 | /*! |
1220 | Returns the small pixmap associated with type \a t. | 1222 | Returns the small pixmap associated with type \a t. |
1221 | 1223 | ||
1222 | For applications, games and settings the type is \c Application; | 1224 | For applications, games and settings the type is \c Application; |
1223 | for documents the type is the document's MIME type. | 1225 | for documents the type is the document's MIME type. |
1224 | */ | 1226 | */ |
1225 | QPixmap AppLnkSet::typePixmap( const QString& t ) const | 1227 | QPixmap AppLnkSet::typePixmap( const QString& t ) const |
1226 | { | 1228 | { |
1227 | AppLnkImagePrivate *alip = d->typPix.find(t); | 1229 | AppLnkImagePrivate *alip = d->typPix.find(t); |
1228 | return alip ? *(alip->small()) : QPixmap(); | 1230 | return alip ? *(alip->small()) : QPixmap(); |
1229 | } | 1231 | } |
1230 | 1232 | ||
1231 | /*! | 1233 | /*! |
1232 | Returns the large pixmap associated with type \a t. | 1234 | Returns the large pixmap associated with type \a t. |
1233 | 1235 | ||
1234 | For applications, games and settings the type is \c Application; | 1236 | For applications, games and settings the type is \c Application; |
1235 | for documents the type is the document's MIME type. | 1237 | for documents the type is the document's MIME type. |
1236 | */ | 1238 | */ |
1237 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const | 1239 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const |
1238 | { | 1240 | { |
1239 | AppLnkImagePrivate *alip = d->typPix.find(t); | 1241 | AppLnkImagePrivate *alip = d->typPix.find(t); |
1240 | return alip ? *(alip->big()) : QPixmap(); | 1242 | return alip ? *(alip->big()) : QPixmap(); |
1241 | } | 1243 | } |
1242 | 1244 | ||
1243 | /*! | 1245 | /*! |
1244 | Returns the AppLnk with the given \a id. | 1246 | Returns the AppLnk with the given \a id. |
1245 | */ | 1247 | */ |
1246 | const AppLnk *AppLnkSet::find( int id ) const | 1248 | const AppLnk *AppLnkSet::find( int id ) const |
1247 | { | 1249 | { |
1248 | QListIterator<AppLnk> it( children() ); | 1250 | QListIterator<AppLnk> it( children() ); |
1249 | 1251 | ||
1250 | for ( ; it.current(); ++it ) { | 1252 | for ( ; it.current(); ++it ) { |
1251 | const AppLnk *app = it.current(); | 1253 | const AppLnk *app = it.current(); |
1252 | if ( app->id() == id ) | 1254 | if ( app->id() == id ) |
1253 | return app; | 1255 | return app; |
1254 | } | 1256 | } |
1255 | 1257 | ||
1256 | return 0; | 1258 | return 0; |
1257 | } | 1259 | } |
1258 | 1260 | ||
1259 | /*! | 1261 | /*! |
1260 | Returns the AppLnk with the given \a exec attribute. | 1262 | Returns the AppLnk with the given \a exec attribute. |
1261 | */ | 1263 | */ |
1262 | const AppLnk *AppLnkSet::findExec( const QString& exec ) const | 1264 | const AppLnk *AppLnkSet::findExec( const QString& exec ) const |
1263 | { | 1265 | { |
1264 | QListIterator<AppLnk> it( children() ); | 1266 | QListIterator<AppLnk> it( children() ); |
1265 | 1267 | ||
1266 | for ( ; it.current(); ++it ) { | 1268 | for ( ; it.current(); ++it ) { |
1267 | const AppLnk *app = it.current(); | 1269 | const AppLnk *app = it.current(); |
1268 | if ( app->exec() == exec ) | 1270 | if ( app->exec() == exec ) |
1269 | return app; | 1271 | return app; |
1270 | } | 1272 | } |
1271 | 1273 | ||
1272 | return 0; | 1274 | return 0; |
1273 | } | 1275 | } |
1274 | 1276 | ||
1275 | /*! | 1277 | /*! |
1276 | \class DocLnkSet applnk.h | 1278 | \class DocLnkSet applnk.h |
1277 | \brief The DocLnkSet class is a set of DocLnk objects. | 1279 | \brief The DocLnkSet class is a set of DocLnk objects. |
1278 | */ | 1280 | */ |
1279 | 1281 | ||
1280 | /*! | 1282 | /*! |
1281 | \fn const QList<DocLnk>& DocLnkSet::children() const | 1283 | \fn const QList<DocLnk>& DocLnkSet::children() const |
1282 | 1284 | ||
1283 | Returns the members of the set. | 1285 | Returns the members of the set. |
1284 | */ | 1286 | */ |
1285 | 1287 | ||
1286 | /*! | 1288 | /*! |
1287 | Constructs an empty DocLnkSet. | 1289 | Constructs an empty DocLnkSet. |
1288 | 1290 | ||
1289 | \sa appendFrom() | 1291 | \sa appendFrom() |
1290 | */ | 1292 | */ |
1291 | DocLnkSet::DocLnkSet() | 1293 | DocLnkSet::DocLnkSet() |
1292 | { | 1294 | { |
1293 | } | 1295 | } |
1294 | 1296 | ||
1295 | /*! | 1297 | /*! |
1296 | Constructs a DocLnkSet that contains DocLnk objects representing all | 1298 | Constructs a DocLnkSet that contains DocLnk objects representing all |
1297 | the files in the \a directory (and any subdirectories, recursively). | 1299 | the files in the \a directory (and any subdirectories, recursively). |
1298 | 1300 | ||
1299 | If \a mimefilter is not null, | 1301 | If \a mimefilter is not null, |
1300 | only documents with a MIME type matching \a mimefilter are selected. | 1302 | only documents with a MIME type matching \a mimefilter are selected. |
1301 | The value may contain multiple wild-card patterns separated by ";", | 1303 | The value may contain multiple wild-card patterns separated by ";", |
1302 | such as \c{*o/mpeg;audio/x-wav}. | 1304 | such as \c{*o/mpeg;audio/x-wav}. |
1303 | 1305 | ||
1304 | See also \link applnk.html#files-and-links Files and Links\endlink. | 1306 | See also \link applnk.html#files-and-links Files and Links\endlink. |
1305 | 1307 | ||
1306 | */ | 1308 | */ |
1307 | DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : | 1309 | DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : |
1308 | AppLnkSet() | 1310 | AppLnkSet() |
1309 | { | 1311 | { |
1310 | QDir dir( directory ); | 1312 | QDir dir( directory ); |
1311 | mFile = dir.dirName(); | 1313 | mFile = dir.dirName(); |
1312 | QDict<void> reference(1021); | 1314 | QDict<void> reference(1021); |
1313 | 1315 | ||
1314 | QStringList subFilter = QStringList::split(";", mimefilter); | 1316 | QStringList subFilter = QStringList::split(";", mimefilter); |
1315 | QValueList<QRegExp> mimeFilters; | 1317 | QValueList<QRegExp> mimeFilters; |
1316 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) | 1318 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) |
1317 | mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); | 1319 | mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); |
1318 | 1320 | ||
1319 | findChildren(directory, mimeFilters, reference); | 1321 | findChildren(directory, mimeFilters, reference); |
1320 | 1322 | ||
1321 | const QList<DocLnk> &list = children(); | 1323 | const QList<DocLnk> &list = children(); |
1322 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 1324 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
1323 | reference.remove( (*it)->file() ); | 1325 | reference.remove( (*it)->file() ); |
1324 | } | 1326 | } |
1325 | for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { | 1327 | for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { |
1326 | if ( dit.current() == (void*)2 ) { | 1328 | if ( dit.current() == (void*)2 ) { |
1327 | // Unreferenced, make an unwritten link | 1329 | // Unreferenced, make an unwritten link |
1328 | DocLnk* dl = new DocLnk; | 1330 | DocLnk* dl = new DocLnk; |
1329 | QFileInfo fi( dit.currentKey() ); | 1331 | QFileInfo fi( dit.currentKey() ); |
1330 | dl->setFile(fi.filePath()); | 1332 | dl->setFile(fi.filePath()); |
1331 | dl->setName(fi.baseName()); | 1333 | dl->setName(fi.baseName()); |
1332 | // #### default to current path? | 1334 | // #### default to current path? |
1333 | // dl->setCategories( ... ); | 1335 | // dl->setCategories( ... ); |
1334 | bool match = mimefilter.isNull(); | 1336 | bool match = mimefilter.isNull(); |
1335 | if ( !match ) | 1337 | if ( !match ) |
1336 | for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) | 1338 | for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) |
1337 | if ( (*it).match(dl->type()) >= 0 ) | 1339 | if ( (*it).match(dl->type()) >= 0 ) |
1338 | match = TRUE; | 1340 | match = TRUE; |
1339 | if ( match /* && dl->type() != "application/octet-stream" */ | 1341 | if ( match /* && dl->type() != "application/octet-stream" */ |
1340 | && !!dl->exec() ) | 1342 | && !!dl->exec() ) |
1341 | add(dl); | 1343 | add(dl); |
1342 | else | 1344 | else |
1343 | delete dl; | 1345 | delete dl; |
1344 | } | 1346 | } |
1345 | } | 1347 | } |
1346 | } | 1348 | } |
1347 | 1349 | ||
1348 | // other becomes empty | 1350 | // other becomes empty |
1349 | /*! | 1351 | /*! |
1350 | Transfers all DocLnk objects from \a other to this set. \a other becomes | 1352 | Transfers all DocLnk objects from \a other to this set. \a other becomes |
1351 | empty. | 1353 | empty. |
1352 | */ | 1354 | */ |
1353 | void DocLnkSet::appendFrom( DocLnkSet& other ) | 1355 | void DocLnkSet::appendFrom( DocLnkSet& other ) |
1354 | { | 1356 | { |
1355 | if ( &other == this ) | 1357 | if ( &other == this ) |
1356 | return; | 1358 | return; |
1357 | QListIterator<AppLnk> it( other.mApps ); | 1359 | QListIterator<AppLnk> it( other.mApps ); |
1358 | for ( ; it.current(); ) { | 1360 | for ( ; it.current(); ) { |
1359 | mApps.append(*it); | 1361 | mApps.append(*it); |
1360 | ++it; | 1362 | ++it; |
1361 | } | 1363 | } |
1362 | other.mApps.clear(); | 1364 | other.mApps.clear(); |
1363 | } | 1365 | } |
1364 | 1366 | ||
1365 | void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) | 1367 | void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) |
1366 | { | 1368 | { |
1367 | depth++; | 1369 | depth++; |
1368 | if ( depth > 10 ) | 1370 | if ( depth > 10 ) |
1369 | return; | 1371 | return; |
1370 | 1372 | ||
1371 | QDir dir( dr ); | 1373 | QDir dir( dr ); |
1372 | 1374 | ||
1373 | /* Opie got a different approach | 1375 | /* Opie got a different approach |
1374 | * I guess it's geek vs. consumer | 1376 | * I guess it's geek vs. consumer |
1375 | * in this case to be discussed | 1377 | * in this case to be discussed |
1376 | */ | 1378 | */ |
1377 | if ( dir.exists( ".Qtopia-ignore" ) ) | 1379 | if ( dir.exists( ".Qtopia-ignore" ) ) |
1378 | return; | 1380 | return; |
1379 | 1381 | ||
1380 | const QFileInfoList *list = dir.entryInfoList(); | 1382 | const QFileInfoList *list = dir.entryInfoList(); |
1381 | if ( list ) { | 1383 | if ( list ) { |
1382 | QFileInfo* fi; | 1384 | QFileInfo* fi; |
1383 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1385 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1384 | QString bn = fi->fileName(); | 1386 | QString bn = fi->fileName(); |