diff --git a/src/plugins/hunspell/hunspellclient.h b/src/plugins/hunspell/hunspellclient.h --- a/src/plugins/hunspell/hunspellclient.h +++ b/src/plugins/hunspell/hunspellclient.h @@ -53,6 +53,7 @@ } private: + QString checkForHunspellRCC(); QMap m_languagePaths; }; diff --git a/src/plugins/hunspell/hunspellclient.cpp b/src/plugins/hunspell/hunspellclient.cpp --- a/src/plugins/hunspell/hunspellclient.cpp +++ b/src/plugins/hunspell/hunspellclient.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace Sonnet; @@ -61,6 +62,11 @@ maybeAddPath(QStringLiteral("/usr/share/myspell/")); #endif + const QString hunspellRCC = checkForHunspellRCC(); + if (!hunspellRCC.isEmpty()) { + maybeAddPath(hunspellRCC); + } + for (const QString &dirString : dirList) { QDir dir(dirString); for (const QFileInfo &dict : dir.entryInfoList({QStringLiteral("*.aff")}, QDir::Files)) { @@ -85,3 +91,15 @@ { return m_languagePaths.keys(); } + +QString HunspellClient::checkForHunspellRCC() +{ + const QString hunspellRCC = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("hunspell/hunspell.rcc")); + if (!hunspellRCC.isEmpty()) { + const QString subdir = QStringLiteral("/hunspell_rcc/"); + if (QResource::registerResource(hunspellRCC, subdir)) { + return QString(QLatin1Char(':') + subdir); + } + } + return QString(); +} diff --git a/src/plugins/hunspell/hunspelldict.h b/src/plugins/hunspell/hunspelldict.h --- a/src/plugins/hunspell/hunspelldict.h +++ b/src/plugins/hunspell/hunspelldict.h @@ -24,6 +24,10 @@ #include "spellerplugin_p.h" #include "hunspell.hxx" +QT_BEGIN_NAMESPACE +class QTemporaryDir; +QT_END_NAMESPACE + class HunspellDict : public Sonnet::SpellerPlugin { public: @@ -43,6 +47,7 @@ Hunspell *m_speller = nullptr; QTextCodec *m_codec = nullptr; + QTemporaryDir *m_tempDir = nullptr; }; #endif diff --git a/src/plugins/hunspell/hunspelldict.cpp b/src/plugins/hunspell/hunspelldict.cpp --- a/src/plugins/hunspell/hunspelldict.cpp +++ b/src/plugins/hunspell/hunspelldict.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace Sonnet; @@ -44,6 +45,20 @@ QString dictionary = path + QStringLiteral(".dic"); QString aff = path + QStringLiteral(".aff"); + if (path.startsWith(QLatin1Char(':'))) { + m_tempDir = new QTemporaryDir(); + if (!m_tempDir->isValid()) { + qCWarning(SONNET_HUNSPELL) << "Failed to create QTemporaryDir"; + } + QString newAffName = m_tempDir->path() + QStringLiteral("/aff"); + QString newDictName = m_tempDir->path() + QStringLiteral("/dic"); + + QFile::copy(aff, newAffName); + QFile::copy(dictionary, newDictName); + aff = newAffName; + dictionary = newDictName; + } + if (QFileInfo::exists(dictionary) && QFileInfo::exists(aff)) { m_speller = new Hunspell(aff.toLocal8Bit().constData(), dictionary.toLocal8Bit().constData()); @@ -80,12 +95,15 @@ } userDicFile.close(); } - qCDebug(SONNET_HUNSPELL) << "Created " << m_speller; + qCDebug(SONNET_HUNSPELL) << "Created " << m_speller << aff << dictionary; } HunspellDict::~HunspellDict() { delete m_speller; + if (m_tempDir) { + delete m_tempDir; + } } QByteArray HunspellDict::toDictEncoding(const QString &word) const