Commit 10bc72f4 authored by Harald Hvaal's avatar Harald Hvaal

Aaaand, finally proper drag/drop support stabilized.

svn path=/trunk/KDE/kdeutils/ark/; revision=905855
parent 755f9dd2
......@@ -151,7 +151,7 @@ namespace Kerfuffle
kDebug(1601) << "Starting extraction with selected files "
<< m_files
<< " Destination dir " << m_destinationDir
<< " Preserve paths: " << m_options.value("PreservePaths").toBool()
<< " And options " << m_options
;
setError( !m_interface->copyFiles( m_files, m_destinationDir, m_options ) );
......
......@@ -540,7 +540,8 @@ ArchiveDirNode* ArchiveModel::parentFor( const ArchiveEntry& entry )
if ( !node )
{
ArchiveEntry e;
e[ FileName ] = parent->entry()[ FileName ].toString() + '/' + piece;
e[ FileName ] = (parent == m_rootNode) ?
piece : parent->entry()[ FileName ].toString() + '/' + piece;
e[ IsDirectory ] = true;
node = new ArchiveDirNode( parent, e );
insertNode( node );
......
......@@ -128,13 +128,32 @@ void Part::extractSelectedFilesTo(QString localPath)
kDebug( 1601 ) << "Extract to " << localPath;
if (!m_model) return;
if (m_view->selectionModel()->selectedRows().count() != 1) {
m_view->selectionModel()->setCurrentIndex(m_view->currentIndex(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
if (m_view->selectionModel()->selectedRows().count() != 1) return;
QVariant internalRoot;
kDebug(1601 ) << "valid " << m_view->currentIndex().parent().isValid();
if (m_view->currentIndex().parent().isValid())
internalRoot = m_model->entryForIndex(m_view->currentIndex().parent()).value(InternalID);
if (internalRoot.isNull()) {
//we have the special case valid parent, but the parent does not
//actually correspond to an item in the archive, but an automatically
//created folder. for now, we will just use the filename of the node
//instead, but for plugins that rely on a non-filename value as the
//InternalId, this WILL break things. TODO find a solution
internalRoot = m_model->entryForIndex(m_view->currentIndex().parent()).value(FileName);
}
QList<QVariant> files = selectedFilesWithChildren();
if (files.isEmpty()) return;
kDebug( 1601 ) << "selected files are " << files;
Kerfuffle::ExtractionOptions options;
options["PreservePaths"] = true;
options["TruncateCommonBase"] = true;
if (!internalRoot.isNull()) options["RootNode"] = internalRoot;
ExtractJob *job = m_model->extractFiles( files, localPath, options);
registerJob( job );
......
......@@ -150,18 +150,11 @@ bool LibArchiveInterface::copyFiles( const QList<QVariant> & files, const QStrin
struct archive *arch, *writer;
struct archive_entry *entry;
QString commonBase;
if (options.value("TruncateCommonBase").toBool())
QString rootNode;
if (options.contains("RootNode"))
{
#if 0
Q_ASSERT(files.size() == 1);
QString draggedItem = files.at(0).toString();
QStringList parts = draggedItem.split('/', QString::SkipEmptyParts);
parts.removeLast();
commonBase = parts.join("/") + "/";
kDebug(1601) << "Set common base " << commonBase;
#endif
rootNode = options.value("RootNode").toString();
kDebug(1601) << "Set root node " << rootNode;
}
arch = archive_read_new();
......@@ -246,9 +239,9 @@ retry:
//OR, if the commonBase has been set, then we remove this
//common base from the filename
} else if (!commonBase.isEmpty()) {
} else if (!rootNode.isEmpty()) {
QString truncatedFilename;
truncatedFilename = entryName.remove(0, commonBase.size());
truncatedFilename = entryName.remove(0, rootNode.size());
kDebug( 1601 ) << "Truncated filename: " << truncatedFilename;
archive_entry_copy_pathname( entry, QFile::encodeName(truncatedFilename).constData() );
......
......@@ -207,8 +207,14 @@ class LibZipInterface: public ReadWriteArchiveInterface
return name;
}
bool extractEntry(struct zip_file *file, QVariant entry, const QString & destinationDirectory, bool preservePaths )
bool extractEntry(struct zip_file *file, QVariant entry, const QString & destinationDirectory, bool preservePaths , QString rootNode)
{
if (!rootNode.isEmpty()) {
QString truncatedFilename;
truncatedFilename = entry.toString().remove(0, rootNode.size());
kDebug( 1601 ) << "Truncated filename: " << truncatedFilename;
entry = truncatedFilename;
}
if (entry.toString().right(1) == "/") { // if a folder
//if we don't preserve paths we don't create any folders
......@@ -266,6 +272,13 @@ class LibZipInterface: public ReadWriteArchiveInterface
const bool preservePaths = options.value("PreservePaths").toBool();
QString rootNode;
if (options.contains("RootNode"))
{
rootNode = options.value("RootNode").toString();
kDebug(1601) << "Set root node " << rootNode;
}
if (!m_archive) {
if (!open()) {
return false;
......@@ -274,7 +287,7 @@ class LibZipInterface: public ReadWriteArchiveInterface
int processed = 0;
if (!files.isEmpty()) {
///////////if only extract specified files
foreach( const QVariant &entry, files )
{
......@@ -286,7 +299,7 @@ class LibZipInterface: public ReadWriteArchiveInterface
return false;
}
if (!extractEntry(file, entry, destinationDirectory, preservePaths)) {
if (!extractEntry(file, entry, destinationDirectory, preservePaths, rootNode)) {
return false;
}
......@@ -295,6 +308,7 @@ class LibZipInterface: public ReadWriteArchiveInterface
progress( ( ++processed )*1.0/files.count() );
}
} else {
/////////////////if extract all files
for ( int index = 0; index < zip_get_num_files( m_archive ); ++index )
{
......@@ -306,7 +320,7 @@ class LibZipInterface: public ReadWriteArchiveInterface
return false;
}
if (!extractEntry(file, QDir::fromNativeSeparators(QFile::decodeName(zip_get_name(m_archive, index, 0))), destinationDirectory, preservePaths)) {
if (!extractEntry(file, QDir::fromNativeSeparators(QFile::decodeName(zip_get_name(m_archive, index, 0))), destinationDirectory, preservePaths, rootNode)) {
return false;
}
......
......@@ -196,9 +196,12 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
QDir::setCurrent(destinationDirectory);
QString commonBase;
//if (flags.value("TruncateCommonBase").toBool())
QString rootNode;
if (options.contains("RootNode"))
{
rootNode = options.value("RootNode").toString();
kDebug(1601) << "Set root node " << rootNode;
}
//if we get a hint about this being a password protected archive, ask about
//the password in advance.
......@@ -288,8 +291,8 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
//args << "-p-"; // do not query for password
if ( !password().isEmpty() ) args << "-p" + password();
if (!commonBase.isEmpty())
args << "-ap" + commonBase;
if (!rootNode.isEmpty())
args << "-ap" + rootNode;
args << filename();
foreach( const QVariant& file, overwriteList )
......
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