(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 */
|
||||
break;
|
||||
case TR_RPC_TORRENT_REMOVING:
|
||||
/* FIXME */
|
||||
tr_core_torrent_destroyed( data->cbdata->core, data->torrentId );
|
||||
break;
|
||||
case TR_RPC_TORRENT_CHANGED:
|
||||
case TR_RPC_SESSION_CHANGED:
|
||||
|
|
|
@ -807,7 +807,7 @@ tr_core_torrents_added( TrCore * self )
|
|||
}
|
||||
|
||||
static gboolean
|
||||
findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
|
||||
findTorrentInModel( TrCore * core, int id, GtkTreeIter * setme )
|
||||
{
|
||||
int match = 0;
|
||||
GtkTreeIter iter;
|
||||
|
@ -815,10 +815,9 @@ findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
|
|||
|
||||
if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
|
||||
{
|
||||
TrTorrent * tmp;
|
||||
gtk_tree_model_get( model, &iter, MC_TORRENT, &tmp, -1 );
|
||||
match = tmp == gtor;
|
||||
g_object_unref( G_OBJECT( tmp ) );
|
||||
tr_torrent * tor;
|
||||
gtk_tree_model_get( model, &iter, MC_TORRENT_RAW, &tor, -1 );
|
||||
match = tr_torrentId(tor) == id;
|
||||
}
|
||||
while( !match && gtk_tree_model_iter_next( model, &iter ) );
|
||||
|
||||
|
@ -829,24 +828,46 @@ findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
|
|||
}
|
||||
|
||||
void
|
||||
tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles )
|
||||
tr_core_torrent_destroyed( TrCore * core,
|
||||
int id )
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel * model = tr_core_model( self );
|
||||
|
||||
/* remove from the gui */
|
||||
if( findTorrentInModel( self, gtor, &iter ) )
|
||||
if( findTorrentInModel( core, id, &iter ) )
|
||||
{
|
||||
TrTorrent * gtor;
|
||||
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 );
|
||||
|
||||
/* 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 ) );
|
||||
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 );
|
||||
|
||||
/* update the model with current torrent status */
|
||||
|
|
|
@ -88,6 +88,15 @@ tr_torrent_dispose( GObject * 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
|
||||
tr_torrent_class_init( gpointer g_class, gpointer g_class_data UNUSED )
|
||||
{
|
||||
|
|
|
@ -58,6 +58,9 @@ TrTorrentClass;
|
|||
GType
|
||||
tr_torrent_get_type(void);
|
||||
|
||||
void
|
||||
tr_torrent_clear( TrTorrent * tor );
|
||||
|
||||
tr_torrent *
|
||||
tr_torrent_handle(TrTorrent *tor);
|
||||
|
||||
|
|
Loading…
Reference in New Issue