(gtk) #1090: gtk+ client crashes when a torrent is removed from clutch
This commit is contained in:
parent
d26c3af13d
commit
339fb746ff
|
@ -304,7 +304,7 @@ onRPCIdle( void * vdata )
|
||||||
/* this should be automatic */
|
/* this should be automatic */
|
||||||
break;
|
break;
|
||||||
case TR_RPC_TORRENT_REMOVING:
|
case TR_RPC_TORRENT_REMOVING:
|
||||||
/* FIXME */
|
tr_core_torrent_destroyed( data->cbdata->core, data->torrentId );
|
||||||
break;
|
break;
|
||||||
case TR_RPC_TORRENT_CHANGED:
|
case TR_RPC_TORRENT_CHANGED:
|
||||||
case TR_RPC_SESSION_CHANGED:
|
case TR_RPC_SESSION_CHANGED:
|
||||||
|
|
|
@ -807,7 +807,7 @@ tr_core_torrents_added( TrCore * self )
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
|
findTorrentInModel( TrCore * core, int id, GtkTreeIter * setme )
|
||||||
{
|
{
|
||||||
int match = 0;
|
int match = 0;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
@ -815,10 +815,9 @@ findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
|
||||||
|
|
||||||
if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
|
if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
|
||||||
{
|
{
|
||||||
TrTorrent * tmp;
|
tr_torrent * tor;
|
||||||
gtk_tree_model_get( model, &iter, MC_TORRENT, &tmp, -1 );
|
gtk_tree_model_get( model, &iter, MC_TORRENT_RAW, &tor, -1 );
|
||||||
match = tmp == gtor;
|
match = tr_torrentId(tor) == id;
|
||||||
g_object_unref( G_OBJECT( tmp ) );
|
|
||||||
}
|
}
|
||||||
while( !match && gtk_tree_model_iter_next( model, &iter ) );
|
while( !match && gtk_tree_model_iter_next( model, &iter ) );
|
||||||
|
|
||||||
|
@ -829,24 +828,46 @@ findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles )
|
tr_core_torrent_destroyed( TrCore * core,
|
||||||
|
int id )
|
||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeModel * model = tr_core_model( self );
|
if( findTorrentInModel( core, id, &iter ) )
|
||||||
|
{
|
||||||
/* remove from the gui */
|
TrTorrent * gtor;
|
||||||
if( findTorrentInModel( self, gtor, &iter ) )
|
GtkTreeModel * model = tr_core_model( core );
|
||||||
|
gtk_tree_model_get( model, &iter, MC_TORRENT, >or, -1 );
|
||||||
|
tr_torrent_clear( gtor );
|
||||||
gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
|
gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
|
||||||
|
g_object_unref( G_OBJECT( gtor ) );
|
||||||
/* maybe delete the downloaded files */
|
}
|
||||||
if( deleteFiles )
|
|
||||||
tr_torrent_delete_files( gtor );
|
|
||||||
|
|
||||||
/* remove the torrent */
|
|
||||||
tr_torrent_set_remove_flag( gtor, TRUE );
|
|
||||||
g_object_unref( G_OBJECT( gtor ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tr_core_remove_torrent( TrCore * core, TrTorrent * gtor, int deleteFiles )
|
||||||
|
{
|
||||||
|
const tr_torrent * tor = tr_torrent_handle( gtor );
|
||||||
|
if( tor )
|
||||||
|
{
|
||||||
|
int id = tr_torrentId( tor );
|
||||||
|
GtkTreeIter iter;
|
||||||
|
if( findTorrentInModel( core, id, &iter ) )
|
||||||
|
{
|
||||||
|
GtkTreeModel * model = tr_core_model( core );
|
||||||
|
|
||||||
|
/* remove from the gui */
|
||||||
|
gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
|
||||||
|
|
||||||
|
/* maybe delete the downloaded files */
|
||||||
|
if( deleteFiles )
|
||||||
|
tr_torrent_delete_files( gtor );
|
||||||
|
|
||||||
|
/* remove the torrent */
|
||||||
|
tr_torrent_set_remove_flag( gtor, TRUE );
|
||||||
|
g_object_unref( G_OBJECT( gtor ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
****
|
****
|
||||||
|
|
|
@ -143,6 +143,11 @@ void tr_core_torrents_added( TrCore * self );
|
||||||
*******
|
*******
|
||||||
******/
|
******/
|
||||||
|
|
||||||
|
/* we've gotten notice from RPC that a torrent has been destroyed;
|
||||||
|
update our gui accordingly */
|
||||||
|
void tr_core_torrent_destroyed( TrCore * self, int id );
|
||||||
|
|
||||||
|
/* remove a torrent */
|
||||||
void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles );
|
void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles );
|
||||||
|
|
||||||
/* update the model with current torrent status */
|
/* update the model with current torrent status */
|
||||||
|
|
|
@ -88,6 +88,15 @@ tr_torrent_dispose( GObject * o )
|
||||||
parent->dispose( o );
|
parent->dispose( o );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tr_torrent_clear( TrTorrent * tor )
|
||||||
|
{
|
||||||
|
g_return_if_fail( tor );
|
||||||
|
g_return_if_fail( tor->priv );
|
||||||
|
|
||||||
|
tor->priv->handle = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tr_torrent_class_init( gpointer g_class, gpointer g_class_data UNUSED )
|
tr_torrent_class_init( gpointer g_class, gpointer g_class_data UNUSED )
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,6 +58,9 @@ TrTorrentClass;
|
||||||
GType
|
GType
|
||||||
tr_torrent_get_type(void);
|
tr_torrent_get_type(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
tr_torrent_clear( TrTorrent * tor );
|
||||||
|
|
||||||
tr_torrent *
|
tr_torrent *
|
||||||
tr_torrent_handle(TrTorrent *tor);
|
tr_torrent_handle(TrTorrent *tor);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue