Commit 82a31573 authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Added support for drag/add files to model, fixed support for deleting files in...

Added support for drag/add files to model, fixed support for deleting files in the ui, as well as adding support for it in the rar plugin.

svn path=/trunk/KDE/kdeutils/ark/; revision=845823
parent e42359d2
......@@ -129,7 +129,7 @@ class ArchiveDirNode: public ArchiveNode
}
if ( next && next->isDir() )
{
//pieces.removeAt(0);
pieces.removeAt(0);
return static_cast<ArchiveDirNode*>( next )->findByPath( pieces.join( "/" ) );
}
return 0;
......@@ -351,24 +351,20 @@ int ArchiveModel::columnCount( const QModelIndex &parent ) const
Qt::DropActions ArchiveModel::supportedDropActions () const
{
return Qt::CopyAction;
return Qt::CopyAction | Qt::MoveAction;
}
QStringList ArchiveModel::mimeTypes () const
{
QString archiveName = m_archive->fileName();
QString ext = QFileInfo(archiveName).suffix().toUpper();
QStringList types;
types << "application/x-kde-extractdrag";
if (ext == "TAR" ||
ext == "ZIP" ||
archiveName.right(6).toUpper() == "TAR.GZ")
types << QLatin1String("text/uri-list")
<< QLatin1String( "text/plain" )
<< QLatin1String( "application/x-kde-urilist" );
types << QString("text/uri-list")
<< QString( "text/plain" )
<< QString( "text/x-moz-url" )
<< QString( "application/x-kde-urilist" );
types << "application/x-kde-extractdrag";
return types;
}
......@@ -376,6 +372,7 @@ QStringList ArchiveModel::mimeTypes () const
QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
{
kDebug (1601) ;
//prepare the fallback kio_slave filenames
QStringList files;
......@@ -387,7 +384,7 @@ QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
archiveName.prepend("zip:");
} else if (archiveName.right(6).toUpper() == "TAR.GZ") {
archiveName.prepend("tar:");
} else return NULL;
};
if (archiveName.right(1) != "/") {
archiveName.append("/");
......@@ -403,6 +400,8 @@ QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
files << file;
}
kDebug(1601) << "Sending out mimedata: " << files;
KUrl::List kiolist(files);
//prepare the dbus-based drag/drop mimedata
......@@ -418,8 +417,9 @@ QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
bool ArchiveModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
{
if (action == Qt::IgnoreAction)
return true;
kDebug (1601) << "Fuckings";
//if (action == Qt::IgnoreAction)
//return true;
if (!data->hasFormat("text/uri-list"))
return false;
......@@ -482,6 +482,7 @@ QModelIndex ArchiveModel::indexForNode( ArchiveNode *node )
void ArchiveModel::slotEntryRemoved( const QString & path )
{
// TODO: Do something
kDebug (1601) << "Removed node at path " << path;
ArchiveNode *entry = m_rootNode->findByPath( path );
if ( entry )
{
......@@ -494,7 +495,8 @@ void ArchiveModel::slotEntryRemoved( const QString & path )
parent->entries()[ entry->row() ] = 0;
endRemoveRows();
}
} else
kDebug (1601) << "Did not find the removed node";
}
void ArchiveModel::slotUserQuery(Query *query)
......@@ -509,7 +511,9 @@ void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
if (m_rootNode){
ArchiveNode *existing = m_rootNode->findByPath( entry[ FileName ].toString() );
if ( existing ) {
kDebug (1601) << "Skipping entry creation for" << entry[FileName].toString();
kDebug (1601) << "Refreshing entry for" << entry[FileName].toString();
//TODO: benchmark whether it's a bad idea to reset the entry here.
existing->setEntry(entry);
return;
}
}
......
......@@ -49,9 +49,9 @@ class ArchiveModel: public QAbstractItemModel
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
//drag and drop related
Qt::DropActions supportedDropActions () const;
QStringList mimeTypes () const;
QMimeData * mimeData ( const QModelIndexList & indexes ) const;
virtual Qt::DropActions supportedDropActions () const;
virtual QStringList mimeTypes () const;
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
virtual bool dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );
......
......@@ -29,32 +29,49 @@
ArchiveView::ArchiveView(QWidget *parent)
: QTreeView(parent)
{
}
void ArchiveView::setModel(QAbstractItemModel *model)
{
kDebug (1601) ;
QTreeView::setModel(model);
setSelectionMode( QAbstractItemView::ExtendedSelection );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
setAlternatingRowColors( true );
setAnimated( true );
header()->setResizeMode(0, QHeaderView::ResizeToContents);
setAllColumnsShowFocus( true );
header()->setResizeMode(0, QHeaderView::ResizeToContents);
//drag and drop
setDragEnabled(true);
setAcceptDrops(true);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::DragDrop);
}
void ArchiveView::dragEnterEvent ( QDragEnterEvent * event )
{
//TODO: if no model, trigger some mechanism to create one automatically!
if (!model()) return;
if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
kDebug(1601) << event;
QTreeView::dragEnterEvent(event);
return;
}
void ArchiveView::dropEvent ( QDropEvent * event )
{
kDebug(1601) << event;
QTreeView::dropEvent(event);
return;
}
void ArchiveView::dragMoveEvent ( QDragMoveEvent * event )
{
if (!model()) return;
QTreeView::dragMoveEvent(event);
if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
return;
kDebug() << indexAt(event->pos());
event->acceptProposedAction();
}
......@@ -30,8 +30,11 @@ class ArchiveView : public QTreeView
public:
ArchiveView(QWidget *parent);
void dragEnterEvent ( class QDragEnterEvent * event );
void dragMoveEvent ( class QDragMoveEvent * event );
virtual void dragEnterEvent ( class QDragEnterEvent * event );
virtual void dropEvent ( class QDropEvent * event );
virtual void dragMoveEvent ( class QDragMoveEvent * event );
void setModel(QAbstractItemModel *model);
};
......
......@@ -127,9 +127,6 @@ void Part::extractSelectedFilesTo(QString localPath)
void Part::setupView()
{
m_view->setModel( m_model );
//For some reason, it's not possible to do this before setting the model.
//TODO: why?
m_view->header()->setResizeMode(0, QHeaderView::ResizeToContents);
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
this, SLOT( updateActions() ) );
......@@ -143,8 +140,6 @@ void Part::setupView()
connect( m_model, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex& ) ),
this, SLOT( adjustColumns( const QModelIndex &, const QModelIndex& ) ) );
connect( m_model, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex& ) ),
this, SLOT( adjustColumns( const QModelIndex &, const QModelIndex& ) ) );
}
void Part::setupActions()
......
......@@ -152,7 +152,7 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
kp << "e";
}
kp << "-p-";
kp << "-p-"; // do not query for password
if ( !password().isEmpty() ) kp << "-p" + password();
kp << m_filename;
......@@ -203,7 +203,6 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
return false;
}
}
kDebug( 1601 ) << "Finished reading rar output";
return true;
}
......@@ -217,6 +216,10 @@ bool RARInterface::addFiles( const QStringList & files )
if (!m_rarpath.isNull()) kp << m_rarpath << "a" << "-c-" << m_filename;
else return false;
kp << "-ep"; // discard paths from input filename
foreach( const QString& file, files )
{
kDebug( 1601 ) << file;
......@@ -241,11 +244,7 @@ bool RARInterface::addFiles( const QStringList & files )
}
}
if (!kp.waitForFinished()) {
kDebug( 1601 ) << "Rar did not finish";
return false;
}
list();
kDebug( 1601 ) << "Finished adding files";
......@@ -255,7 +254,37 @@ bool RARInterface::addFiles( const QStringList & files )
bool RARInterface::deleteFiles( const QList<QVariant> & files )
{
kDebug( 1601 ) << "Will try to delete " << files << " from " << m_filename;
return false;
KProcess kp;
if (!m_rarpath.isNull()) kp << m_rarpath << "d" << m_filename;
else return false;
foreach( const QVariant& file, files )
{
kDebug( 1601 ) << file;
kp << file.toString();
}
kp.setOutputChannelMode(KProcess::MergedChannels);
kp.start();
if (!kp.waitForStarted()){
kDebug( 1601 ) << "Rar did not start";
return false;
}
if (!kp.waitForFinished()) {
kDebug( 1601 ) << "Rar did not finish";
return false;
}
foreach( const QVariant& file, files )
{
kDebug( 1601 ) << file;
entryRemoved(file.toString());
}
return false;
}
KERFUFFLE_PLUGIN_FACTORY( RARInterface )
......
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