Changeset 10425


Ignore:
Timestamp:
Mar 27, 2010, 2:52:10 AM (12 years ago)
Author:
charles
Message:

(trunk gtk) rename the "State" filter as the "Activity" filter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/filter.c

    r10395 r10425  
    602602/***
    603603****
    604 ****  STATES
     604****  ACTIVITY
    605605****
    606606***/
     
    608608enum
    609609{
    610     STATE_FILTER_ALL,
    611     STATE_FILTER_DOWNLOADING,
    612     STATE_FILTER_SEEDING,
    613     STATE_FILTER_ACTIVE,
    614     STATE_FILTER_PAUSED,
    615     STATE_FILTER_QUEUED,
    616     STATE_FILTER_VERIFYING,
    617     STATE_FILTER_ERROR,
    618     STATE_FILTER_SEPARATOR
     610    ACTIVITY_FILTER_ALL,
     611    ACTIVITY_FILTER_DOWNLOADING,
     612    ACTIVITY_FILTER_SEEDING,
     613    ACTIVITY_FILTER_ACTIVE,
     614    ACTIVITY_FILTER_PAUSED,
     615    ACTIVITY_FILTER_QUEUED,
     616    ACTIVITY_FILTER_VERIFYING,
     617    ACTIVITY_FILTER_ERROR,
     618    ACTIVITY_FILTER_SEPARATOR
    619619};
    620620
    621621enum
    622622{
    623     STATE_FILTER_COL_NAME,
    624     STATE_FILTER_COL_COUNT,
    625     STATE_FILTER_COL_TYPE,
    626     STATE_FILTER_N_COLS
     623    ACTIVITY_FILTER_COL_NAME,
     624    ACTIVITY_FILTER_COL_COUNT,
     625    ACTIVITY_FILTER_COL_TYPE,
     626    ACTIVITY_FILTER_N_COLS
    627627};
    628628
    629629static gboolean
    630 state_is_it_a_separator( GtkTreeModel * m, GtkTreeIter * i, gpointer d UNUSED )
     630activity_is_it_a_separator( GtkTreeModel * m, GtkTreeIter * i, gpointer d UNUSED )
    631631{
    632632    int type;
    633     gtk_tree_model_get( m, i, STATE_FILTER_COL_TYPE, &type, -1 );
    634     return type == STATE_FILTER_SEPARATOR;
     633    gtk_tree_model_get( m, i, ACTIVITY_FILTER_COL_TYPE, &type, -1 );
     634    return type == ACTIVITY_FILTER_SEPARATOR;
    635635}
    636636
    637637static gboolean
    638 test_torrent_state( tr_torrent * tor, int type )
     638test_torrent_activity( tr_torrent * tor, int type )
    639639{
    640640    const tr_stat * st = tr_torrentStat( tor );
     
    642642    switch( type )
    643643    {
    644         case STATE_FILTER_DOWNLOADING:
     644        case ACTIVITY_FILTER_DOWNLOADING:
    645645            return st->activity == TR_STATUS_DOWNLOAD;
    646646
    647         case STATE_FILTER_SEEDING:
     647        case ACTIVITY_FILTER_SEEDING:
    648648            return st->activity == TR_STATUS_SEED;
    649649
    650         case STATE_FILTER_ACTIVE:
     650        case ACTIVITY_FILTER_ACTIVE:
    651651            return ( st->peersSendingToUs > 0 )
    652652                || ( st->peersGettingFromUs > 0 )
    653653                || ( st->activity == TR_STATUS_CHECK );
    654654
    655         case STATE_FILTER_PAUSED:
     655        case ACTIVITY_FILTER_PAUSED:
    656656            return st->activity == TR_STATUS_STOPPED;
    657657
    658         case STATE_FILTER_QUEUED:
     658        case ACTIVITY_FILTER_QUEUED:
    659659            return FALSE;
    660660
    661         case STATE_FILTER_VERIFYING:
     661        case ACTIVITY_FILTER_VERIFYING:
    662662            return ( st->activity == TR_STATUS_CHECK_WAIT )
    663663                || ( st->activity == TR_STATUS_CHECK );
    664664
    665         case STATE_FILTER_ERROR:
     665        case ACTIVITY_FILTER_ERROR:
    666666            return st->error != 0;
    667667
    668         default: /* STATE_FILTER_ALL */
     668        default: /* ACTIVITY_FILTER_ALL */
    669669            return TRUE;
    670670
     
    673673
    674674static gboolean
    675 testState( GtkWidget * state_combo, tr_torrent * tor )
     675testActivity( GtkWidget * activity_combo, tr_torrent * tor )
    676676{
    677677    int type;
    678678    GtkTreeIter iter;
    679     GtkComboBox * combo = GTK_COMBO_BOX( state_combo );
     679    GtkComboBox * combo = GTK_COMBO_BOX( activity_combo );
    680680    GtkTreeModel * model = gtk_combo_box_get_model( combo );
    681681
     
    683683        return TRUE;
    684684
    685     gtk_tree_model_get( model, &iter, STATE_FILTER_COL_TYPE, &type, -1 );
    686     return test_torrent_state( tor, type );
     685    gtk_tree_model_get( model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1 );
     686    return test_torrent_activity( tor, type );
    687687}
    688688
     
    692692    int count;
    693693    GtkTreeModel * model = GTK_TREE_MODEL( store );
    694     gtk_tree_model_get( model, iter, STATE_FILTER_COL_COUNT, &count, -1 );
     694    gtk_tree_model_get( model, iter, ACTIVITY_FILTER_COL_COUNT, &count, -1 );
    695695    if( n != count )
    696         gtk_list_store_set( store, iter, STATE_FILTER_COL_COUNT, n, -1 );
    697 }
    698 
    699 static void
    700 state_filter_model_update( GtkListStore * store )
     696        gtk_list_store_set( store, iter, ACTIVITY_FILTER_COL_COUNT, n, -1 );
     697}
     698
     699static void
     700activity_filter_model_update( GtkListStore * store )
    701701{
    702702    GtkTreeIter iter;
     
    713713        GtkTreeIter torrent_iter;
    714714
    715         gtk_tree_model_get( model, &iter, STATE_FILTER_COL_TYPE, &type, -1 );
     715        gtk_tree_model_get( model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1 );
    716716
    717717        hits = 0;
     
    719719            tr_torrent * tor;
    720720            gtk_tree_model_get( tmodel, &torrent_iter, MC_TORRENT_RAW, &tor, -1 );
    721             if( test_torrent_state( tor, type ) )
     721            if( test_torrent_activity( tor, type ) )
    722722                ++hits;
    723723        } while( gtk_tree_model_iter_next( tmodel, &torrent_iter ) );
     
    729729
    730730static GtkTreeModel *
    731 state_filter_model_new( GtkTreeModel * tmodel )
     731activity_filter_model_new( GtkTreeModel * tmodel )
    732732{
    733733    int i, n;
     
    736736        const char * name;
    737737    } types[] = {
    738         { STATE_FILTER_ALL, N_( "All" ) },
    739         { STATE_FILTER_SEPARATOR, NULL },
    740         { STATE_FILTER_DOWNLOADING, N_( "Downloading" ) },
    741         { STATE_FILTER_SEEDING, N_( "Seeding" ) },
    742         { STATE_FILTER_ACTIVE, N_( "Active" ) },
    743         { STATE_FILTER_PAUSED, N_( "Paused" ) },
    744         { STATE_FILTER_QUEUED, N_( "Queued" ) },
    745         { STATE_FILTER_VERIFYING, N_( "Verifying" ) },
    746         { STATE_FILTER_ERROR, N_( "Error" ) }
     738        { ACTIVITY_FILTER_ALL, N_( "All" ) },
     739        { ACTIVITY_FILTER_SEPARATOR, NULL },
     740        { ACTIVITY_FILTER_DOWNLOADING, N_( "Downloading" ) },
     741        { ACTIVITY_FILTER_SEEDING, N_( "Seeding" ) },
     742        { ACTIVITY_FILTER_ACTIVE, N_( "Active" ) },
     743        { ACTIVITY_FILTER_PAUSED, N_( "Paused" ) },
     744        { ACTIVITY_FILTER_QUEUED, N_( "Queued" ) },
     745        { ACTIVITY_FILTER_VERIFYING, N_( "Verifying" ) },
     746        { ACTIVITY_FILTER_ERROR, N_( "Error" ) }
    747747    };
    748748    GtkListStore * store;
    749749
    750     store = gtk_list_store_new( STATE_FILTER_N_COLS,
     750    store = gtk_list_store_new( ACTIVITY_FILTER_N_COLS,
    751751                                G_TYPE_STRING,
    752752                                G_TYPE_INT,
     
    754754    for( i=0, n=G_N_ELEMENTS(types); i<n; ++i )
    755755        gtk_list_store_insert_with_values( store, NULL, -1,
    756             STATE_FILTER_COL_NAME, _( types[i].name ),
    757             STATE_FILTER_COL_TYPE, types[i].type,
     756            ACTIVITY_FILTER_COL_NAME, _( types[i].name ),
     757            ACTIVITY_FILTER_COL_TYPE, types[i].type,
    758758            -1 );
    759759
    760760    g_object_set_data( G_OBJECT( store ), TORRENT_MODEL_KEY, tmodel );
    761     state_filter_model_update( store );
     761    activity_filter_model_update( store );
    762762    return GTK_TREE_MODEL( store );
    763763}
    764764
    765765static void
    766 state_model_update_idle( gpointer state_model )
    767 {
    768     GObject * o = G_OBJECT( state_model );
     766activity_model_update_idle( gpointer activity_model )
     767{
     768    GObject * o = G_OBJECT( activity_model );
    769769    const gboolean pending = g_object_get_data( o, DIRTY_KEY ) != NULL;
    770770    if( !pending )
    771771    {
    772         GSourceFunc func = (GSourceFunc) state_filter_model_update;
     772        GSourceFunc func = (GSourceFunc) activity_filter_model_update;
    773773        g_object_set_data( o, DIRTY_KEY, GINT_TO_POINTER(1) );
    774         gtr_idle_add( func, state_model );
     774        gtr_idle_add( func, activity_model );
    775775    }
    776776}
    777777
    778778static void
    779 state_torrent_model_row_changed( GtkTreeModel  * tmodel UNUSED,
    780                                  GtkTreePath   * path UNUSED,
    781                                  GtkTreeIter   * iter UNUSED,
    782                                  gpointer        state_model )
    783 {
    784     state_model_update_idle( state_model );
    785 }
    786 
    787 static void
    788 state_torrent_model_row_deleted_cb( GtkTreeModel  * tmodel UNUSED,
     779activity_torrent_model_row_changed( GtkTreeModel  * tmodel UNUSED,
    789780                                    GtkTreePath   * path UNUSED,
    790                                     gpointer        state_model )
    791 {
    792     state_model_update_idle( state_model );
     781                                    GtkTreeIter   * iter UNUSED,
     782                                    gpointer        activity_model )
     783{
     784    activity_model_update_idle( activity_model );
     785}
     786
     787static void
     788activity_torrent_model_row_deleted_cb( GtkTreeModel  * tmodel UNUSED,
     789                                       GtkTreePath   * path UNUSED,
     790                                       gpointer        activity_model )
     791{
     792    activity_model_update_idle( activity_model );
    793793}
    794794
    795795static GtkWidget *
    796 state_combo_box_new( GtkTreeModel * tmodel )
     796activity_combo_box_new( GtkTreeModel * tmodel )
    797797{
    798798    GtkWidget * c;
    799799    GtkCellRenderer * r;
    800     GtkTreeModel * state_model;
    801 
    802     state_model = state_filter_model_new( tmodel );
    803     c = gtk_combo_box_new_with_model( state_model );
     800    GtkTreeModel * activity_model;
     801
     802    activity_model = activity_filter_model_new( tmodel );
     803    c = gtk_combo_box_new_with_model( activity_model );
    804804    gtk_combo_box_set_row_separator_func( GTK_COMBO_BOX( c ),
    805                                           state_is_it_a_separator, NULL, NULL );
     805                                       activity_is_it_a_separator, NULL, NULL );
    806806    gtk_combo_box_set_active( GTK_COMBO_BOX( c ), 0 );
    807807
     
    809809    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( c ), r, TRUE );
    810810    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( c ), r,
    811                                     "text", STATE_FILTER_COL_NAME,
     811                                    "text", ACTIVITY_FILTER_COL_NAME,
    812812                                    NULL );
    813813
     
    818818
    819819    g_signal_connect( tmodel, "row-changed",
    820                       G_CALLBACK( state_torrent_model_row_changed ), state_model );
     820                      G_CALLBACK( activity_torrent_model_row_changed ),
     821                      activity_model );
    821822    g_signal_connect( tmodel, "row-inserted",
    822                       G_CALLBACK( state_torrent_model_row_changed ), state_model );
     823                      G_CALLBACK( activity_torrent_model_row_changed ),
     824                      activity_model );
    823825    g_signal_connect( tmodel, "row-deleted",
    824                       G_CALLBACK( state_torrent_model_row_deleted_cb ), state_model );
     826                      G_CALLBACK( activity_torrent_model_row_deleted_cb ),
     827                      activity_model );
    825828
    826829    return c;
     
    938941struct filter_data
    939942{
    940     GtkWidget * state;
     943    GtkWidget * activity;
    941944    GtkWidget * category;
    942945    GtkWidget * entry;
     
    959962
    960963    return ( tor != NULL ) && testCategory( data->category, tor )
    961                            && testState( data->state, tor )
     964                           && testActivity( data->activity, tor )
    962965                           && testText( tor, text, mode );
    963966}
     
    979982    GtkWidget * s;
    980983    GtkWidget * menu;
    981     GtkWidget * state;
     984    GtkWidget * activity;
    982985    GtkWidget * category;
    983986    GSList * sl;
     
    990993
    991994    data = g_new( struct filter_data, 1 );
    992     data->state = state = state_combo_box_new( tmodel );
     995    data->activity = activity = activity_combo_box_new( tmodel );
    993996    data->category = category = category_combo_box_new( tmodel );
    994997    data->entry = NULL;
     
    10031006
    10041007    g_signal_connect( data->category, "changed", G_CALLBACK( selection_changed_cb ), data );
    1005     g_signal_connect( data->state, "changed", G_CALLBACK( selection_changed_cb ), data );
     1008    g_signal_connect( data->activity, "changed", G_CALLBACK( selection_changed_cb ), data );
    10061009
    10071010
     
    10221025    gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    10231026
    1024     /* add the state combobox */
    1025     str = _( "_State:" );
    1026     w = state;
     1027    /* add the activity combobox */
     1028    str = _( "_Activity:" );
     1029    w = activity;
    10271030    l = gtk_label_new( NULL );
    10281031    gtk_label_set_markup_with_mnemonic( GTK_LABEL( l ), str );
Note: See TracChangeset for help on using the changeset viewer.