2022-05-30 20:05:02 +02:00
|
|
|
#include "../shared/common.h"
|
2022-01-03 22:59:44 +01:00
|
|
|
#include "previewgenerator.h"
|
2022-10-22 15:07:46 +02:00
|
|
|
#include <QMutexLocker>
|
2022-04-24 12:22:59 +02:00
|
|
|
#include "previewgeneratorpdf.h"
|
|
|
|
#include "previewgeneratorplaintext.h"
|
2022-07-24 11:42:29 +02:00
|
|
|
#include "previewgeneratorodt.h"
|
2022-04-24 12:22:59 +02:00
|
|
|
|
|
|
|
static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText();
|
|
|
|
|
2022-10-22 15:07:46 +02:00
|
|
|
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},
|
2022-07-24 11:42:29 +02:00
|
|
|
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator},
|
|
|
|
{"odt", new PreviewGeneratorOdt()}};
|
2022-04-24 12:22:59 +02:00
|
|
|
|
2022-10-22 15:07:46 +02:00
|
|
|
static QMutex generatorsMutex;
|
2022-04-24 12:22:59 +02:00
|
|
|
PreviewGenerator *PreviewGenerator::get(QFileInfo &info)
|
|
|
|
{
|
2022-10-22 15:07:46 +02:00
|
|
|
QMutexLocker locker(&generatorsMutex);
|
2022-05-30 20:05:02 +02:00
|
|
|
PreviewGenerator *result = generators.value(info.suffix(), nullptr);
|
2022-10-22 15:07:46 +02:00
|
|
|
locker.unlock();
|
2022-05-30 20:05:02 +02:00
|
|
|
if(result == nullptr)
|
|
|
|
{
|
|
|
|
if(Common::isTextFile(info))
|
|
|
|
{
|
|
|
|
return plainTextGenerator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2022-04-24 12:22:59 +02:00
|
|
|
}
|