From 1d2dbfb7741df181a88af4f11abf1159f0dc0a70 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 18 Aug 2017 11:02:31 +0200 Subject: [PATCH] feat(Chat): detect correctly mime types for file messages --- src/components/chat/ChatModel.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/chat/ChatModel.cpp b/src/components/chat/ChatModel.cpp index 80be1b39e..97d229dad 100644 --- a/src/components/chat/ChatModel.cpp +++ b/src/components/chat/ChatModel.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "../../app/App.hpp" #include "../../app/paths/Paths.hpp" @@ -392,8 +393,15 @@ void ChatModel::sendFileMessage (const QString &path) { } shared_ptr content = CoreManager::getInstance()->getCore()->createContent(); - content->setType("application"); - content->setSubtype("octet-stream"); + { + QStringList mimeType = QMimeDatabase().mimeTypeForFile(path).name().split('/'); + if (mimeType.length() != 2) { + qWarning() << QStringLiteral("Unable to get supported mime type for: `%1`.").arg(path); + return; + } + content->setType(::Utils::appStringToCoreString(mimeType[0])); + content->setSubtype(::Utils::appStringToCoreString(mimeType[1])); + } content->setSize(static_cast(fileSize)); content->setName(::Utils::appStringToCoreString(QFileInfo(file).fileName()));