[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdeplasma-addons/frameworks] runners/dictionary: death to the tabs
From:       Marco Martin <notmart () gmail ! com>
Date:       2014-07-30 18:10:36
Message-ID: E1XCYKi-0008At-OS () scm ! kde ! org
[Download RAW message or body]

Git commit 91b851b201e70a62b36a5dd4898ff26af551bc7e by Marco Martin.
Committed on 30/07/2014 at 18:10.
Pushed by mart into branch 'frameworks'.

death to the tabs

M  +40   -40   runners/dictionary/dictionarymatchengine.cpp
M  +12   -12   runners/dictionary/dictionarymatchengine.h

http://commits.kde.org/kdeplasma-addons/91b851b201e70a62b36a5dd4898ff26af551bc7e

diff --git a/runners/dictionary/dictionarymatchengine.cpp \
b/runners/dictionary/dictionarymatchengine.cpp index 5d53e1c..bc966db 100644
--- a/runners/dictionary/dictionarymatchengine.cpp
+++ b/runners/dictionary/dictionarymatchengine.cpp
@@ -9,67 +9,67 @@
 #include <QDebug>
 
 DictionaryMatchEngine::DictionaryMatchEngine(Plasma::DataEngine *dictionaryEngine, \
                QObject *parent)
-	: QObject(parent),
-	  m_dictionaryEngine(dictionaryEngine)
+    : QObject(parent),
+      m_dictionaryEngine(dictionaryEngine)
 {
-	/* We have to connect source in two different places, due to the difference in
-	 * how the connection is made based on data availability. There are two cases,
-	 * and this extra connection handles the second case. */
-	connect(m_dictionaryEngine, SIGNAL(sourceAdded(QString)), this, \
SLOT(sourceAdded(QString))); +    /* We have to connect source in two different \
places, due to the difference in +     * how the connection is made based on data \
availability. There are two cases, +     * and this extra connection handles the \
second case. */ +    connect(m_dictionaryEngine, SIGNAL(sourceAdded(QString)), this, \
SLOT(sourceAdded(QString)));  }
 
 /* This function should be called from a different thread. */
 QString DictionaryMatchEngine::lookupWord(const QString &word)
 {
-	if (!m_dictionaryEngine) {
-		qDebug() << "Could not find dictionary data engine.";
-		return QString();
-	}
-	if (thread() == QThread::currentThread()) {
-		qDebug() << "DictionaryMatchEngine::lookupWord is only meant to be called from \
                non-primary threads.";
-		return QString();
-	}
+    if (!m_dictionaryEngine) {
+        qDebug() << "Could not find dictionary data engine.";
+        return QString();
+    }
+    if (thread() == QThread::currentThread()) {
+        qDebug() << "DictionaryMatchEngine::lookupWord is only meant to be called \
from non-primary threads."; +        return QString();
+    }
 
-	ThreadData data;
+    ThreadData data;
 
-	m_wordLock.lockForWrite();
-	m_lockers.insert(word, &data);
-	m_wordLock.unlock();
+    m_wordLock.lockForWrite();
+    m_lockers.insert(word, &data);
+    m_wordLock.unlock();
 
-	/* We lock it in this thread. Then we try to lock it again, which we cannot do, \
                until the other thread
-	 * unlocks it for us first. We time-out after 30 seconds. */
-	data.mutex.lock();
-	QMetaObject::invokeMethod(this, "sourceAdded", Qt::QueuedConnection, Q_ARG(const \
                QString&, QLatin1Char(':') + word));
-	if (!data.mutex.tryLock(30 * 1000))
-		qDebug() << "The dictionary data engine timed out.";
+    /* We lock it in this thread. Then we try to lock it again, which we cannot do, \
until the other thread +     * unlocks it for us first. We time-out after 30 seconds. \
*/ +    data.mutex.lock();
+    QMetaObject::invokeMethod(this, "sourceAdded", Qt::QueuedConnection, Q_ARG(const \
QString&, QLatin1Char(':') + word)); +    if (!data.mutex.tryLock(30 * 1000))
+        qDebug() << "The dictionary data engine timed out.";
 
-	m_wordLock.lockForWrite();
-	m_lockers.remove(word, &data);
-	m_wordLock.unlock();
+    m_wordLock.lockForWrite();
+    m_lockers.remove(word, &data);
+    m_wordLock.unlock();
 
-	return data.definition;
+    return data.definition;
 }
 
 void DictionaryMatchEngine::sourceAdded(const QString &source)
 {
-	m_dictionaryEngine->connectSource(source, this);
+    m_dictionaryEngine->connectSource(source, this);
 }
 
 void DictionaryMatchEngine::dataUpdated(const QString &source, const \
Plasma::DataEngine::Data &result)  {
-	if (!result.contains(QLatin1String("text")))
-		return;
+    if (!result.contains(QLatin1String("text")))
+        return;
 
-	QString definition(result[QLatin1String("text")].toString());
+    QString definition(result[QLatin1String("text")].toString());
 
-	m_wordLock.lockForRead();
-	foreach (ThreadData *data, m_lockers.values(source)) {
-		/* Because of QString's CoW semantics, we don't have to worry about
-		 * the overhead of assigning this to every item. */
-		data->definition = definition;
-		data->mutex.unlock();
-	}
-	m_wordLock.unlock();
+    m_wordLock.lockForRead();
+    foreach (ThreadData *data, m_lockers.values(source)) {
+        /* Because of QString's CoW semantics, we don't have to worry about
+         * the overhead of assigning this to every item. */
+        data->definition = definition;
+        data->mutex.unlock();
+    }
+    m_wordLock.unlock();
 }
 
 #include "dictionarymatchengine.moc"
diff --git a/runners/dictionary/dictionarymatchengine.h \
b/runners/dictionary/dictionarymatchengine.h index f6cb43b..19ed971 100644
--- a/runners/dictionary/dictionarymatchengine.h
+++ b/runners/dictionary/dictionarymatchengine.h
@@ -17,24 +17,24 @@ class RunnerContext;
 }
 class DictionaryMatchEngine : public QObject
 {
-	Q_OBJECT
+    Q_OBJECT
 
 public:
-	DictionaryMatchEngine(Plasma::DataEngine *dictionaryEngine, QObject *parent = 0);
-	QString lookupWord(const QString &word);
+    DictionaryMatchEngine(Plasma::DataEngine *dictionaryEngine, QObject *parent = \
0); +    QString lookupWord(const QString &word);
 
 private:
-	struct ThreadData {
-		QMutex mutex;
-		QString definition;
-	};
-	QMultiMap <QString, ThreadData*> m_lockers;
-	QReadWriteLock m_wordLock;
-	Plasma::DataEngine *m_dictionaryEngine;
+    struct ThreadData {
+        QMutex mutex;
+        QString definition;
+    };
+    QMultiMap <QString, ThreadData*> m_lockers;
+    QReadWriteLock m_wordLock;
+    Plasma::DataEngine *m_dictionaryEngine;
 
 private slots:
-	void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
-	void sourceAdded(const QString &source);
+    void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
+    void sourceAdded(const QString &source);
 
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic