]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/InGuiThread.cpp
Make the InsetInfo dialog a bit less esoteric.
[lyx.git] / src / frontends / qt4 / InGuiThread.cpp
1 /**
2  * \file InGuiThread.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Peter Kümmel
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InGuiThread.h"
14
15 #include "frontends/Application.h"
16
17 #include <QThread>
18 #include <QEventLoop>
19 #include <QApplication>
20 #include <QMutexLocker>
21
22
23 namespace lyx {
24 namespace frontend {
25
26
27 IntoGuiThreadMover::IntoGuiThreadMover()
28 {
29 }
30
31
32 void IntoGuiThreadMover::callInGuiThread()
33 {
34         if (!theApp() || !QApplication::instance() ||
35                 QThread::currentThread() == QApplication::instance()->thread()) {
36                 synchronousFunctionCall();
37         } else {
38                 moveToThread(QApplication::instance()->thread());
39                 connect(this, SIGNAL(triggerFunctionCall()),
40                         this, SLOT(doFunctionCall()), Qt::QueuedConnection);
41                 QMutexLocker lock(&sync_mutex_);
42                 Q_EMIT triggerFunctionCall();
43                 condition_.wait(&sync_mutex_);
44         }
45 }
46
47
48 void IntoGuiThreadMover::doFunctionCall()
49 {
50         synchronousFunctionCall();
51         condition_.wakeOne();
52 }
53
54
55 } // namespace frontend
56 } // namespace lyx
57
58 #include "moc_InGuiThread.cpp"