mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 10:52:56 +00:00
use timers for QDeclarativeWorkerScriptEngine and QDeclarativePixmapReader if thread is not supported
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
a8ff5d36ee
commit
711de9e459
3 changed files with 92 additions and 3 deletions
|
@ -510,13 +510,23 @@ QDeclarativeError WorkerErrorEvent::error() const
|
|||
}
|
||||
|
||||
QDeclarativeWorkerScriptEngine::QDeclarativeWorkerScriptEngine(QDeclarativeEngine *parent)
|
||||
: QThread(parent), d(new QDeclarativeWorkerScriptEnginePrivate(parent))
|
||||
#ifndef QT_NO_THREAD
|
||||
: QThread(parent),
|
||||
#else
|
||||
: QObject(parent),
|
||||
#endif
|
||||
d(new QDeclarativeWorkerScriptEnginePrivate(parent))
|
||||
{
|
||||
d->m_lock.lock();
|
||||
connect(d, SIGNAL(stopThread()), this, SLOT(quit()), Qt::DirectConnection);
|
||||
#ifndef QT_NO_THREAD
|
||||
start(QThread::IdlePriority);
|
||||
d->m_wait.wait(&d->m_lock);
|
||||
d->moveToThread(this);
|
||||
#else
|
||||
d->workerEngine = new QDeclarativeWorkerScriptEnginePrivate::ScriptEngine(d);
|
||||
timerid = startTimer(500);
|
||||
#endif
|
||||
d->m_lock.unlock();
|
||||
}
|
||||
|
||||
|
@ -528,7 +538,11 @@ QDeclarativeWorkerScriptEngine::~QDeclarativeWorkerScriptEngine()
|
|||
QCoreApplication::postEvent(d, new QEvent((QEvent::Type)QDeclarativeWorkerScriptEnginePrivate::WorkerDestroyEvent));
|
||||
d->m_lock.unlock();
|
||||
|
||||
#ifndef QT_NO_THREAD
|
||||
wait();
|
||||
#else
|
||||
killTimer(timerid);
|
||||
#endif
|
||||
d->deleteLater();
|
||||
}
|
||||
|
||||
|
@ -565,6 +579,7 @@ void QDeclarativeWorkerScriptEngine::sendMessage(int id, const QVariant &data)
|
|||
QCoreApplication::postEvent(d, new WorkerDataEvent(id, data));
|
||||
}
|
||||
|
||||
#ifndef QT_NO_THREAD
|
||||
void QDeclarativeWorkerScriptEngine::run()
|
||||
{
|
||||
d->m_lock.lock();
|
||||
|
@ -579,7 +594,21 @@ void QDeclarativeWorkerScriptEngine::run()
|
|||
|
||||
delete d->workerEngine; d->workerEngine = 0;
|
||||
}
|
||||
#else
|
||||
void QDeclarativeWorkerScriptEngine::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (event->timerId() == timerid) {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void QDeclarativeWorkerScriptEngine::quit()
|
||||
{
|
||||
killTimer(timerid);
|
||||
timerid = -1;
|
||||
deleteLater();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\qmlclass WorkerScript QDeclarativeWorkerScript
|
||||
|
|
|
@ -59,7 +59,11 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
class QDeclarativeWorkerScript;
|
||||
class QDeclarativeWorkerScriptEnginePrivate;
|
||||
#ifndef QT_NO_THREAD
|
||||
class QDeclarativeWorkerScriptEngine : public QThread
|
||||
#else
|
||||
class QDeclarativeWorkerScriptEngine : public QObject
|
||||
#endif
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -72,9 +76,18 @@ public:
|
|||
void sendMessage(int, const QVariant &);
|
||||
|
||||
protected:
|
||||
#ifndef QT_NO_THREAD
|
||||
virtual void run();
|
||||
#else
|
||||
virtual void timerEvent(QTimerEvent *event);
|
||||
public Q_SLOTS:
|
||||
void quit();
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifdef QT_NO_THREAD
|
||||
int timerid;
|
||||
#endif
|
||||
QDeclarativeWorkerScriptEnginePrivate *d;
|
||||
};
|
||||
|
||||
|
|
|
@ -131,7 +131,11 @@ private:
|
|||
};
|
||||
|
||||
class QDeclarativePixmapData;
|
||||
#ifndef QT_NO_THREAD
|
||||
class QDeclarativePixmapReader : public QThread
|
||||
#else
|
||||
class QDeclarativePixmapReader : public QObject
|
||||
#endif
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -146,6 +150,9 @@ public:
|
|||
|
||||
protected:
|
||||
void run();
|
||||
#ifdef QT_NO_THREAD
|
||||
void timerEvent(QTimerEvent *event);
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend class QDeclarativePixmapReaderThreadObject;
|
||||
|
@ -156,7 +163,9 @@ private:
|
|||
QList<QDeclarativePixmapReply*> jobs;
|
||||
QList<QDeclarativePixmapReply*> cancelled;
|
||||
QDeclarativeEngine *engine;
|
||||
#ifndef QT_NO_THREAD
|
||||
QObject *eventLoopQuitHack;
|
||||
#endif
|
||||
|
||||
QMutex mutex;
|
||||
QDeclarativePixmapReaderThreadObject *threadObject;
|
||||
|
@ -167,6 +176,10 @@ private:
|
|||
|
||||
QHash<QNetworkReply*,QDeclarativePixmapReply*> replies;
|
||||
|
||||
#ifdef QT_NO_THREAD
|
||||
int timerid;
|
||||
#endif
|
||||
|
||||
static int replyDownloadProgress;
|
||||
static int replyFinished;
|
||||
static int downloadProgress;
|
||||
|
@ -309,16 +322,32 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
|
|||
}
|
||||
|
||||
QDeclarativePixmapReader::QDeclarativePixmapReader(QDeclarativeEngine *eng)
|
||||
: QThread(eng), engine(eng), threadObject(0), accessManager(0)
|
||||
#ifndef QT_NO_THREAD
|
||||
: QThread(eng),
|
||||
#else
|
||||
: QObject(eng),
|
||||
#endif
|
||||
engine(eng),
|
||||
threadObject(0),
|
||||
accessManager(0)
|
||||
{
|
||||
#ifndef QT_NO_THREAD
|
||||
eventLoopQuitHack = new QObject;
|
||||
eventLoopQuitHack->moveToThread(this);
|
||||
connect(eventLoopQuitHack, SIGNAL(destroyed(QObject*)), SLOT(quit()), Qt::DirectConnection);
|
||||
start(QThread::IdlePriority);
|
||||
#else
|
||||
run();
|
||||
timerid = startTimer(500);
|
||||
#endif
|
||||
}
|
||||
|
||||
QDeclarativePixmapReader::~QDeclarativePixmapReader()
|
||||
{
|
||||
#ifdef QT_NO_THREAD
|
||||
killTimer(timerid);
|
||||
#endif
|
||||
|
||||
readerMutex.lock();
|
||||
readers.remove(engine);
|
||||
readerMutex.unlock();
|
||||
|
@ -336,11 +365,19 @@ QDeclarativePixmapReader::~QDeclarativePixmapReader()
|
|||
reply->data = 0;
|
||||
}
|
||||
}
|
||||
if (threadObject) threadObject->processJobs();
|
||||
if (threadObject) {
|
||||
threadObject->processJobs();
|
||||
#ifdef QT_NO_THREAD
|
||||
delete threadObject;
|
||||
threadObject = 0;
|
||||
#endif
|
||||
}
|
||||
mutex.unlock();
|
||||
|
||||
#ifndef QT_NO_THREAD
|
||||
eventLoopQuitHack->deleteLater();
|
||||
wait();
|
||||
#endif
|
||||
}
|
||||
|
||||
void QDeclarativePixmapReader::networkRequestDone(QNetworkReply *reply)
|
||||
|
@ -566,13 +603,23 @@ void QDeclarativePixmapReader::run()
|
|||
threadObject = new QDeclarativePixmapReaderThreadObject(this);
|
||||
mutex.unlock();
|
||||
|
||||
#ifndef QT_NO_THREAD
|
||||
processJobs();
|
||||
exec();
|
||||
|
||||
delete threadObject;
|
||||
threadObject = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef QT_NO_THREAD
|
||||
void QDeclarativePixmapReader::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (event->timerId() == timerid)
|
||||
processJobs();
|
||||
}
|
||||
#endif
|
||||
|
||||
class QDeclarativePixmapKey
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue