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.
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "FileList.h"
|
|
|
|
|
2022-12-29 02:42:20 +00:00
|
|
|
#include "GtkCompat.h"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "HigWorkarea.h" // GUI_PAD, GUI_PAD_BIG
|
|
|
|
#include "IconCache.h"
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <giomm/icon.h>
|
|
|
|
#include <glibmm/fileutils.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/main.h>
|
|
|
|
#include <glibmm/markup.h>
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
#include <glibmm/nodetree.h>
|
|
|
|
#include <gtkmm/cellrendererpixbuf.h>
|
|
|
|
#include <gtkmm/cellrendererprogress.h>
|
|
|
|
#include <gtkmm/cellrenderertext.h>
|
|
|
|
#include <gtkmm/cellrenderertoggle.h>
|
|
|
|
#include <gtkmm/messagedialog.h>
|
|
|
|
#include <gtkmm/treemodel.h>
|
|
|
|
#include <gtkmm/treemodelcolumn.h>
|
|
|
|
#include <gtkmm/treeselection.h>
|
|
|
|
#include <gtkmm/treestore.h>
|
|
|
|
#include <gtkmm/treeview.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
|
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2022-07-26 02:45:54 +00:00
|
|
|
#include <algorithm>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <cstddef>
|
2022-07-26 02:45:54 +00:00
|
|
|
#include <list>
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <memory>
|
2022-12-16 17:40:28 +00:00
|
|
|
#include <queue>
|
2022-11-14 16:22:38 +00:00
|
|
|
#include <stack>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <string>
|
2022-04-26 23:24:07 +00:00
|
|
|
#include <string_view>
|
2022-07-26 02:45:54 +00:00
|
|
|
#include <unordered_map>
|
2022-04-26 23:24:07 +00:00
|
|
|
#include <utility>
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* these two fields could be any number at all so long as they're not
|
2021-10-18 20:22:31 +00:00
|
|
|
* TR_PRI_LOW, TR_PRI_NORMAL, TR_PRI_HIGH, true, or false */
|
2017-04-19 12:04:45 +00:00
|
|
|
NOT_SET = 1000,
|
|
|
|
MIXED = 1001
|
2008-05-29 02:59:22 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class FileModelColumns : public Gtk::TreeModelColumnRecord
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-11-15 00:53:12 +00:00
|
|
|
FileModelColumns() noexcept
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
add(icon);
|
|
|
|
add(label);
|
|
|
|
add(label_esc);
|
|
|
|
add(prog);
|
2022-03-30 01:52:24 +00:00
|
|
|
add(prog_str);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(index);
|
|
|
|
add(size);
|
|
|
|
add(size_str);
|
|
|
|
add(have);
|
|
|
|
add(priority);
|
|
|
|
add(enabled);
|
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::RefPtr<Gio::Icon>> icon;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> label;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> label_esc;
|
|
|
|
Gtk::TreeModelColumn<int> prog;
|
2022-03-30 01:52:24 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> prog_str;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<unsigned int> index;
|
|
|
|
Gtk::TreeModelColumn<uint64_t> size;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> size_str;
|
|
|
|
Gtk::TreeModelColumn<uint64_t> have;
|
|
|
|
Gtk::TreeModelColumn<int> priority;
|
|
|
|
Gtk::TreeModelColumn<int> enabled;
|
2008-02-10 22:25:42 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
FileModelColumns const file_cols;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class FileList::Impl
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-09-07 22:25:04 +00:00
|
|
|
Impl(
|
|
|
|
FileList& widget,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
Glib::ustring const& view_name,
|
|
|
|
Glib::RefPtr<Session> const& core,
|
|
|
|
tr_torrent_id_t torrent_id);
|
2021-10-18 20:22:31 +00:00
|
|
|
~Impl();
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Impl)
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
void set_torrent(tr_torrent_id_t torrent_id);
|
2022-11-14 16:22:38 +00:00
|
|
|
void reset_torrent();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void clearData();
|
|
|
|
void refresh();
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
bool getAndSelectEventPath(double view_x, double view_y, Gtk::TreeViewColumn*& col, Gtk::TreeModel::Path& path);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-10 19:35:31 +00:00
|
|
|
[[nodiscard]] std::vector<tr_file_index_t> getActiveFilesForPath(Gtk::TreeModel::Path const& path) const;
|
|
|
|
[[nodiscard]] std::vector<tr_file_index_t> getSelectedFilesAndDescendants() const;
|
|
|
|
[[nodiscard]] std::vector<tr_file_index_t> getSubtree(Gtk::TreeModel::Path const& path) const;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
bool onViewButtonPressed(guint button, TrGdkModifierType state, double view_x, double view_y);
|
2021-10-18 20:22:31 +00:00
|
|
|
bool onViewPathToggled(Gtk::TreeViewColumn* col, Gtk::TreeModel::Path const& path);
|
|
|
|
void onRowActivated(Gtk::TreeModel::Path const& path, Gtk::TreeViewColumn* col);
|
|
|
|
void cell_edited_callback(Glib::ustring const& path_string, Glib::ustring const& newname);
|
2022-12-16 17:40:28 +00:00
|
|
|
void on_rename_done(Glib::ustring const& path_string, Glib::ustring const& newname, int error);
|
|
|
|
void on_rename_done_idle(Glib::ustring const& path_string, Glib::ustring const& newname, int error);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FileList& widget_;
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const core_;
|
2021-10-18 20:22:31 +00:00
|
|
|
// GtkWidget* top_ = nullptr; // == widget_
|
|
|
|
Gtk::TreeView* view_ = nullptr;
|
|
|
|
Glib::RefPtr<Gtk::TreeStore> store_;
|
2022-06-17 15:43:04 +00:00
|
|
|
tr_torrent_id_t torrent_id_ = {};
|
2021-10-18 20:22:31 +00:00
|
|
|
sigc::connection timeout_tag_;
|
2022-12-16 17:40:28 +00:00
|
|
|
std::queue<sigc::connection> rename_done_tags_;
|
2021-10-18 20:22:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void FileList::Impl::clearData()
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
torrent_id_ = -1;
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2022-12-16 17:40:28 +00:00
|
|
|
timeout_tag_.disconnect();
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
FileList::Impl::~Impl()
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2022-12-16 17:40:28 +00:00
|
|
|
while (!rename_done_tags_.empty())
|
|
|
|
{
|
|
|
|
rename_done_tags_.front().disconnect();
|
|
|
|
rename_done_tags_.pop();
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
clearData();
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2010-09-17 13:23:20 +00:00
|
|
|
struct RefreshData
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int sort_column_id;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool resort_needed;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor;
|
2010-09-17 13:23:20 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool refreshFilesForeach(
|
|
|
|
Glib::RefPtr<Gtk::TreeStore> const& store,
|
|
|
|
Gtk::TreeModel::iterator const& iter,
|
|
|
|
RefreshData& refresh_data)
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const is_file = iter->children().empty();
|
|
|
|
|
|
|
|
auto const old_enabled = iter->get_value(file_cols.enabled);
|
|
|
|
auto const old_have = iter->get_value(file_cols.have);
|
2022-04-26 23:24:07 +00:00
|
|
|
auto const old_priority = iter->get_value(file_cols.priority);
|
|
|
|
auto const old_progress = iter->get_value(file_cols.prog);
|
|
|
|
auto const old_size = iter->get_value(file_cols.size);
|
|
|
|
|
2022-04-28 01:06:51 +00:00
|
|
|
auto new_enabled = int{};
|
2022-05-16 14:06:18 +00:00
|
|
|
auto new_have = decltype(old_have){};
|
2022-04-28 01:06:51 +00:00
|
|
|
auto new_priority = int{};
|
|
|
|
auto new_progress = int{};
|
2022-05-25 18:27:33 +00:00
|
|
|
auto new_size = decltype(old_size){};
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (is_file)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
auto const index = iter->get_value(file_cols.index);
|
|
|
|
auto const file = tr_torrentFile(refresh_data.tor, index);
|
2020-11-01 21:47:57 +00:00
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
new_enabled = static_cast<int>(file.wanted);
|
2022-11-15 00:53:12 +00:00
|
|
|
new_priority = int{ file.priority };
|
2022-04-26 23:24:07 +00:00
|
|
|
new_have = file.have;
|
2022-05-25 18:27:33 +00:00
|
|
|
new_size = file.length;
|
|
|
|
new_progress = static_cast<int>(100 * file.progress);
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2009-06-06 04:29:08 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
new_enabled = NOT_SET;
|
|
|
|
new_priority = NOT_SET;
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
/* since gtk_tree_model_foreach() is depth-first, we can
|
2017-04-19 12:04:45 +00:00
|
|
|
* get the `sub' info by walking the immediate children */
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& child : iter->children())
|
2009-06-06 04:29:08 +00:00
|
|
|
{
|
2022-05-16 14:06:18 +00:00
|
|
|
auto const child_size = child[file_cols.size];
|
|
|
|
auto const child_have = child[file_cols.have];
|
|
|
|
auto const child_priority = child[file_cols.priority];
|
|
|
|
auto const child_enabled = child[file_cols.enabled];
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
if (child_enabled != static_cast<int>(false) && (child_enabled != NOT_SET))
|
2013-02-09 19:28:38 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
new_size += child_size;
|
|
|
|
new_have += child_have;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2009-06-10 00:04:43 +00:00
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
if (new_enabled == NOT_SET)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
new_enabled = child_enabled;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2022-04-26 23:24:07 +00:00
|
|
|
else if (new_enabled != child_enabled)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
new_enabled = MIXED;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2009-06-10 00:04:43 +00:00
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
if (new_priority == NOT_SET)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
new_priority = child_priority;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2022-04-26 23:24:07 +00:00
|
|
|
else if (new_priority != child_priority)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
new_priority = MIXED;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 14:06:18 +00:00
|
|
|
new_progress = new_size != 0 ? static_cast<int>(100.0 * new_have / new_size) : 1;
|
2022-04-26 23:24:07 +00:00
|
|
|
}
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2022-05-16 14:06:18 +00:00
|
|
|
new_progress = std::clamp(new_progress, 0, 100);
|
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
if (new_priority != old_priority || new_enabled != old_enabled)
|
|
|
|
{
|
|
|
|
/* Changing a value in the sort column can trigger a resort
|
|
|
|
* which breaks this foreach () call. (See #3529)
|
|
|
|
* As a workaround: if that's about to happen, temporarily disable
|
|
|
|
* sorting until we finish walking the tree. */
|
|
|
|
if (!refresh_data.resort_needed &&
|
|
|
|
(((refresh_data.sort_column_id == file_cols.priority.index()) && (new_priority != old_priority)) ||
|
|
|
|
((refresh_data.sort_column_id == file_cols.enabled.index()) && (new_enabled != old_enabled))))
|
2011-01-06 17:21:55 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
refresh_data.resort_needed = true;
|
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
store->set_sort_column(GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, TR_GTK_SORT_TYPE(ASCENDING));
|
2011-01-06 17:21:55 +00:00
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
if (new_enabled != old_enabled)
|
|
|
|
{
|
|
|
|
(*iter)[file_cols.enabled] = new_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_priority != old_priority)
|
|
|
|
{
|
|
|
|
(*iter)[file_cols.priority] = new_priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_size != old_size)
|
|
|
|
{
|
|
|
|
(*iter)[file_cols.size] = new_size;
|
|
|
|
(*iter)[file_cols.size_str] = tr_strlsize(new_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_have != old_have)
|
|
|
|
{
|
|
|
|
(*iter)[file_cols.have] = new_have;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_progress != old_progress)
|
|
|
|
{
|
|
|
|
(*iter)[file_cols.prog] = new_progress;
|
|
|
|
(*iter)[file_cols.prog_str] = fmt::format(FMT_STRING("{:d}%"), new_progress);
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false; /* keep walking */
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 16:22:38 +00:00
|
|
|
void gtr_tree_model_foreach_postorder(Glib::RefPtr<Gtk::TreeModel> const& model, Gtk::TreeModel::SlotForeachIter const& func)
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2022-11-14 16:22:38 +00:00
|
|
|
auto items = std::stack<Gtk::TreeModel::iterator>();
|
|
|
|
if (auto const root_child_it = model->children().begin(); root_child_it)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-11-14 16:22:38 +00:00
|
|
|
items.push(root_child_it);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 16:22:38 +00:00
|
|
|
while (!items.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-11-14 16:22:38 +00:00
|
|
|
while (items.top())
|
|
|
|
{
|
|
|
|
if (auto const child_it = items.top()->children().begin(); child_it)
|
|
|
|
{
|
|
|
|
items.push(child_it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
func(items.top()++);
|
|
|
|
}
|
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2022-11-14 16:22:38 +00:00
|
|
|
items.pop();
|
|
|
|
|
|
|
|
if (!items.empty())
|
|
|
|
{
|
|
|
|
func(items.top()++);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void FileList::Impl::refresh()
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
if (tr_torrent* tor = core_->find_torrent(torrent_id_); tor == nullptr)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
widget_.clear();
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
Gtk::SortType order = TR_GTK_SORT_TYPE(ASCENDING);
|
|
|
|
int sort_column_id = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
store_->get_sort_column_id(sort_column_id, order);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-21 18:31:03 +00:00
|
|
|
RefreshData refresh_data{ sort_column_id, false, tor };
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_tree_model_foreach_postorder(
|
|
|
|
store_,
|
|
|
|
[this, &refresh_data](Gtk::TreeModel::iterator const& iter)
|
|
|
|
{ return refreshFilesForeach(store_, iter, refresh_data); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (refresh_data.resort_needed)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
store_->set_sort_column(sort_column_id, order);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool getSelectedFilesForeach(
|
|
|
|
Gtk::TreeModel::iterator const& iter,
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> const& sel,
|
|
|
|
std::vector<tr_file_index_t>& indexBuf)
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2022-02-02 01:09:11 +00:00
|
|
|
if (bool const is_file = iter->children().empty(); is_file)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* active means: if it's selected or any ancestor is selected */
|
2021-10-18 20:22:31 +00:00
|
|
|
bool is_active = sel->is_selected(iter);
|
2010-05-12 01:34:08 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!is_active)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto walk = iter->parent(); !is_active && walk; walk = walk->parent())
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
is_active = sel->is_selected(walk);
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (is_active)
|
2010-05-12 01:34:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
indexBuf.push_back(iter->get_value(file_cols.index));
|
2010-05-12 01:34:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false; /* keep walking */
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_file_index_t> FileList::Impl::getSelectedFilesAndDescendants() const
|
|
|
|
{
|
|
|
|
auto const sel = view_->get_selection();
|
|
|
|
std::vector<tr_file_index_t> indexBuf;
|
|
|
|
store_->foreach_iter([&sel, &indexBuf](Gtk::TreeModel::iterator const& iter)
|
|
|
|
{ return getSelectedFilesForeach(iter, sel, indexBuf); });
|
|
|
|
return indexBuf;
|
2008-10-26 22:58:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2008-10-26 22:58:57 +00:00
|
|
|
{
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool getSubtreeForeach(
|
|
|
|
Gtk::TreeModel::Path const& path,
|
|
|
|
Gtk::TreeModel::iterator const& iter,
|
|
|
|
Gtk::TreeModel::Path const& subtree_path,
|
|
|
|
std::vector<tr_file_index_t>& indexBuf)
|
2008-10-26 22:58:57 +00:00
|
|
|
{
|
2022-02-02 01:09:11 +00:00
|
|
|
if (bool const is_file = iter->children().empty(); is_file)
|
2010-05-12 01:34:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (path == subtree_path || path.is_descendant(subtree_path))
|
2010-05-12 01:34:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
indexBuf.push_back(iter->get_value(file_cols.index));
|
2010-05-12 01:34:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-26 22:58:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false; /* keep walking */
|
2008-10-26 22:58:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
std::vector<tr_file_index_t> FileList::Impl::getSubtree(Gtk::TreeModel::Path const& subtree_path) const
|
2008-10-26 22:58:57 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_file_index_t> indexBuf;
|
|
|
|
store_->foreach ([&subtree_path, &indexBuf](Gtk::TreeModel::Path const& path, Gtk::TreeModel::iterator const& iter)
|
|
|
|
{ return getSubtreeForeach(path, iter, subtree_path, indexBuf); });
|
|
|
|
return indexBuf;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-09-05 21:01:00 +00:00
|
|
|
|
2008-09-06 01:52:47 +00:00
|
|
|
/* if `path' is a selected row, all selected rows are returned.
|
|
|
|
* otherwise, only the row indicated by `path' is returned.
|
|
|
|
* this is for toggling all the selected rows' states in a batch.
|
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings
* fix: implicit fallthrough warning
* fixup! fix: implicit fallthrough warning
* fix: disable warnings for 3rd party code
Since we want to leave upstream code as-is
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: disable warnings for 3rd party code
* silence spurious alignment warning
Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: https://pagure.io/SSSD/sssd/blob/90ac46f71068d131391492360a8553bdd005b5a7/f/src/util/util_safealign.h#_35
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: implicit fallthrough warning
* make uncrustify happy
* remove uncrustify-test.sh
that's probably off-topic for this PR
* fixup! fix: __attribute__(__printf__) warnings
* Update libtransmission/CMakeLists.txt
Co-Authored-By: ckerr <ckerr@github.com>
* fixup! silence spurious alignment warning
* use -w for DISABLE_WARNINGS in Clang
* refactor: fix libtransmission deprecation warnings
* fix: pthread_create's start_routine's return value
This was defined as `void` on non-Windows but should have been `void*`
* chore: uncrustify
* fix: add DISABLE_WARNINGS option for SunPro Studio
* fix "unused in lambda capture" warnings by clang++
* fix 'increases required alignment' warning
Caused from storing int16_t's in a char array.
* fix net.c 'increases required alignment' warning
The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.
* make building quieter so warnings are more visible
* fixup! fix 'increases required alignment' warning
* Fix -Wcast-function-type warnings in GTK+ app code
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.
GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.
Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.
In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).
* fixup! fix "unused in lambda capture" warnings by clang++
* fixup! fix "unused in lambda capture" warnings by clang++
* fix two more libtransmission compiler warnings
* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 17:27:03 +00:00
|
|
|
*
|
|
|
|
* indexBuf should be large enough to hold tr_inf.fileCount files.
|
2008-09-06 01:52:47 +00:00
|
|
|
*/
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_file_index_t> FileList::Impl::getActiveFilesForPath(Gtk::TreeModel::Path const& path) const
|
2008-02-15 18:20:56 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (view_->get_selection()->is_selected(path))
|
2008-09-05 21:01:00 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* clicked in a selected row... use the current selection */
|
2021-10-18 20:22:31 +00:00
|
|
|
return getSelectedFilesAndDescendants();
|
2008-09-05 21:01:00 +00:00
|
|
|
}
|
2022-11-09 16:58:36 +00:00
|
|
|
|
|
|
|
/* clicked OUTSIDE of the selected row... just use the clicked row */
|
|
|
|
return getSubtree(path);
|
2008-02-15 18:20:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void FileList::clear()
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2022-11-14 16:22:38 +00:00
|
|
|
impl_->reset_torrent();
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
struct build_data
|
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
Gtk::Widget* w = nullptr;
|
|
|
|
tr_torrent* tor = nullptr;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeStore::iterator iter;
|
|
|
|
Glib::RefPtr<Gtk::TreeStore> store;
|
2009-06-06 04:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct row_struct
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
uint64_t length = 0;
|
|
|
|
Glib::ustring name;
|
|
|
|
int index = 0;
|
2009-06-06 04:29:08 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
using FileRowNode = Glib::NodeTree<row_struct>;
|
|
|
|
|
|
|
|
void buildTree(FileRowNode& node, build_data& build)
|
2009-06-06 04:29:08 +00:00
|
|
|
{
|
2022-04-02 22:42:51 +00:00
|
|
|
auto const& child_data = node.data();
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const isLeaf = node.child_count() == 0;
|
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
auto const mime_type = isLeaf ? tr_get_mime_type_for_filename(child_data.name.raw()) : DirectoryMimeType;
|
2022-10-08 22:50:03 +00:00
|
|
|
auto const icon = gtr_get_mime_type_icon(mime_type);
|
2021-12-08 01:03:32 +00:00
|
|
|
auto const file = isLeaf ? tr_torrentFile(build.tor, child_data.index) : tr_file_view{};
|
2021-11-28 03:17:47 +00:00
|
|
|
int const priority = isLeaf ? file.priority : 0;
|
|
|
|
bool const enabled = isLeaf ? file.wanted : true;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto name_esc = Glib::Markup::escape_text(child_data.name);
|
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
auto const child_iter = build.store->prepend(build.iter->children());
|
2021-10-18 20:22:31 +00:00
|
|
|
(*child_iter)[file_cols.index] = child_data.index;
|
|
|
|
(*child_iter)[file_cols.label] = child_data.name;
|
|
|
|
(*child_iter)[file_cols.label_esc] = name_esc;
|
|
|
|
(*child_iter)[file_cols.size] = child_data.length;
|
|
|
|
(*child_iter)[file_cols.size_str] = tr_strlsize(child_data.length);
|
|
|
|
(*child_iter)[file_cols.icon] = icon;
|
|
|
|
(*child_iter)[file_cols.priority] = priority;
|
2022-11-09 16:58:36 +00:00
|
|
|
(*child_iter)[file_cols.enabled] = static_cast<int>(enabled);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!isLeaf)
|
2009-06-06 04:29:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
build_data b = build;
|
|
|
|
b.iter = child_iter;
|
2022-09-10 13:19:54 +00:00
|
|
|
node.foreach ([&b](auto& child_node) { buildTree(child_node, b); }, TR_GLIB_NODE_TREE_TRAVERSE_FLAGS(FileRowNode, ALL));
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
void FileList::set_torrent(tr_torrent_id_t torrent_id)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-09 16:58:36 +00:00
|
|
|
impl_->set_torrent(torrent_id);
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
struct PairHash
|
|
|
|
{
|
|
|
|
template<typename T1, typename T2>
|
|
|
|
auto operator()(std::pair<T1, T2> const& pair) const
|
|
|
|
{
|
|
|
|
return std::hash<T1>{}(pair.first) ^ std::hash<T2>{}(pair.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
void FileList::Impl::set_torrent(tr_torrent_id_t torrent_id)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2022-11-09 16:58:36 +00:00
|
|
|
if (torrent_id_ == torrent_id && store_ != nullptr && !store_->children().empty())
|
2022-10-22 09:42:38 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* unset the old fields */
|
2021-10-18 20:22:31 +00:00
|
|
|
clearData();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* instantiate the model */
|
2021-10-18 20:22:31 +00:00
|
|
|
store_ = Gtk::TreeStore::create(file_cols);
|
2022-11-09 16:58:36 +00:00
|
|
|
torrent_id_ = torrent_id;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* populate the model */
|
2022-02-08 05:44:31 +00:00
|
|
|
if (torrent_id_ > 0)
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2022-02-08 05:44:31 +00:00
|
|
|
if (auto* const tor = core_->find_torrent(torrent_id_); tor != nullptr)
|
2008-02-12 18:53:31 +00:00
|
|
|
{
|
2022-02-08 05:44:31 +00:00
|
|
|
// build a GNode tree of the files
|
2022-04-26 23:24:07 +00:00
|
|
|
auto root = FileRowNode{};
|
2022-02-08 05:44:31 +00:00
|
|
|
auto& root_data = root.data();
|
|
|
|
root_data.name = tr_torrentName(tor);
|
|
|
|
root_data.index = -1;
|
|
|
|
root_data.length = 0;
|
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
auto nodes = std::unordered_map<std::pair<FileRowNode* /*parent*/, std::string_view>, FileRowNode*, PairHash>{};
|
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
for (tr_file_index_t i = 0, n_files = tr_torrentFileCount(tor); i < n_files; ++i)
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2022-02-08 05:44:31 +00:00
|
|
|
auto* parent = &root;
|
|
|
|
auto const file = tr_torrentFile(tor, i);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
auto path = std::string_view{ file.name };
|
|
|
|
auto token = std::string_view{};
|
|
|
|
while (tr_strvSep(&path, &token, '/'))
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
auto*& node = nodes[std::make_pair(parent, token)];
|
2022-02-08 05:44:31 +00:00
|
|
|
|
|
|
|
if (node == nullptr)
|
|
|
|
{
|
2022-04-26 23:24:07 +00:00
|
|
|
auto const is_leaf = std::empty(path);
|
|
|
|
|
|
|
|
node = parent->prepend_data({});
|
|
|
|
auto& node_data = node->data();
|
|
|
|
node_data.name = std::string{ token };
|
|
|
|
node_data.index = is_leaf ? (int)i : -1;
|
|
|
|
node_data.length = is_leaf ? file.length : 0;
|
2022-02-08 05:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parent = node;
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
// now, add them to the model
|
|
|
|
struct build_data build;
|
|
|
|
build.w = &widget_;
|
|
|
|
build.tor = tor;
|
|
|
|
build.store = store_;
|
2022-09-10 13:19:54 +00:00
|
|
|
root.foreach (
|
|
|
|
[&build](auto& child_node) { buildTree(child_node, build); },
|
|
|
|
TR_GLIB_NODE_TREE_TRAVERSE_FLAGS(FileRowNode, ALL));
|
2022-02-08 05:44:31 +00:00
|
|
|
}
|
2020-11-08 19:54:40 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
refresh();
|
|
|
|
timeout_tag_ = Glib::signal_timeout().connect_seconds(
|
|
|
|
[this]() { return refresh(), true; },
|
|
|
|
SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS);
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
view_->set_model(store_);
|
2020-04-27 21:34:02 +00:00
|
|
|
|
|
|
|
/* set default sort by label */
|
2022-09-10 13:19:54 +00:00
|
|
|
store_->set_sort_column(file_cols.label, TR_GTK_SORT_TYPE(ASCENDING));
|
2020-04-27 21:34:02 +00:00
|
|
|
|
2022-04-26 23:24:07 +00:00
|
|
|
view_->expand_row(Gtk::TreeModel::Path("0"), false);
|
|
|
|
// view_->expand_all();
|
2008-02-12 18:53:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 16:22:38 +00:00
|
|
|
void FileList::Impl::reset_torrent()
|
|
|
|
{
|
|
|
|
clearData();
|
|
|
|
|
|
|
|
store_ = Gtk::TreeStore::create(file_cols);
|
|
|
|
view_->set_model(store_);
|
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void renderDownload(Gtk::CellRenderer* renderer, Gtk::TreeModel::const_iterator const& iter)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
auto* const toggle_renderer = dynamic_cast<Gtk::CellRendererToggle*>(renderer);
|
|
|
|
g_assert(toggle_renderer != nullptr);
|
|
|
|
if (toggle_renderer == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const enabled = iter->get_value(file_cols.enabled);
|
2022-11-13 17:36:16 +00:00
|
|
|
toggle_renderer->property_inconsistent() = enabled == MIXED;
|
|
|
|
toggle_renderer->property_active() = enabled == static_cast<int>(true);
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void renderPriority(Gtk::CellRenderer* renderer, Gtk::TreeModel::const_iterator const& iter)
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
auto* const text_renderer = dynamic_cast<Gtk::CellRendererText*>(renderer);
|
|
|
|
g_assert(text_renderer != nullptr);
|
|
|
|
if (text_renderer == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring text;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-01-24 00:53:35 +00:00
|
|
|
switch (auto const priority = iter->get_value(file_cols.priority); priority)
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_PRI_HIGH:
|
|
|
|
text = _("High");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
text = _("Normal");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
text = _("Low");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
text = _("Mixed");
|
|
|
|
break;
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
text_renderer->property_text() = text;
|
2008-02-15 18:20:56 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
/* build a filename from tr_torrentGetCurrentDir() + the model's FC_LABELs */
|
2021-10-18 20:22:31 +00:00
|
|
|
std::string buildFilename(tr_torrent const* tor, Gtk::TreeModel::iterator const& iter)
|
2010-07-11 17:56:58 +00:00
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
std::vector<std::string> tokens;
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto child = iter; child; child = child->parent())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
tokens.push_back(child->get_value(file_cols.label));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
tokens.emplace_back(tr_torrentGetCurrentDir(tor));
|
|
|
|
std::reverse(tokens.begin(), tokens.end());
|
2021-10-18 20:22:31 +00:00
|
|
|
return Glib::build_filename(tokens);
|
2010-07-11 17:56:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void FileList::Impl::onRowActivated(Gtk::TreeModel::Path const& path, Gtk::TreeViewColumn* /*col*/)
|
|
|
|
{
|
|
|
|
bool handled = false;
|
2010-07-11 17:56:58 +00:00
|
|
|
|
2022-02-08 05:44:31 +00:00
|
|
|
if (auto const* tor = core_->find_torrent(torrent_id_); tor != nullptr)
|
2010-07-11 17:56:58 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = store_->get_iter(path); iter)
|
2010-07-11 17:56:58 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto filename = buildFilename(tor, iter);
|
|
|
|
auto const prog = iter->get_value(file_cols.prog);
|
2010-07-11 17:56:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* if the file's not done, walk up the directory tree until we find
|
|
|
|
* an ancestor that exists, and open that instead */
|
2022-09-10 13:19:54 +00:00
|
|
|
if (!filename.empty() && (prog < 100 || !Glib::file_test(filename, TR_GLIB_FILE_TEST(EXISTS))))
|
2010-07-11 17:56:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
do
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
filename = Glib::path_get_dirname(filename);
|
2022-09-10 13:19:54 +00:00
|
|
|
} while (!filename.empty() && !Glib::file_test(filename, TR_GLIB_FILE_TEST(EXISTS)));
|
2010-07-11 17:56:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (handled = !filename.empty(); handled)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
gtr_open_file(filename);
|
|
|
|
}
|
2010-07-11 17:56:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
// return handled;
|
2010-07-11 17:56:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool FileList::Impl::onViewPathToggled(Gtk::TreeViewColumn* col, Gtk::TreeModel::Path const& path)
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (col == nullptr || path.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool handled = false;
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
auto const cid = col->get_sort_column_id();
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* tor = core_->find_torrent(torrent_id_);
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tor != nullptr && (cid == file_cols.priority.index() || cid == file_cols.enabled.index()))
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const indexBuf = getActiveFilesForPath(path);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const iter = store_->get_iter(path);
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (cid == file_cols.priority.index())
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto priority = iter->get_value(file_cols.priority);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
switch (priority)
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrentSetFilePriorities(tor, indexBuf.data(), indexBuf.size(), priority);
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2022-11-09 16:58:36 +00:00
|
|
|
auto const enabled = iter->get_value(file_cols.enabled);
|
|
|
|
tr_torrentSetFileDLs(tor, indexBuf.data(), indexBuf.size(), enabled == static_cast<int>(false));
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
refresh();
|
|
|
|
handled = true;
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handled;
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
/**
|
2021-10-06 16:32:17 +00:00
|
|
|
* @note 'col' and 'path' are assumed not to be nullptr.
|
2011-01-05 07:08:34 +00:00
|
|
|
*/
|
2022-10-08 22:50:03 +00:00
|
|
|
bool FileList::Impl::getAndSelectEventPath(double view_x, double view_y, Gtk::TreeViewColumn*& col, Gtk::TreeModel::Path& path)
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
int cell_x = 0;
|
|
|
|
int cell_y = 0;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
if (view_->get_path_at_pos(view_x, view_y, path, col, cell_x, cell_y))
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2022-02-02 01:09:11 +00:00
|
|
|
if (auto const sel = view_->get_selection(); !sel->is_selected(path))
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
sel->unselect_all();
|
|
|
|
sel->select(path);
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return true;
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2008-09-08 15:17:18 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false;
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
bool FileList::Impl::onViewButtonPressed(guint button, TrGdkModifierType state, double view_x, double view_y)
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
Gtk::TreeViewColumn* col = nullptr;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModel::Path path;
|
|
|
|
bool handled = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
if (button == GDK_BUTTON_PRIMARY &&
|
|
|
|
(state & (TR_GDK_MODIFIED_TYPE(SHIFT_MASK) | TR_GDK_MODIFIED_TYPE(CONTROL_MASK))) == TrGdkModifierType{} &&
|
|
|
|
getAndSelectEventPath(view_x, view_y, col, path))
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
handled = onViewPathToggled(col, path);
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2008-09-05 21:01:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handled;
|
2008-09-05 21:01:00 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 08:44:23 +00:00
|
|
|
struct rename_data
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring newname;
|
|
|
|
Glib::ustring path_string;
|
2022-11-13 17:36:16 +00:00
|
|
|
gpointer impl = nullptr;
|
2013-01-19 08:44:23 +00:00
|
|
|
};
|
|
|
|
|
2022-12-16 17:40:28 +00:00
|
|
|
void FileList::Impl::on_rename_done(Glib::ustring const& path_string, Glib::ustring const& newname, int error)
|
|
|
|
{
|
|
|
|
rename_done_tags_.push(Glib::signal_idle().connect(
|
|
|
|
[this, path_string, newname, error]()
|
|
|
|
{
|
|
|
|
rename_done_tags_.pop();
|
|
|
|
on_rename_done_idle(path_string, newname, error);
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileList::Impl::on_rename_done_idle(Glib::ustring const& path_string, Glib::ustring const& newname, int error)
|
2013-01-19 08:44:23 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (error == 0)
|
2013-01-19 08:44:23 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = store_->get_iter(path_string); iter)
|
2017-02-21 20:18:52 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const isLeaf = iter->children().empty();
|
2022-04-26 23:24:07 +00:00
|
|
|
auto const mime_type = isLeaf ? tr_get_mime_type_for_filename(newname.raw()) : DirectoryMimeType;
|
2022-10-08 22:50:03 +00:00
|
|
|
auto const icon = gtr_get_mime_type_icon(mime_type);
|
2017-02-21 20:18:52 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[file_cols.label] = newname;
|
|
|
|
(*iter)[file_cols.icon] = icon;
|
2017-02-21 20:18:52 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!iter->parent())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->torrent_changed(torrent_id_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2017-02-21 20:18:52 +00:00
|
|
|
}
|
2013-01-19 08:44:23 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-19 08:44:23 +00:00
|
|
|
{
|
2022-09-10 18:15:01 +00:00
|
|
|
auto w = std::make_shared<Gtk::MessageDialog>(
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_widget_get_window(widget_),
|
2022-03-15 14:52:16 +00:00
|
|
|
fmt::format(
|
2022-03-16 00:51:36 +00:00
|
|
|
_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("old_path", path_string),
|
|
|
|
fmt::arg("path", newname),
|
2022-03-16 00:51:36 +00:00
|
|
|
fmt::arg("error", tr_strerror(error)),
|
|
|
|
fmt::arg("error_code", error)),
|
2021-10-18 20:22:31 +00:00
|
|
|
false,
|
2022-09-10 13:19:54 +00:00
|
|
|
TR_GTK_MESSAGE_TYPE(ERROR),
|
|
|
|
TR_GTK_BUTTONS_TYPE(CLOSE),
|
2021-10-18 20:22:31 +00:00
|
|
|
true);
|
2022-09-10 18:15:01 +00:00
|
|
|
w->set_secondary_text(_("Please correct the errors and try again."));
|
|
|
|
w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
|
|
|
|
w->show();
|
2013-01-19 08:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void FileList::Impl::cell_edited_callback(Glib::ustring const& path_string, Glib::ustring const& newname)
|
2013-01-19 08:44:23 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent* const tor = core_->find_torrent(torrent_id_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (tor == nullptr)
|
2013-01-19 08:44:23 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto iter = store_->get_iter(path_string);
|
|
|
|
if (!iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build oldpath */
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring oldpath;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
oldpath.insert(0, iter->get_value(file_cols.label));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
iter = iter->parent();
|
|
|
|
if (!iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-01-19 08:44:23 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
oldpath.insert(0, 1, G_DIR_SEPARATOR);
|
2013-01-19 08:44:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* do the renaming */
|
2021-12-14 08:43:27 +00:00
|
|
|
auto rename_data = std::make_unique<struct rename_data>();
|
2021-10-18 20:22:31 +00:00
|
|
|
rename_data->newname = newname;
|
|
|
|
rename_data->impl = this;
|
|
|
|
rename_data->path_string = path_string;
|
|
|
|
tr_torrentRenamePath(
|
|
|
|
tor,
|
|
|
|
oldpath.c_str(),
|
|
|
|
newname.c_str(),
|
|
|
|
static_cast<tr_torrent_rename_done_func>(
|
2021-12-14 08:43:27 +00:00
|
|
|
[](tr_torrent* /*tor*/, char const* /*oldpath*/, char const* /*newname*/, int error, gpointer data)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-16 17:40:28 +00:00
|
|
|
auto const data_grave = std::unique_ptr<struct rename_data>(static_cast<struct rename_data*>(data));
|
|
|
|
static_cast<Impl*>(data_grave->impl)->on_rename_done(data_grave->path_string, data_grave->newname, error);
|
2021-10-18 20:22:31 +00:00
|
|
|
}),
|
2021-12-14 08:43:27 +00:00
|
|
|
rename_data.release());
|
2013-01-19 08:44:23 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
FileList::FileList(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
Glib::ustring const& view_name,
|
|
|
|
Glib::RefPtr<Session> const& core,
|
|
|
|
tr_torrent_id_t torrent_id)
|
|
|
|
: Gtk::ScrolledWindow(cast_item)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, builder, view_name, core, torrent_id))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
FileList::Impl::Impl(
|
|
|
|
FileList& widget,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
Glib::ustring const& view_name,
|
|
|
|
Glib::RefPtr<Session> const& core,
|
|
|
|
tr_torrent_id_t torrent_id)
|
2021-10-18 20:22:31 +00:00
|
|
|
: widget_(widget)
|
|
|
|
, core_(core)
|
2022-10-08 22:50:03 +00:00
|
|
|
, view_(gtr_get_widget<Gtk::TreeView>(builder, view_name))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* create the view */
|
2021-11-12 09:12:50 +00:00
|
|
|
view_->signal_row_activated().connect(sigc::mem_fun(*this, &Impl::onRowActivated));
|
2022-10-08 22:50:03 +00:00
|
|
|
setup_tree_view_button_event_handling(
|
|
|
|
*view_,
|
|
|
|
[this](guint button, TrGdkModifierType state, double view_x, double view_y, bool /*context_menu_requested*/)
|
|
|
|
{ return onViewButtonPressed(button, state, view_x, view_y); },
|
|
|
|
[this](double view_x, double view_y) { return on_tree_view_button_released(*view_, view_x, view_y); });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
auto pango_font_description = view_->create_pango_context()->get_font_description();
|
2022-10-08 22:50:03 +00:00
|
|
|
if (auto const new_size = pango_font_description.get_size() * 0.8; pango_font_description.get_size_is_absolute())
|
|
|
|
{
|
|
|
|
pango_font_description.set_absolute_size(new_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pango_font_description.set_size(new_size);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* set up view */
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const sel = view_->get_selection();
|
2022-09-10 13:19:54 +00:00
|
|
|
sel->set_mode(TR_GTK_SELECTION_MODE(MULTIPLE));
|
2021-10-18 20:22:31 +00:00
|
|
|
view_->expand_all();
|
|
|
|
view_->set_search_column(file_cols.label);
|
|
|
|
|
|
|
|
{
|
|
|
|
/* add file column */
|
|
|
|
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>();
|
|
|
|
col->set_expand(true);
|
|
|
|
col->set_title(_("Name"));
|
|
|
|
col->set_resizable(true);
|
|
|
|
auto* icon_rend = Gtk::make_managed<Gtk::CellRendererPixbuf>();
|
|
|
|
col->pack_start(*icon_rend, false);
|
2022-10-08 22:50:03 +00:00
|
|
|
col->add_attribute(icon_rend->property_gicon(), file_cols.icon);
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
icon_rend->property_icon_size() = Gtk::IconSize::NORMAL;
|
|
|
|
#else
|
|
|
|
icon_rend->property_stock_size() = Gtk::ICON_SIZE_MENU;
|
|
|
|
#endif
|
2021-10-18 20:22:31 +00:00
|
|
|
/* add text renderer */
|
|
|
|
auto* text_rend = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
text_rend->property_editable() = true;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_rend->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(END);
|
2021-10-18 20:22:31 +00:00
|
|
|
text_rend->property_font_desc() = pango_font_description;
|
2021-11-12 09:12:50 +00:00
|
|
|
text_rend->signal_edited().connect(sigc::mem_fun(*this, &Impl::cell_edited_callback));
|
2021-10-18 20:22:31 +00:00
|
|
|
col->pack_start(*text_rend, true);
|
|
|
|
col->add_attribute(text_rend->property_text(), file_cols.label);
|
|
|
|
col->set_sort_column(file_cols.label);
|
|
|
|
view_->append_column(*col);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* add "size" column */
|
|
|
|
auto* rend = Gtk::make_managed<Gtk::CellRendererText>();
|
2022-09-10 13:19:54 +00:00
|
|
|
rend->property_alignment() = TR_PANGO_ALIGNMENT(RIGHT);
|
2021-10-18 20:22:31 +00:00
|
|
|
rend->property_font_desc() = pango_font_description;
|
|
|
|
rend->property_xpad() = GUI_PAD;
|
|
|
|
rend->property_xalign() = 1.0F;
|
|
|
|
rend->property_yalign() = 0.5F;
|
|
|
|
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>(_("Size"), *rend);
|
2022-09-10 13:19:54 +00:00
|
|
|
col->set_sizing(TR_GTK_TREE_VIEW_COLUMN_SIZING(GROW_ONLY));
|
2021-10-18 20:22:31 +00:00
|
|
|
col->set_sort_column(file_cols.size);
|
|
|
|
col->add_attribute(rend->property_text(), file_cols.size_str);
|
|
|
|
view_->append_column(*col);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* add "progress" column */
|
|
|
|
auto const* title = _("Have");
|
2022-11-13 17:36:16 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
view_->create_pango_layout(title)->get_pixel_size(width, height);
|
|
|
|
width += 30; /* room for the sort indicator */
|
|
|
|
auto* rend = Gtk::make_managed<Gtk::CellRendererProgress>();
|
|
|
|
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>(title, *rend);
|
2022-03-30 01:52:24 +00:00
|
|
|
col->add_attribute(rend->property_text(), file_cols.prog_str);
|
|
|
|
col->add_attribute(rend->property_value(), file_cols.prog);
|
2021-10-18 20:22:31 +00:00
|
|
|
col->set_fixed_width(width);
|
2022-09-10 13:19:54 +00:00
|
|
|
col->set_sizing(TR_GTK_TREE_VIEW_COLUMN_SIZING(FIXED));
|
2021-10-18 20:22:31 +00:00
|
|
|
col->set_sort_column(file_cols.prog);
|
|
|
|
view_->append_column(*col);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* add "enabled" column */
|
|
|
|
auto const* title = _("Download");
|
2022-11-13 17:36:16 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
view_->create_pango_layout(title)->get_pixel_size(width, height);
|
|
|
|
width += 30; /* room for the sort indicator */
|
|
|
|
auto* rend = Gtk::make_managed<Gtk::CellRendererToggle>();
|
|
|
|
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>(title, *rend);
|
|
|
|
col->set_fixed_width(width);
|
2022-09-10 13:19:54 +00:00
|
|
|
col->set_sizing(TR_GTK_TREE_VIEW_COLUMN_SIZING(FIXED));
|
2021-10-18 20:22:31 +00:00
|
|
|
col->set_cell_data_func(*rend, sigc::ptr_fun(&renderDownload));
|
|
|
|
col->set_sort_column(file_cols.enabled);
|
|
|
|
view_->append_column(*col);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* add priority column */
|
|
|
|
auto const* title = _("Priority");
|
2022-11-13 17:36:16 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
view_->create_pango_layout(title)->get_pixel_size(width, height);
|
|
|
|
width += 30; /* room for the sort indicator */
|
|
|
|
auto* rend = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
rend->property_xalign() = 0.5F;
|
|
|
|
rend->property_yalign() = 0.5F;
|
|
|
|
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>(title, *rend);
|
|
|
|
col->set_fixed_width(width);
|
2022-09-10 13:19:54 +00:00
|
|
|
col->set_sizing(TR_GTK_TREE_VIEW_COLUMN_SIZING(FIXED));
|
2021-10-18 20:22:31 +00:00
|
|
|
col->set_sort_column(file_cols.priority);
|
|
|
|
col->set_cell_data_func(*rend, sigc::ptr_fun(&renderPriority));
|
|
|
|
view_->append_column(*col);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* add tooltip to tree */
|
2021-10-18 20:22:31 +00:00
|
|
|
view_->set_tooltip_column(file_cols.label_esc.index());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
set_torrent(torrent_id);
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
FileList::~FileList() = default;
|