author | mickeyl <mickeyl> | 2004-03-08 16:37:42 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-08 16:37:42 (UTC) |
commit | 2599910741451f86323af10585c858d217a122d5 (patch) (unidiff) | |
tree | e00a51cc13f2cfd85eb79e9af7a79d69f777ad77 | |
parent | 82fb70f4e5d8582185da89264e1a1e3b2517f459 (diff) | |
download | opie-2599910741451f86323af10585c858d217a122d5.zip opie-2599910741451f86323af10585c858d217a122d5.tar.gz opie-2599910741451f86323af10585c858d217a122d5.tar.bz2 |
support launching applications with user defined arguments
-rw-r--r-- | library/applnk.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 9c60f1a..5f7da8e 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -286,803 +286,806 @@ int AppLnk::bigIconSize() | |||
286 | */ | 286 | */ |
287 | /*! | 287 | /*! |
288 | \fn QString AppLnk::comment() const | 288 | \fn QString AppLnk::comment() const |
289 | 289 | ||
290 | Returns the Comment property. | 290 | Returns the Comment property. |
291 | 291 | ||
292 | \sa setComment() | 292 | \sa setComment() |
293 | */ | 293 | */ |
294 | /*! | 294 | /*! |
295 | \fn QStringList AppLnk::mimeTypes() const | 295 | \fn QStringList AppLnk::mimeTypes() const |
296 | 296 | ||
297 | Returns the MimeTypes property. This is the list of MIME types | 297 | Returns the MimeTypes property. This is the list of MIME types |
298 | that the application can view or edit. | 298 | that the application can view or edit. |
299 | */ | 299 | */ |
300 | /*! | 300 | /*! |
301 | \fn const QArray<int>& AppLnk::categories() const | 301 | \fn const QArray<int>& AppLnk::categories() const |
302 | 302 | ||
303 | Returns the Categories property. | 303 | Returns the Categories property. |
304 | 304 | ||
305 | See the CategoryWidget for more details. | 305 | See the CategoryWidget for more details. |
306 | 306 | ||
307 | \sa setCategories() | 307 | \sa setCategories() |
308 | */ | 308 | */ |
309 | 309 | ||
310 | const QArray<int>& AppLnk::categories() const | 310 | const QArray<int>& AppLnk::categories() const |
311 | { | 311 | { |
312 | d->ensureCatArray(); | 312 | d->ensureCatArray(); |
313 | return d->mCat; | 313 | return d->mCat; |
314 | } | 314 | } |
315 | 315 | ||
316 | /*! | 316 | /*! |
317 | \fn int AppLnk::id() const | 317 | \fn int AppLnk::id() const |
318 | 318 | ||
319 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, | 319 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, |
320 | this value is 0, otherwise it is a value that is unique for the | 320 | this value is 0, otherwise it is a value that is unique for the |
321 | duration of the current process. | 321 | duration of the current process. |
322 | 322 | ||
323 | \sa AppLnkSet::find() | 323 | \sa AppLnkSet::find() |
324 | */ | 324 | */ |
325 | 325 | ||
326 | /*! | 326 | /*! |
327 | \fn bool AppLnk::isValid() const | 327 | \fn bool AppLnk::isValid() const |
328 | 328 | ||
329 | Returns TRUE if this AppLnk is valid; otherwise returns FALSE. | 329 | Returns TRUE if this AppLnk is valid; otherwise returns FALSE. |
330 | */ | 330 | */ |
331 | /*! | 331 | /*! |
332 | \fn bool AppLnk::fileKnown() const | 332 | \fn bool AppLnk::fileKnown() const |
333 | 333 | ||
334 | If the with the AppLnk associated file is not equal to QString::null | 334 | If the with the AppLnk associated file is not equal to QString::null |
335 | */ | 335 | */ |
336 | /*! | 336 | /*! |
337 | \fn bool AppLnk::linkFileKnown()const | 337 | \fn bool AppLnk::linkFileKnown()const |
338 | 338 | ||
339 | The filename of the AppLnk | 339 | The filename of the AppLnk |
340 | 340 | ||
341 | */ | 341 | */ |
342 | /*! | 342 | /*! |
343 | \fn void AppLnk::setRotation( const QString& ) | 343 | \fn void AppLnk::setRotation( const QString& ) |
344 | 344 | ||
345 | The default rotation of the associated application. This | 345 | The default rotation of the associated application. This |
346 | function is included inline for binary compatible issues | 346 | function is included inline for binary compatible issues |
347 | */ | 347 | */ |
348 | /*! | 348 | /*! |
349 | Creates an invalid AppLnk. | 349 | Creates an invalid AppLnk. |
350 | 350 | ||
351 | \sa isValid() | 351 | \sa isValid() |
352 | */ | 352 | */ |
353 | AppLnk::AppLnk() | 353 | AppLnk::AppLnk() |
354 | { | 354 | { |
355 | mId = 0; | 355 | mId = 0; |
356 | d = new AppLnkPrivate(); | 356 | d = new AppLnkPrivate(); |
357 | } | 357 | } |
358 | 358 | ||
359 | /*! | 359 | /*! |
360 | Loads \a file (e.g. \e app.desktop) as an AppLnk. | 360 | Loads \a file (e.g. \e app.desktop) as an AppLnk. |
361 | 361 | ||
362 | \sa writeLink() | 362 | \sa writeLink() |
363 | */ | 363 | */ |
364 | AppLnk::AppLnk( const QString &file ) | 364 | AppLnk::AppLnk( const QString &file ) |
365 | { | 365 | { |
366 | QStringList sl; | 366 | QStringList sl; |
367 | d = new AppLnkPrivate(); | 367 | d = new AppLnkPrivate(); |
368 | if ( !file.isNull() ) { | 368 | if ( !file.isNull() ) { |
369 | Config config( file, Config::File ); | 369 | Config config( file, Config::File ); |
370 | 370 | ||
371 | if ( config.isValid() ) { | 371 | if ( config.isValid() ) { |
372 | config.setGroup( "Desktop Entry" ); | 372 | config.setGroup( "Desktop Entry" ); |
373 | 373 | ||
374 | mName = config.readEntry( "Name", file ); | 374 | mName = config.readEntry( "Name", file ); |
375 | mExec = config.readEntry( "Exec" ); | 375 | mExec = config.readEntry( "Exec" ); |
376 | mType = config.readEntry( "Type", QString::null ); | 376 | mType = config.readEntry( "Type", QString::null ); |
377 | mIconFile = config.readEntry( "Icon", QString::null ); | 377 | mIconFile = config.readEntry( "Icon", QString::null ); |
378 | mRotation = config.readEntry( "Rotation", "" ); | 378 | mRotation = config.readEntry( "Rotation", "" ); |
379 | mComment = config.readEntry( "Comment", QString::null ); | 379 | mComment = config.readEntry( "Comment", QString::null ); |
380 | // MIME types are case-insensitive. | 380 | // MIME types are case-insensitive. |
381 | mMimeTypes = config.readListEntry( "MimeType", ';' ); | 381 | mMimeTypes = config.readListEntry( "MimeType", ';' ); |
382 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) | 382 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) |
383 | *it = (*it).lower(); | 383 | *it = (*it).lower(); |
384 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); | 384 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); |
385 | mLinkFile = file; | 385 | mLinkFile = file; |
386 | mFile = config.readEntry("File", QString::null); | 386 | mFile = config.readEntry("File", QString::null); |
387 | if ( !mExec. isEmpty ( )) { | 387 | if ( !mExec. isEmpty ( )) { |
388 | mFile = QString::null; | 388 | mFile = QString::null; |
389 | } | 389 | } |
390 | else if ( mFile[0] != '/' ) { | 390 | else if ( mFile[0] != '/' ) { |
391 | int slash = file.findRev('/'); | 391 | int slash = file.findRev('/'); |
392 | if ( slash >= 0 ) { | 392 | if ( slash >= 0 ) { |
393 | mFile = file.left(slash) + '/' + mFile; | 393 | mFile = file.left(slash) + '/' + mFile; |
394 | } | 394 | } |
395 | } | 395 | } |
396 | d->mCatList = config.readListEntry("Categories", ';'); | 396 | d->mCatList = config.readListEntry("Categories", ';'); |
397 | if ( d->mCatList[0].toInt() < -1 ) { | 397 | if ( d->mCatList[0].toInt() < -1 ) { |
398 | // numeric cats in file! convert to text | 398 | // numeric cats in file! convert to text |
399 | Categories cat( 0 ); | 399 | Categories cat( 0 ); |
400 | cat.load( categoryFileName() ); | 400 | cat.load( categoryFileName() ); |
401 | d->mCat.resize( d->mCatList.count() ); | 401 | d->mCat.resize( d->mCatList.count() ); |
402 | int i; | 402 | int i; |
403 | QStringList::ConstIterator it; | 403 | QStringList::ConstIterator it; |
404 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); | 404 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); |
405 | ++it, i++ ) { | 405 | ++it, i++ ) { |
406 | bool number; | 406 | bool number; |
407 | int id = (*it).toInt( &number ); | 407 | int id = (*it).toInt( &number ); |
408 | if ( !number ) { | 408 | if ( !number ) { |
409 | // convert from text | 409 | // convert from text |
410 | id = cat.id( "Document View", *it ); | 410 | id = cat.id( "Document View", *it ); |
411 | if ( id == 0 ) | 411 | if ( id == 0 ) |
412 | id = cat.addCategory( "Document View", *it ); | 412 | id = cat.addCategory( "Document View", *it ); |
413 | } | 413 | } |
414 | d->mCat[i] = id; | 414 | d->mCat[i] = id; |
415 | } | 415 | } |
416 | d->updateCatListFromArray(); | 416 | d->updateCatListFromArray(); |
417 | } | 417 | } |
418 | } | 418 | } |
419 | } | 419 | } |
420 | mId = 0; | 420 | mId = 0; |
421 | } | 421 | } |
422 | 422 | ||
423 | AppLnk& AppLnk::operator=(const AppLnk ©) | 423 | AppLnk& AppLnk::operator=(const AppLnk ©) |
424 | { | 424 | { |
425 | if ( this == © ) return *this; | 425 | if ( this == © ) return *this; |
426 | if ( mId ) | 426 | if ( mId ) |
427 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 427 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
428 | if ( d ) | 428 | if ( d ) |
429 | delete d; | 429 | delete d; |
430 | 430 | ||
431 | 431 | ||
432 | mName = copy.mName; | 432 | mName = copy.mName; |
433 | 433 | ||
434 | /* remove for Qtopia 3.0 -zecke */ | 434 | /* remove for Qtopia 3.0 -zecke */ |
435 | mPixmap = copy.mPixmap; | 435 | mPixmap = copy.mPixmap; |
436 | mBigPixmap = copy.mBigPixmap; | 436 | mBigPixmap = copy.mBigPixmap; |
437 | 437 | ||
438 | mExec = copy.mExec; | 438 | mExec = copy.mExec; |
439 | mType = copy.mType; | 439 | mType = copy.mType; |
440 | mRotation = copy.mRotation; | 440 | mRotation = copy.mRotation; |
441 | mComment = copy.mComment; | 441 | mComment = copy.mComment; |
442 | mFile = copy.mFile; | 442 | mFile = copy.mFile; |
443 | mLinkFile = copy.mLinkFile; | 443 | mLinkFile = copy.mLinkFile; |
444 | mIconFile = copy.mIconFile; | 444 | mIconFile = copy.mIconFile; |
445 | mMimeTypes = copy.mMimeTypes; | 445 | mMimeTypes = copy.mMimeTypes; |
446 | mMimeTypeIcons = copy.mMimeTypeIcons; | 446 | mMimeTypeIcons = copy.mMimeTypeIcons; |
447 | mId = 0; | 447 | mId = 0; |
448 | d = new AppLnkPrivate(); | 448 | d = new AppLnkPrivate(); |
449 | d->mCat = copy.d->mCat; | 449 | d->mCat = copy.d->mCat; |
450 | d->mCatList = copy.d->mCatList; | 450 | d->mCatList = copy.d->mCatList; |
451 | d->mPixmaps = copy.d->mPixmaps; | 451 | d->mPixmaps = copy.d->mPixmaps; |
452 | 452 | ||
453 | return *this; | 453 | return *this; |
454 | } | 454 | } |
455 | /*! | 455 | /*! |
456 | protected internally to share code | 456 | protected internally to share code |
457 | should I document that at all? | 457 | should I document that at all? |
458 | I don't know the TT style for that | 458 | I don't know the TT style for that |
459 | */ | 459 | */ |
460 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { | 460 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { |
461 | if ( d->mPixmaps[pos].isNull() ) { | 461 | if ( d->mPixmaps[pos].isNull() ) { |
462 | AppLnk* that = (AppLnk*)this; | 462 | AppLnk* that = (AppLnk*)this; |
463 | if ( mIconFile.isEmpty() ) { | 463 | if ( mIconFile.isEmpty() ) { |
464 | MimeType mt(type()); | 464 | MimeType mt(type()); |
465 | that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); | 465 | that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); |
466 | if ( that->d->mPixmaps[pos].isNull() ) | 466 | if ( that->d->mPixmaps[pos].isNull() ) |
467 | that->d->mPixmaps[pos].convertFromImage( | 467 | that->d->mPixmaps[pos].convertFromImage( |
468 | Resource::loadImage("UnknownDocument") | 468 | Resource::loadImage("UnknownDocument") |
469 | .smoothScale( size, size ) ); | 469 | .smoothScale( size, size ) ); |
470 | return that->d->mPixmaps[pos]; | 470 | return that->d->mPixmaps[pos]; |
471 | } | 471 | } |
472 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); | 472 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); |
473 | if ( unscaledIcon.isNull() ) { | 473 | if ( unscaledIcon.isNull() ) { |
474 | // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); | 474 | // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); |
475 | that->d->mPixmaps[pos].convertFromImage( | 475 | that->d->mPixmaps[pos].convertFromImage( |
476 | Resource::loadImage("UnknownDocument") | 476 | Resource::loadImage("UnknownDocument") |
477 | .smoothScale( size, size ) ); | 477 | .smoothScale( size, size ) ); |
478 | } else { | 478 | } else { |
479 | that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 479 | that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
480 | that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 480 | that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
481 | } | 481 | } |
482 | return that->d->mPixmaps[pos]; | 482 | return that->d->mPixmaps[pos]; |
483 | } | 483 | } |
484 | return d->mPixmaps[pos]; | 484 | return d->mPixmaps[pos]; |
485 | } | 485 | } |
486 | 486 | ||
487 | /*! | 487 | /*! |
488 | Returns a small pixmap associated with the application. | 488 | Returns a small pixmap associated with the application. |
489 | 489 | ||
490 | \sa bigPixmap() setIcon() | 490 | \sa bigPixmap() setIcon() |
491 | */ | 491 | */ |
492 | const QPixmap& AppLnk::pixmap() const | 492 | const QPixmap& AppLnk::pixmap() const |
493 | { | 493 | { |
494 | if ( d->mPixmaps[0].isNull() ) { | 494 | if ( d->mPixmaps[0].isNull() ) { |
495 | return pixmap(AppLnkPrivate::Normal, smallSize ); | 495 | return pixmap(AppLnkPrivate::Normal, smallSize ); |
496 | } | 496 | } |
497 | return d->mPixmaps[0]; | 497 | return d->mPixmaps[0]; |
498 | } | 498 | } |
499 | 499 | ||
500 | /*! | 500 | /*! |
501 | Returns a large pixmap associated with the application. | 501 | Returns a large pixmap associated with the application. |
502 | 502 | ||
503 | \sa pixmap() setIcon() | 503 | \sa pixmap() setIcon() |
504 | */ | 504 | */ |
505 | const QPixmap& AppLnk::bigPixmap() const | 505 | const QPixmap& AppLnk::bigPixmap() const |
506 | { | 506 | { |
507 | if ( d->mPixmaps[1].isNull() ) { | 507 | if ( d->mPixmaps[1].isNull() ) { |
508 | return pixmap( AppLnkPrivate::Big, bigSize ); | 508 | return pixmap( AppLnkPrivate::Big, bigSize ); |
509 | } | 509 | } |
510 | return d->mPixmaps[1]; | 510 | return d->mPixmaps[1]; |
511 | } | 511 | } |
512 | 512 | ||
513 | /*! | 513 | /*! |
514 | Returns the type of the AppLnk. For applications, games and | 514 | Returns the type of the AppLnk. For applications, games and |
515 | settings the type is \c Application; for documents the type is the | 515 | settings the type is \c Application; for documents the type is the |
516 | document's MIME type. | 516 | document's MIME type. |
517 | */ | 517 | */ |
518 | QString AppLnk::type() const | 518 | QString AppLnk::type() const |
519 | { | 519 | { |
520 | if ( mType.isNull() ) { | 520 | if ( mType.isNull() ) { |
521 | AppLnk* that = (AppLnk*)this; | 521 | AppLnk* that = (AppLnk*)this; |
522 | QString f = file(); | 522 | QString f = file(); |
523 | if ( !f.isNull() ) { | 523 | if ( !f.isNull() ) { |
524 | MimeType mt(f); | 524 | MimeType mt(f); |
525 | that->mType = mt.id(); | 525 | that->mType = mt.id(); |
526 | return that->mType; | 526 | return that->mType; |
527 | } | 527 | } |
528 | } | 528 | } |
529 | return mType; | 529 | return mType; |
530 | } | 530 | } |
531 | 531 | ||
532 | /*! | 532 | /*! |
533 | Returns the file associated with the AppLnk. | 533 | Returns the file associated with the AppLnk. |
534 | 534 | ||
535 | \sa exec() name() | 535 | \sa exec() name() |
536 | */ | 536 | */ |
537 | QString AppLnk::file() const | 537 | QString AppLnk::file() const |
538 | { | 538 | { |
539 | if ( mExec.isEmpty ( ) && mFile.isNull() ) { | 539 | if ( mExec.isEmpty ( ) && mFile.isNull() ) { |
540 | AppLnk* that = (AppLnk*)this; | 540 | AppLnk* that = (AppLnk*)this; |
541 | QString ext = MimeType(mType).extension(); | 541 | QString ext = MimeType(mType).extension(); |
542 | if ( !ext.isEmpty() ) | 542 | if ( !ext.isEmpty() ) |
543 | ext = "." + ext; | 543 | ext = "." + ext; |
544 | if ( !mLinkFile.isEmpty() ) { | 544 | if ( !mLinkFile.isEmpty() ) { |
545 | that->mFile = | 545 | that->mFile = |
546 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") | 546 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") |
547 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; | 547 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; |
548 | qDebug("mFile now == %s", mFile.latin1()); | 548 | qDebug("mFile now == %s", mFile.latin1()); |
549 | } else if ( mType.contains('/') ) { | 549 | } else if ( mType.contains('/') ) { |
550 | that->mFile = | 550 | that->mFile = |
551 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); | 551 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); |
552 | /* | 552 | /* |
553 | * A file with the same name or a .desktop file already exists | 553 | * A file with the same name or a .desktop file already exists |
554 | */ | 554 | */ |
555 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { | 555 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { |
556 | int n=1; | 556 | int n=1; |
557 | QString nn; | 557 | QString nn; |
558 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) | 558 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) |
559 | || QFile::exists(nn+".desktop")) | 559 | || QFile::exists(nn+".desktop")) |
560 | n++; | 560 | n++; |
561 | that->mFile = nn; | 561 | that->mFile = nn; |
562 | } | 562 | } |
563 | that->mLinkFile = that->mFile+".desktop"; | 563 | that->mLinkFile = that->mFile+".desktop"; |
564 | that->mFile += ext; | 564 | that->mFile += ext; |
565 | } | 565 | } |
566 | prepareDirectories(that->mFile); | 566 | prepareDirectories(that->mFile); |
567 | if ( !that->mFile.isEmpty() ) { | 567 | if ( !that->mFile.isEmpty() ) { |
568 | QFile f(that->mFile); | 568 | QFile f(that->mFile); |
569 | if ( !f.open(IO_WriteOnly) ) | 569 | if ( !f.open(IO_WriteOnly) ) |
570 | that->mFile = QString::null; | 570 | that->mFile = QString::null; |
571 | return that->mFile; | 571 | return that->mFile; |
572 | } | 572 | } |
573 | } | 573 | } |
574 | return mFile; | 574 | return mFile; |
575 | } | 575 | } |
576 | 576 | ||
577 | /*! | 577 | /*! |
578 | Returns the desktop file corresponding to this AppLnk. | 578 | Returns the desktop file corresponding to this AppLnk. |
579 | 579 | ||
580 | \sa file() exec() name() | 580 | \sa file() exec() name() |
581 | */ | 581 | */ |
582 | QString AppLnk::linkFile() const | 582 | QString AppLnk::linkFile() const |
583 | { | 583 | { |
584 | if ( mLinkFile.isNull() ) { | 584 | if ( mLinkFile.isNull() ) { |
585 | AppLnk* that = (AppLnk*)this; | 585 | AppLnk* that = (AppLnk*)this; |
586 | if ( type().contains('/') ) { | 586 | if ( type().contains('/') ) { |
587 | StorageInfo storage; | 587 | StorageInfo storage; |
588 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); | 588 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); |
589 | /* tmpfs + and ramfs are available too but not removable | 589 | /* tmpfs + and ramfs are available too but not removable |
590 | * either we fix storage or add this | 590 | * either we fix storage or add this |
591 | */ | 591 | */ |
592 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { | 592 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { |
593 | that->mLinkFile = fs->path(); | 593 | that->mLinkFile = fs->path(); |
594 | } else | 594 | } else |
595 | that->mLinkFile = getenv( "HOME" ); | 595 | that->mLinkFile = getenv( "HOME" ); |
596 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); | 596 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); |
597 | 597 | ||
598 | /* the desktop file exists make sure we don't point to the same file */ | 598 | /* the desktop file exists make sure we don't point to the same file */ |
599 | if ( QFile::exists(that->mLinkFile+".desktop") ) { | 599 | if ( QFile::exists(that->mLinkFile+".desktop") ) { |
600 | AppLnk lnk( that->mLinkFile + ".desktop" ); | 600 | AppLnk lnk( that->mLinkFile + ".desktop" ); |
601 | 601 | ||
602 | /* the linked is different */ | 602 | /* the linked is different */ |
603 | if(that->file() != lnk.file() ) { | 603 | if(that->file() != lnk.file() ) { |
604 | int n = 1; | 604 | int n = 1; |
605 | QString nn; | 605 | QString nn; |
606 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { | 606 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { |
607 | n++; | 607 | n++; |
608 | /* just to be sure */ | 608 | /* just to be sure */ |
609 | AppLnk lnk(nn ); | 609 | AppLnk lnk(nn ); |
610 | if (lnk.file() == that->file() ) | 610 | if (lnk.file() == that->file() ) |
611 | break; | 611 | break; |
612 | } | 612 | } |
613 | that->mLinkFile = nn; | 613 | that->mLinkFile = nn; |
614 | } | 614 | } |
615 | } | 615 | } |
616 | that->mLinkFile += ".desktop"; | 616 | that->mLinkFile += ".desktop"; |
617 | storeLink(); | 617 | storeLink(); |
618 | } | 618 | } |
619 | return that->mLinkFile; | 619 | return that->mLinkFile; |
620 | } | 620 | } |
621 | return mLinkFile; | 621 | return mLinkFile; |
622 | } | 622 | } |
623 | 623 | ||
624 | /*! | 624 | /*! |
625 | Copies \a copy. | 625 | Copies \a copy. |
626 | */ | 626 | */ |
627 | AppLnk::AppLnk( const AppLnk © ) | 627 | AppLnk::AppLnk( const AppLnk © ) |
628 | { | 628 | { |
629 | mName = copy.mName; | 629 | mName = copy.mName; |
630 | mPixmap = copy.mPixmap; | 630 | mPixmap = copy.mPixmap; |
631 | mBigPixmap = copy.mBigPixmap; | 631 | mBigPixmap = copy.mBigPixmap; |
632 | mExec = copy.mExec; | 632 | mExec = copy.mExec; |
633 | mType = copy.mType; | 633 | mType = copy.mType; |
634 | mRotation = copy.mRotation; | 634 | mRotation = copy.mRotation; |
635 | mComment = copy.mComment; | 635 | mComment = copy.mComment; |
636 | mFile = copy.mFile; | 636 | mFile = copy.mFile; |
637 | mLinkFile = copy.mLinkFile; | 637 | mLinkFile = copy.mLinkFile; |
638 | mIconFile = copy.mIconFile; | 638 | mIconFile = copy.mIconFile; |
639 | mMimeTypes = copy.mMimeTypes; | 639 | mMimeTypes = copy.mMimeTypes; |
640 | mMimeTypeIcons = copy.mMimeTypeIcons; | 640 | mMimeTypeIcons = copy.mMimeTypeIcons; |
641 | mId = 0; | 641 | mId = 0; |
642 | d = new AppLnkPrivate(); | 642 | d = new AppLnkPrivate(); |
643 | d->mCat = copy.d->mCat; | 643 | d->mCat = copy.d->mCat; |
644 | d->mCatList = copy.d->mCatList; | 644 | d->mCatList = copy.d->mCatList; |
645 | d->mPixmaps = copy.d->mPixmaps; | 645 | d->mPixmaps = copy.d->mPixmaps; |
646 | } | 646 | } |
647 | 647 | ||
648 | /*! | 648 | /*! |
649 | Destroys the AppLnk. Note that if the AppLnk is currently a member | 649 | Destroys the AppLnk. Note that if the AppLnk is currently a member |
650 | of an AppLnkSet, this will produce a run-time warning. | 650 | of an AppLnkSet, this will produce a run-time warning. |
651 | 651 | ||
652 | \sa AppLnkSet::add() AppLnkSet::remove() | 652 | \sa AppLnkSet::add() AppLnkSet::remove() |
653 | */ | 653 | */ |
654 | AppLnk::~AppLnk() | 654 | AppLnk::~AppLnk() |
655 | { | 655 | { |
656 | if ( mId ) | 656 | if ( mId ) |
657 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 657 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
658 | if ( d ) | 658 | if ( d ) |
659 | delete d; | 659 | delete d; |
660 | } | 660 | } |
661 | 661 | ||
662 | /*! | 662 | /*! |
663 | \overload | 663 | \overload |
664 | Executes the application associated with this AppLnk. | 664 | Executes the application associated with this AppLnk. |
665 | 665 | ||
666 | \sa exec() | 666 | \sa exec() |
667 | */ | 667 | */ |
668 | void AppLnk::execute() const | 668 | void AppLnk::execute() const |
669 | { | 669 | { |
670 | execute(QStringList()); | 670 | execute( QStringList::split( ' ', property( "Arguments" ) ) ); |
671 | } | 671 | } |
672 | 672 | ||
673 | /*! | 673 | /*! |
674 | Executes the application associated with this AppLnk, with | 674 | Executes the application associated with this AppLnk, with |
675 | \a args as arguments. | 675 | \a args as arguments. |
676 | 676 | ||
677 | \sa exec() | 677 | \sa exec() |
678 | */ | 678 | */ |
679 | void AppLnk::execute(const QStringList& args) const | 679 | void AppLnk::execute(const QStringList& args) const |
680 | { | 680 | { |
681 | #ifdef Q_WS_QWS | 681 | #ifdef Q_WS_QWS |
682 | if ( !mRotation.isEmpty() ) { | 682 | if ( !mRotation.isEmpty() ) { |
683 | // ######## this will only work in the server | 683 | // ######## this will only work in the server |
684 | int rot = QPEApplication::defaultRotation(); | 684 | int rot = QPEApplication::defaultRotation(); |
685 | rot = (rot+mRotation.toInt())%360; | 685 | rot = (rot+mRotation.toInt())%360; |
686 | QCString old = getenv("QWS_DISPLAY"); | 686 | QCString old = getenv("QWS_DISPLAY"); |
687 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 687 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
688 | invoke(args); | 688 | invoke(args); |
689 | setenv("QWS_DISPLAY", old.data(), 1); | 689 | setenv("QWS_DISPLAY", old.data(), 1); |
690 | } else | 690 | } else |
691 | #endif | 691 | #endif |
692 | invoke(args); | 692 | invoke(args); |
693 | } | 693 | } |
694 | 694 | ||
695 | /*! | 695 | /*! |
696 | Invokes the application associated with this AppLnk, with | 696 | Invokes the application associated with this AppLnk, with |
697 | \a args as arguments. Rotation is not taken into account by | 697 | \a args as arguments. Rotation is not taken into account by |
698 | this function, so you should not call it directly. | 698 | this function, so you should not call it directly. |
699 | 699 | ||
700 | \sa execute() | 700 | \sa execute() |
701 | */ | 701 | */ |
702 | void AppLnk::invoke(const QStringList& args) const | 702 | void AppLnk::invoke(const QStringList& args) const |
703 | { | 703 | { |
704 | Global::execute( exec(), args[0] ); | 704 | if ( property( "Arguments" ).isEmpty() ) |
705 | Global::execute( exec(), args[0] ); | ||
706 | else | ||
707 | Global::execute( exec(), args.join( " " ) ); | ||
705 | } | 708 | } |
706 | 709 | ||
707 | /*! | 710 | /*! |
708 | Sets the Exec property to \a exec. | 711 | Sets the Exec property to \a exec. |
709 | 712 | ||
710 | \sa exec() name() | 713 | \sa exec() name() |
711 | */ | 714 | */ |
712 | void AppLnk::setExec( const QString& exec ) | 715 | void AppLnk::setExec( const QString& exec ) |
713 | { | 716 | { |
714 | mExec = exec; | 717 | mExec = exec; |
715 | } | 718 | } |
716 | 719 | ||
717 | #if 0 // this was inlined for better BC | 720 | #if 0 // this was inlined for better BC |
718 | /*! | 721 | /*! |
719 | Sets the Rotation property to \a rot. | 722 | Sets the Rotation property to \a rot. |
720 | 723 | ||
721 | \sa rotation() | 724 | \sa rotation() |
722 | */ | 725 | */ |
723 | void AppLnk::setRotation ( const QString &rot ) | 726 | void AppLnk::setRotation ( const QString &rot ) |
724 | { | 727 | { |
725 | mRotation = rot; | 728 | mRotation = rot; |
726 | } | 729 | } |
727 | #endif | 730 | #endif |
728 | 731 | ||
729 | /*! | 732 | /*! |
730 | Sets the Name property to \a docname. | 733 | Sets the Name property to \a docname. |
731 | 734 | ||
732 | \sa name() | 735 | \sa name() |
733 | */ | 736 | */ |
734 | void AppLnk::setName( const QString& docname ) | 737 | void AppLnk::setName( const QString& docname ) |
735 | { | 738 | { |
736 | mName = docname; | 739 | mName = docname; |
737 | } | 740 | } |
738 | 741 | ||
739 | /*! | 742 | /*! |
740 | Sets the File property to \a filename. | 743 | Sets the File property to \a filename. |
741 | 744 | ||
742 | \sa file() name() | 745 | \sa file() name() |
743 | */ | 746 | */ |
744 | void AppLnk::setFile( const QString& filename ) | 747 | void AppLnk::setFile( const QString& filename ) |
745 | { | 748 | { |
746 | mFile = filename; | 749 | mFile = filename; |
747 | } | 750 | } |
748 | 751 | ||
749 | /*! | 752 | /*! |
750 | Sets the LinkFile property to \a filename. | 753 | Sets the LinkFile property to \a filename. |
751 | 754 | ||
752 | \sa linkFile() | 755 | \sa linkFile() |
753 | */ | 756 | */ |
754 | void AppLnk::setLinkFile( const QString& filename ) | 757 | void AppLnk::setLinkFile( const QString& filename ) |
755 | { | 758 | { |
756 | mLinkFile = filename; | 759 | mLinkFile = filename; |
757 | } | 760 | } |
758 | 761 | ||
759 | /*! | 762 | /*! |
760 | Sets the Comment property to \a comment. | 763 | Sets the Comment property to \a comment. |
761 | 764 | ||
762 | This text is displayed in the 'Details Dialog', for example if the | 765 | This text is displayed in the 'Details Dialog', for example if the |
763 | user uses the 'press-and-hold' gesture. | 766 | user uses the 'press-and-hold' gesture. |
764 | 767 | ||
765 | \sa comment() | 768 | \sa comment() |
766 | */ | 769 | */ |
767 | void AppLnk::setComment( const QString& comment ) | 770 | void AppLnk::setComment( const QString& comment ) |
768 | { | 771 | { |
769 | mComment = comment; | 772 | mComment = comment; |
770 | } | 773 | } |
771 | 774 | ||
772 | /*! | 775 | /*! |
773 | Sets the Type property to \a type. | 776 | Sets the Type property to \a type. |
774 | 777 | ||
775 | For applications, games and settings the type should be \c | 778 | For applications, games and settings the type should be \c |
776 | Application; for documents the type should be the document's MIME | 779 | Application; for documents the type should be the document's MIME |
777 | type. | 780 | type. |
778 | 781 | ||
779 | \sa type() | 782 | \sa type() |
780 | */ | 783 | */ |
781 | void AppLnk::setType( const QString& type ) | 784 | void AppLnk::setType( const QString& type ) |
782 | { | 785 | { |
783 | mType = type; | 786 | mType = type; |
784 | } | 787 | } |
785 | 788 | ||
786 | /*! | 789 | /*! |
787 | \fn QString AppLnk::icon() const | 790 | \fn QString AppLnk::icon() const |
788 | 791 | ||
789 | Returns the Icon property. | 792 | Returns the Icon property. |
790 | 793 | ||
791 | \sa setIcon() | 794 | \sa setIcon() |
792 | */ | 795 | */ |
793 | 796 | ||
794 | /*! | 797 | /*! |
795 | Sets the Icon property to \a iconname. This is the filename from | 798 | Sets the Icon property to \a iconname. This is the filename from |
796 | which the pixmap() and bigPixmap() are obtained. | 799 | which the pixmap() and bigPixmap() are obtained. |
797 | 800 | ||
798 | \sa icon() setSmallIconSize() setBigIconSize() | 801 | \sa icon() setSmallIconSize() setBigIconSize() |
799 | */ | 802 | */ |
800 | void AppLnk::setIcon( const QString& iconname ) | 803 | void AppLnk::setIcon( const QString& iconname ) |
801 | { | 804 | { |
802 | mIconFile = iconname; | 805 | mIconFile = iconname; |
803 | QImage unscaledIcon = Resource::loadImage( mIconFile ); | 806 | QImage unscaledIcon = Resource::loadImage( mIconFile ); |
804 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 807 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
805 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 808 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
806 | } | 809 | } |
807 | 810 | ||
808 | /*! | 811 | /*! |
809 | Sets the Categories property to \a c. | 812 | Sets the Categories property to \a c. |
810 | 813 | ||
811 | See the CategoryWidget for more details. | 814 | See the CategoryWidget for more details. |
812 | 815 | ||
813 | \sa categories() | 816 | \sa categories() |
814 | */ | 817 | */ |
815 | void AppLnk::setCategories( const QArray<int>& c ) | 818 | void AppLnk::setCategories( const QArray<int>& c ) |
816 | { | 819 | { |
817 | d->mCat = c; | 820 | d->mCat = c; |
818 | d->updateCatListFromArray(); | 821 | d->updateCatListFromArray(); |
819 | } | 822 | } |
820 | 823 | ||
821 | /*! | 824 | /*! |
822 | \fn QStringList AppLnk::mimeTypeIcons() const | 825 | \fn QStringList AppLnk::mimeTypeIcons() const |
823 | 826 | ||
824 | Returns the MimeTypeIcons property of the AppLnk. | 827 | Returns the MimeTypeIcons property of the AppLnk. |
825 | */ | 828 | */ |
826 | 829 | ||
827 | /*! | 830 | /*! |
828 | Attempts to ensure that the link file for this AppLnk exists, | 831 | Attempts to ensure that the link file for this AppLnk exists, |
829 | including creating any required directories. Returns TRUE if | 832 | including creating any required directories. Returns TRUE if |
830 | successful; otherwise returns FALSE. | 833 | successful; otherwise returns FALSE. |
831 | 834 | ||
832 | You should not need to use this function. | 835 | You should not need to use this function. |
833 | */ | 836 | */ |
834 | bool AppLnk::ensureLinkExists() const | 837 | bool AppLnk::ensureLinkExists() const |
835 | { | 838 | { |
836 | QString lf = linkFile(); | 839 | QString lf = linkFile(); |
837 | return prepareDirectories(lf); | 840 | return prepareDirectories(lf); |
838 | } | 841 | } |
839 | 842 | ||
840 | /*! | 843 | /*! |
841 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; | 844 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; |
842 | otherwise returns FALSE. | 845 | otherwise returns FALSE. |
843 | 846 | ||
844 | In addition, the "linkChanged(QString)" message is sent to the | 847 | In addition, the "linkChanged(QString)" message is sent to the |
845 | "QPE/System" \link qcop.html QCop\endlink channel. | 848 | "QPE/System" \link qcop.html QCop\endlink channel. |
846 | */ | 849 | */ |
847 | bool AppLnk::writeLink() const | 850 | bool AppLnk::writeLink() const |
848 | { | 851 | { |
849 | // Only re-writes settable parts | 852 | // Only re-writes settable parts |
850 | QString lf = linkFile(); | 853 | QString lf = linkFile(); |
851 | if ( !ensureLinkExists() ) | 854 | if ( !ensureLinkExists() ) |
852 | return FALSE; | 855 | return FALSE; |
853 | storeLink(); | 856 | storeLink(); |
854 | return TRUE; | 857 | return TRUE; |
855 | } | 858 | } |
856 | 859 | ||
857 | /*! | 860 | /*! |
858 | \internal | 861 | \internal |
859 | */ | 862 | */ |
860 | void AppLnk::storeLink() const | 863 | void AppLnk::storeLink() const |
861 | { | 864 | { |
862 | Config config( mLinkFile, Config::File ); | 865 | Config config( mLinkFile, Config::File ); |
863 | config.setGroup("Desktop Entry"); | 866 | config.setGroup("Desktop Entry"); |
864 | config.writeEntry("Name",mName); | 867 | config.writeEntry("Name",mName); |
865 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); | 868 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); |
866 | config.writeEntry("Type",type()); | 869 | config.writeEntry("Type",type()); |
867 | if(!rotation().isEmpty()) | 870 | if(!rotation().isEmpty()) |
868 | config.writeEntry("Rotation",rotation()); | 871 | config.writeEntry("Rotation",rotation()); |
869 | else | 872 | else |
870 | config.removeEntry("Rotation"); | 873 | config.removeEntry("Rotation"); |
871 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); | 874 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); |
872 | QString f = file(); | 875 | QString f = file(); |
873 | int i = 0; | 876 | int i = 0; |
874 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) | 877 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) |
875 | i++; | 878 | i++; |
876 | while ( i && f[i] != '/' ) | 879 | while ( i && f[i] != '/' ) |
877 | i--; | 880 | i--; |
878 | // simple case where in the same directory | 881 | // simple case where in the same directory |
879 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) | 882 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) |
880 | f = f.mid(i+1); | 883 | f = f.mid(i+1); |
881 | // ### could do relative ie ../../otherDocs/file.doc | 884 | // ### could do relative ie ../../otherDocs/file.doc |
882 | config.writeEntry("File",f); | 885 | config.writeEntry("File",f); |
883 | config.writeEntry( "Categories", d->mCatList, ';' ); | 886 | config.writeEntry( "Categories", d->mCatList, ';' ); |
884 | 887 | ||
885 | #ifndef QT_NO_COP | 888 | #ifndef QT_NO_COP |
886 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 889 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
887 | e << mLinkFile; | 890 | e << mLinkFile; |
888 | #endif | 891 | #endif |
889 | } | 892 | } |
890 | 893 | ||
891 | /*! | 894 | /*! |
892 | Sets the property named \a key to \a value. | 895 | Sets the property named \a key to \a value. |
893 | 896 | ||
894 | \sa property() | 897 | \sa property() |
895 | */ | 898 | */ |
896 | void AppLnk::setProperty(const QString& key, const QString& value) | 899 | void AppLnk::setProperty(const QString& key, const QString& value) |
897 | { | 900 | { |
898 | if ( ensureLinkExists() ) { | 901 | if ( ensureLinkExists() ) { |
899 | Config cfg(linkFile(), Config::File); | 902 | Config cfg(linkFile(), Config::File); |
900 | cfg.writeEntry(key,value); | 903 | cfg.writeEntry(key,value); |
901 | } | 904 | } |
902 | } | 905 | } |
903 | 906 | ||
904 | /*! | 907 | /*! |
905 | Returns the property named \a key. | 908 | Returns the property named \a key. |
906 | 909 | ||
907 | \sa setProperty() | 910 | \sa setProperty() |
908 | */ | 911 | */ |
909 | QString AppLnk::property(const QString& key) const | 912 | QString AppLnk::property(const QString& key) const |
910 | { | 913 | { |
911 | QString lf = linkFile(); | 914 | QString lf = linkFile(); |
912 | if ( !QFile::exists(lf) ) | 915 | if ( !QFile::exists(lf) ) |
913 | return QString::null; | 916 | return QString::null; |
914 | Config cfg(lf, Config::File); | 917 | Config cfg(lf, Config::File); |
915 | return cfg.readEntry(key); | 918 | return cfg.readEntry(key); |
916 | } | 919 | } |
917 | 920 | ||
918 | bool AppLnk::isPreloaded() const { | 921 | bool AppLnk::isPreloaded() const { |
919 | // Preload information is stored in the Launcher config in v1.5. | 922 | // Preload information is stored in the Launcher config in v1.5. |
920 | Config cfg("Launcher"); | 923 | Config cfg("Launcher"); |
921 | cfg.setGroup("Preload"); | 924 | cfg.setGroup("Preload"); |
922 | QStringList apps = cfg.readListEntry("Apps",','); | 925 | QStringList apps = cfg.readListEntry("Apps",','); |
923 | if (apps.contains(exec())) | 926 | if (apps.contains(exec())) |
924 | return true; | 927 | return true; |
925 | return false; | 928 | return false; |
926 | } | 929 | } |
927 | 930 | ||
928 | void AppLnk::setPreloaded(bool yesNo) { | 931 | void AppLnk::setPreloaded(bool yesNo) { |
929 | // Preload information is stored in the Launcher config in v1.5. | 932 | // Preload information is stored in the Launcher config in v1.5. |
930 | Config cfg("Launcher"); | 933 | Config cfg("Launcher"); |
931 | cfg.setGroup("Preload"); | 934 | cfg.setGroup("Preload"); |
932 | QStringList apps = cfg.readListEntry("Apps", ','); | 935 | QStringList apps = cfg.readListEntry("Apps", ','); |
933 | if (apps.contains(exec()) && !yesNo) | 936 | if (apps.contains(exec()) && !yesNo) |
934 | apps.remove(exec()); | 937 | apps.remove(exec()); |
935 | else if (yesNo && !apps.contains(exec())) | 938 | else if (yesNo && !apps.contains(exec())) |
936 | apps.append(exec()); | 939 | apps.append(exec()); |
937 | cfg.writeEntry("Apps", apps, ','); | 940 | cfg.writeEntry("Apps", apps, ','); |
938 | } | 941 | } |
939 | 942 | ||
940 | 943 | ||
941 | /*! | 944 | /*! |
942 | Deletes both the linkFile() and the file() associated with this AppLnk. | 945 | Deletes both the linkFile() and the file() associated with this AppLnk. |
943 | 946 | ||
944 | \sa removeLinkFile() | 947 | \sa removeLinkFile() |
945 | */ | 948 | */ |
946 | void AppLnk::removeFiles() | 949 | void AppLnk::removeFiles() |
947 | { | 950 | { |
948 | bool valid = isValid(); | 951 | bool valid = isValid(); |
949 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { | 952 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { |
950 | if ( QFile::remove(file()) ) { | 953 | if ( QFile::remove(file()) ) { |
951 | #ifndef QT_NO_COP | 954 | #ifndef QT_NO_COP |
952 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 955 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
953 | if ( linkFileKnown() ) | 956 | if ( linkFileKnown() ) |
954 | e << linkFile(); | 957 | e << linkFile(); |
955 | else | 958 | else |
956 | e << file(); | 959 | e << file(); |
957 | #endif | 960 | #endif |
958 | } else if ( valid ) { | 961 | } else if ( valid ) { |
959 | // restore link | 962 | // restore link |
960 | writeLink(); | 963 | writeLink(); |
961 | } | 964 | } |
962 | } | 965 | } |
963 | } | 966 | } |
964 | 967 | ||
965 | /*! | 968 | /*! |
966 | Deletes the linkFile(), leaving any file() untouched. | 969 | Deletes the linkFile(), leaving any file() untouched. |
967 | 970 | ||
968 | \sa removeFiles() | 971 | \sa removeFiles() |
969 | */ | 972 | */ |
970 | void AppLnk::removeLinkFile() | 973 | void AppLnk::removeLinkFile() |
971 | { | 974 | { |
972 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { | 975 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { |
973 | #ifndef QT_NO_COP | 976 | #ifndef QT_NO_COP |
974 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 977 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
975 | e << linkFile(); | 978 | e << linkFile(); |
976 | #endif | 979 | #endif |
977 | } | 980 | } |
978 | } | 981 | } |
979 | 982 | ||
980 | class AppLnkSetPrivate { | 983 | class AppLnkSetPrivate { |
981 | public: | 984 | public: |
982 | AppLnkSetPrivate() | 985 | AppLnkSetPrivate() |
983 | { | 986 | { |
984 | typPix.setAutoDelete(TRUE); | 987 | typPix.setAutoDelete(TRUE); |
985 | typPixBig.setAutoDelete(TRUE); | 988 | typPixBig.setAutoDelete(TRUE); |
986 | typName.setAutoDelete(TRUE); | 989 | typName.setAutoDelete(TRUE); |
987 | } | 990 | } |
988 | 991 | ||
989 | QDict<QPixmap> typPix; | 992 | QDict<QPixmap> typPix; |
990 | QDict<QPixmap> typPixBig; | 993 | QDict<QPixmap> typPixBig; |
991 | QDict<QString> typName; | 994 | QDict<QString> typName; |
992 | }; | 995 | }; |
993 | 996 | ||
994 | /*! | 997 | /*! |
995 | \class AppLnkSet applnk.h | 998 | \class AppLnkSet applnk.h |
996 | \brief The AppLnkSet class is a set of AppLnk objects. | 999 | \brief The AppLnkSet class is a set of AppLnk objects. |
997 | */ | 1000 | */ |
998 | 1001 | ||
999 | /*! | 1002 | /*! |
1000 | \fn QStringList AppLnkSet::types() const | 1003 | \fn QStringList AppLnkSet::types() const |
1001 | 1004 | ||
1002 | Returns the list of \link applnk.html#Types types\endlink in the set. | 1005 | Returns the list of \link applnk.html#Types types\endlink in the set. |
1003 | 1006 | ||
1004 | For applications, games and settings the type is \c Application; | 1007 | For applications, games and settings the type is \c Application; |
1005 | for documents the type is the document's MIME type. | 1008 | for documents the type is the document's MIME type. |
1006 | 1009 | ||
1007 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() | 1010 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() |
1008 | */ | 1011 | */ |
1009 | 1012 | ||
1010 | /*! | 1013 | /*! |
1011 | \fn const QList<AppLnk>& AppLnkSet::children() const | 1014 | \fn const QList<AppLnk>& AppLnkSet::children() const |
1012 | 1015 | ||
1013 | Returns the members of the set. | 1016 | Returns the members of the set. |
1014 | */ | 1017 | */ |
1015 | 1018 | ||
1016 | /*! | 1019 | /*! |
1017 | Constructs an empty AppLnkSet. | 1020 | Constructs an empty AppLnkSet. |
1018 | */ | 1021 | */ |
1019 | AppLnkSet::AppLnkSet() : | 1022 | AppLnkSet::AppLnkSet() : |
1020 | d(new AppLnkSetPrivate) | 1023 | d(new AppLnkSetPrivate) |
1021 | { | 1024 | { |
1022 | } | 1025 | } |
1023 | 1026 | ||
1024 | /*! | 1027 | /*! |
1025 | Constructs an AppLnkSet that contains AppLnk objects representing | 1028 | Constructs an AppLnkSet that contains AppLnk objects representing |
1026 | all the files in the given \a directory (and any subdirectories | 1029 | all the files in the given \a directory (and any subdirectories |
1027 | recursively). | 1030 | recursively). |
1028 | 1031 | ||
1029 | \omit | 1032 | \omit |
1030 | The directories may contain ".directory" files which override | 1033 | The directories may contain ".directory" files which override |
1031 | any AppLnk::type() values for AppLnk objects found in the directory. | 1034 | any AppLnk::type() values for AppLnk objects found in the directory. |
1032 | This allows simple localization of application types. | 1035 | This allows simple localization of application types. |
1033 | \endomit | 1036 | \endomit |
1034 | */ | 1037 | */ |
1035 | AppLnkSet::AppLnkSet( const QString &directory ) : | 1038 | AppLnkSet::AppLnkSet( const QString &directory ) : |
1036 | d(new AppLnkSetPrivate) | 1039 | d(new AppLnkSetPrivate) |
1037 | { | 1040 | { |
1038 | QDir dir( directory ); | 1041 | QDir dir( directory ); |
1039 | mFile = directory; | 1042 | mFile = directory; |
1040 | findChildren(directory,QString::null,QString::null); | 1043 | findChildren(directory,QString::null,QString::null); |
1041 | } | 1044 | } |
1042 | 1045 | ||
1043 | /*! | 1046 | /*! |
1044 | Detaches all AppLnk objects from the set. The set become empty and | 1047 | Detaches all AppLnk objects from the set. The set become empty and |
1045 | the caller becomes responsible for deleting the AppLnk objects. | 1048 | the caller becomes responsible for deleting the AppLnk objects. |
1046 | */ | 1049 | */ |
1047 | void AppLnkSet::detachChildren() | 1050 | void AppLnkSet::detachChildren() |
1048 | { | 1051 | { |
1049 | QListIterator<AppLnk> it( mApps ); | 1052 | QListIterator<AppLnk> it( mApps ); |
1050 | for ( ; it.current(); ) { | 1053 | for ( ; it.current(); ) { |
1051 | AppLnk* a = *it; | 1054 | AppLnk* a = *it; |
1052 | ++it; | 1055 | ++it; |
1053 | a->mId = 0; | 1056 | a->mId = 0; |
1054 | } | 1057 | } |
1055 | mApps.clear(); | 1058 | mApps.clear(); |
1056 | } | 1059 | } |
1057 | 1060 | ||
1058 | /*! | 1061 | /*! |
1059 | Destroys the set, deleting all the AppLnk objects it contains. | 1062 | Destroys the set, deleting all the AppLnk objects it contains. |
1060 | 1063 | ||
1061 | \sa detachChildren() | 1064 | \sa detachChildren() |
1062 | */ | 1065 | */ |
1063 | AppLnkSet::~AppLnkSet() | 1066 | AppLnkSet::~AppLnkSet() |
1064 | { | 1067 | { |
1065 | QListIterator<AppLnk> it( mApps ); | 1068 | QListIterator<AppLnk> it( mApps ); |
1066 | for ( ; it.current(); ) { | 1069 | for ( ; it.current(); ) { |
1067 | AppLnk* a = *it; | 1070 | AppLnk* a = *it; |
1068 | ++it; | 1071 | ++it; |
1069 | a->mId = 0; | 1072 | a->mId = 0; |
1070 | delete a; | 1073 | delete a; |
1071 | } | 1074 | } |
1072 | delete d; | 1075 | delete d; |
1073 | } | 1076 | } |
1074 | 1077 | ||
1075 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) | 1078 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) |
1076 | { | 1079 | { |
1077 | depth++; | 1080 | depth++; |
1078 | if ( depth > 10 ) | 1081 | if ( depth > 10 ) |
1079 | return; | 1082 | return; |
1080 | 1083 | ||
1081 | QDir dir( dr ); | 1084 | QDir dir( dr ); |
1082 | QString typNameLocal = typName; | 1085 | QString typNameLocal = typName; |
1083 | 1086 | ||
1084 | if ( dir.exists( ".directory" ) ) { | 1087 | if ( dir.exists( ".directory" ) ) { |
1085 | Config config( dr + "/.directory", Config::File ); | 1088 | Config config( dr + "/.directory", Config::File ); |
1086 | config.setGroup( "Desktop Entry" ); | 1089 | config.setGroup( "Desktop Entry" ); |
1087 | typNameLocal = config.readEntry( "Name", typNameLocal ); | 1090 | typNameLocal = config.readEntry( "Name", typNameLocal ); |
1088 | if ( !typ.isEmpty() ) { | 1091 | if ( !typ.isEmpty() ) { |