2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2009-2023 Mnemosyne LLC.
|
2022-02-07 16:25:02 +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
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2020-11-02 15:16:12 +00:00
|
|
|
#include <set>
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <utility>
|
2015-06-10 21:27:11 +00:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QStyle>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h> // priorities
|
|
|
|
|
|
|
|
#include "FileTreeItem.h"
|
|
|
|
#include "FileTreeModel.h"
|
|
|
|
#include "Formatter.h"
|
2020-08-15 15:42:51 +00:00
|
|
|
#include "IconCache.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QHash<QString, int> const& FileTreeItem::getMyChildRows()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-11-09 03:31:02 +00:00
|
|
|
int const n = childCount();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// ensure that all the rows are hashed
|
2020-05-27 21:53:12 +00:00
|
|
|
while (first_unhashed_row_ < n)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
child_rows_.insert(children_[first_unhashed_row_]->name(), first_unhashed_row_);
|
|
|
|
++first_unhashed_row_;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
return child_rows_;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
FileTreeItem::~FileTreeItem()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-04-02 14:06:02 +00:00
|
|
|
assert(std::empty(children_));
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-04-02 14:06:02 +00:00
|
|
|
if (parent_ == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the parent's reference to this child
|
|
|
|
auto& siblings = parent_->children_;
|
|
|
|
auto it = std::find(std::begin(siblings), std::end(siblings), this);
|
|
|
|
if (it == std::end(siblings))
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-04-02 14:06:02 +00:00
|
|
|
return;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2022-04-02 14:06:02 +00:00
|
|
|
|
|
|
|
// remove this child from the parent
|
|
|
|
parent_->child_rows_.remove(name());
|
|
|
|
it = siblings.erase(it);
|
|
|
|
|
|
|
|
// invalidate the row numbers of the siblings that came after this child
|
|
|
|
parent_->first_unhashed_row_ = std::distance(std::begin(siblings), it);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FileTreeItem::appendChild(FileTreeItem* child)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-11-09 03:31:02 +00:00
|
|
|
int const n = childCount();
|
2020-05-27 21:53:12 +00:00
|
|
|
child->parent_ = this;
|
2022-04-02 14:06:02 +00:00
|
|
|
children_.push_back(child);
|
2020-05-27 21:53:12 +00:00
|
|
|
first_unhashed_row_ = n;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem* FileTreeItem::child(QString const& filename)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-30 09:29:58 +00:00
|
|
|
FileTreeItem* item(nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (int const row = getMyChildRows().value(filename, -1); row != -1)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
item = child(row);
|
|
|
|
assert(filename == item->name());
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return item;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int FileTreeItem::row() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int i(-1);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (parent_ != nullptr)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
i = parent_->getMyChildRows().value(name(), -1);
|
2022-11-24 16:17:02 +00:00
|
|
|
assert(i == -1 || this == parent_->children_[i]);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return i;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QVariant FileTreeItem::data(int column, int role) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QVariant value;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (role)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case FileTreeModel::FileIndexRole:
|
2020-05-27 21:53:12 +00:00
|
|
|
value.setValue(file_index_);
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case FileTreeModel::WantedRole:
|
|
|
|
value.setValue(isSubtreeWanted());
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case FileTreeModel::CompleteRole:
|
|
|
|
value.setValue(isComplete());
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-09-30 17:26:49 +00:00
|
|
|
case Qt::ToolTipRole:
|
2017-04-19 12:04:45 +00:00
|
|
|
case Qt::EditRole:
|
2015-08-16 22:07:09 +00:00
|
|
|
if (column == FileTreeModel::COL_NAME)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
value.setValue(name());
|
|
|
|
}
|
|
|
|
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Qt::TextAlignmentRole:
|
2015-08-16 22:07:09 +00:00
|
|
|
if (column == FileTreeModel::COL_SIZE)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
value = static_cast<int>(Qt::AlignRight | Qt::AlignVCenter);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
case FileTreeModel::SortRole:
|
2015-08-16 22:07:09 +00:00
|
|
|
switch (column)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
case FileTreeModel::COL_NAME:
|
|
|
|
value.setValue(name());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileTreeModel::COL_SIZE:
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
value.setValue(sizeString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value.setValue<quint64>(size());
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileTreeModel::COL_PROGRESS:
|
|
|
|
value.setValue(progress());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileTreeModel::COL_WANTED:
|
|
|
|
value.setValue(isSubtreeWanted());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileTreeModel::COL_PRIORITY:
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
value.setValue(priorityString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value.setValue(priority());
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Qt::DecorationRole:
|
2015-08-16 22:07:09 +00:00
|
|
|
if (column == FileTreeModel::COL_NAME)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (file_index_ < 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-02 01:13:32 +00:00
|
|
|
value = QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-15 21:07:46 +00:00
|
|
|
else
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-02 15:16:12 +00:00
|
|
|
auto const& icon_cache = IconCache::get();
|
2021-08-15 09:41:48 +00:00
|
|
|
value = childCount() > 0 ? icon_cache.folderIcon() : icon_cache.guessMimeIcon(name(), icon_cache.fileIcon());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 22:07:09 +00:00
|
|
|
break;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return value;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FileTreeItem::getSubtreeWantedSize(uint64_t& have, uint64_t& total) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_wanted_)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
have += have_size_;
|
|
|
|
total += total_size_;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (FileTreeItem const* const i : children_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
i->getSubtreeWantedSize(have, total);
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
double FileTreeItem::progress() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
double d(0);
|
2017-05-01 15:46:41 +00:00
|
|
|
uint64_t have(0);
|
|
|
|
uint64_t total(0);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
getSubtreeWantedSize(have, total);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (total != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-08-11 18:11:55 +00:00
|
|
|
d = static_cast<double>(have) / static_cast<double>(total);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return d;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString FileTreeItem::sizeString() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
return Formatter::get().sizeToString(size());
|
2015-06-15 21:07:46 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t FileTreeItem::size() const
|
2015-06-15 21:07:46 +00:00
|
|
|
{
|
2022-04-02 14:06:02 +00:00
|
|
|
if (std::empty(children_))
|
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
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t have = 0;
|
|
|
|
uint64_t total = 0;
|
|
|
|
getSubtreeWantedSize(have, total);
|
|
|
|
return total;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
std::pair<int, int> FileTreeItem::update(QString const& name, bool wanted, int priority, uint64_t have_size, bool update_fields)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-11-02 15:16:12 +00:00
|
|
|
auto changed_columns = std::set<int>{};
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (name_ != name)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (parent_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
parent_->first_unhashed_row_ = row();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
name_ = name;
|
2020-11-02 15:16:12 +00:00
|
|
|
changed_columns.insert(FileTreeModel::COL_NAME);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (fileIndex() != -1)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (have_size_ != have_size)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
have_size_ = have_size;
|
2020-11-02 15:16:12 +00:00
|
|
|
changed_columns.insert(FileTreeModel::COL_PROGRESS);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (update_fields)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_wanted_ != wanted)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
is_wanted_ = wanted;
|
2020-11-02 15:16:12 +00:00
|
|
|
changed_columns.insert(FileTreeModel::COL_WANTED);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (priority_ != priority)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
priority_ = priority;
|
2020-11-02 15:16:12 +00:00
|
|
|
changed_columns.insert(FileTreeModel::COL_PRIORITY);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
std::pair<int, int> changed(-1, -1);
|
|
|
|
|
2020-11-02 15:16:12 +00:00
|
|
|
if (!changed_columns.empty())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-11-02 15:16:12 +00:00
|
|
|
changed.first = *std::cbegin(changed_columns);
|
|
|
|
changed.second = *std::crbegin(changed_columns);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
return changed;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString FileTreeItem::priorityString() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const i = priority();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-02-09 02:25:19 +00:00
|
|
|
case Low:
|
2017-04-19 12:04:45 +00:00
|
|
|
return tr("Low");
|
|
|
|
|
2022-02-09 02:25:19 +00:00
|
|
|
case High:
|
2017-04-19 12:04:45 +00:00
|
|
|
return tr("High");
|
|
|
|
|
2022-02-09 02:25:19 +00:00
|
|
|
case Normal:
|
2017-04-19 12:04:45 +00:00
|
|
|
return tr("Normal");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return tr("Mixed");
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int FileTreeItem::priority() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int i(0);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-04-02 14:06:02 +00:00
|
|
|
if (std::empty(children_))
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
switch (priority_)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_PRI_LOW:
|
2022-02-09 02:25:19 +00:00
|
|
|
i |= Low;
|
2015-06-10 21:27:11 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_PRI_HIGH:
|
2022-02-09 02:25:19 +00:00
|
|
|
i |= High;
|
2015-06-10 21:27:11 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2022-02-09 02:25:19 +00:00
|
|
|
i |= Normal;
|
2015-06-10 21:27:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (FileTreeItem const* const child : children_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
i |= child->priority();
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return i;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 23:26:18 +00:00
|
|
|
void FileTreeItem::setSubtreePriority(int priority, QSet<int>& ids)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-09-08 23:26:18 +00:00
|
|
|
if (priority_ != priority)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-09-08 23:26:18 +00:00
|
|
|
priority_ = priority;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (file_index_ >= 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ids.insert(file_index_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (FileTreeItem* const child : children_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-08 23:26:18 +00:00
|
|
|
child->setSubtreePriority(priority, ids);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int FileTreeItem::isSubtreeWanted() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-04-02 14:06:02 +00:00
|
|
|
if (std::empty(children_))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return is_wanted_ ? Qt::Checked : Qt::Unchecked;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int wanted(-1);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (FileTreeItem const* const child : children_)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
int const child_wanted = child->isSubtreeWanted();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (wanted == -1)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
wanted = child_wanted;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (wanted != child_wanted)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
wanted = Qt::PartiallyChecked;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (wanted == Qt::PartiallyChecked)
|
|
|
|
{
|
|
|
|
return wanted;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return wanted;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FileTreeItem::setSubtreeWanted(bool b, QSet<int>& ids)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_wanted_ != b)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
is_wanted_ = b;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (file_index_ >= 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ids.insert(file_index_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (FileTreeItem* const child : children_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
child->setSubtreeWanted(b, ids);
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString FileTreeItem::path() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QString item_path;
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem const* item = this;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
while (item != nullptr && !item->name().isEmpty())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (item_path.isEmpty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
item_path = item->name();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
item_path = item->name() + QLatin1Char('/') + item_path;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item = item->parent();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
return item_path;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool FileTreeItem::isComplete() const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return have_size_ == totalSize();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|