2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 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
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
#include <algorithm>
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <cassert>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <memory>
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-08-10 19:40:58 +00:00
|
|
|
#include <libtransmission/transmission.h> // priorities
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "FileTreeItem.h"
|
|
|
|
#include "FileTreeModel.h"
|
|
|
|
|
2015-07-12 20:48:54 +00:00
|
|
|
namespace
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
class PathIteratorBase
|
|
|
|
{
|
|
|
|
protected:
|
2021-08-15 09:41:48 +00:00
|
|
|
PathIteratorBase(QString const& path, int slash_index)
|
|
|
|
: path_(path)
|
|
|
|
, slash_index_(slash_index)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
token_.reserve(path.size() / 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const& path_;
|
|
|
|
QString token_;
|
|
|
|
int slash_index_;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
static QChar const SlashChar;
|
2017-04-19 12:04:45 +00:00
|
|
|
};
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
QChar const PathIteratorBase::SlashChar = QLatin1Char('/');
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
class ForwardPathIterator : public PathIteratorBase
|
|
|
|
{
|
|
|
|
public:
|
2021-08-15 09:41:48 +00:00
|
|
|
explicit ForwardPathIterator(QString const& path)
|
|
|
|
: PathIteratorBase(path, path.size() - 1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
[[nodiscard]] bool hasNext() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return slash_index_ > -1;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-07-12 20:48:54 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const& next()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-07-27 14:03:13 +00:00
|
|
|
int const new_slash_index = path_.lastIndexOf(SlashChar, slash_index_);
|
2020-05-27 21:53:12 +00:00
|
|
|
token_.truncate(0);
|
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
|
|
|
token_.append(&path_.data()[new_slash_index + 1], slash_index_ - new_slash_index);
|
2020-05-27 21:53:12 +00:00
|
|
|
slash_index_ = new_slash_index - 1;
|
|
|
|
return token_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BackwardPathIterator : public PathIteratorBase
|
|
|
|
{
|
|
|
|
public:
|
2021-08-15 09:41:48 +00:00
|
|
|
explicit BackwardPathIterator(QString const& path)
|
|
|
|
: PathIteratorBase(path, 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
[[nodiscard]] bool hasNext() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return slash_index_ < path_.size();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const& next()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
int new_slash_index = path_.indexOf(SlashChar, slash_index_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (new_slash_index == -1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
new_slash_index = path_.size();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
token_.truncate(0);
|
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
|
|
|
token_.append(&path_.data()[slash_index_], new_slash_index - slash_index_);
|
2020-05-27 21:53:12 +00:00
|
|
|
slash_index_ = new_slash_index + 1;
|
|
|
|
return token_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
2015-07-12 20:48:54 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FileTreeModel::FileTreeModel(QObject* parent, bool is_editable)
|
2021-11-26 01:14:14 +00:00
|
|
|
: QAbstractItemModel{ parent }
|
2021-11-28 01:58:35 +00:00
|
|
|
, root_item_{ std::make_unique<FileTreeItem>() }
|
2021-11-26 01:14:14 +00:00
|
|
|
, is_editable_{ is_editable }
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeModel::~FileTreeModel()
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
clear();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void FileTreeModel::setEditable(bool is_editable)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
is_editable_ = is_editable;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem* FileTreeModel::itemFromIndex(QModelIndex const& index) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!index.isValid())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
assert(index.model() == this);
|
|
|
|
return static_cast<FileTreeItem*>(index.internalPointer());
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndexList FileTreeModel::getOrphanIndices(QModelIndexList const& indices) const
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QModelIndexList orphan_indices = indices;
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
std::sort(orphan_indices.begin(), orphan_indices.end());
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QMutableListIterator<QModelIndex> it(orphan_indices); it.hasNext();)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex walk = it.next();
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (;;)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
walk = parent(walk, walk.column());
|
|
|
|
|
|
|
|
if (!walk.isValid())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (std::binary_search(orphan_indices.begin(), orphan_indices.end(), walk))
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
it.remove();
|
|
|
|
break;
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
return orphan_indices;
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QVariant FileTreeModel::data(QModelIndex const& index, int role) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (index.isValid())
|
|
|
|
{
|
2020-09-08 16:51:33 +00:00
|
|
|
return itemFromIndex(index)->data(index.column(), role);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-09-08 16:51:33 +00:00
|
|
|
return {};
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
Qt::ItemFlags FileTreeModel::flags(QModelIndex const& index) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int i(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (is_editable_ && index.column() == COL_NAME)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
i |= Qt::ItemIsEditable;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (index.column() == COL_WANTED)
|
|
|
|
{
|
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
|
|
|
i |= Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
return { i };
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 23:26:18 +00:00
|
|
|
bool FileTreeModel::setData(QModelIndex const& index, QVariant const& value, int role)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (role == Qt::EditRole)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-11-02 15:16:12 +00:00
|
|
|
FileTreeItem const* item = itemFromIndex(index);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-09-08 23:26:18 +00:00
|
|
|
emit pathEdited(item->path(), value.toString());
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return false; // don't update the view until the session confirms the change
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QVariant FileTreeModel::headerData(int column, Qt::Orientation orientation, int role) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (column)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case COL_NAME:
|
2020-09-08 16:51:33 +00:00
|
|
|
return tr("File");
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case COL_SIZE:
|
2020-09-08 16:51:33 +00:00
|
|
|
return tr("Size");
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case COL_PROGRESS:
|
2020-09-08 16:51:33 +00:00
|
|
|
return tr("Progress");
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case COL_WANTED:
|
2020-09-08 16:51:33 +00:00
|
|
|
return tr("Download");
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case COL_PRIORITY:
|
2020-09-08 16:51:33 +00:00
|
|
|
return tr("Priority");
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2015-06-10 21:27:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 16:51:33 +00:00
|
|
|
return {};
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndex FileTreeModel::index(int row, int column, QModelIndex const& parent) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (hasIndex(row, column, parent))
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-02-08 03:56:04 +00:00
|
|
|
auto* const parent_item = parent.isValid() ? itemFromIndex(parent) : root_item_.get();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
if (auto* const child_item = parent_item->child(row); child_item != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-02-08 03:56:04 +00:00
|
|
|
return createIndex(row, column, child_item);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
return {};
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndex FileTreeModel::parent(QModelIndex const& child) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return parent(child, 0); // QAbstractItemModel::parent() wants col 0
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QModelIndex FileTreeModel::parent(QModelIndex const& child, int column) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex parent;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (child.isValid())
|
|
|
|
{
|
|
|
|
parent = indexOf(itemFromIndex(child)->parent(), column);
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return parent;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int FileTreeModel::rowCount(QModelIndex const& parent) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2021-11-28 01:58:35 +00:00
|
|
|
FileTreeItem const* parent_item = parent.isValid() ? itemFromIndex(parent) : root_item_.get();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
return parent_item->childCount();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int FileTreeModel::columnCount(QModelIndex const& parent) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
Q_UNUSED(parent)
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return NUM_COLUMNS;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex FileTreeModel::indexOf(FileTreeItem* item, int column) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2021-11-28 01:58:35 +00:00
|
|
|
if (item == nullptr || item == root_item_.get())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-02-08 03:56:04 +00:00
|
|
|
return {};
|
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 createIndex(item->row(), column, item);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FileTreeModel::clearSubtree(QModelIndex const& top)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t i = rowCount(top);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
clearSubtree(index(--i, 0, top));
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
FileTreeItem* const item = itemFromIndex(top);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
if (item == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-16 14:30:05 +00:00
|
|
|
if (auto const idx = item->fileIndex(); idx != -1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-08-16 14:30:05 +00:00
|
|
|
if (auto const iter = index_cache_.find(idx); iter != std::end(index_cache_))
|
|
|
|
{
|
|
|
|
index_cache_.erase(iter);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
delete item;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FileTreeModel::clear()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
beginResetModel();
|
|
|
|
clearSubtree(QModelIndex());
|
2021-11-28 01:58:35 +00:00
|
|
|
root_item_ = std::make_unique<FileTreeItem>();
|
2017-04-19 12:04:45 +00:00
|
|
|
endResetModel();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-08-16 14:30:05 +00:00
|
|
|
assert(std::empty(index_cache_));
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
FileTreeItem* FileTreeModel::findItemForFileIndex(int file_index) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-08-16 14:30:05 +00:00
|
|
|
auto iter = index_cache_.find(file_index);
|
|
|
|
return iter == std::end(index_cache_) ? nullptr : iter->second;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
void FileTreeModel::addFile(
|
|
|
|
int file_index,
|
|
|
|
QString const& filename,
|
|
|
|
bool wanted,
|
|
|
|
int priority,
|
|
|
|
uint64_t total_size,
|
|
|
|
uint64_t have,
|
|
|
|
bool update_fields)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-02-08 03:56:04 +00:00
|
|
|
auto* item = findItemForFileIndex(file_index);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (item != nullptr) // this file is already in the tree, we've added this
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QModelIndex index_with_changed_parents;
|
|
|
|
ForwardPathIterator filename_it(filename);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
while (filename_it.hasNext())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-02-08 05:44:31 +00:00
|
|
|
auto const& token = filename_it.next();
|
|
|
|
auto const& [first_col, last_col] = item->update(token, wanted, priority, have, update_fields);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
if (first_col >= 0)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2022-02-08 05:44:31 +00:00
|
|
|
emit dataChanged(indexOf(item, first_col), indexOf(item, last_col));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
if (!index_with_changed_parents.isValid() && first_col <= COL_PRIORITY && last_col >= COL_SIZE)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
index_with_changed_parents = indexOf(item, 0);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
item = item->parent();
|
|
|
|
}
|
|
|
|
|
2021-11-28 01:58:35 +00:00
|
|
|
assert(item == root_item_.get());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (index_with_changed_parents.isValid())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emitParentsChanged(index_with_changed_parents, COL_SIZE, COL_PRIORITY);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else // we haven't build the FileTreeItems for these tokens yet
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
bool added = false;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-11-28 01:58:35 +00:00
|
|
|
item = root_item_.get();
|
2020-05-27 21:53:12 +00:00
|
|
|
BackwardPathIterator filename_it(filename);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
while (filename_it.hasNext())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const& token = filename_it.next();
|
2017-04-19 12:04:45 +00:00
|
|
|
FileTreeItem* child(item->child(token));
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (child == nullptr)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
added = true;
|
2022-07-27 14:03:13 +00:00
|
|
|
QModelIndex const parent_index(indexOf(item, 0));
|
2017-04-20 16:02:19 +00:00
|
|
|
int const n(item->childCount());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
beginInsertRows(parent_index, n, n);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!filename_it.hasNext())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
child = new FileTreeItem(token, file_index, total_size);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child = new FileTreeItem(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
item->appendChild(child);
|
|
|
|
endInsertRows();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
item = child;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 01:58:35 +00:00
|
|
|
if (item != root_item_.get())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
assert(item->fileIndex() == file_index);
|
|
|
|
assert(item->totalSize() == total_size);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
index_cache_[file_index] = item;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
auto const [first_col, last_col] = item->update(item->name(), wanted, priority, have, added || update_fields);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
if (first_col >= 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-02-08 05:44:31 +00:00
|
|
|
emit dataChanged(indexOf(item, first_col), indexOf(item, last_col));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
void FileTreeModel::emitParentsChanged(
|
|
|
|
QModelIndex const& index,
|
|
|
|
int first_column,
|
|
|
|
int last_column,
|
2020-05-27 21:53:12 +00:00
|
|
|
QSet<QModelIndex>* visited_parent_indices)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
assert(first_column <= last_column);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex walk = index;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (;;)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
walk = parent(walk, first_column);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!walk.isValid())
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (visited_parent_indices != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (visited_parent_indices->contains(walk))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
visited_parent_indices->insert(walk);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
emit dataChanged(walk, walk.sibling(walk.row(), last_column));
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
void FileTreeModel::emitSubtreeChanged(QModelIndex const& idx, int first_column, int last_column)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
assert(first_column <= last_column);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
int const child_count = rowCount(idx);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (child_count == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// tell everyone that this item changed
|
2020-06-05 19:02:11 +00:00
|
|
|
emit dataChanged(index(0, first_column, idx), index(child_count - 1, last_column, idx));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// walk the subitems
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int i = 0; i < child_count; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
emitSubtreeChanged(index(i, 0, idx), first_column, last_column);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FileTreeModel::twiddleWanted(QModelIndexList const& indices)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QMap<bool, QModelIndexList> wanted_indices;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QModelIndex const& i : getOrphanIndices(indices))
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem const* const item = itemFromIndex(i);
|
2020-05-27 21:53:12 +00:00
|
|
|
wanted_indices[item->isSubtreeWanted() != Qt::Checked] << i;
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int i = 0; i <= 1; ++i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (wanted_indices.contains(i))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setWanted(wanted_indices[i], i != 0);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FileTreeModel::twiddlePriority(QModelIndexList const& indices)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QMap<int, QModelIndexList> priority_indices;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QModelIndex const& i : getOrphanIndices(indices))
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem const* const item = itemFromIndex(i);
|
2017-04-19 12:04:45 +00:00
|
|
|
int priority = item->priority();
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// ... -> normal -> high -> low -> normal -> ...; mixed -> normal
|
2022-02-09 02:25:19 +00:00
|
|
|
if (priority == FileTreeItem::Normal)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
}
|
2022-02-09 02:25:19 +00:00
|
|
|
else if (priority == FileTreeItem::High)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
priority_indices[priority] << i;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int i = TR_PRI_LOW; i <= TR_PRI_HIGH; ++i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (priority_indices.contains(i))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setPriority(priority_indices[i], i);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FileTreeModel::setWanted(QModelIndexList const& indices, bool wanted)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (indices.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QModelIndexList const orphan_indices = getOrphanIndices(indices);
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QSet<int> file_ids;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QModelIndex const& i : orphan_indices)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
FileTreeItem* const item = itemFromIndex(i);
|
2020-05-27 21:53:12 +00:00
|
|
|
item->setSubtreeWanted(wanted, file_ids);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit dataChanged(i, i);
|
|
|
|
emitSubtreeChanged(i, COL_WANTED, COL_WANTED);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// emit parent changes separately to avoid multiple updates for same items
|
2020-05-27 21:53:12 +00:00
|
|
|
QSet<QModelIndex> parent_indices;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QModelIndex const& i : orphan_indices)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emitParentsChanged(i, COL_SIZE, COL_WANTED, &parent_indices);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!file_ids.isEmpty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emit wantedChanged(file_ids, wanted);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FileTreeModel::setPriority(QModelIndexList const& indices, int priority)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (indices.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QModelIndexList const orphan_indices = getOrphanIndices(indices);
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QSet<int> file_ids;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QModelIndex const& i : orphan_indices)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
FileTreeItem* const item = itemFromIndex(i);
|
2020-05-27 21:53:12 +00:00
|
|
|
item->setSubtreePriority(priority, file_ids);
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit dataChanged(i, i);
|
|
|
|
emitSubtreeChanged(i, COL_PRIORITY, COL_PRIORITY);
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// emit parent changes separately to avoid multiple updates for same items
|
2020-05-27 21:53:12 +00:00
|
|
|
QSet<QModelIndex> parent_indices;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QModelIndex const& i : orphan_indices)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emitParentsChanged(i, COL_PRIORITY, COL_PRIORITY, &parent_indices);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!file_ids.isEmpty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emit priorityChanged(file_ids, priority);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-08-10 19:40:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool FileTreeModel::openFile(QModelIndex const& index)
|
2015-08-10 19:40:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!index.isValid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-11-02 15:16:12 +00:00
|
|
|
FileTreeItem const* const item = itemFromIndex(index);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (item->fileIndex() < 0 || !item->isComplete())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit openRequested(item->path());
|
|
|
|
return true;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|