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

source code of sonnet/src/core/loader_p.h