summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
Unidiff
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp130
1 files changed, 81 insertions, 49 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 1c1a227..80f2c62 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -920,353 +920,385 @@ QString AppLnk::property(const QString& key) const
920} 920}
921 921
922bool AppLnk::isPreloaded() const { 922bool 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
932void AppLnk::setPreloaded(bool yesNo) { 932void 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*/
950void AppLnk::removeFiles() 950void 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*/
974void AppLnk::removeLinkFile() 974void 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
984class AppLnkImagePrivate {
985public :
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
984class AppLnkSetPrivate { 1021class AppLnkSetPrivate {
985public: 1022public:
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*/
1023AppLnkSet::AppLnkSet() : 1058AppLnkSet::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*/
1039AppLnkSet::AppLnkSet( const QString &directory ) : 1074AppLnkSet::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*/
1051void AppLnkSet::detachChildren() 1086void 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*/
1067AppLnkSet::~AppLnkSet() 1102AppLnkSet::~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
1079void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) 1114void 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*/
1147void AppLnkSet::add( AppLnk *f ) 1179void 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*/
1165bool AppLnkSet::remove( AppLnk *f ) 1197bool 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*/
1181QString AppLnkSet::typeName( const QString& t ) const 1213QString 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*/
1193QPixmap AppLnkSet::typePixmap( const QString& t ) const 1225QPixmap 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*/
1205QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const 1237QPixmap 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*/
1214const AppLnk *AppLnkSet::find( int id ) const 1246const 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*/
1230const AppLnk *AppLnkSet::findExec( const QString& exec ) const 1262const 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*/
1259DocLnkSet::DocLnkSet() 1291DocLnkSet::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.