Changeset 3449


Ignore:
Timestamp:
Oct 17, 2007, 6:31:12 PM (14 years ago)
Author:
charles
Message:

(gtk) remember between sessions which column is used for sorting in the main window's torrent list

Location:
trunk/gtk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r3401 r3449  
    651651        PREF_KEY_PEX,
    652652        PREF_KEY_SYSTRAY,
     653        PREF_KEY_SORT_COLUMN,
    653654        PREF_KEY_ENCRYPTED_ONLY
    654655    };
     
    711712            cbdata->icon = NULL;
    712713        }
     714    }
     715    else if( !strcmp( key, PREF_KEY_SORT_COLUMN ) )
     716    {
     717        tr_core_set_sort_column_from_prefs( cbdata->core );
    713718    }
    714719    else if( !strcmp( key, PREF_KEY_PEX ) )
  • trunk/gtk/tr_core.c

    r3435 r3449  
    237237}
    238238
     239#define STR_REVERSE "reverse-"
     240#define STR_PROGRESS "progress"
     241#define STR_NAME "name"
     242
     243static void
     244onSortColumnChanged( GtkTreeSortable * sortable, gpointer unused UNUSED )
     245{
     246    int column;
     247    GtkSortType order;
     248    if( gtk_tree_sortable_get_sort_column_id( sortable, &column, &order ) )
     249    {
     250        GString * gstr = g_string_new( NULL );
     251        switch( column ) {
     252            case MC_PROG_D: g_string_assign( gstr, STR_PROGRESS ); break;
     253            default: g_string_assign( gstr, STR_NAME ); break;
     254        }
     255        if( order == GTK_SORT_DESCENDING )
     256            g_string_prepend( gstr, STR_REVERSE );
     257        pref_string_set( PREF_KEY_SORT_COLUMN, gstr->str );
     258        g_string_free( gstr, TRUE );
     259    }
     260}
     261
     262void
     263tr_core_set_sort_column_from_prefs( TrCore * core )
     264{
     265    char * val = pref_string_get( PREF_KEY_SORT_COLUMN );
     266    char * freeme = val;
     267    gint column;
     268    GtkSortType order = GTK_SORT_ASCENDING;
     269    if( g_str_has_prefix( val, STR_REVERSE ) ) {
     270        order = GTK_SORT_DESCENDING;
     271        val += strlen( STR_REVERSE );
     272    }
     273    if( !strcmp( val, STR_PROGRESS ) )
     274        column = MC_PROG_D;
     275    else /* default */
     276        column = MC_NAME;
     277    gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE( core->model ), column, order );
     278    g_free( freeme );
     279}
     280
    239281static void
    240282tr_core_init( GTypeInstance * instance, gpointer g_class SHUTUP )
     
    266308    g_assert( ALEN( types ) == MC_ROW_COUNT );
    267309    store = gtk_list_store_newv( MC_ROW_COUNT, types );
     310    g_signal_connect( store, "sort-column-changed", G_CALLBACK(onSortColumnChanged), NULL );
    268311
    269312    gtk_tree_sortable_set_sort_func( GTK_TREE_SORTABLE(store),
  • trunk/gtk/tr_core.h

    r3381 r3449  
    181181tr_core_set_pref_int( TrCore * self, const char * key, int val );
    182182
     183void
     184tr_core_set_sort_column_from_prefs( TrCore * core );
     185
    183186/* column names for the model used to store torrent information */
    184187/* keep this in sync with the type array in tr_core_init() in tr_core.c */
  • trunk/gtk/tr_prefs.c

    r3401 r3449  
    4848    pref_int_set_default    ( PREF_KEY_MSGLEVEL, TR_MSG_INF );
    4949
     50    pref_string_set_default ( PREF_KEY_SORT_COLUMN, "name" );
     51
    5052    pref_save( NULL );
    5153}
  • trunk/gtk/tr_prefs.h

    r3209 r3449  
    3636#define PREF_KEY_ENCRYPTED_ONLY    "encrypted-connections-only"
    3737#define PREF_KEY_MSGLEVEL          "debug-message-level"
     38#define PREF_KEY_SORT_COLUMN       "sort-column"
    3839
    3940void tr_prefs_init_global( void );
  • trunk/gtk/tr_window.c

    r3401 r3449  
    174174    char              * str;
    175175
    176     view     = gtk_tree_view_new();
     176    view = gtk_tree_view_new();
    177177
    178178    p->selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(view) );
Note: See TracChangeset for help on using the changeset viewer.