Changeset 5991


Ignore:
Timestamp:
Jun 1, 2008, 3:46:20 PM (14 years ago)
Author:
charles
Message:

(gtk) unclutter the "new torrent" dialog a bit.

Location:
trunk/gtk
Files:
4 edited

Legend:

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

    r5989 r5991  
    2626#define UPDATE_INTERVAL_MSEC 200
    2727
    28 #define BUILDER_KEY "builder"
    2928#define UI_KEY "ui"
    3029
    3130typedef struct
    3231{
     32    GtkWidget * filename_entry;
    3333    GtkWidget * size_lb;
    3434    GtkWidget * pieces_lb;
     
    247247
    248248static void
    249 onSelectionChanged( GtkFileChooser * chooser, gpointer gui )
    250 {
     249onSourceActivated( GtkEditable * editable, gpointer gui )
     250{
     251    const char * filename = gtk_entry_get_text( GTK_ENTRY( editable ) );
    251252    MakeMetaUI * ui = gui;
    252     char * filename = gtk_file_chooser_get_filename( chooser );
    253     tr_metainfo_builder * builder = tr_metaInfoBuilderCreate( ui->handle, filename );
    254 
    255     g_object_set_data_full( G_OBJECT( chooser ),
    256                             BUILDER_KEY,
    257                             builder,
    258                             (GDestroyNotify)tr_metaInfoBuilderFree );
    259     ui->builder = builder;
    260 
     253
     254    if( ui->builder )
     255        tr_metaInfoBuilderFree( ui->builder );
     256    ui->builder = tr_metaInfoBuilderCreate( ui->handle, filename );
    261257    refreshFromBuilder( ui );
    262 
    263     g_free( filename );
    264 }
    265 
    266 static void
    267 onFileModeToggled( GtkToggleButton * t, gpointer w )
    268 {
    269     const gboolean active = gtk_toggle_button_get_active( t );
    270     gtk_widget_set_sensitive( w, active );
    271     if( active )
     258}
     259
     260static gboolean
     261onSourceLostFocus( GtkWidget * w, GdkEventFocus * focus UNUSED, gpointer gui )
     262{
     263    onSourceActivated( GTK_EDITABLE( w ), gui );
     264    return FALSE;
     265}
     266
     267static void
     268onChooseClicked( GtkButton              * button,
     269                 gpointer                 gui,
     270                 const char             * title,
     271                 GtkFileChooserAction     chooserAction )
     272{
     273    GtkWidget * top = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
     274    GtkWidget * d = gtk_file_chooser_dialog_new( title,
     275                                                 GTK_WINDOW( top ),
     276                                                 chooserAction,
     277                                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     278                                                 GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
     279                                                 NULL );
     280    if( gtk_dialog_run( GTK_DIALOG( d ) ) == GTK_RESPONSE_ACCEPT )
    272281    {
    273         MakeMetaUI * ui = g_object_get_data( G_OBJECT( w ), UI_KEY );
    274         ui->builder = g_object_get_data( G_OBJECT( w ), BUILDER_KEY );
    275         refreshFromBuilder( ui );
    276     }
    277 }
    278    
     282        MakeMetaUI * ui = gui;
     283        char * filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( d ) );
     284        gtk_entry_set_text( GTK_ENTRY( ui->filename_entry ), filename );
     285        onSourceActivated( GTK_EDITABLE( ui->filename_entry ), gui );
     286        g_free( filename );
     287    }
     288
     289    gtk_widget_destroy( d );
     290}
     291
     292static void
     293onChooseDirectoryClicked( GtkButton * b, gpointer gui )
     294{
     295    onChooseClicked( b, gui, _( "Choose Directory" ), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
     296}
     297
     298static void
     299onChooseFileClicked( GtkButton * b, gpointer gui )
     300{
     301    onChooseClicked( b, gui, _( "Choose File" ), GTK_FILE_CHOOSER_ACTION_OPEN );
     302}
     303
    279304GtkWidget*
    280305make_meta_ui( GtkWindow * parent, tr_handle * handle )
    281306{
    282     GSList * group;
    283307    int row = 0;
    284     GtkWidget *l, *d, *t, *w, *h;
     308    GtkWidget *d, *t, *w, *h, *h2, *v, *focusMe;
    285309    GtkBox * main_vbox;
    286310    MakeMetaUI * ui = g_new0 ( MakeMetaUI, 1 );
     
    301325    t = hig_workarea_create ();
    302326
    303     hig_workarea_add_section_title (t, &row, _( "Content" ));
    304 
    305         l = gtk_radio_button_new_with_mnemonic( NULL, _( "_Single File:" ) );
    306         w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_OPEN );
    307         g_object_set_data( G_OBJECT( w ), UI_KEY, ui );
    308         hig_workarea_add_row_w( t, &row, l, w, NULL );
    309         group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( l ) );
    310         g_signal_connect( l, "toggled", G_CALLBACK(onFileModeToggled), w );
    311         g_signal_connect( w, "selection-changed", G_CALLBACK(onSelectionChanged), ui );
    312 
    313         l = gtk_radio_button_new_with_mnemonic( group, _( "_Folder:" ) );
    314         w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
    315         g_object_set_data( G_OBJECT( w ), UI_KEY, ui );
    316         hig_workarea_add_row_w( t, &row, l, w, NULL );
    317         g_signal_connect( l, "toggled", G_CALLBACK(onFileModeToggled), w );
    318         g_signal_connect( w, "selection-changed", G_CALLBACK(onSelectionChanged), ui );
    319         gtk_widget_set_sensitive( w, FALSE );
    320 
    321         h = gtk_hbox_new( FALSE, GUI_PAD_SMALL );
     327    hig_workarea_add_section_title (t, &row, _( "Source" ));
     328
     329        h = gtk_hbox_new( FALSE, GUI_PAD );
     330        v = gtk_vbox_new( FALSE, GUI_PAD_SMALL );
     331        w = ui->filename_entry = gtk_entry_new( );
     332        g_signal_connect( w, "activate", G_CALLBACK( onSourceActivated ), ui );
     333        g_signal_connect( w, "focus-out-event", G_CALLBACK( onSourceLostFocus ), ui );
     334        gtk_box_pack_start( GTK_BOX( v ), w, FALSE, FALSE, 0 );
     335        h2 = gtk_hbox_new( FALSE, GUI_PAD_SMALL );
    322336        w = ui->size_lb = gtk_label_new (NULL);
    323337        gtk_label_set_markup ( GTK_LABEL(w), _( "<i>No files selected</i>" ) );
    324         gtk_box_pack_start( GTK_BOX(h), w, FALSE, FALSE, 0 );
     338        gtk_box_pack_start( GTK_BOX(h2), w, FALSE, FALSE, GUI_PAD_SMALL );
    325339        w = ui->pieces_lb = gtk_label_new (NULL);
    326         gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, 0 );
    327         w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     340        gtk_box_pack_end( GTK_BOX(h2), w, FALSE, FALSE, GUI_PAD_SMALL );
     341        w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
    328342        gtk_widget_set_size_request (w, 2 * GUI_PAD_BIG, 0);
    329         gtk_box_pack_start_defaults ( GTK_BOX(h), w );
    330         hig_workarea_add_row (t, &row, "", h, NULL);
    331        
     343        gtk_box_pack_start_defaults ( GTK_BOX(h2), w );
     344        gtk_box_pack_start( GTK_BOX( v ), h2, FALSE, FALSE, 0 );
     345        gtk_box_pack_start_defaults( GTK_BOX( h ), v );
     346        v = gtk_vbox_new( FALSE, GUI_PAD_SMALL );
     347        w = tr_button_new_from_stock( GTK_STOCK_DIRECTORY, _( "F_older" ) );
     348        focusMe = w;
     349        g_signal_connect( w, "clicked", G_CALLBACK( onChooseDirectoryClicked ), ui );
     350        gtk_box_pack_start_defaults( GTK_BOX( v ), w );
     351        w = tr_button_new_from_stock( GTK_STOCK_FILE, _( "_File" ) );
     352        g_signal_connect( w, "clicked", G_CALLBACK( onChooseFileClicked ), ui );
     353        gtk_box_pack_start_defaults( GTK_BOX( v ), w );
     354        gtk_box_pack_start( GTK_BOX( h ), v, FALSE, FALSE, 0 );
     355        hig_workarea_add_wide_control( t, &row, h );
    332356
    333357    hig_workarea_add_section_divider( t, &row );
    334     hig_workarea_add_section_title (t, &row, _("Tracker"));
    335 
    336         w = ui->private_check = hig_workarea_add_wide_checkbutton( t, &row, _( "_Private to this tracker" ), FALSE );
    337 
    338         w = tracker_list_new( NULL, GTK_POS_LEFT );
     358    hig_workarea_add_section_title( t, &row, _( "Trackers" ) );
     359
     360        w = tracker_list_new( NULL, GTK_POS_RIGHT );
    339361        ui->announce_list = w;
    340         hig_workarea_add_wide_control (t, &row, w );
     362        hig_workarea_add_wide_control( t, &row, w );
    341363
    342364    hig_workarea_add_section_divider( t, &row );
    343     hig_workarea_add_section_title (t, &row, _("Optional Information"));
     365    hig_workarea_add_section_title( t, &row, _( "Options" ) );
    344366
    345367        w = ui->comment_entry = gtk_entry_new( );
    346368        hig_workarea_add_row (t, &row, _( "Commen_t:" ), w, NULL );
     369
     370        w = hig_workarea_add_wide_checkbutton( t, &row, _( "_Private torrent" ), FALSE );
     371        ui->private_check = w;
     372 
    347373
    348374    hig_workarea_finish( t, &row );
     
    359385    gtk_box_pack_start( main_vbox, w, FALSE, FALSE, GUI_PAD_BIG );
    360386
    361     gtk_window_set_default_size( GTK_WINDOW(d), 400u, 0u );
     387    gtk_window_set_default_size( GTK_WINDOW(d), 500, 0 );
    362388    gtk_widget_show_all( GTK_DIALOG(d)->vbox );
    363389    setIsBuilding( ui, FALSE );
     390    gtk_widget_grab_focus( focusMe );
    364391    return d;
    365392}
  • trunk/gtk/tracker-list.c

    r5989 r5991  
    255255    GtkWidget * w;
    256256    GtkWidget * buttons;
     257    GtkWidget * box;
    257258    GtkWidget * top;
    258259    GtkWidget * fr;
     
    265266    page->gtor = gtor;
    266267
    267     top = buttonPos == GTK_POS_LEFT || buttonPos == GTK_POS_RIGHT
    268         ? gtk_hbox_new( FALSE, GUI_PAD )
    269         : gtk_vbox_new( FALSE, GUI_PAD );
    270 
    271     buttons = buttonPos == GTK_POS_LEFT || buttonPos == GTK_POS_RIGHT
    272         ? gtk_vbox_new( FALSE, 0 )
    273         : gtk_hbox_new( FALSE, 0 );
     268    if( buttonPos == GTK_POS_LEFT || buttonPos == GTK_POS_RIGHT )
     269    {
     270        top = gtk_hbox_new( FALSE, GUI_PAD );
     271        box = gtk_vbox_new( FALSE, GUI_PAD );
     272        buttons = gtk_vbox_new( TRUE, GUI_PAD );
     273    }
     274    else
     275    {
     276        top = gtk_vbox_new( FALSE, GUI_PAD );
     277        box = gtk_hbox_new( FALSE, 0 );
     278        buttons = gtk_hbox_new( TRUE, GUI_PAD );
     279    }
    274280
    275281    m = tracker_model_new( tr_torrent_handle( gtor ) );
     
    318324    w = gtk_button_new_from_stock( GTK_STOCK_ADD );
    319325    g_signal_connect( w, "clicked", G_CALLBACK( onTrackerAddClicked ), page );
    320     gtk_box_pack_start( GTK_BOX( buttons ), w, FALSE, FALSE, 0 );
     326    gtk_box_pack_start_defaults( GTK_BOX( buttons ), w );
    321327    page->add_button = w;
    322328    w = gtk_button_new_from_stock( GTK_STOCK_REMOVE );
    323329    g_signal_connect( w, "clicked", G_CALLBACK( onTrackerRemoveClicked ), page );
    324     gtk_box_pack_start( GTK_BOX( buttons ), w, FALSE, FALSE, 0 );
     330    gtk_box_pack_start_defaults( GTK_BOX( buttons ), w );
    325331    page->remove_button = w;
    326332    if( gtor )
     
    329335        g_signal_connect( w, "clicked", G_CALLBACK( onTrackerSaveClicked ), page );
    330336        gtk_widget_set_sensitive( w, FALSE );
    331         gtk_box_pack_start( GTK_BOX( buttons ), w, FALSE, FALSE, 0 );
     337        gtk_box_pack_start_defaults( GTK_BOX( buttons ), w );
    332338        page->save_button = w;
    333339
     
    335341        g_signal_connect( w, "clicked", G_CALLBACK( onTrackerRevertClicked ), page );
    336342        gtk_widget_set_sensitive( w, FALSE );
    337         gtk_box_pack_start( GTK_BOX( buttons ), w, FALSE, FALSE, 0 );
     343        gtk_box_pack_start_defaults( GTK_BOX( buttons ), w );
    338344        page->revert_button = w;
    339345    }
    340346
    341     w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
    342     gtk_box_pack_start_defaults( GTK_BOX( buttons ), w );
    343 
    344     if( buttonPos == GTK_POS_LEFT || buttonPos == GTK_POS_TOP )
    345     {
    346         gtk_box_pack_start( GTK_BOX( top ), buttons, FALSE, FALSE, 0 );
     347   
     348    if( buttonPos == GTK_POS_LEFT || buttonPos == GTK_POS_RIGHT ) {
     349        gtk_box_pack_start( GTK_BOX( box ), buttons, FALSE, FALSE, 0 );
     350    } else {
     351        gtk_box_pack_end( GTK_BOX( box ), buttons, FALSE, FALSE, 0 );
     352    }
     353
     354    if( buttonPos == GTK_POS_LEFT || buttonPos == GTK_POS_TOP ) {
     355        gtk_box_pack_start( GTK_BOX( top ), box, FALSE, FALSE, 0 );
    347356        gtk_box_pack_start_defaults( GTK_BOX( top ), fr );
    348     }
    349     else
    350     {
     357    } else {
    351358        gtk_box_pack_start_defaults( GTK_BOX( top ), fr );
    352         gtk_box_pack_start( GTK_BOX( top ), buttons, FALSE, FALSE, 0 );
     359        gtk_box_pack_start( GTK_BOX( top ), box, FALSE, FALSE, 0 );
    353360    }
    354361
  • trunk/gtk/util.c

    r5928 r5991  
    4444
    4545#include "conf.h"
     46#include "hig.h"
    4647#include "tr-prefs.h"
    4748#include "util.h"
     
    478479    return success;
    479480}
     481
     482GtkWidget *
     483tr_button_new_from_stock( const char * stock,
     484                          const char * mnemonic )
     485{
     486    GtkWidget * button = gtk_button_new( );
     487    GtkWidget * label = gtk_label_new_with_mnemonic( mnemonic );
     488    gtk_label_set_mnemonic_widget( GTK_LABEL( label ), GTK_WIDGET( button ) );
     489
     490    GtkWidget * image = gtk_image_new_from_stock( stock, GTK_ICON_SIZE_BUTTON );
     491    GtkWidget * hbox = gtk_hbox_new( FALSE, GUI_PAD );
     492    GtkWidget * align = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 );
     493
     494    gtk_box_pack_start( GTK_BOX( hbox ), image, FALSE, FALSE, 0 );
     495    gtk_box_pack_end( GTK_BOX( hbox ), label, FALSE, FALSE, 0 );
     496
     497    gtk_container_add( GTK_CONTAINER( align ), hbox );
     498    gtk_container_add( GTK_CONTAINER( button ), align );
     499    gtk_widget_show_all( align );
     500
     501    return button;
     502}
  • trunk/gtk/util.h

    r5928 r5991  
    8989#ifdef GTK_MAJOR_VERSION
    9090
     91GtkWidget * tr_button_new_from_stock( const char * stock,
     92                                      const char * mnemonic );
     93
    9194/* create an error dialog, if wind is NULL or mapped then show dialog now,
    9295   otherwise show it when wind becomes mapped */
Note: See TracChangeset for help on using the changeset viewer.