Changeset 12316


Ignore:
Timestamp:
Apr 5, 2011, 3:41:51 PM (11 years ago)
Author:
jordan
Message:

(trunk gtk) more heap pruning: in the main window's torrent list, only update the case-insensitive "collated name" of a torrent when the torrent's metadata changes (such as when a magnet link's metadata finishes downloading).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-core.c

    r12315 r12316  
    894894
    895895/***
    896 ****
    897 ****  ADDING TORRENTS
    898 ****
     896****  METADATA CALLBACK
    899897***/
    900898
     
    909907    return collated;
    910908}
     909
     910struct metadata_callback_data
     911{
     912    TrCore * core;
     913    int torrent_id;
     914};
     915
     916static gboolean
     917find_row_from_torrent_id( GtkTreeModel * model, int id, GtkTreeIter * setme )
     918{
     919    GtkTreeIter iter;
     920    gboolean match = FALSE;
     921
     922    if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
     923    {
     924        int row_id;
     925        gtk_tree_model_get( model, &iter, MC_TORRENT_ID, &row_id, -1 );
     926        match = id == row_id;
     927    }
     928    while( !match && gtk_tree_model_iter_next( model, &iter ) );
     929
     930    if( match )
     931        *setme = iter;
     932
     933    return match;
     934}
     935
     936static gboolean
     937on_torrent_metadata_changed_idle( gpointer gdata )
     938{
     939    struct notify_callback_data * data = gdata;
     940    tr_session * session = gtr_core_session( data->core );
     941    tr_torrent * tor = tr_torrentFindFromId( session, data->torrent_id );
     942
     943    /* update the torrent's collated name */
     944    if( tor != NULL ) {
     945        GtkTreeIter iter;
     946        GtkTreeModel * model = core_raw_model( data->core );
     947        if( find_row_from_torrent_id( model, data->torrent_id, &iter ) ) {
     948            char * collated = get_collated_name( tor );
     949            GtkListStore * store = GTK_LIST_STORE( model );
     950            gtk_list_store_set( store, &iter, MC_NAME_COLLATED, collated, -1 );
     951            g_free( collated );
     952        }
     953    }
     954
     955    /* cleanup */
     956    g_object_unref( G_OBJECT( data->core ) );
     957    g_free( data );
     958    return FALSE;
     959}
     960
     961/* this is called in the libtransmission thread, *NOT* the GTK+ thread,
     962   so delegate to the GTK+ thread before changing our list store... */
     963static void
     964on_torrent_metadata_changed( tr_torrent * tor, void * gcore )
     965{
     966    struct notify_callback_data * data = g_new( struct notify_callback_data, 1 );
     967    data->core = gcore;
     968    data->torrent_id = tr_torrentId( tor );
     969    g_object_ref( G_OBJECT( data->core ) );
     970    gtr_idle_add( on_torrent_metadata_changed_idle, data );
     971}
     972
     973/***
     974****
     975****  ADDING TORRENTS
     976****
     977***/
    911978
    912979static unsigned int
     
    9631030            gtr_notify_torrent_added( name );
    9641031
     1032        tr_torrentSetMetadataCallback( tor, on_torrent_metadata_changed, core );
    9651033        tr_torrentSetCompletenessCallback( tor, on_torrent_completeness_changed, core );
    9661034
     
    12781346}
    12791347
    1280 static gboolean
    1281 find_row_from_torrent_id( GtkTreeModel * model, int id, GtkTreeIter * setme )
    1282 {
    1283     GtkTreeIter iter;
    1284     gboolean match = FALSE;
    1285 
    1286     if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
    1287     {
    1288         int row_id;
    1289         gtk_tree_model_get( model, &iter, MC_TORRENT_ID, &row_id, -1 );
    1290         match = id == row_id;
    1291     }
    1292     while( !match && gtk_tree_model_iter_next( model, &iter ) );
    1293 
    1294     if( match )
    1295         *setme = iter;
    1296 
    1297     return match;
    1298 }
    1299 
    13001348void
    13011349gtr_core_remove_torrent( TrCore * core, int id, gboolean delete_local_data )
     
    13691417    bool oldFinished, newFinished;
    13701418    tr_priority_t oldPriority, newPriority;
    1371     char * oldCollatedName, * newCollatedName;
    13721419    unsigned int oldTrackers, newTrackers;
    13731420    double oldUpSpeed, newUpSpeed;
     
    13811428    gtk_tree_model_get( model, iter,
    13821429                        MC_TORRENT,  &tor,
    1383                         MC_NAME_COLLATED, &oldCollatedName,
    13841430                        MC_ACTIVE, &oldActive,
    13851431                        MC_ACTIVE_PEER_COUNT, &oldActivePeerCount,
     
    14061452    newActivePeerCount = st->peersSendingToUs + st->peersGettingFromUs + st->webseedsSendingToUs;
    14071453    newError = st->error;
    1408     newCollatedName = get_collated_name( tor );
    14091454
    14101455    /* updating the model triggers off resort/refresh,
     
    14171462        || ( newActivePeerCount != oldActivePeerCount )
    14181463        || ( newTrackers != oldTrackers )
    1419         || tr_strcmp0( oldCollatedName, newCollatedName )
    14201464        || gtr_compare_double( newUpSpeed, oldUpSpeed, 3 )
    14211465        || gtr_compare_double( newDownSpeed, oldDownSpeed, 3 )
     
    14271471                            MC_ERROR, newError,
    14281472                            MC_ACTIVITY, newActivity,
    1429                             MC_NAME_COLLATED, newCollatedName,
    14301473                            MC_FINISHED, newFinished,
    14311474                            MC_PRIORITY, newPriority,
     
    14381481
    14391482    /* cleanup */
    1440     g_free( newCollatedName );
    1441     g_free( oldCollatedName );
    14421483    return FALSE;
    14431484}
Note: See TracChangeset for help on using the changeset viewer.