source: trunk/gtk/tr-core.h @ 10031

Last change on this file since 10031 was 10031, checked in by charles, 12 years ago

(trunk) remove unnecessary #includes

  • Property svn:keywords set to Date Rev Author Id
File size: 6.7 KB
Line 
1/******************************************************************************
2 * $Id: tr-core.h 10031 2010-01-28 13:33:40Z 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
46typedef struct TrCore
47{
48    GObject    parent;
49    struct TrCorePrivate  * priv;
50}
51TrCore;
52
53typedef struct TrCoreClass
54{
55    GObjectClass    parent;
56
57    /* "blocklist-updated" signal with a callback type of
58        void (*callback )( TrCore*, int ruleCount, gpointer userData ). */
59    int blocklistSignal;
60
61    /* "port-tested" signal with a callback type of
62       void( *callback )( TrCore*, gboolean isOpen, gpointer userData ). */
63    int portSignal;
64
65    /* "error" signal with a callback type of
66       void( *callback )( TrCore*, enum tr_core_err, const char * humanReadable, gpointer userData ). */
67    int errsig;
68
69    /* "add-torrent-prompt" signal with a callback type of
70       void ( *callback)( TrCore *, gpointer ctor, gpointer userData )
71       The handler assumes ownership of ctor and must free when done */
72    int promptsig;
73
74    /* "quit" signal:
75       void handler( TrCore *, gpointer ) */
76    int quitsig;
77
78    /* "prefs-changed" signal:
79       void handler( TrCore *, int, gpointer ) */
80    int prefsig;
81}
82TrCoreClass;
83
84enum tr_core_err
85{
86    TR_CORE_ERR_ADD_TORRENT_ERR  = TR_PARSE_ERR,
87    TR_CORE_ERR_ADD_TORRENT_DUP  = TR_PARSE_DUPLICATE,
88    TR_CORE_ERR_NO_MORE_TORRENTS = 1000 /* finished adding a batch */
89};
90
91GType          tr_core_get_type( void );
92
93TrCore *       tr_core_new( tr_session * );
94
95void           tr_core_close( TrCore* );
96
97/* Return the model used without incrementing the reference count */
98GtkTreeModel * tr_core_model( TrCore * self );
99
100tr_session *   tr_core_session( TrCore * self );
101
102/******
103*******
104******/
105
106/**
107 * Load saved state and return number of torrents added.
108 * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT
109 */
110int      tr_core_load( TrCore * self,
111                       gboolean forcepaused );
112
113/**
114 * Add a list of torrents.
115 * This function assumes ownership of torrentFiles
116 *
117 * May pop up dialogs for each torrent if that preference is enabled.
118 * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT
119 */
120void     tr_core_add_list( TrCore *    self,
121                           GSList *    torrentFiles,
122                           pref_flag_t start,
123                           pref_flag_t prompt,
124                           gboolean    doNotify );
125
126#define tr_core_add_list_defaults( c, l, doNotify ) \
127    tr_core_add_list( c, l, PREF_FLAG_DEFAULT, PREF_FLAG_DEFAULT, doNotify )
128
129
130/** @brief Add a torrent. */
131gboolean tr_core_add_metainfo( TrCore      * core,
132                               const char  * base64_metainfo,
133                               gboolean    * setme_success,
134                               GError     ** err );
135
136/** @brief Add a torrent from a URL */
137void tr_core_add_from_url( TrCore * core, const char * url );
138
139/** @brief Add a torrent.
140    @param ctor this function assumes ownership of the ctor */
141void tr_core_add_ctor( TrCore  * core,
142                       tr_ctor * ctor );
143
144
145/** Add a torrent. */
146void tr_core_add_torrent( TrCore*, TrTorrent*, gboolean doNotify );
147
148/** Present the main window */
149gboolean tr_core_present_window( TrCore*, gboolean * setme_success, GError ** err );
150
151
152/**
153 * Notifies listeners that torrents have been added.
154 * This should be called after one or more tr_core_add*() calls.
155 */
156void     tr_core_torrents_added( TrCore * self );
157
158/******
159*******
160******/
161
162/* we've gotten notice from RPC that a torrent has been destroyed;
163   update our gui accordingly */
164void  tr_core_torrent_destroyed( TrCore * self, int torrentId );
165
166/* remove a torrent */
167void  tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles );
168
169/* update the model with current torrent status */
170void  tr_core_update( TrCore * self );
171
172/* emit the "quit" signal */
173void  tr_core_quit( TrCore * self );
174
175/**
176***  Set a preference value, save the prefs file, and emit the "prefs-changed" signal
177**/
178
179void tr_core_set_pref     ( TrCore * self, const char * key, const char * val );
180void tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val );
181void tr_core_set_pref_int ( TrCore * self, const char * key, int val );
182void tr_core_set_pref_double( TrCore * self, const char * key, double val );
183
184/**
185***
186**/
187
188void tr_core_port_test( TrCore * core );
189
190void tr_core_blocklist_update( TrCore * core );
191
192void tr_core_exec( TrCore * core, const tr_benc * benc );
193
194void tr_core_exec_json( TrCore * core, const char * json );
195
196
197/**
198***
199**/
200
201/* column names for the model used to store torrent information */
202/* keep this in sync with the type array in tr_core_init() in tr_core.c */
203enum
204{
205    MC_NAME,
206    MC_NAME_COLLATED,
207    MC_TORRENT,
208    MC_TORRENT_RAW,
209    MC_SPEED_UP,
210    MC_SPEED_DOWN,
211    MC_ACTIVITY,
212    MC_ROW_COUNT
213};
214
215#endif
Note: See TracBrowser for help on using the repository browser.