archivemodel.h 2.41 KB
Newer Older
Henrique Pinto's avatar
Henrique Pinto committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * ark -- archiver for the KDE project
 *
 * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
 *
 * 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.
 *
 */
21 22 23 24
#ifndef ARCHIVEMODEL_H
#define ARCHIVEMODEL_H

#include <QAbstractItemModel>
25
#include "kerfuffle/archive.h"
26

27
class ArchiveNode;
28 29
class ArchiveDirNode;

30 31
using namespace Kerfuffle;

32 33 34 35
class ArchiveModel: public QAbstractItemModel
{
	Q_OBJECT
	public:
36
		ArchiveModel( QObject *parent = 0 );
37 38 39 40 41 42 43 44 45 46 47 48
		~ArchiveModel();

		QVariant data( const QModelIndex &index, int role ) const;
		Qt::ItemFlags flags( const QModelIndex &index ) const;
		QVariant headerData( int section, Qt::Orientation orientation,
		                     int role = Qt::DisplayRole ) const;
		QModelIndex index( int row, int column,
		                   const QModelIndex &parent = QModelIndex() ) const;
		QModelIndex parent( const QModelIndex &index ) const;
		int rowCount( const QModelIndex &parent = QModelIndex() ) const;
		int columnCount( const QModelIndex &parent = QModelIndex() ) const;

49 50
		void setArchive( Kerfuffle::Archive *archive );
		Kerfuffle::Archive *archive() const { return m_archive; }
51

52
		ArchiveEntry entryForIndex( const QModelIndex &index );
53
		int childCount( const QModelIndex &index );
54

55
		ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths = false );
Henrique Pinto's avatar
Henrique Pinto committed
56

57 58 59
	signals:
		void loadingStarted();
		void loadingFinished();
Henrique Pinto's avatar
Henrique Pinto committed
60
		void extractionFinished( bool success );
61
		void error( const QString& error, const QString& details );
62

63 64 65 66
	private slots:
		void slotNewEntry( const ArchiveEntry& entry );

	private:
67 68 69
		ArchiveDirNode* parentFor( const ArchiveEntry& entry );
		QModelIndex indexForNode( ArchiveNode *node );

70
		Kerfuffle::Archive *m_archive;
71 72 73 74
		ArchiveDirNode *m_rootNode;
};

#endif // ARCHIVEMODEL_H