Changeset 6344


Ignore:
Timestamp:
Jul 16, 2008, 7:38:22 PM (13 years ago)
Author:
charles
Message:

(gtk) #1090: gtk+ client crashes when a torrent is removed from clutch

Location:
trunk/gtk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r6329 r6344  
    305305            break;
    306306        case TR_RPC_TORRENT_REMOVING:
    307             /* FIXME */
     307            tr_core_torrent_destroyed( data->cbdata->core, data->torrentId );
    308308            break;
    309309        case TR_RPC_TORRENT_CHANGED:
  • trunk/gtk/tr-core.c

    r6309 r6344  
    808808
    809809static gboolean
    810 findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
     810findTorrentInModel( TrCore * core, int id, GtkTreeIter * setme )
    811811{
    812812    int match = 0;
     
    816816    if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
    817817    {
    818         TrTorrent * tmp;
    819         gtk_tree_model_get( model, &iter, MC_TORRENT, &tmp, -1 );
    820         match = tmp == gtor;
    821         g_object_unref( G_OBJECT( tmp ) );
     818        tr_torrent * tor;
     819        gtk_tree_model_get( model, &iter, MC_TORRENT_RAW, &tor, -1 );
     820        match = tr_torrentId(tor) == id;
    822821    }
    823822    while( !match && gtk_tree_model_iter_next( model, &iter ) );
     
    830829
    831830void
    832 tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles )
     831tr_core_torrent_destroyed( TrCore   * core,
     832                           int        id )
    833833{
    834834    GtkTreeIter iter;
    835     GtkTreeModel * model = tr_core_model( self );
    836 
    837     /* remove from the gui */
    838     if( findTorrentInModel( self, gtor, &iter ) )
     835    if( findTorrentInModel( core, id, &iter ) )
     836    {
     837        TrTorrent * gtor;
     838        GtkTreeModel * model = tr_core_model( core );
     839        gtk_tree_model_get( model, &iter, MC_TORRENT, &gtor, -1 );
     840        tr_torrent_clear( gtor );
    839841        gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
    840 
    841     /* maybe delete the downloaded files */
    842     if( deleteFiles )
    843         tr_torrent_delete_files( gtor );
    844 
    845     /* remove the torrent */
    846     tr_torrent_set_remove_flag( gtor, TRUE );
    847     g_object_unref( G_OBJECT( gtor ) );
    848 }
    849 
     842        g_object_unref( G_OBJECT( gtor ) );
     843    }
     844}
     845
     846void
     847tr_core_remove_torrent( TrCore * core, TrTorrent * gtor, int deleteFiles )
     848{
     849    const tr_torrent * tor = tr_torrent_handle( gtor );
     850    if( tor )
     851    {
     852        int id = tr_torrentId( tor );
     853        GtkTreeIter iter;
     854        if( findTorrentInModel( core, id, &iter ) )
     855        {
     856            GtkTreeModel * model = tr_core_model( core );
     857
     858            /* remove from the gui */
     859            gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
     860
     861            /* maybe delete the downloaded files */
     862            if( deleteFiles )
     863                tr_torrent_delete_files( gtor );
     864
     865            /* remove the torrent */
     866            tr_torrent_set_remove_flag( gtor, TRUE );
     867            g_object_unref( G_OBJECT( gtor ) );
     868        }
     869    }
     870}
    850871
    851872/***
  • trunk/gtk/tr-core.h

    r6309 r6344  
    144144******/
    145145
     146/* we've gotten notice from RPC that a torrent has been destroyed;
     147   update our gui accordingly */
     148void tr_core_torrent_destroyed( TrCore * self, int id );
     149
     150/* remove a torrent */
    146151void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles );
    147152
  • trunk/gtk/tr-torrent.c

    r6279 r6344  
    8989}
    9090
     91void
     92tr_torrent_clear( TrTorrent * tor )
     93{
     94    g_return_if_fail( tor );
     95    g_return_if_fail( tor->priv );
     96
     97    tor->priv->handle = NULL;
     98}
     99
    91100static void
    92101tr_torrent_class_init( gpointer g_class, gpointer g_class_data UNUSED )
  • trunk/gtk/tr-torrent.h

    r5947 r6344  
    5959tr_torrent_get_type(void);
    6060
     61void
     62tr_torrent_clear( TrTorrent * tor );
     63
    6164tr_torrent *
    6265tr_torrent_handle(TrTorrent *tor);
Note: See TracChangeset for help on using the changeset viewer.