Changeset 8238


Ignore:
Timestamp:
Apr 15, 2009, 4:28:04 AM (13 years ago)
Author:
charles
Message:

(trunk gtk) #1522: Lack of fast bw limit settings and display

Location:
trunk/gtk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/Makefile.am

    r8174 r8238  
    4949    msgwin.h \
    5050    notify.h \
     51    options-icon.h \
    5152    stats.h \
    5253    sexy-icon-entry.h \
  • trunk/gtk/actions.c

    r8097 r8238  
    2121#include "lock.h"
    2222#include "logo.h"
     23#include "options-icon.h"
    2324#include "turtles.h"
    2425
     
    142143    { tr_icon_logo, "transmission"      },
    143144    { tr_icon_lock, "transmission-lock" },
     145    { options_icon, "options"           },
    144146    { blue_turtle,  "alt-speed-on"      },
    145147    { grey_turtle,  "alt-speed-off"     }
  • trunk/gtk/tr-window.c

    r8195 r8238  
    7474typedef struct
    7575{
     76    GtkWidget *           ratio_on_item;
     77    GtkWidget *           ratio_off_item;
     78    GtkWidget *           downlimit_on_item;
     79    GtkWidget *           downlimit_off_item;
     80    GtkWidget *           uplimit_on_item;
     81    GtkWidget *           uplimit_off_item;
    7682    GtkWidget *           scroll;
    7783    GtkWidget *           view;
     
    8692    GtkWidget *           alt_speed_image[2]; /* 0==off, 1==on */
    8793    GtkWidget *           alt_speed_button;
     94    GtkWidget *           options_menu;
    8895    GtkTreeSelection *    selection;
    8996    GtkCellRenderer *     renderer;
     
    574581{
    575582    g_idle_add( onAltSpeedToggledIdle, p );
     583}
     584
     585#define ENABLED_KEY "enabled-key"
     586#define SPEED_KEY "speed-key"
     587
     588static void
     589onSpeedLimitToggled( GtkCheckMenuItem * check, tr_direction direction, gpointer vp )
     590{
     591    PrivateData * p = vp;
     592    if( gtk_check_menu_item_get_active( check ) )
     593    {
     594        const gboolean isEnabled = g_object_get_data( G_OBJECT( check ), ENABLED_KEY ) != 0;
     595        const char * key = direction == TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
     596        tr_core_set_pref_bool( p->core, key, isEnabled );
     597    }
     598}
     599static void
     600onSpeedLimitSet( GtkCheckMenuItem * check, tr_direction direction, gpointer vp )
     601{
     602    PrivateData * p = vp;
     603    gpointer d = g_object_get_data( G_OBJECT( check ), SPEED_KEY );
     604    const int kb = GPOINTER_TO_INT( d );
     605    const char * key = direction == TR_UP ? TR_PREFS_KEY_USPEED : TR_PREFS_KEY_DSPEED;
     606    tr_core_set_pref_int( p->core, key, kb );
     607}
     608static void
     609onUploadLimitedToggled( GtkCheckMenuItem * check, gpointer p )
     610{
     611    onSpeedLimitToggled( check, TR_UP, p );
     612}
     613static void
     614onUploadLimitSet( GtkCheckMenuItem * check, gpointer vp )
     615{
     616    PrivateData * p = vp;
     617    onSpeedLimitSet( check, TR_UP, p );
     618    tr_core_set_pref_bool( p->core, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
     619}
     620static void
     621onDownloadLimitedToggled( GtkCheckMenuItem * check, gpointer p )
     622{
     623    onSpeedLimitToggled( check, TR_DOWN, p );
     624}
     625static void
     626onDownloadLimitSet( GtkCheckMenuItem * check, gpointer vp )
     627{
     628    PrivateData * p = vp;
     629    onSpeedLimitSet( check, TR_DOWN, p );
     630    tr_core_set_pref_bool( p->core, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
     631}
     632static void
     633onRatioToggled( GtkCheckMenuItem * check, gpointer vp )
     634{
     635    PrivateData * p = vp;
     636    if( gtk_check_menu_item_get_active( check ) )
     637    {
     638        const gboolean isEnabled = g_object_get_data( G_OBJECT( check ), ENABLED_KEY ) != 0;
     639        tr_core_set_pref_bool( p->core, TR_PREFS_KEY_RATIO_ENABLED, isEnabled );
     640    }
     641}
     642static void
     643onRatioSet( GtkCheckMenuItem * check, gpointer vp )
     644{
     645    PrivateData * p = vp;
     646    gpointer d = g_object_get_data( G_OBJECT( check ), SPEED_KEY );
     647    const int ratio = GPOINTER_TO_INT( d );
     648    tr_core_set_pref_double( p->core, TR_PREFS_KEY_RATIO, ratio/100.0 );
     649}
     650
     651static GtkWidget*
     652createOptionsMenu( PrivateData * p )
     653{
     654    int i, n;
     655    GtkWidget *sub, *w, *up, *down;
     656    GtkWidget * top = gtk_menu_new( );
     657    const int stockSpeeds[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
     658    const int stockRatios[] = { 25, 50, 75, 100, 150, 200, 300 };
     659
     660    down = gtk_menu_item_new_with_label( _( "Limit Download Speed" ) );
     661    gtk_menu_shell_append( GTK_MENU_SHELL( top ), down );
     662    gtk_widget_show( down );
     663
     664    sub = gtk_menu_new( );
     665
     666    w = p->downlimit_off_item = gtk_radio_menu_item_new_with_label( NULL, _( "Unlimited" ) );
     667    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     668    gtk_widget_show( w );
     669    g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( 0 ) );
     670    g_signal_connect( w, "toggled", G_CALLBACK(onDownloadLimitedToggled), p );
     671
     672    w = p->downlimit_on_item = gtk_radio_menu_item_new_with_label_from_widget( GTK_RADIO_MENU_ITEM( w ), _( "Limit at XXX" ) );
     673    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     674    gtk_widget_show( w );
     675    g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( 1 ) );
     676    g_signal_connect( w, "toggled", G_CALLBACK(onDownloadLimitedToggled), p );
     677
     678    w = gtk_separator_menu_item_new( );
     679    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     680    gtk_widget_show( w );
     681
     682    for( i=0, n=G_N_ELEMENTS(stockSpeeds); i<n; ++i ) {
     683        char buf[128];
     684        tr_strlspeed( buf, stockSpeeds[i], sizeof( buf ) );
     685        w = gtk_menu_item_new_with_label( buf );
     686        gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     687        gtk_widget_show( w );
     688        g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( stockSpeeds[i] ) );
     689        g_signal_connect( w, "activate", G_CALLBACK(onDownloadLimitSet), p );
     690    }
     691
     692    gtk_menu_item_set_submenu( GTK_MENU_ITEM( down ), sub );
     693
     694    up = gtk_menu_item_new_with_label( _( "Limit Upload Speed" ) );
     695    gtk_menu_shell_append( GTK_MENU_SHELL( top ), up );
     696    gtk_widget_show( up );
     697
     698    sub = gtk_menu_new( );
     699
     700    w = p->uplimit_off_item = gtk_radio_menu_item_new_with_label( NULL, _( "Unlimited" ) );
     701    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     702    gtk_widget_show( w );
     703    g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( 0 ) );
     704    g_signal_connect( w, "toggled", G_CALLBACK(onUploadLimitedToggled), p );
     705
     706    w = p->uplimit_on_item = gtk_radio_menu_item_new_with_label_from_widget( GTK_RADIO_MENU_ITEM( w ), _( "Limit at XXX" ) );
     707    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     708    gtk_widget_show( w );
     709    g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( 1 ) );
     710    g_signal_connect( w, "toggled", G_CALLBACK(onUploadLimitedToggled), p );
     711
     712    w = gtk_separator_menu_item_new( );
     713    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     714    gtk_widget_show( w );
     715
     716    for( i=0, n=G_N_ELEMENTS(stockSpeeds); i<n; ++i ) {
     717        char buf[128];
     718        tr_strlspeed( buf, stockSpeeds[i], sizeof( buf ) );
     719        w = gtk_menu_item_new_with_label( buf );
     720        gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     721        gtk_widget_show( w );
     722        g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( stockSpeeds[i] ) );
     723        g_signal_connect( w, "activate", G_CALLBACK(onUploadLimitSet), p );
     724    }
     725    gtk_menu_item_set_submenu( GTK_MENU_ITEM( up ), sub );
     726
     727    w = gtk_separator_menu_item_new( );
     728    gtk_menu_shell_append( GTK_MENU_SHELL( top ), w );
     729    gtk_widget_show( w );
     730
     731    up = gtk_menu_item_new_with_label( _( "Stop Seeding at Ratio" ) );
     732    gtk_menu_shell_append( GTK_MENU_SHELL( top ), up );
     733    gtk_widget_show( up );
     734
     735    sub = gtk_menu_new( );
     736
     737    w = p->ratio_off_item = gtk_radio_menu_item_new_with_label( NULL, _( "Seed Forever" ) );
     738    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     739    gtk_widget_show( w );
     740    g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( 0 ) );
     741    g_signal_connect( w, "toggled", G_CALLBACK(onRatioToggled), p );
     742
     743    w = p->ratio_on_item = gtk_radio_menu_item_new_with_label_from_widget( GTK_RADIO_MENU_ITEM( w ), _( "Stop at Ratio (XXX)" ) );
     744    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     745    gtk_widget_show( w );
     746    g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( 1 ) );
     747    g_signal_connect( w, "toggled", G_CALLBACK(onRatioToggled), p );
     748
     749    w = gtk_separator_menu_item_new( );
     750    gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     751    gtk_widget_show( w );
     752
     753    for( i=0, n=G_N_ELEMENTS(stockRatios); i<n; ++i ) {
     754        char buf[128];
     755        tr_strlratio( buf, stockRatios[i]/100.0, sizeof( buf ) );
     756        w = gtk_menu_item_new_with_label( buf );
     757        gtk_menu_shell_append( GTK_MENU_SHELL( sub ), w );
     758        gtk_widget_show( w );
     759        g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( stockRatios[i] ) );
     760        g_signal_connect( w, "activate", G_CALLBACK(onRatioSet), p );
     761    }
     762    gtk_menu_item_set_submenu( GTK_MENU_ITEM( up ), sub );
     763
     764    return top;
     765}
     766
     767static void
     768onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
     769{
     770    char buf1[512];
     771    char buf2[512];
     772    gboolean b;
     773    PrivateData * p = vp;
     774
     775    tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_DSPEED ), sizeof( buf1 ) );
     776    g_snprintf( buf2, sizeof( buf2 ), _( "Limited to %s" ), buf1 );
     777    gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( p->downlimit_on_item ) ) ), buf2 );
     778
     779    b = pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED );
     780    gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( b ? p->downlimit_on_item : p->downlimit_off_item ), TRUE );
     781
     782    tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_USPEED ), sizeof( buf1 ) );
     783    g_snprintf( buf2, sizeof( buf2 ), _( "Limited to %s" ), buf1 );
     784    gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( p->uplimit_on_item ) ) ), buf2 );
     785
     786    b = pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED );
     787    gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( b ? p->uplimit_on_item : p->uplimit_off_item ), TRUE );
     788
     789    tr_strlratio( buf1, pref_double_get( TR_PREFS_KEY_RATIO ), sizeof( buf1 ) );
     790    g_snprintf( buf2, sizeof( buf2 ), _( "Stop at Ratio (%s)" ), buf1 );
     791    gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( p->ratio_on_item ) ) ), buf2 );
     792
     793    b = pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED );
     794    gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( b ? p->ratio_on_item : p->ratio_off_item ), TRUE );
     795
     796    gtk_menu_popup ( GTK_MENU( p->options_menu ), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time( ) );
    576797}
    577798
     
    690911    h = status = p->status = gtk_hbox_new( FALSE, GUI_PAD );
    691912    gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
    692     p->alt_speed_image[0] = gtk_image_new_from_stock( "alt-speed-off", -1 );
    693     p->alt_speed_image[1]  = gtk_image_new_from_stock( "alt-speed-on", -1 );
    694     w = p->alt_speed_button = gtk_toggle_button_new( );
    695     /*gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );*/
    696     g_object_ref( G_OBJECT( p->alt_speed_image[0] ) );
    697     g_object_ref( G_OBJECT( p->alt_speed_image[1] ) );
    698     g_signal_connect( w, "toggled", G_CALLBACK(alt_speed_toggled_cb ), p );
    699     gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
    700     w = p->gutter_lb = gtk_label_new( "N Torrents" );
    701     gtk_box_pack_start( GTK_BOX( h ), w, 1, 1, GUI_PAD_BIG );
    702     w = p->ul_lb = gtk_label_new( NULL );
    703     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    704     w = gtk_image_new_from_stock( GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU );
    705     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    706     w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
    707     gtk_widget_set_size_request( w, GUI_PAD, 0u );
    708     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    709     w = p->dl_lb = gtk_label_new( NULL );
    710     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    711     w = gtk_image_new_from_stock( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU );
    712     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    713     w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
    714     gtk_widget_set_size_request( w, GUI_PAD, 0u );
    715     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    716     w = p->stats_lb = gtk_label_new( NULL );
    717     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    718     w = gtk_image_new_from_stock( GTK_STOCK_REFRESH, GTK_ICON_SIZE_MENU );
    719     c = gtk_event_box_new( );
    720     gtk_container_add( GTK_CONTAINER( c ), w );
    721     w = c;
    722     gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    723     g_signal_connect( w, "button-release-event",
    724                       G_CALLBACK( onYinYangReleased ), p );
     913
     914        w = gtk_button_new( );
     915        gtk_container_add( GTK_CONTAINER( w ), gtk_image_new_from_stock( "options", GTK_ICON_SIZE_SMALL_TOOLBAR ) );
     916        gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
     917        gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
     918        p->options_menu = createOptionsMenu( p );
     919        g_signal_connect( w, "clicked", G_CALLBACK(onOptionsClicked), p );
     920
     921        p->alt_speed_image[0] = gtk_image_new_from_stock( "alt-speed-off", -1 );
     922        p->alt_speed_image[1]  = gtk_image_new_from_stock( "alt-speed-on", -1 );
     923        w = p->alt_speed_button = gtk_toggle_button_new( );
     924        gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
     925        g_object_ref( G_OBJECT( p->alt_speed_image[0] ) );
     926        g_object_ref( G_OBJECT( p->alt_speed_image[1] ) );
     927        g_signal_connect( w, "toggled", G_CALLBACK(alt_speed_toggled_cb ), p );
     928        gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
     929
     930        w = p->gutter_lb = gtk_label_new( "N Torrents" );
     931        gtk_box_pack_start( GTK_BOX( h ), w, 1, 1, GUI_PAD_BIG );
     932
     933        w = p->ul_lb = gtk_label_new( NULL );
     934        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     935        w = gtk_image_new_from_stock( GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU );
     936        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     937
     938        w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
     939        gtk_widget_set_size_request( w, GUI_PAD, 0u );
     940        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     941        w = p->dl_lb = gtk_label_new( NULL );
     942        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     943
     944        w = gtk_image_new_from_stock( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU );
     945        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     946        w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
     947        gtk_widget_set_size_request( w, GUI_PAD, 0u );
     948        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     949        w = p->stats_lb = gtk_label_new( NULL );
     950        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     951
     952        w = gtk_image_new_from_stock( GTK_STOCK_REFRESH, GTK_ICON_SIZE_MENU );
     953        c = gtk_event_box_new( );
     954        gtk_container_add( GTK_CONTAINER( c ), w );
     955        w = c;
     956        gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     957        g_signal_connect( w, "button-release-event", G_CALLBACK( onYinYangReleased ), p );
    725958
    726959    menu = gtk_menu_new( );
Note: See TracChangeset for help on using the changeset viewer.