aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard/hunspellworker.h
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2015-03-25 10:08:02 +0200
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2015-06-17 12:35:27 +0300
commit1d5eae310178006383a298156bdb134beffca36b (patch)
treec49abdb16c05cf01c22335b5a3cf69ba4037f0fc /src/virtualkeyboard/hunspellworker.h
parenta6333e2fedb2798f62c7cee16a3634707b6b52d5 (diff)
Move Hunspell dictionary loading to worker thread
This change moves the Hunspell dictionary loading to worker thread. The dictionary loading is relatively heavy task for large dictionary files, such as Arabic, which can take more than 2 seconds to load on the Nexus 7 hardware. The Hunspell worker thread is no longer destroyed and created every time the dictionary changes, instead the worker thread is re-used. The dictionary loading happens by adding a new kind of task for the worker thread. Also, added a special function for clearing all but dictionary loading tasks from the worker task queue. This is needed for a special case where the dictionary is still loading while the user starts typing. Updated the test cases to take into account changes in delays in loading the dictionary. Change-Id: If9be14c7703b39af79f6e3b6708e297a28c49f2f Reviewed-by: Gatis Paeglis <gatis.paeglis@theqtcompany.com>
Diffstat (limited to 'src/virtualkeyboard/hunspellworker.h')
-rw-r--r--src/virtualkeyboard/hunspellworker.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/virtualkeyboard/hunspellworker.h b/src/virtualkeyboard/hunspellworker.h
index 789cd6e3..38cc59d8 100644
--- a/src/virtualkeyboard/hunspellworker.h
+++ b/src/virtualkeyboard/hunspellworker.h
@@ -40,6 +40,19 @@ public:
Hunhandle *hunspell;
};
+class HunspellLoadDictionaryTask : public HunspellTask
+{
+ Q_OBJECT
+public:
+ explicit HunspellLoadDictionaryTask(const QString &locale, const QStringList &searchPaths);
+
+ void run();
+
+ Hunhandle **hunspellPtr;
+ const QString locale;
+ const QStringList searchPaths;
+};
+
class HunspellWordList
{
public:
@@ -85,16 +98,32 @@ class HunspellWorker : public QThread
{
Q_OBJECT
public:
- explicit HunspellWorker(Hunhandle *hunspell, QObject *parent = 0);
+ explicit HunspellWorker(QObject *parent = 0);
~HunspellWorker();
void addTask(QSharedPointer<HunspellTask> task);
void removeAllTasks();
+ template <class X>
+ void removeAllTasksExcept() {
+ QMutexLocker guard(&taskLock);
+ for (int i = 0; i < taskList.size();) {
+ QSharedPointer<X> task(taskList[i].objectCast<X>());
+ if (!task)
+ taskList.removeAt(i);
+ else
+ i++;
+ }
+ }
+
protected:
void run();
private:
+ void createHunspell();
+
+private:
+ friend class HunspellLoadDictionaryTask;
QList<QSharedPointer<HunspellTask> > taskList;
QSemaphore taskSema;
QMutex taskLock;