2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2007-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.
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "TorrentCellRenderer.h"
|
|
|
|
|
|
|
|
#include "HigWorkarea.h" // GUI_PAD, GUI_PAD_SMALL
|
2023-02-18 01:14:01 +00:00
|
|
|
#include "Percents.h"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Torrent.h"
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h> /* tr_truncd() */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <cairomm/context.h>
|
|
|
|
#include <cairomm/refptr.h>
|
|
|
|
#include <cairomm/surface.h>
|
|
|
|
#include <gdkmm/rectangle.h>
|
|
|
|
#include <gdkmm/rgba.h>
|
|
|
|
#include <giomm/icon.h>
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/property.h>
|
|
|
|
#include <gtkmm/cellrendererpixbuf.h>
|
|
|
|
#include <gtkmm/cellrendererprogress.h>
|
|
|
|
#include <gtkmm/cellrenderertext.h>
|
|
|
|
#include <gtkmm/requisition.h>
|
|
|
|
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
#include <gtkmm/snapshot.h>
|
|
|
|
#endif
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <algorithm> // std::max()
|
|
|
|
#include <cstring> // strchr()
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2008-02-16 19:36:07 +00:00
|
|
|
/* #define TEST_RTL */
|
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
using namespace std::string_literals;
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
auto const DefaultBarHeight = 12;
|
|
|
|
auto const CompactBarWidth = 50;
|
|
|
|
auto const SmallScale = 0.9;
|
2023-08-06 03:26:29 +00:00
|
|
|
auto const CompactIconSize = Gtk::ICON_SIZE_MENU;
|
|
|
|
auto const FullIconSize = Gtk::ICON_SIZE_DND;
|
2022-11-13 17:36:16 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class TorrentCellRenderer::Impl
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2021-12-14 08:43:27 +00:00
|
|
|
explicit Impl(TorrentCellRenderer& renderer);
|
2021-10-18 20:22:31 +00:00
|
|
|
~Impl();
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Impl)
|
|
|
|
|
2022-11-15 19:30:32 +00:00
|
|
|
Gtk::Requisition get_size_compact(Gtk::Widget& widget) const;
|
|
|
|
Gtk::Requisition get_size_full(Gtk::Widget& widget) const;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
void render_compact(
|
2023-08-06 03:26:29 +00:00
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& background_area,
|
|
|
|
Gtk::CellRendererState flags);
|
|
|
|
void render_full(
|
2023-08-06 03:26:29 +00:00
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& background_area,
|
|
|
|
Gtk::CellRendererState flags);
|
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
auto& property_torrent()
|
|
|
|
{
|
|
|
|
return property_torrent_;
|
|
|
|
}
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
auto& property_bar_height()
|
|
|
|
{
|
|
|
|
return property_bar_height_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& property_compact()
|
|
|
|
{
|
|
|
|
return property_compact_;
|
|
|
|
}
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
private:
|
2022-10-18 23:17:54 +00:00
|
|
|
void render_progress_bar(
|
2023-08-06 03:26:29 +00:00
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2022-10-18 23:17:54 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& area,
|
|
|
|
Gtk::CellRendererState flags,
|
2023-08-06 03:26:29 +00:00
|
|
|
std::optional<Gdk::RGBA> const& color);
|
2022-10-18 23:17:54 +00:00
|
|
|
|
|
|
|
static void adjust_progress_bar_hue(
|
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
|
|
|
Gdk::RGBA const& color,
|
2023-01-29 23:20:28 +00:00
|
|
|
Gdk::Rectangle const& area);
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
private:
|
|
|
|
TorrentCellRenderer& renderer_;
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::Property<Torrent*> property_torrent_;
|
2022-11-13 17:36:16 +00:00
|
|
|
Glib::Property<int> property_bar_height_;
|
|
|
|
Glib::Property<bool> property_compact_;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::CellRendererText* text_renderer_ = nullptr;
|
|
|
|
Gtk::CellRendererProgress* progress_renderer_ = nullptr;
|
|
|
|
Gtk::CellRendererPixbuf* icon_renderer_ = nullptr;
|
|
|
|
};
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2022-11-15 19:30:32 +00:00
|
|
|
Gtk::Requisition TorrentCellRenderer::Impl::get_size_compact(Gtk::Widget& widget) const
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
int xpad = 0;
|
|
|
|
int ypad = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Requisition min_size;
|
|
|
|
Gtk::Requisition icon_size;
|
|
|
|
Gtk::Requisition name_size;
|
|
|
|
Gtk::Requisition stat_size;
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const& torrent = *property_torrent_.get_value();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const icon = torrent.get_icon();
|
|
|
|
auto const name = torrent.get_name();
|
|
|
|
auto const gstr_stat = torrent.get_short_status_text();
|
2021-10-18 20:22:31 +00:00
|
|
|
renderer_.get_padding(xpad, ypad);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->property_gicon() = icon;
|
|
|
|
icon_renderer_->property_stock_size() = CompactIconSize;
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_renderer_->get_preferred_size(widget, min_size, icon_size);
|
|
|
|
text_renderer_->property_text() = name;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(NONE);
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_scale() = 1.0;
|
|
|
|
text_renderer_->get_preferred_size(widget, min_size, name_size);
|
|
|
|
text_renderer_->property_text() = gstr_stat;
|
2021-12-14 08:43:27 +00:00
|
|
|
text_renderer_->property_scale() = SmallScale;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->get_preferred_size(widget, min_size, stat_size);
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
return { xpad * 2 + icon_size.width + GUI_PAD + CompactBarWidth + GUI_PAD + stat_size.width,
|
|
|
|
ypad * 2 + std::max(name_size.height, property_bar_height_.get_value()) };
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 19:30:32 +00:00
|
|
|
Gtk::Requisition TorrentCellRenderer::Impl::get_size_full(Gtk::Widget& widget) const
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
int xpad = 0;
|
|
|
|
int ypad = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Requisition min_size;
|
|
|
|
Gtk::Requisition icon_size;
|
|
|
|
Gtk::Requisition name_size;
|
|
|
|
Gtk::Requisition stat_size;
|
|
|
|
Gtk::Requisition prog_size;
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const& torrent = *property_torrent_.get_value();
|
|
|
|
|
|
|
|
auto const icon = torrent.get_icon();
|
|
|
|
auto const name = torrent.get_name();
|
|
|
|
auto const gstr_stat = torrent.get_long_status_text();
|
|
|
|
auto const gstr_prog = torrent.get_long_progress_text();
|
2021-10-18 20:22:31 +00:00
|
|
|
renderer_.get_padding(xpad, ypad);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->property_gicon() = icon;
|
|
|
|
icon_renderer_->property_stock_size() = FullIconSize;
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_renderer_->get_preferred_size(widget, min_size, icon_size);
|
|
|
|
text_renderer_->property_text() = name;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_weight() = TR_PANGO_WEIGHT(BOLD);
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_scale() = 1.0;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(NONE);
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->get_preferred_size(widget, min_size, name_size);
|
|
|
|
text_renderer_->property_text() = gstr_prog;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_weight() = TR_PANGO_WEIGHT(NORMAL);
|
2021-12-14 08:43:27 +00:00
|
|
|
text_renderer_->property_scale() = SmallScale;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->get_preferred_size(widget, min_size, prog_size);
|
|
|
|
text_renderer_->property_text() = gstr_stat;
|
|
|
|
text_renderer_->get_preferred_size(widget, min_size, stat_size);
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
return { xpad * 2 + icon_size.width + GUI_PAD + std::max(prog_size.width, stat_size.width),
|
|
|
|
ypad * 2 + name_size.height + prog_size.height + GUI_PAD_SMALL + property_bar_height_.get_value() + GUI_PAD_SMALL +
|
|
|
|
stat_size.height };
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void TorrentCellRenderer::get_preferred_width_vfunc(Gtk::Widget& widget, int& minimum_width, int& natural_width) const
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
if (impl_->property_torrent().get_value() != nullptr)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2022-11-15 19:30:32 +00:00
|
|
|
auto const size = impl_->property_compact().get_value() ? impl_->get_size_compact(widget) :
|
|
|
|
impl_->get_size_full(widget);
|
2007-12-19 20:04:38 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
minimum_width = size.width;
|
2022-11-15 19:30:32 +00:00
|
|
|
natural_width = minimum_width;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void TorrentCellRenderer::get_preferred_height_vfunc(Gtk::Widget& widget, int& minimum_height, int& natural_height) const
|
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
if (impl_->property_torrent().get_value() != nullptr)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-15 19:30:32 +00:00
|
|
|
auto const size = impl_->property_compact().get_value() ? impl_->get_size_compact(widget) :
|
|
|
|
impl_->get_size_full(widget);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
minimum_height = size.height;
|
2022-11-15 19:30:32 +00:00
|
|
|
natural_height = minimum_height;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-07-26 01:02:32 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
void set_error_color(
|
|
|
|
Gtk::CellRendererText& text_renderer,
|
|
|
|
Torrent const& torrent,
|
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gtk::CellRendererState flags)
|
|
|
|
{
|
|
|
|
static auto const error_color_name = Glib::ustring("tr_error_color"s);
|
|
|
|
|
|
|
|
auto color = Gdk::RGBA();
|
|
|
|
if (torrent.get_error_code() != 0 && (flags & TR_GTK_CELL_RENDERER_STATE(SELECTED)) == Gtk::CellRendererState{} &&
|
|
|
|
widget.get_style_context()->lookup_color(error_color_name, color))
|
|
|
|
{
|
|
|
|
text_renderer.property_foreground_rgba() = color;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text_renderer.property_foreground_set() = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<Gdk::RGBA> get_progress_bar_color(Torrent const& torrent, Gtk::Widget const& widget)
|
2022-10-18 23:17:54 +00:00
|
|
|
{
|
2023-08-06 03:26:29 +00:00
|
|
|
static auto const down_color_name = Glib::ustring("tr_transfer_down_color"s);
|
|
|
|
static auto const up_color_name = Glib::ustring("tr_transfer_up_color"s);
|
|
|
|
static auto const idle_color_name = Glib::ustring("tr_transfer_idle_color"s);
|
2022-10-18 23:17:54 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
auto const* color_name = &idle_color_name;
|
2022-12-21 21:26:25 +00:00
|
|
|
switch (torrent.get_activity())
|
|
|
|
{
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
2023-08-06 03:26:29 +00:00
|
|
|
color_name = &down_color_name;
|
|
|
|
break;
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
case TR_STATUS_SEED:
|
2023-08-06 03:26:29 +00:00
|
|
|
color_name = &up_color_name;
|
|
|
|
break;
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
default:
|
2023-08-06 03:26:29 +00:00
|
|
|
break;
|
2022-12-21 21:26:25 +00:00
|
|
|
}
|
2023-08-06 03:26:29 +00:00
|
|
|
|
|
|
|
auto color = Gdk::RGBA();
|
|
|
|
return widget.get_style_context()->lookup_color(*color_name, color) ? std::make_optional(color) : std::nullopt;
|
2022-10-18 23:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Cairo::RefPtr<Cairo::Surface> get_mask_surface(Cairo::RefPtr<Cairo::Surface> const& surface, Gdk::Rectangle const& area)
|
|
|
|
{
|
2023-02-09 11:02:39 +00:00
|
|
|
auto const mask_surface = Cairo::Surface::create(surface, Cairo::CONTENT_ALPHA, area.get_width(), area.get_height());
|
2022-10-18 23:17:54 +00:00
|
|
|
auto const mask_context = Cairo::Context::create(mask_surface);
|
|
|
|
|
|
|
|
mask_context->set_source_rgb(0, 0, 0);
|
|
|
|
mask_context->rectangle(area.get_x(), area.get_y(), area.get_width(), area.get_height());
|
|
|
|
mask_context->fill();
|
|
|
|
|
|
|
|
mask_context->set_operator(TR_CAIRO_CONTEXT_OPERATOR(CLEAR));
|
|
|
|
mask_context->mask(surface, area.get_x(), area.get_y());
|
|
|
|
mask_context->fill();
|
|
|
|
|
|
|
|
return mask_surface;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2011-07-26 01:02:32 +00:00
|
|
|
|
2022-10-18 23:17:54 +00:00
|
|
|
void TorrentCellRenderer::Impl::adjust_progress_bar_hue(
|
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
|
|
|
Gdk::RGBA const& color,
|
2023-01-29 23:20:28 +00:00
|
|
|
Gdk::Rectangle const& area)
|
2022-10-18 23:17:54 +00:00
|
|
|
{
|
|
|
|
auto const mask_surface = get_mask_surface(context->get_target(), area);
|
|
|
|
|
|
|
|
// Adjust surface color
|
|
|
|
context->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());
|
2023-08-06 03:26:29 +00:00
|
|
|
context->set_operator(static_cast<Cairo::Operator>(CAIRO_OPERATOR_HSL_COLOR));
|
2022-10-18 23:17:54 +00:00
|
|
|
context->rectangle(area.get_x(), area.get_y(), area.get_width(), area.get_height());
|
|
|
|
context->fill();
|
|
|
|
|
|
|
|
// Clear out masked (fully transparent) areas
|
|
|
|
context->set_operator(TR_CAIRO_CONTEXT_OPERATOR(CLEAR));
|
|
|
|
context->mask(mask_surface, area.get_x(), area.get_y());
|
|
|
|
context->fill();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentCellRenderer::Impl::render_progress_bar(
|
2023-08-06 03:26:29 +00:00
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2022-10-18 23:17:54 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& area,
|
|
|
|
Gtk::CellRendererState flags,
|
2023-08-06 03:26:29 +00:00
|
|
|
std::optional<Gdk::RGBA> const& color)
|
2022-10-18 23:17:54 +00:00
|
|
|
{
|
2023-08-06 03:26:29 +00:00
|
|
|
if (!color.has_value())
|
|
|
|
{
|
|
|
|
progress_renderer_->render(context, widget, area, area, flags);
|
|
|
|
return;
|
|
|
|
}
|
2023-02-09 11:02:39 +00:00
|
|
|
|
2022-10-18 23:17:54 +00:00
|
|
|
auto const temp_area = Gdk::Rectangle(0, 0, area.get_width(), area.get_height());
|
2023-02-09 11:02:39 +00:00
|
|
|
auto const temp_surface = Cairo::Surface::create(
|
|
|
|
context->get_target(),
|
|
|
|
Cairo::CONTENT_COLOR_ALPHA,
|
|
|
|
area.get_width(),
|
|
|
|
area.get_height());
|
2022-10-18 23:17:54 +00:00
|
|
|
auto const temp_context = Cairo::Context::create(temp_surface);
|
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
progress_renderer_->render(temp_context, widget, temp_area, temp_area, flags);
|
2022-10-18 23:17:54 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
adjust_progress_bar_hue(temp_context, color.value(), temp_area);
|
2022-10-18 23:17:54 +00:00
|
|
|
|
|
|
|
context->set_source(temp_context->get_target(), area.get_x(), area.get_y());
|
|
|
|
context->rectangle(area.get_x(), area.get_y(), area.get_width(), area.get_height());
|
|
|
|
context->fill();
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void TorrentCellRenderer::Impl::render_compact(
|
2023-08-06 03:26:29 +00:00
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& background_area,
|
|
|
|
Gtk::CellRendererState flags)
|
2011-07-26 01:02:32 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
int xpad = 0;
|
|
|
|
int ypad = 0;
|
|
|
|
int min_width = 0;
|
|
|
|
int width = 0;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const& torrent = *property_torrent_.get_value();
|
2023-02-18 01:14:01 +00:00
|
|
|
auto const percent_done = torrent.get_percent_done().to_int();
|
2022-12-21 21:26:25 +00:00
|
|
|
bool const sensitive = torrent.get_sensitive();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
set_error_color(*text_renderer_, torrent, widget, flags);
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const icon = torrent.get_icon();
|
|
|
|
auto const name = torrent.get_name();
|
2023-08-06 03:26:29 +00:00
|
|
|
auto const progress_color = get_progress_bar_color(torrent, widget);
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const gstr_stat = torrent.get_short_status_text();
|
2021-10-18 20:22:31 +00:00
|
|
|
renderer_.get_padding(xpad, ypad);
|
|
|
|
|
|
|
|
auto fill_area = background_area;
|
|
|
|
fill_area.set_x(fill_area.get_x() + xpad);
|
|
|
|
fill_area.set_y(fill_area.get_y() + ypad);
|
|
|
|
fill_area.set_width(fill_area.get_width() - xpad * 2);
|
|
|
|
fill_area.set_height(fill_area.get_height() - ypad * 2);
|
|
|
|
|
|
|
|
auto icon_area = fill_area;
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->property_gicon() = icon;
|
|
|
|
icon_renderer_->property_stock_size() = CompactIconSize;
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_renderer_->get_preferred_width(widget, min_width, width);
|
|
|
|
icon_area.set_width(width);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
|
|
|
auto prog_area = fill_area;
|
2021-12-14 08:43:27 +00:00
|
|
|
prog_area.set_width(CompactBarWidth);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
|
|
|
auto stat_area = fill_area;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = gstr_stat;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(NONE);
|
2021-12-14 08:43:27 +00:00
|
|
|
text_renderer_->property_scale() = SmallScale;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->get_preferred_width(widget, min_width, width);
|
|
|
|
stat_area.set_width(width);
|
|
|
|
|
2021-11-15 16:32:41 +00:00
|
|
|
auto name_area = fill_area;
|
|
|
|
name_area.set_width(
|
|
|
|
fill_area.get_width() - icon_area.get_width() - stat_area.get_width() - prog_area.get_width() - GUI_PAD * 3);
|
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
if ((renderer_.get_state(widget, flags) & TR_GTK_STATE_FLAGS(DIR_RTL)) == Gtk::StateFlags{})
|
2021-11-15 16:32:41 +00:00
|
|
|
{
|
|
|
|
icon_area.set_x(fill_area.get_x());
|
|
|
|
prog_area.set_x(fill_area.get_x() + fill_area.get_width() - prog_area.get_width());
|
|
|
|
stat_area.set_x(prog_area.get_x() - stat_area.get_width() - GUI_PAD);
|
|
|
|
name_area.set_x(icon_area.get_x() + icon_area.get_width() + GUI_PAD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
icon_area.set_x(fill_area.get_x() + fill_area.get_width() - icon_area.get_width());
|
|
|
|
prog_area.set_x(fill_area.get_x());
|
|
|
|
stat_area.set_x(prog_area.get_x() + prog_area.get_width() + GUI_PAD);
|
|
|
|
name_area.set_x(stat_area.get_x() + stat_area.get_width() + GUI_PAD);
|
|
|
|
}
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** RENDER
|
|
|
|
**/
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->property_gicon() = icon;
|
|
|
|
icon_renderer_->property_stock_size() = CompactIconSize;
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_renderer_->property_sensitive() = sensitive;
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->render(context, widget, icon_area, icon_area, flags);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2022-04-01 16:29:05 +00:00
|
|
|
progress_renderer_->property_value() = percent_done;
|
|
|
|
progress_renderer_->property_text() = fmt::format(FMT_STRING("{:d}%"), percent_done);
|
2021-10-18 20:22:31 +00:00
|
|
|
progress_renderer_->property_sensitive() = sensitive;
|
2023-08-06 03:26:29 +00:00
|
|
|
render_progress_bar(context, widget, prog_area, flags, progress_color);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = gstr_stat;
|
2021-12-14 08:43:27 +00:00
|
|
|
text_renderer_->property_scale() = SmallScale;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(END);
|
2022-12-21 21:26:25 +00:00
|
|
|
text_renderer_->property_sensitive() = sensitive;
|
2023-08-06 03:26:29 +00:00
|
|
|
text_renderer_->render(context, widget, stat_area, stat_area, flags);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = name;
|
|
|
|
text_renderer_->property_scale() = 1.0;
|
2023-08-06 03:26:29 +00:00
|
|
|
text_renderer_->render(context, widget, name_area, name_area, flags);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void TorrentCellRenderer::Impl::render_full(
|
2023-08-06 03:26:29 +00:00
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& background_area,
|
|
|
|
Gtk::CellRendererState flags)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
int xpad = 0;
|
|
|
|
int ypad = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Requisition min_size;
|
|
|
|
Gtk::Requisition size;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const& torrent = *property_torrent_.get_value();
|
2023-02-18 01:14:01 +00:00
|
|
|
auto const percent_done = torrent.get_percent_done().to_int();
|
2022-12-21 21:26:25 +00:00
|
|
|
bool const sensitive = torrent.get_sensitive();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
set_error_color(*text_renderer_, torrent, widget, flags);
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const icon = torrent.get_icon();
|
|
|
|
auto const name = torrent.get_name();
|
2023-08-06 03:26:29 +00:00
|
|
|
auto const progress_color = get_progress_bar_color(torrent, widget);
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const gstr_prog = torrent.get_long_progress_text();
|
|
|
|
auto const gstr_stat = torrent.get_long_status_text();
|
2021-10-18 20:22:31 +00:00
|
|
|
renderer_.get_padding(xpad, ypad);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
2021-11-15 16:32:41 +00:00
|
|
|
Gdk::Rectangle icon_area;
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->property_gicon() = icon;
|
|
|
|
icon_renderer_->property_stock_size() = FullIconSize;
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_renderer_->get_preferred_size(widget, min_size, size);
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_area.set_width(size.width);
|
|
|
|
icon_area.set_height(size.height);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
|
|
|
Gdk::Rectangle name_area;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = name;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_weight() = TR_PANGO_WEIGHT(BOLD);
|
|
|
|
text_renderer_->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(NONE);
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_scale() = 1.0;
|
|
|
|
text_renderer_->get_preferred_size(widget, min_size, size);
|
2023-08-06 03:26:29 +00:00
|
|
|
name_area.set_height(size.height);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
|
|
|
Gdk::Rectangle prog_area;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = gstr_prog;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_weight() = TR_PANGO_WEIGHT(NORMAL);
|
2021-12-14 08:43:27 +00:00
|
|
|
text_renderer_->property_scale() = SmallScale;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->get_preferred_size(widget, min_size, size);
|
2023-08-06 03:26:29 +00:00
|
|
|
prog_area.set_height(size.height);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
|
|
|
Gdk::Rectangle stat_area;
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = gstr_stat;
|
|
|
|
text_renderer_->get_preferred_size(widget, min_size, size);
|
2023-08-06 03:26:29 +00:00
|
|
|
stat_area.set_height(size.height);
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2021-11-15 16:32:41 +00:00
|
|
|
Gdk::Rectangle prct_area;
|
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto fill_area = background_area;
|
|
|
|
fill_area.set_x(fill_area.get_x() + xpad);
|
|
|
|
fill_area.set_y(fill_area.get_y() + ypad);
|
|
|
|
fill_area.set_width(fill_area.get_width() - xpad * 2);
|
|
|
|
fill_area.set_height(fill_area.get_height() - ypad * 2);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* icon */
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_area.set_y(fill_area.get_y() + (fill_area.get_height() - icon_area.get_height()) / 2);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* name */
|
2021-10-18 20:22:31 +00:00
|
|
|
name_area.set_y(fill_area.get_y());
|
2021-11-15 16:32:41 +00:00
|
|
|
name_area.set_width(fill_area.get_width() - GUI_PAD - icon_area.get_width());
|
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
if ((renderer_.get_state(widget, flags) & TR_GTK_STATE_FLAGS(DIR_RTL)) == Gtk::StateFlags{})
|
2021-11-15 16:32:41 +00:00
|
|
|
{
|
|
|
|
icon_area.set_x(fill_area.get_x());
|
|
|
|
name_area.set_x(fill_area.get_x() + fill_area.get_width() - name_area.get_width());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
icon_area.set_x(fill_area.get_x() + fill_area.get_width() - icon_area.get_width());
|
|
|
|
name_area.set_x(fill_area.get_x());
|
|
|
|
}
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* prog */
|
2021-10-18 20:22:31 +00:00
|
|
|
prog_area.set_x(name_area.get_x());
|
|
|
|
prog_area.set_y(name_area.get_y() + name_area.get_height());
|
|
|
|
prog_area.set_width(name_area.get_width());
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* progressbar */
|
2021-10-18 20:22:31 +00:00
|
|
|
prct_area.set_x(prog_area.get_x());
|
|
|
|
prct_area.set_y(prog_area.get_y() + prog_area.get_height() + GUI_PAD_SMALL);
|
|
|
|
prct_area.set_width(prog_area.get_width());
|
2022-11-13 17:36:16 +00:00
|
|
|
prct_area.set_height(property_bar_height_.get_value());
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* status */
|
2021-10-18 20:22:31 +00:00
|
|
|
stat_area.set_x(prct_area.get_x());
|
|
|
|
stat_area.set_y(prct_area.get_y() + prct_area.get_height() + GUI_PAD_SMALL);
|
|
|
|
stat_area.set_width(prct_area.get_width());
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** RENDER
|
|
|
|
**/
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->property_gicon() = icon;
|
|
|
|
icon_renderer_->property_stock_size() = FullIconSize;
|
2021-10-18 20:22:31 +00:00
|
|
|
icon_renderer_->property_sensitive() = sensitive;
|
2023-08-06 03:26:29 +00:00
|
|
|
icon_renderer_->render(context, widget, icon_area, icon_area, flags);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = name;
|
|
|
|
text_renderer_->property_scale() = 1.0;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(END);
|
|
|
|
text_renderer_->property_weight() = TR_PANGO_WEIGHT(BOLD);
|
2022-12-21 21:26:25 +00:00
|
|
|
text_renderer_->property_sensitive() = sensitive;
|
2023-08-06 03:26:29 +00:00
|
|
|
text_renderer_->render(context, widget, name_area, name_area, flags);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = gstr_prog;
|
2021-12-14 08:43:27 +00:00
|
|
|
text_renderer_->property_scale() = SmallScale;
|
2022-09-10 13:19:54 +00:00
|
|
|
text_renderer_->property_weight() = TR_PANGO_WEIGHT(NORMAL);
|
2023-08-06 03:26:29 +00:00
|
|
|
text_renderer_->render(context, widget, prog_area, prog_area, flags);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
progress_renderer_->property_value() = percent_done;
|
2021-10-18 20:22:31 +00:00
|
|
|
progress_renderer_->property_text() = Glib::ustring();
|
|
|
|
progress_renderer_->property_sensitive() = sensitive;
|
2023-08-06 03:26:29 +00:00
|
|
|
render_progress_bar(context, widget, prct_area, flags, progress_color);
|
2021-11-15 16:32:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_text() = gstr_stat;
|
2023-08-06 03:26:29 +00:00
|
|
|
text_renderer_->render(context, widget, stat_area, stat_area, flags);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
void TorrentCellRenderer::render_vfunc(
|
|
|
|
Cairo::RefPtr<Cairo::Context> const& context,
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget& widget,
|
|
|
|
Gdk::Rectangle const& background_area,
|
|
|
|
Gdk::Rectangle const& /*cell_area*/,
|
|
|
|
Gtk::CellRendererState flags)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2008-02-16 19:36:07 +00:00
|
|
|
#ifdef TEST_RTL
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const real_dir = widget.get_direction();
|
|
|
|
widget.set_direction(Gtk::TEXT_DIR_RTL);
|
2008-02-16 19:36:07 +00:00
|
|
|
#endif
|
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
if (impl_->property_torrent().get_value() != nullptr)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
if (impl_->property_compact().get_value())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-08-06 03:26:29 +00:00
|
|
|
impl_->render_compact(context, widget, background_area, flags);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-19 20:04:38 +00:00
|
|
|
else
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-08-06 03:26:29 +00:00
|
|
|
impl_->render_full(context, widget, background_area, flags);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
2021-10-18 20:22:31 +00:00
|
|
|
widget.set_direction(real_dir);
|
2008-02-16 19:36:07 +00:00
|
|
|
#endif
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
TorrentCellRenderer::Impl::~Impl()
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->unreference();
|
|
|
|
progress_renderer_->unreference();
|
|
|
|
icon_renderer_->unreference();
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
TorrentCellRenderer::TorrentCellRenderer()
|
|
|
|
: Glib::ObjectBase(typeid(TorrentCellRenderer))
|
|
|
|
, impl_(std::make_unique<Impl>(*this))
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
TorrentCellRenderer::~TorrentCellRenderer() = default;
|
2011-08-09 06:31:33 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
TorrentCellRenderer::Impl::Impl(TorrentCellRenderer& renderer)
|
2022-11-13 17:36:16 +00:00
|
|
|
: renderer_(renderer)
|
|
|
|
, property_torrent_(renderer, "torrent", nullptr)
|
|
|
|
, property_bar_height_(renderer, "bar-height", DefaultBarHeight)
|
|
|
|
, property_compact_(renderer, "compact", false)
|
|
|
|
, text_renderer_(Gtk::make_managed<Gtk::CellRendererText>())
|
|
|
|
, progress_renderer_(Gtk::make_managed<Gtk::CellRendererProgress>())
|
|
|
|
, icon_renderer_(Gtk::make_managed<Gtk::CellRendererPixbuf>())
|
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
renderer_.property_xpad() = GUI_PAD_SMALL;
|
|
|
|
renderer_.property_ypad() = GUI_PAD_SMALL;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
text_renderer_->property_xpad() = 0;
|
|
|
|
text_renderer_->property_ypad() = 0;
|
2008-01-12 17:59:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::PropertyProxy<Torrent*> TorrentCellRenderer::property_torrent()
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->property_torrent().get_proxy();
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::PropertyProxy<int> TorrentCellRenderer::property_bar_height()
|
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->property_bar_height().get_proxy();
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::PropertyProxy<bool> TorrentCellRenderer::property_compact()
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->property_compact().get_proxy();
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|