Axe the stupid torrent flags.

This commit is contained in:
Josh Elsasser 2007-05-23 19:26:29 +00:00
parent e52e736e91
commit eadedea754
11 changed files with 134 additions and 126 deletions

View File

@ -57,10 +57,11 @@ struct addcb {
struct dirdata struct dirdata
{ {
add_torrents_func_t addfunc; add_torrents_func_t addfunc;
void * cbdata; void * cbdata;
GList * files; GList * files;
guint flags; enum tr_torrent_action action;
gboolean paused;
}; };
struct quitdata struct quitdata
@ -213,8 +214,8 @@ addresp(GtkWidget *widget, gint resp, gpointer gdata) {
struct addcb *data = gdata; struct addcb *data = gdata;
GSList *files, *ii; GSList *files, *ii;
GList *stupidgtk; GList *stupidgtk;
int flags;
char *dir; char *dir;
enum tr_torrent_action action;
if(GTK_RESPONSE_ACCEPT == resp) { if(GTK_RESPONSE_ACCEPT == resp) {
dir = NULL; dir = NULL;
@ -224,9 +225,9 @@ addresp(GtkWidget *widget, gint resp, gpointer gdata) {
stupidgtk = NULL; stupidgtk = NULL;
for(ii = files; NULL != ii; ii = ii->next) for(ii = files; NULL != ii; ii = ii->next)
stupidgtk = g_list_append(stupidgtk, ii->data); stupidgtk = g_list_append(stupidgtk, ii->data);
flags = ( data->autostart ? TR_TORNEW_RUNNING : TR_TORNEW_PAUSED ); action = toraddaction( tr_prefs_get( PREF_ID_ADDSTD ) );
flags |= addactionflag( tr_prefs_get( PREF_ID_ADDSTD ) ); data->addfunc( data->data, NULL, stupidgtk, dir,
data->addfunc( data->data, NULL, stupidgtk, dir, flags ); action, !data->autostart );
if(NULL != dir) if(NULL != dir)
g_free(dir); g_free(dir);
g_slist_free(files); g_slist_free(files);
@ -507,7 +508,7 @@ fmtpeercount( GtkLabel * label, int count )
void void
promptfordir( GtkWindow * parent, add_torrents_func_t addfunc, void *cbdata, promptfordir( GtkWindow * parent, add_torrents_func_t addfunc, void *cbdata,
GList * files, guint flags ) GList * files, enum tr_torrent_action act, gboolean paused )
{ {
struct dirdata * stuff; struct dirdata * stuff;
GtkWidget * wind; GtkWidget * wind;
@ -516,7 +517,8 @@ promptfordir( GtkWindow * parent, add_torrents_func_t addfunc, void *cbdata,
stuff->addfunc = addfunc; stuff->addfunc = addfunc;
stuff->cbdata = cbdata; stuff->cbdata = cbdata;
stuff->files = dupstrlist( files ); stuff->files = dupstrlist( files );
stuff->flags = flags; stuff->action = act;
stuff->paused = paused;
wind = gtk_file_chooser_dialog_new( _("Choose a directory"), parent, wind = gtk_file_chooser_dialog_new( _("Choose a directory"), parent,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
@ -547,7 +549,8 @@ promptresp( GtkWidget * widget, gint resp, gpointer data )
dir = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( widget ) ); dir = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( widget ) );
/* it seems that we will always get a directory */ /* it seems that we will always get a directory */
g_assert( NULL != dir ); g_assert( NULL != dir );
stuff->addfunc( stuff->cbdata, NULL, stuff->files, dir, stuff->flags ); stuff->addfunc( stuff->cbdata, NULL, stuff->files, dir,
stuff->action, stuff->paused );
g_free( dir ); g_free( dir );
} }

View File

@ -40,7 +40,7 @@ makeinfowind( GtkWindow * parent, GtkTreeModel * model, GtkTreePath * path,
/* prompt for a download directory for torrents, then add them */ /* prompt for a download directory for torrents, then add them */
void void
promptfordir( GtkWindow * parent, add_torrents_func_t addfunc, void *cbdata, promptfordir( GtkWindow * parent, add_torrents_func_t addfunc, void *cbdata,
GList * files, guint flags ); GList * files, enum tr_torrent_action act, gboolean paused );
/* prompt if the user wants to quit, calls func with cbdata if they do */ /* prompt if the user wants to quit, calls func with cbdata if they do */
void void

View File

@ -462,7 +462,6 @@ srv_addfile(struct constate *con, const char *name SHUTUP, benc_val_t *val) {
struct constate_serv *srv = &con->u.serv; struct constate_serv *srv = &con->u.serv;
GList *files; GList *files;
int ii; int ii;
guint flags;
if(TYPE_LIST == val->type) { if(TYPE_LIST == val->type) {
files = NULL; files = NULL;
@ -471,8 +470,8 @@ srv_addfile(struct constate *con, const char *name SHUTUP, benc_val_t *val) {
/* XXX somehow escape invalid utf-8 */ /* XXX somehow escape invalid utf-8 */
g_utf8_validate(val->val.l.vals[ii].val.s.s, -1, NULL)) g_utf8_validate(val->val.l.vals[ii].val.s.s, -1, NULL))
files = g_list_append(files, val->val.l.vals[ii].val.s.s); files = g_list_append(files, val->val.l.vals[ii].val.s.s);
flags = addactionflag( tr_prefs_get( PREF_ID_ADDIPC ) ); srv->addfunc( srv->cbdata, NULL, files, NULL,
srv->addfunc( srv->cbdata, NULL, files, NULL, flags ); toraddaction( tr_prefs_get( PREF_ID_ADDIPC ) ), FALSE );
g_list_free(files); g_list_free(files);
} }
} }

View File

@ -186,7 +186,7 @@ handleaction( struct cbdata *data, int action );
static void static void
addtorrents(void *vdata, void *state, GList *files, addtorrents(void *vdata, void *state, GList *files,
const char *dir, guint flags); const char *dir, enum tr_torrent_action act, gboolean paused);
static void static void
safepipe(void); safepipe(void);
static void static void
@ -373,7 +373,6 @@ static void
appsetup( TrWindow * wind, benc_val_t * state, GList * args, gboolean paused ) appsetup( TrWindow * wind, benc_val_t * state, GList * args, gboolean paused )
{ {
struct cbdata * cbdata; struct cbdata * cbdata;
guint flags;
/* fill out cbdata */ /* fill out cbdata */
cbdata = g_new0( struct cbdata, 1 ); cbdata = g_new0( struct cbdata, 1 );
@ -396,13 +395,8 @@ appsetup( TrWindow * wind, benc_val_t * state, GList * args, gboolean paused )
winsetup( cbdata, wind ); winsetup( cbdata, wind );
/* add torrents from command-line and saved state */ /* add torrents from command-line and saved state */
flags = addactionflag( tr_prefs_get( PREF_ID_ADDIPC ) ); addtorrents( cbdata, state, args, NULL,
g_assert( !( flags & ( TR_TORNEW_PAUSED | TR_TORNEW_RUNNING ) ) ); toraddaction( tr_prefs_get( PREF_ID_ADDIPC ) ), paused );
if( paused )
{
flags |= TR_TORNEW_PAUSED;
}
addtorrents( cbdata, state, args, NULL, flags );
/* start model update timer */ /* start model update timer */
cbdata->timer = g_timeout_add( UPDATE_INTERVAL, updatemodel, cbdata ); cbdata->timer = g_timeout_add( UPDATE_INTERVAL, updatemodel, cbdata );
@ -667,7 +661,7 @@ gotdrag(GtkWidget *widget SHUTUP, GdkDragContext *dc, gint x SHUTUP,
if( NULL != paths ) if( NULL != paths )
{ {
addtorrents( data, NULL, paths, NULL, addtorrents( data, NULL, paths, NULL,
addactionflag( tr_prefs_get( PREF_ID_ADDSTD ) ) ); toraddaction( tr_prefs_get( PREF_ID_ADDSTD ) ), FALSE );
} }
freestrlist(freeables); freestrlist(freeables);
g_free(files); g_free(files);
@ -1011,8 +1005,9 @@ handleaction( struct cbdata * data, int act )
} }
static void static void
addtorrents(void *vdata, void *state, GList *files, addtorrents( void * vdata, void * state, GList * files, const char * dir,
const char *dir, guint flags) { enum tr_torrent_action act, gboolean paused )
{
struct cbdata *data = vdata; struct cbdata *data = vdata;
const char * pref; const char * pref;
int added; int added;
@ -1021,7 +1016,7 @@ addtorrents(void *vdata, void *state, GList *files,
if( NULL != state ) if( NULL != state )
{ {
added += tr_core_load( data->core, state ); added += tr_core_load( data->core, state, paused );
} }
if(NULL != files) { if(NULL != files) {
@ -1030,14 +1025,14 @@ addtorrents(void *vdata, void *state, GList *files,
pref = tr_prefs_get( PREF_ID_ASKDIR ); pref = tr_prefs_get( PREF_ID_ASKDIR );
if( NULL != pref && strbool( pref ) ) if( NULL != pref && strbool( pref ) )
{ {
promptfordir( data->wind, addtorrents, data, files, flags ); promptfordir( data->wind, addtorrents, data, files, act, paused );
files = NULL; files = NULL;
} }
dir = getdownloaddir(); dir = getdownloaddir();
} }
for( files = g_list_first( files ); NULL != files; files = files->next ) for( files = g_list_first( files ); NULL != files; files = files->next )
{ {
if( tr_core_add_torrent( data->core, files->data, dir, flags ) ) if( tr_core_add_torrent( data->core, files->data, dir, act, paused ) )
{ {
added++; added++;
} }

View File

@ -432,7 +432,7 @@ tr_core_save( TrCore * self )
} }
int int
tr_core_load( TrCore * self, benc_val_t * state ) tr_core_load( TrCore * self, benc_val_t * state, gboolean forcepaused )
{ {
int ii, count; int ii, count;
char * errstr; char * errstr;
@ -450,7 +450,7 @@ tr_core_load( TrCore * self, benc_val_t * state )
{ {
errstr = NULL; errstr = NULL;
tor = tr_torrent_new_with_state( self->handle, state->val.l.vals + ii, tor = tr_torrent_new_with_state( self->handle, state->val.l.vals + ii,
0, &errstr ); forcepaused, &errstr );
if( NULL == tor ) if( NULL == tor )
{ {
tr_core_errsig( self, TR_CORE_ERR_ADD_TORRENT, errstr ); tr_core_errsig( self, TR_CORE_ERR_ADD_TORRENT, errstr );
@ -468,8 +468,8 @@ tr_core_load( TrCore * self, benc_val_t * state )
} }
gboolean gboolean
tr_core_add_torrent( TrCore * self, const char * torrent, const char * dir, tr_core_add_torrent( TrCore * self, const char * path, const char * dir,
guint flags ) enum tr_torrent_action act, gboolean paused )
{ {
TrTorrent * tor; TrTorrent * tor;
char * errstr; char * errstr;
@ -477,7 +477,7 @@ tr_core_add_torrent( TrCore * self, const char * torrent, const char * dir,
TR_IS_CORE( self ); TR_IS_CORE( self );
errstr = NULL; errstr = NULL;
tor = tr_torrent_new( self->handle, torrent, dir, flags, &errstr ); tor = tr_torrent_new( self->handle, path, dir, act, paused, &errstr );
if( NULL == tor ) if( NULL == tor )
{ {
tr_core_errsig( self, TR_CORE_ERR_ADD_TORRENT, errstr ); tr_core_errsig( self, TR_CORE_ERR_ADD_TORRENT, errstr );

View File

@ -32,6 +32,8 @@
#include "bencode.h" #include "bencode.h"
#include "util.h"
#define TR_CORE_TYPE ( tr_core_get_type() ) #define TR_CORE_TYPE ( tr_core_get_type() )
#define TR_CORE( obj ) \ #define TR_CORE( obj ) \
@ -108,13 +110,12 @@ tr_core_save( TrCore * self );
/* Load saved state, return number of torrents added. May trigger one /* Load saved state, return number of torrents added. May trigger one
or more "error" signals with TR_CORE_ERR_ADD_TORRENT */ or more "error" signals with TR_CORE_ERR_ADD_TORRENT */
int int
tr_core_load( TrCore * self, benc_val_t * state ); tr_core_load( TrCore * self, benc_val_t * state, gboolean forcepaused );
/* Add a torrent. Torrent, dir and flags arguments are the same as /* Add a torrent. May trigger "error" signal with TR_CORE_ERR_ADD_TORRENT */
tr_torrent_new(). May trigger "error" signal with TR_CORE_ERR_ADD_TORRENT */
gboolean gboolean
tr_core_add_torrent( TrCore * self, const char * torrent, const char * dir, tr_core_add_torrent( TrCore * self, const char * path, const char * dir,
guint flags ); enum tr_torrent_action act, gboolean paused );
/* Trigger "error" signal with TR_CORE_ERR_NO_MORE_TORRENTS */ /* Trigger "error" signal with TR_CORE_ERR_NO_MORE_TORRENTS */
void void

View File

@ -854,13 +854,13 @@ makecombomodel( void )
/* create the model used by the two popup menus */ /* create the model used by the two popup menus */
list = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT ); list = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
gtk_list_store_append( list, &iter ); gtk_list_store_append( list, &iter );
gtk_list_store_set( list, &iter, 1, 0, 0, gtk_list_store_set( list, &iter, 1, TR_TOR_LEAVE, 0,
_("Use the torrent file where it is"), -1 ); _("Use the torrent file where it is"), -1 );
gtk_list_store_append( list, &iter ); gtk_list_store_append( list, &iter );
gtk_list_store_set( list, &iter, 1, TR_TORNEW_SAVE_COPY, 0, gtk_list_store_set( list, &iter, 1, TR_TOR_COPY, 0,
_("Keep a copy of the torrent file"), -1 ); _("Keep a copy of the torrent file"), -1 );
gtk_list_store_append( list, &iter ); gtk_list_store_append( list, &iter );
gtk_list_store_set( list, &iter, 1, TR_TORNEW_SAVE_MOVE, 0, gtk_list_store_set( list, &iter, 1, TR_TOR_MOVE, 0,
_("Keep a copy and remove the original"), -1 ); _("Keep a copy and remove the original"), -1 );
return GTK_TREE_MODEL( list ); return GTK_TREE_MODEL( list );
@ -873,7 +873,7 @@ addwid_combo( TrPrefs * self, int id, GtkTooltips * tips,
GtkWidget * combo, * label; GtkWidget * combo, * label;
GtkCellRenderer * rend; GtkCellRenderer * rend;
GtkTreeIter iter; GtkTreeIter iter;
guint prefsflag, modelflag; enum tr_torrent_action prefsact, modelact;
g_assert( ALEN( defs ) > id && GTK_TYPE_COMBO_BOX == PTYPE( id ) ); g_assert( ALEN( defs ) > id && GTK_TYPE_COMBO_BOX == PTYPE( id ) );
combo = gtk_combo_box_new(); combo = gtk_combo_box_new();
@ -885,13 +885,13 @@ addwid_combo( TrPrefs * self, int id, GtkTooltips * tips,
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), rend, TRUE ); gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), rend, TRUE );
gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT( combo ), rend, "text", 0 ); gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT( combo ), rend, "text", 0 );
prefsflag = addactionflag( tr_prefs_get( id ) ); prefsact = toraddaction( tr_prefs_get( id ) );
if( gtk_tree_model_get_iter_first( self->combomodel, &iter ) ) if( gtk_tree_model_get_iter_first( self->combomodel, &iter ) )
{ {
do do
{ {
gtk_tree_model_get( self->combomodel, &iter, 1, &modelflag, -1 ); gtk_tree_model_get( self->combomodel, &iter, 1, &modelact, -1 );
if( modelflag == prefsflag) if( modelact == prefsact )
{ {
gtk_combo_box_set_active_iter( GTK_COMBO_BOX( combo ), &iter ); gtk_combo_box_set_active_iter( GTK_COMBO_BOX( combo ), &iter );
break; break;
@ -912,7 +912,7 @@ combochosen( GtkWidget * widget, gpointer data )
TrPrefs * self; TrPrefs * self;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel * model; GtkTreeModel * model;
guint flags; enum tr_torrent_action action;
int id; int id;
TR_IS_PREFS( data ); TR_IS_PREFS( data );
@ -920,9 +920,9 @@ combochosen( GtkWidget * widget, gpointer data )
if( gtk_combo_box_get_active_iter( GTK_COMBO_BOX( widget ), &iter ) ) if( gtk_combo_box_get_active_iter( GTK_COMBO_BOX( widget ), &iter ) )
{ {
model = gtk_combo_box_get_model( GTK_COMBO_BOX( widget ) ); model = gtk_combo_box_get_model( GTK_COMBO_BOX( widget ) );
gtk_tree_model_get( model, &iter, 1, &flags, -1 ); gtk_tree_model_get( model, &iter, 1, &action, -1 );
GETPREFID( widget, id ); GETPREFID( widget, id );
savepref( self, id, addactionname( flags ) ); savepref( self, id, toractionname( action ) );
} }
} }

View File

@ -290,27 +290,38 @@ tr_torrent_info(TrTorrent *tor) {
return tr_torrentInfo(tor->handle); return tr_torrentInfo(tor->handle);
} }
static TrTorrent *
maketorrent( tr_torrent_t * handle, const char * dir, gboolean paused )
{
TrTorrent * tor;
tr_torrentDisablePex( handle,
!tr_prefs_get_bool_with_default( PREF_ID_PEX ) );
tor = g_object_new( TR_TORRENT_TYPE, "torrent-handle", handle,
"download-directory", dir, NULL);
g_object_set( tor, "paused", paused, NULL );
return tor;
}
TrTorrent * TrTorrent *
tr_torrent_new( tr_handle_t * back, const char *torrent, const char *dir, tr_torrent_new( tr_handle_t * back, const char *torrent, const char *dir,
guint flags, char **err) { enum tr_torrent_action act, gboolean paused, char **err )
{
TrTorrent *ret; TrTorrent *ret;
tr_torrent_t *handle; tr_torrent_t *handle;
int errcode, trflags; int errcode, flag;
gboolean boolval;
g_assert(NULL != dir); g_assert(NULL != dir);
*err = NULL; *err = NULL;
trflags = 0; flag = ( TR_TOR_COPY == act || TR_TOR_MOVE == act ? TR_FLAG_SAVE : 0 );
if((TR_TORNEW_SAVE_COPY|TR_TORNEW_SAVE_MOVE) & flags)
trflags |= TR_FLAG_SAVE;
errcode = -1; errcode = -1;
if(TR_TORNEW_LOAD_SAVED & flags) handle = tr_torrentInit( back, torrent, NULL, flag, &errcode );
handle = tr_torrentInitSaved(back, torrent, 0, &errcode);
else
handle = tr_torrentInit(back, torrent, NULL, trflags, &errcode);
if(NULL == handle) { if(NULL == handle) {
switch(errcode) { switch(errcode) {
@ -327,17 +338,9 @@ tr_torrent_new( tr_handle_t * back, const char *torrent, const char *dir,
return NULL; return NULL;
} }
/* I should probably add a property for this but I've had enough ret = maketorrent( handle, dir, paused );
with adding useless gtk glue to this program */
boolval = tr_prefs_get_bool_with_default( PREF_ID_PEX );
tr_torrentDisablePex( handle, !boolval );
ret = g_object_new(TR_TORRENT_TYPE, "torrent-handle", handle, if( TR_TOR_MOVE == act )
"download-directory", dir, NULL);
g_object_set(ret, "paused", (TR_TORNEW_PAUSED & flags ? TRUE : FALSE), NULL);
if(TR_TORNEW_SAVE_MOVE & flags)
ret->delfile = g_strdup(torrent); ret->delfile = g_strdup(torrent);
return ret; return ret;
@ -345,13 +348,13 @@ tr_torrent_new( tr_handle_t * back, const char *torrent, const char *dir,
TrTorrent * TrTorrent *
tr_torrent_new_with_state( tr_handle_t * back, benc_val_t * state, tr_torrent_new_with_state( tr_handle_t * back, benc_val_t * state,
guint forcedflags, char ** err) gboolean forcedpause, char ** err )
{ {
int ii; tr_torrent_t * handle;
int ii, errcode;
benc_val_t *name, *data; benc_val_t *name, *data;
char *torrent, *hash, *dir; char *torrent, *hash, *dir;
gboolean hadpaused, paused; gboolean paused;
guint flags;
*err = NULL; *err = NULL;
@ -359,8 +362,7 @@ tr_torrent_new_with_state( tr_handle_t * back, benc_val_t * state,
return NULL; return NULL;
torrent = hash = dir = NULL; torrent = hash = dir = NULL;
hadpaused = FALSE; paused = FALSE;
paused = FALSE; /* silence stupid compiler warning */
for(ii = 0; ii + 1 < state->val.l.count; ii += 2) { for(ii = 0; ii + 1 < state->val.l.count; ii += 2) {
name = state->val.l.vals + ii; name = state->val.l.vals + ii;
@ -374,7 +376,6 @@ tr_torrent_new_with_state( tr_handle_t * back, benc_val_t * state,
else if(0 == strcmp("dir", name->val.s.s)) else if(0 == strcmp("dir", name->val.s.s))
dir = data->val.s.s; dir = data->val.s.s;
else if(0 == strcmp("paused", name->val.s.s)) { else if(0 == strcmp("paused", name->val.s.s)) {
hadpaused = TRUE;
paused = (data->val.i ? TRUE : FALSE); paused = (data->val.i ? TRUE : FALSE);
} }
} }
@ -384,21 +385,28 @@ tr_torrent_new_with_state( tr_handle_t * back, benc_val_t * state,
(NULL == torrent && NULL == hash) || NULL == dir) (NULL == torrent && NULL == hash) || NULL == dir)
return NULL; return NULL;
flags = 0; if( NULL != hash )
if(hadpaused) handle = tr_torrentInitSaved(back, hash, 0, &errcode);
flags |= (paused ? TR_TORNEW_PAUSED : TR_TORNEW_RUNNING); else
if(NULL != hash) { handle = tr_torrentInit(back, torrent, NULL, 0, &errcode);
flags |= TR_TORNEW_LOAD_SAVED;
torrent = hash; if(NULL == handle) {
} torrent = ( NULL == hash ? torrent : hash );
forcedflags &= TR_TORNEW_PAUSED | TR_TORNEW_RUNNING; switch(errcode) {
if( forcedflags ) case TR_EINVALID:
{ *err = g_strdup_printf(_("%s: not a valid torrent file"), torrent);
flags &= ~( TR_TORNEW_PAUSED | TR_TORNEW_RUNNING ); break;
flags |= forcedflags; case TR_EDUPLICATE:
*err = g_strdup_printf(_("%s: torrent is already open"), torrent);
break;
default:
*err = g_strdup(torrent);
break;
}
return NULL;
} }
return tr_torrent_new( back, torrent, dir, flags, err ); return maketorrent( handle, dir, paused || forcedpause );
} }
gboolean gboolean

View File

@ -30,6 +30,8 @@
#include "transmission.h" #include "transmission.h"
#include "bencode.h" #include "bencode.h"
#include "util.h"
/* boxed type for tr_tracker_info_t */ /* boxed type for tr_tracker_info_t */
#define TR_TRACKER_BOXED_TYPE (tr_tracker_boxed_get_type ()) #define TR_TRACKER_BOXED_TYPE (tr_tracker_boxed_get_type ())
GType GType
@ -76,25 +78,15 @@ tr_torrent_stat(TrTorrent *tor);
tr_info_t * tr_info_t *
tr_torrent_info(TrTorrent *tor); tr_torrent_info(TrTorrent *tor);
/* explicitly start the torrent running or paused */
#define TR_TORNEW_PAUSED 0x01
#define TR_TORNEW_RUNNING 0x02
/* load a saved torrent file, torrent param is hash instead of filename */
#define TR_TORNEW_LOAD_SAVED 0x04
/* save a private copy of the torrent file */
#define TR_TORNEW_SAVE_COPY 0x08
/* save a private copy of the torrent file and remove the original */
#define TR_TORNEW_SAVE_MOVE 0x10
#ifdef TR_WANT_TORRENT_PRIVATE #ifdef TR_WANT_TORRENT_PRIVATE
TrTorrent * TrTorrent *
tr_torrent_new( tr_handle_t * handle, const char *torrent, const char *dir, tr_torrent_new( tr_handle_t * handle, const char * path, const char * dir,
guint flags, char **err); enum tr_torrent_action act, gboolean paused, char ** err);
TrTorrent * TrTorrent *
tr_torrent_new_with_state( tr_handle_t * handle, benc_val_t * state, tr_torrent_new_with_state( tr_handle_t * handle, benc_val_t * state,
guint flags, char ** err ); gboolean forcepaused, char ** err );
gboolean gboolean
tr_torrent_get_state( TrTorrent * tor, benc_val_t * state ); tr_torrent_get_state( TrTorrent * tor, benc_val_t * state );

View File

@ -268,29 +268,35 @@ checkfilenames(int argc, char **argv) {
return ret; return ret;
} }
guint enum tr_torrent_action
addactionflag(const char *action) { toraddaction( const char * action )
if(NULL == action) {
return TR_TORNEW_SAVE_COPY; if( NULL == action || 0 == strcmp( "copy", action ) )
else if(0 == strcmp("copy", action)) {
return TR_TORNEW_SAVE_COPY; return TR_TOR_COPY;
else if(0 == strcmp("move", action)) }
return TR_TORNEW_SAVE_MOVE; else if( 0 == strcmp( "move", action ) )
else {
return 0; return TR_TOR_MOVE;
}
else
{
return TR_TOR_LEAVE;
}
} }
const char * const char *
addactionname( guint flag ) toractionname( enum tr_torrent_action action )
{ {
static char name[6]; switch( action )
{
snprintf( name, sizeof name, "%s", case TR_TOR_COPY:
( TR_TORNEW_SAVE_COPY & flag ? "copy" : return "copy";
( TR_TORNEW_SAVE_MOVE & flag ? "move" : case TR_TOR_MOVE:
"leave" ) ) ); return "move";
default:
return name; return "leave";
}
} }
const char * const char *

View File

@ -35,7 +35,11 @@
#define SHUTUP #define SHUTUP
#endif #endif
typedef void (*add_torrents_func_t)(void*,void*,GList*,const char*,guint); /* XXX this shouldn't be here */
enum tr_torrent_action { TR_TOR_LEAVE, TR_TOR_COPY, TR_TOR_MOVE };
typedef void (*add_torrents_func_t)(void*,void*,GList*,const char*,
enum tr_torrent_action,gboolean);
/* return number of items in array */ /* return number of items in array */
#define ALEN( a ) ( ( signed )( sizeof(a) / sizeof( (a)[0] ) ) ) #define ALEN( a ) ( ( signed )( sizeof(a) / sizeof( (a)[0] ) ) )
@ -106,12 +110,12 @@ GList *
checkfilenames(int argc, char **argv); checkfilenames(int argc, char **argv);
/* returns the flag for an action string */ /* returns the flag for an action string */
guint enum tr_torrent_action
addactionflag(const char *action); toraddaction( const char * action );
/* returns the action string for a flag */ /* returns the action string for a flag */
const char * const char *
addactionname(guint flag); toractionname( enum tr_torrent_action action );
/* retrieve the global download directory */ /* retrieve the global download directory */
const char * const char *