Merge lp:~michael-sheldon/ubuntu-keyboard/fix-1448019 into lp:ubuntu-keyboard

Proposed by Michael Sheldon on 2015-04-29
Status: Merged
Approved by: Bill Filler on 2015-05-05
Approved revision: 359
Merged at revision: 360
Proposed branch: lp:~michael-sheldon/ubuntu-keyboard/fix-1448019
Merge into: lp:ubuntu-keyboard
Diff against target: 226 lines (+48/-44)
7 files modified
plugins/pinyin/src/pinyinadapter.cpp (+0/-16)
plugins/pinyin/src/pinyinplugin.cpp (+17/-2)
plugins/pinyin/src/pinyinplugin.h (+3/-0)
plugins/westernsupport/spellpredictworker.cpp (+6/-21)
plugins/westernsupport/spellpredictworker.h (+0/-2)
plugins/westernsupport/westernlanguagesplugin.cpp (+19/-3)
plugins/westernsupport/westernlanguagesplugin.h (+3/-0)
To merge this branch: bzr merge lp:~michael-sheldon/ubuntu-keyboard/fix-1448019
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2015-04-29
Ubuntu Phablet Team 2015-04-29 Pending
Review via email: mp+257783@code.launchpad.net

Commit Message

Discard spellcheck words that arrive whilst still processing outside of the spellcheck worker thread instead of as part of that thread

Description of the Change

Discard spellcheck words that arrive whilst still processing outside of the spellcheck worker thread instead of as part of that thread

To post a comment you must log in.
Michael Sheldon (michael-sheldon) wrote :

Are there any related MPs required for this MP to build/function as expected? Please list.

 * No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)

 * Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?

 * Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/ubuntu-keyboard) on device or emulator?

 * Yes

If you changed the UI, was the change specified/approved by design?

 * No change

If you changed UI labels, did you update the pot file?

 * No change

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?

 * No change

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/pinyin/src/pinyinadapter.cpp'
2--- plugins/pinyin/src/pinyinadapter.cpp 2015-02-17 17:23:09 +0000
3+++ plugins/pinyin/src/pinyinadapter.cpp 2015-04-29 15:50:17 +0000
4@@ -45,22 +45,6 @@
5
6 void PinyinAdapter::parse(const QString& string)
7 {
8- // Run through all the words queued in the event loop
9- // so we only fetch suggestions for the latest word
10- bool setProcessingWords = false;
11- if(m_processingWords == false) {
12- setProcessingWords = true;
13- m_processingWords = true;
14- }
15- QCoreApplication::processEvents();
16- if(setProcessingWords == true) {
17- m_processingWords = false;
18- }
19-
20- if(m_processingWords) {
21- return;
22- }
23-
24 pinyin_parse_more_full_pinyins(m_instance, string.toLatin1().data());
25
26 #ifdef PINYIN_DEBUG
27
28=== modified file 'plugins/pinyin/src/pinyinplugin.cpp'
29--- plugins/pinyin/src/pinyinplugin.cpp 2015-02-17 18:15:29 +0000
30+++ plugins/pinyin/src/pinyinplugin.cpp 2015-04-29 15:50:17 +0000
31@@ -6,12 +6,13 @@
32 PinyinPlugin::PinyinPlugin(QObject *parent) :
33 AbstractLanguagePlugin(parent)
34 , m_chineseLanguageFeatures(new ChineseLanguageFeatures)
35+ , m_processingWord(false)
36 {
37 m_pinyinThread = new QThread();
38 m_pinyinAdapter = new PinyinAdapter();
39 m_pinyinAdapter->moveToThread(m_pinyinThread);
40
41- connect(m_pinyinAdapter, SIGNAL(newPredictionSuggestions(QString, QStringList)), this, SIGNAL(newPredictionSuggestions(QString, QStringList)));
42+ connect(m_pinyinAdapter, SIGNAL(newPredictionSuggestions(QString, QStringList)), this, SLOT(finishedProcessing(QString, QStringList)));
43 connect(this, SIGNAL(parsePredictionText(QString)), m_pinyinAdapter, SLOT(parse(QString)));
44 connect(this, SIGNAL(candidateSelected(QString)), m_pinyinAdapter, SLOT(wordCandidateSelected(QString)));
45 m_pinyinThread->start();
46@@ -27,7 +28,11 @@
47 void PinyinPlugin::predict(const QString& surroundingLeft, const QString& preedit)
48 {
49 Q_UNUSED(surroundingLeft);
50- Q_EMIT parsePredictionText(preedit);
51+ m_nextWord = preedit;
52+ if (!m_processingWord) {
53+ m_processingWord = true;
54+ Q_EMIT parsePredictionText(preedit);
55+ }
56 }
57
58 void PinyinPlugin::wordCandidateSelected(QString word)
59@@ -39,3 +44,13 @@
60 {
61 return m_chineseLanguageFeatures;
62 }
63+
64+void PinyinPlugin::finishedProcessing(QString word, QStringList suggestions)
65+{
66+ Q_EMIT newPredictionSuggestions(word, suggestions);
67+ if (word != m_nextWord) {
68+ Q_EMIT(parsePredictionText(word));
69+ } else {
70+ m_processingWord = false;
71+ }
72+}
73
74=== modified file 'plugins/pinyin/src/pinyinplugin.h'
75--- plugins/pinyin/src/pinyinplugin.h 2015-04-13 10:54:12 +0000
76+++ plugins/pinyin/src/pinyinplugin.h 2015-04-29 15:50:17 +0000
77@@ -38,11 +38,14 @@
78 void candidateSelected(QString word);
79
80 public slots:
81+ void finishedProcessing(QString word, QStringList suggestions);
82
83 private:
84 QThread *m_pinyinThread;
85 PinyinAdapter *m_pinyinAdapter;
86 ChineseLanguageFeatures* m_chineseLanguageFeatures;
87+ QString m_nextWord;
88+ bool m_processingWord;
89 };
90
91 #endif // PINYINPLUGIN_H
92
93=== modified file 'plugins/westernsupport/spellpredictworker.cpp'
94--- plugins/westernsupport/spellpredictworker.cpp 2015-04-13 10:54:12 +0000
95+++ plugins/westernsupport/spellpredictworker.cpp 2015-04-29 15:50:17 +0000
96@@ -35,9 +35,7 @@
97 , m_presageCandidates(CandidatesCallback(m_candidatesContext))
98 , m_presage(&m_presageCandidates)
99 , m_spellChecker()
100- , m_word()
101 , m_limit(5)
102- , m_processingWords(false)
103 {
104 m_presage.config("Presage.Selector.SUGGESTIONS", "6");
105 m_presage.config("Presage.Selector.REPEAT_SUGGESTIONS", "yes");
106@@ -102,31 +100,18 @@
107
108 void SpellPredictWorker::suggest(const QString& word, int limit)
109 {
110+ QStringList suggestions;
111 if(!m_spellChecker.spell(word)) {
112- QStringList suggestions = m_spellChecker.suggest(word, limit);
113- Q_EMIT newSpellingSuggestions(word, suggestions);
114+ suggestions = m_spellChecker.suggest(word, limit);
115 }
116+ // If spelt correctly still send empty suggestions so the plugin knows we
117+ // have finished processing.
118+ Q_EMIT newSpellingSuggestions(word, suggestions);
119 }
120
121 void SpellPredictWorker::newSpellCheckWord(QString word)
122 {
123- // Run through all the words queued in the event loop
124- // so we only fetch suggestions for the latest word
125- bool setProcessingWords = false;
126- if(m_processingWords == false) {
127- setProcessingWords = true;
128- m_processingWords = true;
129- }
130- QCoreApplication::processEvents();
131- if(setProcessingWords == true) {
132- m_processingWords = false;
133- }
134-
135- m_word = word;
136-
137- if(!m_processingWords) {
138- suggest(m_word, m_limit);
139- }
140+ suggest(word, m_limit);
141 }
142
143 void SpellPredictWorker::addToUserWordList(const QString& word)
144
145=== modified file 'plugins/westernsupport/spellpredictworker.h'
146--- plugins/westernsupport/spellpredictworker.h 2015-04-13 10:54:12 +0000
147+++ plugins/westernsupport/spellpredictworker.h 2015-04-29 15:50:17 +0000
148@@ -63,9 +63,7 @@
149 CandidatesCallback m_presageCandidates;
150 Presage m_presage;
151 SpellChecker m_spellChecker;
152- QString m_word;
153 int m_limit;
154- bool m_processingWords;
155 QMap<QString, QString> m_overrides;
156 };
157
158
159=== modified file 'plugins/westernsupport/westernlanguagesplugin.cpp'
160--- plugins/westernsupport/westernlanguagesplugin.cpp 2015-04-13 10:54:12 +0000
161+++ plugins/westernsupport/westernlanguagesplugin.cpp 2015-04-29 15:50:17 +0000
162@@ -8,12 +8,13 @@
163 AbstractLanguagePlugin(parent)
164 , m_languageFeatures(new WesternLanguageFeatures)
165 , m_spellCheckEnabled(false)
166+ , m_processingSpelling(false)
167 {
168 m_spellPredictThread = new QThread();
169 m_spellPredictWorker = new SpellPredictWorker();
170 m_spellPredictWorker->moveToThread(m_spellPredictThread);
171
172- connect(m_spellPredictWorker, SIGNAL(newSpellingSuggestions(QString, QStringList)), this, SIGNAL(newSpellingSuggestions(QString, QStringList)));
173+ connect(m_spellPredictWorker, SIGNAL(newSpellingSuggestions(QString, QStringList)), this, SLOT(spellCheckFinishedProcessing(QString, QStringList)));
174 connect(m_spellPredictWorker, SIGNAL(newPredictionSuggestions(QString, QStringList)), this, SIGNAL(newPredictionSuggestions(QString, QStringList)));
175 connect(this, SIGNAL(newSpellCheckWord(QString)), m_spellPredictWorker, SLOT(newSpellCheckWord(QString)));
176 connect(this, SIGNAL(setSpellPredictLanguage(QString, QString)), m_spellPredictWorker, SLOT(setLanguage(QString, QString)));
177@@ -48,8 +49,14 @@
178
179 void WesternLanguagesPlugin::spellCheckerSuggest(const QString& word, int limit)
180 {
181- Q_EMIT setSpellCheckLimit(limit);
182- Q_EMIT newSpellCheckWord(word);
183+ m_nextSpellWord = word;
184+ // Don't accept new words whilst we're processing, so we only process the
185+ // most recent input once the current processing has completed
186+ if (!m_processingSpelling) {
187+ m_processingSpelling = true;
188+ Q_EMIT setSpellCheckLimit(limit);
189+ Q_EMIT newSpellCheckWord(word);
190+ }
191 }
192
193 void WesternLanguagesPlugin::addToSpellCheckerUserWordList(const QString& word)
194@@ -82,3 +89,12 @@
195 }
196 }
197 }
198+
199+void WesternLanguagesPlugin::spellCheckFinishedProcessing(QString word, QStringList suggestions) {
200+ Q_EMIT newSpellingSuggestions(word, suggestions);
201+ if (word != m_nextSpellWord) {
202+ Q_EMIT newSpellCheckWord(m_nextSpellWord);
203+ } else {
204+ m_processingSpelling = false;
205+ }
206+}
207
208=== modified file 'plugins/westernsupport/westernlanguagesplugin.h'
209--- plugins/westernsupport/westernlanguagesplugin.h 2015-04-13 10:54:12 +0000
210+++ plugins/westernsupport/westernlanguagesplugin.h 2015-04-29 15:50:17 +0000
211@@ -47,12 +47,15 @@
212 void addOverride(const QString& orig, const QString& overriden);
213
214 public slots:
215+ void spellCheckFinishedProcessing(QString word, QStringList suggestions);
216
217 private:
218 WesternLanguageFeatures* m_languageFeatures;
219 SpellPredictWorker *m_spellPredictWorker;
220 QThread *m_spellPredictThread;
221 bool m_spellCheckEnabled;
222+ QString m_nextSpellWord;
223+ bool m_processingSpelling;
224 };
225
226 #endif // WESTERNLANGUAGESPLUGIN_H

Subscribers

People subscribed via source and target branches