2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// This file is licensed under the MIT (SPDX: MIT) license,
|
|
|
|
// A copy of this license can be found in licenses/ .
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Session.h"
|
2010-12-20 02:07:51 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Actions.h"
|
|
|
|
#include "ListModelAdapter.h"
|
|
|
|
#include "Notify.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "PrefsDialog.h"
|
2023-01-08 15:31:03 +00:00
|
|
|
#include "SortListModel.hh"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Torrent.h"
|
|
|
|
#include "TorrentSorter.h"
|
|
|
|
#include "Utils.h"
|
2022-03-14 04:43:35 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2013-01-25 23:34:20 +00:00
|
|
|
#include <libtransmission/log.h>
|
2009-04-07 20:13:08 +00:00
|
|
|
#include <libtransmission/rpcimpl.h>
|
2021-12-26 16:25:07 +00:00
|
|
|
#include <libtransmission/torrent-metainfo.h>
|
2022-08-18 14:14:12 +00:00
|
|
|
#include <libtransmission/utils.h> // tr_time()
|
2012-12-14 04:34:42 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <libtransmission/web-utils.h> // tr_urlIsValid()
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <giomm/asyncresult.h>
|
|
|
|
#include <giomm/dbusconnection.h>
|
|
|
|
#include <giomm/fileinfo.h>
|
|
|
|
#include <giomm/filemonitor.h>
|
|
|
|
#include <giomm/liststore.h>
|
|
|
|
#include <glibmm/error.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/miscutils.h>
|
|
|
|
#include <glibmm/stringutils.h>
|
|
|
|
#include <glibmm/variant.h>
|
|
|
|
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
#include <gtkmm/sortlistmodel.h>
|
|
|
|
#else
|
|
|
|
#include <gtkmm/treemodelsort.h>
|
|
|
|
#endif
|
2022-12-26 21:13:21 +00:00
|
|
|
|
|
|
|
#include <fmt/core.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cinttypes> // PRId64
|
|
|
|
#include <cstring> // strstr
|
|
|
|
#include <functional>
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <utility>
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
class Session::Impl
|
2008-02-09 17:29:05 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-07-22 05:52:48 +00:00
|
|
|
Impl(Session& core, tr_session* session);
|
2022-12-16 17:40:28 +00:00
|
|
|
~Impl();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-12-28 14:47:53 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Impl)
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_session* close();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Gio::ListStore<Torrent>> get_raw_model() const;
|
2023-01-08 15:31:03 +00:00
|
|
|
Glib::RefPtr<SortListModel<Torrent>> get_model();
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_session* get_session() const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
std::pair<Glib::RefPtr<Torrent>, guint> find_torrent_by_id(tr_torrent_id_t torrent_id) const;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
size_t get_active_torrent_count() const;
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void update();
|
|
|
|
void torrents_added();
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void add_files(std::vector<Glib::RefPtr<Gio::File>> const& files, bool do_start, bool do_prompt, bool do_notify);
|
2023-12-25 00:05:18 +00:00
|
|
|
void add_ctor(tr_ctor* ctor, bool do_prompt, bool do_notify);
|
2022-12-21 21:26:25 +00:00
|
|
|
void add_torrent(Glib::RefPtr<Torrent> const& torrent, bool do_notify);
|
2022-11-09 16:58:36 +00:00
|
|
|
bool add_from_url(Glib::ustring const& url);
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
void send_rpc_request(tr_variant const& request, int64_t tag, std::function<void(tr_variant&)> const& response_func);
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void commit_prefs_change(tr_quark key);
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
auto& signal_add_error()
|
|
|
|
{
|
|
|
|
return signal_add_error_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& signal_add_prompt()
|
|
|
|
{
|
|
|
|
return signal_add_prompt_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& signal_blocklist_updated()
|
|
|
|
{
|
|
|
|
return signal_blocklist_updated_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& signal_busy()
|
|
|
|
{
|
|
|
|
return signal_busy_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& signal_prefs_changed()
|
|
|
|
{
|
|
|
|
return signal_prefs_changed_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& signal_port_tested()
|
|
|
|
{
|
|
|
|
return signal_port_tested_;
|
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto& signal_torrents_changed()
|
|
|
|
{
|
|
|
|
return signal_torrents_changed_;
|
|
|
|
}
|
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
[[nodiscard]] constexpr auto& favicon_cache()
|
|
|
|
{
|
|
|
|
return favicon_cache_;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
private:
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> get_core_ptr() const;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
bool is_busy() const;
|
2021-10-18 20:22:31 +00:00
|
|
|
void add_to_busy(int addMe);
|
|
|
|
void inc_busy();
|
|
|
|
void dec_busy();
|
|
|
|
|
|
|
|
bool add_file(Glib::RefPtr<Gio::File> const& file, bool do_start, bool do_prompt, bool do_notify);
|
|
|
|
void add_file_async_callback(
|
|
|
|
Glib::RefPtr<Gio::File> const& file,
|
|
|
|
Glib::RefPtr<Gio::AsyncResult>& result,
|
|
|
|
tr_ctor* ctor,
|
|
|
|
bool do_prompt,
|
|
|
|
bool do_notify);
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Torrent> create_new_torrent(tr_ctor* ctor);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
void maybe_inhibit_hibernation();
|
|
|
|
void set_hibernation_allowed(bool allowed);
|
|
|
|
|
|
|
|
void watchdir_update();
|
|
|
|
void watchdir_scan();
|
|
|
|
void watchdir_monitor_file(Glib::RefPtr<Gio::File> const& file);
|
|
|
|
bool watchdir_idle();
|
|
|
|
void on_file_changed_in_watchdir(
|
|
|
|
Glib::RefPtr<Gio::File> const& file,
|
|
|
|
Glib::RefPtr<Gio::File> const& other_type,
|
2022-09-10 13:19:54 +00:00
|
|
|
IF_GLIBMM2_68(Gio::FileMonitor::Event, Gio::FileMonitorEvent) event_type);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
void on_pref_changed(tr_quark key);
|
|
|
|
|
|
|
|
void on_torrent_completeness_changed(tr_torrent* tor, tr_completeness completeness, bool was_running);
|
2022-12-21 21:26:25 +00:00
|
|
|
void on_torrent_metadata_changed(tr_torrent* raw_torrent);
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
private:
|
2021-11-01 00:11:23 +00:00
|
|
|
Session& core_;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
sigc::signal<void(ErrorCode, Glib::ustring const&)> signal_add_error_;
|
|
|
|
sigc::signal<void(tr_ctor*)> signal_add_prompt_;
|
2022-12-17 23:12:25 +00:00
|
|
|
sigc::signal<void(bool)> signal_blocklist_updated_;
|
2022-11-13 17:36:16 +00:00
|
|
|
sigc::signal<void(bool)> signal_busy_;
|
|
|
|
sigc::signal<void(tr_quark)> signal_prefs_changed_;
|
|
|
|
sigc::signal<void(bool)> signal_port_tested_;
|
2022-12-21 21:26:25 +00:00
|
|
|
sigc::signal<void(std::unordered_set<tr_torrent_id_t> const&, Torrent::ChangeFlags)> signal_torrents_changed_;
|
2022-11-13 17:36:16 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::RefPtr<Gio::FileMonitor> monitor_;
|
|
|
|
sigc::connection monitor_tag_;
|
|
|
|
Glib::RefPtr<Gio::File> monitor_dir_;
|
|
|
|
std::vector<Glib::RefPtr<Gio::File>> monitor_files_;
|
|
|
|
sigc::connection monitor_idle_tag_;
|
|
|
|
|
|
|
|
bool adding_from_watch_dir_ = false;
|
|
|
|
bool inhibit_allowed_ = false;
|
|
|
|
bool have_inhibit_cookie_ = false;
|
|
|
|
bool dbus_error_ = false;
|
|
|
|
guint inhibit_cookie_ = 0;
|
|
|
|
gint busy_count_ = 0;
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Gio::ListStore<Torrent>> raw_model_;
|
2023-01-08 15:31:03 +00:00
|
|
|
Glib::RefPtr<SortListModel<Torrent>> sorted_model_;
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<TorrentSorter> sorter_ = TorrentSorter::create();
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_session* session_ = nullptr;
|
2023-04-23 02:11:16 +00:00
|
|
|
|
|
|
|
FaviconCache<Glib::RefPtr<Gdk::Pixbuf>> favicon_cache_;
|
2021-10-18 20:22:31 +00:00
|
|
|
};
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> Session::Impl::get_core_ptr() const
|
2011-03-03 07:17:57 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
core_.reference();
|
2022-10-14 04:59:38 +00:00
|
|
|
return Glib::make_refptr_for_instance(&core_);
|
2011-03-03 07:17:57 +00:00
|
|
|
}
|
|
|
|
|
2010-06-26 15:55:19 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Gio::ListStore<Torrent>> Session::Impl::get_raw_model() const
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return raw_model_;
|
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Gio::ListModel> Session::get_model() const
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
return impl_->get_raw_model();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Session::Model> Session::get_sorted_model() const
|
2022-11-09 16:58:36 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
return impl_->get_model();
|
2022-11-09 16:58:36 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 15:31:03 +00:00
|
|
|
Glib::RefPtr<SortListModel<Torrent>> Session::Impl::get_model()
|
2011-01-31 23:01:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return sorted_model_;
|
2011-01-31 23:01:46 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
tr_session* Session::get_session() const
|
2011-01-31 23:01:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return impl_->get_session();
|
2011-01-31 23:01:46 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
tr_session* Session::Impl::get_session() const
|
2011-01-31 23:01:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return session_;
|
2011-01-31 23:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
2011-03-04 14:31:23 +00:00
|
|
|
**** BUSY
|
2011-01-31 23:01:46 +00:00
|
|
|
***/
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
bool Session::Impl::is_busy() const
|
2010-06-26 15:55:19 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return busy_count_ > 0;
|
2010-06-26 15:55:19 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::add_to_busy(int addMe)
|
2010-06-26 15:55:19 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const wasBusy = is_busy();
|
2010-06-26 15:55:19 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
busy_count_ += addMe;
|
2010-06-26 15:55:19 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (wasBusy != is_busy())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
signal_busy_.emit(is_busy());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-06-26 15:55:19 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::inc_busy()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
add_to_busy(1);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::dec_busy()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
add_to_busy(-1);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-06-26 15:55:19 +00:00
|
|
|
|
2011-03-03 07:17:57 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** WATCHDIR
|
|
|
|
****
|
|
|
|
***/
|
2008-03-09 22:11:36 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2009-10-11 06:23:31 +00:00
|
|
|
{
|
2013-01-20 04:10:47 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
time_t get_file_mtime(Glib::RefPtr<Gio::File> const& file)
|
|
|
|
{
|
2022-11-02 17:17:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return file->query_info(G_FILE_ATTRIBUTE_TIME_MODIFIED)->get_attribute_uint64(G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
|
|
|
}
|
|
|
|
catch (Glib::Error const&)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2009-10-11 06:23:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void rename_torrent(Glib::RefPtr<Gio::File> const& file)
|
2011-08-13 22:24:31 +00:00
|
|
|
{
|
2022-11-02 17:17:29 +00:00
|
|
|
auto info = Glib::RefPtr<Gio::FileInfo>();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-11-02 17:17:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
info = file->query_info(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
|
|
|
|
}
|
|
|
|
catch (Glib::Error const&)
|
2013-01-20 04:10:47 +00:00
|
|
|
{
|
2022-11-02 17:17:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-20 04:10:47 +00:00
|
|
|
|
2022-11-02 17:17:29 +00:00
|
|
|
auto const old_name = info->get_attribute_as_string(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
|
|
|
|
auto const new_name = fmt::format("{}.added", old_name);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
file->set_display_name(new_name);
|
|
|
|
}
|
|
|
|
catch (Glib::Error const& e)
|
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_message(fmt::format(
|
2022-11-02 17:17:29 +00:00
|
|
|
_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"),
|
|
|
|
fmt::arg("old_path", old_name),
|
|
|
|
fmt::arg("path", new_name),
|
|
|
|
fmt::arg("error", e.what()),
|
2022-11-13 17:36:16 +00:00
|
|
|
fmt::arg("error_code", e.code())));
|
2013-01-20 04:10:47 +00:00
|
|
|
}
|
2011-08-13 22:24:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
bool Session::Impl::watchdir_idle()
|
2008-03-09 22:11:36 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<Glib::RefPtr<Gio::File>> changing;
|
|
|
|
std::vector<Glib::RefPtr<Gio::File>> unchanging;
|
2017-04-20 16:02:19 +00:00
|
|
|
time_t const now = tr_time();
|
2011-08-13 13:58:35 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* separate the files into two lists: changing and unchanging */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& file : monitor_files_)
|
2011-08-13 13:58:35 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
time_t const mtime = get_file_mtime(file);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (mtime + 2 >= now)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
changing.push_back(file);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
unchanging.push_back(file);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-10-11 06:23:31 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* add the files that have stopped changing */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!unchanging.empty())
|
2011-08-13 13:58:35 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
|
|
|
|
bool const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
adding_from_watch_dir_ = true;
|
|
|
|
add_files(unchanging, do_start, do_prompt, true);
|
|
|
|
std::for_each(unchanging.begin(), unchanging.end(), rename_torrent);
|
|
|
|
adding_from_watch_dir_ = false;
|
2011-08-13 13:58:35 +00:00
|
|
|
}
|
2008-03-12 02:11:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* keep monitoring the ones that are still changing */
|
2021-10-18 20:22:31 +00:00
|
|
|
monitor_files_ = changing;
|
2009-10-11 06:23:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* if monitor_files is nonempty, keep checking every second */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!monitor_files_.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
monitor_idle_tag_.disconnect();
|
|
|
|
return false;
|
2008-03-09 22:11:36 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 13:58:35 +00:00
|
|
|
/* If this file is a torrent, add it to our list */
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::watchdir_monitor_file(Glib::RefPtr<Gio::File> const& file)
|
2008-03-13 01:06:54 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const filename = file->get_path();
|
|
|
|
bool const is_torrent = Glib::str_has_suffix(filename, ".torrent");
|
2008-03-13 01:06:54 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (is_torrent)
|
2008-03-13 01:06:54 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* if we're not already watching this file, start watching it now */
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const found = std::any_of(
|
|
|
|
monitor_files_.begin(),
|
|
|
|
monitor_files_.end(),
|
|
|
|
[file](auto const& f) { return file->equal(f); });
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (!found)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
monitor_files_.push_back(file);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!monitor_idle_tag_.connected())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-11-12 09:12:50 +00:00
|
|
|
monitor_idle_tag_ = Glib::signal_timeout().connect_seconds(sigc::mem_fun(*this, &Impl::watchdir_idle), 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-08-13 13:58:35 +00:00
|
|
|
}
|
2008-03-13 01:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-13 13:58:35 +00:00
|
|
|
/* GFileMonitor noticed a file was created */
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::on_file_changed_in_watchdir(
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::RefPtr<Gio::File> const& file,
|
|
|
|
Glib::RefPtr<Gio::File> const& /*other_type*/,
|
2022-09-10 13:19:54 +00:00
|
|
|
IF_GLIBMM2_68(Gio::FileMonitor::Event, Gio::FileMonitorEvent) event_type)
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
if (event_type == TR_GIO_FILE_MONITOR_EVENT(CREATED))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
watchdir_monitor_file(file);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-03-09 15:27:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 13:58:35 +00:00
|
|
|
/* walk through the pre-existing files in the watchdir */
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::watchdir_scan()
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const dirname = gtr_pref_string_get(TR_KEY_watch_dir);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
try
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& name : Glib::Dir(dirname))
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
watchdir_monitor_file(Gio::File::create_for_path(Glib::build_filename(dirname, name)));
|
2008-03-13 01:06:54 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
catch (Glib::FileError const&)
|
|
|
|
{
|
2008-03-09 15:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::watchdir_update()
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const is_enabled = gtr_pref_flag_get(TR_KEY_watch_dir_enabled);
|
|
|
|
auto const dir = Gio::File::create_for_path(gtr_pref_string_get(TR_KEY_watch_dir));
|
2008-03-09 15:27:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (monitor_ != nullptr && (!is_enabled || !dir->equal(monitor_dir_)))
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
monitor_tag_.disconnect();
|
|
|
|
monitor_->cancel();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
monitor_dir_.reset();
|
|
|
|
monitor_.reset();
|
2008-03-09 15:27:08 +00:00
|
|
|
}
|
2008-03-09 22:11:36 +00:00
|
|
|
|
2022-12-12 17:12:30 +00:00
|
|
|
if (!is_enabled || monitor_ != nullptr)
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2022-12-12 17:12:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto monitor = Glib::RefPtr<Gio::FileMonitor>();
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2022-12-12 17:12:30 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
monitor = dir->monitor_directory();
|
2008-03-09 15:27:08 +00:00
|
|
|
}
|
2022-12-12 17:12:30 +00:00
|
|
|
catch (Glib::Error const&)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
watchdir_scan();
|
|
|
|
|
|
|
|
monitor_ = monitor;
|
|
|
|
monitor_dir_ = dir;
|
|
|
|
monitor_tag_ = monitor_->signal_changed().connect(sigc::mem_fun(*this, &Impl::on_file_changed_in_watchdir));
|
2008-03-09 15:27:08 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2011-03-03 07:17:57 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::on_pref_changed(tr_quark const key)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (key)
|
2008-03-09 15:27:08 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_KEY_sort_mode:
|
2022-12-21 21:26:25 +00:00
|
|
|
sorter_->set_mode(gtr_pref_string_get(TR_KEY_sort_mode));
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_KEY_sort_reversed:
|
2022-12-21 21:26:25 +00:00
|
|
|
sorter_->set_reversed(gtr_pref_flag_get(TR_KEY_sort_reversed));
|
|
|
|
break;
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_KEY_peer_limit_global:
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_sessionSetPeerLimit(session_, gtr_pref_int_get(key));
|
2012-12-22 20:35:19 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_KEY_peer_limit_per_torrent:
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_sessionSetPeerLimitPerTorrent(session_, gtr_pref_int_get(key));
|
2012-12-22 20:35:19 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_KEY_inhibit_desktop_hibernation:
|
2021-10-18 20:22:31 +00:00
|
|
|
maybe_inhibit_hibernation();
|
2012-12-22 20:35:19 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_KEY_watch_dir:
|
|
|
|
case TR_KEY_watch_dir_enabled:
|
2021-10-18 20:22:31 +00:00
|
|
|
watchdir_update();
|
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;
|
2008-05-18 16:44:30 +00:00
|
|
|
}
|
2007-05-23 00:49:31 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 14:16:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2022-07-22 05:52:48 +00:00
|
|
|
Glib::RefPtr<Session> Session::create(tr_session* session)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
|
2022-07-22 05:52:48 +00:00
|
|
|
return Glib::make_refptr_for_instance(new Session(session));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 05:52:48 +00:00
|
|
|
Session::Session(tr_session* session)
|
2021-11-01 00:11:23 +00:00
|
|
|
: Glib::ObjectBase(typeid(Session))
|
2022-07-22 05:52:48 +00:00
|
|
|
, impl_(std::make_unique<Impl>(*this, session))
|
2007-05-23 00:49:31 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
Session::~Session() = default;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-07-22 05:52:48 +00:00
|
|
|
Session::Impl::Impl(Session& core, tr_session* session)
|
2023-04-23 02:11:16 +00:00
|
|
|
: core_{ core }
|
|
|
|
, session_{ session }
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
raw_model_ = Gio::ListStore<Torrent>::create();
|
2023-08-06 03:26:29 +00:00
|
|
|
signal_torrents_changed_.connect(sigc::hide<0>(sigc::mem_fun(*sorter_, &TorrentSorter::update)));
|
2023-01-08 15:31:03 +00:00
|
|
|
sorted_model_ = SortListModel<Torrent>::create(gtr_ptr_static_cast<Gio::ListModel>(raw_model_), sorter_);
|
2007-12-19 19:16:36 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* init from prefs & listen to pref changes */
|
2021-10-18 20:22:31 +00:00
|
|
|
on_pref_changed(TR_KEY_sort_mode);
|
|
|
|
on_pref_changed(TR_KEY_sort_reversed);
|
|
|
|
on_pref_changed(TR_KEY_watch_dir_enabled);
|
|
|
|
on_pref_changed(TR_KEY_peer_limit_global);
|
|
|
|
on_pref_changed(TR_KEY_inhibit_desktop_hibernation);
|
2022-11-13 17:36:16 +00:00
|
|
|
signal_prefs_changed_.connect([this](auto key) { on_pref_changed(key); });
|
2022-07-23 06:04:34 +00:00
|
|
|
|
|
|
|
tr_sessionSetMetadataCallback(
|
|
|
|
session,
|
|
|
|
[](auto* /*session*/, auto* tor, gpointer impl) { static_cast<Impl*>(impl)->on_torrent_metadata_changed(tor); },
|
|
|
|
this);
|
|
|
|
|
|
|
|
tr_sessionSetCompletenessCallback(
|
|
|
|
session,
|
|
|
|
[](auto* tor, auto completeness, bool was_running, gpointer impl)
|
|
|
|
{ static_cast<Impl*>(impl)->on_torrent_completeness_changed(tor, completeness, was_running); },
|
|
|
|
this);
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2007-12-19 19:16:36 +00:00
|
|
|
|
2022-12-16 17:40:28 +00:00
|
|
|
Session::Impl::~Impl()
|
|
|
|
{
|
|
|
|
monitor_idle_tag_.disconnect();
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
tr_session* Session::close()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return impl_->close();
|
2007-05-23 00:49:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
tr_session* Session::Impl::close()
|
2008-04-17 20:35:18 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* session = session_;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (session != nullptr)
|
2008-04-17 20:35:18 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
session_ = nullptr;
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_pref_save(session);
|
2008-04-17 20:35:18 +00:00
|
|
|
}
|
2013-01-04 06:57:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return session;
|
2008-04-17 20:35:18 +00:00
|
|
|
}
|
|
|
|
|
2011-03-03 07:17:57 +00:00
|
|
|
/***
|
2011-03-04 14:31:23 +00:00
|
|
|
**** COMPLETENESS CALLBACK
|
2011-03-03 07:17:57 +00:00
|
|
|
***/
|
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
/* this is called in the libtransmission thread, *NOT* the GTK+ thread,
|
|
|
|
so delegate to the GTK+ thread before calling notify's dbus code... */
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::on_torrent_completeness_changed(tr_torrent* tor, tr_completeness completeness, bool was_running)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
if (was_running && completeness != TR_LEECH && tr_torrentStat(tor)->sizeWhenDone != 0)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::signal_idle().connect(
|
|
|
|
[core = get_core_ptr(), torrent_id = tr_torrentId(tor)]()
|
|
|
|
{
|
|
|
|
gtr_notify_torrent_completed(core, torrent_id);
|
|
|
|
return false;
|
|
|
|
});
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-04 14:31:23 +00:00
|
|
|
/***
|
2011-04-05 15:41:51 +00:00
|
|
|
**** METADATA CALLBACK
|
2011-03-04 14:31:23 +00:00
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2011-03-04 14:31:23 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2011-04-05 15:41:51 +00:00
|
|
|
struct metadata_callback_data
|
|
|
|
{
|
2021-11-01 00:11:23 +00:00
|
|
|
Session* core;
|
2022-06-17 15:43:04 +00:00
|
|
|
tr_torrent_id_t torrent_id;
|
2011-04-05 15:41:51 +00:00
|
|
|
};
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
std::pair<Glib::RefPtr<Torrent>, guint> Session::Impl::find_torrent_by_id(tr_torrent_id_t torrent_id) const
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto begin_position = 0U;
|
|
|
|
auto end_position = raw_model_->get_n_items();
|
|
|
|
|
|
|
|
while (begin_position < end_position)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const position = begin_position + (end_position - begin_position) / 2;
|
|
|
|
auto const torrent = raw_model_->get_item(position);
|
2022-12-28 14:47:53 +00:00
|
|
|
auto const current_torrent_id = torrent->get_id();
|
2022-12-21 21:26:25 +00:00
|
|
|
|
2022-12-28 14:47:53 +00:00
|
|
|
if (current_torrent_id == torrent_id)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
return { torrent, position };
|
|
|
|
}
|
2022-12-28 14:47:53 +00:00
|
|
|
|
|
|
|
(current_torrent_id < torrent_id ? begin_position : end_position) = position;
|
2011-04-05 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return {};
|
2011-04-05 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this is called in the libtransmission thread, *NOT* the GTK+ thread,
|
|
|
|
so delegate to the GTK+ thread before changing our list store... */
|
2022-12-21 21:26:25 +00:00
|
|
|
void Session::Impl::on_torrent_metadata_changed(tr_torrent* raw_torrent)
|
2011-04-05 15:41:51 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::signal_idle().connect(
|
2022-12-21 21:26:25 +00:00
|
|
|
[this, core = get_core_ptr(), torrent_id = tr_torrentId(raw_torrent)]()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
/* update the torrent's collated name */
|
2023-04-18 04:11:09 +00:00
|
|
|
if (auto const& [torrent, position] = find_torrent_by_id(torrent_id); torrent)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
torrent->update();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2011-04-05 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** ADDING TORRENTS
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void Session::add_torrent(Glib::RefPtr<Torrent> const& torrent, bool do_notify)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
impl_->add_torrent(torrent, do_notify);
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void Session::Impl::add_torrent(Glib::RefPtr<Torrent> const& torrent, bool do_notify)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
if (torrent != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
raw_model_->insert_sorted(torrent, &Torrent::compare_by_id);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (do_notify)
|
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
gtr_notify_torrent_added(get_core_ptr(), torrent->get_id());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
2007-10-16 14:16:01 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Torrent> Session::Impl::create_new_torrent(tr_ctor* ctor)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
bool do_trash = false;
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* let the gtk client handle the removal, since libT
|
|
|
|
* doesn't have any concept of the glib trash API */
|
|
|
|
tr_ctorGetDeleteSource(ctor, &do_trash);
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_ctorSetDeleteSource(ctor, false);
|
2021-12-24 22:05:17 +00:00
|
|
|
tr_torrent* const tor = tr_torrentNew(ctor, nullptr);
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (tor != nullptr && do_trash)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2022-07-22 05:52:48 +00:00
|
|
|
char const* config = tr_sessionGetConfigDir(session_);
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* source = tr_ctorGetSourceFile(ctor);
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (source != nullptr)
|
2012-09-23 15:38:07 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* #1294: don't delete the .torrent file if it's our internal copy */
|
2022-07-22 05:52:48 +00:00
|
|
|
bool const is_internal = strstr(source, config) == source;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!is_internal)
|
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
gtr_file_trash_or_remove(source, nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2012-09-23 15:38:07 +00:00
|
|
|
}
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
return Torrent::create(tor);
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
|
2023-12-25 00:05:18 +00:00
|
|
|
void Session::Impl::add_ctor(tr_ctor* ctor, bool do_prompt, bool do_notify)
|
2009-06-11 14:51:21 +00:00
|
|
|
{
|
2021-12-26 16:25:07 +00:00
|
|
|
auto const* metainfo = tr_ctorGetMetainfo(ctor);
|
|
|
|
if (metainfo == nullptr)
|
2009-06-11 14:51:21 +00:00
|
|
|
{
|
2023-12-25 00:05:18 +00:00
|
|
|
return;
|
2021-12-26 16:25:07 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
if (tr_torrentFindFromMetainfo(get_session(), metainfo) != nullptr)
|
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
/* don't complain about torrent files in the watch directory
|
2012-12-05 17:29:46 +00:00
|
|
|
* that have already been added... that gets annoying and we
|
|
|
|
* don't want to be nagging users to clean up their watch dirs */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tr_ctorGetSourceFile(ctor) == nullptr || !adding_from_watch_dir_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
signal_add_error_.emit(ERR_ADD_TORRENT_DUP, metainfo->name().c_str());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tr_ctorFree(ctor);
|
2023-12-25 00:05:18 +00:00
|
|
|
return;
|
2021-12-26 16:25:07 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
if (!do_prompt)
|
|
|
|
{
|
|
|
|
add_torrent(create_new_torrent(ctor), do_notify);
|
|
|
|
tr_ctorFree(ctor);
|
2023-12-25 00:05:18 +00:00
|
|
|
return;
|
2009-06-11 14:51:21 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
signal_add_prompt_.emit(ctor);
|
2009-06-11 14:51:21 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void core_apply_defaults(tr_ctor* ctor)
|
2011-03-03 07:17:57 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
if (!tr_ctorGetPaused(ctor, TR_FORCE, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_ctorSetPaused(ctor, TR_FORCE, !gtr_pref_flag_get(TR_KEY_start_added_torrents));
|
|
|
|
}
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (!tr_ctorGetDeleteSource(ctor, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_ctorSetDeleteSource(ctor, gtr_pref_flag_get(TR_KEY_trash_original_torrent_files));
|
|
|
|
}
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (!tr_ctorGetPeerLimit(ctor, TR_FORCE, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_ctorSetPeerLimit(ctor, TR_FORCE, gtr_pref_int_get(TR_KEY_peer_limit_per_torrent));
|
|
|
|
}
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (!tr_ctorGetDownloadDir(ctor, TR_FORCE, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_ctorSetDownloadDir(ctor, TR_FORCE, gtr_pref_string_get(TR_KEY_download_dir).c_str());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-03-03 07:17:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::add_ctor(tr_ctor* ctor)
|
2009-09-17 01:28:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const do_notify = false;
|
|
|
|
bool const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
|
2017-04-19 12:04:45 +00:00
|
|
|
core_apply_defaults(ctor);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->add_ctor(ctor, do_prompt, do_notify);
|
2009-09-17 01:28:45 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::add_file_async_callback(
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::RefPtr<Gio::File> const& file,
|
|
|
|
Glib::RefPtr<Gio::AsyncResult>& result,
|
|
|
|
tr_ctor* ctor,
|
|
|
|
bool do_prompt,
|
|
|
|
bool do_notify)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
try
|
2010-06-25 17:40:55 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
gsize length = 0;
|
|
|
|
char* contents = nullptr;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!file->load_contents_finish(result, contents, length))
|
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_message(fmt::format(_("Couldn't read '{path}'"), fmt::arg("path", file->get_parse_name())));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2021-12-26 16:25:07 +00:00
|
|
|
else if (tr_ctorSetMetainfo(ctor, contents, length, nullptr))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
add_ctor(ctor, do_prompt, do_notify);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_ctorFree(ctor);
|
|
|
|
}
|
2010-06-25 17:40:55 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
catch (Glib::Error const& e)
|
2010-06-25 17:40:55 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_message(fmt::format(
|
2022-03-16 00:51:36 +00:00
|
|
|
_("Couldn't read '{path}': {error} ({error_code})"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("path", file->get_parse_name()),
|
|
|
|
fmt::arg("error", e.what()),
|
2022-11-13 17:36:16 +00:00
|
|
|
fmt::arg("error_code", e.code())));
|
2010-06-25 17:40:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
dec_busy();
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
bool Session::Impl::add_file(Glib::RefPtr<Gio::File> const& file, bool do_start, bool do_prompt, bool do_notify)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2023-11-26 21:43:37 +00:00
|
|
|
auto* const session = get_session();
|
2022-02-13 04:16:55 +00:00
|
|
|
if (session == nullptr)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2022-02-13 04:16:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-29 07:42:39 +00:00
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
bool handled = false;
|
|
|
|
auto* ctor = tr_ctorNew(session);
|
|
|
|
core_apply_defaults(ctor);
|
|
|
|
tr_ctorSetPaused(ctor, TR_FORCE, !do_start);
|
2009-11-22 16:20:22 +00:00
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
bool loaded = false;
|
|
|
|
if (auto const path = file->get_path(); !std::empty(path))
|
|
|
|
{
|
|
|
|
// try to treat it as a file...
|
|
|
|
loaded = tr_ctorSetMetainfoFromFile(ctor, path.c_str(), nullptr);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
if (!loaded)
|
|
|
|
{
|
|
|
|
// try to treat it as a magnet link...
|
|
|
|
loaded = tr_ctorSetMetainfoFromMagnetLink(ctor, file->get_uri().c_str(), nullptr);
|
|
|
|
}
|
2009-11-22 16:20:22 +00:00
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
// if we could make sense of it, add it
|
|
|
|
if (loaded)
|
|
|
|
{
|
|
|
|
handled = true;
|
|
|
|
add_ctor(ctor, do_prompt, do_notify);
|
|
|
|
}
|
|
|
|
else if (tr_urlIsValid(file->get_uri()))
|
|
|
|
{
|
|
|
|
handled = true;
|
|
|
|
inc_busy();
|
|
|
|
file->load_contents_async([this, file, ctor, do_prompt, do_notify](auto& result)
|
|
|
|
{ add_file_async_callback(file, result, ctor, do_prompt, do_notify); });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_ctorFree(ctor);
|
2022-03-21 14:15:48 +00:00
|
|
|
std::cerr << fmt::format(_("Couldn't add torrent file '{path}'"), fmt::arg("path", file->get_parse_name()))
|
|
|
|
<< std::endl;
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|
2008-12-03 06:01:38 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return handled;
|
2008-05-18 16:44:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
bool Session::add_from_url(Glib::ustring const& url)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-09 16:58:36 +00:00
|
|
|
return impl_->add_from_url(url);
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
bool Session::Impl::add_from_url(Glib::ustring const& url)
|
2007-05-24 10:37:07 +00:00
|
|
|
{
|
2022-11-09 16:58:36 +00:00
|
|
|
auto const file = Gio::File::create_for_uri(url);
|
2022-02-13 04:16:55 +00:00
|
|
|
auto const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
|
|
|
|
auto const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
|
|
|
|
auto const do_notify = false;
|
2010-08-02 22:31:31 +00:00
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
auto const handled = add_file(file, do_start, do_prompt, do_notify);
|
|
|
|
torrents_added();
|
2017-04-19 12:04:45 +00:00
|
|
|
return handled;
|
2007-05-24 10:37:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::add_files(std::vector<Glib::RefPtr<Gio::File>> const& files, bool do_start, bool do_prompt, bool do_notify)
|
2010-12-22 06:11:49 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->add_files(files, do_start, do_prompt, do_notify);
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::add_files(std::vector<Glib::RefPtr<Gio::File>> const& files, bool do_start, bool do_prompt, bool do_notify)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
for (auto const& file : files)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
add_file(file, do_start, do_prompt, do_notify);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-08-09 02:30:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
torrents_added();
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::torrents_added()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
impl_->torrents_added();
|
2010-12-22 06:11:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::torrents_added()
|
2007-05-23 17:59:35 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
update();
|
2022-11-13 17:36:16 +00:00
|
|
|
signal_add_error_.emit(ERR_NO_MORE_TORRENTS, {});
|
2007-05-23 17:59:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
void Session::torrent_changed(tr_torrent_id_t id)
|
2017-02-21 20:18:52 +00:00
|
|
|
{
|
2023-04-18 04:11:09 +00:00
|
|
|
if (auto const& [torrent, position] = impl_->find_torrent_by_id(id); torrent)
|
2017-02-21 20:18:52 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
torrent->update();
|
2017-02-21 20:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
void Session::remove_torrent(tr_torrent_id_t id, bool delete_files)
|
2008-02-19 03:57:03 +00:00
|
|
|
{
|
2023-04-18 04:11:09 +00:00
|
|
|
if (auto const& [torrent, position] = impl_->find_torrent_by_id(id); torrent)
|
2008-07-16 19:38:22 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* remove from the gui */
|
2022-12-21 21:26:25 +00:00
|
|
|
impl_->get_raw_model()->remove(position);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* remove the torrent */
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrentRemove(
|
2022-12-21 21:26:25 +00:00
|
|
|
&torrent->get_underlying(),
|
2022-11-09 16:58:36 +00:00
|
|
|
delete_files,
|
2023-11-04 16:39:41 +00:00
|
|
|
[](char const* filename, void* /*user_data*/, tr_error* error)
|
2022-10-23 16:51:35 +00:00
|
|
|
{ return gtr_file_trash_or_remove(filename, error); },
|
|
|
|
nullptr);
|
2008-07-16 19:38:22 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-19 03:57:03 +00:00
|
|
|
|
2022-08-18 14:14:12 +00:00
|
|
|
void Session::load(bool force_paused)
|
2011-03-03 07:17:57 +00:00
|
|
|
{
|
2022-08-18 14:14:12 +00:00
|
|
|
auto* const ctor = tr_ctorNew(impl_->get_session());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-08-18 14:14:12 +00:00
|
|
|
if (force_paused)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_ctorSetPaused(ctor, TR_FORCE, true);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_ctorSetPeerLimit(ctor, TR_FALLBACK, gtr_pref_int_get(TR_KEY_peer_limit_per_torrent));
|
2011-03-03 07:17:57 +00:00
|
|
|
|
2022-08-18 14:14:12 +00:00
|
|
|
auto* session = impl_->get_session();
|
|
|
|
auto const n_torrents = tr_sessionLoadTorrents(session, ctor);
|
|
|
|
tr_ctorFree(ctor);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto raw_torrents = std::vector<tr_torrent*>{};
|
|
|
|
raw_torrents.resize(n_torrents);
|
|
|
|
tr_sessionGetAllTorrents(session, std::data(raw_torrents), std::size(raw_torrents));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto torrents = std::vector<Glib::RefPtr<Torrent>>();
|
|
|
|
torrents.reserve(raw_torrents.size());
|
|
|
|
std::transform(raw_torrents.begin(), raw_torrents.end(), std::back_inserter(torrents), &Torrent::create);
|
|
|
|
std::sort(torrents.begin(), torrents.end(), &Torrent::less_by_id);
|
|
|
|
|
|
|
|
auto const model = impl_->get_raw_model();
|
|
|
|
model->splice(0, model->get_n_items(), torrents);
|
2011-03-03 07:17:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::clear()
|
2011-03-03 07:17:57 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
impl_->get_raw_model()->remove_all();
|
2011-03-03 07:17:57 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:29:05 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::update()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->update();
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
void Session::start_now(tr_torrent_id_t id)
|
2021-11-08 17:21:20 +00:00
|
|
|
{
|
|
|
|
tr_variant top;
|
|
|
|
tr_variantInitDict(&top, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&top, TR_KEY_method, "torrent-start-now");
|
2021-11-08 17:21:20 +00:00
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
auto* args = tr_variantDictAddDict(&top, TR_KEY_arguments, 1);
|
|
|
|
auto* ids = tr_variantDictAddList(args, TR_KEY_ids, 1);
|
2021-11-08 17:21:20 +00:00
|
|
|
tr_variantListAddInt(ids, id);
|
2024-01-03 04:14:43 +00:00
|
|
|
exec(top);
|
2021-11-08 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::update()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto torrent_ids = std::unordered_set<tr_torrent_id_t>();
|
|
|
|
auto changes = Torrent::ChangeFlags();
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* update the model */
|
2022-12-21 21:26:25 +00:00
|
|
|
for (auto i = 0U, count = raw_model_->get_n_items(); i < count; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const torrent = raw_model_->get_item(i);
|
|
|
|
if (auto const torrent_changes = torrent->update(); torrent_changes.any())
|
|
|
|
{
|
|
|
|
torrent_ids.insert(torrent->get_id());
|
|
|
|
changes |= torrent_changes;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update hibernation */
|
2021-10-18 20:22:31 +00:00
|
|
|
maybe_inhibit_hibernation();
|
2022-12-21 21:26:25 +00:00
|
|
|
|
|
|
|
if (changes.any())
|
|
|
|
{
|
|
|
|
signal_torrents_changed_.emit(torrent_ids, changes);
|
|
|
|
}
|
2007-05-23 01:47:42 +00:00
|
|
|
}
|
2007-05-23 17:59:35 +00:00
|
|
|
|
2008-05-24 23:23:20 +00:00
|
|
|
/**
|
|
|
|
*** Hibernate
|
|
|
|
**/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
auto const SessionManagerServiceName = "org.gnome.SessionManager"sv; // TODO(C++20): Use ""s
|
|
|
|
auto const SessionManagerInterface = "org.gnome.SessionManager"sv; // TODO(C++20): Use ""s
|
|
|
|
auto const SessionManagerObjectPath = "/org/gnome/SessionManager"sv; // TODO(C++20): Use ""s
|
2021-12-14 08:43:27 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool gtr_inhibit_hibernation(guint32& cookie)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool success = false;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* application = "Transmission BitTorrent Client";
|
|
|
|
char const* reason = "BitTorrent Activity";
|
|
|
|
int const toplevel_xid = 0;
|
|
|
|
int const flags = 4; /* Inhibit suspending the session or computer */
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
try
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
auto const connection = Gio::DBus::Connection::get_sync(TR_GIO_DBUS_BUS_TYPE(SESSION));
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto response = connection->call_sync(
|
2022-11-15 00:53:12 +00:00
|
|
|
std::string(SessionManagerObjectPath),
|
|
|
|
std::string(SessionManagerInterface),
|
2021-10-18 20:22:31 +00:00
|
|
|
"Inhibit",
|
|
|
|
Glib::VariantContainerBase::create_tuple({
|
|
|
|
Glib::Variant<Glib::ustring>::create(application),
|
|
|
|
Glib::Variant<guint32>::create(toplevel_xid),
|
|
|
|
Glib::Variant<Glib::ustring>::create(reason),
|
|
|
|
Glib::Variant<guint32>::create(flags),
|
|
|
|
}),
|
2022-11-15 00:53:12 +00:00
|
|
|
std::string(SessionManagerServiceName),
|
2021-10-18 20:22:31 +00:00
|
|
|
1000);
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
cookie = Glib::VariantBase::cast_dynamic<Glib::Variant<guint32>>(response.get_child(0)).get();
|
|
|
|
|
|
|
|
/* logging */
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(_("Inhibiting desktop hibernation"));
|
2008-05-24 23:23:20 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
success = true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
catch (Glib::Error const& e)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
tr_logAddError(fmt::format(_("Couldn't inhibit desktop hibernation: {error}"), fmt::arg("error", e.what())));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-10-11 20:32:15 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return success;
|
2008-05-24 23:23:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void gtr_uninhibit_hibernation(guint inhibit_cookie)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
try
|
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
auto const connection = Gio::DBus::Connection::get_sync(TR_GIO_DBUS_BUS_TYPE(SESSION));
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
connection->call_sync(
|
2022-11-15 00:53:12 +00:00
|
|
|
std::string(SessionManagerObjectPath),
|
|
|
|
std::string(SessionManagerInterface),
|
2021-10-18 20:22:31 +00:00
|
|
|
"Uninhibit",
|
|
|
|
Glib::VariantContainerBase::create_tuple({ Glib::Variant<guint32>::create(inhibit_cookie) }),
|
2022-11-15 00:53:12 +00:00
|
|
|
std::string(SessionManagerServiceName),
|
2021-10-18 20:22:31 +00:00
|
|
|
1000);
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/* logging */
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(_("Allowing desktop hibernation"));
|
2012-12-05 17:29:46 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
catch (Glib::Error const& e)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
tr_logAddError(fmt::format(_("Couldn't inhibit desktop hibernation: {error}"), fmt::arg("error", e.what())));
|
2008-05-24 23:23:20 +00:00
|
|
|
}
|
2011-08-07 16:42:38 +00:00
|
|
|
}
|
2008-05-24 23:23:20 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2008-05-24 23:23:20 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::set_hibernation_allowed(bool allowed)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
inhibit_allowed_ = allowed;
|
2008-05-24 23:23:20 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (allowed && have_inhibit_cookie_)
|
2008-05-24 23:23:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_uninhibit_hibernation(inhibit_cookie_);
|
|
|
|
have_inhibit_cookie_ = false;
|
2008-05-24 23:23:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!allowed && !have_inhibit_cookie_ && !dbus_error_)
|
2008-05-24 23:23:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (gtr_inhibit_hibernation(inhibit_cookie_))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
have_inhibit_cookie_ = true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
dbus_error_ = true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-05-24 23:23:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::maybe_inhibit_hibernation()
|
2008-07-02 18:49:07 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* hibernation is allowed if EITHER
|
|
|
|
* (a) the "inhibit" pref is turned off OR
|
|
|
|
* (b) there aren't any active torrents */
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const hibernation_allowed = !gtr_pref_flag_get(TR_KEY_inhibit_desktop_hibernation) || get_active_torrent_count() == 0;
|
|
|
|
set_hibernation_allowed(hibernation_allowed);
|
2008-07-02 18:49:07 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
/**
|
|
|
|
*** Prefs
|
|
|
|
**/
|
2007-06-27 18:34:38 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::Impl::commit_prefs_change(tr_quark const key)
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
signal_prefs_changed_.emit(key);
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_pref_save(session_);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2007-05-24 13:55:57 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::set_pref(tr_quark const key, std::string const& newval)
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (newval != gtr_pref_string_get(key))
|
2007-05-24 13:55:57 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_pref_string_set(key, newval);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->commit_prefs_change(key);
|
2007-05-24 13:55:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::set_pref(tr_quark const key, bool newval)
|
2007-05-24 13:55:57 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (newval != gtr_pref_flag_get(key))
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_pref_flag_set(key, newval);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->commit_prefs_change(key);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2007-05-24 13:55:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::set_pref(tr_quark const key, int newval)
|
2007-05-24 13:55:57 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (newval != gtr_pref_int_get(key))
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_pref_int_set(key, newval);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->commit_prefs_change(key);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2007-05-24 13:55:57 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::set_pref(tr_quark const key, double newval)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
if (std::fabs(newval - gtr_pref_double_get(key)) >= 0.0001)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_pref_double_set(key, newval);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->commit_prefs_change(key);
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 20:13:08 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** RPC Interface
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
/* #define DEBUG_RPC */
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-11-13 13:57:22 +00:00
|
|
|
int64_t nextTag = 1;
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2022-11-13 20:50:07 +00:00
|
|
|
std::map<int64_t, std::function<void(tr_variant&)>> pendingRequests;
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2022-11-13 20:50:07 +00:00
|
|
|
bool core_read_rpc_response_idle(tr_variant& response)
|
2009-04-07 20:13:08 +00:00
|
|
|
{
|
2022-11-13 20:50:07 +00:00
|
|
|
if (int64_t tag = 0; tr_variantDictFindInt(&response, TR_KEY_tag, &tag))
|
2010-09-23 17:05:40 +00:00
|
|
|
{
|
2021-11-13 13:57:22 +00:00
|
|
|
if (auto const data_it = pendingRequests.find(tag); data_it != pendingRequests.end())
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2021-11-13 13:57:22 +00:00
|
|
|
if (auto const& response_func = data_it->second; response_func)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-11-13 20:50:07 +00:00
|
|
|
response_func(response);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
pendingRequests.erase(data_it);
|
2010-09-23 17:05:40 +00:00
|
|
|
}
|
2021-11-13 13:57:22 +00:00
|
|
|
else
|
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_warning(fmt::format(_("Couldn't find pending RPC request for tag {tag}"), fmt::arg("tag", tag)));
|
2021-11-13 13:57:22 +00:00
|
|
|
}
|
2010-09-23 17:05:40 +00:00
|
|
|
}
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false;
|
2009-04-07 20:13:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
void core_read_rpc_response(tr_session* /*session*/, tr_variant&& response)
|
2009-04-07 20:13:08 +00:00
|
|
|
{
|
2024-01-03 04:14:43 +00:00
|
|
|
auto owned_response = std::make_shared<tr_variant>(std::move(response));
|
2023-08-21 04:15:23 +00:00
|
|
|
Glib::signal_idle().connect([owned_response]() mutable { return core_read_rpc_response_idle(*owned_response); });
|
2009-04-07 20:13:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2021-11-13 13:57:22 +00:00
|
|
|
void Session::Impl::send_rpc_request(
|
2024-01-03 04:14:43 +00:00
|
|
|
tr_variant const& request,
|
2021-11-13 13:57:22 +00:00
|
|
|
int64_t tag,
|
2022-11-13 20:50:07 +00:00
|
|
|
std::function<void(tr_variant&)> const& response_func)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
if (session_ == nullptr)
|
2009-04-07 20:13:08 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_error("GTK+ client doesn't support connections to remote servers yet.");
|
2009-04-07 20:13:08 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2009-04-07 20:13:08 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* remember this request */
|
2021-12-01 23:11:57 +00:00
|
|
|
pendingRequests.try_emplace(tag, response_func);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* make the request */
|
2009-04-07 20:13:08 +00:00
|
|
|
#ifdef DEBUG_RPC
|
2022-11-13 17:36:16 +00:00
|
|
|
gtr_message(fmt::format("request: [{}]", tr_variantToStr(request, TR_VARIANT_FMT_JSON_LEAN)));
|
2009-04-07 20:13:08 +00:00
|
|
|
#endif
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
tr_rpc_request_exec(session_, request, core_read_rpc_response);
|
2009-04-07 20:13:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
**** Sending a test-port request via RPC
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::port_test()
|
2009-04-07 20:13:08 +00:00
|
|
|
{
|
2021-12-01 23:11:57 +00:00
|
|
|
auto const tag = nextTag;
|
|
|
|
++nextTag;
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2019-03-17 05:00:15 +00:00
|
|
|
tr_variant request;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&request, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&request, TR_KEY_method, "port-test");
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddInt(&request, TR_KEY_tag, tag);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->send_rpc_request(
|
2024-01-03 04:14:43 +00:00
|
|
|
request,
|
2021-10-18 20:22:31 +00:00
|
|
|
tag,
|
2022-11-13 20:50:07 +00:00
|
|
|
[this](auto& response)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
tr_variant* args = nullptr;
|
|
|
|
bool is_open = false;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-13 20:50:07 +00:00
|
|
|
if (!tr_variantDictFindDict(&response, TR_KEY_arguments, &args) ||
|
2021-10-18 20:22:31 +00:00
|
|
|
!tr_variantDictFindBool(args, TR_KEY_port_is_open, &is_open))
|
|
|
|
{
|
|
|
|
is_open = false;
|
|
|
|
}
|
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
impl_->signal_port_tested().emit(is_open);
|
2021-10-18 20:22:31 +00:00
|
|
|
});
|
2009-04-07 20:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
**** Updating a blocklist via RPC
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void Session::blocklist_update()
|
2009-04-07 20:13:08 +00:00
|
|
|
{
|
2021-12-01 23:11:57 +00:00
|
|
|
auto const tag = nextTag;
|
|
|
|
++nextTag;
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2019-03-17 05:00:15 +00:00
|
|
|
tr_variant request;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&request, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&request, TR_KEY_method, "blocklist-update");
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddInt(&request, TR_KEY_tag, tag);
|
2021-10-18 20:22:31 +00:00
|
|
|
impl_->send_rpc_request(
|
2024-01-03 04:14:43 +00:00
|
|
|
request,
|
2021-10-18 20:22:31 +00:00
|
|
|
tag,
|
2022-11-13 20:50:07 +00:00
|
|
|
[this](auto& response)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
tr_variant* args = nullptr;
|
|
|
|
int64_t ruleCount = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-13 20:50:07 +00:00
|
|
|
if (!tr_variantDictFindDict(&response, TR_KEY_arguments, &args) ||
|
2021-10-18 20:22:31 +00:00
|
|
|
!tr_variantDictFindInt(args, TR_KEY_blocklist_size, &ruleCount))
|
|
|
|
{
|
|
|
|
ruleCount = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleCount > 0)
|
|
|
|
{
|
|
|
|
gtr_pref_int_set(TR_KEY_blocklist_date, tr_time());
|
|
|
|
}
|
|
|
|
|
2022-12-17 23:12:25 +00:00
|
|
|
impl_->signal_blocklist_updated().emit(ruleCount >= 0);
|
2021-10-18 20:22:31 +00:00
|
|
|
});
|
2009-04-07 20:13:08 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
void Session::exec(tr_variant const& request)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-12-01 23:11:57 +00:00
|
|
|
auto const tag = nextTag;
|
|
|
|
++nextTag;
|
2019-03-17 05:00:15 +00:00
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
impl_->send_rpc_request(request, tag, {});
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
size_t Session::get_torrent_count() const
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
return impl_->get_raw_model()->get_n_items();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
size_t Session::get_active_torrent_count() const
|
2010-04-29 23:08:11 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return impl_->get_active_torrent_count();
|
2010-04-29 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
size_t Session::Impl::get_active_torrent_count() const
|
2010-04-29 23:08:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t activeCount = 0;
|
2010-04-29 23:08:11 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
for (auto i = 0U, count = raw_model_->get_n_items(); i < count; ++i)
|
2010-04-29 23:08:11 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
if (raw_model_->get_item(i)->get_activity() != TR_STATUS_STOPPED)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
++activeCount;
|
|
|
|
}
|
2010-04-29 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return activeCount;
|
2010-04-29 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
tr_torrent* Session::find_torrent(tr_torrent_id_t id) const
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
tr_torrent* tor = nullptr;
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto* const session = impl_->get_session(); session != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tor = tr_torrentFindFromId(session, id);
|
|
|
|
}
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return tor;
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
FaviconCache<Glib::RefPtr<Gdk::Pixbuf>>& Session::favicon_cache() const
|
|
|
|
{
|
|
|
|
return impl_->favicon_cache();
|
|
|
|
}
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
void Session::open_folder(tr_torrent_id_t torrent_id) const
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* tor = find_torrent(torrent_id);
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (tor != nullptr)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2021-11-28 03:17:47 +00:00
|
|
|
bool const single = tr_torrentFileCount(tor) == 1;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* currentDir = tr_torrentGetCurrentDir(tor);
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (single)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_open_file(currentDir);
|
2012-12-05 17:29:46 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_open_file(Glib::build_filename(currentDir, tr_torrentName(tor)));
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
sigc::signal<void(Session::ErrorCode, Glib::ustring const&)>& Session::signal_add_error()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->signal_add_error();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
sigc::signal<void(tr_ctor*)>& Session::signal_add_prompt()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->signal_add_prompt();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 23:12:25 +00:00
|
|
|
sigc::signal<void(bool)>& Session::signal_blocklist_updated()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->signal_blocklist_updated();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
sigc::signal<void(bool)>& Session::signal_busy()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->signal_busy();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
sigc::signal<void(tr_quark)>& Session::signal_prefs_changed()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->signal_prefs_changed();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
sigc::signal<void(bool)>& Session::signal_port_tested()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
return impl_->signal_port_tested();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2022-12-21 21:26:25 +00:00
|
|
|
|
|
|
|
sigc::signal<void(std::unordered_set<tr_torrent_id_t> const&, Torrent::ChangeFlags)>& Session::signal_torrents_changed()
|
|
|
|
{
|
|
|
|
return impl_->signal_torrents_changed();
|
|
|
|
}
|