Commit 51d34e4c authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Basic extracting of dragged file to temp folder

svn path=/trunk/KDE/kdeutils/ark/; revision=836978
parent df70c28b
......@@ -25,6 +25,8 @@
#include <QList>
#include <QPixmap>
#include <QFont>
#include <QMimeData>
#include <QDir>
#include <KDebug>
#include <KLocale>
......@@ -214,9 +216,11 @@ QVariant ArchiveModel::data( const QModelIndex &index, int role ) const
Qt::ItemFlags ArchiveModel::flags( const QModelIndex &index ) const
{
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
if ( index.isValid() )
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | defaultFlags;
}
return 0;
......@@ -311,11 +315,52 @@ int ArchiveModel::rowCount( const QModelIndex &parent ) const
int ArchiveModel::columnCount( const QModelIndex &parent ) const
{
return 2; // TODO: Completely bogus
if ( parent.isValid() )
{
return static_cast<ArchiveNode*>( parent.internalPointer() )->entry().size();
}
return 2; // TODO: Completely bogus
}
Qt::DropActions ArchiveModel::supportedDropActions () const
{
return Qt::CopyAction;
}
QStringList ArchiveModel::mimeTypes () const
{
return QStringList() << QLatin1String("text/uri-list")
<< QLatin1String( "text/plain" )
<< QLatin1String( "application/x-kde-urilist" );
}
QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
{
QVariantList files;
//1. Prepare the temp path
bool ret = QDir::temp().mkpath("kdeark-drag-temp");
if (!ret) return NULL;
QString tempPath = QDir::tempPath() + "/kdeark-drag-temp";
Q_ASSERT(QFile::exists(tempPath));
//2. Populate the internal list of files
foreach ( const QModelIndex &index, indexes ) {
//to limit only one index per row
if (index.column() != 0) continue;
files << static_cast<ArchiveNode*>( index.internalPointer() )->entry()[ InternalID ];
}
kDebug() << "Extracting " << files << "to" << tempPath;
ExtractJob *job = extractFiles(files, tempPath, false);
job->start();
KUrl::List urls;
QMimeData *data = new QMimeData();
urls.populateMimeData( data );
return data;
}
ArchiveDirNode* ArchiveModel::parentFor( const ArchiveEntry& entry )
......@@ -451,14 +496,14 @@ void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
reset();
}
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths )
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths ) const
{
QList<QVariant> files;
files << fileName;
return extractFiles( files, destinationDir, preservePaths );
}
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths )
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths ) const
{
Q_ASSERT( m_archive );
return m_archive->copyFiles( files, destinationDir, preservePaths );
......
......@@ -47,14 +47,20 @@ class ArchiveModel: public QAbstractItemModel
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
//drag and drop related
Qt::DropActions supportedDropActions () const;
QStringList mimeTypes () const;
QMimeData * mimeData ( const QModelIndexList & indexes ) const;
void setArchive( Kerfuffle::Archive *archive );
Kerfuffle::Archive *archive() const { return m_archive; }
ArchiveEntry entryForIndex( const QModelIndex &index );
int childCount( const QModelIndex &index );
ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths = false );
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths = false );
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;
AddJob* addFiles( const QStringList & paths );
DeleteJob* deleteFiles( const QList<QVariant> & files );
......
......@@ -106,6 +106,12 @@ void Part::setupView()
m_view->setColumnWidth( 0, 150 );
m_view->setAllColumnsShowFocus( true );
//drag and drop
m_view->setDragDropMode(QAbstractItemView::DragDrop);
m_view->setDragEnabled(true);
m_view->setAcceptDrops(true);
m_view->setDropIndicatorShown(true);
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
this, SLOT( updateActions() ) );
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
......
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