diff options
author | 2021-04-07 21:47:03 +0530 | |
---|---|---|
committer | 2021-04-07 21:47:03 +0530 | |
commit | 3808c7afabaf3217b2641083cc3a07e771848eaa (patch) | |
tree | 8b899b4595ce851a8a0369e55d2adad4352fa5fe /src/dictionaries.cpp | |
parent | a789bdfd3f9aa06f814f7f799056db35db4bedf9 (diff) | |
download | whatsie-3808c7afabaf3217b2641083cc3a07e771848eaa.tar.gz whatsie-3808c7afabaf3217b2641083cc3a07e771848eaa.zip |
added dictionary helper class
Diffstat (limited to 'src/dictionaries.cpp')
-rw-r--r-- | src/dictionaries.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/dictionaries.cpp b/src/dictionaries.cpp new file mode 100644 index 0000000..5ae6cc3 --- /dev/null +++ b/src/dictionaries.cpp @@ -0,0 +1,73 @@ +#include "dictionaries.h" +#include <QDir> +#include <QCoreApplication> +#include <QLibraryInfo> +#include <QString> +#include <QStringList> +#include "utils.h" + +static QString DICTIONARY_FILE_SUFFIX = ".bdic"; + +Dictionaries::Dictionaries(QObject *parent) : QObject(parent) +{ + setParent(parent); +} + +Dictionaries::~Dictionaries() +{ + this->deleteLater(); +} + + +QString Dictionaries::GetDictionaryPath() +{ + QString dict_path; + + // the environment variable takes precedence on all platforms + if (qEnvironmentVariableIsSet("QTWEBENGINE_DICTIONARIES_PATH")) { + dict_path = utils::GetEnvironmentVar("QTWEBENGINE_DICTIONARIES_PATH"); + return dict_path; + } + + // next look relative to the executable + dict_path = QCoreApplication::applicationDirPath() + "/qtwebengine_dictionaries"; + + + if (QDir(dict_path).exists()) { + return dict_path; + } + + //inside the installed Qt directories + dict_path = QLibraryInfo::location(QLibraryInfo::DataPath) + "/qtwebengine_dictionaries"; + + + if (QDir(dict_path).exists()) { + return dict_path; + } + + return QString(); +} + + +QStringList Dictionaries::GetDictionaries() +{ + QStringList dictionaries; + QString dict_path = GetDictionaryPath(); + if (dict_path.isEmpty()) { + return dictionaries; + } + QDir dictDir(dict_path); + if (dictDir.exists()) { + QStringList filters; + // Look for all *.bdic files. + filters << "*" + DICTIONARY_FILE_SUFFIX; + dictDir.setNameFilters(filters); + QStringList dictionary_files = dictDir.entryList(); + foreach(QString file, dictionary_files) { + QFileInfo fileInfo(file); + QString dname = fileInfo.baseName(); + dictionaries.append(dname); + } + } + return dictionaries; +} |