#include <QSet>
#include <QStyle>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include <QMimeDatabase>
+#include <QMimeType>
+#endif
+
#include <libtransmission/transmission.h>
#include <libtransmission/utils.h> // tr_formatter
} // namespace
#endif
+#include <QDebug>
QIcon
Utils::guessMimeIcon (const QString& filename)
{
+ static const QIcon fallback = qApp->style ()->standardIcon (QStyle::SP_FileIcon);
+
#ifdef _WIN32
+
QIcon icon;
if (!filename.isEmpty ())
addAssociatedFileIcon (fileInfo, SHGFI_LARGEICON, icon);
}
- if (icon.isNull ())
- icon = qApp->style ()->standardIcon (QStyle::SP_FileIcon);
+ if (!icon.isNull ())
+ return icon;
+
+#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+
+ QMimeDatabase mimeDb;
+ QMimeType mimeType = mimeDb.mimeTypeForFile (filename, QMimeDatabase::MatchExtension);
+ if (mimeType.isValid ())
+ return QIcon::fromTheme (mimeType.iconName (), QIcon::fromTheme (mimeType.genericIconName (), fallback));
- return icon;
#else
+
enum { DISK, DOCUMENT, PICTURE, VIDEO, ARCHIVE, AUDIO, APP, TYPE_COUNT };
- static QIcon fallback;
static QIcon fileIcons[TYPE_COUNT];
static QSet<QString> suffixes[TYPE_COUNT];
if (fileIcons[0].isNull ())
{
- fallback = qApp->style()->standardIcon (QStyle::SP_FileIcon);
-
suffixes[DISK] << QString::fromLatin1("iso");
fileIcons[DISK]= QIcon::fromTheme (QString::fromLatin1("media-optical"), fallback);
if (suffixes[i].contains (suffix))
return fileIcons[i];
- return fallback;
#endif
+
+ return fallback;
}
bool