Commit 1016bed5 authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Moved threading support to a separate ThreadExecution class. Made all jobs a...

Moved threading support to a separate ThreadExecution class. Made all jobs a subclass of Kerfuffle::Job

svn path=/trunk/KDE/kdeutils/ark/; revision=859539
parent 5e12c14c
......@@ -15,6 +15,7 @@ set(kerfuffle_SRCS
archiveinterface.cpp
internaljobs.cpp
jobs.cpp
threading.cpp
archivebase.cpp
extractiondialog.cpp
queries.cpp
......
......@@ -24,6 +24,7 @@
*/
#include "jobs.h"
#include "internaljobs.h"
#include "threading.h"
#include <kdebug.h>
#include <KLocale>
......@@ -31,15 +32,30 @@
namespace Kerfuffle
{
Job::Job(ReadOnlyArchiveInterface *interface, QObject *parent)
: KJob(parent),
m_interface(interface)
{
}
void Job::start()
{
ThreadExecution *thread = new ThreadExecution(this);
ThreadWeaver::Weaver::instance()->enqueue( thread );
}
ListJob::ListJob( ReadOnlyArchiveInterface *interface, QObject *parent )
: KJob( parent ), m_archive( interface ),
: Job( interface, parent ), m_archive( interface ),
m_isSingleFolderArchive(true),
m_isPasswordProtected(false),
m_extractedFilesSize(0)
{
}
void ListJob::start()
void ListJob::doWork()
{
emit description( this, i18n( "Listing entries" ) );
InternalListingJob *job = new InternalListingJob( m_archive, this );
......@@ -98,11 +114,11 @@ namespace Kerfuffle
ExtractJob::ExtractJob( const QList<QVariant>& files, const QString& destinationDir,
Archive::CopyFlags flags, ReadOnlyArchiveInterface *interface, QObject *parent )
: KJob( parent ), m_files( files ), m_destinationDir( destinationDir ), m_flags(flags), m_archive( interface )
: Job(interface, parent ), m_files( files ), m_destinationDir( destinationDir ), m_flags(flags), m_archive( interface )
{
}
void ExtractJob::start()
void ExtractJob::doWork()
{
QString desc;
if ( m_files.count() == 0 )
......@@ -150,11 +166,11 @@ namespace Kerfuffle
}
AddJob::AddJob( const QString& path, const QStringList & files, ReadWriteArchiveInterface *interface, QObject *parent )
: KJob( parent ), m_files( files ), m_path(path), m_archive( interface )
: Job( interface, parent ), m_files( files ), m_path(path), m_archive( interface )
{
}
void AddJob::start()
void AddJob::doWork()
{
emit description( this, i18np( "Adding a file", "Adding %1 files", m_files.count() ) );
......@@ -194,11 +210,11 @@ namespace Kerfuffle
}
DeleteJob::DeleteJob( const QList<QVariant>& files, ReadWriteArchiveInterface *interface, QObject *parent )
: KJob( parent ), m_files( files ), m_archive( interface )
: Job( interface, parent ), m_files( files ), m_archive( interface )
{
}
void DeleteJob::start()
void DeleteJob::doWork()
{
emit description( this, i18np( "Deleting a file from the archive", "Deleting %1 files", m_files.count() ) );
......
......@@ -42,22 +42,41 @@ namespace ThreadWeaver
namespace Kerfuffle
{
class KERFUFFLE_EXPORT ListJob: public KJob
class KERFUFFLE_EXPORT Job: public KJob
{
Q_OBJECT
//we friend the Archive class to let it create jobs
friend class Archive;
public:
void start();
virtual void doWork() = 0;
signals:
void userQuery( Query* );
void newEntry( const ArchiveEntry & );
void error( const QString& errorMessage, const QString& details );
protected:
Job(ReadOnlyArchiveInterface *interface, QObject *parent = 0);
private:
ReadOnlyArchiveInterface* m_interface;
};
class KERFUFFLE_EXPORT ListJob: public Job
{
Q_OBJECT
public:
explicit ListJob( ReadOnlyArchiveInterface *interface, QObject *parent = 0 );
void start();
void doWork();
bool isSingleFolderArchive() { return m_isSingleFolderArchive; }
bool isPasswordProtected() { return m_isPasswordProtected; }
QString subfolderName() { return m_subfolderName; }
qlonglong extractedFilesSize() { return m_extractedFilesSize; }
signals:
void newEntry( const ArchiveEntry & );
void error( const QString& errorMessage, const QString& details );
private slots:
void done( ThreadWeaver::Job* );
void progress( double );
......@@ -73,16 +92,13 @@ namespace Kerfuffle
qlonglong m_extractedFilesSize;
};
class KERFUFFLE_EXPORT ExtractJob: public KJob
class KERFUFFLE_EXPORT ExtractJob: public Job
{
Q_OBJECT
public:
ExtractJob( const QList<QVariant> & files, const QString& destinationDir, Archive::CopyFlags flags, ReadOnlyArchiveInterface *interface, QObject *parent = 0 );
void start();
signals:
void userQuery( Query* );
void doWork();
private slots:
void done( ThreadWeaver::Job * );
......@@ -96,17 +112,13 @@ namespace Kerfuffle
ReadOnlyArchiveInterface *m_archive;
};
class KERFUFFLE_EXPORT AddJob: public KJob
class KERFUFFLE_EXPORT AddJob: public Job
{
Q_OBJECT
public:
AddJob(const QString& path, const QStringList & files, ReadWriteArchiveInterface *interface, QObject *parent = 0 );
void start();
signals:
void newEntry( const ArchiveEntry & );
void userQuery( Query* );
void doWork();
private slots:
void done( ThreadWeaver::Job * );
......@@ -120,18 +132,16 @@ namespace Kerfuffle
};
class KERFUFFLE_EXPORT DeleteJob: public KJob
class KERFUFFLE_EXPORT DeleteJob: public Job
{
Q_OBJECT
public:
DeleteJob( const QList<QVariant>& files, ReadWriteArchiveInterface *interface, QObject *parent = 0 );
void start();
void doWork();
signals:
void entryRemoved( const QString & entry );
void error( const QString& errorMessage, const QString& details );
void userQuery( Query* );
private slots:
void done( ThreadWeaver::Job * );
......
/*
* Copyright (c) 2008 Harald Hvaal <haraldhv )@@@( stud(dot)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"
namespace Kerfuffle
{
ThreadExecution::ThreadExecution(Kerfuffle::Job *job)
: m_job(job)
{
}
void ThreadExecution::run()
{
//perform the work in this thread!
m_job->doWork();
}
}
/*
* Copyright (c) 2008 Harald Hvaal <haraldhv )@@@( stud(dot)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 <ThreadWeaver/Job>
#include <ThreadWeaver/Weaver>
#include "jobs.h"
namespace Kerfuffle
{
class ThreadExecution : public ThreadWeaver::Job
{
public:
ThreadExecution(Kerfuffle::Job *job);
private:
void run();
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