2010-10-20 23:50:49 +00:00
|
|
|
/**
|
|
|
|
* \file InGuiThread.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Peter Kümmel
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2010-10-20 23:58:22 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2010-10-21 00:07:48 +00:00
|
|
|
#include "InGuiThread.h"
|
2010-10-20 23:50:49 +00:00
|
|
|
|
2010-11-01 21:32:59 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2010-10-20 23:50:49 +00:00
|
|
|
#include <QThread>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QApplication>
|
2010-10-21 21:29:08 +00:00
|
|
|
#include <QMutexLocker>
|
|
|
|
|
2010-10-20 23:50:49 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
IntoGuiThreadMover::IntoGuiThreadMover()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IntoGuiThreadMover::callInGuiThread()
|
|
|
|
{
|
2010-11-01 21:32:59 +00:00
|
|
|
if (!theApp() || !QApplication::instance() ||
|
|
|
|
QThread::currentThread() == QApplication::instance()->thread()) {
|
2010-10-20 23:50:49 +00:00
|
|
|
synchronousFunctionCall();
|
|
|
|
} else {
|
2010-11-01 21:32:59 +00:00
|
|
|
moveToThread(QApplication::instance()->thread());
|
2010-10-21 21:29:08 +00:00
|
|
|
connect(this, SIGNAL(triggerFunctionCall()),
|
|
|
|
this, SLOT(doFunctionCall()), Qt::QueuedConnection);
|
|
|
|
QMutexLocker lock(&sync_mutex_);
|
|
|
|
Q_EMIT triggerFunctionCall();
|
|
|
|
condition_.wait(&sync_mutex_);
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IntoGuiThreadMover::doFunctionCall()
|
|
|
|
{
|
|
|
|
synchronousFunctionCall();
|
2010-10-21 21:29:08 +00:00
|
|
|
condition_.wakeOne();
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2010-10-21 00:24:57 +00:00
|
|
|
#include "moc_InGuiThread.cpp"
|