summaryrefslogtreecommitdiff
authorsandman <sandman>2002-09-24 23:36:58 (UTC)
committer sandman <sandman>2002-09-24 23:36:58 (UTC)
commit6398fb2352fd4b53a023ec2884b786b08af8bd9f (patch) (unidiff)
tree7d65dd2faebf08af764a8497f825c9e8b500acc0
parentcfb3613fcf068f071b353b26f778fc9b41ac8a38 (diff)
downloadopie-6398fb2352fd4b53a023ec2884b786b08af8bd9f.zip
opie-6398fb2352fd4b53a023ec2884b786b08af8bd9f.tar.gz
opie-6398fb2352fd4b53a023ec2884b786b08af8bd9f.tar.bz2
Fixed loading of file extensions from mime.types (only the first ext was
loaded)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/mimetype.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/library/mimetype.cpp b/library/mimetype.cpp
index e2e0dab..92fe5e6 100644
--- a/library/mimetype.cpp
+++ b/library/mimetype.cpp
@@ -198,104 +198,102 @@ void MimeType::registerApp( const AppLnk& lnk )
198 if ( !cur ) { 198 if ( !cur ) {
199 cur = new MimeTypeData( *it ); 199 cur = new MimeTypeData( *it );
200 data().insert( *it, cur ); 200 data().insert( *it, cur );
201 cur->apps.append(l); 201 cur->apps.append(l);
202 } else if ( cur->apps.count() ) { 202 } else if ( cur->apps.count() ) {
203 Config binding(serviceBinding("Open/"+*it)); 203 Config binding(serviceBinding("Open/"+*it));
204 binding.setGroup("Service"); 204 binding.setGroup("Service");
205 QString def = binding.readEntry("default"); 205 QString def = binding.readEntry("default");
206 if ( l->exec() == def ) 206 if ( l->exec() == def )
207 cur->apps.prepend(l); 207 cur->apps.prepend(l);
208 else 208 else
209 cur->apps.append(l); 209 cur->apps.append(l);
210 } else { 210 } else {
211 cur->apps.append(l); 211 cur->apps.append(l);
212 } 212 }
213 } 213 }
214} 214}
215 215
216void MimeType::clear() 216void MimeType::clear()
217{ 217{
218 delete d; 218 delete d;
219 d = 0; 219 d = 0;
220} 220}
221 221
222void MimeType::loadExtensions() 222void MimeType::loadExtensions()
223{ 223{
224 if ( !typeFor ) { 224 if ( !typeFor ) {
225 extFor = new QMap<QString,QStringList>; 225 extFor = new QMap<QString,QStringList>;
226 typeFor = new QMap<QString,QString>; 226 typeFor = new QMap<QString,QString>;
227 loadExtensions("/etc/mime.types"); 227 loadExtensions("/etc/mime.types");
228 loadExtensions(QPEApplication::qpeDir()+"etc/mime.types"); 228 loadExtensions(QPEApplication::qpeDir()+"etc/mime.types");
229 } 229 }
230} 230}
231 231
232void MimeType::loadExtensions(const QString& filename) 232void MimeType::loadExtensions(const QString& filename)
233{ 233{
234 QFile file(filename); 234 QFile file(filename);
235 if ( file.open(IO_ReadOnly) ) { 235 if ( file.open(IO_ReadOnly) ) {
236 QTextStream in(&file); 236 QTextStream in(&file);
237 QRegExp space("[ \t]+"); 237 QRegExp space("[ \t]+");
238 while (!in.atEnd()) { 238 while (!in.atEnd()) {
239 QStringList tokens = QStringList::split(space, in.readLine()); 239 QStringList tokens = QStringList::split(space, in.readLine());
240 QStringList::ConstIterator it = tokens.begin(); 240 QStringList::ConstIterator it = tokens.begin();
241 if ( it != tokens.end() ) { 241 if ( it != tokens.end() ) {
242 QString id = *it; ++it; 242 QString id = *it; ++it;
243 // new override old (though left overrides right) 243 // new override old (though left overrides right)
244 QStringList exts = (*extFor)[id]; 244 QStringList exts = (*extFor)[id];
245 QStringList newexts; 245 QStringList newexts;
246 if ( it != tokens.end() ) { 246 while ( it != tokens.end() ) {
247 exts.remove(*it); 247 exts.remove(*it);
248 if ( !newexts.contains(*it) ) 248 if ( !newexts.contains(*it) )
249 newexts.append(*it); 249 newexts.append(*it);
250 while (it != tokens.end()) { 250 (*typeFor)[*it] = id;
251 (*typeFor)[*it] = id; 251 ++it;
252 ++it;
253 }
254 } 252 }
255 (*extFor)[id] = newexts + exts; 253 (*extFor)[id] = newexts + exts;
256 } 254 }
257 } 255 }
258 } 256 }
259} 257}
260 258
261void MimeType::init( const QString& ext_or_id ) 259void MimeType::init( const QString& ext_or_id )
262{ 260{
263 if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) { 261 if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) {
264 i = ext_or_id.lower(); 262 i = ext_or_id.lower();
265 } else { 263 } else {
266 loadExtensions(); 264 loadExtensions();
267 int dot = ext_or_id.findRev('.'); 265 int dot = ext_or_id.findRev('.');
268 QString ext = dot >= 0 ? ext_or_id.mid(dot+1) : ext_or_id; 266 QString ext = dot >= 0 ? ext_or_id.mid(dot+1) : ext_or_id;
269 i = (*typeFor)[ext.lower()]; 267 i = (*typeFor)[ext.lower()];
270 if ( i.isNull() ) 268 if ( i.isNull() )
271 i = "application/octet-stream"; 269 i = "application/octet-stream";
272 } 270 }
273 static bool appsUpdated = FALSE; 271 static bool appsUpdated = FALSE;
274 if ( !appsUpdated ) { 272 if ( !appsUpdated ) {
275 appsUpdated = TRUE; 273 appsUpdated = TRUE;
276 updateApplications(); 274 updateApplications();
277 } 275 }
278} 276}
279 277
280MimeTypeData* MimeType::data(const QString& id) 278MimeTypeData* MimeType::data(const QString& id)
281{ 279{
282 MimeTypeData* d = data()[id]; 280 MimeTypeData* d = data()[id];
283 if ( !d ) { 281 if ( !d ) {
284 int s = id.find('/'); 282 int s = id.find('/');
285 QString idw = id.left(s)+"/*"; 283 QString idw = id.left(s)+"/*";
286 d = data()[idw]; 284 d = data()[idw];
287 } 285 }
288 return d; 286 return d;
289} 287}
290 288
291QString MimeType::appsFolderName() 289QString MimeType::appsFolderName()
292{ 290{
293 return QPEApplication::qpeDir() + "apps"; 291 return QPEApplication::qpeDir() + "apps";
294} 292}
295 293
296void MimeType::updateApplications() 294void MimeType::updateApplications()
297{ 295{
298 clear(); 296 clear();
299 AppLnkSet apps( appsFolderName() ); 297 AppLnkSet apps( appsFolderName() );
300 updateApplications(&apps); 298 updateApplications(&apps);
301} 299}