2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-06-12 22:41:36 +00:00
|
|
|
#include <cstdint>
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QCoreApplication>
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <QHash>
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QList>
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
#include <libtransmission/tr-macros.h>
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
class FileTreeItem
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(FileTreeItem)
|
2020-08-11 18:11:55 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(FileTreeItem)
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2022-02-09 02:25:19 +00:00
|
|
|
static auto constexpr Low = int{ 1 << 0 };
|
|
|
|
static auto constexpr Normal = int{ 1 << 1 };
|
|
|
|
static auto constexpr High = int{ 1 << 2 };
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FileTreeItem(QString const& name = QString(), int file_index = -1, uint64_t size = 0)
|
|
|
|
: name_(name)
|
|
|
|
, total_size_(size)
|
|
|
|
, file_index_(file_index)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
~FileTreeItem();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void appendChild(FileTreeItem* child);
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem* child(QString const& filename);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
FileTreeItem* child(int row)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return children_.at(row);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int childCount() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return children_.size();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeItem* parent()
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return parent_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem const* parent() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return parent_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int row() const;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const& name() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return name_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const;
|
2020-05-27 21:53:12 +00:00
|
|
|
std::pair<int, int> update(QString const& name, bool want, int priority, uint64_t have, bool update_fields);
|
|
|
|
void setSubtreeWanted(bool, QSet<int>& file_ids);
|
|
|
|
void setSubtreePriority(int priority, QSet<int>& file_ids);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
int fileIndex() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return file_index_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t totalSize() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return total_size_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString path() const;
|
|
|
|
bool isComplete() const;
|
|
|
|
int priority() const;
|
|
|
|
int isSubtreeWanted() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString priorityString() const;
|
|
|
|
QString sizeString() const;
|
|
|
|
void getSubtreeWantedSize(uint64_t& have, uint64_t& total) const;
|
|
|
|
double progress() const;
|
|
|
|
uint64_t size() const;
|
2017-04-20 16:02:19 +00:00
|
|
|
QHash<QString, int> const& getMyChildRows();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
FileTreeItem* parent_ = {};
|
|
|
|
QHash<QString, int> child_rows_;
|
|
|
|
QList<FileTreeItem*> children_;
|
|
|
|
QString name_;
|
|
|
|
uint64_t const total_size_ = {};
|
|
|
|
uint64_t have_size_ = {};
|
2020-11-09 03:31:02 +00:00
|
|
|
int first_unhashed_row_ = {};
|
2020-05-27 21:53:12 +00:00
|
|
|
int const file_index_ = {};
|
|
|
|
int priority_ = {};
|
|
|
|
bool is_wanted_ = {};
|
2015-06-10 21:27:11 +00:00
|
|
|
};
|