archivemodel.h 3.42 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 <kjobtrackerinterface.h>
26
#include "kerfuffle/archive.h"
27
#include "kerfuffle/queries.h"
28

29
class ArchiveNode;
30
31
class ArchiveDirNode;

32
33
using namespace Kerfuffle;

34
35
36
37
class ArchiveModel: public QAbstractItemModel
{
	Q_OBJECT
	public:
38
		ArchiveModel( QObject *parent = 0 );
39
40
41
42
43
44
45
46
47
48
49
50
		~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;

51
		//drag and drop related
52
53
54
		virtual Qt::DropActions supportedDropActions () const;
		virtual QStringList mimeTypes () const;
		virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
55

56
57
		virtual bool dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );

58

59
60
		void setArchive( Kerfuffle::Archive *archive );
		Kerfuffle::Archive *archive() const { return m_archive; }
61

62
		ArchiveEntry entryForIndex( const QModelIndex &index );
63
		int childCount( const QModelIndex &index );
64

65
66
		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;
67

68
		AddJob* addFiles( const QStringList & paths );
69
		DeleteJob* deleteFiles( const QList<QVariant> & files );
70

71
		void setJobTracker( KJobTrackerInterface *tracker ) { m_jobTracker = tracker; }
Henrique Pinto's avatar
Henrique Pinto committed
72

73
74
75
	signals:
		void loadingStarted();
		void loadingFinished();
Henrique Pinto's avatar
Henrique Pinto committed
76
		void extractionFinished( bool success );
77
		void error( const QString& error, const QString& details );
78
		void startedAddFilesJob ( KJob *job);
79

80
81
	private slots:
		void slotNewEntry( const ArchiveEntry& entry );
82
		void slotEntryRemoved( const QString & path );
83
		void slotUserQuery(Query *query);
84
85

	private:
86
87
		ArchiveDirNode* parentFor( const ArchiveEntry& entry );
		QModelIndex indexForNode( ArchiveNode *node );
88
89
90
91
92
		/**
		 * Insert the node @p node into the model, ensuring all views are notified
		 * of the change.
		 */
		void insertNode( ArchiveNode *node );
93

94
		Kerfuffle::Archive *m_archive;
95
		ArchiveDirNode *m_rootNode;
96
		KJobTrackerInterface *m_jobTracker;
97
98
99
};

#endif // ARCHIVEMODEL_H