2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2009-2023 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// 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>
|
2022-04-02 14:06:02 +00:00
|
|
|
#include <vector>
|
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>
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2022-12-23 21:21:40 +00:00
|
|
|
[[nodiscard]] TR_CONSTEXPR20 int childCount() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-06-13 03:59:30 +00:00
|
|
|
return std::size(children_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 21:21:40 +00:00
|
|
|
[[nodiscard]] constexpr auto* parent() noexcept
|
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
|
|
|
}
|
|
|
|
|
2022-12-23 21:21:40 +00:00
|
|
|
[[nodiscard]] constexpr auto const* parent() const noexcept
|
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;
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] constexpr auto const& name() const noexcept
|
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
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] constexpr auto fileIndex() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return file_index_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] constexpr auto totalSize() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
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_;
|
2022-04-02 14:06:02 +00:00
|
|
|
std::vector<FileTreeItem*> children_;
|
2020-05-27 21:53:12 +00:00
|
|
|
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
|
|
|
};
|