2007-02-07 07:35:33 +00:00
|
|
|
|
/******************************************************************************
|
2011-01-19 13:48:47 +00:00
|
|
|
|
* Copyright (c) Transmission authors and contributors
|
2007-02-07 07:35:33 +00:00
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2013-02-14 15:17:42 +00:00
|
|
|
|
#include <string.h> /* strlen() */
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
#include <glibmm/i18n.h>
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
|
#include <libtransmission/transmission.h>
|
2017-04-21 07:40:57 +00:00
|
|
|
|
#include <libtransmission/utils.h> /* tr_formatter_speed_KBps() */
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
|
#include "Actions.h"
|
|
|
|
|
#include "FilterBar.h"
|
|
|
|
|
#include "HigWorkarea.h"
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
|
#include "Prefs.h"
|
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
|
#include "Session.h"
|
|
|
|
|
#include "TorrentCellRenderer.h"
|
|
|
|
|
#include "Utils.h"
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
class MainWindow::Impl
|
2007-02-07 07:35:33 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
public:
|
2021-11-12 09:12:50 +00:00
|
|
|
|
Impl(MainWindow& window, Glib::RefPtr<Gio::ActionGroup> const& actions, Glib::RefPtr<Session> const& core);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
~Impl();
|
|
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> get_selection() const;
|
|
|
|
|
|
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
|
|
void prefsChanged(tr_quark key);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Gtk::TreeView* makeview(Glib::RefPtr<Gtk::TreeModel> const& model);
|
|
|
|
|
|
|
|
|
|
Gtk::Menu* createOptionsMenu();
|
|
|
|
|
Gtk::Menu* createSpeedMenu(tr_direction dir);
|
|
|
|
|
Gtk::Menu* createRatioMenu();
|
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
void on_popup_menu(GdkEventButton* event);
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void onSpeedToggled(Gtk::CheckMenuItem* check, tr_direction dir, bool enabled);
|
|
|
|
|
void onSpeedSet(tr_direction dir, int KBps);
|
|
|
|
|
|
|
|
|
|
void onRatioToggled(Gtk::CheckMenuItem* check, bool enabled);
|
|
|
|
|
void onRatioSet(double ratio);
|
|
|
|
|
|
|
|
|
|
void updateStats();
|
|
|
|
|
void updateSpeeds();
|
|
|
|
|
|
|
|
|
|
void syncAltSpeedButton();
|
|
|
|
|
|
|
|
|
|
void status_menu_toggled_cb(Gtk::CheckMenuItem* menu_item, std::string const& val);
|
|
|
|
|
void onOptionsClicked(Gtk::Button* button);
|
|
|
|
|
void onYinYangClicked(Gtk::Button* button);
|
|
|
|
|
void alt_speed_toggled_cb();
|
|
|
|
|
void onAltSpeedToggledIdle();
|
|
|
|
|
|
|
|
|
|
private:
|
2021-11-12 09:12:50 +00:00
|
|
|
|
MainWindow& window_;
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Gtk::RadioMenuItem* speedlimit_on_item_[2] = { nullptr, nullptr };
|
|
|
|
|
Gtk::RadioMenuItem* speedlimit_off_item_[2] = { nullptr, nullptr };
|
|
|
|
|
Gtk::RadioMenuItem* ratio_on_item_ = nullptr;
|
|
|
|
|
Gtk::RadioMenuItem* ratio_off_item_ = nullptr;
|
|
|
|
|
Gtk::ScrolledWindow* scroll_ = nullptr;
|
|
|
|
|
Gtk::TreeView* view_ = nullptr;
|
|
|
|
|
Gtk::Toolbar* toolbar_ = nullptr;
|
|
|
|
|
FilterBar* filter_ = nullptr;
|
|
|
|
|
Gtk::Grid* status_ = nullptr;
|
|
|
|
|
Gtk::Menu* status_menu_;
|
|
|
|
|
Gtk::Label* ul_lb_ = nullptr;
|
|
|
|
|
Gtk::Label* dl_lb_ = nullptr;
|
|
|
|
|
Gtk::Label* stats_lb_ = nullptr;
|
|
|
|
|
Gtk::Image* alt_speed_image_ = nullptr;
|
|
|
|
|
Gtk::ToggleButton* alt_speed_button_ = nullptr;
|
|
|
|
|
Gtk::Menu* options_menu_ = nullptr;
|
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> selection_;
|
|
|
|
|
TorrentCellRenderer* renderer_ = nullptr;
|
|
|
|
|
Gtk::TreeViewColumn* column_ = nullptr;
|
2021-11-01 00:11:23 +00:00
|
|
|
|
Glib::RefPtr<Session> const core_;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
sigc::connection pref_handler_id_;
|
2021-11-13 12:59:39 +00:00
|
|
|
|
Gtk::Menu* popup_menu_ = nullptr;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
};
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
|
/***
|
|
|
|
|
****
|
|
|
|
|
***/
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
void MainWindow::Impl::on_popup_menu(GdkEventButton* event)
|
2007-02-07 07:35:33 +00:00
|
|
|
|
{
|
2021-11-12 09:12:50 +00:00
|
|
|
|
if (popup_menu_ == nullptr)
|
|
|
|
|
{
|
|
|
|
|
popup_menu_ = Gtk::make_managed<Gtk::Menu>(gtr_action_get_object<Gio::Menu>("main-window-popup"));
|
|
|
|
|
popup_menu_->attach_to_widget(window_);
|
|
|
|
|
}
|
2020-08-18 10:36:10 +00:00
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
popup_menu_->popup_at_pointer(reinterpret_cast<GdkEvent*>(event));
|
2007-02-07 07:35:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
bool tree_view_search_equal_func(
|
|
|
|
|
Glib::RefPtr<Gtk::TreeModel> const& /*model*/,
|
|
|
|
|
int /*column*/,
|
|
|
|
|
Glib::ustring const& key,
|
|
|
|
|
Gtk::TreeModel::iterator const& iter)
|
2007-02-07 07:35:33 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const name = iter->get_value(torrent_cols.name_collated);
|
|
|
|
|
return name.find(key.lowercase()) == Glib::ustring::npos;
|
2007-02-07 07:35:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
} // namespace
|
2011-09-12 06:11:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Gtk::TreeView* MainWindow::Impl::makeview(Glib::RefPtr<Gtk::TreeModel> const& model)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* view = Gtk::make_managed<Gtk::TreeView>();
|
|
|
|
|
view->set_search_column(torrent_cols.name_collated);
|
|
|
|
|
view->set_search_equal_func(&tree_view_search_equal_func);
|
|
|
|
|
view->set_headers_visible(false);
|
|
|
|
|
view->set_fixed_height_mode(true);
|
|
|
|
|
|
|
|
|
|
selection_ = view->get_selection();
|
|
|
|
|
|
|
|
|
|
column_ = new Gtk::TreeViewColumn();
|
|
|
|
|
column_->set_title(_("Torrent"));
|
|
|
|
|
column_->set_resizable(true);
|
|
|
|
|
column_->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
|
|
|
|
|
|
|
|
|
|
renderer_ = Gtk::make_managed<TorrentCellRenderer>();
|
|
|
|
|
column_->pack_start(*renderer_, false);
|
|
|
|
|
column_->add_attribute(renderer_->property_torrent(), torrent_cols.torrent);
|
|
|
|
|
column_->add_attribute(renderer_->property_piece_upload_speed(), torrent_cols.speed_up);
|
|
|
|
|
column_->add_attribute(renderer_->property_piece_download_speed(), torrent_cols.speed_down);
|
|
|
|
|
|
|
|
|
|
view->append_column(*column_);
|
|
|
|
|
renderer_->property_xpad() = GUI_PAD_SMALL;
|
|
|
|
|
renderer_->property_ypad() = GUI_PAD_SMALL;
|
|
|
|
|
|
|
|
|
|
selection_->set_mode(Gtk::SELECTION_MULTIPLE);
|
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
view->signal_popup_menu().connect_notify([this]() { on_popup_menu(nullptr); });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
view->signal_button_press_event().connect(
|
2021-11-12 09:12:50 +00:00
|
|
|
|
[this, view](GdkEventButton* event)
|
|
|
|
|
{ return on_tree_view_button_pressed(view, event, sigc::mem_fun(*this, &Impl::on_popup_menu)); },
|
2021-10-18 20:22:31 +00:00
|
|
|
|
false);
|
|
|
|
|
view->signal_button_release_event().connect([view](GdkEventButton* event)
|
|
|
|
|
{ return on_tree_view_button_released(view, event); });
|
|
|
|
|
view->signal_row_activated().connect([](auto const& /*path*/, auto* /*column*/)
|
|
|
|
|
{ gtr_action_activate("show-torrent-properties"); });
|
|
|
|
|
|
|
|
|
|
view->set_model(model);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
return view;
|
2007-02-07 07:35:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::prefsChanged(tr_quark const key)
|
2007-12-19 19:16:36 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
switch (key)
|
2007-12-19 19:16:36 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
case TR_KEY_compact_view:
|
2021-10-18 20:22:31 +00:00
|
|
|
|
renderer_->property_compact() = gtr_pref_flag_get(key);
|
2012-12-22 20:35:19 +00:00
|
|
|
|
/* since the cell size has changed, we need gtktreeview to revalidate
|
|
|
|
|
* its fixed-height mode values. Unfortunately there's not an API call
|
|
|
|
|
* for that, but it *does* revalidate when it thinks the style's been tweaked */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
g_signal_emit_by_name(Glib::unwrap(view_), "style-updated", nullptr, nullptr);
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
case TR_KEY_show_statusbar:
|
2021-10-18 20:22:31 +00:00
|
|
|
|
status_->set_visible(gtr_pref_flag_get(key));
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
case TR_KEY_show_filterbar:
|
2021-10-18 20:22:31 +00:00
|
|
|
|
filter_->set_visible(gtr_pref_flag_get(key));
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
case TR_KEY_show_toolbar:
|
2021-10-18 20:22:31 +00:00
|
|
|
|
toolbar_->set_visible(gtr_pref_flag_get(key));
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
case TR_KEY_statusbar_stats:
|
2021-10-18 20:22:31 +00:00
|
|
|
|
refresh();
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
case TR_KEY_alt_speed_enabled:
|
|
|
|
|
case TR_KEY_alt_speed_up:
|
|
|
|
|
case TR_KEY_alt_speed_down:
|
2021-10-18 20:22:31 +00:00
|
|
|
|
syncAltSpeedButton();
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
default:
|
2012-12-22 20:35:19 +00:00
|
|
|
|
break;
|
2009-03-28 16:47:01 +00:00
|
|
|
|
}
|
2007-12-19 19:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
MainWindow::Impl::~Impl()
|
2007-12-19 19:16:36 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
pref_handler_id_.disconnect();
|
2007-12-19 19:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onYinYangClicked(Gtk::Button* button)
|
2007-12-20 19:21:21 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
status_menu_->popup_at_widget(button, Gdk::GRAVITY_NORTH_EAST, Gdk::GRAVITY_SOUTH_EAST, nullptr);
|
2007-12-20 19:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::status_menu_toggled_cb(Gtk::CheckMenuItem* menu_item, std::string const& val)
|
2007-12-20 19:21:21 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
if (menu_item->get_active())
|
2007-12-20 19:21:21 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(TR_KEY_statusbar_stats, val);
|
2007-12-20 19:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::syncAltSpeedButton()
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
bool const b = gtr_pref_flag_get(TR_KEY_alt_speed_enabled);
|
2020-11-01 21:47:57 +00:00
|
|
|
|
char const* const stock = b ? "alt-speed-on" : "alt-speed-off";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
|
char u[32];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_formatter_speed_KBps(u, gtr_pref_int_get(TR_KEY_alt_speed_up), sizeof(u));
|
2020-11-01 21:47:57 +00:00
|
|
|
|
char d[32];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_formatter_speed_KBps(d, gtr_pref_int_get(TR_KEY_alt_speed_down), sizeof(d));
|
2020-11-01 21:47:57 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const str = b ? gtr_sprintf(_("Click to disable Alternative Speed Limits\n (%1$s down, %2$s up)"), d, u) :
|
|
|
|
|
gtr_sprintf(_("Click to enable Alternative Speed Limits\n (%1$s down, %2$s up)"), d, u);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
alt_speed_button_->set_active(b);
|
2021-11-12 09:12:50 +00:00
|
|
|
|
alt_speed_image_->set_from_icon_name(stock, Gtk::BuiltinIconSize::ICON_SIZE_MENU);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
alt_speed_button_->set_halign(Gtk::ALIGN_CENTER);
|
|
|
|
|
alt_speed_button_->set_valign(Gtk::ALIGN_CENTER);
|
|
|
|
|
alt_speed_button_->set_tooltip_text(str);
|
2009-03-28 16:47:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::alt_speed_toggled_cb()
|
2009-03-28 16:47:01 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(TR_KEY_alt_speed_enabled, alt_speed_button_->get_active());
|
2009-03-28 16:47:01 +00:00
|
|
|
|
}
|
2009-08-10 20:04:08 +00:00
|
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
|
/***
|
|
|
|
|
**** FILTER
|
|
|
|
|
***/
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onAltSpeedToggledIdle()
|
2009-03-28 16:47:01 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(TR_KEY_alt_speed_enabled, tr_sessionUsesAltSpeed(core_->get_session()));
|
2009-03-28 16:47:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
|
/***
|
|
|
|
|
**** Speed limit menu
|
|
|
|
|
***/
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onSpeedToggled(Gtk::CheckMenuItem* check, tr_direction dir, bool enabled)
|
2009-04-15 04:28:04 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
if (check->get_active())
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(dir == TR_UP ? TR_KEY_speed_limit_up_enabled : TR_KEY_speed_limit_down_enabled, enabled);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
}
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onSpeedSet(tr_direction dir, int KBps)
|
2009-04-15 04:28:04 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(dir == TR_UP ? TR_KEY_speed_limit_up : TR_KEY_speed_limit_down, KBps);
|
|
|
|
|
core_->set_pref(dir == TR_UP ? TR_KEY_speed_limit_up_enabled : TR_KEY_speed_limit_down_enabled, true);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Gtk::Menu* MainWindow::Impl::createSpeedMenu(tr_direction dir)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
static int const speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
|
|
|
|
|
|
|
|
|
|
auto* m = Gtk::make_managed<Gtk::Menu>();
|
|
|
|
|
Gtk::RadioButtonGroup group;
|
|
|
|
|
|
|
|
|
|
speedlimit_off_item_[dir] = Gtk::make_managed<Gtk::RadioMenuItem>(group, _("Unlimited"));
|
|
|
|
|
speedlimit_off_item_[dir]->signal_toggled().connect([this, dir]()
|
|
|
|
|
{ onSpeedToggled(speedlimit_off_item_[dir], dir, false); });
|
|
|
|
|
m->append(*speedlimit_off_item_[dir]);
|
|
|
|
|
|
|
|
|
|
speedlimit_on_item_[dir] = Gtk::make_managed<Gtk::RadioMenuItem>(group, "");
|
|
|
|
|
speedlimit_on_item_[dir]->signal_toggled().connect([this, dir]() { onSpeedToggled(speedlimit_on_item_[dir], dir, true); });
|
|
|
|
|
m->append(*speedlimit_on_item_[dir]);
|
|
|
|
|
|
|
|
|
|
m->append(*Gtk::make_managed<Gtk::SeparatorMenuItem>());
|
|
|
|
|
|
|
|
|
|
for (auto const speed : speeds_KBps)
|
2009-04-15 15:10:22 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
char buf[128];
|
2021-10-18 20:22:31 +00:00
|
|
|
|
tr_formatter_speed_KBps(buf, speed, sizeof(buf));
|
|
|
|
|
auto* w = Gtk::make_managed<Gtk::MenuItem>(buf);
|
|
|
|
|
w->signal_activate().connect([this, dir, speed]() { onSpeedSet(dir, speed); });
|
|
|
|
|
m->append(*w);
|
2009-04-15 15:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
return m;
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
**** Speed limit menu
|
|
|
|
|
***/
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onRatioToggled(Gtk::CheckMenuItem* check, bool enabled)
|
2009-04-15 04:28:04 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
if (check->get_active())
|
2009-04-15 04:28:04 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(TR_KEY_ratio_limit_enabled, enabled);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-14 21:30:14 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onRatioSet(double ratio)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
core_->set_pref(TR_KEY_ratio_limit, ratio);
|
|
|
|
|
core_->set_pref(TR_KEY_ratio_limit_enabled, true);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Gtk::Menu* MainWindow::Impl::createRatioMenu()
|
2009-04-15 04:28:04 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
static double const stockRatios[] = { 0.25, 0.5, 0.75, 1, 1.5, 2, 3 };
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* m = Gtk::make_managed<Gtk::Menu>();
|
|
|
|
|
Gtk::RadioButtonGroup group;
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
ratio_off_item_ = Gtk::make_managed<Gtk::RadioMenuItem>(group, _("Seed Forever"));
|
|
|
|
|
ratio_off_item_->signal_toggled().connect([this]() { onRatioToggled(ratio_off_item_, false); });
|
|
|
|
|
m->append(*ratio_off_item_);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
ratio_on_item_ = Gtk::make_managed<Gtk::RadioMenuItem>(group, "");
|
|
|
|
|
ratio_on_item_->signal_toggled().connect([this]() { onRatioToggled(ratio_on_item_, true); });
|
|
|
|
|
m->append(*ratio_on_item_);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
m->append(*Gtk::make_managed<Gtk::SeparatorMenuItem>());
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
for (auto const ratio : stockRatios)
|
2009-04-15 15:10:22 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* w = Gtk::make_managed<Gtk::MenuItem>(tr_strlratio(ratio));
|
|
|
|
|
w->signal_activate().connect([this, ratio]() { onRatioSet(ratio); });
|
|
|
|
|
m->append(*w);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
|
return m;
|
|
|
|
|
}
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
|
/***
|
|
|
|
|
**** Option menu
|
|
|
|
|
***/
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Gtk::Menu* MainWindow::Impl::createOptionsMenu()
|
2009-04-15 15:10:22 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Gtk::MenuItem* m;
|
|
|
|
|
auto* top = Gtk::make_managed<Gtk::Menu>();
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
m = Gtk::make_managed<Gtk::MenuItem>(_("Limit Download Speed"));
|
|
|
|
|
m->set_submenu(*createSpeedMenu(TR_DOWN));
|
|
|
|
|
top->append(*m);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
m = Gtk::make_managed<Gtk::MenuItem>(_("Limit Upload Speed"));
|
|
|
|
|
m->set_submenu(*createSpeedMenu(TR_UP));
|
|
|
|
|
top->append(*m);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
top->append(*Gtk::make_managed<Gtk::SeparatorMenuItem>());
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
m = Gtk::make_managed<Gtk::MenuItem>(_("Stop Seeding at Ratio"));
|
|
|
|
|
m->set_submenu(*createRatioMenu());
|
|
|
|
|
top->append(*m);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
top->show_all();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
return top;
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::onOptionsClicked(Gtk::Button* button)
|
2009-04-15 04:28:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
char buf1[512];
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_formatter_speed_KBps(buf1, gtr_pref_int_get(TR_KEY_speed_limit_down), sizeof(buf1));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
gtr_label_set_text(*static_cast<Gtk::Label*>(speedlimit_on_item_[TR_DOWN]->get_child()), buf1);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
(gtr_pref_flag_get(TR_KEY_speed_limit_down_enabled) ? speedlimit_on_item_[TR_DOWN] : speedlimit_off_item_[TR_DOWN])
|
|
|
|
|
->set_active(true);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_formatter_speed_KBps(buf1, gtr_pref_int_get(TR_KEY_speed_limit_up), sizeof(buf1));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
gtr_label_set_text(*static_cast<Gtk::Label*>(speedlimit_on_item_[TR_UP]->get_child()), buf1);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
(gtr_pref_flag_get(TR_KEY_speed_limit_up_enabled) ? speedlimit_on_item_[TR_UP] : speedlimit_off_item_[TR_UP])
|
|
|
|
|
->set_active(true);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
gtr_label_set_text(
|
|
|
|
|
*static_cast<Gtk::Label*>(ratio_on_item_->get_child()),
|
|
|
|
|
gtr_sprintf(_("Stop at Ratio (%s)"), tr_strlratio(gtr_pref_double_get(TR_KEY_ratio_limit))));
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
(gtr_pref_flag_get(TR_KEY_ratio_limit_enabled) ? ratio_on_item_ : ratio_off_item_)->set_active(true);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
options_menu_->popup_at_widget(button, Gdk::GRAVITY_NORTH_WEST, Gdk::GRAVITY_SOUTH_WEST, nullptr);
|
2009-04-15 04:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
|
/***
|
|
|
|
|
**** PUBLIC
|
|
|
|
|
***/
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
std::unique_ptr<MainWindow> MainWindow::create(
|
|
|
|
|
Gtk::Application& app,
|
2021-11-12 09:12:50 +00:00
|
|
|
|
Glib::RefPtr<Gio::ActionGroup> const& actions,
|
2021-11-01 00:11:23 +00:00
|
|
|
|
Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
|
{
|
2021-11-12 09:12:50 +00:00
|
|
|
|
return std::unique_ptr<MainWindow>(new MainWindow(app, actions, core));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
MainWindow::MainWindow(Gtk::Application& app, Glib::RefPtr<Gio::ActionGroup> const& actions, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
|
: Gtk::ApplicationWindow()
|
2021-11-12 09:12:50 +00:00
|
|
|
|
, impl_(std::make_unique<Impl>(*this, actions, core))
|
2021-10-18 20:22:31 +00:00
|
|
|
|
{
|
|
|
|
|
app.add_window(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() = default;
|
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
MainWindow::Impl::Impl(MainWindow& window, Glib::RefPtr<Gio::ActionGroup> const& actions, Glib::RefPtr<Session> const& core)
|
|
|
|
|
: window_(window)
|
|
|
|
|
, core_(core)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
char const* val;
|
|
|
|
|
char const* i18n;
|
|
|
|
|
} const stats_modes[] = {
|
|
|
|
|
{ "total-ratio", N_("Total Ratio") },
|
|
|
|
|
{ "session-ratio", N_("Session Ratio") },
|
|
|
|
|
{ "total-transfer", N_("Total Transfer") },
|
|
|
|
|
{ "session-transfer", N_("Session Transfer") },
|
|
|
|
|
};
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* make the window */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
window.set_title(Glib::get_application_name());
|
|
|
|
|
window.set_role("tr-main");
|
|
|
|
|
window.set_default_size(gtr_pref_int_get(TR_KEY_main_window_width), gtr_pref_int_get(TR_KEY_main_window_height));
|
|
|
|
|
window.move(gtr_pref_int_get(TR_KEY_main_window_x), gtr_pref_int_get(TR_KEY_main_window_y));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
if (gtr_pref_flag_get(TR_KEY_main_window_is_maximized))
|
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
window.maximize();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
|
window.insert_action_group("win", actions);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* Add style provider to the window. */
|
|
|
|
|
/* Please move it to separate .css file if you’re adding more styles here. */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const* style = ".tr-workarea.frame {border-left-width: 0; border-right-width: 0; border-radius: 0;}";
|
|
|
|
|
auto css_provider = Gtk::CssProvider::create();
|
|
|
|
|
css_provider->load_from_data(style);
|
|
|
|
|
Gtk::StyleContext::add_provider_for_screen(
|
|
|
|
|
Gdk::Screen::get_default(),
|
|
|
|
|
css_provider,
|
2017-04-19 12:04:45 +00:00
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
|
|
|
|
|
|
/* window's main container */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* vbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL, 0);
|
|
|
|
|
window.add(*vbox);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* toolbar */
|
2021-11-12 09:12:50 +00:00
|
|
|
|
toolbar_ = gtr_action_get_widget<Gtk::Toolbar>("main-window-toolbar");
|
2021-10-18 20:22:31 +00:00
|
|
|
|
toolbar_->get_style_context()->add_class(GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* filter */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
filter_ = Gtk::make_managed<FilterBar>(core_->get_session(), core_->get_model());
|
|
|
|
|
filter_->set_border_width(GUI_PAD_SMALL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* status menu */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
status_menu_ = Gtk::make_managed<Gtk::Menu>();
|
|
|
|
|
Gtk::RadioButtonGroup stats_modes_group;
|
|
|
|
|
auto const pch = gtr_pref_string_get(TR_KEY_statusbar_stats);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
for (auto const& mode : stats_modes)
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* w = Gtk::make_managed<Gtk::RadioMenuItem>(stats_modes_group, _(mode.i18n));
|
|
|
|
|
w->set_active(mode.val == pch);
|
|
|
|
|
w->signal_toggled().connect([this, w, val = mode.val]() { status_menu_toggled_cb(w, val); });
|
|
|
|
|
status_menu_->append(*w);
|
|
|
|
|
w->show();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*** Statusbar
|
|
|
|
|
**/
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
status_ = Gtk::make_managed<Gtk::Grid>();
|
|
|
|
|
status_->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
|
|
status_->set_border_width(GUI_PAD_SMALL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* gear */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* gear_button = Gtk::make_managed<Gtk::Button>();
|
2021-11-21 11:36:52 +00:00
|
|
|
|
gear_button->add(*Gtk::make_managed<Gtk::Image>("preferences-other", Gtk::ICON_SIZE_MENU));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
gear_button->set_tooltip_text(_("Options"));
|
|
|
|
|
gear_button->set_relief(Gtk::RELIEF_NONE);
|
|
|
|
|
options_menu_ = createOptionsMenu();
|
|
|
|
|
gear_button->signal_clicked().connect([this, gear_button]() { onOptionsClicked(gear_button); });
|
|
|
|
|
status_->add(*gear_button);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* turtle */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
alt_speed_image_ = Gtk::make_managed<Gtk::Image>();
|
|
|
|
|
alt_speed_button_ = Gtk::make_managed<Gtk::ToggleButton>();
|
|
|
|
|
alt_speed_button_->set_image(*alt_speed_image_);
|
|
|
|
|
alt_speed_button_->set_relief(Gtk::RELIEF_NONE);
|
2021-11-12 09:12:50 +00:00
|
|
|
|
alt_speed_button_->signal_toggled().connect(sigc::mem_fun(*this, &Impl::alt_speed_toggled_cb));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
status_->add(*alt_speed_button_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* spacer */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* w = Gtk::make_managed<Gtk::Fixed>();
|
|
|
|
|
w->set_hexpand(true);
|
|
|
|
|
status_->add(*w);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* download */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
dl_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
|
dl_lb_->set_single_line_mode(true);
|
|
|
|
|
status_->add(*dl_lb_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* upload */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
ul_lb_ = Gtk::make_managed<Gtk::Label>();
|
2021-11-12 09:12:50 +00:00
|
|
|
|
ul_lb_->set_margin_start(GUI_PAD);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
ul_lb_->set_single_line_mode(true);
|
|
|
|
|
status_->add(*ul_lb_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* ratio */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
stats_lb_ = Gtk::make_managed<Gtk::Label>();
|
2021-11-12 09:12:50 +00:00
|
|
|
|
stats_lb_->set_margin_start(GUI_PAD_BIG);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
stats_lb_->set_single_line_mode(true);
|
|
|
|
|
status_->add(*stats_lb_);
|
2019-11-06 19:09:27 +00:00
|
|
|
|
|
|
|
|
|
/* ratio selector */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto* ratio_button = Gtk::make_managed<Gtk::Button>();
|
|
|
|
|
ratio_button->set_tooltip_text(_("Statistics"));
|
2021-11-21 11:36:52 +00:00
|
|
|
|
ratio_button->add(*Gtk::make_managed<Gtk::Image>("view-statistics", Gtk::ICON_SIZE_MENU));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
ratio_button->set_relief(Gtk::RELIEF_NONE);
|
|
|
|
|
ratio_button->signal_clicked().connect([this, ratio_button]() { onYinYangClicked(ratio_button); });
|
|
|
|
|
status_->add(*ratio_button);
|
2019-11-06 19:09:27 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*** Workarea
|
|
|
|
|
**/
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
view_ = makeview(filter_->get_filter_model());
|
|
|
|
|
scroll_ = Gtk::make_managed<Gtk::ScrolledWindow>();
|
|
|
|
|
scroll_->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
|
|
|
|
scroll_->set_shadow_type(Gtk::SHADOW_OUT);
|
|
|
|
|
scroll_->get_style_context()->add_class("tr-workarea");
|
|
|
|
|
scroll_->add(*view_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* lay out the widgets */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
vbox->pack_start(*toolbar_, false, false);
|
|
|
|
|
vbox->pack_start(*filter_, false, false);
|
|
|
|
|
vbox->pack_start(*scroll_, true, true);
|
|
|
|
|
vbox->pack_start(*status_, false, false);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2010-01-10 01:43:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* this is to determine the maximum width/height for the label */
|
2020-08-11 18:11:55 +00:00
|
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const pango_layout = ul_lb_->create_pango_layout("999.99 kB/s");
|
|
|
|
|
pango_layout->get_pixel_size(width, height);
|
|
|
|
|
ul_lb_->set_size_request(width, height);
|
|
|
|
|
dl_lb_->set_size_request(width, height);
|
|
|
|
|
ul_lb_->set_halign(Gtk::ALIGN_END);
|
|
|
|
|
ul_lb_->set_valign(Gtk::ALIGN_CENTER);
|
|
|
|
|
dl_lb_->set_halign(Gtk::ALIGN_END);
|
|
|
|
|
dl_lb_->set_valign(Gtk::ALIGN_CENTER);
|
2010-01-10 01:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* show all but the window */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
vbox->show_all();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* listen for prefs changes that affect the window */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
prefsChanged(TR_KEY_compact_view);
|
|
|
|
|
prefsChanged(TR_KEY_show_filterbar);
|
|
|
|
|
prefsChanged(TR_KEY_show_statusbar);
|
|
|
|
|
prefsChanged(TR_KEY_statusbar_stats);
|
|
|
|
|
prefsChanged(TR_KEY_show_toolbar);
|
|
|
|
|
prefsChanged(TR_KEY_alt_speed_enabled);
|
2021-11-12 09:12:50 +00:00
|
|
|
|
pref_handler_id_ = core_->signal_prefs_changed().connect(sigc::mem_fun(*this, &Impl::prefsChanged));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
|
|
tr_sessionSetAltSpeedFunc(
|
|
|
|
|
core_->get_session(),
|
|
|
|
|
[](tr_session* /*s*/, bool /*isEnabled*/, bool /*byUser*/, void* p)
|
|
|
|
|
{ Glib::signal_idle().connect_once([p]() { static_cast<Impl*>(p)->onAltSpeedToggledIdle(); }); },
|
|
|
|
|
this);
|
|
|
|
|
|
|
|
|
|
refresh();
|
2007-02-07 07:35:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::updateStats()
|
2007-12-24 19:12:52 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Glib::ustring buf;
|
|
|
|
|
tr_session_stats stats;
|
|
|
|
|
auto const* const session = core_->get_session();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
/* update the stats */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const pch = gtr_pref_string_get(TR_KEY_statusbar_stats);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
if (pch == "session-ratio")
|
2008-09-23 19:11:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_sessionGetStats(session, &stats);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
buf = gtr_sprintf(_("Ratio: %s"), tr_strlratio(stats.ratio));
|
2008-09-23 19:11:04 +00:00
|
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
else if (pch == "session-transfer")
|
2008-09-23 19:11:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_sessionGetStats(session, &stats);
|
|
|
|
|
/* Translators: "size|" is here for disambiguation. Please remove it from your translation.
|
|
|
|
|
%1$s is the size of the data we've downloaded
|
|
|
|
|
%2$s is the size of the data we've uploaded */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
buf = gtr_sprintf(Q_("Down: %1$s, Up: %2$s"), tr_strlsize(stats.downloadedBytes), tr_strlsize(stats.uploadedBytes));
|
2008-09-23 19:11:04 +00:00
|
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
else if (pch == "total-transfer")
|
2008-09-23 19:11:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_sessionGetCumulativeStats(session, &stats);
|
|
|
|
|
/* Translators: "size|" is here for disambiguation. Please remove it from your translation.
|
|
|
|
|
%1$s is the size of the data we've downloaded
|
|
|
|
|
%2$s is the size of the data we've uploaded */
|
2021-10-18 20:22:31 +00:00
|
|
|
|
buf = gtr_sprintf(
|
|
|
|
|
Q_("size|Down: %1$s, Up: %2$s"),
|
|
|
|
|
tr_strlsize(stats.downloadedBytes),
|
|
|
|
|
tr_strlsize(stats.uploadedBytes));
|
2008-09-23 19:11:04 +00:00
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
else /* default is total-ratio */
|
2008-09-23 19:11:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_sessionGetCumulativeStats(session, &stats);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
buf = gtr_sprintf(_("Ratio: %s"), tr_strlratio(stats.ratio));
|
2007-12-24 19:12:52 +00:00
|
|
|
|
}
|
2012-12-13 03:37:55 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
stats_lb_->set_text(buf);
|
2007-12-24 19:12:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::updateSpeeds()
|
2007-12-24 19:12:52 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const* const session = core_->get_session();
|
2007-12-24 19:12:52 +00:00
|
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
|
if (session != nullptr)
|
2008-11-08 02:49:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
char speed_str[128];
|
|
|
|
|
double upSpeed = 0;
|
|
|
|
|
double downSpeed = 0;
|
|
|
|
|
int upCount = 0;
|
|
|
|
|
int downCount = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const model = core_->get_model();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
for (auto const& row : model->children())
|
2009-08-07 20:49:06 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
upSpeed += row.get_value(torrent_cols.speed_up);
|
|
|
|
|
upCount += row.get_value(torrent_cols.active_peers_up);
|
|
|
|
|
downSpeed += row.get_value(torrent_cols.speed_down);
|
|
|
|
|
downCount += row.get_value(torrent_cols.active_peers_down);
|
2009-08-07 20:49:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_formatter_speed_KBps(speed_str, downSpeed, sizeof(speed_str));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
dl_lb_->set_text(gtr_sprintf("%s %s", speed_str, gtr_get_unicode_string(GTR_UNICODE_DOWN)));
|
|
|
|
|
dl_lb_->set_visible(downCount > 0);
|
2008-11-08 02:49:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_formatter_speed_KBps(speed_str, upSpeed, sizeof(speed_str));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
ul_lb_->set_text(gtr_sprintf("%s %s", speed_str, gtr_get_unicode_string(GTR_UNICODE_UP)));
|
|
|
|
|
ul_lb_->set_visible(downCount > 0 || upCount > 0);
|
2008-11-08 02:49:04 +00:00
|
|
|
|
}
|
2007-12-24 19:12:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::refresh()
|
2007-02-07 07:35:33 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
impl_->refresh();
|
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::Impl::refresh()
|
|
|
|
|
{
|
|
|
|
|
if (core_ != nullptr && core_->get_session() != nullptr)
|
2007-12-20 19:21:21 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
updateSpeeds();
|
|
|
|
|
updateStats();
|
2007-12-20 19:21:21 +00:00
|
|
|
|
}
|
2007-02-07 07:35:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> MainWindow::get_selection() const
|
2007-02-07 07:35:33 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
return impl_->get_selection();
|
2007-02-07 07:35:33 +00:00
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> MainWindow::Impl::get_selection() const
|
2010-06-26 15:55:19 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
return selection_;
|
|
|
|
|
}
|
2012-12-13 03:37:55 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
void MainWindow::set_busy(bool isBusy)
|
|
|
|
|
{
|
|
|
|
|
if (get_realized())
|
2010-12-12 16:43:19 +00:00
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
auto const display = get_display();
|
|
|
|
|
auto const cursor = isBusy ? Gdk::Cursor::create(display, Gdk::WATCH) : Glib::RefPtr<Gdk::Cursor>();
|
2010-06-26 15:55:19 +00:00
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
|
get_window()->set_cursor(cursor);
|
|
|
|
|
display->flush();
|
2010-06-26 15:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|