~ampelbein/transmission/bug-726756

« back to all changes in this revision

Viewing changes to gtk/tr-prefs.c

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2010-11-22 17:12:14 UTC
  • mfrom: (1.1.40 upstream) (2.1.25 experimental)
  • Revision ID: james.westby@ubuntu.com-20101122171214-awf9ejuo8v5mgi1i
Tags: 2.12-0ubuntu1
* New upstream release, merged 2.11-1 from Debian experimental
* Remove 0101-fix_dso_linking.patch which has been applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: tr-prefs.c 11253 2010-09-22 16:44:38Z charles $
 
10
 * $Id: tr-prefs.c 11401 2010-11-13 17:05:22Z charles $
11
11
 */
12
12
 
13
13
#include <ctype.h> /* isspace */
245
245
}
246
246
 
247
247
static void
248
 
target_cb( GtkWidget * tb,
249
 
           gpointer    target )
 
248
target_cb( GtkWidget * tb, gpointer target )
250
249
{
251
250
    const gboolean b = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( tb ) );
252
251
 
383
382
    gulong      updateBlocklistTag;
384
383
    GtkWidget * updateBlocklistButton;
385
384
    GtkWidget * updateBlocklistDialog;
 
385
    GtkWidget * label;
386
386
    GtkWidget * check;
387
387
    TrCore    * core;
388
388
};
390
390
static void
391
391
updateBlocklistText( GtkWidget * w, TrCore * core )
392
392
{
 
393
    char buf1[512];
 
394
    char buf2[512];
393
395
    const int n = tr_blocklistGetRuleCount( tr_core_session( core ) );
394
 
    char      buf[512];
395
 
    g_snprintf( buf, sizeof( buf ),
396
 
                gtr_ngettext( "Enable _blocklist (contains %'d rule)",
397
 
                              "Enable _blocklist (contains %'d rules)", n ), n );
398
 
    gtk_button_set_label( GTK_BUTTON( w ), buf );
 
396
    g_snprintf( buf1, sizeof( buf1 ),
 
397
                gtr_ngettext( "Blocklist contains %'d rule",
 
398
                              "Blocklist contains %'d rules", n ), n );
 
399
    g_snprintf( buf2, sizeof( buf2 ), "<i>%s</i>", buf1 );
 
400
    gtk_label_set_markup( GTK_LABEL( w ), buf2 );
399
401
}
400
402
 
401
403
/* prefs dialog is being destroyed, so stop listening to blocklist updates */
423
425
static void
424
426
onBlocklistUpdated( TrCore * core, int n, gpointer gdata )
425
427
{
426
 
    const char * s = gtr_ngettext( "Blocklist now has %'d rule.", "Blocklist now has %'d rules.", n );
 
428
    const tr_bool success = n >= 0;
 
429
    const int count = n >=0 ? n : tr_blocklistGetRuleCount( tr_core_session( core ) );
 
430
    const char * s = gtr_ngettext( "Blocklist has %'d rule.", "Blocklist has %'d rules.", count );
427
431
    struct blocklist_data * data = gdata;
428
432
    GtkMessageDialog * d = GTK_MESSAGE_DIALOG( data->updateBlocklistDialog );
429
433
    gtk_widget_set_sensitive( data->updateBlocklistButton, TRUE );
430
 
    gtk_message_dialog_set_markup( d, _( "<b>Update succeeded!</b>" ) );
431
 
    gtk_message_dialog_format_secondary_text( d, s, n );
432
 
    updateBlocklistText( data->check, core );
 
434
    gtk_message_dialog_set_markup( d, success ? _( "<b>Update succeeded!</b>" ) : _( "<b>Unable to update.</b>" ) );
 
435
    gtk_message_dialog_format_secondary_text( d, s, count );
 
436
    updateBlocklistText( data->label, core );
433
437
}
434
438
 
435
439
/* user pushed a button to update the blocklist */
476
480
static GtkWidget*
477
481
privacyPage( GObject * core )
478
482
{
479
 
    int                     row = 0;
480
 
    const char *            s;
481
 
    GtkWidget *             t;
482
 
    GtkWidget *             w;
483
 
    GtkWidget *             b;
484
 
    GtkWidget *             h;
 
483
    int row = 0;
 
484
    const char * s;
 
485
    GtkWidget * t;
 
486
    GtkWidget * w;
 
487
    GtkWidget * b;
 
488
    GtkWidget * h;
 
489
    GtkWidget * e;
485
490
    struct blocklist_data * data;
486
491
 
487
492
    data = g_new0( struct blocklist_data, 1 );
490
495
    t = hig_workarea_create( );
491
496
    hig_workarea_add_section_title( t, &row, _( "Blocklist" ) );
492
497
 
493
 
    w = new_check_button( "", TR_PREFS_KEY_BLOCKLIST_ENABLED, core );
 
498
    b = new_check_button( _( "Enable _blocklist:" ), TR_PREFS_KEY_BLOCKLIST_ENABLED, core );
 
499
    e = new_entry( TR_PREFS_KEY_BLOCKLIST_URL, core );
 
500
    gtk_widget_set_size_request( e, 300, -1 );
 
501
    hig_workarea_add_row_w( t, &row, b, e, NULL );
 
502
    data->check = b;
 
503
    g_signal_connect( b, "toggled", G_CALLBACK( target_cb ), e );
 
504
    target_cb( b, e );
 
505
 
 
506
    w = gtk_label_new( "" );
 
507
    gtk_misc_set_alignment( GTK_MISC( w ), 0.0f, 0.5f );
494
508
    updateBlocklistText( w, TR_CORE( core ) );
 
509
    data->label = w;
495
510
    h = gtk_hbox_new( FALSE, GUI_PAD_BIG );
496
511
    gtk_box_pack_start( GTK_BOX( h ), w, TRUE, TRUE, 0 );
497
512
    b = data->updateBlocklistButton = gtk_button_new_with_mnemonic( _( "_Update" ) );
498
 
    data->check = w;
499
 
    g_object_set_data( G_OBJECT( b ), "session",
500
 
                      tr_core_session( TR_CORE( core ) ) );
 
513
    g_object_set_data( G_OBJECT( b ), "session", tr_core_session( TR_CORE( core ) ) );
501
514
    g_signal_connect( b, "clicked", G_CALLBACK( onBlocklistUpdate ), data );
 
515
    g_signal_connect( data->check, "toggled", G_CALLBACK( target_cb ), b ); target_cb( data->check, b );
502
516
    gtk_box_pack_start( GTK_BOX( h ), b, FALSE, FALSE, 0 );
503
 
    g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), b );
504
 
    target_cb( w, b );
 
517
    g_signal_connect( data->check, "toggled", G_CALLBACK( target_cb ), w ); target_cb( data->check, w );
505
518
    hig_workarea_add_wide_control( t, &row, h );
506
519
 
507
520
    s = _( "Enable _automatic updates" );
508
521
    w = new_check_button( s, PREF_KEY_BLOCKLIST_UPDATES_ENABLED, core );
509
522
    hig_workarea_add_wide_control( t, &row, w );
510
 
    g_signal_connect( data->check, "toggled", G_CALLBACK( target_cb ), w );
511
 
    target_cb( data->check, w );
 
523
    g_signal_connect( data->check, "toggled", G_CALLBACK( target_cb ), w ); target_cb( data->check, w );
512
524
 
513
525
    hig_workarea_add_section_divider( t, &row );
514
526
    hig_workarea_add_section_title ( t, &row, _( "Privacy" ) );
872
884
}
873
885
 
874
886
/****
875
 
*****  Proxy Tab
876
 
****/
877
 
 
878
 
struct ProxyPage
879
 
{
880
 
    GSList *  proxy_widgets;
881
 
    GSList *  proxy_auth_widgets;
882
 
};
883
 
 
884
 
static void
885
 
refreshProxySensitivity( struct ProxyPage * p )
886
 
{
887
 
    GSList *       l;
888
 
    const gboolean proxy_enabled = pref_flag_get( TR_PREFS_KEY_PROXY_ENABLED );
889
 
    const gboolean proxy_auth_enabled = pref_flag_get( TR_PREFS_KEY_PROXY_AUTH_ENABLED );
890
 
 
891
 
    for( l = p->proxy_widgets; l != NULL; l = l->next )
892
 
        gtk_widget_set_sensitive( GTK_WIDGET( l->data ), proxy_enabled );
893
 
 
894
 
    for( l = p->proxy_auth_widgets; l != NULL; l = l->next )
895
 
        gtk_widget_set_sensitive( GTK_WIDGET( l->data ),
896
 
                                  proxy_enabled && proxy_auth_enabled );
897
 
}
898
 
 
899
 
static void
900
 
onProxyToggled( GtkToggleButton * tb UNUSED,
901
 
                gpointer             user_data )
902
 
{
903
 
    refreshProxySensitivity( user_data );
904
 
}
905
 
 
906
 
static void
907
 
proxyPageFree( gpointer gpage )
908
 
{
909
 
    struct ProxyPage * page = gpage;
910
 
 
911
 
    g_slist_free( page->proxy_widgets );
912
 
    g_slist_free( page->proxy_auth_widgets );
913
 
    g_free( page );
914
 
}
915
 
 
916
 
static GtkWidget*
917
 
proxy_combo_box_new( GObject * core, const char * key )
918
 
{
919
 
    GtkWidget * w =  gtr_combo_box_new_enum( "HTTP",   TR_PROXY_HTTP,
920
 
                                             "SOCKS4", TR_PROXY_SOCKS4,
921
 
                                             "SOCKS5", TR_PROXY_SOCKS5,
922
 
                                             NULL );
923
 
    gtr_combo_box_set_active_enum( GTK_COMBO_BOX( w ), pref_int_get( key ) );
924
 
    g_object_set_data_full( G_OBJECT( w ), PREF_KEY, tr_strdup( key ), g_free );
925
 
    g_signal_connect( w, "changed", G_CALLBACK( onIntComboChanged ), core );
926
 
    return w;
927
 
}
928
 
 
929
 
static GtkWidget*
930
 
trackerPage( GObject * core )
931
 
{
932
 
    int                row = 0;
933
 
    const char *       s;
934
 
    GtkWidget *        t;
935
 
    GtkWidget *        w;
936
 
    struct ProxyPage * page = tr_new0( struct ProxyPage, 1 );
937
 
 
938
 
    t = hig_workarea_create( );
939
 
    hig_workarea_add_section_title ( t, &row, _( "Tracker" ) );
940
 
 
941
 
    s = _( "Connect to tracker via a pro_xy" );
942
 
    w = new_check_button( s, TR_PREFS_KEY_PROXY_ENABLED, core );
943
 
    g_signal_connect( w, "toggled", G_CALLBACK( onProxyToggled ), page );
944
 
    hig_workarea_add_wide_control( t, &row, w );
945
 
 
946
 
    s = _( "Proxy _server:" );
947
 
    w = new_entry( TR_PREFS_KEY_PROXY, core );
948
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
949
 
    w = hig_workarea_add_row( t, &row, s, w, NULL );
950
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
951
 
 
952
 
    w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 0, USHRT_MAX, 1 );
953
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
954
 
    w = hig_workarea_add_row( t, &row, _( "Proxy _port:" ), w, NULL );
955
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
956
 
 
957
 
    s = _( "Proxy _type:" );
958
 
    w = proxy_combo_box_new( core, TR_PREFS_KEY_PROXY_TYPE );
959
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
960
 
    w = hig_workarea_add_row( t, &row, s, w, NULL );
961
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
962
 
 
963
 
    s = _( "Use _authentication" );
964
 
    w = new_check_button( s, TR_PREFS_KEY_PROXY_AUTH_ENABLED, core );
965
 
    g_signal_connect( w, "toggled", G_CALLBACK( onProxyToggled ), page );
966
 
    hig_workarea_add_wide_control( t, &row, w );
967
 
    page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
968
 
 
969
 
    s = _( "_Username:" );
970
 
    w = new_entry( TR_PREFS_KEY_PROXY_USERNAME, core );
971
 
    page->proxy_auth_widgets = g_slist_append( page->proxy_auth_widgets, w );
972
 
    w = hig_workarea_add_row( t, &row, s, w, NULL );
973
 
    page->proxy_auth_widgets = g_slist_append( page->proxy_auth_widgets, w );
974
 
 
975
 
    s = _( "Pass_word:" );
976
 
    w = new_entry( TR_PREFS_KEY_PROXY_PASSWORD, core );
977
 
    gtk_entry_set_visibility( GTK_ENTRY( w ), FALSE );
978
 
    page->proxy_auth_widgets = g_slist_append( page->proxy_auth_widgets, w );
979
 
    w = hig_workarea_add_row( t, &row, s, w, NULL );
980
 
    page->proxy_auth_widgets = g_slist_append( page->proxy_auth_widgets, w );
981
 
 
982
 
    hig_workarea_finish( t, &row );
983
 
    g_object_set_data_full( G_OBJECT( t ), "page", page, proxyPageFree );
984
 
 
985
 
    refreshProxySensitivity( page );
986
 
    return t;
987
 
}
988
 
 
989
 
/****
990
887
*****  Bandwidth Tab
991
888
****/
992
889
 
1322
1219
                                     GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1323
1220
                                     NULL );
1324
1221
    gtk_window_set_role( GTK_WINDOW( d ), "transmission-preferences-dialog" );
1325
 
    gtk_dialog_set_has_separator( GTK_DIALOG( d ), FALSE );
1326
1222
    gtk_container_set_border_width( GTK_CONTAINER( d ), GUI_PAD );
1327
1223
 
1328
1224
    n = gtk_notebook_new( );
1346
1242
    gtk_notebook_append_page( GTK_NOTEBOOK( n ),
1347
1243
                              webPage( core ),
1348
1244
                              gtk_label_new ( _( "Web" ) ) );
1349
 
    gtk_notebook_append_page( GTK_NOTEBOOK( n ),
1350
 
                              trackerPage( core ),
1351
 
                              gtk_label_new ( _( "Proxy" ) ) );
1352
1245
 
1353
1246
    g_signal_connect( d, "response", G_CALLBACK( response_cb ), core );
1354
1247
    gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), n, TRUE, TRUE, 0 );