archivemodel.h 4.7 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 31 32
using Kerfuffle::ArchiveEntry;
using Kerfuffle::Query;

33
class ArchiveNode;
34 35 36 37
class ArchiveDirNode;

class ArchiveModel: public QAbstractItemModel
{
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    Q_OBJECT
public:
    ArchiveModel(QObject *parent = 0);
    ~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;

    virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);

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

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

    KJob* setArchive(Kerfuffle::Archive *archive);
63
    Kerfuffle::Archive *archive() const;
64

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

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

71 72
    Kerfuffle::AddJob* addFiles(const QStringList & paths, const Kerfuffle::CompressionOptions& options = Kerfuffle::CompressionOptions());
    Kerfuffle::DeleteJob* deleteFiles(const QList<QVariant> & files);
73 74 75 76 77 78 79 80 81

signals:
    void loadingStarted();
    void loadingFinished(KJob *);
    void extractionFinished(bool success);
    void error(const QString& error, const QString& details);
    void droppedFiles(const QStringList& files, const QString& path = QString());

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

private:
90 91 92 93 94 95 96 97 98 99 100
    /**
     * Strips file names that start with './'.
     *
     * For more information, see bug 194241.
     *
     * @param fileName The file name that will be stripped.
     *
     * @return @p fileName without the leading './'
     */
    QString cleanFileName(const QString& fileName);

101
    ArchiveDirNode* parentFor(const Kerfuffle::ArchiveEntry& entry);
102 103 104 105 106 107 108 109 110
    QModelIndex indexForNode(ArchiveNode *node);
    static bool compareAscending(const QModelIndex& a, const QModelIndex& b);
    static bool compareDescending(const QModelIndex& a, const QModelIndex& b);
    /**
     * Insert the node @p node into the model, ensuring all views are notified
     * of the change.
     */
    enum InsertBehaviour { NotifyViews, DoNotNotifyViews };
    void insertNode(ArchiveNode *node, InsertBehaviour behaviour = NotifyViews);
111
    void newEntry(const Kerfuffle::ArchiveEntry& entry, InsertBehaviour behaviour);
112

113
    QList<Kerfuffle::ArchiveEntry> m_newArchiveEntries; // holds entries from opening a new archive until it's totally open
114 115 116 117
    QList<int> m_showColumns;
    Kerfuffle::Archive *m_archive;
    ArchiveDirNode *m_rootNode;
    KJobTrackerInterface *m_jobTracker;
118 119 120
};

#endif // ARCHIVEMODEL_H