Skip to content

Commit

Permalink
gui: previewgenerator: Use QHash and guard using mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
crtxcr committed Oct 22, 2022
1 parent 48ca25a commit 49a1a14
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gui/previewgenerator.cpp
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit 49a1a14

Please sign in to comment.