looqs/gui/previewgenerator.cpp

31 wiersze
970 B
C++
Czysty Zwykły widok Historia

#include "../shared/common.h"
#include "previewgenerator.h"
#include <QMutexLocker>
2022-04-24 12:22:59 +02:00
#include "previewgeneratorpdf.h"
#include "previewgeneratorplaintext.h"
#include "previewgeneratorodt.h"
2022-04-24 12:22:59 +02:00
static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText();
static QHash<QString, PreviewGenerator *> generators{
2022-04-24 12:22:59 +02:00
{"pdf", new PreviewGeneratorPdf()}, {"txt", plainTextGenerator}, {"md", plainTextGenerator},
{"py", plainTextGenerator}, {"java", plainTextGenerator}, {"js", plainTextGenerator},
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator},
{"odt", new PreviewGeneratorOdt()}};
2022-04-24 12:22:59 +02:00
static QMutex generatorsMutex;
2022-04-24 12:22:59 +02:00
PreviewGenerator *PreviewGenerator::get(QFileInfo &info)
{
QMutexLocker locker(&generatorsMutex);
PreviewGenerator *result = generators.value(info.suffix(), nullptr);
locker.unlock();
if(result == nullptr)
{
if(Common::isTextFile(info))
{
return plainTextGenerator;
}
}
return result;
2022-04-24 12:22:59 +02:00
}