1 | /****************************************************************************** |
---|
2 | * $Id: tr-core.h 6309 2008-07-09 16:33:00Z 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 <string.h> |
---|
29 | |
---|
30 | #include <glib-object.h> |
---|
31 | #include <gtk/gtk.h> |
---|
32 | |
---|
33 | #include <libtransmission/transmission.h> |
---|
34 | #include "conf.h" /* pref_flag_t */ |
---|
35 | #include "tr-torrent.h" |
---|
36 | |
---|
37 | #define TR_CORE_TYPE (tr_core_get_type()) |
---|
38 | #define TR_CORE(o) G_TYPE_CHECK_INSTANCE_CAST((o),TR_CORE_TYPE,TrCore) |
---|
39 | #define TR_IS_CORE(o) G_TYPE_CHECK_INSTANCE_TYPE((o),TR_CORE_TYPE) |
---|
40 | #define TR_CORE_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k),TR_CORE_TYPE,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),TR_CORE_TYPE,TrCoreClass) |
---|
43 | |
---|
44 | struct core_stats |
---|
45 | { |
---|
46 | int downloadCount; |
---|
47 | int seedingCount; |
---|
48 | float clientDownloadSpeed; |
---|
49 | float clientUploadSpeed; |
---|
50 | }; |
---|
51 | |
---|
52 | typedef struct TrCore |
---|
53 | { |
---|
54 | GObject parent; |
---|
55 | struct TrCorePrivate * priv; |
---|
56 | } |
---|
57 | TrCore; |
---|
58 | |
---|
59 | typedef struct TrCoreClass |
---|
60 | { |
---|
61 | GObjectClass parent; |
---|
62 | |
---|
63 | /* "error" signal: |
---|
64 | void handler( TrCore *, enum tr_core_err, const char *, gpointer ) */ |
---|
65 | int errsig; |
---|
66 | |
---|
67 | /* "add-torrent-prompt" signal: |
---|
68 | void handler( TrCore *, gpointer ctor, gpointer userData ) |
---|
69 | The handler assumes ownership of ctor and must free when done */ |
---|
70 | int promptsig; |
---|
71 | |
---|
72 | /* "quit" signal: |
---|
73 | void handler( TrCore *, gpointer ) */ |
---|
74 | int quitsig; |
---|
75 | |
---|
76 | /* "prefs-changed" signal: |
---|
77 | void handler( TrCore *, int, gpointer ) */ |
---|
78 | int prefsig; |
---|
79 | } |
---|
80 | TrCoreClass; |
---|
81 | |
---|
82 | enum tr_core_err |
---|
83 | { |
---|
84 | TR_CORE_ERR_ADD_TORRENT_ERR = TR_EINVALID, |
---|
85 | TR_CORE_ERR_ADD_TORRENT_DUP = TR_EDUPLICATE, |
---|
86 | TR_CORE_ERR_NO_MORE_TORRENTS, /* finished adding a batch */ |
---|
87 | TR_CORE_ERR_SAVE_STATE /* error saving state */ |
---|
88 | }; |
---|
89 | |
---|
90 | GType tr_core_get_type( void ); |
---|
91 | |
---|
92 | TrCore * tr_core_new( tr_handle * ); |
---|
93 | |
---|
94 | void tr_core_close( TrCore* ); |
---|
95 | |
---|
96 | /* Return the model used without incrementing the reference count */ |
---|
97 | GtkTreeModel * tr_core_model( TrCore * self ); |
---|
98 | |
---|
99 | tr_handle * tr_core_handle( TrCore * self ); |
---|
100 | |
---|
101 | void tr_core_get_stats( const TrCore * core, |
---|
102 | struct core_stats * setme ); |
---|
103 | |
---|
104 | /****** |
---|
105 | ******* |
---|
106 | ******/ |
---|
107 | |
---|
108 | /** |
---|
109 | * Load saved state and return number of torrents added. |
---|
110 | * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT |
---|
111 | */ |
---|
112 | int tr_core_load( TrCore * self, gboolean forcepaused ); |
---|
113 | |
---|
114 | /** |
---|
115 | * Add a list of torrents. |
---|
116 | * This function assumes ownership of torrentFiles |
---|
117 | * |
---|
118 | * May pop up dialogs for each torrent if that preference is enabled. |
---|
119 | * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT |
---|
120 | */ |
---|
121 | void tr_core_add_list( TrCore * self, |
---|
122 | GSList * torrentFiles, |
---|
123 | pref_flag_t start, |
---|
124 | pref_flag_t prompt ); |
---|
125 | |
---|
126 | #define tr_core_add_list_defaults(c,l) \ |
---|
127 | tr_core_add_list(c,l,PREF_FLAG_DEFAULT,PREF_FLAG_DEFAULT) |
---|
128 | |
---|
129 | |
---|
130 | /** Add a torrent. */ |
---|
131 | gboolean tr_core_add_file( TrCore*, const char * filename, gboolean * setme_success, GError ** err ); |
---|
132 | |
---|
133 | /** Add a torrent. */ |
---|
134 | void tr_core_add_torrent( TrCore*, TrTorrent* ); |
---|
135 | |
---|
136 | /** |
---|
137 | * Notifies listeners that torrents have been added. |
---|
138 | * This should be called after one or more tr_core_add*() calls. |
---|
139 | */ |
---|
140 | void tr_core_torrents_added( TrCore * self ); |
---|
141 | |
---|
142 | /****** |
---|
143 | ******* |
---|
144 | ******/ |
---|
145 | |
---|
146 | void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles ); |
---|
147 | |
---|
148 | /* update the model with current torrent status */ |
---|
149 | void tr_core_update( TrCore * self ); |
---|
150 | |
---|
151 | /* emit the "quit" signal */ |
---|
152 | void tr_core_quit( TrCore * self ); |
---|
153 | |
---|
154 | /* Set a preference value, save the prefs file, and emit the |
---|
155 | "prefs-changed" signal */ |
---|
156 | void tr_core_set_pref( TrCore * self, const char * key, const char * val ); |
---|
157 | |
---|
158 | /* Set a boolean preference value, save the prefs file, and emit the |
---|
159 | "prefs-changed" signal */ |
---|
160 | void tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val ); |
---|
161 | |
---|
162 | /* Set an integer preference value, save the prefs file, and emit the |
---|
163 | "prefs-changed" signal */ |
---|
164 | void tr_core_set_pref_int( TrCore * self, const char * key, int val ); |
---|
165 | |
---|
166 | /** |
---|
167 | *** |
---|
168 | **/ |
---|
169 | |
---|
170 | /* column names for the model used to store torrent information */ |
---|
171 | /* keep this in sync with the type array in tr_core_init() in tr_core.c */ |
---|
172 | enum |
---|
173 | { |
---|
174 | MC_NAME, |
---|
175 | MC_NAME_COLLATED, |
---|
176 | MC_TORRENT, |
---|
177 | MC_TORRENT_RAW, |
---|
178 | MC_STATUS, |
---|
179 | MC_ROW_COUNT |
---|
180 | }; |
---|
181 | |
---|
182 | #endif |
---|