Changeset 5310


Ignore:
Timestamp:
Mar 19, 2008, 7:23:54 PM (14 years ago)
Author:
charles
Message:

(gtk) make the "new torrent" dialog a little nicer

File:
1 edited

Legend:

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

    r5299 r5310  
    171171
    172172static void
    173 file_selection_changed_cb( GtkFileChooser *chooser, gpointer user_data )
     173onSelectionChanged( GtkFileChooser *chooser, gpointer user_data )
    174174{
    175175    MakeMetaUI * ui = (MakeMetaUI *) user_data;
     
    200200    refreshButtons( ui );
    201201
    202     tr_strlsize( sizeStr, totalSize, sizeof(sizeStr) );
    203     g_snprintf( buf, sizeof( buf ),
    204                 /* %1$s is the torrent size, %2$s is its number of files */
    205                 ngettext( "<i>%1$s; %2$d File</i>",
    206                           "<i>%1$s; %2$d Files</i>", fileCount ),
    207                 sizeStr, fileCount );
     202    if( !filename )
     203        g_snprintf( buf, sizeof( buf ), _( "<i>No files selected</i>" ) );
     204    else {
     205        tr_strlsize( sizeStr, totalSize, sizeof(sizeStr) );
     206        g_snprintf( buf, sizeof( buf ),
     207                    /* %1$s is the torrent size, %2$s is its number of files */
     208                    ngettext( "<i>%1$s; %2$d File</i>",
     209                              "<i>%1$s; %2$d Files</i>", fileCount ),
     210                    sizeStr, fileCount );
     211    }
    208212    gtk_label_set_markup ( GTK_LABEL(ui->size_lb), buf );
    209213
    210     tr_strlsize( sizeStr, pieceSize, sizeof(sizeStr) );
    211     g_snprintf( buf, sizeof( buf ),
    212                 /* %1$s is number of pieces; %2$s is how big each piece is */
    213                 ngettext( "<i>%1$d Piece @ %2$s</i>",
    214                           "<i>%1$d Pieces @ %2$s</i>",
    215                           pieceCount ),
    216                 pieceCount, sizeStr );
     214    if( !filename )
     215        *buf = '\0';
     216    else {
     217        tr_strlsize( sizeStr, pieceSize, sizeof(sizeStr) );
     218        g_snprintf( buf, sizeof( buf ),
     219                    /* %1$s is number of pieces; %2$s is how big each piece is */
     220                    ngettext( "<i>%1$d Piece @ %2$s</i>",
     221                              "<i>%1$d Pieces @ %2$s</i>",
     222                              pieceCount ),
     223                    pieceCount, sizeStr );
     224    }
    217225    gtk_label_set_markup ( GTK_LABEL(ui->pieces_lb), buf );
    218226}
    219227
    220228static void
    221 file_chooser_shown_cb( GtkWidget *w, gpointer folder_toggle )
    222 {
    223     const gboolean isFolder = gtk_toggle_button_get_active( folder_toggle );
    224     gtk_file_chooser_set_action (GTK_FILE_CHOOSER(w), isFolder
    225         ? GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
    226         : GTK_FILE_CHOOSER_ACTION_OPEN );
    227 }
    228 
     229onFileModeToggled( GtkToggleButton * t, gpointer w )
     230{
     231    const gboolean active = gtk_toggle_button_get_active( t );
     232    gtk_widget_set_sensitive( w, active );
     233    if( active )
     234        g_signal_emit_by_name( w, "selection-changed", NULL );
     235}
     236   
    229237GtkWidget*
    230238make_meta_ui( GtkWindow * parent, tr_handle * handle )
    231239{
     240    GSList * group;
    232241    int row = 0;
    233     GtkWidget *d, *t, *w, *h, *rb_file, *rb_dir;
     242    GtkWidget *l, *d, *t, *w, *h;
    234243    GtkBox * main_vbox;
    235     char name[256];
    236244    MakeMetaUI * ui = g_new0 ( MakeMetaUI, 1 );
    237245    ui->handle = handle;
     
    251259    t = hig_workarea_create ();
    252260
    253     hig_workarea_add_section_title (t, &row, _("Files"));
    254 
    255         g_snprintf( name, sizeof(name), "%s:", _("File _Type"));
    256         h = gtk_hbox_new( FALSE, GUI_PAD_SMALL );
    257         w = rb_dir = gtk_radio_button_new_with_mnemonic( NULL, _("Folder"));
    258         gtk_box_pack_start ( GTK_BOX(h), w, FALSE, FALSE, 0 );
    259         w = rb_file = gtk_radio_button_new_with_mnemonic_from_widget( GTK_RADIO_BUTTON(w), _("Single File") );
    260         gtk_box_pack_start ( GTK_BOX(h), w, FALSE, FALSE, 0 );
    261         hig_workarea_add_row (t, &row, name, h, NULL);
    262 
    263         g_snprintf( name, sizeof(name), "%s:", _("_File"));
    264 
    265         w = gtk_file_chooser_dialog_new ( NULL,
    266                                           NULL,
    267                                           GTK_FILE_CHOOSER_ACTION_OPEN,
    268                                           GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
    269                                           GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    270                                           NULL );
    271         g_signal_connect( w, "map", G_CALLBACK(file_chooser_shown_cb), rb_dir );
    272         w = gtk_file_chooser_button_new_with_dialog( w );
    273         g_signal_connect( w, "selection-changed", G_CALLBACK(file_selection_changed_cb), ui );
    274         hig_workarea_add_row (t, &row, name, w, NULL);
    275 
    276         g_snprintf( name, sizeof(name), "<i>%s</i>", _("No files selected"));
     261    hig_workarea_add_section_title (t, &row, _( "Content" ));
     262
     263        l = gtk_radio_button_new_with_mnemonic( NULL, _( "_Single File:" ) );
     264        w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_OPEN );
     265        hig_workarea_add_row_w( t, &row, l, w, NULL );
     266        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( l ) );
     267        g_signal_connect( l, "toggled", G_CALLBACK(onFileModeToggled), w );
     268        g_signal_connect( w, "selection-changed", G_CALLBACK(onSelectionChanged), ui );
     269
     270        l = gtk_radio_button_new_with_mnemonic( group, _( "_Folder:" ) );
     271        w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
     272        hig_workarea_add_row_w( t, &row, l, w, NULL );
     273        g_signal_connect( l, "toggled", G_CALLBACK(onFileModeToggled), w );
     274        g_signal_connect( w, "selection-changed", G_CALLBACK(onSelectionChanged), ui );
     275        gtk_widget_set_sensitive( w, FALSE );
     276
    277277        h = gtk_hbox_new( FALSE, GUI_PAD_SMALL );
    278278        w = ui->size_lb = gtk_label_new (NULL);
    279         gtk_label_set_markup ( GTK_LABEL(w), name );
     279        gtk_label_set_markup ( GTK_LABEL(w), _( "<i>No files selected</i>" ) );
    280280        gtk_box_pack_start( GTK_BOX(h), w, FALSE, FALSE, 0 );
    281281        w = ui->pieces_lb = gtk_label_new (NULL);
     
    288288
    289289    hig_workarea_add_section_divider( t, &row );
    290     hig_workarea_add_section_title (t, &row, _("Torrent"));
    291 
    292         g_snprintf( name, sizeof(name), _("Private to this tracker") );
    293         w = ui->private_check = hig_workarea_add_wide_checkbutton( t, &row, name, FALSE );
    294 
    295         g_snprintf( name, sizeof(name), "%s:", _("Announce _URL"));
     290    hig_workarea_add_section_title (t, &row, _("Metainfo"));
     291
     292        w = ui->private_check = hig_workarea_add_wide_checkbutton( t, &row, _( "_Private to this tracker" ), FALSE );
     293
    296294        w = ui->announce_entry = gtk_entry_new( );
    297295        gtk_entry_set_text(GTK_ENTRY(w), "http://");
    298         hig_workarea_add_row (t, &row, name, w, NULL );
    299 
    300         g_snprintf( name, sizeof(name), "%s:", _("Commen_t"));
     296        hig_workarea_add_row (t, &row, _( "Announce _URL:" ), w, NULL );
     297
    301298        w = ui->comment_entry = gtk_entry_new( );
    302         hig_workarea_add_row (t, &row, name, w, NULL );
     299        hig_workarea_add_row (t, &row, _( "Commen_t:" ), w, NULL );
    303300
    304301    hig_workarea_finish( t, &row );
Note: See TracChangeset for help on using the changeset viewer.