Commit 9b1bb6b3 authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* Reuse the model when loading a different archive

svn path=/branches/work/libarchive-based-ark/ark/; revision=689495
parent ba5de2d4
......@@ -87,7 +87,7 @@ class ArchiveDirNode: public ArchiveNode
~ArchiveDirNode()
{
qDeleteAll( m_entries );
clear();
}
QList<ArchiveNode*>& entries() { return m_entries; }
......@@ -106,6 +106,12 @@ class ArchiveDirNode: public ArchiveNode
return 0;
}
void clear()
{
qDeleteAll( m_entries );
m_entries.clear();
}
private:
QList<ArchiveNode*> m_entries;
};
......@@ -122,15 +128,10 @@ int ArchiveNode::row()
return 0;
}
ArchiveModel::ArchiveModel( Arch *archive, QObject *parent )
: QAbstractItemModel( parent ), m_archive( archive ),
ArchiveModel::ArchiveModel( QObject *parent )
: QAbstractItemModel( parent ), m_archive( 0 ),
m_rootNode( new ArchiveDirNode( 0, ArchiveEntry() ) )
{
m_archive->setParent( this );
connect( m_archive, SIGNAL( newEntry( const ArchiveEntry& ) ),
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
m_archive->open();
}
ArchiveModel::~ArchiveModel()
......@@ -312,3 +313,18 @@ void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
endInsertRows();
}
}
void ArchiveModel::setArchive( Arch *archive )
{
m_archive = archive;
m_rootNode->clear();
if ( m_archive )
{
m_archive->setParent( this );
connect( m_archive, SIGNAL( newEntry( const ArchiveEntry& ) ),
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
m_archive->open();
}
reset();
}
......@@ -31,7 +31,7 @@ class ArchiveModel: public QAbstractItemModel
{
Q_OBJECT
public:
ArchiveModel( Arch *archive, QObject *parent = 0 );
ArchiveModel( QObject *parent = 0 );
~ArchiveModel();
QVariant data( const QModelIndex &index, int role ) const;
......@@ -44,6 +44,8 @@ class ArchiveModel: public QAbstractItemModel
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
void setArchive( Arch *archive );
private slots:
void slotNewEntry( const ArchiveEntry& entry );
......
......@@ -29,12 +29,13 @@ typedef KParts::GenericFactory<Part> Factory;
K_EXPORT_COMPONENT_FACTORY( libarkpartnew, Factory );
Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
: KParts::ReadWritePart( parent ), m_model( 0 ), m_view( new QTreeView( parentWidget ) )
: KParts::ReadWritePart( parent ), m_model( new ArchiveModel( this ) ), m_view( new QTreeView( parentWidget ) )
{
Q_UNUSED( args );
setComponentData( Factory::componentData() );
setXMLFile( "ark_part_new.rc" );
setWidget( m_view );
m_view->setModel( m_model );
}
Part::~Part()
......@@ -48,11 +49,10 @@ KAboutData* Part::createAboutData()
bool Part::openFile()
{
delete m_model;
m_model = new ArchiveModel( Arch::factory( localFilePath() ), this );
m_view->setModel( m_model );
Arch *archive = Arch::factory( localFilePath() );
m_model->setArchive( archive );
return true;
return ( archive != 0 );
}
bool Part::saveFile()
......
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