mirror of
https://github.com/transmission/transmission.git
synced 2025-12-27 21:53:42 +00:00
refactor: sonarcloud "use if init" statements (#2587)
This commit is contained in:
@@ -475,52 +475,51 @@ void FileList::Impl::set_torrent(int torrentId)
|
||||
torrent_id_ = torrentId;
|
||||
|
||||
/* populate the model */
|
||||
auto* const tor = torrent_id_ > 0 ? core_->find_torrent(torrent_id_) : nullptr;
|
||||
if (tor != nullptr)
|
||||
{
|
||||
// build a GNode tree of the files
|
||||
FileRowNode root;
|
||||
auto& root_data = root.data();
|
||||
root_data.name = tr_torrentName(tor);
|
||||
root_data.index = -1;
|
||||
root_data.length = 0;
|
||||
|
||||
for (tr_file_index_t i = 0, n_files = tr_torrentFileCount(tor); i < n_files; ++i)
|
||||
{
|
||||
auto* parent = &root;
|
||||
auto const file = tr_torrentFile(tor, i);
|
||||
|
||||
for (char const *last = file.name, *next = strchr(last, '/'); last != nullptr;
|
||||
last = next != nullptr ? next + 1 : nullptr, next = last != nullptr ? strchr(last, '/') : nullptr)
|
||||
{
|
||||
bool const isLeaf = next == nullptr;
|
||||
auto name = Glib::ustring(isLeaf ? last : std::string(last, next - last));
|
||||
auto* node = find_child(parent, name);
|
||||
|
||||
if (node == nullptr)
|
||||
{
|
||||
node = new FileRowNode();
|
||||
auto& row = node->data();
|
||||
row.name = std::move(name);
|
||||
row.index = isLeaf ? (int)i : -1;
|
||||
row.length = isLeaf ? file.length : 0;
|
||||
parent->append(*node);
|
||||
}
|
||||
|
||||
parent = node;
|
||||
}
|
||||
}
|
||||
|
||||
// now, add them to the model
|
||||
struct build_data build;
|
||||
build.w = &widget_;
|
||||
build.tor = tor;
|
||||
build.store = store_;
|
||||
root.foreach ([&build](auto& child_node) { buildTree(child_node, build); }, FileRowNode::TRAVERSE_ALL);
|
||||
}
|
||||
|
||||
if (torrent_id_ > 0)
|
||||
{
|
||||
if (auto* const tor = core_->find_torrent(torrent_id_); tor != nullptr)
|
||||
{
|
||||
// build a GNode tree of the files
|
||||
FileRowNode root;
|
||||
auto& root_data = root.data();
|
||||
root_data.name = tr_torrentName(tor);
|
||||
root_data.index = -1;
|
||||
root_data.length = 0;
|
||||
|
||||
for (tr_file_index_t i = 0, n_files = tr_torrentFileCount(tor); i < n_files; ++i)
|
||||
{
|
||||
auto* parent = &root;
|
||||
auto const file = tr_torrentFile(tor, i);
|
||||
|
||||
for (char const *last = file.name, *next = strchr(last, '/'); last != nullptr;
|
||||
last = next != nullptr ? next + 1 : nullptr, next = last != nullptr ? strchr(last, '/') : nullptr)
|
||||
{
|
||||
bool const isLeaf = next == nullptr;
|
||||
auto name = Glib::ustring(isLeaf ? last : std::string(last, next - last));
|
||||
auto* node = find_child(parent, name);
|
||||
|
||||
if (node == nullptr)
|
||||
{
|
||||
node = new FileRowNode();
|
||||
auto& row = node->data();
|
||||
row.name = std::move(name);
|
||||
row.index = isLeaf ? (int)i : -1;
|
||||
row.length = isLeaf ? file.length : 0;
|
||||
parent->append(*node);
|
||||
}
|
||||
|
||||
parent = node;
|
||||
}
|
||||
}
|
||||
|
||||
// now, add them to the model
|
||||
struct build_data build;
|
||||
build.w = &widget_;
|
||||
build.tor = tor;
|
||||
build.store = store_;
|
||||
root.foreach ([&build](auto& child_node) { buildTree(child_node, build); }, FileRowNode::TRAVERSE_ALL);
|
||||
}
|
||||
|
||||
refresh();
|
||||
timeout_tag_ = Glib::signal_timeout().connect_seconds(
|
||||
[this]() { return refresh(), true; },
|
||||
@@ -593,9 +592,8 @@ std::string buildFilename(tr_torrent const* tor, Gtk::TreeModel::iterator const&
|
||||
void FileList::Impl::onRowActivated(Gtk::TreeModel::Path const& path, Gtk::TreeViewColumn* /*col*/)
|
||||
{
|
||||
bool handled = false;
|
||||
auto const* tor = core_->find_torrent(torrent_id_);
|
||||
|
||||
if (tor != nullptr)
|
||||
if (auto const* tor = core_->find_torrent(torrent_id_); tor != nullptr)
|
||||
{
|
||||
if (auto const iter = store_->get_iter(path); iter)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user