Changeset View
Changeset View
Standalone View
Standalone View
runners/dictionary/dictionarymatchengine.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2010, 2012 Jason A. Donenfeld <Jason@zx2c4.com> | 2 | * Copyright (C) 2010, 2012 Jason A. Donenfeld <Jason@zx2c4.com> | ||
3 | * Copyright (C) 2020 Alexander Lohnau <alexander.lohnau@gmx.de> | ||||
3 | */ | 4 | */ | ||
4 | 5 | | |||
5 | #include "dictionarymatchengine.h" | 6 | #include "dictionarymatchengine.h" | ||
6 | #include <KRunner/AbstractRunner> | 7 | #include <KRunner/AbstractRunner> | ||
7 | #include <QThread> | 8 | #include <QThread> | ||
8 | #include <QMetaMethod> | 9 | #include <QMetaMethod> | ||
9 | #include <QDebug> | 10 | #include <QDebug> | ||
10 | #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) | 11 | #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) | ||
11 | #include <QDeadlineTimer> | 12 | #include <QDeadlineTimer> | ||
12 | #endif | 13 | #endif | ||
13 | DictionaryMatchEngine::DictionaryMatchEngine(Plasma::DataEngine *dictionaryEngine, QObject *parent) | 14 | DictionaryMatchEngine::DictionaryMatchEngine(Plasma::DataEngine *dictionaryEngine, QObject *parent) | ||
14 | : QObject(parent), | 15 | : QObject(parent), | ||
15 | m_dictionaryEngine(dictionaryEngine) | 16 | m_dictionaryEngine(dictionaryEngine) | ||
16 | { | 17 | { | ||
17 | /* We have to connect source in two different places, due to the difference in | 18 | /* We have to connect source in two different places, due to the difference in | ||
18 | * how the connection is made based on data availability. There are two cases, | 19 | * how the connection is made based on data availability. There are two cases, | ||
19 | * and this extra connection handles the second case. */ | 20 | * and this extra connection handles the second case. */ | ||
20 | Q_ASSERT(m_dictionaryEngine); | 21 | Q_ASSERT(m_dictionaryEngine); | ||
21 | connect(m_dictionaryEngine, SIGNAL(sourceAdded(QString)), this, SLOT(sourceAdded(QString))); | 22 | connect(m_dictionaryEngine, &Plasma::DataEngine::sourceAdded, this, &DictionaryMatchEngine::sourceAdded); | ||
22 | } | 23 | } | ||
23 | 24 | | |||
24 | /* This function should be called from a different thread. */ | 25 | /* This function should be called from a different thread. */ | ||
25 | QString DictionaryMatchEngine::lookupWord(const QString &word) | 26 | QString DictionaryMatchEngine::lookupWord(const QString &word) | ||
26 | { | 27 | { | ||
27 | if (!m_dictionaryEngine) { | 28 | if (!m_dictionaryEngine) { | ||
28 | qDebug() << "Could not find dictionary data engine."; | 29 | qDebug() << "Could not find dictionary data engine."; | ||
29 | return QString(); | 30 | return QString(); | ||
Show All 39 Lines | |||||
69 | 70 | | |||
70 | void DictionaryMatchEngine::sourceRemoved(const QString &source) | 71 | void DictionaryMatchEngine::sourceRemoved(const QString &source) | ||
71 | { | 72 | { | ||
72 | m_dictionaryEngine->disconnectSource(source, this); | 73 | m_dictionaryEngine->disconnectSource(source, this); | ||
73 | } | 74 | } | ||
74 | 75 | | |||
75 | void DictionaryMatchEngine::dataUpdated(const QString &source, const Plasma::DataEngine::Data &result) | 76 | void DictionaryMatchEngine::dataUpdated(const QString &source, const Plasma::DataEngine::Data &result) | ||
76 | { | 77 | { | ||
77 | if (!result.contains(QLatin1String("text"))) | 78 | if (!result.contains(QStringLiteral("text"))){ | ||
78 | return; | 79 | return; | ||
80 | } | ||||
79 | 81 | | |||
80 | QString definition(result[QLatin1String("text")].toString()); | 82 | QString definition(result[QStringLiteral("text")].toString()); | ||
81 | 83 | | |||
82 | m_wordLock.lockForRead(); | 84 | m_wordLock.lockForRead(); | ||
83 | foreach (ThreadData *data, m_lockers.values(source)) { | 85 | for (ThreadData *data: m_lockers.values(source)) { | ||
sitter: I think our style is space before and after : | |||||
84 | QMutexLocker locker(&data->mutex); | 86 | QMutexLocker locker(&data->mutex); | ||
85 | /* Because of QString's CoW semantics, we don't have to worry about | 87 | /* Because of QString's CoW semantics, we don't have to worry about | ||
86 | * the overhead of assigning this to every item. */ | 88 | * the overhead of assigning this to every item. */ | ||
87 | data->definition = definition; | 89 | data->definition = definition; | ||
88 | data->waitCondition.wakeOne(); | 90 | data->waitCondition.wakeOne(); | ||
89 | } | 91 | } | ||
90 | m_wordLock.unlock(); | 92 | m_wordLock.unlock(); | ||
91 | } | 93 | } | ||
92 | 94 | |
I think our style is space before and after :