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

Added ArchiveView class. Implemented drag/drop for adding files

svn path=/trunk/KDE/kdeutils/ark/; revision=844756
parent 87289954
......@@ -10,6 +10,7 @@ set(arkpart_PART_SRCS
infopanel.cpp
arkviewer.cpp
archivemodel.cpp
archiveview.cpp
jobtracker.cpp
dnddbusinterface.cpp
)
......
......@@ -416,6 +416,26 @@ QMimeData * ArchiveModel::mimeData ( const QModelIndexList & indexes ) const
return data;
}
bool ArchiveModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
{
if (action == Qt::IgnoreAction)
return true;
if (!data->hasFormat("text/uri-list"))
return false;
QStringList paths;
foreach(const QUrl &url, data->urls()) {
paths << url.path();
}
//TODO: if this job fails, no error will be displayeed to the user!!!
addFiles(paths)->start();
kDebug() << "Yes it's a drop!" << paths;
return true;
}
ArchiveDirNode* ArchiveModel::parentFor( const ArchiveEntry& entry )
{
QStringList pieces = entry[ FileName ].toString().split( '/', QString::SkipEmptyParts );
......
......@@ -53,6 +53,8 @@ class ArchiveModel: public QAbstractItemModel
QStringList mimeTypes () const;
QMimeData * mimeData ( const QModelIndexList & indexes ) const;
virtual bool dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );
void setArchive( Kerfuffle::Archive *archive );
Kerfuffle::Archive *archive() const { return m_archive; }
......@@ -73,6 +75,7 @@ class ArchiveModel: public QAbstractItemModel
void loadingFinished();
void extractionFinished( bool success );
void error( const QString& error, const QString& details );
void startedAddFilesJob ( KJob *job);
private slots:
void slotNewEntry( const ArchiveEntry& entry );
......
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv (at@at) stud.ntnu.no>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "archiveview.h"
#include <QHeaderView>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <kdebug.h>
ArchiveView::ArchiveView(QWidget *parent)
: QTreeView(parent)
{
setSelectionMode( QAbstractItemView::ExtendedSelection );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
setAlternatingRowColors( true );
setAnimated( true );
header()->setResizeMode(0, QHeaderView::ResizeToContents);
setAllColumnsShowFocus( true );
//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();
}
void ArchiveView::dragMoveEvent ( QDragMoveEvent * event )
{
if (!model()) return;
kDebug() << indexAt(event->pos());
event->acceptProposedAction();
}
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv (at@at) stud.ntnu.no>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef _ARCHIVEVIEW_H_
#define _ARCHIVEVIEW_H_
#include <QTreeView>
class ArchiveView : public QTreeView
{
Q_OBJECT
public:
ArchiveView(QWidget *parent);
void dragEnterEvent ( class QDragEnterEvent * event );
void dragMoveEvent ( class QDragMoveEvent * event );
};
#endif /* _ARCHIVEVIEW_H_ */
......@@ -20,6 +20,7 @@
*/
#include "part.h"
#include "archivemodel.h"
#include "archiveview.h"
#include "infopanel.h"
#include "arkviewer.h"
#include "kerfuffle/extractiondialog.h"
......@@ -46,7 +47,6 @@
#include <KMessageBox>
#include <QTreeView>
#include <QCursor>
#include <QAction>
#include <QSplitter>
......@@ -73,7 +73,7 @@ Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
setWidget( mainWidget );
QSplitter *splitter = new QSplitter( Qt::Horizontal, mainWidget );
m_view = new QTreeView( mainWidget );
m_view = new ArchiveView( mainWidget );
m_infoPanel = new InfoPanel( m_model, mainWidget );
splitter->addWidget( m_view );
splitter->addWidget( m_infoPanel );
......@@ -126,31 +126,25 @@ void Part::extractSelectedFilesTo(QString localPath)
void Part::setupView()
{
m_view->setSelectionMode( QAbstractItemView::ExtendedSelection );
m_view->setModel( m_model );
m_view->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_view->setAlternatingRowColors( true );
m_view->setAnimated( true );
//For some reason, it's not possible to do this before setting the model.
//TODO: why?
m_view->header()->setResizeMode(0, QHeaderView::ResizeToContents);
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 & ) ),
this, SLOT( selectionChanged() ) );
//TODO: subclass the itemview and fix an actual eventhandler
//TODO: fix an actual eventhandler
connect( m_view, SIGNAL( doubleClicked( const QModelIndex & ) ),
this, SLOT( slotPreview( const QModelIndex & ) ) );
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()
......
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