2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © 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>
|
2023-06-30 19:36:08 +00:00
|
|
|
#include <unordered_map>
|
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 <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
#include <libtransmission/tr-macros.h>
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2023-06-30 19:36:08 +00:00
|
|
|
#include "Utils.h" // for std::hash<QString>
|
2023-10-25 01:14:37 +00:00
|
|
|
#include "Typedefs.h"
|
2023-06-30 19:36:08 +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
|
|
|
|
2023-07-18 15:20:17 +00:00
|
|
|
FileTreeItem(QString const& name = QString{}, int file_index = -1, uint64_t size = 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
: 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);
|
2023-10-25 01:14:37 +00:00
|
|
|
void setSubtreeWanted(bool wanted, file_indices_t& setme_changed_ids);
|
|
|
|
void setSubtreePriority(int priority, file_indices_t& setme_changed_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
|
|
|
}
|
|
|
|
|
2023-07-16 02:55:44 +00:00
|
|
|
[[nodiscard]] constexpr auto isComplete() const noexcept
|
|
|
|
{
|
|
|
|
return have_size_ == totalSize();
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString path() 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;
|
2023-06-30 19:36:08 +00:00
|
|
|
std::unordered_map<QString, int> const& getMyChildRows() const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
FileTreeItem* parent_ = {};
|
2023-06-30 19:36:08 +00:00
|
|
|
mutable std::unordered_map<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_ = {};
|
2023-06-30 19:36:08 +00:00
|
|
|
mutable 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
|
|
|
};
|