summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
Unidiff
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 44f3f58..a56da5d 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -327,97 +327,100 @@ const QArray<int>& AppLnk::categories() const
327 \sa AppLnkSet::find() 327 \sa AppLnkSet::find()
328*/ 328*/
329 329
330/*! 330/*!
331 \fn bool AppLnk::isValid() const 331 \fn bool AppLnk::isValid() const
332 332
333 Returns TRUE if this AppLnk is valid; otherwise returns FALSE. 333 Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
334*/ 334*/
335 335
336/*! 336/*!
337 Creates an invalid AppLnk. 337 Creates an invalid AppLnk.
338 338
339 \sa isValid() 339 \sa isValid()
340*/ 340*/
341AppLnk::AppLnk() 341AppLnk::AppLnk()
342{ 342{
343 mId = 0; 343 mId = 0;
344 d = new AppLnkPrivate(); 344 d = new AppLnkPrivate();
345} 345}
346 346
347/*! 347/*!
348 Loads \a file (e.g. \e app.desktop) as an AppLnk. 348 Loads \a file (e.g. \e app.desktop) as an AppLnk.
349 349
350 \sa writeLink() 350 \sa writeLink()
351*/ 351*/
352AppLnk::AppLnk( const QString &file ) 352AppLnk::AppLnk( const QString &file )
353{ 353{
354 QStringList sl; 354 QStringList sl;
355 d = new AppLnkPrivate(); 355 d = new AppLnkPrivate();
356 if ( !file.isNull() ) { 356 if ( !file.isNull() ) {
357 Config config( file, Config::File ); 357 Config config( file, Config::File );
358 358
359 if ( config.isValid() ) { 359 if ( config.isValid() ) {
360 config.setGroup( "Desktop Entry" ); 360 config.setGroup( "Desktop Entry" );
361 361
362 mName = config.readEntry( "Name", file ); 362 mName = config.readEntry( "Name", file );
363 mExec = config.readEntry( "Exec" ); 363 mExec = config.readEntry( "Exec" );
364 mType = config.readEntry( "Type", QString::null ); 364 mType = config.readEntry( "Type", QString::null );
365 mIconFile = config.readEntry( "Icon", QString::null ); 365 mIconFile = config.readEntry( "Icon", QString::null );
366 mRotation = config.readEntry( "Rotation", "" ); 366 mRotation = config.readEntry( "Rotation", "" );
367 mComment = config.readEntry( "Comment", QString::null ); 367 mComment = config.readEntry( "Comment", QString::null );
368 // MIME types are case-insensitive. 368 // MIME types are case-insensitive.
369 mMimeTypes = config.readListEntry( "MimeType", ';' ); 369 mMimeTypes = config.readListEntry( "MimeType", ';' );
370 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 370 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
371 *it = (*it).lower(); 371 *it = (*it).lower();
372 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 372 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
373 mLinkFile = file; 373 mLinkFile = file;
374 mFile = config.readEntry("File", QString::null); 374 mFile = config.readEntry("File", QString::null);
375 if ( mFile[0] != '/' ) { 375 if ( !mExec. isEmpty ( )) {
376 mFile = QString::null;
377 }
378 else if ( mFile[0] != '/' ) {
376 int slash = file.findRev('/'); 379 int slash = file.findRev('/');
377 if ( slash >= 0 ) { 380 if ( slash >= 0 ) {
378 mFile = file.left(slash) + '/' + mFile; 381 mFile = file.left(slash) + '/' + mFile;
379 } 382 }
380 } 383 }
381 d->mCatList = config.readListEntry("Categories", ';'); 384 d->mCatList = config.readListEntry("Categories", ';');
382 if ( d->mCatList[0].toInt() < -1 ) { 385 if ( d->mCatList[0].toInt() < -1 ) {
383 // numeric cats in file! convert to text 386 // numeric cats in file! convert to text
384 Categories cat( 0 ); 387 Categories cat( 0 );
385 cat.load( categoryFileName() ); 388 cat.load( categoryFileName() );
386 d->mCat.resize( d->mCatList.count() ); 389 d->mCat.resize( d->mCatList.count() );
387 int i; 390 int i;
388 QStringList::ConstIterator it; 391 QStringList::ConstIterator it;
389 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 392 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
390 ++it, i++ ) { 393 ++it, i++ ) {
391 bool number; 394 bool number;
392 int id = (*it).toInt( &number ); 395 int id = (*it).toInt( &number );
393 if ( !number ) { 396 if ( !number ) {
394 // convert from text 397 // convert from text
395 id = cat.id( "Document View", *it ); 398 id = cat.id( "Document View", *it );
396 if ( id == 0 ) 399 if ( id == 0 )
397 id = cat.addCategory( "Document View", *it ); 400 id = cat.addCategory( "Document View", *it );
398 } 401 }
399 d->mCat[i] = id; 402 d->mCat[i] = id;
400 } 403 }
401 d->updateCatListFromArray(); 404 d->updateCatListFromArray();
402 } 405 }
403 } 406 }
404 } 407 }
405 mId = 0; 408 mId = 0;
406} 409}
407 410
408AppLnk& AppLnk::operator=(const AppLnk &copy) 411AppLnk& AppLnk::operator=(const AppLnk &copy)
409{ 412{
410 if ( mId ) 413 if ( mId )
411 qWarning("Deleting AppLnk that is in an AppLnkSet"); 414 qWarning("Deleting AppLnk that is in an AppLnkSet");
412 if ( d ) 415 if ( d )
413 delete d; 416 delete d;
414 417
415 418
416 mName = copy.mName; 419 mName = copy.mName;
417 420
418 /* remove for Qtopia 3.0 -zecke */ 421 /* remove for Qtopia 3.0 -zecke */
419 mPixmap = copy.mPixmap; 422 mPixmap = copy.mPixmap;
420 mBigPixmap = copy.mBigPixmap; 423 mBigPixmap = copy.mBigPixmap;
421 424
422 mExec = copy.mExec; 425 mExec = copy.mExec;
423 mType = copy.mType; 426 mType = copy.mType;
@@ -475,105 +478,106 @@ const QPixmap& AppLnk::pixmap( int pos, int size ) const {
475*/ 478*/
476const QPixmap& AppLnk::pixmap() const 479const QPixmap& AppLnk::pixmap() const
477{ 480{
478 if ( d->mPixmaps[0].isNull() ) { 481 if ( d->mPixmaps[0].isNull() ) {
479 return pixmap(AppLnkPrivate::Normal, smallSize ); 482 return pixmap(AppLnkPrivate::Normal, smallSize );
480 } 483 }
481 return d->mPixmaps[0]; 484 return d->mPixmaps[0];
482} 485}
483 486
484/*! 487/*!
485 Returns a large pixmap associated with the application. 488 Returns a large pixmap associated with the application.
486 489
487 \sa pixmap() setIcon() 490 \sa pixmap() setIcon()
488*/ 491*/
489const QPixmap& AppLnk::bigPixmap() const 492const QPixmap& AppLnk::bigPixmap() const
490{ 493{
491 if ( d->mPixmaps[1].isNull() ) { 494 if ( d->mPixmaps[1].isNull() ) {
492 return pixmap( AppLnkPrivate::Big, bigSize ); 495 return pixmap( AppLnkPrivate::Big, bigSize );
493 } 496 }
494 return d->mPixmaps[1]; 497 return d->mPixmaps[1];
495} 498}
496 499
497/*! 500/*!
498 Returns the type of the AppLnk. For applications, games and 501 Returns the type of the AppLnk. For applications, games and
499 settings the type is \c Application; for documents the type is the 502 settings the type is \c Application; for documents the type is the
500 document's MIME type. 503 document's MIME type.
501*/ 504*/
502QString AppLnk::type() const 505QString AppLnk::type() const
503{ 506{
504 if ( mType.isNull() ) { 507 if ( mType.isNull() ) {
505 AppLnk* that = (AppLnk*)this; 508 AppLnk* that = (AppLnk*)this;
506 QString f = file(); 509 QString f = file();
507 if ( !f.isNull() ) { 510 if ( !f.isNull() ) {
508 MimeType mt(f); 511 MimeType mt(f);
509 that->mType = mt.id(); 512 that->mType = mt.id();
510 return that->mType; 513 return that->mType;
511 } 514 }
512 } 515 }
513 return mType; 516 return mType;
514} 517}
515 518
516/*! 519/*!
517 Returns the file associated with the AppLnk. 520 Returns the file associated with the AppLnk.
518 521
519 \sa exec() name() 522 \sa exec() name()
520*/ 523*/
521QString AppLnk::file() const 524QString AppLnk::file() const
522{ 525{
523 if ( mFile.isNull() ) { 526 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
524 AppLnk* that = (AppLnk*)this; 527 AppLnk* that = (AppLnk*)this;
525 QString ext = MimeType(mType).extension(); 528 QString ext = MimeType(mType).extension();
526 if ( !ext.isEmpty() ) 529 if ( !ext.isEmpty() )
527 ext = "." + ext; 530 ext = "." + ext;
528 if ( !mLinkFile.isEmpty() ) { 531 if ( !mLinkFile.isEmpty() ) {
529 that->mFile = 532 that->mFile =
530 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 533 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
531 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 534 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
535 qDebug("mFile now == %s", mFile.latin1());
532 } else if ( mType.contains('/') ) { 536 } else if ( mType.contains('/') ) {
533 that->mFile = 537 that->mFile =
534 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 538 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
535 /* 539 /*
536 * A file with the same name or a .desktop file already exists 540 * A file with the same name or a .desktop file already exists
537 */ 541 */
538 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { 542 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
539 int n=1; 543 int n=1;
540 QString nn; 544 QString nn;
541 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 545 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
542 || QFile::exists(nn+".desktop")) 546 || QFile::exists(nn+".desktop"))
543 n++; 547 n++;
544 that->mFile = nn; 548 that->mFile = nn;
545 } 549 }
546 that->mLinkFile = that->mFile+".desktop"; 550 that->mLinkFile = that->mFile+".desktop";
547 that->mFile += ext; 551 that->mFile += ext;
548 } 552 }
549 prepareDirectories(that->mFile); 553 prepareDirectories(that->mFile);
550 if ( !that->mFile.isEmpty() ) { 554 if ( !that->mFile.isEmpty() ) {
551 QFile f(that->mFile); 555 QFile f(that->mFile);
552 if ( !f.open(IO_WriteOnly) ) 556 if ( !f.open(IO_WriteOnly) )
553 that->mFile = QString::null; 557 that->mFile = QString::null;
554 return that->mFile; 558 return that->mFile;
555 } 559 }
556 } 560 }
557 return mFile; 561 return mFile;
558} 562}
559 563
560/*! 564/*!
561 Returns the desktop file corresponding to this AppLnk. 565 Returns the desktop file corresponding to this AppLnk.
562 566
563 \sa file() exec() name() 567 \sa file() exec() name()
564*/ 568*/
565QString AppLnk::linkFile() const 569QString AppLnk::linkFile() const
566{ 570{
567 if ( mLinkFile.isNull() ) { 571 if ( mLinkFile.isNull() ) {
568 AppLnk* that = (AppLnk*)this; 572 AppLnk* that = (AppLnk*)this;
569 if ( type().contains('/') ) { 573 if ( type().contains('/') ) {
570 StorageInfo storage; 574 StorageInfo storage;
571 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 575 const FileSystem *fs = storage.fileSystemOf( that->mFile );
572 /* tmpfs + and ramfs are available too but not removable 576 /* tmpfs + and ramfs are available too but not removable
573 * either we fix storage or add this 577 * either we fix storage or add this
574 */ 578 */
575 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { 579 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
576 that->mLinkFile = fs->path(); 580 that->mLinkFile = fs->path();
577 } else 581 } else
578 that->mLinkFile = getenv( "HOME" ); 582 that->mLinkFile = getenv( "HOME" );
579 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 583 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
@@ -652,96 +656,108 @@ void AppLnk::execute() const
652{ 656{
653 execute(QStringList()); 657 execute(QStringList());
654} 658}
655 659
656/*! 660/*!
657 Executes the application associated with this AppLnk, with 661 Executes the application associated with this AppLnk, with
658 \a args as arguments. 662 \a args as arguments.
659 663
660 \sa exec() 664 \sa exec()
661*/ 665*/
662void AppLnk::execute(const QStringList& args) const 666void AppLnk::execute(const QStringList& args) const
663{ 667{
664#ifdef Q_WS_QWS 668#ifdef Q_WS_QWS
665 if ( !mRotation.isEmpty() ) { 669 if ( !mRotation.isEmpty() ) {
666 // ######## this will only work in the server 670 // ######## this will only work in the server
667 int rot = QPEApplication::defaultRotation(); 671 int rot = QPEApplication::defaultRotation();
668 rot = (rot+mRotation.toInt())%360; 672 rot = (rot+mRotation.toInt())%360;
669 QCString old = getenv("QWS_DISPLAY"); 673 QCString old = getenv("QWS_DISPLAY");
670 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 674 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
671 invoke(args); 675 invoke(args);
672 setenv("QWS_DISPLAY", old.data(), 1); 676 setenv("QWS_DISPLAY", old.data(), 1);
673 } else 677 } else
674#endif 678#endif
675 invoke(args); 679 invoke(args);
676} 680}
677 681
678/*! 682/*!
679 Invokes the application associated with this AppLnk, with 683 Invokes the application associated with this AppLnk, with
680 \a args as arguments. Rotation is not taken into account by 684 \a args as arguments. Rotation is not taken into account by
681 this function, so you should not call it directly. 685 this function, so you should not call it directly.
682 686
683 \sa execute() 687 \sa execute()
684*/ 688*/
685void AppLnk::invoke(const QStringList& args) const 689void AppLnk::invoke(const QStringList& args) const
686{ 690{
687 Global::execute( exec(), args[0] ); 691 Global::execute( exec(), args[0] );
688} 692}
689 693
690/*! 694/*!
691 Sets the Exec property to \a exec. 695 Sets the Exec property to \a exec.
692 696
693 \sa exec() name() 697 \sa exec() name()
694*/ 698*/
695void AppLnk::setExec( const QString& exec ) 699void AppLnk::setExec( const QString& exec )
696{ 700{
697 mExec = exec; 701 mExec = exec;
698} 702}
699 703
704#if 0 // this was inlined for better BC
705/*!
706 Sets the Rotation property to \a rot.
707
708 \sa rotation()
709*/
710void AppLnk::setRotation ( const QString &rot )
711{
712 mRotation = rot;
713}
714#endif
715
700/*! 716/*!
701 Sets the Name property to \a docname. 717 Sets the Name property to \a docname.
702 718
703 \sa name() 719 \sa name()
704*/ 720*/
705void AppLnk::setName( const QString& docname ) 721void AppLnk::setName( const QString& docname )
706{ 722{
707 mName = docname; 723 mName = docname;
708} 724}
709 725
710/*! 726/*!
711 Sets the File property to \a filename. 727 Sets the File property to \a filename.
712 728
713 \sa file() name() 729 \sa file() name()
714*/ 730*/
715void AppLnk::setFile( const QString& filename ) 731void AppLnk::setFile( const QString& filename )
716{ 732{
717 mFile = filename; 733 mFile = filename;
718} 734}
719 735
720/*! 736/*!
721 Sets the LinkFile property to \a filename. 737 Sets the LinkFile property to \a filename.
722 738
723 \sa linkFile() 739 \sa linkFile()
724*/ 740*/
725void AppLnk::setLinkFile( const QString& filename ) 741void AppLnk::setLinkFile( const QString& filename )
726{ 742{
727 mLinkFile = filename; 743 mLinkFile = filename;
728} 744}
729 745
730/*! 746/*!
731 Sets the Comment property to \a comment. 747 Sets the Comment property to \a comment.
732 748
733 This text is displayed in the 'Details Dialog', for example if the 749 This text is displayed in the 'Details Dialog', for example if the
734 user uses the 'press-and-hold' gesture. 750 user uses the 'press-and-hold' gesture.
735 751
736 \sa comment() 752 \sa comment()
737*/ 753*/
738void AppLnk::setComment( const QString& comment ) 754void AppLnk::setComment( const QString& comment )
739{ 755{
740 mComment = comment; 756 mComment = comment;
741} 757}
742 758
743/*! 759/*!
744 Sets the Type property to \a type. 760 Sets the Type property to \a type.
745 761
746 For applications, games and settings the type should be \c 762 For applications, games and settings the type should be \c
747 Application; for documents the type should be the document's MIME 763 Application; for documents the type should be the document's MIME
@@ -790,96 +806,100 @@ void AppLnk::setCategories( const QArray<int>& c )
790} 806}
791 807
792/*! 808/*!
793 \fn QStringList AppLnk::mimeTypeIcons() const 809 \fn QStringList AppLnk::mimeTypeIcons() const
794 810
795 Returns the MimeTypeIcons property of the AppLnk. 811 Returns the MimeTypeIcons property of the AppLnk.
796*/ 812*/
797 813
798/*! 814/*!
799 Attempts to ensure that the link file for this AppLnk exists, 815 Attempts to ensure that the link file for this AppLnk exists,
800 including creating any required directories. Returns TRUE if 816 including creating any required directories. Returns TRUE if
801 successful; otherwise returns FALSE. 817 successful; otherwise returns FALSE.
802 818
803 You should not need to use this function. 819 You should not need to use this function.
804*/ 820*/
805bool AppLnk::ensureLinkExists() const 821bool AppLnk::ensureLinkExists() const
806{ 822{
807 QString lf = linkFile(); 823 QString lf = linkFile();
808 return prepareDirectories(lf); 824 return prepareDirectories(lf);
809} 825}
810 826
811/*! 827/*!
812 Commits the AppLnk to disk. Returns TRUE if the operation succeeded; 828 Commits the AppLnk to disk. Returns TRUE if the operation succeeded;
813 otherwise returns FALSE. 829 otherwise returns FALSE.
814 830
815 In addition, the "linkChanged(QString)" message is sent to the 831 In addition, the "linkChanged(QString)" message is sent to the
816 "QPE/System" \link qcop.html QCop\endlink channel. 832 "QPE/System" \link qcop.html QCop\endlink channel.
817*/ 833*/
818bool AppLnk::writeLink() const 834bool AppLnk::writeLink() const
819{ 835{
820 // Only re-writes settable parts 836 // Only re-writes settable parts
821 QString lf = linkFile(); 837 QString lf = linkFile();
822 if ( !ensureLinkExists() ) 838 if ( !ensureLinkExists() )
823 return FALSE; 839 return FALSE;
824 storeLink(); 840 storeLink();
825 return TRUE; 841 return TRUE;
826} 842}
827 843
828/*! 844/*!
829 \internal 845 \internal
830*/ 846*/
831void AppLnk::storeLink() const 847void AppLnk::storeLink() const
832{ 848{
833 Config config( mLinkFile, Config::File ); 849 Config config( mLinkFile, Config::File );
834 config.setGroup("Desktop Entry"); 850 config.setGroup("Desktop Entry");
835 config.writeEntry("Name",mName); 851 config.writeEntry("Name",mName);
836 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 852 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
837 config.writeEntry("Type",type()); 853 config.writeEntry("Type",type());
854 if(!rotation().isEmpty())
855 config.writeEntry("Rotation",rotation());
856 else
857 config.removeEntry("Rotation");
838 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 858 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
839 QString f = file(); 859 QString f = file();
840 int i = 0; 860 int i = 0;
841 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) 861 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
842 i++; 862 i++;
843 while ( i && f[i] != '/' ) 863 while ( i && f[i] != '/' )
844 i--; 864 i--;
845 // simple case where in the same directory 865 // simple case where in the same directory
846 if ( mLinkFile.find( '/', i + 1 ) < 0 ) 866 if ( mLinkFile.find( '/', i + 1 ) < 0 )
847 f = f.mid(i+1); 867 f = f.mid(i+1);
848 // ### could do relative ie ../../otherDocs/file.doc 868 // ### could do relative ie ../../otherDocs/file.doc
849 config.writeEntry("File",f); 869 config.writeEntry("File",f);
850 config.writeEntry( "Categories", d->mCatList, ';' ); 870 config.writeEntry( "Categories", d->mCatList, ';' );
851 871
852#ifndef QT_NO_COP 872#ifndef QT_NO_COP
853 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 873 QCopEnvelope e("QPE/System", "linkChanged(QString)");
854 e << mLinkFile; 874 e << mLinkFile;
855#endif 875#endif
856} 876}
857 877
858/*! 878/*!
859 Sets the property named \a key to \a value. 879 Sets the property named \a key to \a value.
860 880
861 \sa property() 881 \sa property()
862*/ 882*/
863void AppLnk::setProperty(const QString& key, const QString& value) 883void AppLnk::setProperty(const QString& key, const QString& value)
864{ 884{
865 if ( ensureLinkExists() ) { 885 if ( ensureLinkExists() ) {
866 Config cfg(linkFile(), Config::File); 886 Config cfg(linkFile(), Config::File);
867 cfg.writeEntry(key,value); 887 cfg.writeEntry(key,value);
868 } 888 }
869} 889}
870 890
871/*! 891/*!
872 Returns the property named \a key. 892 Returns the property named \a key.
873 893
874 \sa setProperty() 894 \sa setProperty()
875*/ 895*/
876QString AppLnk::property(const QString& key) const 896QString AppLnk::property(const QString& key) const
877{ 897{
878 QString lf = linkFile(); 898 QString lf = linkFile();
879 if ( !QFile::exists(lf) ) 899 if ( !QFile::exists(lf) )
880 return QString::null; 900 return QString::null;
881 Config cfg(lf, Config::File); 901 Config cfg(lf, Config::File);
882 return cfg.readEntry(key); 902 return cfg.readEntry(key);
883} 903}
884 904
885bool AppLnk::isPreloaded() const { 905bool AppLnk::isPreloaded() const {