Commit 38250503 authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Introduced a Flag parameter for extraction, giving more readable code for...

Introduced a Flag parameter for extraction, giving more readable code for calling Copyfiles, as well as it being more easy to add new parameters without touching everywhere in the code like I did now :)

svn path=/trunk/KDE/kdeutils/ark/; revision=850437
parent f44db798
......@@ -52,10 +52,14 @@ void BatchExtractJob::addExtraction(Kerfuffle::Archive* archive,bool preservePat
}
}
Kerfuffle::Archive::CopyFlags flags;
if (preservePaths)
flags |= Kerfuffle::Archive::PreservePaths;
Kerfuffle::ExtractJob *job = archive->copyFiles(
QVariantList(), //extract all files
autoDestination, //extract to folder
preservePaths //preserve paths
flags
);
connect(job, SIGNAL(userQuery(Query*)),
......
......@@ -51,6 +51,13 @@ namespace Kerfuffle
class KERFUFFLE_EXPORT Archive
{
public:
enum CopyFlag {
PreservePaths = 0x0,
TruncateCommonBase = 0x1
};
Q_DECLARE_FLAGS(CopyFlags, CopyFlag);
virtual ~Archive() {}
virtual QString fileName() = 0;
......@@ -61,7 +68,7 @@ namespace Kerfuffle
virtual ListJob* list() = 0;
virtual DeleteJob* deleteFiles( const QList<QVariant> & files ) = 0;
virtual AddJob* addFiles( const QStringList & files ) = 0;
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, bool preservePaths = false ) = 0;
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags) = 0;
virtual bool isSingleFolderArchive() = 0;
virtual QString subfolderName() = 0;
......@@ -71,6 +78,8 @@ namespace Kerfuffle
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Archive::CopyFlags);
KERFUFFLE_EXPORT Archive* factory( const QString & filename, const QString & requestedMimeType = QString() );
KERFUFFLE_EXPORT QStringList supportedMimeTypes();
KERFUFFLE_EXPORT QStringList supportedWriteMimeTypes();
......
......@@ -105,9 +105,9 @@ namespace Kerfuffle
return newJob;
}
ExtractJob* ArchiveBase::copyFiles( const QList<QVariant> & files, const QString & destinationDir, bool preservePaths )
ExtractJob* ArchiveBase::copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags )
{
ExtractJob *newJob = new ExtractJob( files, destinationDir, preservePaths, m_iface, this );
ExtractJob *newJob = new ExtractJob( files, destinationDir, flags, m_iface, this );
connect(m_iface, SIGNAL(userQuery(Query*)),
newJob, SIGNAL(userQuery(Query*)));
return newJob;
......
......@@ -55,7 +55,7 @@ namespace Kerfuffle
virtual ListJob* list();
virtual DeleteJob* deleteFiles( const QList<QVariant> & files );
virtual AddJob* addFiles( const QStringList & files );
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, bool preservePaths = false );
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags );
virtual bool isReadOnly();
virtual QString fileName();
......
......@@ -53,7 +53,7 @@ namespace Kerfuffle
virtual bool open() { return true; }
virtual bool list() = 0;
virtual bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths ) = 0;
virtual bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags ) = 0;
void setPassword(QString password) { m_password = password; }
protected:
......
......@@ -61,9 +61,9 @@ namespace Kerfuffle
setSuccess( m_helper->getTheListing() );
}
InternalExtractJob::InternalExtractJob( ReadOnlyArchiveInterface *archive, const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths, QObject *parent )
InternalExtractJob::InternalExtractJob( ReadOnlyArchiveInterface *archive, const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags, QObject *parent )
: InternalJob( parent ), m_archive( archive ), m_files( files ), m_destinationDirectory( destinationDirectory ),
m_helper( 0 ), m_preservePaths( preservePaths )
m_helper( 0 ), m_flags(flags)
{
}
......@@ -82,7 +82,7 @@ namespace Kerfuffle
connect( m_helper, SIGNAL( error( const QString&, const QString& ) ),
this, SIGNAL( error( const QString&, const QString& ) ) );
m_archive->registerObserver( m_helper );
setSuccess( m_archive->copyFiles( m_files, m_destinationDirectory, m_preservePaths ) );
setSuccess( m_archive->copyFiles( m_files, m_destinationDirectory, m_flags ) );
m_archive->removeObserver( m_helper );
}
......
......@@ -79,7 +79,7 @@ namespace Kerfuffle
{
Q_OBJECT
public:
InternalExtractJob( ReadOnlyArchiveInterface *archive, const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths = false, QObject *parent = 0 );
InternalExtractJob( ReadOnlyArchiveInterface *archive, const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags, QObject *parent = 0 );
~InternalExtractJob();
protected:
......@@ -94,7 +94,7 @@ namespace Kerfuffle
QList<QVariant> m_files;
QString m_destinationDirectory;
ArchiveJobHelper *m_helper;
bool m_preservePaths;
Archive::CopyFlags m_flags;
};
class InternalAddJob: public InternalJob
......
......@@ -88,8 +88,8 @@ namespace Kerfuffle
}
ExtractJob::ExtractJob( const QList<QVariant>& files, const QString& destinationDir,
bool preservePaths, ReadOnlyArchiveInterface *interface, QObject *parent )
: KJob( parent ), m_files( files ), m_destinationDir( destinationDir ), m_preservePaths( preservePaths ), m_archive( interface )
Archive::CopyFlags flags, ReadOnlyArchiveInterface *interface, QObject *parent )
: KJob( parent ), m_files( files ), m_destinationDir( destinationDir ), m_flags(flags), m_archive( interface )
{
}
......@@ -105,7 +105,7 @@ namespace Kerfuffle
desc = i18np( "Extracting one file", "Extracting %1 files", m_files.count() );
}
emit description( this, desc );
InternalExtractJob *job = new InternalExtractJob( m_archive, m_files, m_destinationDir, m_preservePaths, this );
InternalExtractJob *job = new InternalExtractJob( m_archive, m_files, m_destinationDir, m_flags, this );
connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
this, SLOT( done( ThreadWeaver::Job* ) ) );
......
......@@ -76,7 +76,7 @@ namespace Kerfuffle
{
Q_OBJECT
public:
ExtractJob( const QList<QVariant> & files, const QString& destinationDir, bool preservePaths, ReadOnlyArchiveInterface *interface, QObject *parent = 0 );
ExtractJob( const QList<QVariant> & files, const QString& destinationDir, Archive::CopyFlags flags, ReadOnlyArchiveInterface *interface, QObject *parent = 0 );
void start();
......@@ -91,7 +91,7 @@ namespace Kerfuffle
private:
QList<QVariant> m_files;
QString m_destinationDir;
bool m_preservePaths;
Archive::CopyFlags m_flags;
ReadOnlyArchiveInterface *m_archive;
};
......
......@@ -577,17 +577,17 @@ void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
reset();
}
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths ) const
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, Archive::CopyFlags flags ) const
{
QList<QVariant> files;
files << fileName;
return extractFiles( files, destinationDir, preservePaths );
return extractFiles( files, destinationDir, flags );
}
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths ) const
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, Kerfuffle::Archive::CopyFlags flags ) const
{
Q_ASSERT( m_archive );
ExtractJob *newJob = m_archive->copyFiles( files, destinationDir, preservePaths );
ExtractJob *newJob = m_archive->copyFiles( files, destinationDir, flags );
connect(newJob, SIGNAL(userQuery(Query*)),
this, SLOT(slotUserQuery(Query*)));
return newJob;
......
......@@ -62,8 +62,8 @@ class ArchiveModel: public QAbstractItemModel
ArchiveEntry entryForIndex( const QModelIndex &index );
int childCount( const QModelIndex &index );
ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths = false ) const;
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths = false ) const;
ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, Archive::CopyFlags flags ) const;
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, Kerfuffle::Archive::CopyFlags flags ) const;
AddJob* addFiles( const QStringList & paths );
DeleteJob* deleteFiles( const QList<QVariant> & files );
......
......@@ -123,7 +123,7 @@ void Part::extractSelectedFilesTo(QString localPath)
if (files.isEmpty()) return;
kDebug( 1601 ) << "selected files are " << files;
ExtractJob *job = m_model->extractFiles( files, localPath, true );
ExtractJob *job = m_model->extractFiles( files, localPath, Archive::PreservePaths );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
......@@ -248,7 +248,7 @@ void Part::slotQuickExtractFiles(QAction *triggeredAction)
else finalDestinationDirectory = userDestination;
QList<QVariant> files = selectedFilesWithParents();
ExtractJob *job = m_model->extractFiles( files, finalDestinationDirectory, true );
ExtractJob *job = m_model->extractFiles( files, finalDestinationDirectory, Archive::PreservePaths );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
......@@ -350,7 +350,7 @@ void Part::slotPreview( const QModelIndex & index )
if ( !entry.isEmpty() )
{
m_previewDir = new KTempDir();
ExtractJob *job = m_model->extractFile( entry[ InternalID ], m_previewDir->name(), false );
ExtractJob *job = m_model->extractFile( entry[ InternalID ], m_previewDir->name(), Archive::CopyFlags() );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotPreviewExtracted( KJob* ) ) );
......@@ -473,7 +473,12 @@ void Part::slotExtractFiles()
}
kDebug( 1601 ) << "Selected " << files;
ExtractJob *job = m_model->extractFiles( files, destinationDirectory, dialog.preservePaths() );
Kerfuffle::Archive::CopyFlags flags;
if (dialog.preservePaths())
flags |= Kerfuffle::Archive::PreservePaths;
ExtractJob *job = m_model->extractFiles( files, destinationDirectory, flags );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
......
......@@ -58,9 +58,11 @@ bool BKInterface::list()
return browse( BK_BASE_PTR( &( m_volInfo.dirTree ) ) );
}
bool BKInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths )
bool BKInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
{
Q_UNUSED(preservePaths );
//TODO: this var should be used!
const bool preservePaths = flags & Archive::PreservePaths;
foreach( const QVariant& file, files )
{
int rc;
......
......@@ -34,7 +34,7 @@ class BKInterface: public ReadWriteArchiveInterface
~BKInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths );
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags);
bool addFiles( const QString& path, const QStringList & files );
bool deleteFiles( const QList<QVariant> & files );
......
......@@ -115,11 +115,12 @@ bool LibArchiveInterface::list()
#endif
}
bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths )
bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
{
QDir::setCurrent( destinationDirectory );
const bool extractAll = files.isEmpty();
const bool preservePaths = flags & Archive::PreservePaths;
struct archive *arch, *writer;
struct archive_entry *entry;
......
......@@ -38,7 +38,7 @@ class LibArchiveInterface: public ReadWriteArchiveInterface
~LibArchiveInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths );
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags );
bool addFiles(const QString& path, const QStringList & files );
bool deleteFiles( const QList<QVariant> & files );
......
......@@ -205,9 +205,12 @@ class LibZipInterface: public ReadWriteArchiveInterface
return true;
}
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths )
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
{
kDebug( 1601 ) ;
const bool preservePaths = flags & Archive::PreservePaths;
if (!m_archive) {
if (!open()) {
return false;
......
......@@ -137,9 +137,12 @@ void RARInterface::processListLine(const QString& line)
}
bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths )
bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
{
const bool preservePaths = flags & Archive::PreservePaths;
kDebug( 1601 ) << files << destinationDirectory << (preservePaths? " with paths":"");
KProcess kp;
kp.setOutputChannelMode(KProcess::MergedChannels);
if (!m_unrarpath.isNull()) kp << m_unrarpath;
......
......@@ -34,7 +34,7 @@ class RARInterface: public ReadWriteArchiveInterface
~RARInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths );
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags );
bool addFiles(const QString& path, const QStringList & files );
bool deleteFiles( const QList<QVariant> & files );
......
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