// Copyright © Transmission authors and contributors. // This file is licensed under the MIT (SPDX: MIT) license, // A copy of this license can be found in licenses/ . #pragma once #include #include #include #include #include #include #include #include #include #include class Session : public Glib::Object { public: enum ErrorCode { ERR_ADD_TORRENT_ERR = TR_PARSE_ERR, ERR_ADD_TORRENT_DUP = TR_PARSE_DUPLICATE, ERR_NO_MORE_TORRENTS = 1000 /* finished adding a batch */ }; public: ~Session() override; TR_DISABLE_COPY_MOVE(Session) static Glib::RefPtr create(tr_session* session); tr_session* close(); /* Return the model used without incrementing the reference count */ Glib::RefPtr get_model() const; void clear(); tr_session* get_session() const; size_t get_active_torrent_count() const; size_t get_torrent_count() const; tr_torrent* find_torrent(tr_torrent_id_t id) const; /****** ******* ******/ /** * Load saved state and return number of torrents added. * May trigger one or more "error" signals with ERR_ADD_TORRENT */ void load(bool forcepaused); /** * Add a list of torrents. * This function assumes ownership of torrentFiles * * May pop up dialogs for each torrent if that preference is enabled. * May trigger one or more "error" signals with ERR_ADD_TORRENT */ void add_files(std::vector> const& files, bool do_start, bool do_prompt, bool do_notify); /** @brief Add a torrent from a URL */ bool add_from_url(Glib::ustring const& url); /** @brief Add a torrent. @param ctor this function assumes ownership of the ctor */ void add_ctor(tr_ctor* ctor); /** Add a torrent. */ void add_torrent(tr_torrent*, bool do_notify); /** * Notifies listeners that torrents have been added. * This should be called after one or more tr_core_add* () calls. */ void torrents_added(); void torrent_changed(tr_torrent_id_t id); /****** ******* ******/ /* remove a torrent */ void remove_torrent(tr_torrent_id_t id, bool delete_files); /* update the model with current torrent status */ void update(); /** * Attempts to start a torrent immediately. */ void start_now(tr_torrent_id_t id); /** *** Set a preference value, save the prefs file, and emit the "prefs-changed" signal **/ void set_pref(tr_quark key, std::string const& val); void set_pref(tr_quark key, bool val); void set_pref(tr_quark key, int val); void set_pref(tr_quark key, double val); /** *** **/ void port_test(); void blocklist_update(); void exec(tr_variant const* benc); void open_folder(tr_torrent_id_t torrent_id); sigc::signal& signal_add_error(); sigc::signal& signal_add_prompt(); sigc::signal& signal_blocklist_updated(); sigc::signal& signal_busy(); sigc::signal& signal_prefs_changed(); sigc::signal& signal_port_tested(); protected: explicit Session(tr_session* session); private: class Impl; std::unique_ptr const impl_; }; /** *** **/ class TorrentModelColumns : public Gtk::TreeModelColumnRecord { public: TorrentModelColumns(); Gtk::TreeModelColumn name_collated; Gtk::TreeModelColumn torrent; Gtk::TreeModelColumn torrent_id; Gtk::TreeModelColumn speed_up; Gtk::TreeModelColumn speed_down; Gtk::TreeModelColumn active_peers_up; Gtk::TreeModelColumn active_peers_down; Gtk::TreeModelColumn recheck_progress; Gtk::TreeModelColumn active; Gtk::TreeModelColumn activity; Gtk::TreeModelColumn finished; Gtk::TreeModelColumn priority; Gtk::TreeModelColumn queue_position; Gtk::TreeModelColumn trackers; /* tr_stat.error * Tracked because ACTIVITY_FILTER_ERROR needs the row-changed events */ Gtk::TreeModelColumn error; /* tr_stat.{ peersSendingToUs + peersGettingFromUs + webseedsSendingToUs } * Tracked because ACTIVITY_FILTER_ACTIVE needs the row-changed events */ Gtk::TreeModelColumn active_peer_count; }; extern TorrentModelColumns const torrent_cols;