Changeset 12357


Ignore:
Timestamp:
Apr 13, 2011, 10:04:31 PM (11 years ago)
Author:
jordan
Message:

(trunk gtk) Avoid unnecessary GtkComboBox? queries.

Instead of calling gtk_combo_box_get_active_iter() on the filterbar's two comboboxes in every periodic update, keep the state information in a local struct and update it when the selection changes. That way the filter code doesn't even need to know about the GtkComboBox? or the GtkTreeModel?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/filter.c

    r12317 r12357  
    145145     * for the various categories. Also make a sorted list of all tracker
    146146     * hosts s.t. we can merge it with the existing list */
    147     if( gtk_tree_model_get_iter_first( tmodel, &iter )) do
     147    if( gtk_tree_model_iter_nth_child( tmodel, &iter, NULL, 0 ) ) do
    148148    {
    149149        tr_torrent * tor;
     
    523523
    524524static gboolean
    525 testCategory( GtkWidget * category_combo, tr_torrent * tor )
    526 {
    527     int type;
    528     const tr_info * inf;
    529     GtkTreeIter iter;
    530     GtkComboBox * combo = GTK_COMBO_BOX( category_combo );
    531     GtkTreeModel * model = gtk_combo_box_get_model( combo );
    532 
    533     if( !gtk_combo_box_get_active_iter( combo, &iter ) )
    534         return TRUE;
    535 
    536     inf = tr_torrentInfo( tor );
    537     gtk_tree_model_get( model, &iter, CAT_FILTER_COL_TYPE, &type, -1 );
    538     switch( type )
     525test_category( tr_torrent * tor, int active_category_type, const char * host )
     526{
     527    const tr_info * const inf = tr_torrentInfo( tor );
     528
     529    switch( active_category_type )
    539530    {
    540531        case CAT_FILTER_TYPE_ALL:
     
    558549        case CAT_FILTER_TYPE_HOST: {
    559550            int i;
    560             char * host;
    561551            char tmp[1024];
    562             gtk_tree_model_get( model, &iter, CAT_FILTER_COL_HOST, &host, -1 );
    563552            for( i=0; i<inf->trackerCount; ++i ) {
    564553                gtr_get_host_from_url( tmp, sizeof( tmp ), inf->trackers[i].announce );
     
    566555                    break;
    567556            }
    568             g_free( host );
    569557            return i < inf->trackerCount;
    570558        }
     
    655643}
    656644
    657 static gboolean
    658 testActivity( GtkWidget * activity_combo, tr_torrent * tor )
    659 {
    660     int type;
    661     GtkTreeIter iter;
    662     GtkComboBox * combo = GTK_COMBO_BOX( activity_combo );
    663     GtkTreeModel * model = gtk_combo_box_get_model( combo );
    664 
    665     if( !gtk_combo_box_get_active_iter( combo, &iter ) )
    666         return TRUE;
    667 
    668     gtk_tree_model_get( model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1 );
    669     return test_torrent_activity( tor, type );
    670 }
    671 
    672645static void
    673646status_model_update_count( GtkListStore * store, GtkTreeIter * iter, int n )
     
    690663    g_object_steal_qdata( o, DIRTY_KEY );
    691664
    692     if( gtk_tree_model_get_iter_first( model, &iter )) do
     665    if( gtk_tree_model_iter_nth_child( model, &iter, NULL, 0 ) ) do
    693666    {
    694667        int hits;
     
    699672
    700673        hits = 0;
    701         if( gtk_tree_model_get_iter_first( tmodel, &torrent_iter )) do {
     674        if( gtk_tree_model_iter_nth_child( tmodel, &torrent_iter, NULL, 0 ) ) do {
    702675            tr_torrent * tor;
    703676            gtk_tree_model_get( tmodel, &torrent_iter, MC_TORRENT, &tor, -1 );
     
    912885    GtkWidget * entry;
    913886    GtkTreeModel * filter_model;
     887    int active_activity_type;
     888    int active_category_type;
     889    char * active_category_host;
    914890};
    915891
     
    926902    text = (const char*) g_object_get_qdata( o, TEXT_KEY );
    927903
    928     return ( tor != NULL ) && testCategory( data->category, tor )
    929                            && testActivity( data->activity, tor )
     904    return ( tor != NULL ) && test_category( tor, data->active_category_type, data->active_category_host )
     905                           && test_torrent_activity( tor, data->active_activity_type )
    930906                           && testText( tor, text );
    931907}
    932908
    933909static void
    934 selection_changed_cb( GtkComboBox * combo UNUSED, gpointer vdata )
    935 {
     910selection_changed_cb( GtkComboBox * combo, gpointer vdata )
     911{
     912    int type;
     913    char * host;
     914    GtkTreeIter iter;
     915    GtkTreeModel * model;
    936916    struct filter_data * data = vdata;
     917
     918    /* set data->active_activity_type from the activity combobox */
     919    combo = GTK_COMBO_BOX( data->activity );
     920    model = gtk_combo_box_get_model( combo );
     921    if( gtk_combo_box_get_active_iter( combo, &iter ) )
     922        gtk_tree_model_get( model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1 );
     923    else
     924        type = ACTIVITY_FILTER_ALL;
     925    data->active_activity_type = type;
     926
     927    /* set the active category type & host from the category combobox */
     928    combo = GTK_COMBO_BOX( data->category );
     929    model = gtk_combo_box_get_model( combo );
     930    if( gtk_combo_box_get_active_iter( combo, &iter ) ) {
     931        gtk_tree_model_get( model, &iter, CAT_FILTER_COL_TYPE, &type,
     932                                          CAT_FILTER_COL_HOST, &host,
     933                                          -1 );
     934    } else {
     935        type = CAT_FILTER_TYPE_ALL;
     936        host = NULL;
     937    }
     938    g_free( data->active_category_host );
     939    data->active_category_host = host;
     940    data->active_category_type = type;
     941
     942    /* refilter */
    937943    gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( data->filter_model ) );
    938944}
     
    956962    TORRENT_MODEL_KEY = g_quark_from_static_string( "tr-filter-torrent-model-key" );
    957963
    958     data = g_new( struct filter_data, 1 );
     964    data = g_new0( struct filter_data, 1 );
    959965    data->activity = activity = activity_combo_box_new( tmodel );
    960966    data->category = category = category_combo_box_new( tmodel );
    961     data->entry = NULL;
    962967    data->filter_model = gtk_tree_model_filter_new( tmodel, NULL );
    963968
     
    10161021
    10171022    g_signal_connect( s, "changed", G_CALLBACK( filter_entry_changed ), data->filter_model );
     1023    selection_changed_cb( NULL, data );
    10181024
    10191025    *filter_model = data->filter_model;
Note: See TracChangeset for help on using the changeset viewer.