2015-06-10 21:27:11 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
#include <cstdint> // uint64_t
|
2015-06-10 21:27:11 +00:00
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QSet>
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "Macros.h"
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
class FileTreeItem;
|
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
class FileTreeModel final : public QAbstractItemModel
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-08-11 18:11:55 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(FileTreeModel)
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2015-06-10 21:27:11 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
COL_NAME,
|
|
|
|
COL_SIZE,
|
|
|
|
COL_PROGRESS,
|
|
|
|
COL_WANTED,
|
|
|
|
COL_PRIORITY,
|
|
|
|
//
|
|
|
|
NUM_COLUMNS
|
2015-06-10 21:27:11 +00:00
|
|
|
};
|
|
|
|
|
2015-06-15 21:07:46 +00:00
|
|
|
enum Role
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
SortRole = Qt::UserRole,
|
|
|
|
FileIndexRole,
|
|
|
|
WantedRole,
|
|
|
|
CompleteRole
|
2015-06-15 21:07:46 +00:00
|
|
|
};
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
FileTreeModel(QObject* parent = nullptr, bool is_editable = true);
|
2020-09-09 14:24:39 +00:00
|
|
|
~FileTreeModel() override;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void setEditable(bool editable);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void clear();
|
2017-04-20 16:02:19 +00:00
|
|
|
void addFile(int index, QString const& filename, bool wanted, int priority, uint64_t size, uint64_t have,
|
2020-05-27 21:53:12 +00:00
|
|
|
bool torrent_changed);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool openFile(QModelIndex const& index);
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void twiddleWanted(QModelIndexList const& indices);
|
|
|
|
void twiddlePriority(QModelIndexList const& indices);
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void setWanted(QModelIndexList const& indices, bool wanted);
|
|
|
|
void setPriority(QModelIndexList const& indices, int priority);
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndex parent(QModelIndex const& child, int column) const;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
|
|
|
// QAbstractItemModel
|
2019-11-12 01:37:05 +00:00
|
|
|
QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override;
|
|
|
|
Qt::ItemFlags flags(QModelIndex const& index) const override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
2020-05-27 21:53:12 +00:00
|
|
|
QModelIndex index(int row, int column, QModelIndex const& parent = {}) const override;
|
2019-11-12 01:37:05 +00:00
|
|
|
QModelIndex parent(QModelIndex const& child) const override;
|
2020-05-27 21:53:12 +00:00
|
|
|
int rowCount(QModelIndex const& parent = {}) const override;
|
|
|
|
int columnCount(QModelIndex const& parent = {}) const override;
|
2019-11-12 01:37:05 +00:00
|
|
|
bool setData(QModelIndex const& index, QVariant const& value, int role = Qt::EditRole) override;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
signals:
|
2020-05-27 21:53:12 +00:00
|
|
|
void priorityChanged(QSet<int> const& file_indices, int);
|
|
|
|
void wantedChanged(QSet<int> const& file_indices, bool);
|
|
|
|
void pathEdited(QString const& oldpath, QString const& new_name);
|
2017-04-20 16:02:19 +00:00
|
|
|
void openRequested(QString const& path);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-20 16:02:19 +00:00
|
|
|
void clearSubtree(QModelIndex const&);
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex indexOf(FileTreeItem*, int column) const;
|
2020-05-27 21:53:12 +00:00
|
|
|
void emitParentsChanged(QModelIndex const&, int first_column, int last_column,
|
|
|
|
QSet<QModelIndex>* visited_parent_indices = nullptr);
|
|
|
|
void emitSubtreeChanged(QModelIndex const&, int first_column, int last_column);
|
|
|
|
FileTreeItem* findItemForFileIndex(int file_index) const;
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem* itemFromIndex(QModelIndex const&) const;
|
|
|
|
QModelIndexList getOrphanIndices(QModelIndexList const& indices) const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QMap<int, FileTreeItem*> index_cache_;
|
|
|
|
FileTreeItem* root_item_ = {};
|
|
|
|
bool is_editable_ = {};
|
2015-06-10 21:27:11 +00:00
|
|
|
};
|