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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2020-11-02 15:16:12 +00:00
|
|
|
#include <set>
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
size_t 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
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
assert(children_.isEmpty());
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const pos = row();
|
2017-04-30 16:25:26 +00:00
|
|
|
assert(pos >= 0 && "couldn't find child in parent's lookup");
|
2020-05-27 21:53:12 +00:00
|
|
|
parent_->children_.removeAt(pos);
|
|
|
|
parent_->child_rows_.remove(name());
|
|
|
|
parent_->first_unhashed_row_ = pos;
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
size_t const n = childCount();
|
2020-05-27 21:53:12 +00:00
|
|
|
child->parent_ = this;
|
|
|
|
children_.append(child);
|
|
|
|
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
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int const row = getMyChildRows().value(filename, -1);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (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);
|
|
|
|
assert(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
|
|
|
{
|
|
|
|
value = Qt::AlignRight + Qt::AlignVCenter;
|
|
|
|
}
|
|
|
|
|
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();
|
2020-09-03 00:28:36 +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
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (children_.isEmpty())
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case LOW:
|
|
|
|
return tr("Low");
|
|
|
|
|
|
|
|
case HIGH:
|
|
|
|
return tr("High");
|
|
|
|
|
|
|
|
case NORMAL:
|
|
|
|
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
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (children_.isEmpty())
|
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:
|
2015-06-10 21:27:11 +00:00
|
|
|
i |= LOW;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_PRI_HIGH:
|
2015-06-10 21:27:11 +00:00
|
|
|
i |= HIGH;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2015-06-10 21:27:11 +00:00
|
|
|
i |= NORMAL;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FileTreeItem::setSubtreePriority(int i, QSet<int>& ids)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (priority_ != i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
priority_ = i;
|
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->setSubtreePriority(i, ids);
|
|
|
|
}
|
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
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (children_.isEmpty())
|
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
|
|
|
}
|