diff options
author | 2021-04-07 21:47:03 +0530 | |
---|---|---|
committer | 2021-04-07 21:47:03 +0530 | |
commit | 3808c7afabaf3217b2641083cc3a07e771848eaa (patch) | |
tree | 8b899b4595ce851a8a0369e55d2adad4352fa5fe | |
parent | a789bdfd3f9aa06f814f7f799056db35db4bedf9 (diff) | |
download | whatsie-3808c7afabaf3217b2641083cc3a07e771848eaa.tar.gz whatsie-3808c7afabaf3217b2641083cc3a07e771848eaa.zip |
added dictionary helper class
-rw-r--r-- | src/WhatsApp.pro | 2 | ||||
-rw-r--r-- | src/dictionaries.cpp | 73 | ||||
-rw-r--r-- | src/dictionaries.h | 21 |
3 files changed, 96 insertions, 0 deletions
diff --git a/src/WhatsApp.pro b/src/WhatsApp.pro index 6b6a24c..aa51a4b 100644 --- a/src/WhatsApp.pro +++ b/src/WhatsApp.pro @@ -41,6 +41,7 @@ DEFINES += VERSIONSTR=\\\"$${VERSION}\\\" SOURCES += \ about.cpp \ + dictionaries.cpp \ downloadmanagerwidget.cpp \ downloadwidget.cpp \ elidedlabel.cpp \ @@ -59,6 +60,7 @@ RESOURCES += \ HEADERS += \ about.h \ common.h \ + dictionaries.h \ downloadmanagerwidget.h \ downloadwidget.h \ elidedlabel.h \ 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; +} diff --git a/src/dictionaries.h b/src/dictionaries.h new file mode 100644 index 0000000..2ed7612 --- /dev/null +++ b/src/dictionaries.h @@ -0,0 +1,21 @@ +#ifndef DICTIONARIES_H +#define DICTIONARIES_H + +#include <QString> +#include <QStringList> +#include <QObject> + + +class Dictionaries : public QObject +{ + Q_OBJECT + +public: + Dictionaries(QObject* parent=0); + virtual ~Dictionaries(); +public slots: + QString GetDictionaryPath(); + QStringList GetDictionaries(); +}; + +#endif // DICTIONARIES_H |