debug and actual first way to display pictures in messageFeed

This commit is contained in:
Blue 2021-04-21 00:56:47 +03:00
parent 48e498be25
commit 0e937199b0
7 changed files with 118 additions and 8 deletions

View file

@ -81,7 +81,8 @@ Shared::Global::Global():
}),
pluginSupport({
{"KWallet", false}
})
}),
fileCache()
{
if (instance != 0) {
throw 551;
@ -90,6 +91,34 @@ Shared::Global::Global():
instance = this;
}
Shared::Global::FileInfo Shared::Global::getFileInfo(const QString& path)
{
std::map<QString, FileInfo>::const_iterator itr = instance->fileCache.find(path);
if (itr == instance->fileCache.end()) {
QMimeDatabase db;
QMimeType type = db.mimeTypeForFile(path);
QStringList parts = type.name().split("/");
QString big = parts.front();
QFileInfo info(path);
FileInfo::Preview p = FileInfo::Preview::none;
QSize size;
if (big == "image") {
if (parts.back() == "gif") {
//TODO need to consider GIF as a movie
}
p = FileInfo::Preview::picture;
QImage img(path);
size = img.size();
}
itr = instance->fileCache.insert(std::make_pair(path, FileInfo({info.fileName(), size, type, p}))).first;
}
return itr->second;
}
Shared::Global * Shared::Global::getInstance()
{
return instance;

View file

@ -29,6 +29,11 @@
#include <QCoreApplication>
#include <QDebug>
#include <QMimeType>
#include <QMimeDatabase>
#include <QFileInfo>
#include <QImage>
#include <QSize>
namespace Shared {
@ -36,6 +41,19 @@ namespace Shared {
Q_DECLARE_TR_FUNCTIONS(Global)
public:
struct FileInfo {
enum class Preview {
none,
picture,
movie
};
QString name;
QSize size;
QMimeType mime;
Preview preview;
};
Global();
static Global* getInstance();
@ -64,6 +82,8 @@ namespace Shared {
static const std::set<QString> supportedImagesExts;
static FileInfo getFileInfo(const QString& path);
template<typename T>
static T fromInt(int src);
@ -87,6 +107,7 @@ namespace Shared {
static Global* instance;
std::map<QString, bool> pluginSupport;
std::map<QString, FileInfo> fileCache;
};
}