gui: previewgenerator: Use QHash and guard using mutexes
This commit is contained in:
父節點
48ca25abe3
當前提交
49a1a14009
@ -1,20 +1,24 @@
|
||||
#include "../shared/common.h"
|
||||
#include "previewgenerator.h"
|
||||
#include <QMutexLocker>
|
||||
#include "previewgeneratorpdf.h"
|
||||
#include "previewgeneratorplaintext.h"
|
||||
#include "previewgeneratorodt.h"
|
||||
|
||||
static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText();
|
||||
|
||||
static QMap<QString, PreviewGenerator *> generators{
|
||||
static QHash<QString, PreviewGenerator *> generators{
|
||||
{"pdf", new PreviewGeneratorPdf()}, {"txt", plainTextGenerator}, {"md", plainTextGenerator},
|
||||
{"py", plainTextGenerator}, {"java", plainTextGenerator}, {"js", plainTextGenerator},
|
||||
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator},
|
||||
{"odt", new PreviewGeneratorOdt()}};
|
||||
|
||||
static QMutex generatorsMutex;
|
||||
PreviewGenerator *PreviewGenerator::get(QFileInfo &info)
|
||||
{
|
||||
QMutexLocker locker(&generatorsMutex);
|
||||
PreviewGenerator *result = generators.value(info.suffix(), nullptr);
|
||||
locker.unlock();
|
||||
if(result == nullptr)
|
||||
{
|
||||
if(Common::isTextFile(info))
|
||||
|
Loading…
Reference in New Issue
Block a user