diff --git a/src/core/guesslanguage.cpp b/src/core/guesslanguage.cpp --- a/src/core/guesslanguage.cpp +++ b/src/core/guesslanguage.cpp @@ -630,8 +630,13 @@ "kf5/sonnet/trigrams.map")); if (triMapFile.isEmpty()) { +#ifdef Q_OS_WIN + triMapFile = QStringLiteral("%1/data/kf5/sonnet/trigrams.map").arg( + QCoreApplication::applicationDirPath()); +#else triMapFile = QStringLiteral("%1/../share/kf5/sonnet/trigrams.map").arg( QCoreApplication::applicationDirPath()); +#endif } qCDebug(SONNET_LOG_CORE) << "Loading trigrams from" << triMapFile; diff --git a/src/plugins/hunspell/CMakeLists.txt b/src/plugins/hunspell/CMakeLists.txt --- a/src/plugins/hunspell/CMakeLists.txt +++ b/src/plugins/hunspell/CMakeLists.txt @@ -1,12 +1,6 @@ ########### next target ############### -if (EXISTS "/usr/share/hunspell/") -add_definitions(-DHUNSPELL_MAIN_DICT_PATH="/usr/share/hunspell") -elseif (EXISTS "/usr/share/myspell/") -add_definitions(-DHUNSPELL_MAIN_DICT_PATH="/usr/share/myspell") -endif (EXISTS "/usr/share/hunspell/") - include_directories( ${HUNSPELL_INCLUDE_DIRS} ) set(sonnet_hunspell_PART_SRCS hunspellclient.cpp @@ -17,6 +11,7 @@ add_library(sonnet_hunspell MODULE ${sonnet_hunspell_PART_SRCS}) target_link_libraries(sonnet_hunspell PRIVATE KF5::SonnetCore ${HUNSPELL_LIBRARIES}) +target_compile_definitions(sonnet_hunspell PRIVATE DEFINITIONS SONNET_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") install(TARGETS sonnet_hunspell DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/sonnet/) 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 @@ -35,36 +35,29 @@ qCDebug(SONNET_HUNSPELL) << " HunspellClient::HunspellClient"; QStringList dirList; - const QString AFF_MASK = QStringLiteral("*.aff"); - -#if defined(Q_OS_MAC) || defined(Q_OS_WIN) -#ifdef Q_OS_MAC - QDir lodir(QStringLiteral("/Applications/LibreOffice.app/Contents/Resources/extensions")); -#endif -#ifdef Q_OS_WIN - QDir lodir(QStringLiteral("C:/Program Files (x86)/LibreOffice 5/share/extensions")); -#endif - const QString DIR_MASK = QStringLiteral("dict-*"); - if (lodir.exists()) { - foreach (const QString &d, lodir.entryList(QStringList(DIR_MASK), QDir::Dirs)) { - dirList.append(lodir.absoluteFilePath(d)); - } - } -#endif - // search QStandardPaths dirList.append(QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, QStringLiteral("hunspell"), QStandardPaths::LocateDirectory)); - dirList.append(QStringLiteral(HUNSPELL_MAIN_DICT_PATH)); - dirList.append(QStringLiteral("%1/../share/hunspell").arg( - QCoreApplication::applicationDirPath())); + auto maybeAddPath = [&dirList](const QString &path) + { + if (QFileInfo::exists(path)) { + dirList.append(path); + } + }; +#ifdef Q_OS_WIN + maybeAddPath(QStringLiteral(SONNET_INSTALL_PREFIX "/bin/data/hunspell/")); +#else + maybeAddPath(QStringLiteral("/System/Library/Spelling")); + maybeAddPath(QStringLiteral("/usr/share/hunspell/")); + maybeAddPath(QStringLiteral("/usr/share/myspell/")); +#endif for (const QString &dirString : dirList) { QDir dir(dirString); - for (const QFileInfo &dict : dir.entryInfoList(QStringList(AFF_MASK), QDir::Files)) { + for (const QFileInfo &dict : dir.entryInfoList({QStringLiteral("*.aff")}, QDir::Files)) { m_languagePaths.insert(dict.baseName(), dict.canonicalPath()); } } 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,14 +24,6 @@ #include "spellerplugin_p.h" #include "hunspell.hxx" -#ifndef HUNSPELL_MAIN_DICT_PATH -#ifdef Q_OS_MAC -#define HUNSPELL_MAIN_DICT_PATH "/System/Library/Spelling" -#else -#define HUNSPELL_MAIN_DICT_PATH "/usr/share/hunspell" -#endif -#endif - class HunspellDict : public Sonnet::SpellerPlugin { public: