Commit 363cf102 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa
Browse files

Move our worker thread to a d-pointer in our Job class.

It was only used by the Job classes, so it's easier to just put it into
a d-pointer in Job.

svn path=/trunk/KDE/kdeutils/ark/; revision=1154161
parent 4ae974da
......@@ -12,7 +12,6 @@ set(kerfuffle_SRCS
archive.cpp
archiveinterface.cpp
jobs.cpp
threading.cpp
archivebase.cpp
extractiondialog.cpp
adddialog.cpp
......
......@@ -26,23 +26,46 @@
*/
#include "jobs.h"
#include "threading.h"
#include <QApplication>
#include <QDir>
#include <QTimer>
#include <QThread>
#include <KDebug>
#include <KLocale>
//#define DEBUG_RACECONDITION
namespace Kerfuffle
{
class Job::Private : public QThread
{
public:
virtual void run();
Job *q;
};
void Job::Private::run()
{
connect(q, SIGNAL(result(KJob*)), this, SLOT(quit()), Qt::DirectConnection);
QMetaObject::invokeMethod(q, "doWork", Qt::DirectConnection);
exec();
#ifdef DEBUG_RACECONDITION
QThread::sleep(2);
#endif
}
Job::Job(ReadOnlyArchiveInterface *interface, QObject *parent)
: KJob(parent)
, m_interface(interface)
, m_workerThread(0)
, d(new Private())
{
d->q = this;
static bool onlyOnce = false;
if (!onlyOnce) {
qRegisterMetaType<QPair<QString, QString> >("QPair<QString,QString>");
......@@ -54,18 +77,16 @@ Job::Job(ReadOnlyArchiveInterface *interface, QObject *parent)
Job::~Job()
{
if (m_workerThread) {
m_workerThread->wait();
if (d->isRunning()) {
d->wait();
}
delete m_workerThread;
m_workerThread = 0;
delete d;
}
void Job::start()
{
m_workerThread = new ThreadExecution(this);
m_workerThread->start();
d->start();
}
void Job::onError(const QString & message, const QString & details)
......
......@@ -67,9 +67,6 @@ protected:
ReadOnlyArchiveInterface *m_interface;
private:
ThreadExecution *m_workerThread;
public slots:
virtual void doWork() = 0;
......@@ -78,6 +75,10 @@ signals:
void error(const QString& errorMessage, const QString& details);
void newEntry(const ArchiveEntry &);
void userQuery(Kerfuffle::Query*);
private:
class Private;
Private * const d;
};
class KERFUFFLE_EXPORT ListJob : public Job
......
/*
* Copyright (c) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "threading.h"
#include <KDebug>
#include <QTimer>
//#define DEBUG_RACECONDITION
namespace Kerfuffle
{
ThreadExecution::ThreadExecution(Kerfuffle::Job *job)
: m_job(job)
{
}
void ThreadExecution::run()
{
connect(m_job, SIGNAL(result(KJob*)), this, SLOT(quit()), Qt::DirectConnection);
QTimer doWorkTimer;
doWorkTimer.setSingleShot(true);
connect(&doWorkTimer, SIGNAL(timeout()), m_job, SLOT(doWork()), Qt::DirectConnection);
doWorkTimer.start(0);
exec();
#ifdef DEBUG_RACECONDITION
QThread::sleep(2);
#endif
}
}
#include "threading.moc"
/*
* Copyright (c) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THREADING_H
#define THREADING_H
#include "jobs.h"
#include <QThread>
namespace Kerfuffle
{
class ThreadExecution : public QThread
{
Q_OBJECT
public:
ThreadExecution(Kerfuffle::Job *job);
protected:
void run();
private:
Kerfuffle::Job *m_job;
};
}
#endif /* THREADING_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment