1 | /****************************************************************************** |
---|
2 | * $Id: tr-core.h 14724 2016-03-29 16:37:21Z mikedld $ |
---|
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 | #pragma once |
---|
26 | |
---|
27 | #include <gtk/gtk.h> |
---|
28 | |
---|
29 | #include <libtransmission/transmission.h> |
---|
30 | #include <libtransmission/variant.h> |
---|
31 | |
---|
32 | G_BEGIN_DECLS |
---|
33 | |
---|
34 | #define TR_CORE_TYPE (tr_core_get_type ()) |
---|
35 | #define TR_CORE(o)(G_TYPE_CHECK_INSTANCE_CAST ((o), TR_CORE_TYPE, TrCore)) |
---|
36 | |
---|
37 | #define TR_RESOURCE_PATH "/com/transmissionbt/transmission/" |
---|
38 | |
---|
39 | typedef struct _TrCore |
---|
40 | { |
---|
41 | GObject parent; |
---|
42 | |
---|
43 | /*< private >*/ |
---|
44 | struct TrCorePrivate * priv; |
---|
45 | } |
---|
46 | TrCore; |
---|
47 | |
---|
48 | enum tr_core_err |
---|
49 | { |
---|
50 | TR_CORE_ERR_ADD_TORRENT_ERR = TR_PARSE_ERR, |
---|
51 | TR_CORE_ERR_ADD_TORRENT_DUP = TR_PARSE_DUPLICATE, |
---|
52 | TR_CORE_ERR_NO_MORE_TORRENTS = 1000 /* finished adding a batch */ |
---|
53 | }; |
---|
54 | |
---|
55 | typedef struct _TrCoreClass |
---|
56 | { |
---|
57 | GObjectClass parent_class; |
---|
58 | |
---|
59 | void (* add_error) (TrCore*, enum tr_core_err, const char * name); |
---|
60 | void (* add_prompt) (TrCore*, gpointer ctor); |
---|
61 | void (* blocklist_updated)(TrCore*, int ruleCount); |
---|
62 | void (* busy) (TrCore*, gboolean is_busy); |
---|
63 | void (* prefs_changed) (TrCore*, const tr_quark key); |
---|
64 | void (* port_tested) (TrCore*, gboolean is_open); |
---|
65 | void (* quit) (TrCore*); |
---|
66 | } |
---|
67 | TrCoreClass; |
---|
68 | |
---|
69 | GType tr_core_get_type (void) G_GNUC_CONST; |
---|
70 | |
---|
71 | TrCore * gtr_core_new (tr_session *); |
---|
72 | |
---|
73 | tr_session * gtr_core_close (TrCore*); |
---|
74 | |
---|
75 | /* Return the model used without incrementing the reference count */ |
---|
76 | GtkTreeModel * gtr_core_model (TrCore * self); |
---|
77 | |
---|
78 | void gtr_core_clear (TrCore * self); |
---|
79 | |
---|
80 | tr_session * gtr_core_session (TrCore * self); |
---|
81 | |
---|
82 | size_t gtr_core_get_active_torrent_count (TrCore * self); |
---|
83 | |
---|
84 | size_t gtr_core_get_torrent_count (TrCore * self); |
---|
85 | |
---|
86 | tr_torrent * gtr_core_find_torrent (TrCore * core, int id); |
---|
87 | |
---|
88 | void gtr_core_pref_changed (TrCore * core, const tr_quark key); |
---|
89 | |
---|
90 | |
---|
91 | /****** |
---|
92 | ******* |
---|
93 | ******/ |
---|
94 | |
---|
95 | /** |
---|
96 | * Load saved state and return number of torrents added. |
---|
97 | * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT |
---|
98 | */ |
---|
99 | void gtr_core_load (TrCore * self, gboolean forcepaused); |
---|
100 | |
---|
101 | /** |
---|
102 | * Add a list of torrents. |
---|
103 | * This function assumes ownership of torrentFiles |
---|
104 | * |
---|
105 | * May pop up dialogs for each torrent if that preference is enabled. |
---|
106 | * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT |
---|
107 | */ |
---|
108 | void gtr_core_add_files (TrCore * core, |
---|
109 | GSList * files, |
---|
110 | gboolean do_start, |
---|
111 | gboolean do_prompt, |
---|
112 | gboolean do_notify); |
---|
113 | |
---|
114 | /** @brief Add a torrent from a URL */ |
---|
115 | bool gtr_core_add_from_url (TrCore * core, const char * url); |
---|
116 | |
---|
117 | /** @brief Add a torrent. |
---|
118 | @param ctor this function assumes ownership of the ctor */ |
---|
119 | void gtr_core_add_ctor (TrCore * core, tr_ctor * ctor); |
---|
120 | |
---|
121 | /** Add a torrent. */ |
---|
122 | void gtr_core_add_torrent (TrCore*, tr_torrent*, gboolean do_notify); |
---|
123 | |
---|
124 | /** |
---|
125 | * Notifies listeners that torrents have been added. |
---|
126 | * This should be called after one or more tr_core_add* () calls. |
---|
127 | */ |
---|
128 | void gtr_core_torrents_added (TrCore * self); |
---|
129 | |
---|
130 | /****** |
---|
131 | ******* |
---|
132 | ******/ |
---|
133 | |
---|
134 | /* remove a torrent */ |
---|
135 | void gtr_core_remove_torrent (TrCore * self, int id, gboolean delete_files); |
---|
136 | |
---|
137 | /* update the model with current torrent status */ |
---|
138 | void gtr_core_update (TrCore * self); |
---|
139 | |
---|
140 | /** |
---|
141 | *** Set a preference value, save the prefs file, and emit the "prefs-changed" signal |
---|
142 | **/ |
---|
143 | |
---|
144 | void gtr_core_set_pref (TrCore * self, const tr_quark key, const char * val); |
---|
145 | void gtr_core_set_pref_bool (TrCore * self, const tr_quark key, gboolean val); |
---|
146 | void gtr_core_set_pref_int (TrCore * self, const tr_quark key, int val); |
---|
147 | void gtr_core_set_pref_double (TrCore * self, const tr_quark key, double val); |
---|
148 | |
---|
149 | /** |
---|
150 | *** |
---|
151 | **/ |
---|
152 | |
---|
153 | void gtr_core_port_test (TrCore * core); |
---|
154 | |
---|
155 | void gtr_core_blocklist_update (TrCore * core); |
---|
156 | |
---|
157 | void gtr_core_exec (TrCore * core, const tr_variant * benc); |
---|
158 | |
---|
159 | void gtr_core_open_folder (TrCore * core, int torrent_id); |
---|
160 | |
---|
161 | |
---|
162 | /** |
---|
163 | *** |
---|
164 | **/ |
---|
165 | |
---|
166 | /* column names for the model used to store torrent information */ |
---|
167 | /* keep this in sync with the type array in tr_core_init () in tr_core.c */ |
---|
168 | enum |
---|
169 | { |
---|
170 | MC_NAME_COLLATED, |
---|
171 | MC_TORRENT, |
---|
172 | MC_TORRENT_ID, |
---|
173 | MC_SPEED_UP, |
---|
174 | MC_SPEED_DOWN, |
---|
175 | MC_ACTIVE_PEERS_UP, |
---|
176 | MC_ACTIVE_PEERS_DOWN, |
---|
177 | MC_RECHECK_PROGRESS, |
---|
178 | MC_ACTIVE, |
---|
179 | MC_ACTIVITY, |
---|
180 | MC_FINISHED, |
---|
181 | MC_PRIORITY, |
---|
182 | MC_QUEUE_POSITION, |
---|
183 | MC_TRACKERS, |
---|
184 | |
---|
185 | /* tr_stat.error |
---|
186 | * Tracked because ACTIVITY_FILTER_ERROR needs the row-changed events */ |
---|
187 | MC_ERROR, |
---|
188 | |
---|
189 | /* tr_stat.{ peersSendingToUs + peersGettingFromUs + webseedsSendingToUs } |
---|
190 | * Tracked because ACTIVITY_FILTER_ACTIVE needs the row-changed events */ |
---|
191 | MC_ACTIVE_PEER_COUNT, |
---|
192 | |
---|
193 | MC_ROW_COUNT |
---|
194 | }; |
---|
195 | |
---|
196 | G_END_DECLS |
---|
197 | |
---|