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

Last change on this file since 8671 was 8671, checked in by charles, 13 years ago

(trunk gtk) #1963: Use tooltip to notify user of added torrent

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