source: trunk/gtk/tr_core.h @ 4704

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

(gtk) #616: tray icon info popup, suggested by inferneux and seconded a few times in the forums.

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