source: trunk/gtk/tr_core.h @ 4998

Last change on this file since 4998 was 4998, checked in by charles, 14 years ago

(gtk) make TrCore?'s fields private

  • Property svn:keywords set to Date Rev Author Id
File size: 6.1 KB
Line 
1/******************************************************************************
2 * $Id: tr_core.h 4998 2008-02-09 17:29:05Z 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/bencode.h>
34#include <libtransmission/transmission.h>
35
36#include "util.h"
37
38#define TR_CORE_TYPE            ( tr_core_get_type() )
39
40#define TR_CORE( obj )                                                        \
41  ( G_TYPE_CHECK_INSTANCE_CAST( (obj),   TR_CORE_TYPE, TrCore ) )
42
43#define TR_CORE_CLASS( class )                                                \
44  ( G_TYPE_CHECK_CLASS_CAST(    (class), TR_CORE_TYPE, TrCoreClass ) )
45
46#define TR_IS_CORE( obj )                                                     \
47  ( G_TYPE_CHECK_INSTANCE_TYPE( (obj),   TR_CORE_TYPE ) )
48
49#define TR_IS_CORE_CLASS( class )                                             \
50  ( G_TYPE_CHECK_CLASS_TYPE(    (class), TR_CORE_TYPE ) )
51
52#define TR_CORE_GET_CLASS( obj )                                              \
53  ( G_TYPE_INSTANCE_GET_CLASS(  (obj),   TR_CORE_TYPE, TrCoreClass ) )
54
55
56struct core_stats
57{
58    int downloadCount;
59    int seedingCount;
60    float clientDownloadSpeed;
61    float clientUploadSpeed;
62};
63
64/* treat the contents of this structure as private */
65typedef struct TrCore
66{
67    GObject                 parent;
68    struct TrCorePrivate  * priv;
69}
70TrCore;
71
72typedef struct TrCoreClass
73{
74    GObjectClass parent;
75
76    /* "error" signal:
77       void handler( TrCore *, enum tr_core_err, const char *, gpointer ) */
78    int errsig;
79
80    /* "directory-prompt" signal:
81       void handler( TrCore *, GList *, enum tr_torrent_action, gboolean, gpointer ) */
82    int promptsig;
83
84    /* "directory-prompt-data" signal:
85       void handler( TrCore *, uint8_t *, size_t, gboolean, gpointer ) */
86    int promptdatasig;
87
88    /* "quit" signal:
89       void handler( TrCore *, gpointer ) */
90    int quitsig;
91
92    /* "prefs-changed" signal:
93       void handler( TrCore *, int, gpointer ) */
94    int prefsig;
95}
96TrCoreClass;
97
98enum tr_core_err
99{
100    TR_CORE_ERR_ADD_TORRENT,    /* adding a torrent failed */
101    /* no more torrents to be added, used for grouping torrent add errors */
102    TR_CORE_ERR_NO_MORE_TORRENTS,
103    TR_CORE_ERR_SAVE_STATE      /* error saving state */
104};
105
106GType
107tr_core_get_type( void );
108
109TrCore *
110tr_core_new( void );
111
112/* Return the model used without incrementing the reference count */
113GtkTreeModel *
114tr_core_model( TrCore * self );
115
116/* Returns the libtransmission handle */
117tr_handle *
118tr_core_handle( TrCore * self );
119
120const struct core_stats*
121tr_core_get_stats( const TrCore * self );
122
123/* Load saved state, return number of torrents added. May trigger one
124   or more "error" signals with TR_CORE_ERR_ADD_TORRENT */
125int
126tr_core_load( TrCore * self, gboolean forcepaused );
127
128/* Any the tr_core_add functions below may trigger an "error" signal
129   with TR_CORE_ERR_ADD_TORRENT */
130
131/* Add the torrent at the given path */
132gboolean
133tr_core_add( TrCore * self, const char * path, enum tr_torrent_action act,
134             gboolean paused );
135
136/* Add the torrent at the given path with the given download directory */
137gboolean
138tr_core_add_dir( TrCore * self, const char * path, const char * dir,
139                 enum tr_torrent_action act, gboolean paused );
140
141/* Add a list of torrents with the given paths */
142int
143tr_core_add_list( TrCore * self, GList * paths, enum tr_torrent_action act,
144                  gboolean paused );
145
146/* Add the torrent data in the given buffer */
147gboolean
148tr_core_add_data( TrCore * self, uint8_t * data, size_t size, gboolean paused );
149
150/* Add the torrent data in the given buffer with the given download directory */
151gboolean
152tr_core_add_data_dir( TrCore * self, uint8_t * data, size_t size,
153                      const char * dir, gboolean paused );
154
155/* Save state, update model, and signal the end of a torrent cluster */
156void
157tr_core_torrents_added( TrCore * self );
158
159/* remove a torrent, waiting for it to pause if necessary */
160void
161tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter /* XXX */ );
162
163/* update the model with current torrent status */
164void
165tr_core_update( TrCore * self );
166
167/* emit the "quit" signal */
168void
169tr_core_quit( TrCore * self );
170
171/* Set a preference value, save the prefs file, and emit the
172   "prefs-changed" signal */
173void
174tr_core_set_pref( TrCore * self, const char * key, const char * val );
175
176/* Set a boolean preference value, save the prefs file, and emit the
177   "prefs-changed" signal */
178void
179tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val );
180
181/* Set an integer preference value, save the prefs file, and emit the
182   "prefs-changed" signal */
183void
184tr_core_set_pref_int( TrCore * self, const char * key, int val );
185
186/* column names for the model used to store torrent information */
187/* keep this in sync with the type array in tr_core_init() in tr_core.c */
188enum
189{
190    MC_NAME,
191    MC_NAME_COLLATED,
192    MC_HASH,
193    MC_TORRENT,
194    MC_TORRENT_RAW,
195    MC_STATUS,
196    MC_ID,
197    MC_ROW_COUNT
198};
199
200#endif
Note: See TracBrowser for help on using the repository browser.