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