Changeset View
Changeset View
Standalone View
Standalone View
runners/spellchecker/spellcheck.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | { | 49 | { | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | void SpellCheckRunner::init() | 52 | void SpellCheckRunner::init() | ||
53 | { | 53 | { | ||
54 | Plasma::AbstractRunner::init(); | 54 | Plasma::AbstractRunner::init(); | ||
55 | 55 | | |||
56 | //Connect prepare and teardown signals | 56 | //Connect prepare and teardown signals | ||
57 | connect(this, SIGNAL(prepare()), this, SLOT(loaddata())); | 57 | connect(this, &SpellCheckRunner::prepare, this, &SpellCheckRunner::loaddata); | ||
58 | connect(this, SIGNAL(teardown()), this, SLOT(destroydata())); | 58 | connect(this, &SpellCheckRunner::teardown, this, &SpellCheckRunner::destroydata); | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | //Load a default dictionary and some locale names | 61 | //Load a default dictionary and some locale names | ||
62 | void SpellCheckRunner::loaddata() | 62 | void SpellCheckRunner::loaddata() | ||
63 | { | 63 | { | ||
64 | //Load the default speller, with the default language | 64 | //Load the default speller, with the default language | ||
65 | auto defaultSpellerIt = m_spellers.find(QString()); | 65 | auto defaultSpellerIt = m_spellers.find(QString()); | ||
66 | if (defaultSpellerIt == m_spellers.end()) { | 66 | if (defaultSpellerIt == m_spellers.end()) { | ||
67 | defaultSpellerIt = m_spellers.insert(QString(), QSharedPointer<Sonnet::Speller> (new Sonnet::Speller(QString()))); | 67 | defaultSpellerIt = m_spellers.insert(QString(), QSharedPointer<Sonnet::Speller> (new Sonnet::Speller(QString()))); | ||
68 | } | 68 | } | ||
69 | auto& defaultSpeller = defaultSpellerIt.value(); | 69 | auto& defaultSpeller = defaultSpellerIt.value(); | ||
70 | 70 | | |||
71 | //store all language names, makes it possible to type "spell german TERM" if english locale is set | 71 | //store all language names, makes it possible to type "spell german TERM" if english locale is set | ||
72 | //Need to construct a map between natual language names and names the spell-check recognises. | 72 | //Need to construct a map between natual language names and names the spell-check recognises. | ||
73 | const QStringList avail = defaultSpeller->availableLanguages(); | 73 | const QStringList avail = defaultSpeller->availableLanguages(); | ||
74 | //We need to filter the available languages so that we associate the natural language | 74 | //We need to filter the available languages so that we associate the natural language | ||
75 | //name (eg. 'german') with one sub-code. | 75 | //name (eg. 'german') with one sub-code. | ||
76 | QSet<QString> families; | 76 | QSet<QString> families; | ||
77 | //First get the families | 77 | //First get the families | ||
78 | foreach (const QString &code, avail) { | 78 | for (const QString &code: avail) { | ||
79 | families +=code.left(2); | 79 | families +=code.left(2); | ||
80 | } | 80 | } | ||
81 | //Now for each family figure out which is the main code. | 81 | //Now for each family figure out which is the main code. | ||
82 | foreach (const QString &fcode,families) { | 82 | for (const QString &fcode: qAsConst(families)) { | ||
83 | QStringList family = avail.filter(fcode); | 83 | const QStringList family = avail.filter(fcode); | ||
84 | QString code; | 84 | QString code; | ||
85 | //If we only have one code, use it. | 85 | //If we only have one code, use it. | ||
86 | //If a string is the default language, use it | 86 | //If a string is the default language, use it | ||
87 | if (family.contains(defaultSpeller->language())) { | 87 | if (family.contains(defaultSpeller->language())) { | ||
88 | code = defaultSpeller->language(); | 88 | code = defaultSpeller->language(); | ||
89 | } else if (fcode == QLatin1String("en")) { | 89 | } else if (fcode == QLatin1String("en")) { | ||
90 | //If the family is english, default to en_US. | 90 | //If the family is english, default to en_US. | ||
91 | const auto enUS = QStringLiteral("en_US"); | 91 | const auto enUS = QStringLiteral("en_US"); | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 121 | { | |||
137 | syns << s; | 137 | syns << s; | ||
138 | setSyntaxes(syns); | 138 | setSyntaxes(syns); | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | /* Take the input query, split into a list, and see if it contains a language to spell in. | 141 | /* Take the input query, split into a list, and see if it contains a language to spell in. | ||
142 | * Return the empty string if we can't match a language. */ | 142 | * Return the empty string if we can't match a language. */ | ||
143 | QString SpellCheckRunner::findlang(const QStringList& terms) | 143 | QString SpellCheckRunner::findlang(const QStringList& terms) | ||
144 | { | 144 | { | ||
145 | auto defaultSpeller = m_spellers[QString()]; | 145 | auto &defaultSpeller = m_spellers[QString()]; | ||
davidedmundson: Const auto &
| |||||
146 | //If first term is a language code (like en_GB), set it as the spell-check language | 146 | //If first term is a language code (like en_GB), set it as the spell-check language | ||
147 | if (terms.count() >= 1 && defaultSpeller->availableLanguages().contains(terms[0])) { | 147 | if (terms.count() >= 1 && defaultSpeller->availableLanguages().contains(terms[0])) { | ||
148 | return terms[0]; | 148 | return terms[0]; | ||
149 | } | 149 | } | ||
150 | //If we have two terms and the first is a language name (eg 'french'), | 150 | //If we have two terms and the first is a language name (eg 'french'), | ||
151 | //set it as the available language | 151 | //set it as the available language | ||
152 | else if (terms.count() >=2) { | 152 | else if (terms.count() >=2) { | ||
153 | QString code; | 153 | QString code; | ||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |
Const auto &