Changeset 5765


Ignore:
Timestamp:
May 7, 2008, 4:06:07 AM (14 years ago)
Author:
charles
Message:

(gtk) #906: Making a new torrent folder scans the entire home directory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/makemeta-ui.c

    r5636 r5765  
    2525#define UPDATE_INTERVAL_MSEC 200
    2626
     27#define BUILDER_KEY "builder"
     28#define UI_KEY "ui"
     29
    2730typedef struct
    2831{
     
    4649{
    4750    MakeMetaUI * ui = p;
    48     tr_metaInfoBuilderFree( ui->builder );
    4951    memset( ui, ~0, sizeof(MakeMetaUI) );
    5052    g_free( ui );
     
    8082    char buf[1024];
    8183    double fraction;
    82     MakeMetaUI * ui = (MakeMetaUI *) user_data;
     84    MakeMetaUI * ui = user_data;
    8385    GtkProgressBar * p = GTK_PROGRESS_BAR( ui->progressbar );
    8486
     
    140142response_cb( GtkDialog* d, int response, gpointer user_data )
    141143{
    142     MakeMetaUI * ui = (MakeMetaUI*) user_data;
     144    MakeMetaUI * ui = user_data;
    143145    char *tmp;
    144146    char buf[1024];
     
    191193
    192194static void
    193 onSelectionChanged( GtkFileChooser *chooser, gpointer user_data )
    194 {
    195     MakeMetaUI * ui = (MakeMetaUI *) user_data;
    196     char * filename;
     195refreshFromBuilder( MakeMetaUI * ui )
     196{
    197197    char sizeStr[128];
    198198    char buf[MAX_PATH_LENGTH];
    199     uint64_t totalSize=0;
    200     int fileCount=0, pieceCount=0, pieceSize=0;
    201 
    202     if( ui->builder ) {
    203         tr_metaInfoBuilderFree( ui->builder );
    204         ui->builder = NULL;
    205     }
    206 
    207     filename = gtk_file_chooser_get_filename( chooser );
     199    tr_metainfo_builder * builder = ui->builder;
     200    const char * filename = builder ? builder->top : NULL;
     201
    208202    if( !filename )
    209203        g_snprintf( buf, sizeof( buf ), _( "No files selected" ) );
    210     else {
    211         ui->builder = tr_metaInfoBuilderCreate( ui->handle, filename );
     204    else
    212205        g_snprintf( buf, sizeof(buf), "%s.torrent (%d%%)", filename, 0 );
    213         g_free( filename );
    214         fileCount = ui->builder->fileCount;
    215         totalSize = ui->builder->totalSize;
    216         pieceCount = ui->builder->pieceCount;
    217         pieceSize = ui->builder->pieceSize;
    218     }
    219206    gtk_progress_bar_set_text( GTK_PROGRESS_BAR( ui->progressbar ), buf );
    220207    refreshButtons( ui );
     
    223210        g_snprintf( buf, sizeof( buf ), _( "<i>No files selected</i>" ) );
    224211    else {
    225         tr_strlsize( sizeStr, totalSize, sizeof(sizeStr) );
     212        tr_strlsize( sizeStr, builder->totalSize, sizeof(sizeStr) );
    226213        g_snprintf( buf, sizeof( buf ),
    227214                    /* %1$s is the torrent size
    228215                       %2$'d is its number of files */
    229216                    ngettext( "<i>%1$s; %2$'d File</i>",
    230                               "<i>%1$s; %2$'d Files</i>", fileCount ),
    231                     sizeStr, fileCount );
     217                              "<i>%1$s; %2$'d Files</i>", builder->fileCount ),
     218                    sizeStr, builder->fileCount );
    232219    }
    233220    gtk_label_set_markup ( GTK_LABEL(ui->size_lb), buf );
     
    236223        *buf = '\0';
    237224    else {
    238         tr_strlsize( sizeStr, pieceSize, sizeof(sizeStr) );
     225        tr_strlsize( sizeStr, builder->pieceSize, sizeof(sizeStr) );
    239226        g_snprintf( buf, sizeof( buf ),
    240227                    /* %1$'s is number of pieces;
     
    242229                    ngettext( "<i>%1$'d Piece @ %2$s</i>",
    243230                              "<i>%1$'d Pieces @ %2$s</i>",
    244                               pieceCount ),
    245                     pieceCount, sizeStr );
     231                              builder->pieceCount ),
     232                    builder->pieceCount, sizeStr );
    246233    }
    247234    gtk_label_set_markup ( GTK_LABEL(ui->pieces_lb), buf );
     235}
     236
     237static void
     238onSelectionChanged( GtkFileChooser * chooser, gpointer gui )
     239{
     240    MakeMetaUI * ui = gui;
     241    char * filename = gtk_file_chooser_get_filename( chooser );
     242    tr_metainfo_builder * builder = tr_metaInfoBuilderCreate( ui->handle, filename );
     243
     244    g_object_set_data_full( G_OBJECT( chooser ),
     245                            BUILDER_KEY,
     246                            builder,
     247                            (GDestroyNotify)tr_metaInfoBuilderFree );
     248    ui->builder = builder;
     249
     250    refreshFromBuilder( ui );
     251
     252    g_free( filename );
    248253}
    249254
     
    254259    gtk_widget_set_sensitive( w, active );
    255260    if( active )
    256         g_signal_emit_by_name( w, "selection-changed", NULL );
     261    {
     262        MakeMetaUI * ui = g_object_get_data( G_OBJECT( w ), UI_KEY );
     263        ui->builder = g_object_get_data( G_OBJECT( w ), BUILDER_KEY );
     264        refreshFromBuilder( ui );
     265    }
    257266}
    258267   
     
    285294        l = gtk_radio_button_new_with_mnemonic( NULL, _( "_Single File:" ) );
    286295        w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_OPEN );
     296        g_object_set_data( G_OBJECT( w ), UI_KEY, ui );
    287297        hig_workarea_add_row_w( t, &row, l, w, NULL );
    288298        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( l ) );
     
    292302        l = gtk_radio_button_new_with_mnemonic( group, _( "_Folder:" ) );
    293303        w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
     304        g_object_set_data( G_OBJECT( w ), UI_KEY, ui );
    294305        hig_workarea_add_row_w( t, &row, l, w, NULL );
    295306        g_signal_connect( l, "toggled", G_CALLBACK(onFileModeToggled), w );
Note: See TracChangeset for help on using the changeset viewer.