File indexing completed on 2024-03-24 04:03:41
0001 /* 0002 * SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 #ifndef SONNET_LOADER_P_H 0007 #define SONNET_LOADER_P_H 0008 0009 #include "sonnetcore_export.h" 0010 0011 #include <QObject> 0012 #include <QSharedPointer> 0013 #include <QString> 0014 #include <QStringList> 0015 0016 #include <memory> 0017 0018 namespace Sonnet 0019 { 0020 class SettingsImpl; 0021 class SpellerPlugin; 0022 class LoaderPrivate; 0023 /** 0024 * \internal 0025 * @short Class used to deal with dictionaries 0026 * 0027 * This class manages all dictionaries. It's the top level 0028 * Sonnet class, you can think of it as the kernel or manager 0029 * of the Sonnet architecture. 0030 */ 0031 class SONNETCORE_EXPORT Loader : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 /** 0036 * Constructs the loader. 0037 * 0038 * It's very important that you leave the return value in a Loader::Ptr. 0039 * Loader is reference counted so if you don't want to have it deleted 0040 * under you simply have to hold it in a Loader::Ptr for as long as 0041 * you're using it. 0042 */ 0043 static Loader *openLoader(); 0044 0045 public: 0046 Loader(); 0047 ~Loader() override; 0048 0049 /** 0050 * Returns dictionary for the given language and preferred client. 0051 * 0052 * @param language specifies the language of the dictionary. If an 0053 * empty string will be passed the default language will 0054 * be used. Has to be one of the values returned by 0055 * \ref languages() 0056 * @param client specifies the preferred client. If no client is 0057 * specified a client which supports the given 0058 * language is picked. If a few clients supports 0059 * the same language the one with the biggest 0060 * reliability value is returned. 0061 * 0062 */ 0063 SpellerPlugin *createSpeller(const QString &language = QString(), const QString &client = QString()) const; 0064 0065 /** 0066 * Returns a shared, cached, dictionary for the given language. 0067 * 0068 * @param language specifies the language of the dictionary. If an 0069 * empty string will be passed the default language will 0070 * be used. Has to be one of the values returned by 0071 * \ref languages() 0072 */ 0073 QSharedPointer<SpellerPlugin> cachedSpeller(const QString &language); 0074 0075 /** 0076 * Returns a shared, cached, dictionary for the given language. 0077 * 0078 * @param language specifies the language of the dictionary. If an 0079 * empty string will be passed the default language will 0080 * be used. Has to be one of the values returned by 0081 * \ref languages() 0082 */ 0083 void clearSpellerCache(); 0084 0085 /** 0086 * Returns names of all supported clients (e.g. ISpell, ASpell) 0087 */ 0088 QStringList clients() const; 0089 0090 /** 0091 * Returns a list of supported languages. 0092 */ 0093 QStringList languages() const; 0094 0095 /** 0096 * Returns a localized list of names of supported languages. 0097 */ 0098 QStringList languageNames() const; 0099 0100 /** 0101 * @param langCode the dictionary name/language code, e.g. en_gb 0102 * @return the localized language name, e.g. "British English" 0103 * @since 4.2 0104 */ 0105 QString languageNameForCode(const QString &langCode) const; 0106 0107 /** 0108 * Returns the SettingsImpl object used by the loader. 0109 */ 0110 SettingsImpl *settings() const; 0111 Q_SIGNALS: 0112 /** 0113 * Signal is emitted whenever the SettingsImpl object 0114 * associated with this Loader changes. 0115 */ 0116 void configurationChanged(); 0117 0118 /** 0119 * Emitted when loading a dictionary fails, so that Ui parts can 0120 * display an appropriate error message informing the user about 0121 * the issue. 0122 * @param language the name of the dictionary that failed to be loaded 0123 * @since 5.56 0124 */ 0125 void loadingDictionaryFailed(const QString &language) const; 0126 0127 protected: 0128 friend class SettingsImpl; 0129 void changed(); 0130 0131 private: 0132 SONNETCORE_NO_EXPORT void loadPlugins(); 0133 SONNETCORE_NO_EXPORT void loadPlugin(const QString &pluginPath); 0134 0135 private: 0136 std::unique_ptr<LoaderPrivate> const d; 0137 }; 0138 } 0139 0140 #endif // SONNET_LOADER_P_H