Commit 1ff8518a authored by Harald Hvaal's avatar Harald Hvaal
Browse files

First attempt to add drag/dropped files to the correct directory

svn path=/trunk/KDE/kdeutils/ark/; revision=869787
parent afda370b
......@@ -67,7 +67,7 @@ namespace Kerfuffle
virtual KJob* create() = 0;
virtual ListJob* list() = 0;
virtual DeleteJob* deleteFiles( const QList<QVariant> & files ) = 0;
virtual AddJob* addFiles( const QStringList & files ) = 0;
virtual AddJob* addFiles( const QStringList & files, const QString& path = QString()) = 0;
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags) = 0;
virtual bool isSingleFolderArchive() = 0;
......
......@@ -96,10 +96,10 @@ namespace Kerfuffle
return newJob;
}
AddJob* ArchiveBase::addFiles( const QStringList & files )
AddJob* ArchiveBase::addFiles( const QStringList & files, const QString& path)
{
Q_ASSERT( !m_iface->isReadOnly() );
AddJob *newJob = new AddJob(QString(), files, static_cast<ReadWriteArchiveInterface*>( m_iface ), this );
AddJob *newJob = new AddJob(path, files, static_cast<ReadWriteArchiveInterface*>( m_iface ), this );
connect(m_iface, SIGNAL(userQuery(Query*)),
newJob, SIGNAL(userQuery(Query*)));
return newJob;
......
......@@ -54,7 +54,7 @@ namespace Kerfuffle
virtual KJob* create();
virtual ListJob* list();
virtual DeleteJob* deleteFiles( const QList<QVariant> & files );
virtual AddJob* addFiles( const QStringList & files );
virtual AddJob* addFiles( const QStringList & files , const QString& path = QString());
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, Archive::CopyFlags flags );
virtual bool isReadOnly();
......
......@@ -83,11 +83,38 @@ namespace Kerfuffle
m_observers.removeAll( observer );
}
QString ReadOnlyArchiveInterface::findCommonBase(const QStringList& files)
{
QString commonBase;
//we loop through all items and find the highest common folder they share
if (files.size() > 1) {
QStringList common = files.first().split("/", QString::SkipEmptyParts);
if (common.size() > 1) {
common.removeLast(); //We don't need the filename
foreach(const QString &selectedEntry, files) {
QStringList parts = selectedEntry.split("/", QString::SkipEmptyParts);
for (int i = common.size() - 1; i > -1; --i) {
if (common.at(i) != parts.at(i))
common.removeLast();
}
}
commonBase = common.join("/") + "/";
}
}
else if (files.size() == 1) {
QStringList parts = files.first().split("/", QString::SkipEmptyParts);
parts.removeLast(); //take of the filename
return parts.join("/") + "/";
}
return commonBase;
}
QString ReadOnlyArchiveInterface::findCommonBase(const QVariantList& files)
{
QString commonBase;
//if we have lots of selected items and the TruncateCommonBase flag is set,
//we loop through all items and find the highest common folder they share
if (files.size() > 1) {
QStringList common = files.first().toString().split("/", QString::SkipEmptyParts);
......
......@@ -66,6 +66,7 @@ namespace Kerfuffle
void entryRemoved( const QString& path );
QString password() { return m_password; }
QString findCommonBase(const QVariantList& files);
QString findCommonBase(const QStringList& files);
void expandDirectories( QStringList &files );
signals:
......
......@@ -451,9 +451,6 @@ QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
bool ArchiveModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
{
Q_UNUSED( action );
Q_UNUSED(parent );
Q_UNUSED( column );
Q_UNUSED( row );
if (!data->hasUrls())
return false;
......@@ -463,7 +460,21 @@ bool ArchiveModel::dropMimeData ( const QMimeData * data, Qt::DropAction action,
paths << url.path();
}
emit droppedFiles(paths);
QString path;
if (parent.isValid()) {
QModelIndex droppedOnto = index(row, column, parent);
if (entryForIndex(droppedOnto).value(IsDirectory).toBool()) {
kDebug() << "Using entry";
path = entryForIndex(droppedOnto).value(FileName).toString();
}
else {
path = entryForIndex(parent).value(FileName).toString();
}
}
kDebug( 1601 ) << "Dropped onto " << path;
emit droppedFiles(paths, path);
return true;
}
......@@ -666,13 +677,13 @@ ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QStr
return newJob;
}
AddJob* ArchiveModel::addFiles( const QStringList & paths )
AddJob* ArchiveModel::addFiles( const QStringList & filenames, const QString& path )
{
Q_ASSERT( m_archive );
if ( !m_archive->isReadOnly())
{
AddJob *job = m_archive->addFiles( paths );
AddJob *job = m_archive->addFiles( filenames, path );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( newEntry( const ArchiveEntry& ) ),
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
......
......@@ -65,7 +65,7 @@ class ArchiveModel: public QAbstractItemModel
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 );
AddJob* addFiles( const QStringList & paths, const QString& path = QString() );
DeleteJob* deleteFiles( const QList<QVariant> & files );
void setJobTracker( KJobTrackerInterface *tracker ) { m_jobTracker = tracker; }
......@@ -75,7 +75,7 @@ class ArchiveModel: public QAbstractItemModel
void loadingFinished(KJob *);
void extractionFinished( bool success );
void error( const QString& error, const QString& details );
void droppedFiles(const QStringList& files);
void droppedFiles(const QStringList& files, const QString& path = QString());
private slots:
void slotNewEntry( const ArchiveEntry& entry );
......
......@@ -84,8 +84,8 @@ Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
this, SLOT( slotLoadingStarted() ) );
connect( m_model, SIGNAL( loadingFinished(KJob *) ),
this, SLOT( slotLoadingFinished(KJob *) ) );
connect( m_model, SIGNAL( droppedFiles(const QStringList&) ),
this, SLOT( slotAddFiles(const QStringList&) ) );
connect( m_model, SIGNAL( droppedFiles(const QStringList&, const QString&) ),
this, SLOT( slotAddFiles(const QStringList&, const QString&) ) );
connect( m_model, SIGNAL( error( const QString&, const QString& ) ),
this, SLOT( slotError( const QString&, const QString& ) ) );
......@@ -575,13 +575,13 @@ void Part::adjustColumns( const QModelIndex & topleft, const QModelIndex& bottom
} while (firstColumn < lastColumn);
}
void Part::slotAddFiles(const QStringList& filesToAdd)
void Part::slotAddFiles(const QStringList& filesToAdd, const QString& path)
{
kDebug( 1601 ) ;
kDebug( 1601 ) << "Adding " << filesToAdd << " to " << path;
if ( !filesToAdd.isEmpty() )
{
AddJob *job = m_model->addFiles( filesToAdd );
AddJob *job = m_model->addFiles( filesToAdd, path );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotAddFilesDone( KJob* ) ) );
job->start();
......
......@@ -68,7 +68,7 @@ class Part: public KParts::ReadWritePart, public Interface
void slotExtractionDone( KJob* );
void slotQuickExtractFiles(QAction*);
void slotAddFiles();
void slotAddFiles(const QStringList& files);
void slotAddFiles(const QStringList& files, const QString& path = QString());
void slotAddDir();
void slotAddFilesDone( KJob* );
void slotDeleteFiles();
......
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