2007-05-23 00:49:31 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Transmission authors and contributors
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TR_CORE_H
|
|
|
|
#define TR_CORE_H
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-05-23 00:49:31 +00:00
|
|
|
#include <glib-object.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
#include "bencode.h"
|
|
|
|
|
2007-05-23 19:26:29 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2007-05-23 00:49:31 +00:00
|
|
|
#define TR_CORE_TYPE ( tr_core_get_type() )
|
|
|
|
|
|
|
|
#define TR_CORE( obj ) \
|
|
|
|
( G_TYPE_CHECK_INSTANCE_CAST( (obj), TR_CORE_TYPE, TrCore ) )
|
|
|
|
|
|
|
|
#define TR_CORE_CLASS( class ) \
|
|
|
|
( G_TYPE_CHECK_CLASS_CAST( (class), TR_CORE_TYPE, TrCoreClass ) )
|
|
|
|
|
|
|
|
#define TR_IS_CORE( obj ) \
|
|
|
|
( G_TYPE_CHECK_INSTANCE_TYPE( (obj), TR_CORE_TYPE ) )
|
|
|
|
|
|
|
|
#define TR_IS_CORE_CLASS( class ) \
|
|
|
|
( G_TYPE_CHECK_CLASS_TYPE( (class), TR_CORE_TYPE ) )
|
|
|
|
|
|
|
|
#define TR_CORE_GET_CLASS( obj ) \
|
|
|
|
( G_TYPE_INSTANCE_GET_CLASS( (obj), TR_CORE_TYPE, TrCoreClass ) )
|
|
|
|
|
|
|
|
typedef struct _TrCore TrCore;
|
|
|
|
typedef struct _TrCoreClass TrCoreClass;
|
|
|
|
|
|
|
|
/* treat the contents of this structure as private */
|
|
|
|
struct _TrCore
|
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
GtkTreeModel * model;
|
2007-05-23 04:39:06 +00:00
|
|
|
tr_handle_t * handle;
|
2007-05-24 07:51:37 +00:00
|
|
|
int nextid;
|
2007-05-23 01:47:42 +00:00
|
|
|
gboolean quitting;
|
2007-05-23 00:49:31 +00:00
|
|
|
gboolean disposed;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _TrCoreClass
|
|
|
|
{
|
2007-05-23 06:25:15 +00:00
|
|
|
GObjectClass parent;
|
2007-05-23 17:59:35 +00:00
|
|
|
/* "error" signal:
|
|
|
|
void handler( TrCore *, enum tr_core_err, const char *, gpointer ) */
|
|
|
|
int errsig;
|
2007-05-24 02:50:28 +00:00
|
|
|
/* "directory-prompt" signal:
|
|
|
|
void handler( TrCore *, GList *, enum tr_torrent_action, gboolean,
|
|
|
|
gpointer ) */
|
|
|
|
int promptsig;
|
2007-05-24 10:37:07 +00:00
|
|
|
/* "directory-prompt-data" signal:
|
|
|
|
void handler( TrCore *, uint8_t *, size_t, gboolean, gpointer ) */
|
|
|
|
int promptdatasig;
|
2007-05-24 03:29:23 +00:00
|
|
|
/* "quit" signal:
|
|
|
|
void handler( TrCore *, gpointer ) */
|
|
|
|
int quitsig;
|
2007-05-24 13:55:57 +00:00
|
|
|
/* "prefs-changed" signal:
|
|
|
|
void handler( TrCore *, int, gpointer ) */
|
|
|
|
int prefsig;
|
2007-05-23 17:59:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum tr_core_err
|
|
|
|
{
|
|
|
|
TR_CORE_ERR_ADD_TORRENT, /* adding a torrent failed */
|
|
|
|
/* no more torrents to be added, used for grouping torrent add errors */
|
|
|
|
TR_CORE_ERR_NO_MORE_TORRENTS,
|
|
|
|
TR_CORE_ERR_SAVE_STATE /* error saving state */
|
2007-05-23 00:49:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GType
|
|
|
|
tr_core_get_type( void );
|
|
|
|
|
|
|
|
TrCore *
|
|
|
|
tr_core_new( void );
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
/* Return the model used without incrementing the reference count */
|
2007-05-23 00:49:31 +00:00
|
|
|
GtkTreeModel *
|
|
|
|
tr_core_model( TrCore * self );
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
/* Returns the libtransmission handle */
|
|
|
|
tr_handle_t *
|
|
|
|
tr_core_handle( TrCore * self );
|
|
|
|
|
|
|
|
/* Try to politely stop all torrents and nat traversal */
|
|
|
|
void
|
2007-05-23 06:25:15 +00:00
|
|
|
tr_core_shutdown( TrCore * self );
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2007-05-23 06:25:15 +00:00
|
|
|
/* Returns true if the shutdown has completed */
|
2007-05-23 01:47:42 +00:00
|
|
|
gboolean
|
2007-05-23 06:25:15 +00:00
|
|
|
tr_core_quiescent( TrCore * self );
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2007-05-23 17:59:35 +00:00
|
|
|
/* Save state. May trigger "error" signal with TR_CORE_ERR_SAVE_STATE */
|
2007-05-23 01:47:42 +00:00
|
|
|
void
|
2007-05-23 17:59:35 +00:00
|
|
|
tr_core_save( TrCore * self );
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2007-05-23 17:59:35 +00:00
|
|
|
/* Load saved state, return number of torrents added. May trigger one
|
|
|
|
or more "error" signals with TR_CORE_ERR_ADD_TORRENT */
|
2007-05-23 02:45:28 +00:00
|
|
|
int
|
2007-06-27 18:34:38 +00:00
|
|
|
tr_core_load( TrCore * self, const benc_val_t * state, gboolean forcepaused );
|
2007-05-23 02:45:28 +00:00
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
/* Any the tr_core_add functions below may trigger an "error" signal
|
|
|
|
with TR_CORE_ERR_ADD_TORRENT */
|
|
|
|
|
|
|
|
/* Add the torrent at the given path */
|
|
|
|
gboolean
|
|
|
|
tr_core_add( TrCore * self, const char * path, enum tr_torrent_action act,
|
|
|
|
gboolean paused );
|
|
|
|
|
|
|
|
/* Add the torrent at the given path with the given download directory */
|
2007-05-23 02:45:28 +00:00
|
|
|
gboolean
|
2007-05-24 02:50:28 +00:00
|
|
|
tr_core_add_dir( TrCore * self, const char * path, const char * dir,
|
|
|
|
enum tr_torrent_action act, gboolean paused );
|
|
|
|
|
|
|
|
/* Add a list of torrents with the given paths */
|
|
|
|
int
|
|
|
|
tr_core_add_list( TrCore * self, GList * paths, enum tr_torrent_action act,
|
|
|
|
gboolean paused );
|
2007-05-23 17:59:35 +00:00
|
|
|
|
2007-05-24 10:37:07 +00:00
|
|
|
/* Add the torrent data in the given buffer */
|
|
|
|
gboolean
|
|
|
|
tr_core_add_data( TrCore * self, uint8_t * data, size_t size, gboolean paused );
|
|
|
|
|
|
|
|
/* Add the torrent data in the given buffer with the given download directory */
|
|
|
|
gboolean
|
|
|
|
tr_core_add_data_dir( TrCore * self, uint8_t * data, size_t size,
|
|
|
|
const char * dir, gboolean paused );
|
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
/* Save state, update model, and signal the end of a torrent cluster */
|
2007-05-23 17:59:35 +00:00
|
|
|
void
|
|
|
|
tr_core_torrents_added( TrCore * self );
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2007-05-23 02:45:28 +00:00
|
|
|
/* remove a torrent, waiting for it to pause if necessary */
|
|
|
|
void
|
2007-05-23 06:25:15 +00:00
|
|
|
tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter /* XXX */ );
|
2007-05-23 02:45:28 +00:00
|
|
|
|
2007-05-23 06:25:15 +00:00
|
|
|
/* update the model with current torrent status */
|
2007-05-23 02:45:28 +00:00
|
|
|
void
|
|
|
|
tr_core_update( TrCore * self );
|
|
|
|
|
2007-05-24 03:29:23 +00:00
|
|
|
/* emit the "quit" signal */
|
|
|
|
void
|
|
|
|
tr_core_quit( TrCore * self );
|
|
|
|
|
2007-05-24 13:55:57 +00:00
|
|
|
/* Set a preference value, save the prefs file, and emit the
|
|
|
|
"prefs-changed" signal */
|
|
|
|
void
|
|
|
|
tr_core_set_pref( TrCore * self, int id, const char * val );
|
|
|
|
|
|
|
|
/* Set a boolean preference value, save the prefs file, and emit the
|
|
|
|
"prefs-changed" signal */
|
|
|
|
void
|
|
|
|
tr_core_set_pref_bool( TrCore * self, int id, gboolean val );
|
|
|
|
|
|
|
|
/* Set an integer preference value, save the prefs file, and emit the
|
|
|
|
"prefs-changed" signal */
|
|
|
|
void
|
|
|
|
tr_core_set_pref_int( TrCore * self, int id, int val );
|
|
|
|
|
2007-05-23 00:49:31 +00:00
|
|
|
/* column names for the model used to store torrent information */
|
|
|
|
/* keep this in sync with the type array in tr_core_init() in tr_core.c */
|
|
|
|
enum {
|
2007-05-24 09:18:03 +00:00
|
|
|
MC_NAME, MC_SIZE, MC_HASH, MC_STAT, MC_ERR, MC_TERR,
|
2007-06-18 03:40:41 +00:00
|
|
|
MC_PROG_C, MC_PROG_D, MC_DRATE, MC_URATE, MC_ETA, MC_PEERS,
|
2007-05-23 00:49:31 +00:00
|
|
|
MC_UPEERS, MC_DPEERS, MC_SEED, MC_LEECH, MC_DONE,
|
2007-05-24 07:51:37 +00:00
|
|
|
MC_DOWN, MC_UP, MC_LEFT, MC_TRACKER, MC_TORRENT, MC_ID,
|
|
|
|
MC_ROW_COUNT
|
2007-05-23 00:49:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|