Commit 32556db6 by JanKusanagi

Removed libmagic dependency; Using Qt 5 methods for MIME types

1 parent 9e1e61bf
......@@ -8,6 +8,7 @@ v1.4.0 (July, 2017)
- Auto-switch to full mode in image viewer when using the mouse wheel. (WIP)
- Translatable Appdata file. (TODO)
- Building with Qt 4 is no longer supported.
- Removed libmagic dependency, since Qt 5 has methods for mimetypes.
- Fixed #41, accepting username@localhost as valid Webfinger ID, for testers.
- Handle new HTML-based error messages sent by server since Pump.io 4.0.
- Minor fixes.
......
......@@ -193,7 +193,6 @@ TRANSLATIONS += translations/dianara_es.ts \
RESOURCES += dianara.qrc
LIBS += -lmagic # to use libmagic
CONFIG += oauth
......
......@@ -35,7 +35,6 @@ General runtime dependencies (check carefully!)
- Qt 5.6 or later
- QOAuth 2.x, built with Qt 5
- Libmagic
- OpenSSL plugin for QCA (qca2-plugin-openssl, libqca2-plugin-ossl, or similar)
In some cases, the QCA package includes the plugins directly.
*** Dianara will _crash_ if you don't have this!
......@@ -46,7 +45,7 @@ Dependencies for building
===============================================================================
You'll need qmake and the qt-devel (>= 5.6, including QtNetwork and QtDBUS
modules, if they are separate), qoauth-devel and libmagic-devel packages.
modules, if they are separate), and qoauth-devel packages.
Qmake might be included in the Qt development packages, or it might be a
separate package.
......@@ -55,7 +54,7 @@ These are the names of the packages for the build dependencies
in some GNU/Linux distributions:
- Mageia (probably in Mandriva and ROSA, too):
libqt5base5-devel, libqoauth-qt5-devel and libmagic-devel.
libqt5base5-devel and libqoauth-qt5-devel.
** Note: In x86_64 arch, "lib" packages start with "lib64", such as
lib64qt5base5-devel.
......@@ -64,7 +63,7 @@ in some GNU/Linux distributions:
- Debian (probably in any of its derivatives, too):
qt5-default, libqoauth-dev (>=2.0.0) and libmagic-dev.
qt5-default and libqoauth-dev (>=2.0.0).
> Build tools: build-essential, g++
......@@ -76,11 +75,11 @@ in some GNU/Linux distributions:
- openSUSE:
libqt5-qtbase-devel, qoauth-devel and file-devel (has libmagic).
libqt5-qtbase-devel and qoauth-devel.
- Archlinux (runtime dependencies include build-time dependencies):
qt5-base, qoauth, file (this one includes libmagic).
qt5-base and qoauth.
......
......@@ -5,7 +5,6 @@ General to-do list and ideas for Dianara, in no particular order:
/// v1.4.0?
- Remove libmagic dependency. Qt 5 has methods for mimetypes.
- Fix crash when moving contacts around in the Audience lists of a post.
(Qt bug)
- Use Qt's own plural handling.
......
......@@ -128,41 +128,17 @@ QString MiscHelpers::getSuggestedFilename(QString authorId,
/*
* Return MIME content type, like image/png, audio/ogg, etc.
*
* using libmagic
*
*/
QString MiscHelpers::getFileMimeType(QString fileUri)
{
qDebug() << "getFileMimeType() file:" << fileUri;
magic_t magicCookie = magic_open(MAGIC_MIME_TYPE);
if (magicCookie == NULL)
{
qDebug() << "libmagic init error!";
return QString();
}
if (magic_load(magicCookie, NULL) != 0)
{
qDebug() << "magic_load() error! No system-wide libmagic DB?";
// Try loading from a subdirectory instead (in mswindows, maybe osx)
if (magic_load(magicCookie, "plugins/magic") != 0)
{
qDebug() << "magic_load() error; Can't load plugins/magic.mgc";
magic_close(magicCookie);
return QString();
}
}
const char *magicMimeString;
magicMimeString = magic_file(magicCookie, fileUri.toLocal8Bit());
QString mimeType = QString(magicMimeString);
qDebug() << "File MIME type:" << mimeType;
magic_close(magicCookie);
QMimeDatabase mimeDb;
QMimeType mimeType = mimeDb.mimeTypeForFile(fileUri);
qDebug() << mimeType.name();
qDebug() << mimeType.aliases();
return mimeType;
return mimeType.name(); // mime.aliases() is also interesting
}
......
......@@ -31,8 +31,7 @@
#include <QImageReader>
#include <QMovie>
#include <QStandardPaths>
#include <magic.h>
#include <QMimeDatabase>
#include <QDebug>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!