File indexing completed on 2025-01-12 12:26:25
0001 /** 0002 * kimgio.h -- Implementation of interface to the KDE Image IO library. 0003 * Copyright (c) 1998 Sirtaj Singh Kang <taj@kde.org> 0004 * 0005 * This library is distributed under the conditions of the GNU LGPL. 0006 */ 0007 0008 #include "kimageio.h" 0009 0010 #include "qmimedatabase.h" 0011 #include <QDebug> 0012 #include <kservicetypetrader.h> 0013 #include <klocalizedstring.h> 0014 0015 QString 0016 KImageIO::pattern(Mode mode) 0017 { 0018 QStringList patterns; 0019 QString allPatterns; 0020 QString separator("|"); 0021 QMimeDatabase db; 0022 0023 const KService::List services = KServiceTypeTrader::self()->query("QImageIOPlugins"); 0024 foreach (const KService::Ptr &service, services) { 0025 if ((service->property("X-KDE-Read").toBool() && mode == Reading) || 0026 (service->property("X-KDE-Write").toBool() && mode == Writing)) { 0027 0028 QString mimeType = service->property("X-KDE-MimeType").toString(); 0029 if (mimeType.isEmpty()) { 0030 continue; 0031 } 0032 QMimeType mime = db.mimeTypeForName(mimeType); 0033 if (!mime.isValid()) { 0034 qWarning() << service->entryPath() << " specifies unknown mimetype " << mimeType; 0035 } else { 0036 QString pattern = mime.globPatterns().join(" "); 0037 patterns.append(pattern + separator + mime.comment()); 0038 if (!allPatterns.isEmpty()) { 0039 allPatterns += ' '; 0040 } 0041 allPatterns += pattern; 0042 } 0043 } 0044 } 0045 0046 allPatterns = allPatterns + separator + i18n("All Pictures"); 0047 patterns.sort(); 0048 patterns.prepend(allPatterns); 0049 0050 QString pattern = patterns.join(QLatin1String("\n")); 0051 return pattern; 0052 } 0053 0054 QStringList KImageIO::typeForMime(const QString &mimeType) 0055 { 0056 if (mimeType.isEmpty()) { 0057 return QStringList(); 0058 } 0059 0060 const KService::List services = KServiceTypeTrader::self()->query("QImageIOPlugins"); 0061 foreach (const KService::Ptr &service, services) { 0062 if (mimeType == service->property("X-KDE-MimeType").toString()) { 0063 return (service->property("X-KDE-ImageFormat").toStringList()); 0064 } 0065 } 0066 return QStringList(); 0067 } 0068 0069 QStringList KImageIO::mimeTypes(Mode mode) 0070 { 0071 QStringList mimeList, allFormats; 0072 0073 const KService::List services = KServiceTypeTrader::self()->query("QImageIOPlugins"); 0074 foreach (const KService::Ptr &service, services) { 0075 if ((service->property("X-KDE-Read").toBool() && mode == Reading) || 0076 (service->property("X-KDE-Write").toBool() && mode == Writing)) { 0077 0078 const QString mime = service->property("X-KDE-MimeType").toString(); 0079 if (!mime.isEmpty()) { 0080 mimeList.append(mime); 0081 } 0082 } 0083 } 0084 0085 return mimeList; 0086 } 0087 0088 QStringList KImageIO::types(Mode mode) 0089 { 0090 QStringList imagetypes; 0091 const KService::List services = KServiceTypeTrader::self()->query("QImageIOPlugins"); 0092 foreach (const KService::Ptr &service, services) { 0093 if ((service->property("X-KDE-Read").toBool() && mode == Reading) || 0094 (service->property("X-KDE-Write").toBool() && mode == Writing)) { 0095 0096 imagetypes += service->property("X-KDE-ImageFormat").toStringList(); 0097 } 0098 } 0099 return imagetypes; 0100 } 0101 0102 bool KImageIO::isSupported(const QString &mimeType, Mode mode) 0103 { 0104 if (mimeType.isEmpty()) { 0105 return false; 0106 } 0107 0108 const KService::List services = KServiceTypeTrader::self()->query("QImageIOPlugins"); 0109 foreach (const KService::Ptr &service, services) { 0110 if (mimeType == service->property("X-KDE-MimeType").toString()) { 0111 0112 if ((service->property("X-KDE-Read").toBool() && mode == Reading) || 0113 (service->property("X-KDE-Write").toBool() && mode == Writing)) { 0114 0115 return true; 0116 } else { 0117 return false; 0118 } 0119 } 0120 } 0121 return false; 0122 }