source: trunk/gtk/tr_core.h @ 3821

Last change on this file since 3821 was 3821, checked in by charles, 15 years ago

cruft removal: use tr_stat's ratio field instead of calculating it ourself.

  • Property svn:keywords set to Date Rev Author Id
File size: 6.3 KB
Line 
1/******************************************************************************
2 * $Id: tr_core.h 3821 2007-11-15 04:19:53Z charles $
3 *
4 * Copyright (c) 2007 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
55typedef struct _TrCore TrCore;
56typedef struct _TrCoreClass TrCoreClass;
57
58/* treat the contents of this structure as private */
59struct _TrCore
60{
61    GObject           parent;
62    GtkTreeModel    * model;
63    tr_handle       * handle;
64    int               nextid;
65    gboolean          quitting;
66    gboolean          disposed;
67};
68
69struct _TrCoreClass
70{
71    GObjectClass        parent;
72    /* "error" signal:
73       void handler( TrCore *, enum tr_core_err, const char *, gpointer ) */
74    int                 errsig;
75    /* "directory-prompt" signal:
76       void handler( TrCore *, GList *, enum tr_torrent_action, gboolean,
77                     gpointer ) */
78    int                 promptsig;
79    /* "directory-prompt-data" signal:
80       void handler( TrCore *, uint8_t *, size_t, gboolean, gpointer ) */
81    int                 promptdatasig;
82    /* "quit" signal:
83       void handler( TrCore *, gpointer ) */
84    int                 quitsig;
85    /* "prefs-changed" signal:
86       void handler( TrCore *, int, gpointer ) */
87    int                 prefsig;
88};
89
90enum tr_core_err
91{
92    TR_CORE_ERR_ADD_TORRENT,    /* adding a torrent failed */
93    /* no more torrents to be added, used for grouping torrent add errors */
94    TR_CORE_ERR_NO_MORE_TORRENTS,
95    TR_CORE_ERR_SAVE_STATE      /* error saving state */
96};
97
98GType
99tr_core_get_type( void );
100
101TrCore *
102tr_core_new( void );
103
104/* Return the model used without incrementing the reference count */
105GtkTreeModel *
106tr_core_model( TrCore * self );
107
108/* Returns the libtransmission handle */
109tr_handle *
110tr_core_handle( TrCore * self );
111
112/* Load saved state, return number of torrents added. May trigger one
113   or more "error" signals with TR_CORE_ERR_ADD_TORRENT */
114int
115tr_core_load( TrCore * self, gboolean forcepaused );
116
117/* Any the tr_core_add functions below may trigger an "error" signal
118   with TR_CORE_ERR_ADD_TORRENT */
119
120/* Add the torrent at the given path */
121gboolean
122tr_core_add( TrCore * self, const char * path, enum tr_torrent_action act,
123             gboolean paused );
124
125/* Add the torrent at the given path with the given download directory */
126gboolean
127tr_core_add_dir( TrCore * self, const char * path, const char * dir,
128                 enum tr_torrent_action act, gboolean paused );
129
130/* Add a list of torrents with the given paths */
131int
132tr_core_add_list( TrCore * self, GList * paths, enum tr_torrent_action act,
133                  gboolean paused );
134
135/* Add the torrent data in the given buffer */
136gboolean
137tr_core_add_data( TrCore * self, uint8_t * data, size_t size, gboolean paused );
138
139/* Add the torrent data in the given buffer with the given download directory */
140gboolean
141tr_core_add_data_dir( TrCore * self, uint8_t * data, size_t size,
142                      const char * dir, gboolean paused );
143
144/* Save state, update model, and signal the end of a torrent cluster */
145void
146tr_core_torrents_added( TrCore * self );
147
148/* remove a torrent, waiting for it to pause if necessary */
149void
150tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter /* XXX */ );
151
152/* update the model with current torrent status */
153void
154tr_core_update( TrCore * self );
155
156/* emit the "quit" signal */
157void
158tr_core_quit( TrCore * self );
159
160/* Set a preference value, save the prefs file, and emit the
161   "prefs-changed" signal */
162void
163tr_core_set_pref( TrCore * self, const char * key, const char * val );
164
165/* Set a boolean preference value, save the prefs file, and emit the
166   "prefs-changed" signal */
167void
168tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val );
169
170/* Set an integer preference value, save the prefs file, and emit the
171   "prefs-changed" signal */
172void
173tr_core_set_pref_int( TrCore * self, const char * key, int val );
174
175void
176tr_core_set_sort_column_from_prefs( TrCore * core );
177
178/* column names for the model used to store torrent information */
179/* keep this in sync with the type array in tr_core_init() in tr_core.c */
180enum {
181  MC_NAME, MC_SIZE, MC_HASH, MC_STAT, MC_ERR, MC_TERR,
182  MC_PROG_C, MC_PROG_D, MC_DRATE, MC_URATE, MC_ETA, MC_PEERS,
183  MC_UPEERS, MC_DPEERS, MC_SEED, MC_LEECH, MC_DONE,
184  MC_DOWN, MC_UP, MC_RATIO, MC_LEFT, MC_TORRENT, MC_ID,
185  MC_ROW_COUNT
186};
187
188#endif
Note: See TracBrowser for help on using the repository browser.