author | zecke <zecke> | 2003-02-11 17:26:51 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-11 17:26:51 (UTC) |
commit | 99ccdda218112cfb0f7371fa05d7a696b8da1c40 (patch) (unidiff) | |
tree | 64d46b22de7acbccbc2ee73c406be7645ff693c3 | |
parent | df37010a49dfa9624c9600e4ed838ec7aade1b31 (diff) | |
download | opie-99ccdda218112cfb0f7371fa05d7a696b8da1c40.zip opie-99ccdda218112cfb0f7371fa05d7a696b8da1c40.tar.gz opie-99ccdda218112cfb0f7371fa05d7a696b8da1c40.tar.bz2 |
fix bug 0000591
AppLnk does not need to reload all labels but it needs to reload
the names for the ids in mCat
-rw-r--r-- | library/applnk.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 5763c62..35822dd 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -44,97 +44,101 @@ | |||
44 | 44 | ||
45 | int AppLnk::lastId = 5000; | 45 | int AppLnk::lastId = 5000; |
46 | 46 | ||
47 | static int smallSize = 14; | 47 | static int smallSize = 14; |
48 | static int bigSize = 32; | 48 | static int bigSize = 32; |
49 | 49 | ||
50 | static QString safeFileName(const QString& n) | 50 | static QString safeFileName(const QString& n) |
51 | { | 51 | { |
52 | QString safename=n; | 52 | QString safename=n; |
53 | safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); | 53 | safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); |
54 | safename.replace(QRegExp("^[^A-Za-z]*"),""); | 54 | safename.replace(QRegExp("^[^A-Za-z]*"),""); |
55 | if ( safename.isEmpty() ) | 55 | if ( safename.isEmpty() ) |
56 | safename = "_"; | 56 | safename = "_"; |
57 | return safename; | 57 | return safename; |
58 | } | 58 | } |
59 | 59 | ||
60 | static bool prepareDirectories(const QString& lf) | 60 | static bool prepareDirectories(const QString& lf) |
61 | { | 61 | { |
62 | if ( !QFile::exists(lf) ) { | 62 | if ( !QFile::exists(lf) ) { |
63 | // May need to create directories | 63 | // May need to create directories |
64 | QFileInfo fi(lf); | 64 | QFileInfo fi(lf); |
65 | if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) | 65 | if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) |
66 | return FALSE; | 66 | return FALSE; |
67 | } | 67 | } |
68 | return TRUE; | 68 | return TRUE; |
69 | } | 69 | } |
70 | 70 | ||
71 | class AppLnkPrivate | 71 | class AppLnkPrivate |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | /* the size of the Pixmap */ | 74 | /* the size of the Pixmap */ |
75 | enum Size {Normal = 0, Big }; | 75 | enum Size {Normal = 0, Big }; |
76 | AppLnkPrivate() { | 76 | AppLnkPrivate() { |
77 | /* we want one normal and one big item */ | 77 | /* we want one normal and one big item */ |
78 | 78 | ||
79 | QPixmap pix; | 79 | QPixmap pix; |
80 | mPixmaps.insert(0, pix ); | 80 | mPixmaps.insert(0, pix ); |
81 | mPixmaps.insert(1, pix); | 81 | mPixmaps.insert(1, pix); |
82 | } | 82 | } |
83 | 83 | ||
84 | QStringList mCatList; // always correct | 84 | QStringList mCatList; // always correct |
85 | QArray<int> mCat; // cached value; correct if not empty | 85 | QArray<int> mCat; // cached value; correct if not empty |
86 | QMap<int, QPixmap> mPixmaps; | 86 | QMap<int, QPixmap> mPixmaps; |
87 | 87 | ||
88 | void updateCatListFromArray() | 88 | void updateCatListFromArray() |
89 | { | 89 | { |
90 | Categories cat( 0 ); | 90 | Categories cat( 0 ); |
91 | cat.load( categoryFileName() ); | 91 | cat.load( categoryFileName() ); |
92 | mCatList = cat.labels("Document View",mCat); | 92 | // we need to update the names for the mCat... to mCatList |
93 | mCatList.clear(); | ||
94 | for (uint i = 0; i < mCat.count(); i++ ) | ||
95 | mCatList << cat.label("Document View", mCat[i] ); | ||
96 | |||
93 | } | 97 | } |
94 | 98 | ||
95 | void setCatArrayDirty() | 99 | void setCatArrayDirty() |
96 | { | 100 | { |
97 | mCat.resize(0); | 101 | mCat.resize(0); |
98 | } | 102 | } |
99 | 103 | ||
100 | void ensureCatArray() | 104 | void ensureCatArray() |
101 | { | 105 | { |
102 | if ( mCat.count() > 0 || mCatList.count()==0 ) | 106 | if ( mCat.count() > 0 || mCatList.count()==0 ) |
103 | return; | 107 | return; |
104 | 108 | ||
105 | Categories cat( 0 ); | 109 | Categories cat( 0 ); |
106 | cat.load( categoryFileName() ); | 110 | cat.load( categoryFileName() ); |
107 | mCat.resize( mCatList.count() ); | 111 | mCat.resize( mCatList.count() ); |
108 | int i; | 112 | int i; |
109 | QStringList::ConstIterator it; | 113 | QStringList::ConstIterator it; |
110 | for ( i = 0, it = mCatList.begin(); it != mCatList.end(); | 114 | for ( i = 0, it = mCatList.begin(); it != mCatList.end(); |
111 | ++it, i++ ) { | 115 | ++it, i++ ) { |
112 | 116 | ||
113 | bool number; | 117 | bool number; |
114 | int id = (*it).toInt( &number ); | 118 | int id = (*it).toInt( &number ); |
115 | if ( !number ) { | 119 | if ( !number ) { |
116 | id = cat.id( "Document View", *it ); | 120 | id = cat.id( "Document View", *it ); |
117 | if ( id == 0 ) | 121 | if ( id == 0 ) |
118 | id = cat.addCategory( "Document View", *it ); | 122 | id = cat.addCategory( "Document View", *it ); |
119 | } | 123 | } |
120 | mCat[i] = id; | 124 | mCat[i] = id; |
121 | } | 125 | } |
122 | } | 126 | } |
123 | }; | 127 | }; |
124 | 128 | ||
125 | /*! | 129 | /*! |
126 | \class AppLnk applnk.h | 130 | \class AppLnk applnk.h |
127 | \brief The AppLnk class represents an application available on the system. | 131 | \brief The AppLnk class represents an application available on the system. |
128 | 132 | ||
129 | Every Qtopia application \e app has a corresponding \e app.desktop | 133 | Every Qtopia application \e app has a corresponding \e app.desktop |
130 | file. When one of these files is read its data is stored as an | 134 | file. When one of these files is read its data is stored as an |
131 | AppLnk object. | 135 | AppLnk object. |
132 | 136 | ||
133 | The AppLnk class introduces some Qtopia-specific concepts, and | 137 | The AppLnk class introduces some Qtopia-specific concepts, and |
134 | provides a variety of functions, as described in the following | 138 | provides a variety of functions, as described in the following |
135 | sections. | 139 | sections. |
136 | \tableofcontents | 140 | \tableofcontents |
137 | 141 | ||
138 | \target Types | 142 | \target Types |
139 | \section1 Types | 143 | \section1 Types |
140 | 144 | ||
@@ -361,96 +365,97 @@ AppLnk::AppLnk( const QString &file ) | |||
361 | mIconFile = config.readEntry( "Icon", QString::null ); | 365 | mIconFile = config.readEntry( "Icon", QString::null ); |
362 | mRotation = config.readEntry( "Rotation", "" ); | 366 | mRotation = config.readEntry( "Rotation", "" ); |
363 | mComment = config.readEntry( "Comment", QString::null ); | 367 | mComment = config.readEntry( "Comment", QString::null ); |
364 | // MIME types are case-insensitive. | 368 | // MIME types are case-insensitive. |
365 | mMimeTypes = config.readListEntry( "MimeType", ';' ); | 369 | mMimeTypes = config.readListEntry( "MimeType", ';' ); |
366 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) | 370 | for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) |
367 | *it = (*it).lower(); | 371 | *it = (*it).lower(); |
368 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); | 372 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); |
369 | mLinkFile = file; | 373 | mLinkFile = file; |
370 | mFile = config.readEntry("File", QString::null); | 374 | mFile = config.readEntry("File", QString::null); |
371 | if ( !mExec. isEmpty ( )) { | 375 | if ( !mExec. isEmpty ( )) { |
372 | mFile = QString::null; | 376 | mFile = QString::null; |
373 | } | 377 | } |
374 | else if ( mFile[0] != '/' ) { | 378 | else if ( mFile[0] != '/' ) { |
375 | int slash = file.findRev('/'); | 379 | int slash = file.findRev('/'); |
376 | if ( slash >= 0 ) { | 380 | if ( slash >= 0 ) { |
377 | mFile = file.left(slash) + '/' + mFile; | 381 | mFile = file.left(slash) + '/' + mFile; |
378 | } | 382 | } |
379 | } | 383 | } |
380 | d->mCatList = config.readListEntry("Categories", ';'); | 384 | d->mCatList = config.readListEntry("Categories", ';'); |
381 | if ( d->mCatList[0].toInt() < -1 ) { | 385 | if ( d->mCatList[0].toInt() < -1 ) { |
382 | // numeric cats in file! convert to text | 386 | // numeric cats in file! convert to text |
383 | Categories cat( 0 ); | 387 | Categories cat( 0 ); |
384 | cat.load( categoryFileName() ); | 388 | cat.load( categoryFileName() ); |
385 | d->mCat.resize( d->mCatList.count() ); | 389 | d->mCat.resize( d->mCatList.count() ); |
386 | int i; | 390 | int i; |
387 | QStringList::ConstIterator it; | 391 | QStringList::ConstIterator it; |
388 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); | 392 | for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); |
389 | ++it, i++ ) { | 393 | ++it, i++ ) { |
390 | bool number; | 394 | bool number; |
391 | int id = (*it).toInt( &number ); | 395 | int id = (*it).toInt( &number ); |
392 | if ( !number ) { | 396 | if ( !number ) { |
393 | // convert from text | 397 | // convert from text |
394 | id = cat.id( "Document View", *it ); | 398 | id = cat.id( "Document View", *it ); |
395 | if ( id == 0 ) | 399 | if ( id == 0 ) |
396 | id = cat.addCategory( "Document View", *it ); | 400 | id = cat.addCategory( "Document View", *it ); |
397 | } | 401 | } |
398 | d->mCat[i] = id; | 402 | d->mCat[i] = id; |
399 | } | 403 | } |
400 | d->updateCatListFromArray(); | 404 | d->updateCatListFromArray(); |
401 | } | 405 | } |
402 | } | 406 | } |
403 | } | 407 | } |
404 | mId = 0; | 408 | mId = 0; |
405 | } | 409 | } |
406 | 410 | ||
407 | AppLnk& AppLnk::operator=(const AppLnk ©) | 411 | AppLnk& AppLnk::operator=(const AppLnk ©) |
408 | { | 412 | { |
413 | if ( this == © ) return *this; | ||
409 | if ( mId ) | 414 | if ( mId ) |
410 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 415 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
411 | if ( d ) | 416 | if ( d ) |
412 | delete d; | 417 | delete d; |
413 | 418 | ||
414 | 419 | ||
415 | mName = copy.mName; | 420 | mName = copy.mName; |
416 | 421 | ||
417 | /* remove for Qtopia 3.0 -zecke */ | 422 | /* remove for Qtopia 3.0 -zecke */ |
418 | mPixmap = copy.mPixmap; | 423 | mPixmap = copy.mPixmap; |
419 | mBigPixmap = copy.mBigPixmap; | 424 | mBigPixmap = copy.mBigPixmap; |
420 | 425 | ||
421 | mExec = copy.mExec; | 426 | mExec = copy.mExec; |
422 | mType = copy.mType; | 427 | mType = copy.mType; |
423 | mRotation = copy.mRotation; | 428 | mRotation = copy.mRotation; |
424 | mComment = copy.mComment; | 429 | mComment = copy.mComment; |
425 | mFile = copy.mFile; | 430 | mFile = copy.mFile; |
426 | mLinkFile = copy.mLinkFile; | 431 | mLinkFile = copy.mLinkFile; |
427 | mIconFile = copy.mIconFile; | 432 | mIconFile = copy.mIconFile; |
428 | mMimeTypes = copy.mMimeTypes; | 433 | mMimeTypes = copy.mMimeTypes; |
429 | mMimeTypeIcons = copy.mMimeTypeIcons; | 434 | mMimeTypeIcons = copy.mMimeTypeIcons; |
430 | mId = 0; | 435 | mId = 0; |
431 | d = new AppLnkPrivate(); | 436 | d = new AppLnkPrivate(); |
432 | d->mCat = copy.d->mCat; | 437 | d->mCat = copy.d->mCat; |
433 | d->mCatList = copy.d->mCatList; | 438 | d->mCatList = copy.d->mCatList; |
434 | d->mPixmaps = copy.d->mPixmaps; | 439 | d->mPixmaps = copy.d->mPixmaps; |
435 | 440 | ||
436 | return *this; | 441 | return *this; |
437 | } | 442 | } |
438 | /*! | 443 | /*! |
439 | protected internally to share code | 444 | protected internally to share code |
440 | should I document that at all? | 445 | should I document that at all? |
441 | I don't know the TT style for that | 446 | I don't know the TT style for that |
442 | */ | 447 | */ |
443 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { | 448 | const QPixmap& AppLnk::pixmap( int pos, int size ) const { |
444 | if ( d->mPixmaps[pos].isNull() ) { | 449 | if ( d->mPixmaps[pos].isNull() ) { |
445 | AppLnk* that = (AppLnk*)this; | 450 | AppLnk* that = (AppLnk*)this; |
446 | if ( mIconFile.isEmpty() ) { | 451 | if ( mIconFile.isEmpty() ) { |
447 | MimeType mt(type()); | 452 | MimeType mt(type()); |
448 | that->d->mPixmaps[pos] = mt.pixmap(); | 453 | that->d->mPixmaps[pos] = mt.pixmap(); |
449 | if ( that->d->mPixmaps[pos].isNull() ) | 454 | if ( that->d->mPixmaps[pos].isNull() ) |
450 | that->d->mPixmaps[pos].convertFromImage( | 455 | that->d->mPixmaps[pos].convertFromImage( |
451 | Resource::loadImage("UnknownDocument") | 456 | Resource::loadImage("UnknownDocument") |
452 | .smoothScale( size, size ) ); | 457 | .smoothScale( size, size ) ); |
453 | return that->d->mPixmaps[pos]; | 458 | return that->d->mPixmaps[pos]; |
454 | } | 459 | } |
455 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); | 460 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); |
456 | if ( unscaledIcon.isNull() ) { | 461 | if ( unscaledIcon.isNull() ) { |
@@ -805,97 +810,97 @@ void AppLnk::setCategories( const QArray<int>& c ) | |||
805 | \fn QStringList AppLnk::mimeTypeIcons() const | 810 | \fn QStringList AppLnk::mimeTypeIcons() const |
806 | 811 | ||
807 | Returns the MimeTypeIcons property of the AppLnk. | 812 | Returns the MimeTypeIcons property of the AppLnk. |
808 | */ | 813 | */ |
809 | 814 | ||
810 | /*! | 815 | /*! |
811 | Attempts to ensure that the link file for this AppLnk exists, | 816 | Attempts to ensure that the link file for this AppLnk exists, |
812 | including creating any required directories. Returns TRUE if | 817 | including creating any required directories. Returns TRUE if |
813 | successful; otherwise returns FALSE. | 818 | successful; otherwise returns FALSE. |
814 | 819 | ||
815 | You should not need to use this function. | 820 | You should not need to use this function. |
816 | */ | 821 | */ |
817 | bool AppLnk::ensureLinkExists() const | 822 | bool AppLnk::ensureLinkExists() const |
818 | { | 823 | { |
819 | QString lf = linkFile(); | 824 | QString lf = linkFile(); |
820 | return prepareDirectories(lf); | 825 | return prepareDirectories(lf); |
821 | } | 826 | } |
822 | 827 | ||
823 | /*! | 828 | /*! |
824 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; | 829 | Commits the AppLnk to disk. Returns TRUE if the operation succeeded; |
825 | otherwise returns FALSE. | 830 | otherwise returns FALSE. |
826 | 831 | ||
827 | In addition, the "linkChanged(QString)" message is sent to the | 832 | In addition, the "linkChanged(QString)" message is sent to the |
828 | "QPE/System" \link qcop.html QCop\endlink channel. | 833 | "QPE/System" \link qcop.html QCop\endlink channel. |
829 | */ | 834 | */ |
830 | bool AppLnk::writeLink() const | 835 | bool AppLnk::writeLink() const |
831 | { | 836 | { |
832 | // Only re-writes settable parts | 837 | // Only re-writes settable parts |
833 | QString lf = linkFile(); | 838 | QString lf = linkFile(); |
834 | if ( !ensureLinkExists() ) | 839 | if ( !ensureLinkExists() ) |
835 | return FALSE; | 840 | return FALSE; |
836 | storeLink(); | 841 | storeLink(); |
837 | return TRUE; | 842 | return TRUE; |
838 | } | 843 | } |
839 | 844 | ||
840 | /*! | 845 | /*! |
841 | \internal | 846 | \internal |
842 | */ | 847 | */ |
843 | void AppLnk::storeLink() const | 848 | void AppLnk::storeLink() const |
844 | { | 849 | { |
845 | Config config( mLinkFile, Config::File ); | 850 | Config config( mLinkFile, Config::File ); |
846 | config.setGroup("Desktop Entry"); | 851 | config.setGroup("Desktop Entry"); |
847 | config.writeEntry("Name",mName); | 852 | config.writeEntry("Name",mName); |
848 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); | 853 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); |
849 | config.writeEntry("Type",type()); | 854 | config.writeEntry("Type",type()); |
850 | if(!rotation().isEmpty()) | 855 | if(!rotation().isEmpty()) |
851 | config.writeEntry("Rotation",rotation()); | 856 | config.writeEntry("Rotation",rotation()); |
852 | else | 857 | else |
853 | config.removeEntry("Rotation"); | 858 | config.removeEntry("Rotation"); |
854 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); | 859 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); |
855 | QString f = file(); | 860 | QString f = file(); |
856 | int i = 0; | 861 | int i = 0; |
857 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) | 862 | while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) |
858 | i++; | 863 | i++; |
859 | while ( i && f[i] != '/' ) | 864 | while ( i && f[i] != '/' ) |
860 | i--; | 865 | i--; |
861 | // simple case where in the same directory | 866 | // simple case where in the same directory |
862 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) | 867 | if ( mLinkFile.find( '/', i + 1 ) < 0 ) |
863 | f = f.mid(i+1); | 868 | f = f.mid(i+1); |
864 | // ### could do relative ie ../../otherDocs/file.doc | 869 | // ### could do relative ie ../../otherDocs/file.doc |
865 | config.writeEntry("File",f); | 870 | config.writeEntry("File",f); |
866 | config.writeEntry( "Categories", d->mCatList, ';' ); | 871 | config.writeEntry( "Categories", d->mCatList, ';' ); |
867 | 872 | ||
868 | #ifndef QT_NO_COP | 873 | #ifndef QT_NO_COP |
869 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 874 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
870 | e << mLinkFile; | 875 | e << mLinkFile; |
871 | #endif | 876 | #endif |
872 | } | 877 | } |
873 | 878 | ||
874 | /*! | 879 | /*! |
875 | Sets the property named \a key to \a value. | 880 | Sets the property named \a key to \a value. |
876 | 881 | ||
877 | \sa property() | 882 | \sa property() |
878 | */ | 883 | */ |
879 | void AppLnk::setProperty(const QString& key, const QString& value) | 884 | void AppLnk::setProperty(const QString& key, const QString& value) |
880 | { | 885 | { |
881 | if ( ensureLinkExists() ) { | 886 | if ( ensureLinkExists() ) { |
882 | Config cfg(linkFile(), Config::File); | 887 | Config cfg(linkFile(), Config::File); |
883 | cfg.writeEntry(key,value); | 888 | cfg.writeEntry(key,value); |
884 | } | 889 | } |
885 | } | 890 | } |
886 | 891 | ||
887 | /*! | 892 | /*! |
888 | Returns the property named \a key. | 893 | Returns the property named \a key. |
889 | 894 | ||
890 | \sa setProperty() | 895 | \sa setProperty() |
891 | */ | 896 | */ |
892 | QString AppLnk::property(const QString& key) const | 897 | QString AppLnk::property(const QString& key) const |
893 | { | 898 | { |
894 | QString lf = linkFile(); | 899 | QString lf = linkFile(); |
895 | if ( !QFile::exists(lf) ) | 900 | if ( !QFile::exists(lf) ) |
896 | return QString::null; | 901 | return QString::null; |
897 | Config cfg(lf, Config::File); | 902 | Config cfg(lf, Config::File); |
898 | return cfg.readEntry(key); | 903 | return cfg.readEntry(key); |
899 | } | 904 | } |
900 | 905 | ||
901 | bool AppLnk::isPreloaded() const { | 906 | bool AppLnk::isPreloaded() const { |