00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "jobs.h"
00026 #include "internaljobs.h"
00027
00028 #include <kdebug.h>
00029 #include <KLocale>
00030
00031 namespace Kerfuffle
00032 {
00033 ListJob::ListJob( ReadOnlyArchiveInterface *interface, QObject *parent )
00034 : KJob( parent ), m_archive( interface )
00035 {
00036 }
00037
00038 void ListJob::start()
00039 {
00040 emit description( this, i18n( "Listing entries" ) );
00041 InternalListingJob *job = new InternalListingJob( m_archive, this );
00042
00043 connect( job, SIGNAL( entry( const ArchiveEntry& ) ),
00044 this, SIGNAL( newEntry( const ArchiveEntry & ) ) );
00045 connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
00046 this, SLOT( done( ThreadWeaver::Job* ) ) );
00047 connect( job, SIGNAL( progress( double ) ),
00048 this, SLOT( progress( double ) ) );
00049 ThreadWeaver::Weaver::instance()->enqueue( job );
00050 }
00051
00052 void ListJob::done( ThreadWeaver::Job *job )
00053 {
00054 emitResult();
00055 }
00056
00057 ExtractJob::ExtractJob( const QList<QVariant>& files, const QString& destinationDir,
00058 bool preservePaths, ReadOnlyArchiveInterface *interface, QObject *parent )
00059 : KJob( parent ), m_files( files ), m_destinationDir( destinationDir ), m_preservePaths( preservePaths ), m_archive( interface )
00060 {
00061 }
00062
00063 void ExtractJob::start()
00064 {
00065 QString desc;
00066 if ( m_files.count() == 0 )
00067 {
00068 desc = i18n( "Extracting all files" );
00069 }
00070 else
00071 {
00072 desc = i18np( "Extracting one file", "Extracting %1 files", m_files.count() );
00073 }
00074 emit description( this, desc );
00075 InternalExtractJob *job = new InternalExtractJob( m_archive, m_files, m_destinationDir, m_preservePaths, this );
00076
00077 connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
00078 this, SLOT( done( ThreadWeaver::Job* ) ) );
00079 connect( job, SIGNAL( progress( double ) ),
00080 this, SLOT( progress( double ) ) );
00081 connect( job, SIGNAL( error( const QString&, const QString& ) ),
00082 this, SLOT( error( const QString&, const QString& ) ) );
00083
00084 ThreadWeaver::Weaver::instance()->enqueue( job );
00085 }
00086
00087 void ExtractJob::done( ThreadWeaver::Job *job )
00088 {
00089 emitResult();
00090 }
00091
00092 void ExtractJob::progress( double p )
00093 {
00094 setPercent( static_cast<unsigned long>( 100.0*p ) );
00095 }
00096
00097 void ExtractJob::error( const QString& errorMessage, const QString& details )
00098 {
00099 Q_UNUSED( details );
00100 setError( 1 );
00101 setErrorText( errorMessage );
00102 }
00103
00104 void ListJob::progress( double p )
00105 {
00106 setPercent( static_cast<unsigned long>( 100.0*p ) );
00107 }
00108
00109 AddJob::AddJob( const QStringList & files, ReadWriteArchiveInterface *interface, QObject *parent )
00110 : KJob( parent ), m_files( files ), m_archive( interface )
00111 {
00112 }
00113
00114 void AddJob::start()
00115 {
00116 emit description( this, i18np( "Adding a file", "Adding %1 files", m_files.count() ) );
00117
00118 InternalAddJob *job = new InternalAddJob( m_archive, m_files, this );
00119
00120 connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
00121 this, SLOT( done( ThreadWeaver::Job* ) ) );
00122 connect( job, SIGNAL( progress( double ) ),
00123 this, SLOT( progress( double ) ) );
00124 connect( job, SIGNAL( entry( const ArchiveEntry& ) ),
00125 this, SIGNAL( newEntry( const ArchiveEntry & ) ) );
00126 connect( job, SIGNAL( error( const QString&, const QString& ) ),
00127 this, SLOT( error( const QString&, const QString& ) ) );
00128
00129 ThreadWeaver::Weaver::instance()->enqueue( job );
00130 }
00131
00132 void AddJob::done( ThreadWeaver::Job *job )
00133 {
00134 emitResult();
00135 }
00136
00137 void AddJob::progress( double p )
00138 {
00139 setPercent( static_cast<unsigned long>( 100.0*p ) );
00140 }
00141
00142 void AddJob::error( const QString& errorMessage, const QString& details )
00143 {
00144 kDebug( 1601 ) ;
00145 Q_UNUSED( details );
00146 setError( 1 );
00147 setErrorText( errorMessage );
00148 }
00149
00150 DeleteJob::DeleteJob( const QList<QVariant>& files, ReadWriteArchiveInterface *interface, QObject *parent )
00151 : KJob( parent ), m_files( files ), m_archive( interface )
00152 {
00153 }
00154
00155 void DeleteJob::start()
00156 {
00157 emit description( this, i18np( "Deleting a file from the archive", "Deleting %1 files", m_files.count() ) );
00158
00159 InternalDeleteJob *job = new InternalDeleteJob( m_archive, m_files, this );
00160
00161 connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
00162 this, SLOT( done( ThreadWeaver::Job* ) ) );
00163 connect( job, SIGNAL( progress( double ) ),
00164 this, SLOT( progress( double ) ) );
00165 connect( job, SIGNAL( entryRemoved( const QString& ) ),
00166 this, SIGNAL( entryRemoved( const QString& ) ) );
00167
00168 ThreadWeaver::Weaver::instance()->enqueue( job );
00169 }
00170
00171 void DeleteJob::done( ThreadWeaver::Job *job )
00172 {
00173 emitResult();
00174 }
00175
00176 void DeleteJob::progress( double p )
00177 {
00178 setPercent( static_cast<unsigned long>( 100.0*p ) );
00179 }
00180
00181 }