1 | /****************************************************************************** |
---|
2 | * $Id: tr-core.h 11552 2010-12-20 12:26:18Z charles $ |
---|
3 | * |
---|
4 | * Copyright (c) 2007-2008 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 TR_CORE_H |
---|
26 | #define TR_CORE_H |
---|
27 | |
---|
28 | #include <glib-object.h> |
---|
29 | #include <gtk/gtk.h> |
---|
30 | |
---|
31 | #include <libtransmission/transmission.h> |
---|
32 | #include "conf.h" /* pref_flag_t */ |
---|
33 | #include "tr-torrent.h" |
---|
34 | |
---|
35 | #define TR_CORE_TYPE ( tr_core_get_type( ) ) |
---|
36 | #define TR_CORE( o ) G_TYPE_CHECK_INSTANCE_CAST( ( o ), TR_CORE_TYPE,\ |
---|
37 | TrCore ) |
---|
38 | #define TR_IS_CORE( o ) G_TYPE_CHECK_INSTANCE_TYPE( ( o ), TR_CORE_TYPE ) |
---|
39 | #define TR_CORE_CLASS( k ) G_TYPE_CHECK_CLASS_CAST( ( k ), TR_CORE_TYPE,\ |
---|
40 | TrCoreClass ) |
---|
41 | #define TR_IS_CORE_CLASS( k ) G_TYPE_CHECK_CLASS_TYPE( ( k ), TR_CORE_TYPE ) |
---|
42 | #define TR_CORE_GET_CLASS( o ) G_TYPE_INSTANCE_GET_CLASS( ( o ),\ |
---|
43 | TR_CORE_TYPE, \ |
---|
44 | TrCoreClass ) |
---|
45 | |
---|
46 | typedef struct _TrCore |
---|
47 | { |
---|
48 | GObject parent; |
---|
49 | |
---|
50 | struct TrCorePrivate * priv; |
---|
51 | } |
---|
52 | TrCore; |
---|
53 | |
---|
54 | enum tr_core_err |
---|
55 | { |
---|
56 | TR_CORE_ERR_ADD_TORRENT_ERR = TR_PARSE_ERR, |
---|
57 | TR_CORE_ERR_ADD_TORRENT_DUP = TR_PARSE_DUPLICATE, |
---|
58 | TR_CORE_ERR_NO_MORE_TORRENTS = 1000 /* finished adding a batch */ |
---|
59 | }; |
---|
60 | |
---|
61 | typedef struct _TrCoreClass |
---|
62 | { |
---|
63 | GObjectClass parent_class; |
---|
64 | |
---|
65 | void (* add_error) (TrCore*, enum tr_core_err, const char * name); |
---|
66 | void (* add_prompt) (TrCore*, gpointer ctor); |
---|
67 | void (* blocklist_updated) (TrCore*, int ruleCount ); |
---|
68 | void (* busy) (TrCore*, gboolean isBusy); |
---|
69 | void (* prefs_changed) (TrCore*, const char* key); |
---|
70 | void (* port_tested) (TrCore*, gboolean isOpen); |
---|
71 | void (* quit) (TrCore*); |
---|
72 | } |
---|
73 | TrCoreClass; |
---|
74 | |
---|
75 | GType tr_core_get_type( void ); |
---|
76 | |
---|
77 | TrCore * tr_core_new( tr_session * ); |
---|
78 | |
---|
79 | void tr_core_close( TrCore* ); |
---|
80 | |
---|
81 | /* Return the model used without incrementing the reference count */ |
---|
82 | GtkTreeModel * tr_core_model( TrCore * self ); |
---|
83 | |
---|
84 | tr_session * tr_core_session( TrCore * self ); |
---|
85 | |
---|
86 | size_t tr_core_get_active_torrent_count( TrCore * self ); |
---|
87 | |
---|
88 | size_t tr_core_get_torrent_count( TrCore * self ); |
---|
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 | */ |
---|
98 | int tr_core_load( TrCore * self, |
---|
99 | 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 tr_core_add_list( TrCore * self, |
---|
109 | GSList * torrentFiles, |
---|
110 | pref_flag_t start, |
---|
111 | pref_flag_t prompt, |
---|
112 | gboolean doNotify ); |
---|
113 | |
---|
114 | #define tr_core_add_list_defaults( c, l, doNotify ) \ |
---|
115 | tr_core_add_list( c, l, PREF_FLAG_DEFAULT, PREF_FLAG_DEFAULT, doNotify ) |
---|
116 | |
---|
117 | |
---|
118 | /** @brief Add a torrent. */ |
---|
119 | gboolean tr_core_add_metainfo( TrCore * core, |
---|
120 | const char * base64_metainfo, |
---|
121 | gboolean * setme_success, |
---|
122 | GError ** err ); |
---|
123 | |
---|
124 | /** @brief Add a torrent from a URL */ |
---|
125 | void tr_core_add_from_url( TrCore * core, const char * url ); |
---|
126 | |
---|
127 | /** @brief Add a torrent. |
---|
128 | @param ctor this function assumes ownership of the ctor */ |
---|
129 | void tr_core_add_ctor( TrCore * core, |
---|
130 | tr_ctor * ctor ); |
---|
131 | |
---|
132 | |
---|
133 | /** Add a torrent. */ |
---|
134 | void tr_core_add_torrent( TrCore*, TrTorrent*, gboolean doNotify ); |
---|
135 | |
---|
136 | /** Present the main window */ |
---|
137 | gboolean tr_core_present_window( TrCore*, gboolean * setme_success, GError ** err ); |
---|
138 | |
---|
139 | |
---|
140 | /** |
---|
141 | * Notifies listeners that torrents have been added. |
---|
142 | * This should be called after one or more tr_core_add*() calls. |
---|
143 | */ |
---|
144 | void tr_core_torrents_added( TrCore * self ); |
---|
145 | |
---|
146 | /****** |
---|
147 | ******* |
---|
148 | ******/ |
---|
149 | |
---|
150 | /* remove a torrent */ |
---|
151 | void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, gboolean deleteFiles ); |
---|
152 | void tr_core_remove_torrent_from_id( TrCore * self, int id, gboolean deleteFiles ); |
---|
153 | |
---|
154 | /* update the model with current torrent status */ |
---|
155 | void tr_core_update( TrCore * self ); |
---|
156 | |
---|
157 | /* emit the "quit" signal */ |
---|
158 | void tr_core_quit( TrCore * self ); |
---|
159 | |
---|
160 | /** |
---|
161 | *** Set a preference value, save the prefs file, and emit the "prefs-changed" signal |
---|
162 | **/ |
---|
163 | |
---|
164 | void tr_core_set_pref ( TrCore * self, const char * key, const char * val ); |
---|
165 | void tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val ); |
---|
166 | void tr_core_set_pref_int ( TrCore * self, const char * key, int val ); |
---|
167 | void tr_core_set_pref_double( TrCore * self, const char * key, double val ); |
---|
168 | |
---|
169 | /** |
---|
170 | *** |
---|
171 | **/ |
---|
172 | |
---|
173 | void tr_core_torrent_changed( TrCore * core, int id ); |
---|
174 | |
---|
175 | void tr_core_port_test( TrCore * core ); |
---|
176 | |
---|
177 | void tr_core_blocklist_update( TrCore * core ); |
---|
178 | |
---|
179 | void tr_core_exec( TrCore * core, const tr_benc * benc ); |
---|
180 | |
---|
181 | void tr_core_exec_json( TrCore * core, const char * json ); |
---|
182 | |
---|
183 | |
---|
184 | /** |
---|
185 | *** |
---|
186 | **/ |
---|
187 | |
---|
188 | /* column names for the model used to store torrent information */ |
---|
189 | /* keep this in sync with the type array in tr_core_init() in tr_core.c */ |
---|
190 | enum |
---|
191 | { |
---|
192 | MC_NAME, |
---|
193 | MC_NAME_COLLATED, |
---|
194 | MC_TORRENT, |
---|
195 | MC_TORRENT_RAW, |
---|
196 | MC_SPEED_UP, |
---|
197 | MC_SPEED_DOWN, |
---|
198 | MC_ACTIVE, |
---|
199 | MC_ACTIVITY, |
---|
200 | MC_FINISHED, |
---|
201 | MC_PRIORITY, |
---|
202 | MC_TRACKERS, |
---|
203 | MC_ROW_COUNT |
---|
204 | }; |
---|
205 | |
---|
206 | #endif |
---|