From b41db9bfac46ead20e1c9d3b6924231886cfee0c Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 22 Nov 2019 13:15:21 +0100 Subject: Use QMime* instead of libmagic One more step to make it compile with Windows. And once again, it makes the code much neater and more readable. --- helper.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp index 214e950..4b42f0e 100644 --- a/helper.cpp +++ b/helper.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include @@ -37,28 +39,9 @@ namespace Helper { const QString mimeType(const QString &path){ - QString retval; - magic_t mc = magic_open(MAGIC_MIME_TYPE); - QByteArray name = path.toUtf8(); - if(mc){ - magic_load(mc, nullptr); - const char* magic_c = magic_file(mc, name.constData()); - retval = QString(magic_c); - magic_close(mc); - } - if(retval.toLower().startsWith("application/octet-stream")){ - magic_t mc = magic_open(MAGIC_NONE); - if(mc){ - magic_load(mc, nullptr); - const char* magic_c = magic_file(mc, name.constData()); - QString desc(magic_c); - magic_close(mc); - if(desc.toLower().contains("mpeg sequence") || desc.toLower().contains("microsoft asf") || desc.toLower().contains("matroska")){ - retval = "video/"; - } - } - } - return retval; + QMimeDatabase db; + QMimeType type = db.mimeTypeForFile(path); + return type.name(); } const QString md5Sum(const QString &path){ -- cgit v1.2.3-70-g09d2