2007-05-23 00:49:31 +00:00
|
|
|
/******************************************************************************
|
2011-01-19 13:48:47 +00:00
|
|
|
* Copyright (c) Transmission authors and contributors
|
2007-05-23 00:49:31 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <giomm.h>
|
|
|
|
#include <glibmm.h>
|
|
|
|
#include <gtkmm.h>
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2021-12-14 08:43:27 +00:00
|
|
|
#include <libtransmission/tr-macros.h>
|
2012-12-14 04:34:42 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
class Session : public Glib::Object
|
2007-05-23 00:49:31 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
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 */
|
|
|
|
};
|
2010-06-26 15:55:19 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2021-11-01 00:11:23 +00:00
|
|
|
~Session() override;
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Session)
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
static Glib::RefPtr<Session> create(tr_session* session);
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_session* close();
|
2010-06-26 15:55:19 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/* Return the model used without incrementing the reference count */
|
|
|
|
Glib::RefPtr<Gtk::TreeModel> get_model() const;
|
2010-06-26 15:55:19 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void clear();
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_session* get_session() const;
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
size_t get_active_torrent_count() const;
|
2008-04-17 20:35:18 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
size_t get_torrent_count() const;
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent* find_torrent(int id) const;
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/******
|
|
|
|
*******
|
|
|
|
******/
|
2011-02-01 01:45:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/**
|
|
|
|
* Load saved state and return number of torrents added.
|
|
|
|
* May trigger one or more "error" signals with ERR_ADD_TORRENT
|
|
|
|
*/
|
|
|
|
void load(bool forcepaused);
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/**
|
|
|
|
* 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<Glib::RefPtr<Gio::File>> const& files, bool do_start, bool do_prompt, bool do_notify);
|
2010-04-29 23:08:11 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/** @brief Add a torrent from a URL */
|
|
|
|
bool add_from_url(Glib::ustring const& url);
|
2010-04-29 23:08:11 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/** @brief Add a torrent.
|
|
|
|
@param ctor this function assumes ownership of the ctor */
|
|
|
|
void add_ctor(tr_ctor* ctor);
|
2011-03-04 05:58:32 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/** Add a torrent. */
|
|
|
|
void add_torrent(tr_torrent*, bool do_notify);
|
2009-06-11 14:51:21 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/**
|
|
|
|
* Notifies listeners that torrents have been added.
|
|
|
|
* This should be called after one or more tr_core_add* () calls.
|
|
|
|
*/
|
|
|
|
void torrents_added();
|
2009-11-22 16:20:22 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void torrent_changed(int id);
|
2009-09-17 01:28:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/******
|
|
|
|
*******
|
|
|
|
******/
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/* remove a torrent */
|
|
|
|
void remove_torrent(int id, bool delete_files);
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/* update the model with current torrent status */
|
|
|
|
void update();
|
2017-02-21 20:18:52 +00:00
|
|
|
|
2021-11-08 17:21:20 +00:00
|
|
|
/**
|
|
|
|
* Attempts to start a torrent immediately.
|
|
|
|
*/
|
|
|
|
void start_now(int id);
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/**
|
|
|
|
*** Set a preference value, save the prefs file, and emit the "prefs-changed" signal
|
|
|
|
**/
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
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);
|
2008-02-19 03:57:03 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-05-23 02:45:28 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void port_test();
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void blocklist_update();
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void exec(tr_variant const* benc);
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void open_folder(int torrent_id);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
sigc::signal<void(ErrorCode, Glib::ustring const&)>& signal_add_error();
|
|
|
|
sigc::signal<void(tr_ctor*)>& signal_add_prompt();
|
|
|
|
sigc::signal<void(int)>& signal_blocklist_updated();
|
|
|
|
sigc::signal<void(bool)>& signal_busy();
|
|
|
|
sigc::signal<void(tr_quark)>& signal_prefs_changed();
|
|
|
|
sigc::signal<void(bool)>& signal_port_tested();
|
2009-04-07 20:13:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
protected:
|
2021-12-14 08:43:27 +00:00
|
|
|
explicit Session(tr_session* session);
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
private:
|
|
|
|
class Impl;
|
|
|
|
std::unique_ptr<Impl> const impl_;
|
|
|
|
};
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-05-24 13:55:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class TorrentModelColumns : public Gtk::TreeModelColumnRecord
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
|
|
|
TorrentModelColumns();
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> name_collated;
|
2021-12-14 08:43:27 +00:00
|
|
|
Gtk::TreeModelColumn<gpointer> torrent;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<int> torrent_id;
|
|
|
|
Gtk::TreeModelColumn<double> speed_up;
|
|
|
|
Gtk::TreeModelColumn<double> speed_down;
|
|
|
|
Gtk::TreeModelColumn<int> active_peers_up;
|
|
|
|
Gtk::TreeModelColumn<int> active_peers_down;
|
|
|
|
Gtk::TreeModelColumn<double> recheck_progress;
|
|
|
|
Gtk::TreeModelColumn<bool> active;
|
|
|
|
Gtk::TreeModelColumn<tr_torrent_activity> activity;
|
|
|
|
Gtk::TreeModelColumn<bool> finished;
|
|
|
|
Gtk::TreeModelColumn<tr_priority_t> priority;
|
|
|
|
Gtk::TreeModelColumn<int> queue_position;
|
|
|
|
Gtk::TreeModelColumn<unsigned int> trackers;
|
2011-01-21 17:07:23 +00:00
|
|
|
/* tr_stat.error
|
|
|
|
* Tracked because ACTIVITY_FILTER_ERROR needs the row-changed events */
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<int> error;
|
2011-01-21 17:07:23 +00:00
|
|
|
/* tr_stat.{ peersSendingToUs + peersGettingFromUs + webseedsSendingToUs }
|
|
|
|
* Tracked because ACTIVITY_FILTER_ACTIVE needs the row-changed events */
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<int> active_peer_count;
|
2007-05-23 00:49:31 +00:00
|
|
|
};
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
extern TorrentModelColumns const torrent_cols;
|