Changeset 6278


Ignore:
Timestamp:
Jul 2, 2008, 12:17:27 AM (13 years ago)
Author:
charles
Message:

(gtk) #1043: Include recent folders in the destination folder chooser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/add-dialog.c

    r6162 r6278  
    1919#include "tr-prefs.h"
    2020
     21/****
     22*****
     23****/
     24
     25#define N_RECENT 4
     26
     27static GSList*
     28get_recent_destinations( void )
     29{
     30    int i;
     31    GSList * list = NULL;
     32    for( i=0; i<N_RECENT; ++i )
     33    {
     34        char key[64];
     35        const char * val;
     36        g_snprintf( key, sizeof(key), "recent-download-dir-%d", i+1 );
     37        if(( val = pref_string_get( key )))
     38            list = g_slist_append( list, (void*)val );
     39    }
     40    return list;
     41}
     42
     43static void
     44save_recent_destination( const char * dir  )
     45{
     46    int i;
     47    GSList * list = get_recent_destinations( );
     48    GSList * l;
     49
     50    if( !dir )
     51        return;
     52
     53    /* if it was already in the list, remove it */
     54    if(( l = g_slist_find_custom( list, dir, (GCompareFunc)strcmp )))
     55        list = g_slist_delete_link( list, l );
     56
     57    /* add it to the front of the list */
     58    list = g_slist_prepend( list, (void*)dir );
     59
     60    /* make local copies of the strings that aren't
     61     * invalidated by pref_string_set() */
     62    for( l=list; l; l=l->next )
     63         l->data = g_strdup( l->data );
     64
     65    /* save the first N_RECENT directories */
     66    for( l=list, i=0; l && (i<N_RECENT); ++i, l=l->next ) {
     67        char key[64];
     68        g_snprintf( key, sizeof(key), "recent-download-dir-%d", i+1 );
     69        pref_string_set( key, l->data );
     70    }
     71    pref_save( );
     72
     73    /* cleanup */
     74    g_slist_foreach( list, (GFunc)g_free, NULL );
     75    g_slist_free( list );
     76}
     77
     78/****
     79*****
     80****/
     81
    2182struct AddData
    2283{
     
    59120            if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->trash_check ) ) )
    60121                tr_file_trash_or_unlink( data->filename );
     122            save_recent_destination( data->downloadDir );
    61123        }
    62124    }
     
    161223    struct AddData * data;
    162224    uint8_t flag;
     225    GSList * list;
     226    GSList * walk;
    163227
    164228    /* make the dialog */
     
    221285    if( !gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( w ), data->downloadDir ) )
    222286        g_warning( "couldn't select '%s'", data->downloadDir );
     287    list = get_recent_destinations( );
     288    for( walk=list; walk; walk=walk->next )
     289        gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER( w ), walk->data, NULL );
     290    g_slist_free( list );
    223291    gtk_table_attach( GTK_TABLE( t ), w, col, col+1, row, row+1, ~0, 0, 0, 0 );
    224292    gtk_label_set_mnemonic_widget( GTK_LABEL( l ), w );
Note: See TracChangeset for help on using the changeset viewer.