1/******************************************************************************
2 * $Id: tr-core.h 12676 2011-08-13 14:19:40Z jordan $
3 *
4 * Copyright (c) Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef GTR_CORE_H
26#define GTR_CORE_H
27
28#include <gtk/gtk.h>
29
30#include <libtransmission/transmission.h>
31#include <libtransmission/bencode.h>
32
33G_BEGIN_DECLS
34
35#define TR_CORE_TYPE (tr_core_get_type ())
36#define TR_CORE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), TR_CORE_TYPE, TrCore))
37
38typedef struct _TrCore
39{
40    GObject parent;
41
42    /*< private >*/
43    struct TrCorePrivate  * priv;
44}
45TrCore;
46
47enum tr_core_err
48{
49    TR_CORE_ERR_ADD_TORRENT_ERR  = TR_PARSE_ERR,
50    TR_CORE_ERR_ADD_TORRENT_DUP  = TR_PARSE_DUPLICATE,
51    TR_CORE_ERR_NO_MORE_TORRENTS = 1000 /* finished adding a batch */
52};
53
54typedef struct _TrCoreClass
55{
56    GObjectClass parent_class;
57
58    void (* add_error)         (TrCore*, enum tr_core_err, const char * name);
59    void (* add_prompt)        (TrCore*, gpointer ctor);
60    void (* blocklist_updated) (TrCore*, int ruleCount );
61    void (* busy)              (TrCore*, gboolean is_busy);
62    void (* prefs_changed)     (TrCore*, const char* key);
63    void (* port_tested)       (TrCore*, gboolean is_open);
64    void (* quit)              (TrCore*);
65}
66TrCoreClass;
67
68GType          tr_core_get_type (void) G_GNUC_CONST;
69
70TrCore *       gtr_core_new( tr_session * );
71
72void           gtr_core_close( TrCore* );
73
74/* Return the model used without incrementing the reference count */
75GtkTreeModel * gtr_core_model( TrCore * self );
76
77void           gtr_core_clear( TrCore * self );
78
79tr_session *   gtr_core_session( TrCore * self );
80
81size_t         gtr_core_get_active_torrent_count( TrCore * self );
82
83size_t         gtr_core_get_torrent_count( TrCore * self );
84
85tr_torrent *   gtr_core_find_torrent( TrCore * core, int id );
86
87void           gtr_core_pref_changed( TrCore * core, const char * key );
88
89
90/******
91*******
92******/
93
94/**
95 * Load saved state and return number of torrents added.
96 * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT
97 */
98void gtr_core_load( TrCore * self, gboolean forcepaused );
99
100/**
101 * Add a list of torrents.
102 * This function assumes ownership of torrentFiles
103 *
104 * May pop up dialogs for each torrent if that preference is enabled.
105 * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT
106 */
107void gtr_core_add_files( TrCore     * core,
108                         GSList     * files,
109                         gboolean     do_start,
110                         gboolean     do_prompt,
111                         gboolean     do_notify );
112
113/** @brief Add a torrent from a URL */
114bool gtr_core_add_from_url( TrCore * core, const char * url );
115
116/** @brief Add a torrent.
117    @param ctor this function assumes ownership of the ctor */
118void gtr_core_add_ctor( TrCore * core, tr_ctor * ctor );
119
120/** Add a torrent. */
121void gtr_core_add_torrent( TrCore*, tr_torrent*, gboolean do_notify );
122
123/**
124 * Notifies listeners that torrents have been added.
125 * This should be called after one or more tr_core_add*() calls.
126 */
127void gtr_core_torrents_added( TrCore * self );
128
129/******
130*******
131******/
132
133/* remove a torrent */
134void gtr_core_remove_torrent( TrCore * self, int id, gboolean delete_files );
135
136/* update the model with current torrent status */
137void gtr_core_update( TrCore * self );
138
139/**
140***  Set a preference value, save the prefs file, and emit the "prefs-changed" signal
141**/
142
143void gtr_core_set_pref       ( TrCore * self, const char * key, const char * val );
144void gtr_core_set_pref_bool  ( TrCore * self, const char * key, gboolean val );
145void gtr_core_set_pref_int   ( TrCore * self, const char * key, int val );
146void gtr_core_set_pref_double( TrCore * self, const char * key, double val );
147
148/**
149***
150**/
151
152void gtr_core_port_test( TrCore * core );
153
154void gtr_core_blocklist_update( TrCore * core );
155
156void gtr_core_exec( TrCore * core, const tr_benc * benc );
157
158void gtr_core_exec_json( TrCore * core, const char * json );
159
160void gtr_core_open_folder( TrCore * core, int torrent_id );
161
162
163/**
164***
165**/
166
167/* column names for the model used to store torrent information */
168/* keep this in sync with the type array in tr_core_init() in tr_core.c */
169enum
170{
171    MC_NAME_COLLATED,
172    MC_TORRENT,
173    MC_TORRENT_ID,
174    MC_SPEED_UP,
175    MC_SPEED_DOWN,
176    MC_RECHECK_PROGRESS,
177    MC_ACTIVE,
178    MC_ACTIVITY,
179    MC_FINISHED,
180    MC_PRIORITY,
181    MC_QUEUE_POSITION,
182    MC_TRACKERS,
183
184    /* tr_stat.error
185     * Tracked because ACTIVITY_FILTER_ERROR needs the row-changed events */
186    MC_ERROR,
187
188    /* tr_stat.{ peersSendingToUs + peersGettingFromUs + webseedsSendingToUs }
189     * Tracked because ACTIVITY_FILTER_ACTIVE needs the row-changed events */
190    MC_ACTIVE_PEER_COUNT,
191
192    MC_ROW_COUNT
193};
194
195G_END_DECLS
196
197
198#endif /* GTR_CORE_H */
199