32 #include <QtCore/QHash>
33 #include <QtCore/QMap>
35 #define DEFAULT_CONFIG_FILE "sonnetrc"
57 if (s_loader.isDestroyed()) {
69 d->settings->restore(&config);
77 delete d->settings; d->settings = 0;
82 const QString& clientName)
const
87 if (plang.isEmpty()) {
88 plang = d->settings->defaultLanguage();
93 if (lClients.isEmpty()) {
94 kError()<<
"No language dictionaries for the language : "
99 QListIterator<Client*> itr(lClients);
100 while (itr.hasNext()) {
101 Client* item = itr.next();
102 if (!pclient.isEmpty()) {
103 if (pclient == item->
name()) {
125 return d->languageClients.keys();
130 QString currentDictionary = langCode,
136 QByteArray variantEnglish;
142 struct variantListType
144 const char* variantShortName;
145 const char* variantEnglishName;
148 const variantListType variantList[] = {
149 {
"40",
I18N_NOOP2(
"dictionary variant",
"40") },
150 {
"60",
I18N_NOOP2(
"dictionary variant",
"60") },
151 {
"80",
I18N_NOOP2(
"dictionary variant",
"80") },
152 {
"ise",
I18N_NOOP2(
"dictionary variant",
"-ise suffixes") },
153 {
"ize",
I18N_NOOP2(
"dictionary variant",
"-ize suffixes") },
154 {
"ise-w_accents",
I18N_NOOP2(
"dictionary variant",
"-ise suffixes and with accents") },
155 {
"ise-wo_accents",
I18N_NOOP2(
"dictionary variant",
"-ise suffixes and without accents") },
156 {
"ize-w_accents",
I18N_NOOP2(
"dictionary variant",
"-ize suffixes and with accents") },
157 {
"ize-wo_accents",
I18N_NOOP2(
"dictionary variant",
"-ize suffixes and without accents") },
158 {
"lrg",
I18N_NOOP2(
"dictionary variant",
"large") },
159 {
"med",
I18N_NOOP2(
"dictionary variant",
"medium") },
160 {
"sml",
I18N_NOOP2(
"dictionary variant",
"small") },
161 {
"variant_0",
I18N_NOOP2(
"dictionary variant",
"variant 0") },
162 {
"variant_1",
I18N_NOOP2(
"dictionary variant",
"variant 1") },
163 {
"variant_2",
I18N_NOOP2(
"dictionary variant",
"variant 2") },
164 {
"wo_accents",
I18N_NOOP2(
"dictionary variant",
"without accents") },
165 {
"w_accents",
I18N_NOOP2(
"dictionary variant",
"with accents") },
166 {
"ye",
I18N_NOOP2(
"dictionary variant",
"with ye") },
167 {
"yeyo",
I18N_NOOP2(
"dictionary variant",
"with yeyo") },
168 {
"yo",
I18N_NOOP2(
"dictionary variant",
"with yo") },
169 {
"extended",
I18N_NOOP2(
"dictionary variant",
"extended") },
173 minusPos = currentDictionary.indexOf(QLatin1Char(
'-'));
174 underscorePos = currentDictionary.indexOf(QLatin1Char(
'_'));
175 if (underscorePos != -1 && underscorePos <= 3) {
176 cISOName = currentDictionary.mid(underscorePos + 1, 2);
177 lISOName = currentDictionary.left(underscorePos);
178 if ( minusPos != -1 )
179 variantName = currentDictionary.right(
180 currentDictionary.length() - minusPos - 1);
182 if ( minusPos != -1 ) {
183 variantName = currentDictionary.right(
184 currentDictionary.length() - minusPos - 1);
185 lISOName = currentDictionary.left(minusPos);
188 lISOName = currentDictionary;
191 if (localizedLang.isEmpty())
192 localizedLang = lISOName;
193 if (!cISOName.isEmpty()) {
197 localizedCountry = cISOName;
199 if (!variantName.isEmpty()) {
200 while (variantList[variantCount].variantShortName != 0)
201 if (QLatin1String(variantList[variantCount].variantShortName) == variantName)
205 if (variantList[variantCount].variantShortName != 0)
206 variantEnglish = variantList[variantCount].variantEnglishName;
208 variantEnglish = variantName.toLatin1();
210 if (!cISOName.isEmpty() && !variantName.isEmpty())
212 "dictionary name. %1-language, %2-country and %3 variant name",
213 "%1 (%2) [%3]", localizedLang, localizedCountry,
214 i18nc(
"dictionary variant", variantEnglish));
215 else if (!cISOName.isEmpty())
217 "dictionary name. %1-language and %2-country name",
218 "%1 (%2)", localizedLang, localizedCountry);
219 else if (!variantName.isEmpty())
221 "dictionary name. %1-language and %2-variant name",
222 "%1 [%2]", localizedLang,
223 i18nc(
"dictionary variant", variantEnglish));
225 return localizedLang;
233 if (d->languagesNameCache.count() ==
languages().count() )
234 return d->languagesNameCache;
239 for (QStringList::ConstIterator it = allDictionaries.begin();
240 it != allDictionaries.end(); ++it) {
244 d->languagesNameCache = allLocalizedDictionaries;
245 return allLocalizedDictionaries;
253 void Loader::loadPlugins()
257 for (KService::List::const_iterator itr = d->plugins.constBegin();
258 itr != d->plugins.constEnd(); ++itr ) {
273 d->clients.append(client->name());
275 for (QStringList::const_iterator itr = languages.begin();
276 itr != languages.end(); ++itr) {
277 if (!d->languageClients[*itr].isEmpty() &&
278 client->reliability() <
279 d->languageClients[*itr].first()->reliability())
280 d->languageClients[*itr].append(client);
282 d->languageClients[*itr].prepend(client);
298 #include "loader_p.moc"
void configurationChanged()
Signal is emitted whenever the Settings object associated with this Loader changes.
virtual SpellerPlugin * createSpeller(const QString &language)=0
Returns a dictionary for the given language.
#define I18N_NOOP2(comment, x)
If the string is too ambiguous to be translated well to a non-english language, use this instead of I...
static KServiceTypeTrader * self()
This is a static pointer to the KServiceTypeTrader singleton.
#define K_GLOBAL_STATIC(TYPE, NAME)
This macro makes it easy to use non-POD types as global statics.
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QString countryCodeToName(const QString &country) const
Convert a known country code to a human readable, localized form.
virtual QString name() const =0
QString languageCodeToName(const QString &language) const
Convert a known language code to a human readable, localized form.
QString i18nc(const char *ctxt, const char *text)
Returns a localized version of a string and a context.
KSharedConfigPtr config()
Returns the general config object.
QStringList clients() const
Returns names of all supported clients (e.g.
QStringList languageNames() const
Returns a localized list of names of supported languages.
QStringList languages() const
Returns a list of supported languages.
Class is returned by from Loader.
KLocale * locale()
Returns the global locale object.
KService::List query(const QString &servicetype, const QString &constraint=QString()) const
The main function in the KServiceTypeTrader class.
The central class of the KDE configuration data system.
Settings * settings() const
Returns the Settings object used by the loader.
QString languageNameForCode(const QString &langCode) const
SpellerPlugin * createSpeller(const QString &language=QString(), const QString &client=QString()) const
Returns dictionary for the given language and preferred client.
Class used to deal with dictionaries.
T * createInstance(QObject *parent=0, const QVariantList &args=QVariantList(), QString *error=0) const
This template allows to load the library for the specified service and ask the factory to create an i...
#define DEFAULT_CONFIG_FILE
Copyright (C) 2003 Zack Rusin zack@kde.org