Changeset 8253


Ignore:
Timestamp:
Apr 18, 2009, 11:14:57 PM (13 years ago)
Author:
charles
Message:

(trunk gtk) make the gtk client's preferences dialog's encryption combobox match the qt client's

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-prefs.c

    r8211 r8253  
    430430
    431431static void
    432 onEncryptionToggled( GtkToggleButton * w,
    433                      gpointer          core )
    434 {
    435     const int val = gtk_toggle_button_get_active( w )
    436                   ? TR_ENCRYPTION_REQUIRED
    437                   : TR_ENCRYPTION_PREFERRED;
    438     tr_core_set_pref_int( TR_CORE( core ), TR_PREFS_KEY_ENCRYPTION, val );
     432onIntComboChanged( GtkComboBox * w, gpointer core )
     433{
     434    GtkTreeIter iter;
     435
     436    if( gtk_combo_box_get_active_iter( w, &iter ) )
     437    {
     438        int val = 0;
     439        const char * key = g_object_get_data( G_OBJECT( w ), PREF_KEY );
     440        gtk_tree_model_get( gtk_combo_box_get_model( w ), &iter, 0, &val, -1 );
     441        tr_core_set_pref_int( TR_CORE( core ), key, val );
     442    }
     443}
     444
     445static GtkWidget*
     446new_encryption_combo( GObject * core, const char * key )
     447{
     448    int i;
     449    int selIndex;
     450    GtkWidget * w;
     451    GtkCellRenderer * r;
     452    GtkListStore * store;
     453    const int currentValue = pref_int_get( key );
     454    const struct {
     455        int value;
     456        const char * text;
     457    } items[] = {
     458        { TR_CLEAR_PREFERRED,      N_( "Plaintext Preferred" )  },
     459        { TR_ENCRYPTION_PREFERRED, N_( "Encryption Preferred" ) },
     460        { TR_ENCRYPTION_REQUIRED,  N_( "Encryption Required" )  }
     461    };
     462
     463    /* build a store for encryption */
     464    selIndex = -1;
     465    store = gtk_list_store_new( 2, G_TYPE_INT, G_TYPE_STRING );
     466    for( i=0; i<(int)G_N_ELEMENTS(items); ++i ) {
     467        GtkTreeIter iter;
     468        gtk_list_store_append( store, &iter );
     469        gtk_list_store_set( store, &iter, 0, items[i].value, 1, _( items[i].text ), -1 );
     470        if( items[i].value == currentValue )
     471            selIndex = i;
     472    }
     473
     474    /* build the widget */
     475    w = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
     476    r = gtk_cell_renderer_text_new( );
     477    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( w ), r, TRUE );
     478    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( w ), r, "text", 1, NULL );
     479    g_object_set_data_full( G_OBJECT( w ), PREF_KEY, tr_strdup( key ), g_free );
     480    if( selIndex >= 0 )
     481        gtk_combo_box_set_active( GTK_COMBO_BOX( w ), selIndex );
     482    g_signal_connect( w, "changed", G_CALLBACK( onIntComboChanged ), core );
     483
     484    /* cleanup */
     485    g_object_unref( G_OBJECT( store ) );
     486    return w;
    439487}
    440488
     
    487535    hig_workarea_add_section_title ( t, &row, _( "Privacy" ) );
    488536
    489     s = _( "_Ignore unencrypted peers" );
    490     w = gtk_check_button_new_with_mnemonic( s );
    491     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ),
    492                                   pref_int_get( TR_PREFS_KEY_ENCRYPTION ) ==
    493                                   TR_ENCRYPTION_REQUIRED );
    494     g_signal_connect( w, "toggled", G_CALLBACK( onEncryptionToggled ), core );
    495     hig_workarea_add_wide_control( t, &row, w );
     537    s = _( "_Encryption mode" );
     538    w = new_encryption_combo( core, "encryption" );
     539    hig_workarea_add_row( t, &row, s, w, NULL );
    496540
    497541    s = _( "Use peer e_xchange" );
     
    10541098    g_object_unref( G_OBJECT( store ) );
    10551099    return w;
    1056 }
    1057 
    1058 static void
    1059 onWeekComboChanged( GtkComboBox * w, gpointer core )
    1060 {
    1061     GtkTreeIter iter;
    1062 
    1063     if( gtk_combo_box_get_active_iter( w, &iter ) )
    1064     {
    1065         int val = 0;
    1066         const char * key = g_object_get_data( G_OBJECT( w ), PREF_KEY );
    1067         gtk_tree_model_get( gtk_combo_box_get_model( w ), &iter, 0, &val, -1 );
    1068         tr_core_set_pref_int( TR_CORE( core ), key, val );
    1069     }
    10701100}
    10711101
     
    11141144    if( selIndex >= 0 )
    11151145        gtk_combo_box_set_active( GTK_COMBO_BOX( w ), selIndex );
    1116     g_signal_connect( w, "changed", G_CALLBACK( onWeekComboChanged ), core );
     1146    g_signal_connect( w, "changed", G_CALLBACK( onIntComboChanged ), core );
    11171147
    11181148    /* cleanup */
Note: See TracChangeset for help on using the changeset viewer.