summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
authorzecke <zecke>2004-06-20 19:03:56 (UTC)
committer zecke <zecke>2004-06-20 19:03:56 (UTC)
commit44d69b04b5257592639d2a494c448202c86978c2 (patch) (unidiff)
tree9d776e08f6efa53abc6e2658c94b9e0e18324692 /library/applnk.cpp
parent2055cb9e96b27f95720240a2035ade27cb7bc098 (diff)
downloadopie-44d69b04b5257592639d2a494c448202c86978c2.zip
opie-44d69b04b5257592639d2a494c448202c86978c2.tar.gz
opie-44d69b04b5257592639d2a494c448202c86978c2.tar.bz2
Use A higher prime number in AppLnk
Somehow the Launcher triggers issues with libqpe and MimeType. Due the mix of calling MimeType::clear, MimeType type(doclnk.linkFile()), MimeType::clear the registration of Application was cleared and not reentered due the inner static variable in MimeType::init which was set. Now make sure that if we clear that we will reenter the Application in all cases!
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 5f7da8e..e9d519e 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -895,602 +895,602 @@ void AppLnk::storeLink() const
895 Sets the property named \a key to \a value. 895 Sets the property named \a key to \a value.
896 896
897 \sa property() 897 \sa property()
898*/ 898*/
899void AppLnk::setProperty(const QString& key, const QString& value) 899void AppLnk::setProperty(const QString& key, const QString& value)
900{ 900{
901 if ( ensureLinkExists() ) { 901 if ( ensureLinkExists() ) {
902 Config cfg(linkFile(), Config::File); 902 Config cfg(linkFile(), Config::File);
903 cfg.writeEntry(key,value); 903 cfg.writeEntry(key,value);
904 } 904 }
905} 905}
906 906
907/*! 907/*!
908 Returns the property named \a key. 908 Returns the property named \a key.
909 909
910 \sa setProperty() 910 \sa setProperty()
911*/ 911*/
912QString AppLnk::property(const QString& key) const 912QString AppLnk::property(const QString& key) const
913{ 913{
914 QString lf = linkFile(); 914 QString lf = linkFile();
915 if ( !QFile::exists(lf) ) 915 if ( !QFile::exists(lf) )
916 return QString::null; 916 return QString::null;
917 Config cfg(lf, Config::File); 917 Config cfg(lf, Config::File);
918 return cfg.readEntry(key); 918 return cfg.readEntry(key);
919} 919}
920 920
921bool AppLnk::isPreloaded() const { 921bool AppLnk::isPreloaded() const {
922 // Preload information is stored in the Launcher config in v1.5. 922 // Preload information is stored in the Launcher config in v1.5.
923 Config cfg("Launcher"); 923 Config cfg("Launcher");
924 cfg.setGroup("Preload"); 924 cfg.setGroup("Preload");
925 QStringList apps = cfg.readListEntry("Apps",','); 925 QStringList apps = cfg.readListEntry("Apps",',');
926 if (apps.contains(exec())) 926 if (apps.contains(exec()))
927 return true; 927 return true;
928 return false; 928 return false;
929} 929}
930 930
931void AppLnk::setPreloaded(bool yesNo) { 931void AppLnk::setPreloaded(bool yesNo) {
932 // Preload information is stored in the Launcher config in v1.5. 932 // Preload information is stored in the Launcher config in v1.5.
933 Config cfg("Launcher"); 933 Config cfg("Launcher");
934 cfg.setGroup("Preload"); 934 cfg.setGroup("Preload");
935 QStringList apps = cfg.readListEntry("Apps", ','); 935 QStringList apps = cfg.readListEntry("Apps", ',');
936 if (apps.contains(exec()) && !yesNo) 936 if (apps.contains(exec()) && !yesNo)
937 apps.remove(exec()); 937 apps.remove(exec());
938 else if (yesNo && !apps.contains(exec())) 938 else if (yesNo && !apps.contains(exec()))
939 apps.append(exec()); 939 apps.append(exec());
940 cfg.writeEntry("Apps", apps, ','); 940 cfg.writeEntry("Apps", apps, ',');
941} 941}
942 942
943 943
944/*! 944/*!
945 Deletes both the linkFile() and the file() associated with this AppLnk. 945 Deletes both the linkFile() and the file() associated with this AppLnk.
946 946
947 \sa removeLinkFile() 947 \sa removeLinkFile()
948*/ 948*/
949void AppLnk::removeFiles() 949void AppLnk::removeFiles()
950{ 950{
951 bool valid = isValid(); 951 bool valid = isValid();
952 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 952 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
953 if ( QFile::remove(file()) ) { 953 if ( QFile::remove(file()) ) {
954#ifndef QT_NO_COP 954#ifndef QT_NO_COP
955 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 955 QCopEnvelope e("QPE/System", "linkChanged(QString)");
956 if ( linkFileKnown() ) 956 if ( linkFileKnown() )
957 e << linkFile(); 957 e << linkFile();
958 else 958 else
959 e << file(); 959 e << file();
960#endif 960#endif
961 } else if ( valid ) { 961 } else if ( valid ) {
962 // restore link 962 // restore link
963 writeLink(); 963 writeLink();
964 } 964 }
965 } 965 }
966} 966}
967 967
968/*! 968/*!
969 Deletes the linkFile(), leaving any file() untouched. 969 Deletes the linkFile(), leaving any file() untouched.
970 970
971 \sa removeFiles() 971 \sa removeFiles()
972*/ 972*/
973void AppLnk::removeLinkFile() 973void AppLnk::removeLinkFile()
974{ 974{
975 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 975 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
976#ifndef QT_NO_COP 976#ifndef QT_NO_COP
977 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 977 QCopEnvelope e("QPE/System", "linkChanged(QString)");
978 e << linkFile(); 978 e << linkFile();
979#endif 979#endif
980 } 980 }
981} 981}
982 982
983class AppLnkSetPrivate { 983class AppLnkSetPrivate {
984public: 984public:
985 AppLnkSetPrivate() 985 AppLnkSetPrivate()
986 { 986 {
987 typPix.setAutoDelete(TRUE); 987 typPix.setAutoDelete(TRUE);
988 typPixBig.setAutoDelete(TRUE); 988 typPixBig.setAutoDelete(TRUE);
989 typName.setAutoDelete(TRUE); 989 typName.setAutoDelete(TRUE);
990 } 990 }
991 991
992 QDict<QPixmap> typPix; 992 QDict<QPixmap> typPix;
993 QDict<QPixmap> typPixBig; 993 QDict<QPixmap> typPixBig;
994 QDict<QString> typName; 994 QDict<QString> typName;
995}; 995};
996 996
997/*! 997/*!
998 \class AppLnkSet applnk.h 998 \class AppLnkSet applnk.h
999 \brief The AppLnkSet class is a set of AppLnk objects. 999 \brief The AppLnkSet class is a set of AppLnk objects.
1000*/ 1000*/
1001 1001
1002/*! 1002/*!
1003 \fn QStringList AppLnkSet::types() const 1003 \fn QStringList AppLnkSet::types() const
1004 1004
1005 Returns the list of \link applnk.html#Types types\endlink in the set. 1005 Returns the list of \link applnk.html#Types types\endlink in the set.
1006 1006
1007 For applications, games and settings the type is \c Application; 1007 For applications, games and settings the type is \c Application;
1008 for documents the type is the document's MIME type. 1008 for documents the type is the document's MIME type.
1009 1009
1010 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() 1010 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
1011*/ 1011*/
1012 1012
1013/*! 1013/*!
1014 \fn const QList<AppLnk>& AppLnkSet::children() const 1014 \fn const QList<AppLnk>& AppLnkSet::children() const
1015 1015
1016 Returns the members of the set. 1016 Returns the members of the set.
1017*/ 1017*/
1018 1018
1019/*! 1019/*!
1020 Constructs an empty AppLnkSet. 1020 Constructs an empty AppLnkSet.
1021*/ 1021*/
1022AppLnkSet::AppLnkSet() : 1022AppLnkSet::AppLnkSet() :
1023 d(new AppLnkSetPrivate) 1023 d(new AppLnkSetPrivate)
1024{ 1024{
1025} 1025}
1026 1026
1027/*! 1027/*!
1028 Constructs an AppLnkSet that contains AppLnk objects representing 1028 Constructs an AppLnkSet that contains AppLnk objects representing
1029 all the files in the given \a directory (and any subdirectories 1029 all the files in the given \a directory (and any subdirectories
1030 recursively). 1030 recursively).
1031 1031
1032 \omit 1032 \omit
1033 The directories may contain ".directory" files which override 1033 The directories may contain ".directory" files which override
1034 any AppLnk::type() values for AppLnk objects found in the directory. 1034 any AppLnk::type() values for AppLnk objects found in the directory.
1035 This allows simple localization of application types. 1035 This allows simple localization of application types.
1036 \endomit 1036 \endomit
1037*/ 1037*/
1038AppLnkSet::AppLnkSet( const QString &directory ) : 1038AppLnkSet::AppLnkSet( const QString &directory ) :
1039 d(new AppLnkSetPrivate) 1039 d(new AppLnkSetPrivate)
1040{ 1040{
1041 QDir dir( directory ); 1041 QDir dir( directory );
1042 mFile = directory; 1042 mFile = directory;
1043 findChildren(directory,QString::null,QString::null); 1043 findChildren(directory,QString::null,QString::null);
1044} 1044}
1045 1045
1046/*! 1046/*!
1047 Detaches all AppLnk objects from the set. The set become empty and 1047 Detaches all AppLnk objects from the set. The set become empty and
1048 the caller becomes responsible for deleting the AppLnk objects. 1048 the caller becomes responsible for deleting the AppLnk objects.
1049*/ 1049*/
1050void AppLnkSet::detachChildren() 1050void AppLnkSet::detachChildren()
1051{ 1051{
1052 QListIterator<AppLnk> it( mApps ); 1052 QListIterator<AppLnk> it( mApps );
1053 for ( ; it.current(); ) { 1053 for ( ; it.current(); ) {
1054 AppLnk* a = *it; 1054 AppLnk* a = *it;
1055 ++it; 1055 ++it;
1056 a->mId = 0; 1056 a->mId = 0;
1057 } 1057 }
1058 mApps.clear(); 1058 mApps.clear();
1059} 1059}
1060 1060
1061/*! 1061/*!
1062 Destroys the set, deleting all the AppLnk objects it contains. 1062 Destroys the set, deleting all the AppLnk objects it contains.
1063 1063
1064 \sa detachChildren() 1064 \sa detachChildren()
1065*/ 1065*/
1066AppLnkSet::~AppLnkSet() 1066AppLnkSet::~AppLnkSet()
1067{ 1067{
1068 QListIterator<AppLnk> it( mApps ); 1068 QListIterator<AppLnk> it( mApps );
1069 for ( ; it.current(); ) { 1069 for ( ; it.current(); ) {
1070 AppLnk* a = *it; 1070 AppLnk* a = *it;
1071 ++it; 1071 ++it;
1072 a->mId = 0; 1072 a->mId = 0;
1073 delete a; 1073 delete a;
1074 } 1074 }
1075 delete d; 1075 delete d;
1076} 1076}
1077 1077
1078void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) 1078void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
1079{ 1079{
1080 depth++; 1080 depth++;
1081 if ( depth > 10 ) 1081 if ( depth > 10 )
1082 return; 1082 return;
1083 1083
1084 QDir dir( dr ); 1084 QDir dir( dr );
1085 QString typNameLocal = typName; 1085 QString typNameLocal = typName;
1086 1086
1087 if ( dir.exists( ".directory" ) ) { 1087 if ( dir.exists( ".directory" ) ) {
1088 Config config( dr + "/.directory", Config::File ); 1088 Config config( dr + "/.directory", Config::File );
1089 config.setGroup( "Desktop Entry" ); 1089 config.setGroup( "Desktop Entry" );
1090 typNameLocal = config.readEntry( "Name", typNameLocal ); 1090 typNameLocal = config.readEntry( "Name", typNameLocal );
1091 if ( !typ.isEmpty() ) { 1091 if ( !typ.isEmpty() ) {
1092 QString iconFile = config.readEntry( "Icon", "AppsIcon" ); 1092 QString iconFile = config.readEntry( "Icon", "AppsIcon" );
1093 QImage unscaledIcon = Resource::loadImage( iconFile ); 1093 QImage unscaledIcon = Resource::loadImage( iconFile );
1094 QPixmap pm, bpm; 1094 QPixmap pm, bpm;
1095 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 1095 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
1096 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 1096 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
1097 d->typPix.insert(typ, new QPixmap(pm)); 1097 d->typPix.insert(typ, new QPixmap(pm));
1098 d->typPixBig.insert(typ, new QPixmap(bpm)); 1098 d->typPixBig.insert(typ, new QPixmap(bpm));
1099 d->typName.insert(typ, new QString(typNameLocal)); 1099 d->typName.insert(typ, new QString(typNameLocal));
1100 } 1100 }
1101 } 1101 }
1102 1102
1103 const QFileInfoList *list = dir.entryInfoList(); 1103 const QFileInfoList *list = dir.entryInfoList();
1104 if ( list ) { 1104 if ( list ) {
1105 QFileInfo* fi; 1105 QFileInfo* fi;
1106 bool cadded=FALSE; 1106 bool cadded=FALSE;
1107 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1107 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1108 QString bn = fi->fileName(); 1108 QString bn = fi->fileName();
1109// qDebug("findChildren "+bn); 1109// qDebug("findChildren "+bn);
1110 if ( bn[0] != '.' && bn != "CVS" ) { 1110 if ( bn[0] != '.' && bn != "CVS" ) {
1111 if ( fi->isDir() ) { 1111 if ( fi->isDir() ) {
1112 QString c = typ.isNull() ? bn : typ+"/"+bn; 1112 QString c = typ.isNull() ? bn : typ+"/"+bn;
1113 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; 1113 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
1114 findChildren(fi->filePath(), c, d, depth ); 1114 findChildren(fi->filePath(), c, d, depth );
1115 } else { 1115 } else {
1116 if ( fi->extension(FALSE) == "desktop" ) { 1116 if ( fi->extension(FALSE) == "desktop" ) {
1117 AppLnk* app = new AppLnk( fi->filePath() ); 1117 AppLnk* app = new AppLnk( fi->filePath() );
1118#ifdef QT_NO_QWS_MULTIPROCESS 1118#ifdef QT_NO_QWS_MULTIPROCESS
1119 if ( !Global::isBuiltinCommand( app->exec() ) ) 1119 if ( !Global::isBuiltinCommand( app->exec() ) )
1120 delete app; 1120 delete app;
1121 else 1121 else
1122#endif 1122#endif
1123 { 1123 {
1124 if ( !typ.isEmpty() ) { 1124 if ( !typ.isEmpty() ) {
1125 if ( !cadded ) { 1125 if ( !cadded ) {
1126 typs.append(typ); 1126 typs.append(typ);
1127 cadded = TRUE; 1127 cadded = TRUE;
1128 } 1128 }
1129 app->setType(typ); 1129 app->setType(typ);
1130 } 1130 }
1131 add(app); 1131 add(app);
1132 } 1132 }
1133 } 1133 }
1134 } 1134 }
1135 } 1135 }
1136 } 1136 }
1137 } 1137 }
1138} 1138}
1139 1139
1140/*! 1140/*!
1141 Adds AppLnk \a f to the set. The set takes responsibility for 1141 Adds AppLnk \a f to the set. The set takes responsibility for
1142 deleting \a f. 1142 deleting \a f.
1143 1143
1144 \sa remove() 1144 \sa remove()
1145*/ 1145*/
1146void AppLnkSet::add( AppLnk *f ) 1146void AppLnkSet::add( AppLnk *f )
1147{ 1147{
1148 if ( f->mId == 0 ) { 1148 if ( f->mId == 0 ) {
1149 AppLnk::lastId++; 1149 AppLnk::lastId++;
1150 f->mId = AppLnk::lastId; 1150 f->mId = AppLnk::lastId;
1151 mApps.append( f ); 1151 mApps.append( f );
1152 } else { 1152 } else {
1153 qWarning("Attempt to add an AppLnk twice"); 1153 qWarning("Attempt to add an AppLnk twice");
1154 } 1154 }
1155} 1155}
1156 1156
1157/*! 1157/*!
1158 Removes AppLnk \a f to the set. The caller becomes responsible for 1158 Removes AppLnk \a f to the set. The caller becomes responsible for
1159 deleting \a f. Returns TRUE if \a f was in the set; otherwise 1159 deleting \a f. Returns TRUE if \a f was in the set; otherwise
1160 returns FALSE. 1160 returns FALSE.
1161 1161
1162 \sa add() 1162 \sa add()
1163*/ 1163*/
1164bool AppLnkSet::remove( AppLnk *f ) 1164bool AppLnkSet::remove( AppLnk *f )
1165{ 1165{
1166 if ( mApps.remove( f ) ) { 1166 if ( mApps.remove( f ) ) {
1167 f->mId = 0; 1167 f->mId = 0;
1168 return TRUE; 1168 return TRUE;
1169 } 1169 }
1170 return FALSE; 1170 return FALSE;
1171} 1171}
1172 1172
1173 1173
1174/*! 1174/*!
1175 Returns the localized name for type \a t. 1175 Returns the localized name for type \a t.
1176 1176
1177 For applications, games and settings the type is \c Application; 1177 For applications, games and settings the type is \c Application;
1178 for documents the type is the document's MIME type. 1178 for documents the type is the document's MIME type.
1179*/ 1179*/
1180QString AppLnkSet::typeName( const QString& t ) const 1180QString AppLnkSet::typeName( const QString& t ) const
1181{ 1181{
1182 QString *st = d->typName.find(t); 1182 QString *st = d->typName.find(t);
1183 return st ? *st : QString::null; 1183 return st ? *st : QString::null;
1184} 1184}
1185 1185
1186/*! 1186/*!
1187 Returns the small pixmap associated with type \a t. 1187 Returns the small pixmap associated with type \a t.
1188 1188
1189 For applications, games and settings the type is \c Application; 1189 For applications, games and settings the type is \c Application;
1190 for documents the type is the document's MIME type. 1190 for documents the type is the document's MIME type.
1191*/ 1191*/
1192QPixmap AppLnkSet::typePixmap( const QString& t ) const 1192QPixmap AppLnkSet::typePixmap( const QString& t ) const
1193{ 1193{
1194 QPixmap *pm = d->typPix.find(t); 1194 QPixmap *pm = d->typPix.find(t);
1195 return pm ? *pm : QPixmap(); 1195 return pm ? *pm : QPixmap();
1196} 1196}
1197 1197
1198/*! 1198/*!
1199 Returns the large pixmap associated with type \a t. 1199 Returns the large pixmap associated with type \a t.
1200 1200
1201 For applications, games and settings the type is \c Application; 1201 For applications, games and settings the type is \c Application;
1202 for documents the type is the document's MIME type. 1202 for documents the type is the document's MIME type.
1203*/ 1203*/
1204QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const 1204QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
1205{ 1205{
1206 QPixmap *pm = d->typPixBig.find(t); 1206 QPixmap *pm = d->typPixBig.find(t);
1207 return pm ? *pm : QPixmap(); 1207 return pm ? *pm : QPixmap();
1208} 1208}
1209 1209
1210/*! 1210/*!
1211 Returns the AppLnk with the given \a id. 1211 Returns the AppLnk with the given \a id.
1212*/ 1212*/
1213const AppLnk *AppLnkSet::find( int id ) const 1213const AppLnk *AppLnkSet::find( int id ) const
1214{ 1214{
1215 QListIterator<AppLnk> it( children() ); 1215 QListIterator<AppLnk> it( children() );
1216 1216
1217 for ( ; it.current(); ++it ) { 1217 for ( ; it.current(); ++it ) {
1218 const AppLnk *app = it.current(); 1218 const AppLnk *app = it.current();
1219 if ( app->id() == id ) 1219 if ( app->id() == id )
1220 return app; 1220 return app;
1221 } 1221 }
1222 1222
1223 return 0; 1223 return 0;
1224} 1224}
1225 1225
1226/*! 1226/*!
1227 Returns the AppLnk with the given \a exec attribute. 1227 Returns the AppLnk with the given \a exec attribute.
1228*/ 1228*/
1229const AppLnk *AppLnkSet::findExec( const QString& exec ) const 1229const AppLnk *AppLnkSet::findExec( const QString& exec ) const
1230{ 1230{
1231 QListIterator<AppLnk> it( children() ); 1231 QListIterator<AppLnk> it( children() );
1232 1232
1233 for ( ; it.current(); ++it ) { 1233 for ( ; it.current(); ++it ) {
1234 const AppLnk *app = it.current(); 1234 const AppLnk *app = it.current();
1235 if ( app->exec() == exec ) 1235 if ( app->exec() == exec )
1236 return app; 1236 return app;
1237 } 1237 }
1238 1238
1239 return 0; 1239 return 0;
1240} 1240}
1241 1241
1242/*! 1242/*!
1243 \class DocLnkSet applnk.h 1243 \class DocLnkSet applnk.h
1244 \brief The DocLnkSet class is a set of DocLnk objects. 1244 \brief The DocLnkSet class is a set of DocLnk objects.
1245*/ 1245*/
1246 1246
1247/*! 1247/*!
1248 \fn const QList<DocLnk>& DocLnkSet::children() const 1248 \fn const QList<DocLnk>& DocLnkSet::children() const
1249 1249
1250 Returns the members of the set. 1250 Returns the members of the set.
1251*/ 1251*/
1252 1252
1253/*! 1253/*!
1254 Constructs an empty DocLnkSet. 1254 Constructs an empty DocLnkSet.
1255 1255
1256 \sa appendFrom() 1256 \sa appendFrom()
1257*/ 1257*/
1258DocLnkSet::DocLnkSet() 1258DocLnkSet::DocLnkSet()
1259{ 1259{
1260} 1260}
1261 1261
1262/*! 1262/*!
1263 Constructs a DocLnkSet that contains DocLnk objects representing all 1263 Constructs a DocLnkSet that contains DocLnk objects representing all
1264 the files in the \a directory (and any subdirectories, recursively). 1264 the files in the \a directory (and any subdirectories, recursively).
1265 1265
1266 If \a mimefilter is not null, 1266 If \a mimefilter is not null,
1267 only documents with a MIME type matching \a mimefilter are selected. 1267 only documents with a MIME type matching \a mimefilter are selected.
1268 The value may contain multiple wild-card patterns separated by ";", 1268 The value may contain multiple wild-card patterns separated by ";",
1269 such as \c{*o/mpeg;audio/x-wav}. 1269 such as \c{*o/mpeg;audio/x-wav}.
1270 1270
1271 See also \link applnk.html#files-and-links Files and Links\endlink. 1271 See also \link applnk.html#files-and-links Files and Links\endlink.
1272 1272
1273*/ 1273*/
1274DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : 1274DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
1275 AppLnkSet() 1275 AppLnkSet()
1276{ 1276{
1277 QDir dir( directory ); 1277 QDir dir( directory );
1278 mFile = dir.dirName(); 1278 mFile = dir.dirName();
1279 QDict<void> reference; 1279 QDict<void> reference(1021);
1280 1280
1281 QStringList subFilter = QStringList::split(";", mimefilter); 1281 QStringList subFilter = QStringList::split(";", mimefilter);
1282 QValueList<QRegExp> mimeFilters; 1282 QValueList<QRegExp> mimeFilters;
1283 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) 1283 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
1284 mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 1284 mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
1285 1285
1286 findChildren(directory, mimeFilters, reference); 1286 findChildren(directory, mimeFilters, reference);
1287 1287
1288 const QList<DocLnk> &list = children(); 1288 const QList<DocLnk> &list = children();
1289 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 1289 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
1290 reference.remove( (*it)->file() ); 1290 reference.remove( (*it)->file() );
1291 } 1291 }
1292 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { 1292 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
1293 if ( dit.current() == (void*)2 ) { 1293 if ( dit.current() == (void*)2 ) {
1294 // Unreferenced, make an unwritten link 1294 // Unreferenced, make an unwritten link
1295 DocLnk* dl = new DocLnk; 1295 DocLnk* dl = new DocLnk;
1296 QFileInfo fi( dit.currentKey() ); 1296 QFileInfo fi( dit.currentKey() );
1297 dl->setFile(fi.filePath()); 1297 dl->setFile(fi.filePath());
1298 dl->setName(fi.baseName()); 1298 dl->setName(fi.baseName());
1299 // #### default to current path? 1299 // #### default to current path?
1300 // dl->setCategories( ... ); 1300 // dl->setCategories( ... );
1301 bool match = mimefilter.isNull(); 1301 bool match = mimefilter.isNull();
1302 if ( !match ) 1302 if ( !match )
1303 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) 1303 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
1304 if ( (*it).match(dl->type()) >= 0 ) 1304 if ( (*it).match(dl->type()) >= 0 )
1305 match = TRUE; 1305 match = TRUE;
1306 if ( match /* && dl->type() != "application/octet-stream" */ 1306 if ( match /* && dl->type() != "application/octet-stream" */
1307 && !!dl->exec() ) 1307 && !!dl->exec() )
1308 add(dl); 1308 add(dl);
1309 else 1309 else
1310 delete dl; 1310 delete dl;
1311 } 1311 }
1312 } 1312 }
1313} 1313}
1314 1314
1315// other becomes empty 1315// other becomes empty
1316/*! 1316/*!
1317 Transfers all DocLnk objects from \a other to this set. \a other becomes 1317 Transfers all DocLnk objects from \a other to this set. \a other becomes
1318 empty. 1318 empty.
1319*/ 1319*/
1320void DocLnkSet::appendFrom( DocLnkSet& other ) 1320void DocLnkSet::appendFrom( DocLnkSet& other )
1321{ 1321{
1322 if ( &other == this ) 1322 if ( &other == this )
1323 return; 1323 return;
1324 QListIterator<AppLnk> it( other.mApps ); 1324 QListIterator<AppLnk> it( other.mApps );
1325 for ( ; it.current(); ) { 1325 for ( ; it.current(); ) {
1326 mApps.append(*it); 1326 mApps.append(*it);
1327 ++it; 1327 ++it;
1328 } 1328 }
1329 other.mApps.clear(); 1329 other.mApps.clear();
1330} 1330}
1331 1331
1332void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) 1332void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
1333{ 1333{
1334 depth++; 1334 depth++;
1335 if ( depth > 10 ) 1335 if ( depth > 10 )
1336 return; 1336 return;
1337 1337
1338 QDir dir( dr ); 1338 QDir dir( dr );
1339 1339
1340 /* Opie got a different approach 1340 /* Opie got a different approach
1341 * I guess it's geek vs. consumer 1341 * I guess it's geek vs. consumer
1342 * in this case to be discussed 1342 * in this case to be discussed
1343 */ 1343 */
1344 if ( dir.exists( ".Qtopia-ignore" ) ) 1344 if ( dir.exists( ".Qtopia-ignore" ) )
1345 return; 1345 return;
1346 1346
1347 const QFileInfoList *list = dir.entryInfoList(); 1347 const QFileInfoList *list = dir.entryInfoList();
1348 if ( list ) { 1348 if ( list ) {
1349 QFileInfo* fi; 1349 QFileInfo* fi;
1350 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1350 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1351 QString bn = fi->fileName(); 1351 QString bn = fi->fileName();
1352 if ( bn[0] != '.' ) { 1352 if ( bn[0] != '.' ) {
1353 if ( fi->isDir() ) { 1353 if ( fi->isDir() ) {
1354 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) 1354 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
1355 findChildren(fi->filePath(), mimeFilters, reference, depth); 1355 findChildren(fi->filePath(), mimeFilters, reference, depth);
1356 } else { 1356 } else {
1357 if ( fi->extension(FALSE) == "desktop" ) { 1357 if ( fi->extension(FALSE) == "desktop" ) {
1358 DocLnk* dl = new DocLnk( fi->filePath() ); 1358 DocLnk* dl = new DocLnk( fi->filePath() );
1359 QFileInfo fi2(dl->file()); 1359 QFileInfo fi2(dl->file());
1360 bool match = FALSE; 1360 bool match = FALSE;
1361 if ( !fi2.exists() ) { 1361 if ( !fi2.exists() ) {
1362 dir.remove( dl->file() ); 1362 dir.remove( dl->file() );
1363 } 1363 }
1364 if ( mimeFilters.count() == 0 ) { 1364 if ( mimeFilters.count() == 0 ) {
1365 add( dl ); 1365 add( dl );
1366 match = TRUE; 1366 match = TRUE;
1367 } else { 1367 } else {
1368 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { 1368 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
1369 if ( (*it).match(dl->type()) >= 0 ) { 1369 if ( (*it).match(dl->type()) >= 0 ) {
1370 add(dl); 1370 add(dl);
1371 match = TRUE; 1371 match = TRUE;
1372 } 1372 }
1373 } 1373 }
1374 } 1374 }
1375 if ( !match ) 1375 if ( !match )
1376 delete dl; 1376 delete dl;
1377 } else { 1377 } else {
1378 if ( !reference.find(fi->fileName()) ) 1378 if ( !reference.find(fi->fileName()) )
1379 reference.insert(fi->filePath(), (void*)2); 1379 reference.insert(fi->filePath(), (void*)2);
1380 } 1380 }
1381 } 1381 }
1382 } 1382 }
1383 } 1383 }
1384 } 1384 }
1385} 1385}
1386 1386
1387/*! 1387/*!
1388 \class DocLnk applnk.h 1388 \class DocLnk applnk.h
1389 \brief The DocLnk class represents loaded document references. 1389 \brief The DocLnk class represents loaded document references.
1390*/ 1390*/
1391 1391
1392/*! 1392/*!
1393 \fn DocLnk::DocLnk( const DocLnk &o ) 1393 \fn DocLnk::DocLnk( const DocLnk &o )
1394 1394
1395 Copies \a o. 1395 Copies \a o.
1396*/ 1396*/
1397 1397
1398/*! 1398/*!
1399 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1399 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1400 \a file for other files. 1400 \a file for other files.
1401*/ 1401*/
1402DocLnk::DocLnk( const QString &file ) : 1402DocLnk::DocLnk( const QString &file ) :
1403 AppLnk(file) 1403 AppLnk(file)
1404{ 1404{
1405 init(file); 1405 init(file);
1406} 1406}
1407 1407
1408/*! 1408/*!
1409 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1409 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1410 \a file for other files. If \a may_be_desktopfile is TRUE, then an 1410 \a file for other files. If \a may_be_desktopfile is TRUE, then an
1411 attempt is made to read \a file as a .desktop file; if that fails it 1411 attempt is made to read \a file as a .desktop file; if that fails it
1412 is read as a normal file. 1412 is read as a normal file.
1413*/ 1413*/
1414DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : 1414DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) :
1415 AppLnk(may_be_desktopfile ? file : QString::null) 1415 AppLnk(may_be_desktopfile ? file : QString::null)
1416{ 1416{
1417 init(file); 1417 init(file);
1418} 1418}
1419 1419
1420void DocLnk::init(const QString &file) 1420void DocLnk::init(const QString &file)
1421{ 1421{
1422 if ( isValid() ) { 1422 if ( isValid() ) {
1423#ifndef FORCED_DIR_STRUCTURE_WAY 1423#ifndef FORCED_DIR_STRUCTURE_WAY
1424 if ( mType.isNull() ) 1424 if ( mType.isNull() )
1425 // try to infer it 1425 // try to infer it
1426#endif 1426#endif
1427 { 1427 {
1428 int s0 = file.findRev('/'); 1428 int s0 = file.findRev('/');
1429 if ( s0 > 0 ) { 1429 if ( s0 > 0 ) {
1430 int s1 = file.findRev('/',s0-1); 1430 int s1 = file.findRev('/',s0-1);
1431 if ( s1 > 0 ) { 1431 if ( s1 > 0 ) {
1432 int s2 = file.findRev('/',s1-1); 1432 int s2 = file.findRev('/',s1-1);
1433 if ( s2 > 0 ) { 1433 if ( s2 > 0 ) {
1434 mType = file.mid(s2+1,s0-s2-1); 1434 mType = file.mid(s2+1,s0-s2-1);
1435 } 1435 }
1436 } 1436 }
1437 } 1437 }
1438 } 1438 }
1439 } else if ( QFile::exists(file) ) { 1439 } else if ( QFile::exists(file) ) {
1440 QString n = file; 1440 QString n = file;
1441 n.replace(QRegExp(".*/"),""); 1441 n.replace(QRegExp(".*/"),"");
1442 n.replace(QRegExp("\\..*"),""); 1442 n.replace(QRegExp("\\..*"),"");
1443 setName( n ); 1443 setName( n );
1444 setFile( file ); 1444 setFile( file );
1445 } 1445 }
1446 MimeType mt(mType); 1446 MimeType mt(mType);
1447 if( mt.application() ) 1447 if( mt.application() )
1448 mExec = mt.application()->exec(); 1448 mExec = mt.application()->exec();
1449} 1449}
1450 1450
1451/*! 1451/*!
1452 Constructs an invalid DocLnk. 1452 Constructs an invalid DocLnk.
1453*/ 1453*/
1454DocLnk::DocLnk() 1454DocLnk::DocLnk()
1455{ 1455{
1456} 1456}
1457 1457
1458/*! 1458/*!
1459 Destroys the DocLnk. Just like AppLnk objects, a run-time error 1459 Destroys the DocLnk. Just like AppLnk objects, a run-time error
1460 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). 1460 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet).
1461*/ 1461*/
1462DocLnk::~DocLnk() 1462DocLnk::~DocLnk()
1463{ 1463{
1464} 1464}
1465 1465
1466/*! 1466/*!
1467 \reimp 1467 \reimp
1468*/ 1468*/
1469QString DocLnk::exec() const 1469QString DocLnk::exec() const
1470{ 1470{
1471 MimeType mt(type()); 1471 MimeType mt(type());
1472 const AppLnk* app = mt.application(); 1472 const AppLnk* app = mt.application();
1473 if ( app ) 1473 if ( app )
1474 return app->exec(); 1474 return app->exec();
1475 else 1475 else
1476 return QString::null; 1476 return QString::null;
1477} 1477}
1478 1478
1479/*! 1479/*!
1480 \reimp 1480 \reimp
1481*/ 1481*/
1482void DocLnk::invoke(const QStringList& args) const 1482void DocLnk::invoke(const QStringList& args) const
1483{ 1483{
1484 MimeType mt(type()); 1484 MimeType mt(type());
1485 const AppLnk* app = mt.application(); 1485 const AppLnk* app = mt.application();
1486 if ( app ) { 1486 if ( app ) {
1487 QStringList a = args; 1487 QStringList a = args;
1488 if ( linkFileKnown() && QFile::exists( linkFile() ) ) 1488 if ( linkFileKnown() && QFile::exists( linkFile() ) )
1489 a.append(linkFile()); 1489 a.append(linkFile());
1490 else 1490 else
1491 a.append(file()); 1491 a.append(file());
1492 app->execute(a); 1492 app->execute(a);
1493 } 1493 }
1494} 1494}
1495 1495
1496 1496