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

Added handling of queries to part interface. Added an experimental overwrite...

Added handling of queries to part interface. Added an experimental overwrite query to libarchiveplugin

svn path=/trunk/KDE/kdeutils/ark/; revision=843941
parent ba0adc63
......@@ -20,6 +20,7 @@
*/
#include "queries.h"
#include <QMessageBox>
namespace Kerfuffle
{
......@@ -36,7 +37,8 @@ namespace Kerfuffle
void Query::waitForResponse()
{
m_responseCondition.wait(&m_responseMutex);
m_responseMutex.lock();
m_responseMutex.unlock();
}
void Query::setResponse(QVariant response)
......@@ -54,7 +56,10 @@ namespace Kerfuffle
void OverwriteQuery::execute()
{
//show dialog
int ret = QMessageBox::question(NULL, "File already exists",
QString("The file %1 already exists. Overwrite?").arg(
m_data.value("filename").toString()), QMessageBox::Yes | QMessageBox::No);
setResponse((ret == QMessageBox::Yes));
}
......
......@@ -22,6 +22,8 @@
#ifndef _QUERIES_H_
#define _QUERIES_H_
#include "kerfuffle_export.h"
#include <QString>
#include <QHash>
#include <QWaitCondition>
......@@ -33,9 +35,8 @@ namespace Kerfuffle
typedef QHash<QString, QVariant> QueryData;
class Query : public QObject
class KERFUFFLE_EXPORT Query
{
Q_OBJECT
public:
/**
......@@ -57,6 +58,7 @@ namespace Kerfuffle
* Protected constructor
*/
Query();
virtual ~Query() {}
void setResponse(QVariant response);
......@@ -69,7 +71,7 @@ namespace Kerfuffle
};
class OverwriteQuery : public Query
class KERFUFFLE_EXPORT OverwriteQuery : public Query
{
public:
OverwriteQuery(QString filename);
......
......@@ -477,6 +477,11 @@ void ArchiveModel::slotEntryRemoved( const QString & path )
}
}
void ArchiveModel::slotUserQuery(Query *query)
{
query->execute();
}
void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
{
kDebug (1601) << entry;
......@@ -559,7 +564,10 @@ ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString &
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths ) const
{
Q_ASSERT( m_archive );
return m_archive->copyFiles( files, destinationDir, preservePaths );
ExtractJob *newJob = m_archive->copyFiles( files, destinationDir, preservePaths );
connect(newJob, SIGNAL(userQuery(Query*)),
this, SLOT(slotUserQuery(Query*)));
return newJob;
}
AddJob* ArchiveModel::addFiles( const QStringList & paths )
......@@ -572,6 +580,10 @@ AddJob* ArchiveModel::addFiles( const QStringList & paths )
m_jobTracker->registerJob( job );
connect( job, SIGNAL( newEntry( const ArchiveEntry& ) ),
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
connect(job, SIGNAL(userQuery(Query*)),
this, SLOT(slotUserQuery(Query*)));
return job;
}
return 0;
......@@ -586,6 +598,9 @@ DeleteJob* ArchiveModel::deleteFiles( const QList<QVariant> & files )
m_jobTracker->registerJob( job );
connect( job, SIGNAL( entryRemoved( const QString & ) ),
this, SLOT( slotEntryRemoved( const QString & ) ) );
connect(job, SIGNAL(userQuery(Query*)),
this, SLOT(slotUserQuery(Query*)));
return job;
}
return 0;
......
......@@ -24,6 +24,7 @@
#include <QAbstractItemModel>
#include <kjobtrackerinterface.h>
#include "kerfuffle/archive.h"
#include "kerfuffle/queries.h"
class ArchiveNode;
class ArchiveDirNode;
......@@ -76,6 +77,7 @@ class ArchiveModel: public QAbstractItemModel
private slots:
void slotNewEntry( const ArchiveEntry& entry );
void slotEntryRemoved( const QString & path );
void slotUserQuery(Query *query);
private:
ArchiveDirNode* parentFor( const ArchiveEntry& entry );
......
......@@ -26,6 +26,7 @@
#include "libarchivehandler.h"
//#include "settings.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/queries.h"
#include <archive.h>
#include <archive_entry.h>
......@@ -166,11 +167,31 @@ bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QStrin
while ( archive_read_next_header( arch, &entry ) == ARCHIVE_OK )
{
QString entryName = QFile::decodeName( archive_entry_pathname( entry ) );
if ( entries.contains( entryName ) || extractAll )
{
QFileInfo entryFI( entryName );
if( !preservePaths )
archive_entry_set_pathname( entry, QFile::encodeName( QFileInfo( entryName ).fileName() ).constData() );
archive_entry_set_pathname( entry, QFile::encodeName( entryFI.fileName() ).constData() );
bool exists;
if (preservePaths)
exists = entryFI.exists();
else
exists = QFileInfo(entryFI.fileName()).exists();
if (exists) {
Kerfuffle::OverwriteQuery query(entryName);
emit userQuery(&query);
query.waitForResponse();
if (!query.response().toBool()) {
entries.removeAll( entryName );
archive_read_data_skip( arch );
continue;
}
}
if ( archive_write_header( writer, entry ) == ARCHIVE_OK )
//if the whole archive is extracted and the total filesize is
......
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