1 | /* |
2 | * SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | */ |
6 | #ifndef SONNET_LOADER_P_H |
7 | #define SONNET_LOADER_P_H |
8 | |
9 | #include "sonnetcore_export.h" |
10 | |
11 | #include <QObject> |
12 | #include <QSharedPointer> |
13 | #include <QString> |
14 | #include <QStringList> |
15 | |
16 | #include <memory> |
17 | |
18 | class QStaticPlugin; |
19 | |
20 | namespace Sonnet |
21 | { |
22 | class SettingsImpl; |
23 | class SpellerPlugin; |
24 | class LoaderPrivate; |
25 | class Client; |
26 | /*! |
27 | * \internal |
28 | * \brief Class used to deal with dictionaries. |
29 | * |
30 | * This class manages all dictionaries. It's the top level |
31 | * Sonnet class, you can think of it as the kernel or manager |
32 | * of the Sonnet architecture. |
33 | */ |
34 | class SONNETCORE_EXPORT Loader : public QObject |
35 | { |
36 | Q_OBJECT |
37 | public: |
38 | /*! |
39 | * Constructs the loader. |
40 | * |
41 | * It's very important that you leave the return value in a Loader::Ptr. |
42 | * Loader is reference counted so if you don't want to have it deleted |
43 | * under you simply have to hold it in a Loader::Ptr for as long as |
44 | * you're using it. |
45 | */ |
46 | static Loader *openLoader(); |
47 | |
48 | public: |
49 | /*! |
50 | */ |
51 | Loader(); |
52 | ~Loader() override; |
53 | |
54 | /*! |
55 | * Returns dictionary for the given language and preferred client. |
56 | * |
57 | * \a language specifies the language of the dictionary. If an |
58 | * empty string will be passed the default language will |
59 | * be used. Has to be one of the values returned by |
60 | * languages() |
61 | * \a client specifies the preferred client. If no client is |
62 | * specified a client which supports the given |
63 | * language is picked. If a few clients supports |
64 | * the same language the one with the biggest |
65 | * reliability value is returned. |
66 | * |
67 | */ |
68 | SpellerPlugin *createSpeller(const QString &language = QString(), const QString &client = QString()) const; |
69 | |
70 | /*! |
71 | * Returns a shared, cached, dictionary for the given language. |
72 | * |
73 | * \a language specifies the language of the dictionary. If an |
74 | * empty string will be passed the default language will |
75 | * be used. Has to be one of the values returned by |
76 | * languages() |
77 | */ |
78 | QSharedPointer<SpellerPlugin> cachedSpeller(const QString &language); |
79 | |
80 | /*! |
81 | * Returns a shared, cached, dictionary for the given language. |
82 | * |
83 | * \a language specifies the language of the dictionary. If an |
84 | * empty string will be passed the default language will |
85 | * be used. Has to be one of the values returned by |
86 | * languages() |
87 | */ |
88 | void clearSpellerCache(); |
89 | |
90 | /*! |
91 | * Returns names of all supported clients (e.g. ISpell, ASpell) |
92 | */ |
93 | QStringList clients() const; |
94 | |
95 | /*! |
96 | * Returns a list of supported languages. |
97 | */ |
98 | QStringList languages() const; |
99 | |
100 | /*! |
101 | * Returns a localized list of names of supported languages. |
102 | */ |
103 | QStringList languageNames() const; |
104 | |
105 | /*! |
106 | * \a langCode the dictionary name/language code, e.g. en_gb |
107 | * Returns the localized language name, e.g. "British English" |
108 | * \since 4.2 |
109 | */ |
110 | QString languageNameForCode(const QString &langCode) const; |
111 | |
112 | /*! |
113 | * Returns the SettingsImpl object used by the loader. |
114 | */ |
115 | SettingsImpl *settings() const; |
116 | Q_SIGNALS: |
117 | /*! |
118 | * Signal is emitted whenever the SettingsImpl object |
119 | * associated with this Loader changes. |
120 | */ |
121 | void configurationChanged(); |
122 | |
123 | /*! |
124 | * Emitted when loading a dictionary fails, so that Ui parts can |
125 | * display an appropriate error message informing the user about |
126 | * the issue. |
127 | * \a language the name of the dictionary that failed to be loaded |
128 | * \since 5.56 |
129 | */ |
130 | void loadingDictionaryFailed(const QString &language) const; |
131 | |
132 | protected: |
133 | friend class SettingsImpl; |
134 | void changed(); |
135 | |
136 | private: |
137 | SONNETCORE_NO_EXPORT void loadPlugins(); |
138 | SONNETCORE_NO_EXPORT void loadPlugin(const QString &pluginPath); |
139 | SONNETCORE_NO_EXPORT void loadPlugin(const QStaticPlugin &plugin); |
140 | SONNETCORE_NO_EXPORT void addClient(Sonnet::Client *client); |
141 | |
142 | private: |
143 | std::unique_ptr<LoaderPrivate> const d; |
144 | }; |
145 | } |
146 | |
147 | #endif // SONNET_LOADER_P_H |
148 | |