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

#include <QAbstractItemModel>
26
#include <kjobtrackerinterface.h>
27
#include "kerfuffle/archive.h"
28
#include "kerfuffle/queries.h"
29

30
class ArchiveNode;
31 32
class ArchiveDirNode;

33 34
using namespace Kerfuffle;

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

Harald Hvaal's avatar
Harald Hvaal committed
52 53
		virtual void sort ( int column, Qt::SortOrder order = Qt::AscendingOrder );

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

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

61

62
		KJob* setArchive( Kerfuffle::Archive *archive );
63
		Kerfuffle::Archive *archive() const { return m_archive; }
64

65
		ArchiveEntry entryForIndex( const QModelIndex &index );
66
		int childCount( const QModelIndex &index );
67

68 69
		ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, ExtractionOptions options = ExtractionOptions()) const;
		ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, const Kerfuffle::ExtractionOptions options = ExtractionOptions()	) const;
70

71
		AddJob* addFiles( const QStringList & paths, const CompressionOptions& options = CompressionOptions() );
72
		DeleteJob* deleteFiles( const QList<QVariant> & files );
73

74 75
	signals:
		void loadingStarted();
76
		void loadingFinished(KJob *);
Henrique Pinto's avatar
Henrique Pinto committed
77
		void extractionFinished( bool success );
78
		void error( const QString& error, const QString& details );
79
		void droppedFiles(const QStringList& files, const QString& path = QString());
80

81
	private slots:
82
		void slotNewEntryFromSetArchive( const ArchiveEntry& entry );
83
		void slotNewEntry( const ArchiveEntry& entry );
84
		void slotLoadingFinished(KJob *job);
85
		void slotEntryRemoved( const QString & path );
86
		void slotUserQuery(Query *query);
87
		void slotCleanupEmptyDirs();
88 89

	private:
90 91
		ArchiveDirNode* parentFor( const ArchiveEntry& entry );
		QModelIndex indexForNode( ArchiveNode *node );
Harald Hvaal's avatar
Harald Hvaal committed
92 93
		static bool compareAscending(const QModelIndex& a, const QModelIndex& b);
		static bool compareDescending(const QModelIndex& a, const QModelIndex& b);
94 95 96 97
		/**
		 * Insert the node @p node into the model, ensuring all views are notified
		 * of the change.
		 */
98 99 100
		enum InsertBehaviour { NotifyViews, DoNotNotifyViews };
		void insertNode( ArchiveNode *node, InsertBehaviour behaviour = NotifyViews );
		void newEntry(const ArchiveEntry& entry, InsertBehaviour behaviour);
101

102
		QList<ArchiveEntry> m_newArchiveEntries; // holds entries from opening a new archive until it's totally open
103
		QList<int> m_showColumns;
104
		Kerfuffle::Archive *m_archive;
105
		ArchiveDirNode *m_rootNode;
106
		KJobTrackerInterface *m_jobTracker;
107 108 109
};

#endif // ARCHIVEMODEL_H