~ubuntu-branches/ubuntu/wily/sonnet/wily

« back to all changes in this revision

Viewing changes to src/core/loader.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Scarlett Clark, Jonathan Riddell
  • Date: 2015-10-07 14:00:43 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20151007140043-xwyl21j9rxyqn1pa
Tags: 5.15.0-0ubuntu1
[ Scarlett Clark ]
* Vivid backport

[ Jonathan Riddell ]
* new upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <QDebug>
32
32
#include <QtCore/QDir>
33
33
 
 
34
 
 
35
#ifdef SONNET_STATIC
 
36
#include "../plugins/hunspell/hunspellclient.h"
 
37
#ifdef Q_OS_MAC
 
38
#include "../plugins/nsspellchecker/nsspellcheckerclient.h"
 
39
#endif
 
40
#endif
 
41
 
 
42
 
34
43
namespace Sonnet
35
44
{
36
45
 
40
49
    Settings *settings;
41
50
 
42
51
    // <language, Clients with that language >
43
 
    QMap<QString, QList<Client *> > languageClients;
 
52
    QMap<QString, QVector<Client *> > languageClients;
44
53
    QStringList clients;
45
54
 
46
55
    QStringList languagesNameCache;
83
92
        plang = d->settings->defaultLanguage();
84
93
    }
85
94
 
86
 
    const QList<Client *> lClients = d->languageClients[plang];
 
95
    const QVector<Client *> lClients = d->languageClients[plang];
87
96
 
88
97
    if (lClients.isEmpty()) {
89
98
        qWarning() << "No language dictionaries for the language:" << plang;
90
99
        return 0;
91
100
    }
92
101
 
93
 
    QListIterator<Client *> itr(lClients);
 
102
    QVectorIterator<Client *> itr(lClients);
94
103
    while (itr.hasNext()) {
95
104
        Client *item = itr.next();
96
105
        if (!pclient.isEmpty()) {
235
244
    }
236
245
 
237
246
    QStringList allLocalizedDictionaries;
238
 
    const QStringList allDictionaries = languages();
239
 
 
240
 
    for (QStringList::ConstIterator it = allDictionaries.begin();
241
 
            it != allDictionaries.end(); ++it) {
242
 
        allLocalizedDictionaries.append(languageNameForCode(*it));
 
247
    Q_FOREACH (const QString& langCode, languages()) {
 
248
        allLocalizedDictionaries.append(languageNameForCode(langCode));
243
249
    }
244
250
    // cache the list
245
251
    d->languagesNameCache = allLocalizedDictionaries;
253
259
 
254
260
void Loader::loadPlugins()
255
261
{
 
262
#ifndef SONNET_STATIC
256
263
    const QStringList libPaths = QCoreApplication::libraryPaths() << QLatin1String(INSTALLATION_PLUGIN_PATH);
257
264
    const QLatin1String pathSuffix("/kf5/sonnet/");
258
265
    int plugins = 0;
269
276
    if (plugins == 0) {
270
277
        qWarning() << "Sonnet: No speller backends available!";
271
278
    }
 
279
#else
 
280
#ifdef Q_OS_MAC
 
281
    loadPlugin(QString());
 
282
#endif
 
283
    loadPlugin(QStringLiteral("Hunspell"));
 
284
#endif
272
285
}
273
286
 
274
287
void Loader::loadPlugin(const QString &pluginPath)
275
288
{
 
289
#ifndef SONNET_STATIC
276
290
    QPluginLoader plugin(pluginPath);
277
291
    if (!plugin.load()) { // We do this separately for better error handling
278
292
        qWarning() << "Sonnet: Unable to load plugin" << pluginPath << "Error:" << plugin.errorString();
285
299
        plugin.unload(); // don't leave it in memory
286
300
        return;
287
301
    }
 
302
#else
 
303
    Client *client = 0;
 
304
    if (pluginPath == QLatin1String("Hunspell"))
 
305
        client = new HunspellClient(this);
 
306
#ifdef Q_OS_MAC
 
307
    else
 
308
        client = new NSSpellCheckerClient(this);
 
309
#endif
 
310
#endif
288
311
 
289
312
    const QStringList languages = client->languages();
290
313
    d->clients.append(client->name());
291
314
 
292
315
    Q_FOREACH (const QString &language, languages) {
293
 
        QList<Client *> &languageClients = d->languageClients[language];
 
316
        QVector<Client *> &languageClients = d->languageClients[language];
294
317
 
295
 
        if (languageClients.isEmpty()) {
296
 
            languageClients.append(client);    // no clients yet, just add it
297
 
        } else if (client->reliability() < languageClients.first()->reliability()) {
 
318
        if (languageClients.isEmpty() || client->reliability() < languageClients.first()->reliability()) {
298
319
            languageClients.append(client);    // less reliable, to the end
299
320
        } else {
300
321
            languageClients.prepend(client);    // more reliable, to the front
309
330
 
310
331
}
311
332
 
312
 
#include "moc_loader_p.cpp"