Commit 755f9dd2 authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Use a QHash<QString,QVariant> for options sent to plugins when extracting

svn path=/trunk/KDE/kdeutils/ark/; revision=905854
parent b4e26fce
......@@ -64,14 +64,14 @@ void BatchExtract::addExtraction(Kerfuffle::Archive* archive,bool preservePaths,
}
}
Kerfuffle::Archive::CopyFlags flags;
Kerfuffle::ExtractionOptions options;
if (preservePaths)
flags |= Kerfuffle::Archive::PreservePaths;
options["PreservePaths"] = true;
Kerfuffle::ExtractJob *job = archive->copyFiles(
QVariantList(), //extract all files
autoDestination, //extract to folder
flags
options
);
connect(job, SIGNAL(userQuery(Query*)),
......
......@@ -54,18 +54,12 @@ namespace Kerfuffle
Rar, etc), followed by the property name used
*/
typedef QHash<QString, QVariant> CompressionOptions;
typedef QHash<QString, QVariant> ExtractionOptions;
class KERFUFFLE_EXPORT Archive
{
public:
enum CopyFlag {
PreservePaths = 0x1,
TruncateCommonBase = 0x2,
PasswordProtectedHint = 0x4
};
Q_DECLARE_FLAGS(CopyFlags, CopyFlag)
virtual ~Archive() {}
virtual QString fileName() = 0;
......@@ -90,7 +84,7 @@ namespace Kerfuffle
*/
virtual AddJob* addFiles( const QStringList & files, const CompressionOptions& options = CompressionOptions()) = 0;
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags) = 0;
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, ExtractionOptions options = ExtractionOptions()) = 0;
virtual bool isSingleFolderArchive() = 0;
virtual QString subfolderName() = 0;
......@@ -100,8 +94,6 @@ 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();
......
......@@ -107,13 +107,13 @@ namespace Kerfuffle
return newJob;
}
ExtractJob* ArchiveBase::copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags )
ExtractJob* ArchiveBase::copyFiles( const QList<QVariant> & files, const QString & destinationDir, ExtractionOptions options )
{
Archive::CopyFlags newFlags = flags;
ExtractionOptions newOptions = options;
if (isPasswordProtected())
newFlags |= PasswordProtectedHint;
newOptions["PasswordProtectedHint"] = true;
ExtractJob *newJob = new ExtractJob( files, destinationDir, newFlags, m_iface, this );
ExtractJob *newJob = new ExtractJob( files, destinationDir, newOptions, 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, const CompressionOptions& options = CompressionOptions() );
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags );
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, ExtractionOptions options );
virtual bool isReadOnly();
virtual QString fileName();
......
......@@ -57,8 +57,8 @@ namespace Kerfuffle
virtual bool open();
virtual bool list() = 0;
virtual bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags ) = 0;
void setPassword(QString password);
virtual bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options ) = 0;
protected:
void error( const QString & message, const QString & details = QString() );
......
......@@ -126,8 +126,8 @@ namespace Kerfuffle
}
ExtractJob::ExtractJob( const QList<QVariant>& files, const QString& destinationDir,
Archive::CopyFlags flags, ReadOnlyArchiveInterface *interface, QObject *parent )
: Job(interface, parent ), m_files( files ), m_destinationDir( destinationDir ), m_flags(flags)
ExtractionOptions options, ReadOnlyArchiveInterface *interface, QObject *parent )
: Job(interface, parent ), m_files( files ), m_destinationDir( destinationDir ), m_options(options)
{
}
......@@ -146,19 +146,24 @@ namespace Kerfuffle
m_interface->registerObserver( this );
fillInDefaultValues(m_options);
kDebug(1601) << "Starting extraction with selected files "
<< m_files
<< " Destination dir " << m_destinationDir
<< " Preserve paths: " << (m_flags & Archive::PreservePaths)
<< " Truncate common base: " << (m_flags & Archive::TruncateCommonBase)
<< " Preserve paths: " << m_options.value("PreservePaths").toBool()
;
setError( !m_interface->copyFiles( m_files, m_destinationDir, m_flags ) );
setError( !m_interface->copyFiles( m_files, m_destinationDir, m_options ) );
m_interface->removeObserver( this );
emitResult();
}
void ExtractJob::fillInDefaultValues(ExtractionOptions& options)
{
if (!options.contains("PreservePaths")) options["PreservePaths"] = false;
}
AddJob::AddJob( const QStringList& files, const CompressionOptions& options , ReadWriteArchiveInterface *interface, QObject *parent )
: Job( interface, parent ), m_files( files ), m_options(options)
......
......@@ -102,15 +102,16 @@ namespace Kerfuffle
Q_OBJECT
public:
ExtractJob( const QList<QVariant> & files, const QString&
destinationDir, Archive::CopyFlags flags,
destinationDir, ExtractionOptions options,
ReadOnlyArchiveInterface *interface, QObject *parent = 0 );
void doWork();
private:
void fillInDefaultValues(ExtractionOptions& options);
QList<QVariant> m_files;
QString m_destinationDir;
Archive::CopyFlags m_flags;
ExtractionOptions m_options;
};
class KERFUFFLE_EXPORT AddJob: public Job
......
......@@ -719,17 +719,17 @@ KJob* ArchiveModel::setArchive( Kerfuffle::Archive *archive )
return job;
}
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, Archive::CopyFlags flags ) const
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, const Kerfuffle::ExtractionOptions options ) const
{
QList<QVariant> files;
files << fileName;
return extractFiles( files, destinationDir, flags );
return extractFiles( files, destinationDir, options );
}
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, Kerfuffle::Archive::CopyFlags flags ) const
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, const Kerfuffle::ExtractionOptions options ) const
{
Q_ASSERT( m_archive );
ExtractJob *newJob = m_archive->copyFiles( files, destinationDir, flags );
ExtractJob *newJob = m_archive->copyFiles( files, destinationDir, options );
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, Archive::CopyFlags flags ) const;
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, Kerfuffle::Archive::CopyFlags flags ) const;
ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, ExtractionOptions options = ExtractionOptions()) const;
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, const Kerfuffle::ExtractionOptions options = ExtractionOptions() ) const;
AddJob* addFiles( const QStringList & paths, const CompressionOptions& options = CompressionOptions() );
DeleteJob* deleteFiles( const QList<QVariant> & files );
......
......@@ -132,7 +132,11 @@ void Part::extractSelectedFilesTo(QString localPath)
if (files.isEmpty()) return;
kDebug( 1601 ) << "selected files are " << files;
ExtractJob *job = m_model->extractFiles( files, localPath, Archive::PreservePaths | Archive::TruncateCommonBase );
Kerfuffle::ExtractionOptions options;
options["PreservePaths"] = true;
options["TruncateCommonBase"] = true;
ExtractJob *job = m_model->extractFiles( files, localPath, options);
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
......@@ -257,8 +261,10 @@ void Part::slotQuickExtractFiles(QAction *triggeredAction)
}
else finalDestinationDirectory = userDestination;
Kerfuffle::ExtractionOptions options;
options["PreservePaths"] = true;
QList<QVariant> files = selectedFiles();
ExtractJob *job = m_model->extractFiles( files, finalDestinationDirectory, Archive::PreservePaths );
ExtractJob *job = m_model->extractFiles( files, finalDestinationDirectory, options );
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
......@@ -410,7 +416,7 @@ void Part::slotPreview( const QModelIndex & index )
const ArchiveEntry& entry = m_model->entryForIndex( index );
if ( !entry.isEmpty() )
{
ExtractJob *job = m_model->extractFile( entry[ InternalID ], m_previewDir->name(), Archive::CopyFlags() );
ExtractJob *job = m_model->extractFile( entry[ InternalID ], m_previewDir->name());
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotPreviewExtracted( KJob* ) ) );
......@@ -519,12 +525,13 @@ void Part::slotExtractFiles()
}
kDebug( 1601 ) << "Selected " << files;
Kerfuffle::ExtractionOptions options;
Kerfuffle::Archive::CopyFlags flags;
if (dialog.preservePaths())
flags |= Kerfuffle::Archive::PreservePaths;
options["PreservePaths"] = true;
ExtractJob *job = m_model->extractFiles( files, destinationDirectory, flags );
ExtractJob *job = m_model->extractFiles( files, destinationDirectory, options );
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
......
......@@ -255,9 +255,9 @@ void p7zipInterface::listProcessLine(int& state, const QString& line)
}
}
bool p7zipInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
bool p7zipInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options )
{
const bool preservePaths = flags & Archive::PreservePaths;
const bool preservePaths = options.value("PreservePaths").toBool();
kDebug( 1601 ) << "extract" << files << "to" << destinationDirectory << (preservePaths? " with paths":"");
......
......@@ -39,7 +39,7 @@ class p7zipInterface: public ReadWriteArchiveInterface
~p7zipInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags );
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options );
bool addFiles( const QStringList & files, const CompressionOptions& options );
bool deleteFiles( const QList<QVariant> & files );
......
......@@ -58,7 +58,7 @@ bool BKInterface::list()
return browse( BK_BASE_PTR( &( m_volInfo.dirTree ) ) );
}
bool BKInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
bool BKInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options )
{
//TODO: this var should be used!
const bool preservePaths = flags & Archive::PreservePaths;
......
......@@ -34,7 +34,7 @@ class BKInterface: public ReadWriteArchiveInterface
~BKInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags);
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options);
bool addFiles( const QStringList & files, const CompressionOptions& options );
bool deleteFiles( const QList<QVariant> & files );
......
......@@ -135,14 +135,14 @@ bool LibArchiveInterface::list()
#endif
}
bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options )
{
kDebug( 1601 ) << "Changing current directory to " << destinationDirectory;
QDir::setCurrent( destinationDirectory );
const bool extractAll = files.isEmpty();
const bool preservePaths = (flags & Archive::PreservePaths);
const bool preservePaths = options.value("PreservePaths").toBool();
overwriteAll = false; //we reset this per extract operation
//TODO: don't leak these if the extraction fails with an error in the
......@@ -151,7 +151,7 @@ bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QStrin
struct archive_entry *entry;
QString commonBase;
if (flags & Archive::TruncateCommonBase)
if (options.value("TruncateCommonBase").toBool())
{
#if 0
Q_ASSERT(files.size() == 1);
......
......@@ -38,7 +38,7 @@ class LibArchiveInterface: public ReadWriteArchiveInterface
~LibArchiveInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags );
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options );
bool addFiles( const QStringList & files, const CompressionOptions& options );
bool deleteFiles( const QList<QVariant> & files );
......
......@@ -107,7 +107,7 @@ class LibGzipInterface: public ReadWriteArchiveInterface
if (gzclose(in) != Z_OK) error("failed gzclose");
}
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options )
{
kDebug( 1601 ) ;
......
......@@ -260,11 +260,11 @@ class LibZipInterface: public ReadWriteArchiveInterface
return true;
}
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options )
{
kDebug( 1601 ) ;
const bool preservePaths = flags & Archive::PreservePaths;
const bool preservePaths = options.value("PreservePaths").toBool();
if (!m_archive) {
if (!open()) {
......
......@@ -188,22 +188,21 @@ void RARInterface::processListLine(const QString& line)
}
bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options )
{
const bool preservePaths = flags & Archive::PreservePaths;
const bool preservePaths = options.value("PreservePaths").toBool();
kDebug( 1601 ) << files << destinationDirectory << (preservePaths? " with paths":"");
QDir::setCurrent(destinationDirectory);
QString commonBase;
if (flags & Archive::TruncateCommonBase)
commonBase = findCommonBase(files);
//if (flags.value("TruncateCommonBase").toBool())
//if we get a hint about this being a password protected archive, ask about
//the password in advance.
if (flags & Archive::PasswordProtectedHint) {
if (options.value("PasswordProtectedHint").toBool()) {
kDebug( 1601 ) << "Password hint enabled, querying user";
Kerfuffle::PasswordNeededQuery query(filename());
......
......@@ -39,7 +39,7 @@ class RARInterface: public ReadWriteArchiveInterface
~RARInterface();
bool list();
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags );
bool copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options );
bool addFiles( const QStringList & files, const CompressionOptions& options );
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