-rw-r--r-- | library/applnk.cpp | 130 | ||||
-rw-r--r-- | library/resource.cpp | 13 |
2 files changed, 90 insertions, 53 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 1c1a227..80f2c62 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -600,898 +600,930 @@ QString AppLnk::linkFile() const | |||
600 | if ( QFile::exists(that->mLinkFile+".desktop") ) { | 600 | if ( QFile::exists(that->mLinkFile+".desktop") ) { |
601 | AppLnk lnk( that->mLinkFile + ".desktop" ); | 601 | AppLnk lnk( that->mLinkFile + ".desktop" ); |
602 | 602 | ||
603 | /* the linked is different */ | 603 | /* the linked is different */ |
604 | if(that->file() != lnk.file() ) { | 604 | if(that->file() != lnk.file() ) { |
605 | int n = 1; | 605 | int n = 1; |
606 | QString nn; | 606 | QString nn; |
607 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { | 607 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { |
608 | n++; | 608 | n++; |
609 | /* just to be sure */ | 609 | /* just to be sure */ |
610 | AppLnk lnk(nn ); | 610 | AppLnk lnk(nn ); |
611 | if (lnk.file() == that->file() ) | 611 | if (lnk.file() == that->file() ) |
612 | break; | 612 | break; |
613 | } | 613 | } |
614 | that->mLinkFile = nn; | 614 | that->mLinkFile = nn; |
615 | } | 615 | } |
616 | } | 616 | } |
617 | that->mLinkFile += ".desktop"; | 617 | that->mLinkFile += ".desktop"; |
618 | storeLink(); | 618 | storeLink(); |
619 | } | 619 | } |
620 | return that->mLinkFile; | 620 | return that->mLinkFile; |
621 | } | 621 | } |
622 | return mLinkFile; | 622 | return mLinkFile; |
623 | } | 623 | } |
624 | 624 | ||
625 | /*! | 625 | /*! |
626 | Copies \a copy. | 626 | Copies \a copy. |
627 | */ | 627 | */ |
628 | AppLnk::AppLnk( const AppLnk © ) | 628 | AppLnk::AppLnk( const AppLnk © ) |
629 | { | 629 | { |
630 | mName = copy.mName; | 630 | mName = copy.mName; |
631 | mPixmap = copy.mPixmap; | 631 | mPixmap = copy.mPixmap; |
632 | mBigPixmap = copy.mBigPixmap; | 632 | mBigPixmap = copy.mBigPixmap; |
633 | mExec = copy.mExec; | 633 | mExec = copy.mExec; |
634 | mType = copy.mType; | 634 | mType = copy.mType; |
635 | mRotation = copy.mRotation; | 635 | mRotation = copy.mRotation; |
636 | mComment = copy.mComment; | 636 | mComment = copy.mComment; |
637 | mFile = copy.mFile; | 637 | mFile = copy.mFile; |
638 | mLinkFile = copy.mLinkFile; | 638 | mLinkFile = copy.mLinkFile; |
639 | mIconFile = copy.mIconFile; | 639 | mIconFile = copy.mIconFile; |
640 | mMimeTypes = copy.mMimeTypes; | 640 | mMimeTypes = copy.mMimeTypes; |
641 | mMimeTypeIcons = copy.mMimeTypeIcons; | 641 | mMimeTypeIcons = copy.mMimeTypeIcons; |
642 | mId = 0; | 642 | mId = 0; |
643 | d = new AppLnkPrivate(); | 643 | d = new AppLnkPrivate(); |
644 | d->mCat = copy.d->mCat; | 644 | d->mCat = copy.d->mCat; |
645 | d->mCatList = copy.d->mCatList; | 645 | d->mCatList = copy.d->mCatList; |
646 | d->mPixmaps = copy.d->mPixmaps; | 646 | d->mPixmaps = copy.d->mPixmaps; |
647 | } | 647 | } |
648 | 648 | ||
649 | /*! | 649 | /*! |
650 | Destroys the AppLnk. Note that if the AppLnk is currently a member | 650 | Destroys the AppLnk. Note that if the AppLnk is currently a member |
651 | of an AppLnkSet, this will produce a run-time warning. | 651 | of an AppLnkSet, this will produce a run-time warning. |
652 | 652 | ||
653 | \sa AppLnkSet::add() AppLnkSet::remove() | 653 | \sa AppLnkSet::add() AppLnkSet::remove() |
654 | */ | 654 | */ |
655 | AppLnk::~AppLnk() | 655 | AppLnk::~AppLnk() |
656 | { | 656 | { |
657 | if ( mId ) | 657 | if ( mId ) |
658 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 658 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
659 | if ( d ) | 659 | if ( d ) |
660 | delete d; | 660 | delete d; |
661 | } | 661 | } |
662 | 662 | ||
663 | /*! | 663 | /*! |
664 | \overload | 664 | \overload |
665 | Executes the application associated with this AppLnk. | 665 | Executes the application associated with this AppLnk. |
666 | 666 | ||
667 | \sa exec() | 667 | \sa exec() |
668 | */ | 668 | */ |
669 | void AppLnk::execute() const | 669 | void AppLnk::execute() const |
670 | { | 670 | { |
671 | execute( QStringList::split( ' ', property( "Arguments" ) ) ); | 671 | execute( QStringList::split( ' ', property( "Arguments" ) ) ); |
672 | } | 672 | } |
673 | 673 | ||
674 | /*! | 674 | /*! |
675 | Executes the application associated with this AppLnk, with | 675 | Executes the application associated with this AppLnk, with |
676 | \a args as arguments. | 676 | \a args as arguments. |
677 | 677 | ||
678 | \sa exec() | 678 | \sa exec() |
679 | */ | 679 | */ |
680 | void AppLnk::execute(const QStringList& args) const | 680 | void AppLnk::execute(const QStringList& args) const |
681 | { | 681 | { |
682 | #ifdef Q_WS_QWS | 682 | #ifdef Q_WS_QWS |
683 | if ( !mRotation.isEmpty() ) { | 683 | if ( !mRotation.isEmpty() ) { |
684 | // ######## this will only work in the server | 684 | // ######## this will only work in the server |
685 | int rot = QPEApplication::defaultRotation(); | 685 | int rot = QPEApplication::defaultRotation(); |
686 | rot = (rot+mRotation.toInt())%360; | 686 | rot = (rot+mRotation.toInt())%360; |
687 | QCString old = getenv("QWS_DISPLAY"); | 687 | QCString old = getenv("QWS_DISPLAY"); |
688 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 688 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
689 | invoke(args); | 689 | invoke(args); |
690 | setenv("QWS_DISPLAY", old.data(), 1); | 690 | setenv("QWS_DISPLAY", old.data(), 1); |
691 | } else | 691 | } else |
692 | #endif | 692 | #endif |
693 | invoke(args); | 693 | invoke(args); |
694 | } | 694 | } |
695 | 695 | ||
696 | /*! | 696 | /*! |
697 | Invokes the application associated with this AppLnk, with | 697 | Invokes the application associated with this AppLnk, with |
698 | \a args as arguments. Rotation is not taken into account by | 698 | \a args as arguments. Rotation is not taken into account by |
699 | this function, so you should not call it directly. | 699 | this function, so you should not call it directly. |
700 | 700 | ||
701 | \sa execute() | 701 | \sa execute() |
702 | */ | 702 | */ |
703 | void AppLnk::invoke(const QStringList& args) const | 703 | void AppLnk::invoke(const QStringList& args) const |
704 | { | 704 | { |
705 | if ( property( "Arguments" ).isEmpty() ) | 705 | if ( property( "Arguments" ).isEmpty() ) |
706 | Global::execute( exec(), args[0] ); | 706 | Global::execute( exec(), args[0] ); |
707 | else | 707 | else |
708 | Global::execute( exec(), args.join( " " ) ); | 708 | Global::execute( exec(), args.join( " " ) ); |
709 | } | 709 | } |
710 | 710 | ||
711 | /*! | 711 | /*! |
712 | Sets the Exec property to \a exec. | 712 | Sets the Exec property to \a exec. |
713 | 713 | ||
714 | \sa exec() name() | 714 | \sa exec() name() |
715 | */ | 715 | */ |
716 | void AppLnk::setExec( const QString& exec ) | 716 | void AppLnk::setExec( const QString& exec ) |
717 | { | 717 | { |
718 | mExec = exec; | 718 | mExec = exec; |
719 | } | 719 | } |
720 | 720 | ||
721 | #if 0 // this was inlined for better BC | 721 | #if 0 // this was inlined for better BC |
722 | /*! | 722 | /*! |
723 | Sets the Rotation property to \a rot. | 723 | Sets the Rotation property to \a rot. |
724 | 724 | ||
725 | \sa rotation() | 725 | \sa rotation() |
726 | */ | 726 | */ |
727 | void AppLnk::setRotation ( const QString &rot ) | 727 | void AppLnk::setRotation ( const QString &rot ) |
728 | { | 728 | { |
729 | mRotation = rot; | 729 | mRotation = rot; |
730 | } | 730 | } |
731 | #endif | 731 | #endif |
732 | 732 | ||
733 | /*! | 733 | /*! |
734 | Sets the Name property to \a docname. | 734 | Sets the Name property to \a docname. |
735 | 735 | ||
736 | \sa name() | 736 | \sa name() |
737 | */ | 737 | */ |
738 | void AppLnk::setName( const QString& docname ) | 738 | void AppLnk::setName( const QString& docname ) |
739 | { | 739 | { |
740 | mName = docname; | 740 | mName = docname; |
741 | } | 741 | } |
742 | 742 | ||
743 | /*! | 743 | /*! |
744 | Sets the File property to \a filename. | 744 | Sets the File property to \a filename. |
745 | 745 | ||
746 | \sa file() name() | 746 | \sa file() name() |
747 | */ | 747 | */ |
748 | void AppLnk::setFile( const QString& filename ) | 748 | void AppLnk::setFile( const QString& filename ) |
749 | { | 749 | { |
750 | mFile = filename; | 750 | mFile = filename; |
751 | } | 751 | } |
752 | 752 | ||
753 | /*! | 753 | /*! |
754 | Sets the LinkFile property to \a filename. | 754 | Sets the LinkFile property to \a filename. |
755 | 755 | ||
756 | \sa linkFile() | 756 | \sa linkFile() |
757 | */ | 757 | */ |
758 | void AppLnk::setLinkFile( const QString& filename ) | 758 | void AppLnk::setLinkFile( const QString& filename ) |
759 | { | 759 | { |
760 | mLinkFile = filename; | 760 | mLinkFile = filename; |
761 | } | 761 | } |
762 | 762 | ||
763 | /*! | 763 | /*! |
764 | Sets the Comment property to \a comment. | 764 | Sets the Comment property to \a comment. |
765 | 765 | ||
766 | This text is displayed in the 'Details Dialog', for example if the | 766 | This text is displayed in the 'Details Dialog', for example if the |
767 | user uses the 'press-and-hold' gesture. | 767 | user uses the 'press-and-hold' gesture. |
768 | 768 | ||
769 | \sa comment() | 769 | \sa comment() |
770 | */ | 770 | */ |
771 | void AppLnk::setComment( const QString& comment ) | 771 | void AppLnk::setComment( const QString& comment ) |
772 | { | 772 | { |
773 | mComment = comment; | 773 | mComment = comment; |
774 | } | 774 | } |
775 | 775 | ||
776 | /*! | 776 | /*! |
777 | Sets the Type property to \a type. | 777 | Sets the Type property to \a type. |
778 | 778 | ||
779 | For applications, games and settings the type should be \c | 779 | For applications, games and settings the type should be \c |
780 | Application; for documents the type should be the document's MIME | 780 | Application; for documents the type should be the document's MIME |
781 | type. | 781 | type. |
782 | 782 | ||
783 | \sa type() | 783 | \sa type() |
784 | */ | 784 | */ |
785 | void AppLnk::setType( const QString& type ) | 785 | void AppLnk::setType( const QString& type ) |
786 | { | 786 | { |
787 | mType = type; | 787 | mType = type; |
788 | } | 788 | } |
789 | 789 | ||
790 | /*! | 790 | /*! |
791 | \fn QString AppLnk::icon() const | 791 | \fn QString AppLnk::icon() const |
792 | 792 | ||
793 | Returns the Icon property. | 793 | Returns the Icon property. |
794 | 794 | ||
795 | \sa setIcon() | 795 | \sa setIcon() |
796 | */ | 796 | */ |
797 | 797 | ||
798 | /*! | 798 | /*! |
799 | Sets the Icon property to \a iconname. This is the filename from | 799 | Sets the Icon property to \a iconname. This is the filename from |
800 | which the pixmap() and bigPixmap() are obtained. | 800 | which the pixmap() and bigPixmap() are obtained. |
801 | 801 | ||
802 | \sa icon() setSmallIconSize() setBigIconSize() | 802 | \sa icon() setSmallIconSize() setBigIconSize() |
803 | */ | 803 | */ |
804 | void AppLnk::setIcon( const QString& iconname ) | 804 | void AppLnk::setIcon( const QString& iconname ) |
805 | { | 805 | { |
806 | mIconFile = iconname; | 806 | mIconFile = iconname; |
807 | QImage unscaledIcon = Resource::loadImage( mIconFile ); | 807 | QImage unscaledIcon = Resource::loadImage( mIconFile ); |
808 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 808 | d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
809 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 809 | d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
810 | } | 810 | } |
811 | 811 | ||
812 | /*! | 812 | /*! |
813 | Sets the Categories property to \a c. | 813 | Sets the Categories property to \a c. |
814 | 814 | ||
815 | See the CategoryWidget for more details. | 815 | See the CategoryWidget for more details. |
816 | 816 | ||
817 | \sa categories() | 817 | \sa categories() |
818 | */ | 818 | */ |
819 | void AppLnk::setCategories( const QArray<int>& c ) | 819 | void AppLnk::setCategories( const QArray<int>& c ) |
820 | { | 820 | { |
821 | d->mCat = c; | 821 | d->mCat = c; |
822 | d->updateCatListFromArray(); | 822 | d->updateCatListFromArray(); |
823 | } | 823 | } |
824 | 824 | ||
825 | /*! | 825 | /*! |
826 | \fn QStringList AppLnk::mimeTypeIcons() const | 826 | \fn QStringList AppLnk::mimeTypeIcons() const |
827 | 827 | ||
828 | Returns the MimeTypeIcons property of the AppLnk. | 828 | Returns the MimeTypeIcons property of the AppLnk. |
829 | */ | 829 | */ |
830 | 830 | ||
831 | /*! | 831 | /*! |
832 | Attempts to ensure that the link file for this AppLnk exists, | 832 | Attempts to ensure that the link file for this AppLnk exists, |
833 | including creating any required directories. Returns TRUE if | 833 | including creating any required directories. Returns TRUE if |
834 | successful; otherwise returns FALSE. | 834 | successful; otherwise returns FALSE. |
835 | 835 | ||
836 | You should not need to use this function. | 836 | You should not need to use this function. |
837 | */ | 837 | */ |
838 | bool AppLnk::ensureLinkExists() const | 838 | bool AppLnk::ensureLinkExists() const |
839 | { | 839 | { |
840 | QString lf = linkFile(); | 840 | QString lf = linkFile(); |
841 | return prepareDirectories(lf); | 841 | return prepareDirectories(lf); |
842 | } | 842 | } |
843 | 843 | ||
844 | /*! | 844 | /*! |
845 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; | 845 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; |
846 | otherwise returns FALSE. | 846 | otherwise returns FALSE. |
847 | 847 | ||
848 | In addition, the "linkChanged(QString)" message is sent to the | 848 | In addition, the "linkChanged(QString)" message is sent to the |
849 | "QPE/System" \link qcop.html QCop\endlink channel. | 849 | "QPE/System" \link qcop.html QCop\endlink channel. |
850 | */ | 850 | */ |
851 | bool AppLnk::writeLink() const | 851 | bool AppLnk::writeLink() const |
852 | { | 852 | { |
853 | // Only re-writes settable parts | 853 | // Only re-writes settable parts |
854 | QString lf = linkFile(); | 854 | QString lf = linkFile(); |
855 | if ( !ensureLinkExists() ) | 855 | if ( !ensureLinkExists() ) |
856 | return FALSE; | 856 | return FALSE; |
857 | storeLink(); | 857 | storeLink(); |
858 | return TRUE; | 858 | return TRUE; |
859 | } | 859 | } |
860 | 860 | ||
861 | /*! | 861 | /*! |
862 | \internal | 862 | \internal |
863 | */ | 863 | */ |
864 | void AppLnk::storeLink() const | 864 | void AppLnk::storeLink() const |
865 | { | 865 | { |
866 | Config config( mLinkFile, Config::File ); | 866 | Config config( mLinkFile, Config::File ); |
867 | config.setGroup("Desktop Entry"); | 867 | config.setGroup("Desktop Entry"); |
868 | config.writeEntry("Name",mName); | 868 | config.writeEntry("Name",mName); |
869 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); | 869 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); |
870 | config.writeEntry("Type",type()); | 870 | config.writeEntry("Type",type()); |
871 | if(!rotation().isEmpty()) | 871 | if(!rotation().isEmpty()) |
872 | config.writeEntry("Rotation",rotation()); | 872 | config.writeEntry("Rotation",rotation()); |
873 | else | 873 | else |
874 | config.removeEntry("Rotation"); | 874 | config.removeEntry("Rotation"); |
875 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); | 875 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); |
876 | QString f = file(); | 876 | QString f = file(); |
877 | int i = 0; | 877 | int i = 0; |
878 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) | 878 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) |
879 | i++; | 879 | i++; |
880 | while ( i && f[i] != '/' ) | 880 | while ( i && f[i] != '/' ) |
881 | i--; | 881 | i--; |
882 | // simple case where in the same directory | 882 | // simple case where in the same directory |
883 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) | 883 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) |
884 | f = f.mid(i+1); | 884 | f = f.mid(i+1); |
885 | // ### could do relative ie ../../otherDocs/file.doc | 885 | // ### could do relative ie ../../otherDocs/file.doc |
886 | config.writeEntry("File",f); | 886 | config.writeEntry("File",f); |
887 | config.writeEntry( "Categories", d->mCatList, ';' ); | 887 | config.writeEntry( "Categories", d->mCatList, ';' ); |
888 | 888 | ||
889 | #ifndef QT_NO_COP | 889 | #ifndef QT_NO_COP |
890 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 890 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
891 | e << mLinkFile; | 891 | e << mLinkFile; |
892 | #endif | 892 | #endif |
893 | } | 893 | } |
894 | 894 | ||
895 | /*! | 895 | /*! |
896 | Sets the property named \a key to \a value. | 896 | Sets the property named \a key to \a value. |
897 | 897 | ||
898 | \sa property() | 898 | \sa property() |
899 | */ | 899 | */ |
900 | void AppLnk::setProperty(const QString& key, const QString& value) | 900 | void AppLnk::setProperty(const QString& key, const QString& value) |
901 | { | 901 | { |
902 | if ( ensureLinkExists() ) { | 902 | if ( ensureLinkExists() ) { |
903 | Config cfg(linkFile(), Config::File); | 903 | Config cfg(linkFile(), Config::File); |
904 | cfg.writeEntry(key,value); | 904 | cfg.writeEntry(key,value); |
905 | } | 905 | } |
906 | } | 906 | } |
907 | 907 | ||
908 | /*! | 908 | /*! |
909 | Returns the property named \a key. | 909 | Returns the property named \a key. |
910 | 910 | ||
911 | \sa setProperty() | 911 | \sa setProperty() |
912 | */ | 912 | */ |
913 | QString AppLnk::property(const QString& key) const | 913 | QString AppLnk::property(const QString& key) const |
914 | { | 914 | { |
915 | QString lf = linkFile(); | 915 | QString lf = linkFile(); |
916 | if ( !QFile::exists(lf) ) | 916 | if ( !QFile::exists(lf) ) |
917 | return QString::null; | 917 | return QString::null; |
918 | Config cfg(lf, Config::File); | 918 | Config cfg(lf, Config::File); |
919 | return cfg.readEntry(key); | 919 | return cfg.readEntry(key); |
920 | } | 920 | } |
921 | 921 | ||
922 | bool AppLnk::isPreloaded() const { | 922 | bool AppLnk::isPreloaded() const { |
923 | // Preload information is stored in the Launcher config in v1.5. | 923 | // Preload information is stored in the Launcher config in v1.5. |
924 | Config cfg("Launcher"); | 924 | Config cfg("Launcher"); |
925 | cfg.setGroup("Preload"); | 925 | cfg.setGroup("Preload"); |
926 | QStringList apps = cfg.readListEntry("Apps",','); | 926 | QStringList apps = cfg.readListEntry("Apps",','); |
927 | if (apps.contains(exec())) | 927 | if (apps.contains(exec())) |
928 | return true; | 928 | return true; |
929 | return false; | 929 | return false; |
930 | } | 930 | } |
931 | 931 | ||
932 | void AppLnk::setPreloaded(bool yesNo) { | 932 | void AppLnk::setPreloaded(bool yesNo) { |
933 | // Preload information is stored in the Launcher config in v1.5. | 933 | // Preload information is stored in the Launcher config in v1.5. |
934 | Config cfg("Launcher"); | 934 | Config cfg("Launcher"); |
935 | cfg.setGroup("Preload"); | 935 | cfg.setGroup("Preload"); |
936 | QStringList apps = cfg.readListEntry("Apps", ','); | 936 | QStringList apps = cfg.readListEntry("Apps", ','); |
937 | if (apps.contains(exec()) && !yesNo) | 937 | if (apps.contains(exec()) && !yesNo) |
938 | apps.remove(exec()); | 938 | apps.remove(exec()); |
939 | else if (yesNo && !apps.contains(exec())) | 939 | else if (yesNo && !apps.contains(exec())) |
940 | apps.append(exec()); | 940 | apps.append(exec()); |
941 | cfg.writeEntry("Apps", apps, ','); | 941 | cfg.writeEntry("Apps", apps, ','); |
942 | } | 942 | } |
943 | 943 | ||
944 | 944 | ||
945 | /*! | 945 | /*! |
946 | Deletes both the linkFile() and the file() associated with this AppLnk. | 946 | Deletes both the linkFile() and the file() associated with this AppLnk. |
947 | 947 | ||
948 | \sa removeLinkFile() | 948 | \sa removeLinkFile() |
949 | */ | 949 | */ |
950 | void AppLnk::removeFiles() | 950 | void AppLnk::removeFiles() |
951 | { | 951 | { |
952 | bool valid = isValid(); | 952 | bool valid = isValid(); |
953 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { | 953 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { |
954 | if ( QFile::remove(file()) ) { | 954 | if ( QFile::remove(file()) ) { |
955 | #ifndef QT_NO_COP | 955 | #ifndef QT_NO_COP |
956 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 956 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
957 | if ( linkFileKnown() ) | 957 | if ( linkFileKnown() ) |
958 | e << linkFile(); | 958 | e << linkFile(); |
959 | else | 959 | else |
960 | e << file(); | 960 | e << file(); |
961 | #endif | 961 | #endif |
962 | } else if ( valid ) { | 962 | } else if ( valid ) { |
963 | // restore link | 963 | // restore link |
964 | writeLink(); | 964 | writeLink(); |
965 | } | 965 | } |
966 | } | 966 | } |
967 | } | 967 | } |
968 | 968 | ||
969 | /*! | 969 | /*! |
970 | Deletes the linkFile(), leaving any file() untouched. | 970 | Deletes the linkFile(), leaving any file() untouched. |
971 | 971 | ||
972 | \sa removeFiles() | 972 | \sa removeFiles() |
973 | */ | 973 | */ |
974 | void AppLnk::removeLinkFile() | 974 | void AppLnk::removeLinkFile() |
975 | { | 975 | { |
976 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { | 976 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { |
977 | #ifndef QT_NO_COP | 977 | #ifndef QT_NO_COP |
978 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 978 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
979 | e << linkFile(); | 979 | e << linkFile(); |
980 | #endif | 980 | #endif |
981 | } | 981 | } |
982 | } | 982 | } |
983 | 983 | ||
984 | class AppLnkImagePrivate { | ||
985 | public : | ||
986 | AppLnkImagePrivate( const QString & ImageName ) { | ||
987 | IconName = ImageName; | ||
988 | Small = 0; | ||
989 | Big = 0; | ||
990 | } | ||
991 | ~AppLnkImagePrivate( ) { | ||
992 | if ( Small ) delete Small; | ||
993 | if ( Big ) delete Big; | ||
994 | } | ||
995 | |||
996 | inline QPixmap * small( void ) { | ||
997 | if( ! Small ) { | ||
998 | QImage unscaledIcon = Resource::loadImage( IconName ); | ||
999 | // works as long as smallSize remains static | ||
1000 | Small = new QPixmap(); | ||
1001 | Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | ||
1002 | } | ||
1003 | return Small; | ||
1004 | } | ||
1005 | |||
1006 | inline QPixmap * big( void ) { | ||
1007 | if( ! Big ) { | ||
1008 | QImage unscaledIcon = Resource::loadImage( IconName ); | ||
1009 | // works as long as bigSize remains static | ||
1010 | Big = new QPixmap(); | ||
1011 | Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | ||
1012 | } | ||
1013 | return Big; | ||
1014 | } | ||
1015 | |||
1016 | QString IconName; | ||
1017 | QPixmap * Small; | ||
1018 | QPixmap * Big; | ||
1019 | }; | ||
1020 | |||
984 | class AppLnkSetPrivate { | 1021 | class AppLnkSetPrivate { |
985 | public: | 1022 | public: |
986 | AppLnkSetPrivate() | 1023 | AppLnkSetPrivate() |
987 | { | 1024 | { |
988 | typPix.setAutoDelete(TRUE); | 1025 | typPix.setAutoDelete(TRUE); |
989 | typPixBig.setAutoDelete(TRUE); | 1026 | typName.setAutoDelete(TRUE); |
990 | typName.setAutoDelete(TRUE); | ||
991 | } | 1027 | } |
992 | 1028 | ||
993 | QDict<QPixmap> typPix; | 1029 | QDict<AppLnkImagePrivate> typPix; |
994 | QDict<QPixmap> typPixBig; | ||
995 | QDict<QString> typName; | 1030 | QDict<QString> typName; |
996 | }; | 1031 | }; |
997 | 1032 | ||
998 | /*! | 1033 | /*! |
999 | \class AppLnkSet applnk.h | 1034 | \class AppLnkSet applnk.h |
1000 | \brief The AppLnkSet class is a set of AppLnk objects. | 1035 | \brief The AppLnkSet class is a set of AppLnk objects. |
1001 | */ | 1036 | */ |
1002 | 1037 | ||
1003 | /*! | 1038 | /*! |
1004 | \fn QStringList AppLnkSet::types() const | 1039 | \fn QStringList AppLnkSet::types() const |
1005 | 1040 | ||
1006 | Returns the list of \link applnk.html#Types types\endlink in the set. | 1041 | Returns the list of \link applnk.html#Types types\endlink in the set. |
1007 | 1042 | ||
1008 | For applications, games and settings the type is \c Application; | 1043 | For applications, games and settings the type is \c Application; |
1009 | for documents the type is the document's MIME type. | 1044 | for documents the type is the document's MIME type. |
1010 | 1045 | ||
1011 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() | 1046 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() |
1012 | */ | 1047 | */ |
1013 | 1048 | ||
1014 | /*! | 1049 | /*! |
1015 | \fn const QList<AppLnk>& AppLnkSet::children() const | 1050 | \fn const QList<AppLnk>& AppLnkSet::children() const |
1016 | 1051 | ||
1017 | Returns the members of the set. | 1052 | Returns the members of the set. |
1018 | */ | 1053 | */ |
1019 | 1054 | ||
1020 | /*! | 1055 | /*! |
1021 | Constructs an empty AppLnkSet. | 1056 | Constructs an empty AppLnkSet. |
1022 | */ | 1057 | */ |
1023 | AppLnkSet::AppLnkSet() : | 1058 | AppLnkSet::AppLnkSet() : |
1024 | d(new AppLnkSetPrivate) | 1059 | d(new AppLnkSetPrivate) |
1025 | { | 1060 | { |
1026 | } | 1061 | } |
1027 | 1062 | ||
1028 | /*! | 1063 | /*! |
1029 | Constructs an AppLnkSet that contains AppLnk objects representing | 1064 | Constructs an AppLnkSet that contains AppLnk objects representing |
1030 | all the files in the given \a directory (and any subdirectories | 1065 | all the files in the given \a directory (and any subdirectories |
1031 | recursively). | 1066 | recursively). |
1032 | 1067 | ||
1033 | \omit | 1068 | \omit |
1034 | The directories may contain ".directory" files which override | 1069 | The directories may contain ".directory" files which override |
1035 | any AppLnk::type() values for AppLnk objects found in the directory. | 1070 | any AppLnk::type() values for AppLnk objects found in the directory. |
1036 | This allows simple localization of application types. | 1071 | This allows simple localization of application types. |
1037 | \endomit | 1072 | \endomit |
1038 | */ | 1073 | */ |
1039 | AppLnkSet::AppLnkSet( const QString &directory ) : | 1074 | AppLnkSet::AppLnkSet( const QString &directory ) : |
1040 | d(new AppLnkSetPrivate) | 1075 | d(new AppLnkSetPrivate) |
1041 | { | 1076 | { |
1042 | QDir dir( directory ); | 1077 | QDir dir( directory ); |
1043 | mFile = directory; | 1078 | mFile = directory; |
1044 | findChildren(directory,QString::null,QString::null); | 1079 | findChildren(directory,QString::null,QString::null); |
1045 | } | 1080 | } |
1046 | 1081 | ||
1047 | /*! | 1082 | /*! |
1048 | Detaches all AppLnk objects from the set. The set become empty and | 1083 | Detaches all AppLnk objects from the set. The set become empty and |
1049 | the caller becomes responsible for deleting the AppLnk objects. | 1084 | the caller becomes responsible for deleting the AppLnk objects. |
1050 | */ | 1085 | */ |
1051 | void AppLnkSet::detachChildren() | 1086 | void AppLnkSet::detachChildren() |
1052 | { | 1087 | { |
1053 | QListIterator<AppLnk> it( mApps ); | 1088 | QListIterator<AppLnk> it( mApps ); |
1054 | for ( ; it.current(); ) { | 1089 | for ( ; it.current(); ) { |
1055 | AppLnk* a = *it; | 1090 | AppLnk* a = *it; |
1056 | ++it; | 1091 | ++it; |
1057 | a->mId = 0; | 1092 | a->mId = 0; |
1058 | } | 1093 | } |
1059 | mApps.clear(); | 1094 | mApps.clear(); |
1060 | } | 1095 | } |
1061 | 1096 | ||
1062 | /*! | 1097 | /*! |
1063 | Destroys the set, deleting all the AppLnk objects it contains. | 1098 | Destroys the set, deleting all the AppLnk objects it contains. |
1064 | 1099 | ||
1065 | \sa detachChildren() | 1100 | \sa detachChildren() |
1066 | */ | 1101 | */ |
1067 | AppLnkSet::~AppLnkSet() | 1102 | AppLnkSet::~AppLnkSet() |
1068 | { | 1103 | { |
1069 | QListIterator<AppLnk> it( mApps ); | 1104 | QListIterator<AppLnk> it( mApps ); |
1070 | for ( ; it.current(); ) { | 1105 | for ( ; it.current(); ) { |
1071 | AppLnk* a = *it; | 1106 | AppLnk* a = *it; |
1072 | ++it; | 1107 | ++it; |
1073 | a->mId = 0; | 1108 | a->mId = 0; |
1074 | delete a; | 1109 | delete a; |
1075 | } | 1110 | } |
1076 | delete d; | 1111 | delete d; |
1077 | } | 1112 | } |
1078 | 1113 | ||
1079 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) | 1114 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) |
1080 | { | 1115 | { |
1081 | depth++; | 1116 | depth++; |
1082 | if ( depth > 10 ) | 1117 | if ( depth > 10 ) |
1083 | return; | 1118 | return; |
1084 | 1119 | ||
1085 | QDir dir( dr ); | 1120 | QDir dir( dr ); |
1086 | QString typNameLocal = typName; | 1121 | QString typNameLocal = typName; |
1087 | 1122 | ||
1088 | if ( dir.exists( ".directory" ) ) { | 1123 | if ( dir.exists( ".directory" ) ) { |
1089 | Config config( dr + "/.directory", Config::File ); | 1124 | Config config( dr + "/.directory", Config::File ); |
1090 | config.setGroup( "Desktop Entry" ); | 1125 | config.setGroup( "Desktop Entry" ); |
1091 | typNameLocal = config.readEntry( "Name", typNameLocal ); | 1126 | typNameLocal = config.readEntry( "Name", typNameLocal ); |
1092 | if ( !typ.isEmpty() ) { | 1127 | if ( !typ.isEmpty() ) { |
1093 | QString iconFile = config.readEntry( "Icon", "AppsIcon" ); | 1128 | d->typPix.insert( typ, |
1094 | QImage unscaledIcon = Resource::loadImage( iconFile ); | 1129 | new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) ) |
1095 | QPixmap pm, bpm; | 1130 | ); |
1096 | pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 1131 | d->typName.insert(typ, new QString(typNameLocal)); |
1097 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 1132 | |
1098 | d->typPix.insert(typ, new QPixmap(pm)); | 1133 | } |
1099 | d->typPixBig.insert(typ, new QPixmap(bpm)); | ||
1100 | d->typName.insert(typ, new QString(typNameLocal)); | ||
1101 | } | ||
1102 | } | 1134 | } |
1103 | 1135 | ||
1104 | const QFileInfoList *list = dir.entryInfoList(); | 1136 | const QFileInfoList *list = dir.entryInfoList(); |
1105 | if ( list ) { | 1137 | if ( list ) { |
1106 | QFileInfo* fi; | 1138 | QFileInfo* fi; |
1107 | bool cadded=FALSE; | 1139 | bool cadded=FALSE; |
1108 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1140 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1109 | QString bn = fi->fileName(); | 1141 | QString bn = fi->fileName(); |
1110 | // qDebug("findChildren "+bn); | 1142 | // qDebug("findChildren "+bn); |
1111 | if ( bn[0] != '.' && bn != "CVS" ) { | 1143 | if ( bn[0] != '.' && bn != "CVS" ) { |
1112 | if ( fi->isDir() ) { | 1144 | if ( fi->isDir() ) { |
1113 | QString c = typ.isNull() ? bn : typ+"/"+bn; | 1145 | QString c = typ.isNull() ? bn : typ+"/"+bn; |
1114 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; | 1146 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; |
1115 | findChildren(fi->filePath(), c, d, depth ); | 1147 | findChildren(fi->filePath(), c, d, depth ); |
1116 | } else { | 1148 | } else { |
1117 | if ( fi->extension(FALSE) == "desktop" ) { | 1149 | if ( fi->extension(FALSE) == "desktop" ) { |
1118 | AppLnk* app = new AppLnk( fi->filePath() ); | 1150 | AppLnk* app = new AppLnk( fi->filePath() ); |
1119 | #ifdef QT_NO_QWS_MULTIPROCESS | 1151 | #ifdef QT_NO_QWS_MULTIPROCESS |
1120 | if ( !Global::isBuiltinCommand( app->exec() ) ) | 1152 | if ( !Global::isBuiltinCommand( app->exec() ) ) |
1121 | delete app; | 1153 | delete app; |
1122 | else | 1154 | else |
1123 | #endif | 1155 | #endif |
1124 | { | 1156 | { |
1125 | if ( !typ.isEmpty() ) { | 1157 | if ( !typ.isEmpty() ) { |
1126 | if ( !cadded ) { | 1158 | if ( !cadded ) { |
1127 | typs.append(typ); | 1159 | typs.append(typ); |
1128 | cadded = TRUE; | 1160 | cadded = TRUE; |
1129 | } | 1161 | } |
1130 | app->setType(typ); | 1162 | app->setType(typ); |
1163 | } | ||
1164 | add(app); | ||
1165 | } | ||
1166 | } | ||
1131 | } | 1167 | } |
1132 | add(app); | ||
1133 | } | ||
1134 | } | 1168 | } |
1135 | } | ||
1136 | } | 1169 | } |
1137 | } | ||
1138 | } | 1170 | } |
1139 | } | 1171 | } |
1140 | 1172 | ||
1141 | /*! | 1173 | /*! |
1142 | Adds AppLnk \a f to the set. The set takes responsibility for | 1174 | Adds AppLnk \a f to the set. The set takes responsibility for |
1143 | deleting \a f. | 1175 | deleting \a f. |
1144 | 1176 | ||
1145 | \sa remove() | 1177 | \sa remove() |
1146 | */ | 1178 | */ |
1147 | void AppLnkSet::add( AppLnk *f ) | 1179 | void AppLnkSet::add( AppLnk *f ) |
1148 | { | 1180 | { |
1149 | if ( f->mId == 0 ) { | 1181 | if ( f->mId == 0 ) { |
1150 | AppLnk::lastId++; | 1182 | AppLnk::lastId++; |
1151 | f->mId = AppLnk::lastId; | 1183 | f->mId = AppLnk::lastId; |
1152 | mApps.append( f ); | 1184 | mApps.append( f ); |
1153 | } else { | 1185 | } else { |
1154 | qWarning("Attempt to add an AppLnk twice"); | 1186 | qWarning("Attempt to add an AppLnk twice"); |
1155 | } | 1187 | } |
1156 | } | 1188 | } |
1157 | 1189 | ||
1158 | /*! | 1190 | /*! |
1159 | Removes AppLnk \a f to the set. The caller becomes responsible for | 1191 | Removes AppLnk \a f to the set. The caller becomes responsible for |
1160 | deleting \a f. Returns TRUE if \a f was in the set; otherwise | 1192 | deleting \a f. Returns TRUE if \a f was in the set; otherwise |
1161 | returns FALSE. | 1193 | returns FALSE. |
1162 | 1194 | ||
1163 | \sa add() | 1195 | \sa add() |
1164 | */ | 1196 | */ |
1165 | bool AppLnkSet::remove( AppLnk *f ) | 1197 | bool AppLnkSet::remove( AppLnk *f ) |
1166 | { | 1198 | { |
1167 | if ( mApps.remove( f ) ) { | 1199 | if ( mApps.remove( f ) ) { |
1168 | f->mId = 0; | 1200 | f->mId = 0; |
1169 | return TRUE; | 1201 | return TRUE; |
1170 | } | 1202 | } |
1171 | return FALSE; | 1203 | return FALSE; |
1172 | } | 1204 | } |
1173 | 1205 | ||
1174 | 1206 | ||
1175 | /*! | 1207 | /*! |
1176 | Returns the localized name for type \a t. | 1208 | Returns the localized name for type \a t. |
1177 | 1209 | ||
1178 | For applications, games and settings the type is \c Application; | 1210 | For applications, games and settings the type is \c Application; |
1179 | for documents the type is the document's MIME type. | 1211 | for documents the type is the document's MIME type. |
1180 | */ | 1212 | */ |
1181 | QString AppLnkSet::typeName( const QString& t ) const | 1213 | QString AppLnkSet::typeName( const QString& t ) const |
1182 | { | 1214 | { |
1183 | QString *st = d->typName.find(t); | 1215 | QString *st = d->typName.find(t); |
1184 | return st ? *st : QString::null; | 1216 | return st ? *st : QString::null; |
1185 | } | 1217 | } |
1186 | 1218 | ||
1187 | /*! | 1219 | /*! |
1188 | Returns the small pixmap associated with type \a t. | 1220 | Returns the small pixmap associated with type \a t. |
1189 | 1221 | ||
1190 | For applications, games and settings the type is \c Application; | 1222 | For applications, games and settings the type is \c Application; |
1191 | for documents the type is the document's MIME type. | 1223 | for documents the type is the document's MIME type. |
1192 | */ | 1224 | */ |
1193 | QPixmap AppLnkSet::typePixmap( const QString& t ) const | 1225 | QPixmap AppLnkSet::typePixmap( const QString& t ) const |
1194 | { | 1226 | { |
1195 | QPixmap *pm = d->typPix.find(t); | 1227 | AppLnkImagePrivate *alip = d->typPix.find(t); |
1196 | return pm ? *pm : QPixmap(); | 1228 | return alip ? *(alip->small()) : QPixmap(); |
1197 | } | 1229 | } |
1198 | 1230 | ||
1199 | /*! | 1231 | /*! |
1200 | Returns the large pixmap associated with type \a t. | 1232 | Returns the large pixmap associated with type \a t. |
1201 | 1233 | ||
1202 | For applications, games and settings the type is \c Application; | 1234 | For applications, games and settings the type is \c Application; |
1203 | for documents the type is the document's MIME type. | 1235 | for documents the type is the document's MIME type. |
1204 | */ | 1236 | */ |
1205 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const | 1237 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const |
1206 | { | 1238 | { |
1207 | QPixmap *pm = d->typPixBig.find(t); | 1239 | AppLnkImagePrivate *alip = d->typPix.find(t); |
1208 | return pm ? *pm : QPixmap(); | 1240 | return alip ? *(alip->big()) : QPixmap(); |
1209 | } | 1241 | } |
1210 | 1242 | ||
1211 | /*! | 1243 | /*! |
1212 | Returns the AppLnk with the given \a id. | 1244 | Returns the AppLnk with the given \a id. |
1213 | */ | 1245 | */ |
1214 | const AppLnk *AppLnkSet::find( int id ) const | 1246 | const AppLnk *AppLnkSet::find( int id ) const |
1215 | { | 1247 | { |
1216 | QListIterator<AppLnk> it( children() ); | 1248 | QListIterator<AppLnk> it( children() ); |
1217 | 1249 | ||
1218 | for ( ; it.current(); ++it ) { | 1250 | for ( ; it.current(); ++it ) { |
1219 | const AppLnk *app = it.current(); | 1251 | const AppLnk *app = it.current(); |
1220 | if ( app->id() == id ) | 1252 | if ( app->id() == id ) |
1221 | return app; | 1253 | return app; |
1222 | } | 1254 | } |
1223 | 1255 | ||
1224 | return 0; | 1256 | return 0; |
1225 | } | 1257 | } |
1226 | 1258 | ||
1227 | /*! | 1259 | /*! |
1228 | Returns the AppLnk with the given \a exec attribute. | 1260 | Returns the AppLnk with the given \a exec attribute. |
1229 | */ | 1261 | */ |
1230 | const AppLnk *AppLnkSet::findExec( const QString& exec ) const | 1262 | const AppLnk *AppLnkSet::findExec( const QString& exec ) const |
1231 | { | 1263 | { |
1232 | QListIterator<AppLnk> it( children() ); | 1264 | QListIterator<AppLnk> it( children() ); |
1233 | 1265 | ||
1234 | for ( ; it.current(); ++it ) { | 1266 | for ( ; it.current(); ++it ) { |
1235 | const AppLnk *app = it.current(); | 1267 | const AppLnk *app = it.current(); |
1236 | if ( app->exec() == exec ) | 1268 | if ( app->exec() == exec ) |
1237 | return app; | 1269 | return app; |
1238 | } | 1270 | } |
1239 | 1271 | ||
1240 | return 0; | 1272 | return 0; |
1241 | } | 1273 | } |
1242 | 1274 | ||
1243 | /*! | 1275 | /*! |
1244 | \class DocLnkSet applnk.h | 1276 | \class DocLnkSet applnk.h |
1245 | \brief The DocLnkSet class is a set of DocLnk objects. | 1277 | \brief The DocLnkSet class is a set of DocLnk objects. |
1246 | */ | 1278 | */ |
1247 | 1279 | ||
1248 | /*! | 1280 | /*! |
1249 | \fn const QList<DocLnk>& DocLnkSet::children() const | 1281 | \fn const QList<DocLnk>& DocLnkSet::children() const |
1250 | 1282 | ||
1251 | Returns the members of the set. | 1283 | Returns the members of the set. |
1252 | */ | 1284 | */ |
1253 | 1285 | ||
1254 | /*! | 1286 | /*! |
1255 | Constructs an empty DocLnkSet. | 1287 | Constructs an empty DocLnkSet. |
1256 | 1288 | ||
1257 | \sa appendFrom() | 1289 | \sa appendFrom() |
1258 | */ | 1290 | */ |
1259 | DocLnkSet::DocLnkSet() | 1291 | DocLnkSet::DocLnkSet() |
1260 | { | 1292 | { |
1261 | } | 1293 | } |
1262 | 1294 | ||
1263 | /*! | 1295 | /*! |
1264 | Constructs a DocLnkSet that contains DocLnk objects representing all | 1296 | Constructs a DocLnkSet that contains DocLnk objects representing all |
1265 | the files in the \a directory (and any subdirectories, recursively). | 1297 | the files in the \a directory (and any subdirectories, recursively). |
1266 | 1298 | ||
1267 | If \a mimefilter is not null, | 1299 | If \a mimefilter is not null, |
1268 | only documents with a MIME type matching \a mimefilter are selected. | 1300 | only documents with a MIME type matching \a mimefilter are selected. |
1269 | The value may contain multiple wild-card patterns separated by ";", | 1301 | The value may contain multiple wild-card patterns separated by ";", |
1270 | such as \c{*o/mpeg;audio/x-wav}. | 1302 | such as \c{*o/mpeg;audio/x-wav}. |
1271 | 1303 | ||
1272 | See also \link applnk.html#files-and-links Files and Links\endlink. | 1304 | See also \link applnk.html#files-and-links Files and Links\endlink. |
1273 | 1305 | ||
1274 | */ | 1306 | */ |
1275 | DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : | 1307 | DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : |
1276 | AppLnkSet() | 1308 | AppLnkSet() |
1277 | { | 1309 | { |
1278 | QDir dir( directory ); | 1310 | QDir dir( directory ); |
1279 | mFile = dir.dirName(); | 1311 | mFile = dir.dirName(); |
1280 | QDict<void> reference(1021); | 1312 | QDict<void> reference(1021); |
1281 | 1313 | ||
1282 | QStringList subFilter = QStringList::split(";", mimefilter); | 1314 | QStringList subFilter = QStringList::split(";", mimefilter); |
1283 | QValueList<QRegExp> mimeFilters; | 1315 | QValueList<QRegExp> mimeFilters; |
1284 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) | 1316 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) |
1285 | mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); | 1317 | mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); |
1286 | 1318 | ||
1287 | findChildren(directory, mimeFilters, reference); | 1319 | findChildren(directory, mimeFilters, reference); |
1288 | 1320 | ||
1289 | const QList<DocLnk> &list = children(); | 1321 | const QList<DocLnk> &list = children(); |
1290 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 1322 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
1291 | reference.remove( (*it)->file() ); | 1323 | reference.remove( (*it)->file() ); |
1292 | } | 1324 | } |
1293 | for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { | 1325 | for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { |
1294 | if ( dit.current() == (void*)2 ) { | 1326 | if ( dit.current() == (void*)2 ) { |
1295 | // Unreferenced, make an unwritten link | 1327 | // Unreferenced, make an unwritten link |
1296 | DocLnk* dl = new DocLnk; | 1328 | DocLnk* dl = new DocLnk; |
1297 | QFileInfo fi( dit.currentKey() ); | 1329 | QFileInfo fi( dit.currentKey() ); |
1298 | dl->setFile(fi.filePath()); | 1330 | dl->setFile(fi.filePath()); |
1299 | dl->setName(fi.baseName()); | 1331 | dl->setName(fi.baseName()); |
1300 | // #### default to current path? | 1332 | // #### default to current path? |
1301 | // dl->setCategories( ... ); | 1333 | // dl->setCategories( ... ); |
1302 | bool match = mimefilter.isNull(); | 1334 | bool match = mimefilter.isNull(); |
1303 | if ( !match ) | 1335 | if ( !match ) |
1304 | for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) | 1336 | for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) |
1305 | if ( (*it).match(dl->type()) >= 0 ) | 1337 | if ( (*it).match(dl->type()) >= 0 ) |
1306 | match = TRUE; | 1338 | match = TRUE; |
1307 | if ( match /* && dl->type() != "application/octet-stream" */ | 1339 | if ( match /* && dl->type() != "application/octet-stream" */ |
1308 | && !!dl->exec() ) | 1340 | && !!dl->exec() ) |
1309 | add(dl); | 1341 | add(dl); |
1310 | else | 1342 | else |
1311 | delete dl; | 1343 | delete dl; |
1312 | } | 1344 | } |
1313 | } | 1345 | } |
1314 | } | 1346 | } |
1315 | 1347 | ||
1316 | // other becomes empty | 1348 | // other becomes empty |
1317 | /*! | 1349 | /*! |
1318 | Transfers all DocLnk objects from \a other to this set. \a other becomes | 1350 | Transfers all DocLnk objects from \a other to this set. \a other becomes |
1319 | empty. | 1351 | empty. |
1320 | */ | 1352 | */ |
1321 | void DocLnkSet::appendFrom( DocLnkSet& other ) | 1353 | void DocLnkSet::appendFrom( DocLnkSet& other ) |
1322 | { | 1354 | { |
1323 | if ( &other == this ) | 1355 | if ( &other == this ) |
1324 | return; | 1356 | return; |
1325 | QListIterator<AppLnk> it( other.mApps ); | 1357 | QListIterator<AppLnk> it( other.mApps ); |
1326 | for ( ; it.current(); ) { | 1358 | for ( ; it.current(); ) { |
1327 | mApps.append(*it); | 1359 | mApps.append(*it); |
1328 | ++it; | 1360 | ++it; |
1329 | } | 1361 | } |
1330 | other.mApps.clear(); | 1362 | other.mApps.clear(); |
1331 | } | 1363 | } |
1332 | 1364 | ||
1333 | void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) | 1365 | void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) |
1334 | { | 1366 | { |
1335 | depth++; | 1367 | depth++; |
1336 | if ( depth > 10 ) | 1368 | if ( depth > 10 ) |
1337 | return; | 1369 | return; |
1338 | 1370 | ||
1339 | QDir dir( dr ); | 1371 | QDir dir( dr ); |
1340 | 1372 | ||
1341 | /* Opie got a different approach | 1373 | /* Opie got a different approach |
1342 | * I guess it's geek vs. consumer | 1374 | * I guess it's geek vs. consumer |
1343 | * in this case to be discussed | 1375 | * in this case to be discussed |
1344 | */ | 1376 | */ |
1345 | if ( dir.exists( ".Qtopia-ignore" ) ) | 1377 | if ( dir.exists( ".Qtopia-ignore" ) ) |
1346 | return; | 1378 | return; |
1347 | 1379 | ||
1348 | const QFileInfoList *list = dir.entryInfoList(); | 1380 | const QFileInfoList *list = dir.entryInfoList(); |
1349 | if ( list ) { | 1381 | if ( list ) { |
1350 | QFileInfo* fi; | 1382 | QFileInfo* fi; |
1351 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 1383 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
1352 | QString bn = fi->fileName(); | 1384 | QString bn = fi->fileName(); |
1353 | if ( bn[0] != '.' ) { | 1385 | if ( bn[0] != '.' ) { |
1354 | if ( fi->isDir() ) { | 1386 | if ( fi->isDir() ) { |
1355 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) | 1387 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) |
1356 | findChildren(fi->filePath(), mimeFilters, reference, depth); | 1388 | findChildren(fi->filePath(), mimeFilters, reference, depth); |
1357 | } else { | 1389 | } else { |
1358 | if ( fi->extension(FALSE) == "desktop" ) { | 1390 | if ( fi->extension(FALSE) == "desktop" ) { |
1359 | DocLnk* dl = new DocLnk( fi->filePath() ); | 1391 | DocLnk* dl = new DocLnk( fi->filePath() ); |
1360 | QFileInfo fi2(dl->file()); | 1392 | QFileInfo fi2(dl->file()); |
1361 | bool match = FALSE; | 1393 | bool match = FALSE; |
1362 | if ( !fi2.exists() ) { | 1394 | if ( !fi2.exists() ) { |
1363 | dir.remove( dl->file() ); | 1395 | dir.remove( dl->file() ); |
1364 | } | 1396 | } |
1365 | if ( mimeFilters.count() == 0 ) { | 1397 | if ( mimeFilters.count() == 0 ) { |
1366 | add( dl ); | 1398 | add( dl ); |
1367 | match = TRUE; | 1399 | match = TRUE; |
1368 | } else { | 1400 | } else { |
1369 | for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { | 1401 | for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { |
1370 | if ( (*it).match(dl->type()) >= 0 ) { | 1402 | if ( (*it).match(dl->type()) >= 0 ) { |
1371 | add(dl); | 1403 | add(dl); |
1372 | match = TRUE; | 1404 | match = TRUE; |
1373 | } | 1405 | } |
1374 | } | 1406 | } |
1375 | } | 1407 | } |
1376 | if ( !match ) | 1408 | if ( !match ) |
1377 | delete dl; | 1409 | delete dl; |
1378 | } else { | 1410 | } else { |
1379 | if ( !reference.find(fi->fileName()) ) | 1411 | if ( !reference.find(fi->fileName()) ) |
1380 | reference.insert(fi->filePath(), (void*)2); | 1412 | reference.insert(fi->filePath(), (void*)2); |
1381 | } | 1413 | } |
1382 | } | 1414 | } |
1383 | } | 1415 | } |
1384 | } | 1416 | } |
1385 | } | 1417 | } |
1386 | } | 1418 | } |
1387 | 1419 | ||
1388 | /*! | 1420 | /*! |
1389 | \class DocLnk applnk.h | 1421 | \class DocLnk applnk.h |
1390 | \brief The DocLnk class represents loaded document references. | 1422 | \brief The DocLnk class represents loaded document references. |
1391 | */ | 1423 | */ |
1392 | 1424 | ||
1393 | /*! | 1425 | /*! |
1394 | \fn DocLnk::DocLnk( const DocLnk &o ) | 1426 | \fn DocLnk::DocLnk( const DocLnk &o ) |
1395 | 1427 | ||
1396 | Copies \a o. | 1428 | Copies \a o. |
1397 | */ | 1429 | */ |
1398 | 1430 | ||
1399 | /*! | 1431 | /*! |
1400 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop | 1432 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop |
1401 | \a file for other files. | 1433 | \a file for other files. |
1402 | */ | 1434 | */ |
1403 | DocLnk::DocLnk( const QString &file ) : | 1435 | DocLnk::DocLnk( const QString &file ) : |
1404 | AppLnk(file) | 1436 | AppLnk(file) |
1405 | { | 1437 | { |
1406 | init(file); | 1438 | init(file); |
1407 | } | 1439 | } |
1408 | 1440 | ||
1409 | /*! | 1441 | /*! |
1410 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop | 1442 | Constructs a DocLnk from a valid .desktop \a file or a new .desktop |
1411 | \a file for other files. If \a may_be_desktopfile is TRUE, then an | 1443 | \a file for other files. If \a may_be_desktopfile is TRUE, then an |
1412 | attempt is made to read \a file as a .desktop file; if that fails it | 1444 | attempt is made to read \a file as a .desktop file; if that fails it |
1413 | is read as a normal file. | 1445 | is read as a normal file. |
1414 | */ | 1446 | */ |
1415 | DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : | 1447 | DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : |
1416 | AppLnk(may_be_desktopfile ? file : QString::null) | 1448 | AppLnk(may_be_desktopfile ? file : QString::null) |
1417 | { | 1449 | { |
1418 | init(file); | 1450 | init(file); |
1419 | } | 1451 | } |
1420 | 1452 | ||
1421 | void DocLnk::init(const QString &file) | 1453 | void DocLnk::init(const QString &file) |
1422 | { | 1454 | { |
1423 | if ( isValid() ) { | 1455 | if ( isValid() ) { |
1424 | #ifndef FORCED_DIR_STRUCTURE_WAY | 1456 | #ifndef FORCED_DIR_STRUCTURE_WAY |
1425 | if ( mType.isNull() ) | 1457 | if ( mType.isNull() ) |
1426 | // try to infer it | 1458 | // try to infer it |
1427 | #endif | 1459 | #endif |
1428 | { | 1460 | { |
1429 | int s0 = file.findRev('/'); | 1461 | int s0 = file.findRev('/'); |
1430 | if ( s0 > 0 ) { | 1462 | if ( s0 > 0 ) { |
1431 | int s1 = file.findRev('/',s0-1); | 1463 | int s1 = file.findRev('/',s0-1); |
1432 | if ( s1 > 0 ) { | 1464 | if ( s1 > 0 ) { |
1433 | int s2 = file.findRev('/',s1-1); | 1465 | int s2 = file.findRev('/',s1-1); |
1434 | if ( s2 > 0 ) { | 1466 | if ( s2 > 0 ) { |
1435 | mType = file.mid(s2+1,s0-s2-1); | 1467 | mType = file.mid(s2+1,s0-s2-1); |
1436 | } | 1468 | } |
1437 | } | 1469 | } |
1438 | } | 1470 | } |
1439 | } | 1471 | } |
1440 | } else if ( QFile::exists(file) ) { | 1472 | } else if ( QFile::exists(file) ) { |
1441 | QString n = file; | 1473 | QString n = file; |
1442 | n.replace(QRegExp(".*/"),""); | 1474 | n.replace(QRegExp(".*/"),""); |
1443 | n.replace(QRegExp("\\..*"),""); | 1475 | n.replace(QRegExp("\\..*"),""); |
1444 | setName( n ); | 1476 | setName( n ); |
1445 | setFile( file ); | 1477 | setFile( file ); |
1446 | } | 1478 | } |
1447 | MimeType mt(mType); | 1479 | MimeType mt(mType); |
1448 | if( mt.application() ) | 1480 | if( mt.application() ) |
1449 | mExec = mt.application()->exec(); | 1481 | mExec = mt.application()->exec(); |
1450 | } | 1482 | } |
1451 | 1483 | ||
1452 | /*! | 1484 | /*! |
1453 | Constructs an invalid DocLnk. | 1485 | Constructs an invalid DocLnk. |
1454 | */ | 1486 | */ |
1455 | DocLnk::DocLnk() | 1487 | DocLnk::DocLnk() |
1456 | { | 1488 | { |
1457 | } | 1489 | } |
1458 | 1490 | ||
1459 | /*! | 1491 | /*! |
1460 | Destroys the DocLnk. Just like AppLnk objects, a run-time error | 1492 | Destroys the DocLnk. Just like AppLnk objects, a run-time error |
1461 | occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). | 1493 | occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). |
1462 | */ | 1494 | */ |
1463 | DocLnk::~DocLnk() | 1495 | DocLnk::~DocLnk() |
1464 | { | 1496 | { |
1465 | } | 1497 | } |
1466 | 1498 | ||
1467 | /*! | 1499 | /*! |
1468 | \reimp | 1500 | \reimp |
1469 | */ | 1501 | */ |
1470 | QString DocLnk::exec() const | 1502 | QString DocLnk::exec() const |
1471 | { | 1503 | { |
1472 | MimeType mt(type()); | 1504 | MimeType mt(type()); |
1473 | const AppLnk* app = mt.application(); | 1505 | const AppLnk* app = mt.application(); |
1474 | if ( app ) | 1506 | if ( app ) |
1475 | return app->exec(); | 1507 | return app->exec(); |
1476 | else | 1508 | else |
1477 | return QString::null; | 1509 | return QString::null; |
1478 | } | 1510 | } |
1479 | 1511 | ||
1480 | /*! | 1512 | /*! |
1481 | \reimp | 1513 | \reimp |
1482 | */ | 1514 | */ |
1483 | void DocLnk::invoke(const QStringList& args) const | 1515 | void DocLnk::invoke(const QStringList& args) const |
1484 | { | 1516 | { |
1485 | MimeType mt(type()); | 1517 | MimeType mt(type()); |
1486 | const AppLnk* app = mt.application(); | 1518 | const AppLnk* app = mt.application(); |
1487 | if ( app ) { | 1519 | if ( app ) { |
1488 | QStringList a = args; | 1520 | QStringList a = args; |
1489 | if ( linkFileKnown() && QFile::exists( linkFile() ) ) | 1521 | if ( linkFileKnown() && QFile::exists( linkFile() ) ) |
1490 | a.append(linkFile()); | 1522 | a.append(linkFile()); |
1491 | else | 1523 | else |
1492 | a.append(file()); | 1524 | a.append(file()); |
1493 | app->execute(a); | 1525 | app->execute(a); |
1494 | } | 1526 | } |
1495 | } | 1527 | } |
1496 | 1528 | ||
1497 | 1529 | ||
diff --git a/library/resource.cpp b/library/resource.cpp index cfa0d26..b31876f 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -1,230 +1,235 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_MIMEEXT | 21 | #define QTOPIA_INTERNAL_MIMEEXT |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include "resource.h" | 23 | #include "resource.h" |
24 | #include "mimetype.h" | 24 | #include "mimetype.h" |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qpixmapcache.h> | 26 | #include <qpixmapcache.h> |
27 | 27 | ||
28 | // this namespace is just a workaround for a gcc bug | 28 | // this namespace is just a workaround for a gcc bug |
29 | // gcc exports inline functions in the generated file | 29 | // gcc exports inline functions in the generated file |
30 | // inlinepics_p.h | 30 | // inlinepics_p.h |
31 | 31 | ||
32 | namespace { | 32 | namespace { |
33 | #include "inlinepics_p.h" | 33 | #include "inlinepics_p.h" |
34 | } | 34 | } |
35 | 35 | ||
36 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | 36 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); |
37 | 37 | ||
38 | /*! | 38 | /*! |
39 | \class Resource resource.h | 39 | \class Resource resource.h |
40 | \brief The Resource class provides access to named resources. | 40 | \brief The Resource class provides access to named resources. |
41 | 41 | ||
42 | The resources may be provided from files or other sources. | 42 | The resources may be provided from files or other sources. |
43 | 43 | ||
44 | The allSounds() function returns a list of all the sounds available. | 44 | The allSounds() function returns a list of all the sounds available. |
45 | A particular sound can be searched for using findSound(). | 45 | A particular sound can be searched for using findSound(). |
46 | 46 | ||
47 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 47 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
48 | and loadIconSet(). | 48 | and loadIconSet(). |
49 | 49 | ||
50 | \ingroup qtopiaemb | 50 | \ingroup qtopiaemb |
51 | */ | 51 | */ |
52 | 52 | ||
53 | /*! | 53 | /*! |
54 | \fn Resource::Resource() | 54 | \fn Resource::Resource() |
55 | \internal | 55 | \internal |
56 | */ | 56 | */ |
57 | 57 | ||
58 | /*! | 58 | /*! |
59 | Returns the QPixmap called \a pix. You should avoid including | 59 | Returns the QPixmap called \a pix. You should avoid including |
60 | any filename type extension (e.g. .png, .xpm). | 60 | any filename type extension (e.g. .png, .xpm). |
61 | */ | 61 | */ |
62 | #include <stdio.h> | ||
62 | QPixmap Resource::loadPixmap( const QString &pix ) | 63 | QPixmap Resource::loadPixmap( const QString &pix ) |
63 | { | 64 | { |
64 | QPixmap pm; | 65 | QPixmap pm; // null pixmap |
65 | QString key="QPE_"+pix; | 66 | QString key="QPE_"+pix; |
66 | if ( !QPixmapCache::find(key,pm) ) { | 67 | if ( !QPixmapCache::find(key,pm) ) { |
67 | pm.convertFromImage(loadImage(pix)); | 68 | QImage I = loadImage(pix); |
68 | QPixmapCache::insert(key,pm); | 69 | if( I.isNull() ) { |
70 | qWarning( "Could not load %s", pix.latin1() ); | ||
71 | } else { | ||
72 | pm.convertFromImage(I); | ||
73 | QPixmapCache::insert(key,pm); | ||
74 | } | ||
69 | } | 75 | } |
70 | return pm; | 76 | return pm; |
71 | } | 77 | } |
72 | 78 | ||
73 | /*! | 79 | /*! |
74 | Returns the QBitmap called \a pix. You should avoid including | 80 | Returns the QBitmap called \a pix. You should avoid including |
75 | any filename type extension (e.g. .png, .xpm). | 81 | any filename type extension (e.g. .png, .xpm). |
76 | */ | 82 | */ |
77 | QBitmap Resource::loadBitmap( const QString &pix ) | 83 | QBitmap Resource::loadBitmap( const QString &pix ) |
78 | { | 84 | { |
79 | QBitmap bm; | 85 | QBitmap bm; |
80 | bm = loadPixmap(pix); | 86 | bm = loadPixmap(pix); |
81 | return bm; | 87 | return bm; |
82 | } | 88 | } |
83 | 89 | ||
84 | /*! | 90 | /*! |
85 | Returns the filename of a pixmap called \a pix. You should avoid including | 91 | Returns the filename of a pixmap called \a pix. You should avoid including |
86 | any filename type extension (e.g. .png, .xpm). | 92 | any filename type extension (e.g. .png, .xpm). |
87 | 93 | ||
88 | Normally you will use loadPixmap() rather than this function. | 94 | Normally you will use loadPixmap() rather than this function. |
89 | */ | 95 | */ |
90 | QString Resource::findPixmap( const QString &pix ) | 96 | QString Resource::findPixmap( const QString &pix ) |
91 | { | 97 | { |
92 | QString picsPath = QPEApplication::qpeDir() + "pics/"; | 98 | QString picsPath = QPEApplication::qpeDir() + "pics/"; |
93 | 99 | ||
94 | QString f; | 100 | QString f; |
95 | 101 | ||
96 | // Common case optimizations... | 102 | // Common case optimizations... |
97 | f = picsPath + pix + ".png"; | 103 | f = picsPath + pix + ".png"; |
98 | if ( QFile( f ).exists() ) | 104 | if ( QFile( f ).exists() ) |
99 | return f; | 105 | return f; |
100 | f = picsPath + pix + ".xpm"; | 106 | f = picsPath + pix + ".xpm"; |
101 | if ( QFile( f ).exists() ) | 107 | if ( QFile( f ).exists() ) |
102 | return f; | 108 | return f; |
103 | 109 | ||
104 | |||
105 | // All formats... | 110 | // All formats... |
106 | QStrList fileFormats = QImageIO::inputFormats(); | 111 | QStrList fileFormats = QImageIO::inputFormats(); |
107 | QString ff = fileFormats.first(); | 112 | QString ff = fileFormats.first(); |
108 | while ( fileFormats.current() ) { | 113 | while ( fileFormats.current() ) { |
109 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 114 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
110 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 115 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
111 | QString f = picsPath + pix + "." + *it; | 116 | QString f = picsPath + pix + "." + *it; |
112 | if ( QFile(f).exists() ) | 117 | if ( QFile(f).exists() ) |
113 | return f; | 118 | return f; |
114 | } | 119 | } |
115 | ff = fileFormats.next(); | 120 | ff = fileFormats.next(); |
116 | } | 121 | } |
117 | 122 | ||
118 | // Finally, no (or existing) extension... | 123 | // Finally, no (or existing) extension... |
119 | if ( QFile( picsPath + pix ).exists() ) | 124 | if ( QFile( picsPath + pix ).exists() ) |
120 | return picsPath + pix; | 125 | return picsPath + pix; |
121 | 126 | ||
122 | //qDebug("Cannot find pixmap: %s", pix.latin1()); | 127 | //qDebug("Cannot find pixmap: %s", pix.latin1()); |
123 | return QString(); | 128 | return QString(); |
124 | } | 129 | } |
125 | 130 | ||
126 | /*! | 131 | /*! |
127 | Returns a sound file for a sound called \a name. | 132 | Returns a sound file for a sound called \a name. |
128 | 133 | ||
129 | You should avoid including any filename type extension (e.g. .wav), | 134 | You should avoid including any filename type extension (e.g. .wav), |
130 | as the system will search for only those fileformats which are supported | 135 | as the system will search for only those fileformats which are supported |
131 | by the library. | 136 | by the library. |
132 | 137 | ||
133 | Currently, only WAV files are supported. | 138 | Currently, only WAV files are supported. |
134 | */ | 139 | */ |
135 | QString Resource::findSound( const QString &name ) | 140 | QString Resource::findSound( const QString &name ) |
136 | { | 141 | { |
137 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; | 142 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; |
138 | 143 | ||
139 | QString result; | 144 | QString result; |
140 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) | 145 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) |
141 | return result; | 146 | return result; |
142 | 147 | ||
143 | return QString(); | 148 | return QString(); |
144 | } | 149 | } |
145 | 150 | ||
146 | /*! | 151 | /*! |
147 | Returns a list of all sound names. | 152 | Returns a list of all sound names. |
148 | */ | 153 | */ |
149 | QStringList Resource::allSounds() | 154 | QStringList Resource::allSounds() |
150 | { | 155 | { |
151 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); | 156 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); |
152 | QStringList entries = resourcedir.entryList(); | 157 | QStringList entries = resourcedir.entryList(); |
153 | QStringList result; | 158 | QStringList result; |
154 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) | 159 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) |
155 | result.append((*i).replace(QRegExp("\\.wav"),"")); | 160 | result.append((*i).replace(QRegExp("\\.wav"),"")); |
156 | return result; | 161 | return result; |
157 | } | 162 | } |
158 | 163 | ||
159 | static QImage load_image(const QString &name) | 164 | static QImage load_image(const QString &name) |
160 | { | 165 | { |
161 | if (g_notUseSet ) { | 166 | if (g_notUseSet ) { |
162 | // try file | 167 | // try file |
163 | QImage img; | 168 | QImage img; |
164 | QString f = Resource::findPixmap(name); | 169 | QString f = Resource::findPixmap(name); |
165 | if ( !f.isEmpty() ) | 170 | if ( !f.isEmpty() ) |
166 | img.load(f); | 171 | img.load(f); |
167 | if (img.isNull() ) | 172 | if (img.isNull() ) |
168 | img = qembed_findImage(name.latin1() ); | 173 | img = qembed_findImage(name.latin1() ); |
169 | return img; | 174 | return img; |
170 | } | 175 | } |
171 | else{ | 176 | else{ |
172 | QImage img = qembed_findImage(name.latin1()); | 177 | QImage img = qembed_findImage(name.latin1()); |
173 | 178 | ||
174 | if ( img.isNull() ) { | 179 | if ( img.isNull() ) { |
175 | // No inlined image, try file | 180 | // No inlined image, try file |
176 | QString f = Resource::findPixmap(name); | 181 | QString f = Resource::findPixmap(name); |
177 | if ( !f.isEmpty() ) | 182 | if ( !f.isEmpty() ) |
178 | img.load(f); | 183 | img.load(f); |
179 | } | 184 | } |
180 | return img; | 185 | return img; |
181 | } | 186 | } |
182 | } | 187 | } |
183 | 188 | ||
184 | /*! | 189 | /*! |
185 | Returns the QImage called \a name. You should avoid including | 190 | Returns the QImage called \a name. You should avoid including |
186 | any filename type extension (e.g. .png, .xpm). | 191 | any filename type extension (e.g. .png, .xpm). |
187 | */ | 192 | */ |
188 | QImage Resource::loadImage( const QString &name) | 193 | QImage Resource::loadImage( const QString &name) |
189 | { | 194 | { |
190 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 195 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
191 | static QImage last_enabled; | 196 | static QImage last_enabled; |
192 | static QString last_enabled_name; | 197 | static QString last_enabled_name; |
193 | if ( name == last_enabled_name ) | 198 | if ( name == last_enabled_name ) |
194 | return last_enabled; | 199 | return last_enabled; |
195 | #endif | 200 | #endif |
196 | QImage img = load_image(name); | 201 | QImage img = load_image(name); |
197 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 202 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
198 | if ( img.isNull() ) { | 203 | if ( img.isNull() ) { |
199 | // No file, try generating | 204 | // No file, try generating |
200 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { | 205 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { |
201 | last_enabled_name = name.left(name.length()-9); | 206 | last_enabled_name = name.left(name.length()-9); |
202 | last_enabled = load_image(last_enabled_name); | 207 | last_enabled = load_image(last_enabled_name); |
203 | if ( last_enabled.isNull() ) { | 208 | if ( last_enabled.isNull() ) { |
204 | last_enabled_name = QString::null; | 209 | last_enabled_name = QString::null; |
205 | } else { | 210 | } else { |
206 | img.detach(); | 211 | img.detach(); |
207 | img.create( last_enabled.width(), last_enabled.height(), 32 ); | 212 | img.create( last_enabled.width(), last_enabled.height(), 32 ); |
208 | for ( int y = 0; y < img.height(); y++ ) { | 213 | for ( int y = 0; y < img.height(); y++ ) { |
209 | for ( int x = 0; x < img.width(); x++ ) { | 214 | for ( int x = 0; x < img.width(); x++ ) { |
210 | QRgb p = last_enabled.pixel( x, y ); | 215 | QRgb p = last_enabled.pixel( x, y ); |
211 | int a = qAlpha(p)/3; | 216 | int a = qAlpha(p)/3; |
212 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); | 217 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); |
213 | img.setPixel( x, y, qRgba(g,g,g,a) ); | 218 | img.setPixel( x, y, qRgba(g,g,g,a) ); |
214 | } | 219 | } |
215 | } | 220 | } |
216 | img.setAlphaBuffer( TRUE ); | 221 | img.setAlphaBuffer( TRUE ); |
217 | } | 222 | } |
218 | } | 223 | } |
219 | } | 224 | } |
220 | #endif | 225 | #endif |
221 | return img; | 226 | return img; |
222 | } | 227 | } |
223 | 228 | ||
224 | /*! | 229 | /*! |
225 | \fn QIconSet Resource::loadIconSet( const QString &name ) | 230 | \fn QIconSet Resource::loadIconSet( const QString &name ) |
226 | 231 | ||
227 | Returns a QIconSet for the pixmap named \a name. A disabled icon is | 232 | Returns a QIconSet for the pixmap named \a name. A disabled icon is |
228 | generated that conforms to the Qtopia look & feel. You should avoid | 233 | generated that conforms to the Qtopia look & feel. You should avoid |
229 | including any filename type extension (eg. .png, .xpm). | 234 | including any filename type extension (eg. .png, .xpm). |
230 | */ | 235 | */ |