Changeset 8195


Ignore:
Timestamp:
Apr 10, 2009, 4:22:57 AM (13 years ago)
Author:
charles
Message:

(trunk gtk) remember filtering mode between sessions

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/conf.c

    r8159 r8195  
    196196    tr_bencDictAddBool( d, PREF_KEY_ASKQUIT, TRUE );
    197197
     198    tr_bencDictAddStr( d, PREF_KEY_FILTER_MODE, "show-all" );
    198199    tr_bencDictAddStr( d, PREF_KEY_SORT_MODE, "sort-by-name" );
    199200    tr_bencDictAddBool( d, PREF_KEY_SORT_REVERSED, FALSE );
  • trunk/gtk/tr-prefs.h

    r8088 r8195  
    3434#define PREF_KEY_SORT_MODE                  "sort-mode"
    3535#define PREF_KEY_SORT_REVERSED              "sort-reversed"
     36#define PREF_KEY_FILTER_MODE                "filter-mode"
    3637#define PREF_KEY_MINIMAL_VIEW               "minimal-view"
    3738#define PREF_KEY_FILTERBAR                  "show-filterbar"
  • trunk/gtk/tr-window.c

    r8192 r8195  
    9595    filter_text_mode_t    filter_text_mode;
    9696    char *                filter_text;
     97    GtkToggleButton     * filter_toggles[FILTER_MODE_QTY];
    9798}
    9899PrivateData;
    99100
     101static const char*
     102getFilterName( int mode )
     103{
     104    switch( mode )
     105    {
     106        case FILTER_MODE_ACTIVE:      return "show-active";
     107        case FILTER_MODE_DOWNLOADING: return "show-downloading";
     108        case FILTER_MODE_SEEDING:     return "show-seeding";
     109        case FILTER_MODE_PAUSED:      return "show-paused";
     110        default:                      return "show-active"; /* the fallback */
     111    }
     112}
     113static int
     114getFilterModeFromName( const char * name )
     115{
     116    if( !strcmp( name, "show-active"      ) ) return FILTER_MODE_ACTIVE;
     117    if( !strcmp( name, "show-downloading" ) ) return FILTER_MODE_DOWNLOADING;
     118    if( !strcmp( name, "show-seeding"     ) ) return FILTER_MODE_SEEDING;
     119    if( !strcmp( name, "show-paused"      ) ) return FILTER_MODE_PAUSED;
     120    return FILTER_MODE_ALL; /* the fallback */
     121}
     122
    100123#define PRIVATE_DATA_KEY "private-data"
    101 
    102124#define FILTER_MODE_KEY "tr-filter-mode"
    103125#define FILTER_TEXT_MODE_KEY "tr-filter-text-mode"
    104 #define FILTER_TOGGLES_KEY "tr-filter-toggles"
    105126
    106127static PrivateData*
     
    197218
    198219static void syncAltSpeedButton( PrivateData * p );
     220static void setFilter( PrivateData * p, int mode );
    199221
    200222static void
     
    212234         * for that, but it *does* revalidate when it thinks the style's been tweaked */
    213235        g_signal_emit_by_name( p->view, "style-set", NULL, NULL );
     236    }
     237    else if( !strcmp( key, PREF_KEY_FILTER_MODE ) )
     238    {
     239        setFilter( p, getFilterModeFromName( pref_string_get( key ) ) );
    214240    }
    215241    else if( !strcmp( key, PREF_KEY_STATUSBAR ) )
     
    425451
    426452static void
    427 filter_toggled_cb( GtkToggleButton * toggle,
    428                    gpointer          vprivate )
    429 {
    430     PrivateData *       p = vprivate;
    431     GSList *            l;
    432     GSList *            toggles = g_object_get_data( G_OBJECT(
    433                                                          toggle ),
    434                                                      FILTER_TOGGLES_KEY );
    435     const gboolean      isActive = gtk_toggle_button_get_active( toggle );
    436     const filter_mode_t mode =
    437         GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( toggle ),
    438                                              FILTER_MODE_KEY ) );
    439 
    440     /* update the filter */
    441     if( isActive )
    442     {
     453setFilter( PrivateData * p, int mode )
     454{
     455    if( mode != (int)p->filter_mode )
     456    {
     457        int i;
     458
     459        /* refilter */
    443460        p->filter_mode = mode;
    444461        refilter( p );
    445     }
    446 
    447     /* deactivate the other toggles */
    448     for( l = toggles; l != NULL; l = l->next )
    449     {
    450         GtkToggleButton * walk = GTK_TOGGLE_BUTTON( l->data );
    451         if( isActive && ( toggle != walk ) )
    452             gtk_toggle_button_set_active( walk, FALSE );
    453     }
    454 
    455     /* at least one button must always be set */
    456     if( !isActive && ( p->filter_mode == mode ) )
    457         gtk_toggle_button_set_active( toggle, TRUE );
     462
     463        /* update the prefs */
     464        tr_core_set_pref( p->core, PREF_KEY_FILTER_MODE, getFilterName( mode ) );
     465
     466        /* update the togglebuttons */
     467        for( i=0; i<FILTER_MODE_QTY; ++i )
     468            gtk_toggle_button_set_active( p->filter_toggles[i], i==mode );
     469    }
     470}
     471 
     472
     473static void
     474filter_toggled_cb( GtkToggleButton * toggle, gpointer vprivate )
     475{
     476    if( gtk_toggle_button_get_active( toggle ) )
     477    {
     478        PrivateData * p = vprivate;
     479        const int mode = GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( toggle ), FILTER_MODE_KEY ) );
     480        setFilter( p, mode );
     481    }
    458482}
    459483
     
    566590    GtkWindow *   win;
    567591    GSList *      l;
    568     GSList *      toggles;
    569592
    570593    const char *  filter_names[FILTER_MODE_QTY] = {
     
    585608
    586609    p = g_new0( PrivateData, 1 );
    587     p->filter_mode = FILTER_MODE_ALL;
    588610    p->filter_text_mode = FILTER_TEXT_MODE_NAME;
    589611    p->filter_text = NULL;
     
    619641
    620642    /* filter */
    621     toggles = NULL;
    622643    h = filter = p->filter = gtk_hbox_new( FALSE, 0 );
    623644    gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
     
    626647        const char * mnemonic = _( filter_names[i] );
    627648        w = gtk_toggle_button_new_with_mnemonic( mnemonic );
    628         g_object_set_data( G_OBJECT( w ), FILTER_MODE_KEY,
    629                           GINT_TO_POINTER( i ) );
     649        g_object_set_data( G_OBJECT( w ), FILTER_MODE_KEY, GINT_TO_POINTER( i ) );
    630650        gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
    631         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(
    632                                           w ), i == FILTER_MODE_ALL );
    633         toggles = g_slist_prepend( toggles, w );
     651        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), i == FILTER_MODE_ALL );
     652        p->filter_toggles[i] = GTK_TOGGLE_BUTTON( w );
    634653        g_signal_connect( w, "toggled", G_CALLBACK( filter_toggled_cb ), p );
    635654        gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    636655    }
    637     for( l = toggles; l != NULL; l = l->next )
    638         g_object_set_data( G_OBJECT( l->data ), FILTER_TOGGLES_KEY, toggles );
     656
    639657    s = sexy_icon_entry_new( );
    640658    sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY( s ) );
     
    764782    prefsChanged( core, PREF_KEY_STATUSBAR_STATS, self );
    765783    prefsChanged( core, PREF_KEY_TOOLBAR, self );
     784    prefsChanged( core, PREF_KEY_FILTER_MODE, self );
    766785    prefsChanged( core, TR_PREFS_KEY_ALT_SPEED_ENABLED, self );
    767786    p->pref_handler_id = g_signal_connect( core, "prefs-changed",
Note: See TracChangeset for help on using the changeset viewer.