Changeset 8097


Ignore:
Timestamp:
Mar 28, 2009, 4:47:01 PM (13 years ago)
Author:
charles
Message:

(trunk) more speedlimit work

Location:
trunk
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/rpc-spec.txt

    r8096 r8097  
    9999   ----------------------------------+-------------------------------------------------
    100100   "downloadLimit"                   | number     maximum download speed (in K/s)
    101    "downloadLimitHonored"            | 'boolean'  true if "downloadLimit" is honored
    102    "downloadGlobalHonored"           | 'boolean'  true if global speed limit is honored
     101   "downloadLimited"                 | 'boolean'  true if "downloadLimit" is honored
    103102   "files-wanted"                    | array      indices of file(s) to download
    104103   "files-unwanted"                  | array      indices of file(s) to not download
     104   "honorsSessionLimits"             | 'boolean'  true if session upload limits are honored
    105105   "ids"                             | array      torrent list, as described in 3.1
    106106   "peer-limit"                      | number     maximum number of peers
     
    109109   "priority-normal"                 | array      indices of normal-priority file(s)
    110110   "uploadLimit"                     | number     maximum upload speed (in K/s)
    111    "uploadLimitHonored"              | 'boolean'  true if "uploadLimit" is honored
    112    "uploadGlobalHonored"             | 'boolean'  true if global speed limit is honored
     111   "uploadLimited"                   | 'boolean'  true if "uploadLimit" is honored
    113112
    114113   Just as an empty "ids" value is shorthand for "all ids", using an empty array
     
    148147   downloaders                     | number                      | tr_stat
    149148   downloadLimit                   | number                      | tr_torrent
    150    downloadHonorsLimit             | 'boolean'                   | tr_torrent
    151    downloadHonorsGlobalLimit       | 'boolean'                   | tr_torrent
     149   downloadLimited                 | 'boolean'                   | tr_torrent
    152150   error                           | number                      | tr_stat
    153151   errorString                     | number                      | tr_stat
     
    157155   haveUnchecked                   | number                      | tr_stat
    158156   haveValid                       | number                      | tr_stat
     157   honorsSessionLimits             | 'boolean'                   | tr_torrent
    159158   id                              | number                      | tr_torrent
    160159   isPrivate                       | 'boolean'                   | tr_torrent
     
    195194   uploadedEver                    | number                      | tr_stat
    196195   uploadLimit                     | number                      | tr_torrent
    197    uploadHonorsLimit               | 'boolean'                   | tr_torrent
    198    uploadHonorsGlobalLimit         | 'boolean'                   | tr_torrent
     196   uploadLimited                   | 'boolean'                   | tr_torrent
    199197   uploadRatio                     | 'double'                    | tr_stat
    200198   wanted                          | array (see below)           | n/a
     
    338336   string                     | value type & description
    339337   ---------------------------+-------------------------------------------------
    340    "alt-speed-limit-enabled"  | 'boolean'  true means enabled
    341    "alt-speed-limit-up"       | number     max global upload speed (in K/s)
    342    "alt-speed-limit-down"     | number     max global download speed (in K/s)
    343    "alt-speed-limit-begin"    | number     minutes after midnight. (ex: 60 means starting at 1 am)
    344    "alt-speed-limit-end"      | number     minutes after midnight. (ex: 300 means ending at 5 am)
     338   "alt-speed-down"           | number     max global download speed (in K/s)
     339   "alt-speed-enabled"        | 'boolean'  true means use the alt speeds
     340   "alt-speed-time-begin"     | number     when to turn on alt speeds (units: minutes after midnight)
     341   "alt-speed-time-enabled"   | 'boolean'  true means the scheduled on/off times are used
     342   "alt-speed-time-end"       | number     when to turn off alt speeds (units: same)
     343   "alt-speed-up"             | number     max global upload speed (in K/s)
    345344   "blocklist-enabled"        | 'boolean'  true means enabled
    346345   "blocklist-size"           | number     number of rules in the blocklist
     
    438437   6     | 1.60    | yes       | torrent-get    | new arg "pieces"
    439438         |         | yes       | torrent-set    | new arg "ratio"
    440          |         | yes       | torrent-set    | new arg "downloadHonorsLimit"
    441          |         | yes       | torrent-set    | new arg "downloadHonorsGlobalLimit"
    442          |         | yes       | torrent-set    | new arg "uploadHonorsLimit"
    443          |         | yes       | torrent-set    | new arg "uploadHonorsGlobalLimit"
    444          |         | yes       | torrent-get    | new ids option "recently-active"
    445          |         | yes       | session-get    | new arg "alt-speed-limit-enabled"
    446          |         | yes       | session-get    | new arg "alt-speed-limit-up"
    447          |         | yes       | session-get    | new arg "alt-speed-limit-down"
    448          |         | yes       | session-get    | new arg "alt-speed-limit-begin"
    449          |         | yes       | session-get    | new arg "alt-speed-limit-end"
     439         |         | yes       | torrent-set    | new arg "downloadLimited"
     440         |         | yes       | torrent-set    | new arg "uploadLimited"
     441         |         | yes       | torrent-set    | new arg "honorsSessionLImits"
     442         |         | yes       | session-get    | new arg "alt-speed-enabled"
     443         |         | yes       | session-get    | new arg "alt-speed-time-enabled"
     444         |         | yes       | session-get    | new arg "alt-speed-up"
     445         |         | yes       | session-get    | new arg "alt-speed-down"
     446         |         | yes       | session-get    | new arg "alt-speed-begin"
     447         |         | yes       | session-get    | new arg "alt-speed-end"
    450448         |         | yes       | session-get    | new arg "blocklist-enabled"
    451449         |         | yes       | session-get    | new arg "blocklist-size"
    452450         |         | yes       | session-get    | new arg "peer-limit-per-torrent"
     451         |         | yes       | torrent-get    | new ids option "recently-active"
    453452         |         | yes       |                | new method "torrent-reannounce"
    454453         |         |        NO | torrent-get    | removed arg "downloadLimitMode"
  • trunk/gtk/Makefile.am

    r7996 r8097  
    6161    tr-torrent.h \
    6262    tr-window.h \
     63    turtles.h \
    6364    ui.h \
    6465    util.h
  • trunk/gtk/actions.c

    r7976 r8097  
    2121#include "lock.h"
    2222#include "logo.h"
     23#include "turtles.h"
    2324
    2425#define UNUSED G_GNUC_UNUSED
     
    7071static GtkToggleActionEntry show_toggle_entries[] =
    7172{
    72     { "toggle-main-window", NULL,
    73       N_( "_Main Window" ), NULL, NULL, G_CALLBACK( action_cb ), TRUE },
    74     { "toggle-message-log", NULL,
    75       N_( "Message _Log" ), NULL, NULL, G_CALLBACK( action_cb ), FALSE }
     73    { "toggle-main-window", NULL, N_( "_Main Window" ), NULL, NULL, G_CALLBACK( action_cb ), TRUE },
     74    { "toggle-message-log", NULL, N_( "Message _Log" ), NULL, NULL, G_CALLBACK( action_cb ), FALSE }
    7675};
    7776
     
    142141{
    143142    { tr_icon_logo, "transmission"      },
    144     { tr_icon_lock, "transmission-lock" }
     143    { tr_icon_lock, "transmission-lock" },
     144    { blue_turtle,  "alt-speed-on"      },
     145    { grey_turtle,  "alt-speed-off"     }
    145146};
    146147
  • trunk/gtk/details.c

    r8034 r8097  
    879879    const gboolean b = gtk_toggle_button_get_active( tb );
    880880
    881     tr_torrentUseGlobalSpeedLimit( tor, TR_UP, b );
    882     tr_torrentUseGlobalSpeedLimit( tor, TR_DOWN, b );
     881    tr_torrentUseSessionLimits( tor, b );
    883882}
    884883
     
    986985    hig_workarea_add_section_title( t, &row, _( "Speed Limits" ) );
    987986
    988         b = tr_torrentIsUsingGlobalSpeedLimit( tor, TR_UP );
     987        b = tr_torrentUsesSessionLimits( tor );
    989988        tb = hig_workarea_add_wide_checkbutton( t, &row, _( "Honor global _limits" ), b );
    990989        g_signal_connect( tb, "toggled", G_CALLBACK( global_speed_toggled_cb ), gtor );
    991990
    992991        tb = gtk_check_button_new_with_mnemonic( _( "Limit _download speed (KB/s):" ) );
    993         b = tr_torrentIsUsingSpeedLimit( tor, TR_DOWN );
     992        b = tr_torrentUsesSpeedLimit( tor, TR_DOWN );
    994993        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( tb ), b );
    995994        g_signal_connect( tb, "toggled", G_CALLBACK( down_speed_toggled_cb ), gtor );
     
    10041003
    10051004        tb = gtk_check_button_new_with_mnemonic( _( "Limit _upload speed (KB/s):" ) );
    1006         b = tr_torrentIsUsingSpeedLimit( tor, TR_UP );
     1005        b = tr_torrentUsesSpeedLimit( tor, TR_UP );
    10071006        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( tb ), b );
    10081007        g_signal_connect( tb, "toggled", G_CALLBACK( up_speed_toggled_cb ), gtor );
  • trunk/gtk/hig.c

    r8034 r8097  
    8888    GtkWidget * r = rowNew( w );
    8989
    90     gtk_table_attach( GTK_TABLE(
    91                           t ), r, 0, 2, *row, *row + 1, GTK_FILL, 0, 0, 0 );
     90    gtk_table_attach( GTK_TABLE( t ), r, 0, 2, *row, *row + 1, GTK_FILL, 0, 0, 0 );
    9291    ++ * row;
    9392}
  • trunk/gtk/main.c

    r8088 r8097  
    437437        /* initialize the libtransmission session */
    438438        session = tr_sessionInit( "gtk", configDir, TRUE, pref_get_all( ) );
     439        pref_flag_set( TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed( session ) );
    439440        cbdata->core = tr_core_new( session );
    440441
     
    945946    else if( !strcmp( key, TR_PREFS_KEY_PEER_PORT ) )
    946947    {
    947         const int port = pref_int_get( key );
    948         tr_sessionSetPeerPort( tr, port );
     948        tr_sessionSetPeerPort( tr, pref_int_get( key ) );
    949949    }
    950950    else if( !strcmp( key, TR_PREFS_KEY_BLOCKLIST_ENABLED ) )
    951951    {
    952         const gboolean flag = pref_flag_get( key );
    953         tr_blocklistSetEnabled( tr, flag );
     952        tr_blocklistSetEnabled( tr, pref_flag_get( key ) );
    954953    }
    955954    else if( !strcmp( key, PREF_KEY_SHOW_TRAY_ICON ) )
     
    958957        if( show && !cbdata->icon )
    959958            cbdata->icon = tr_icon_new( cbdata->core );
    960         else if( !show && cbdata->icon )
    961         {
     959        else if( !show && cbdata->icon ) {
    962960            g_object_unref( cbdata->icon );
    963961            cbdata->icon = NULL;
     
    966964    else if( !strcmp( key, TR_PREFS_KEY_DSPEED_ENABLED ) )
    967965    {
    968         const gboolean b = pref_flag_get( key );
    969         tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, b );
     966        tr_sessionLimitSpeed( tr, TR_DOWN, pref_flag_get( key ) );
    970967    }
    971968    else if( !strcmp( key, TR_PREFS_KEY_DSPEED ) )
    972969    {
    973         const int limit = pref_int_get( key );
    974         tr_sessionSetSpeedLimit( tr, TR_DOWN, limit );
     970        tr_sessionSetSpeedLimit( tr, TR_DOWN, pref_int_get( key ) );
    975971    }
    976972    else if( !strcmp( key, TR_PREFS_KEY_USPEED_ENABLED ) )
    977973    {
    978         const gboolean b = pref_flag_get( key );
    979         tr_sessionSetSpeedLimitEnabled( tr, TR_UP, b );
     974        tr_sessionLimitSpeed( tr, TR_UP, pref_flag_get( key ) );
    980975    }
    981976    else if( !strcmp( key, TR_PREFS_KEY_USPEED ) )
    982977    {
    983         const int limit = pref_int_get( key );
    984         tr_sessionSetSpeedLimit( tr, TR_UP, limit );
     978        tr_sessionSetSpeedLimit( tr, TR_UP, pref_int_get( key ) );
    985979    }
    986980    else if( !strcmp( key, TR_PREFS_KEY_RATIO_ENABLED ) )
    987981    {
    988         const gboolean b = pref_flag_get( key );
    989         tr_sessionSetRatioLimited( tr, b );
     982        tr_sessionSetRatioLimited( tr, pref_flag_get( key ) );
    990983    }
    991984    else if( !strcmp( key, TR_PREFS_KEY_RATIO ) )
    992985    {
    993         const double limit = pref_double_get( key );
    994         tr_sessionSetRatioLimit( tr, limit );
     986        tr_sessionSetRatioLimit( tr, pref_double_get( key ) );
    995987    }
    996988    else if( !strcmp( key, TR_PREFS_KEY_PORT_FORWARDING ) )
     
    10121004    else if( !strcmp( key, TR_PREFS_KEY_RPC_WHITELIST ) )
    10131005    {
    1014         const char * s = pref_string_get( key );
    1015         tr_sessionSetRPCWhitelist( tr, s );
     1006        tr_sessionSetRPCWhitelist( tr, pref_string_get( key ) );
    10161007    }
    10171008    else if( !strcmp( key, TR_PREFS_KEY_RPC_WHITELIST_ENABLED ) )
     
    10211012    else if( !strcmp( key, TR_PREFS_KEY_RPC_USERNAME ) )
    10221013    {
    1023         const char * s = pref_string_get( key );
    1024         tr_sessionSetRPCUsername( tr, s );
     1014        tr_sessionSetRPCUsername( tr, pref_string_get( key ) );
    10251015    }
    10261016    else if( !strcmp( key, TR_PREFS_KEY_RPC_PASSWORD ) )
    10271017    {
    1028         const char * s = pref_string_get( key );
    1029         tr_sessionSetRPCPassword( tr, s );
     1018        tr_sessionSetRPCPassword( tr, pref_string_get( key ) );
    10301019    }
    10311020    else if( !strcmp( key, TR_PREFS_KEY_RPC_AUTH_REQUIRED ) )
    10321021    {
    1033         const gboolean enabled = pref_flag_get( key );
    1034         tr_sessionSetRPCPasswordEnabled( tr, enabled );
     1022        tr_sessionSetRPCPasswordEnabled( tr, pref_flag_get( key ) );
    10351023    }
    10361024    else if( !strcmp( key, TR_PREFS_KEY_PROXY ) )
    10371025    {
    1038         const char * s = pref_string_get( key );
    1039         tr_sessionSetProxy( tr, s );
     1026        tr_sessionSetProxy( tr, pref_string_get( key ) );
    10401027    }
    10411028    else if( !strcmp( key, TR_PREFS_KEY_PROXY_TYPE ) )
    10421029    {
    1043         const int i = pref_int_get( key );
    1044         tr_sessionSetProxyType( tr, i );
     1030        tr_sessionSetProxyType( tr, pref_int_get( key ) );
    10451031    }
    10461032    else if( !strcmp( key, TR_PREFS_KEY_PROXY_ENABLED ) )
    10471033    {
    1048         const gboolean enabled = pref_flag_get( key );
    1049         tr_sessionSetProxyEnabled( tr, enabled );
     1034        tr_sessionSetProxyEnabled( tr, pref_flag_get( key ) );
    10501035    }
    10511036    else if( !strcmp( key, TR_PREFS_KEY_PROXY_AUTH_ENABLED ) )
    10521037    {
    1053         const gboolean enabled = pref_flag_get( key );
    1054         tr_sessionSetProxyAuthEnabled( tr, enabled );
     1038        tr_sessionSetProxyAuthEnabled( tr, pref_flag_get( key ) );
    10551039    }
    10561040    else if( !strcmp( key, TR_PREFS_KEY_PROXY_USERNAME ) )
    10571041    {
    1058         const char * s = pref_string_get( key );
    1059         tr_sessionSetProxyUsername( tr, s );
     1042        tr_sessionSetProxyUsername( tr, pref_string_get( key ) );
    10601043    }
    10611044    else if( !strcmp( key, TR_PREFS_KEY_PROXY_PASSWORD ) )
    10621045    {
    1063         const char * s = pref_string_get( key );
    1064         tr_sessionSetProxyPassword( tr, s );
     1046        tr_sessionSetProxyPassword( tr, pref_string_get( key ) );
    10651047    }
    10661048    else if( !strcmp( key, TR_PREFS_KEY_PROXY_PORT ) )
     
    10681050        tr_sessionSetProxyPort( tr, pref_int_get( key ) );
    10691051    }
    1070     else if( !strcmp( key, TR_PREFS_KEY_RPC_PASSWORD ) )
    1071     {
    1072         const char * s = pref_string_get( key );
    1073         tr_sessionSetProxyPassword( tr, s );
    1074     }
    1075     else if( !strcmp( key, TR_PREFS_KEY_ALT_LIMIT_ENABLED ) )
    1076     {
    1077         const gboolean enabled = pref_flag_get( key );
    1078         tr_sessionSetAltSpeedLimitEnabled( tr, enabled );
    1079     }
    1080     else if( !strcmp( key, TR_PREFS_KEY_ALT_BEGIN ) )
    1081     {
    1082         const int minutes = pref_int_get( key );
    1083         tr_sessionSetAltSpeedLimitBegin( tr, minutes );
    1084     }
    1085     else if( !strcmp( key, TR_PREFS_KEY_ALT_DL_LIMIT ) )
    1086     {
    1087         const int speed = pref_int_get( key );
    1088         tr_sessionSetAltSpeedLimit( tr, TR_DOWN, speed );
    1089     }
    1090     else if( !strcmp( key, TR_PREFS_KEY_ALT_END ) )
    1091     {
    1092         const int minutes = pref_int_get( key );
    1093         tr_sessionSetAltSpeedLimitEnd( tr, minutes );
    1094     }
    1095     else if( !strcmp( key, TR_PREFS_KEY_ALT_UL_LIMIT ) )
    1096     {
    1097         const int speed = pref_int_get( key );
    1098         tr_sessionSetAltSpeedLimit( tr, TR_UP, speed );
     1052    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP ) )
     1053    {
     1054        tr_sessionSetAltSpeed( tr, TR_UP, pref_int_get( key ) );
     1055    }
     1056    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN ) )
     1057    {
     1058        tr_sessionSetAltSpeed( tr, TR_DOWN, pref_int_get( key ) );
     1059    }
     1060    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) )
     1061    {
     1062        tr_sessionUseAltSpeed( tr, pref_flag_get( key ) );
     1063    }
     1064    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN ) )
     1065    {
     1066        tr_sessionSetAltSpeedBegin( tr, pref_int_get( key ) );
     1067    }
     1068    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_TIME_END ) )
     1069    {
     1070        tr_sessionSetAltSpeedEnd( tr, pref_int_get( key ) );
     1071    }
     1072    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED ) )
     1073    {
     1074        tr_sessionUseAltSpeedTime( tr, pref_flag_get( key ) );
    10991075    }
    11001076}
  • trunk/gtk/tr-prefs.c

    r8088 r8097  
    272272    GtkWidget *  t;
    273273    GtkWidget *  w;
     274    GtkWidget *  w2;
    274275
    275276#ifdef HAVE_GIO
     
    304305    w = new_path_chooser_button( TR_PREFS_KEY_DOWNLOAD_DIR, core );
    305306    hig_workarea_add_row( t, &row, _( "_Destination folder:" ), w, NULL );
     307
     308    hig_workarea_add_section_divider( t, &row );
     309    hig_workarea_add_section_title( t, &row, _( "Limits" ) );
     310
     311    s = _( "_Stop seeding torrents at ratio:" );
     312    w = new_check_button( s, TR_PREFS_KEY_RATIO_ENABLED, core );
     313    w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, .5, INT_MAX, .05 );
     314    gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED ) );
     315    g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
     316    hig_workarea_add_row_w( t, &row, w, w2, NULL );
    306317
    307318    hig_workarea_finish( t, &row );
     
    779790        page->whitelist_widgets = g_slist_append( page->whitelist_widgets, w );
    780791        v = page->view = GTK_TREE_VIEW( w );
    781 #if GTK_CHECK_VERSION( 2,12,0 )
    782         gtk_widget_set_tooltip_text( w,
    783                   _( "IP addresses may use wildcards, such as 192.168.*.*" ) );
    784 #endif
     792        gtr_widget_set_tooltip_text( w, _( "IP addresses may use wildcards, such as 192.168.*.*" ) );
    785793        sel = gtk_tree_view_get_selection( v );
    786794        g_signal_connect( sel, "changed",
     
    991999{
    9921000    GSList *       l;
    993     const gboolean sched_enabled = pref_flag_get( TR_PREFS_KEY_ALT_LIMIT_ENABLED );
     1001    const gboolean sched_enabled = pref_flag_get( TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED );
    9941002
    9951003    for( l = p->sched_widgets; l != NULL; l = l->next )
     
    10781086    const char *           s;
    10791087    GtkWidget *            t;
    1080     GtkWidget *            w, * w2, * h, * l;
     1088    GtkWidget *            w, * w2, * h;
     1089    char buf[512];
    10811090    struct BandwidthPage * page = tr_new0( struct BandwidthPage, 1 );
    10821091
     
    10841093
    10851094    t = hig_workarea_create( );
    1086     hig_workarea_add_section_title( t, &row, _( "Limits" ) );
    1087 
    1088     s = _( "Limit _download speed (KB/s):" );
    1089     w = new_check_button( s, TR_PREFS_KEY_DSPEED_ENABLED, core );
    1090     w2 = new_spin_button( TR_PREFS_KEY_DSPEED, core, 0, INT_MAX, 5 );
    1091     gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ) );
    1092     g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
    1093     hig_workarea_add_row_w( t, &row, w, w2, NULL );
    1094 
    1095     s = _( "Limit _upload speed (KB/s):" );
    1096     w = new_check_button( s, TR_PREFS_KEY_USPEED_ENABLED, core );
    1097     w2 = new_spin_button( TR_PREFS_KEY_USPEED, core, 0, INT_MAX, 5 );
    1098     gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ) );
    1099     g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
    1100     hig_workarea_add_row_w( t, &row, w, w2, NULL );
    1101 
    1102     s = _( "_Stop seeding when a torrent's ratio reaches:" );
    1103     w = new_check_button( s, TR_PREFS_KEY_RATIO_ENABLED, core );
    1104     w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, .5, INT_MAX, .05 );
    1105     gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED ) );
    1106     g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
    1107     hig_workarea_add_row_w( t, &row, w, w2, NULL );
     1095    hig_workarea_add_section_title( t, &row, _( "Global Bandwidth Limits" ) );
     1096
     1097        s = _( "Limit _download speed (KB/s):" );
     1098        w = new_check_button( s, TR_PREFS_KEY_DSPEED_ENABLED, core );
     1099        w2 = new_spin_button( TR_PREFS_KEY_DSPEED, core, 0, INT_MAX, 5 );
     1100        gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ) );
     1101        g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
     1102        hig_workarea_add_row_w( t, &row, w, w2, NULL );
     1103
     1104        s = _( "Limit _upload speed (KB/s):" );
     1105        w = new_check_button( s, TR_PREFS_KEY_USPEED_ENABLED, core );
     1106        w2 = new_spin_button( TR_PREFS_KEY_USPEED, core, 0, INT_MAX, 5 );
     1107        gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ) );
     1108        g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
     1109        hig_workarea_add_row_w( t, &row, w, w2, NULL );
    11081110
    11091111    hig_workarea_add_section_divider( t, &row );
    1110     hig_workarea_add_section_title( t, &row, _( "Scheduled Limits" ) );
    1111 
    1112     h = gtk_hbox_new( FALSE, 0 );
    1113     w2 = new_time_combo( core, TR_PREFS_KEY_ALT_BEGIN );
    1114     page->sched_widgets = g_slist_append( page->sched_widgets, w2 );
    1115     gtk_box_pack_start( GTK_BOX( h ), w2, FALSE, FALSE, 0 );
    1116     w2 = gtk_label_new ( _( " and " ) );
    1117     page->sched_widgets = g_slist_append( page->sched_widgets, w2 );
    1118     gtk_box_pack_start( GTK_BOX( h ), w2, FALSE, FALSE, 0 );
    1119     w2 = new_time_combo( core, TR_PREFS_KEY_ALT_END );
    1120     page->sched_widgets = g_slist_append( page->sched_widgets, w2 );
    1121     gtk_box_pack_start( GTK_BOX( h ), w2, FALSE, FALSE, 0 );
    1122 
    1123     s = _( "_Limit bandwidth between" );
    1124     w = new_check_button( s, TR_PREFS_KEY_ALT_LIMIT_ENABLED, core );
    1125     g_signal_connect( w, "toggled", G_CALLBACK( onSchedToggled ), page );
    1126     hig_workarea_add_row_w( t, &row, w, h, NULL );
    1127 
    1128     w = new_spin_button( TR_PREFS_KEY_ALT_DL_LIMIT, core, 0, INT_MAX, 5 );
    1129     page->sched_widgets = g_slist_append( page->sched_widgets, w );
    1130     l = hig_workarea_add_row( t, &row, _( "Limit d_ownload speed (KB/s):" ), w, NULL );
    1131     page->sched_widgets = g_slist_append( page->sched_widgets, l );
    1132 
    1133     w = new_spin_button( TR_PREFS_KEY_ALT_UL_LIMIT, core, 0, INT_MAX, 5 );
    1134     page->sched_widgets = g_slist_append( page->sched_widgets, w );
    1135     l = hig_workarea_add_row( t, &row, _( "Limit u_pload speed (KB/s):" ), w, NULL );
    1136     page->sched_widgets = g_slist_append( page->sched_widgets, l );
     1112    h = gtk_hbox_new( FALSE, GUI_PAD );
     1113    w = gtk_image_new_from_stock( "alt-speed-off", GTK_ICON_SIZE_BUTTON );
     1114    gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     1115    g_snprintf( buf, sizeof( buf ), "<b>%s</b>", _( "Speed Limit Mode" ) );
     1116    w = gtk_label_new( buf );
     1117    gtk_misc_set_alignment( GTK_MISC( w ), 0.0f, 0.5f );
     1118    gtk_label_set_use_markup( GTK_LABEL( w ), TRUE );
     1119    gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     1120    hig_workarea_add_section_title_widget( t, &row, h );
     1121
     1122        s = _( "Limit do_wnload speed (KB/s):" );
     1123        w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_DOWN, core, 0, INT_MAX, 5 );
     1124        hig_workarea_add_row( t, &row, s, w, NULL );
     1125
     1126        s = _( "Limit u_pload speed (KB/s):" );
     1127        w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP, core, 0, INT_MAX, 5 );
     1128        hig_workarea_add_row( t, &row, s, w, NULL );
     1129
     1130        s = _( "Use Speed Limit Mode between:" );
     1131        h = gtk_hbox_new( FALSE, 0 );
     1132        w2 = new_time_combo( core, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN );
     1133        page->sched_widgets = g_slist_append( page->sched_widgets, w2 );
     1134        gtk_box_pack_start( GTK_BOX( h ), w2, TRUE, TRUE, 0 );
     1135        w2 = gtk_label_new ( _( " and " ) );
     1136        page->sched_widgets = g_slist_append( page->sched_widgets, w2 );
     1137        gtk_box_pack_start( GTK_BOX( h ), w2, FALSE, FALSE, 0 );
     1138        w2 = new_time_combo( core, TR_PREFS_KEY_ALT_SPEED_TIME_END );
     1139        page->sched_widgets = g_slist_append( page->sched_widgets, w2 );
     1140        gtk_box_pack_start( GTK_BOX( h ), w2, TRUE, TRUE, 0 );
     1141        w = new_check_button( s, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, core );
     1142        g_signal_connect( w, "toggled", G_CALLBACK( onSchedToggled ), page );
     1143        hig_workarea_add_row_w( t, &row, w, h, NULL );
     1144
     1145        g_snprintf( buf, sizeof( buf ), "<small>%s</small>", _( "When enabled, Speed Limit Mode overrides the Global Bandwidth Limits" ) );
     1146        w = gtk_label_new( buf );
     1147        gtk_label_set_use_markup( GTK_LABEL( w ), TRUE );
     1148        gtk_misc_set_alignment( GTK_MISC( w ), 0.5f, 0.5f );
     1149        hig_workarea_add_wide_control( t, &row, w );
    11371150
    11381151    hig_workarea_finish( t, &row );
  • trunk/gtk/tr-window.c

    r7995 r8097  
    8484    GtkWidget *           stats_lb;
    8585    GtkWidget *           gutter_lb;
     86    GtkWidget *           alt_speed_image[2]; /* 0==off, 1==on */
     87    GtkWidget *           alt_speed_button;
    8688    GtkTreeSelection *    selection;
    8789    GtkCellRenderer *     renderer;
     
    194196}
    195197
     198static void syncAltSpeedButton( PrivateData * p );
     199
    196200static void
    197201prefsChanged( TrCore * core UNUSED,
     
    227231    {
    228232        tr_window_update( (TrWindow*)wind );
     233    }
     234    else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) )
     235    {
     236        syncAltSpeedButton( p );
    229237    }
    230238}
     
    277285}
    278286
     287static void
     288syncAltSpeedButton( PrivateData * p )
     289{
     290    const char * tip;
     291    const gboolean b = pref_flag_get( TR_PREFS_KEY_ALT_SPEED_ENABLED );
     292    GtkWidget * w = p->alt_speed_button;
     293
     294    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), b );
     295
     296    gtk_button_set_image( GTK_BUTTON( w ), p->alt_speed_image[b?1:0] );
     297
     298    tip = b ? _( "Click to disable Speed Limit Mode" )
     299            : _( "Click to enable Speed Limit Mode" );
     300    gtr_widget_set_tooltip_text( w, tip );
     301}
     302
     303static void
     304alt_speed_toggled_cb( GtkToggleButton * button, gpointer vprivate )
     305{
     306    PrivateData * p = vprivate;
     307    const gboolean b = gtk_toggle_button_get_active( button );
     308    tr_core_set_pref_bool( p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED,  b );
     309}
     310   
    279311/***
    280312****  FILTER
     
    500532
    501533#endif
     534
     535static gboolean
     536onAltSpeedToggledIdle( gpointer vp )
     537{
     538    PrivateData * p = vp;
     539    gboolean b = tr_sessionUsesAltSpeed( tr_core_session( p->core ) );
     540    tr_core_set_pref_bool( p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b );
     541
     542    return FALSE;
     543}
     544
     545static void
     546onAltSpeedToggled( tr_session * s UNUSED, tr_bool b UNUSED, void * p )
     547{
     548    g_idle_add( onAltSpeedToggledIdle, p );
     549}
    502550
    503551/***
     
    620668    /* status */
    621669    h = status = p->status = gtk_hbox_new( FALSE, GUI_PAD );
    622     gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD );
     670    gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
     671    p->alt_speed_image[0] = gtk_image_new_from_stock( "alt-speed-off", -1 );
     672    p->alt_speed_image[1]  = gtk_image_new_from_stock( "alt-speed-on", -1 );
     673    w = p->alt_speed_button = gtk_toggle_button_new( );
     674    gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
     675    g_object_ref( G_OBJECT( p->alt_speed_image[0] ) );
     676    g_object_ref( G_OBJECT( p->alt_speed_image[1] ) );
     677    g_signal_connect( w, "toggled", G_CALLBACK(alt_speed_toggled_cb ), p );
     678    gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
    623679    w = p->gutter_lb = gtk_label_new( "N Torrents" );
    624     gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
     680    gtk_box_pack_start( GTK_BOX( h ), w, 1, 1, GUI_PAD_BIG );
    625681    w = p->ul_lb = gtk_label_new( NULL );
    626682    gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
     
    705761    prefsChanged( core, PREF_KEY_STATUSBAR_STATS, self );
    706762    prefsChanged( core, PREF_KEY_TOOLBAR, self );
     763    prefsChanged( core, TR_PREFS_KEY_ALT_SPEED_ENABLED, self );
    707764    p->pref_handler_id = g_signal_connect( core, "prefs-changed",
    708765                                           G_CALLBACK( prefsChanged ), self );
     766
     767    tr_sessionSetAltSpeedFunc( tr_core_session( core ), onAltSpeedToggled, p );
    709768
    710769    filter_entry_changed( GTK_EDITABLE( s ), p );
  • trunk/gtk/util.c

    r8078 r8097  
    653653#endif
    654654}
     655
     656
     657void
     658gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip )
     659{
     660#if GTK_CHECK_VERSION( 2,12,0 )
     661    gtk_widget_set_tooltip_text( w, tip );
     662#else
     663    /* FIXME */
     664#endif
     665}
     666
  • trunk/gtk/util.h

    r7774 r8097  
    9393#ifdef GTK_MAJOR_VERSION
    9494
     95void        gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
     96
    9597GtkWidget * gtr_button_new_from_stock( const char * stock,
    9698                                       const char * mnemonic );
  • trunk/libtransmission/peer-mgr.c

    r8092 r8097  
    10281028            tr_torrent * tor = t->tor;
    10291029
    1030             tor->activityDate = now;
     1030            tr_torrentSetActivityDate( tor, now );
    10311031
    10321032            if( e->wasPieceData )
     
    10631063            const time_t now = time( NULL );
    10641064            tr_torrent * tor = t->tor;
    1065             tor->activityDate = now;
     1065
     1066            tr_torrentSetActivityDate( tor, now );
    10661067
    10671068            /* only add this to downloadedCur if we got it from a peer --
  • trunk/libtransmission/resume.c

    r8021 r8097  
    253253    tr_bencDictReserve( d, 3 );
    254254    tr_bencDictAddInt( d, KEY_SPEED, tr_torrentGetSpeedLimit( tor, dir ) );
    255     tr_bencDictAddInt( d, KEY_USE_GLOBAL_SPEED_LIMIT, tr_torrentIsUsingGlobalSpeedLimit( tor, dir ) );
    256     tr_bencDictAddInt( d, KEY_USE_SPEED_LIMIT, tr_torrentIsUsingSpeedLimit( tor, dir ) );
     255    tr_bencDictAddInt( d, KEY_USE_GLOBAL_SPEED_LIMIT, tr_torrentUsesSessionLimits( tor ) );
     256    tr_bencDictAddInt( d, KEY_USE_SPEED_LIMIT, tr_torrentUsesSpeedLimit( tor, dir ) );
    257257}
    258258
     
    284284        tr_torrentUseSpeedLimit( tor, dir, i!=0 );
    285285    if( tr_bencDictFindInt( d, KEY_USE_GLOBAL_SPEED_LIMIT, &i ) )
    286         tr_torrentUseGlobalSpeedLimit( tor, dir, i!=0 );
     286        tr_torrentUseSessionLimits( tor, i!=0 );
    287287}
    288288
     
    318318            tr_torrentSetSpeedLimit( tor, TR_DOWN, i );
    319319        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_MODE, &i ) ) {
    320             tr_torrentUseSpeedLimit ( tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE );
    321             tr_torrentUseGlobalSpeedLimit( tor, TR_DOWN, i==TR_SPEEDLIMIT_GLOBAL );
     320            tr_torrentUseSpeedLimit( tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE );
     321            tr_torrentUseSessionLimits( tor, i==TR_SPEEDLIMIT_GLOBAL );
    322322         }
    323323        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_SPEED, &i ) )
    324324            tr_torrentSetSpeedLimit( tor, TR_UP, i );
    325325        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_MODE, &i ) ) {
    326             tr_torrentUseSpeedLimit ( tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE );
    327             tr_torrentUseGlobalSpeedLimit( tor, TR_UP, i==TR_SPEEDLIMIT_GLOBAL );
     326            tr_torrentUseSpeedLimit( tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE );
     327            tr_torrentUseSessionLimits( tor, i==TR_SPEEDLIMIT_GLOBAL );
    328328        }
    329329        ret = TR_FR_SPEEDLIMIT;
     
    610610      && tr_bencDictFindInt( &top, KEY_ACTIVITY_DATE, &i ) )
    611611    {
    612         tor->activityDate = i;
     612        tr_torrentSetActivityDate( tor, i );
    613613        fieldsLoaded |= TR_FR_ACTIVITY_DATE;
    614614    }
  • trunk/libtransmission/rpcimpl.c

    r8096 r8097  
    409409    else if( !strcmp( key, "downloadLimit" ) )
    410410        tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit( tor, TR_DOWN ) );
    411     else if( !strcmp( key, "downloadHonorsLimit" ) )
    412         tr_bencDictAddInt( d, key, tr_torrentIsUsingSpeedLimit( tor, TR_DOWN ) );
    413     else if( !strcmp( key, "downloadHonorsGlobalLimit" ) )
    414         tr_bencDictAddInt( d, key, tr_torrentIsUsingGlobalSpeedLimit( tor, TR_DOWN ) );
     411    else if( !strcmp( key, "downloadLimited" ) )
     412        tr_bencDictAddInt( d, key, tr_torrentUsesSpeedLimit( tor, TR_DOWN ) );
    415413    else if( !strcmp( key, "error" ) )
    416414        tr_bencDictAddInt( d, key, st->error );
     
    427425    else if( !strcmp( key, "haveValid" ) )
    428426        tr_bencDictAddInt( d, key, st->haveValid );
     427    else if( !strcmp( key, "honorsSessionLimits" ) )
     428        tr_bencDictAddInt( d, key, tr_torrentUsesSessionLimits( tor ) );
    429429    else if( !strcmp( key, "id" ) )
    430430        tr_bencDictAddInt( d, key, st->id );
     
    521521    else if( !strcmp( key, "uploadLimit" ) )
    522522        tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit( tor, TR_UP ) );
    523     else if( !strcmp( key, "uploadHonorsLimit" ) )
    524         tr_bencDictAddInt( d, key, tr_torrentIsUsingSpeedLimit( tor, TR_UP ) );
    525     else if( !strcmp( key, "uploadHonorsGlobalLimit" ) )
    526         tr_bencDictAddInt( d, key, tr_torrentIsUsingGlobalSpeedLimit( tor, TR_UP ) );
     523    else if( !strcmp( key, "uploadLimited" ) )
     524        tr_bencDictAddInt( d, key, tr_torrentUsesSpeedLimit( tor, TR_UP ) );
    527525    else if( !strcmp( key, "wanted" ) )
    528526    {
     
    690688        if( tr_bencDictFindInt( args_in, "downloadLimit", &tmp ) )
    691689            tr_torrentSetSpeedLimit( tor, TR_DOWN, tmp );
    692         if( tr_bencDictFindInt( args_in, "downloadHonorsLimit", &tmp ) )
     690        if( tr_bencDictFindInt( args_in, "downloadLimited", &tmp ) )
    693691            tr_torrentUseSpeedLimit( tor, TR_DOWN, tmp!=0 );
    694         if( tr_bencDictFindInt( args_in, "downloadHonorsGlobalLimit", &tmp ) )
    695             tr_torrentUseGlobalSpeedLimit( tor, TR_DOWN, tmp!=0 );
     692        if( tr_bencDictFindInt( args_in, "honorsSessionLimits", &tmp ) )
     693            tr_torrentUseSessionLimits( tor, tmp!=0 );
    696694        if( tr_bencDictFindInt( args_in, "uploadLimit", &tmp ) )
    697695            tr_torrentSetSpeedLimit( tor, TR_UP, tmp );
    698         if( tr_bencDictFindInt( args_in, "uploadHonorsLimit", &tmp ) )
     696        if( tr_bencDictFindInt( args_in, "uploadLimited", &tmp ) )
    699697            tr_torrentUseSpeedLimit( tor, TR_UP, tmp!=0 );
    700         if( tr_bencDictFindInt( args_in, "uploadHonorsGlobalLimit", &tmp ) )
    701             tr_torrentUseGlobalSpeedLimit( tor, TR_UP, tmp!=0 );
    702698        if( tr_bencDictFindDouble( args_in, "ratio-limit", &d ) )
    703699            tr_torrentSetRatioLimit( tor, d );
     
    865861    assert( idle_data == NULL );
    866862
    867     if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_LIMIT_ENABLED, &i ) )
    868         tr_sessionSetAltSpeedLimitEnabled( session, i!=0 );
    869     if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_BEGIN, &i ) )
    870         tr_sessionSetAltSpeedLimitBegin( session, i );
    871     if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_END, &i ) )
    872         tr_sessionSetAltSpeedLimitEnd( session, i );
    873     if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_DL_LIMIT, &i ) )
    874         tr_sessionSetAltSpeedLimit( session, TR_DOWN, i );
    875     if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_UL_LIMIT, &i ) )
    876         tr_sessionSetAltSpeedLimit( session, TR_UP, i );
     863    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_UP, &i ) )
     864        tr_sessionSetAltSpeed( session, TR_UP, i );
     865    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_DOWN, &i ) )
     866        tr_sessionSetAltSpeed( session, TR_DOWN, i );
     867    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_ENABLED, &i ) )
     868        tr_sessionUseAltSpeed( session, i!=0 );
     869    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i ) )
     870        tr_sessionSetAltSpeedBegin( session, i );
     871    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i ) )
     872        tr_sessionSetAltSpeedEnd( session, i );
     873    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &i ) )
     874        tr_sessionUseAltSpeedTime( session, i!=0 );
    877875    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_BLOCKLIST_ENABLED, &i ) )
    878876        tr_blocklistSetEnabled( session, i!=0 );
     
    892890        tr_sessionSetSpeedLimit( session, TR_DOWN, i );
    893891    if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &i ) )
    894         tr_sessionSetSpeedLimitEnabled( session, TR_DOWN, i );
     892        tr_sessionLimitSpeed( session, TR_DOWN, i!=0 );
    895893    if( tr_bencDictFindInt( args_in, "speed-limit-up", &i ) )
    896894        tr_sessionSetSpeedLimit( session, TR_UP, i );
    897895    if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &i ) )
    898         tr_sessionSetSpeedLimitEnabled( session, TR_UP, i );
     896        tr_sessionLimitSpeed( session, TR_UP, i!=0 );
    899897    if( tr_bencDictFindDouble( args_in, "ratio-limit", &d ) )
    900898        tr_sessionSetRatioLimit( session, d );
    901899    if( tr_bencDictFindInt( args_in, "ratio-limit-enabled", &i ) )
    902         tr_sessionSetRatioLimited( session, i );
     900        tr_sessionSetRatioLimited( session, i!=0 );
    903901    if( tr_bencDictFindStr( args_in, "encryption", &str ) )
    904902    {
     
    973971
    974972    assert( idle_data == NULL );
    975     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_LIMIT_ENABLED, tr_sessionIsAltSpeedLimitEnabled( s ) );
    976     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_UL_LIMIT, tr_sessionGetAltSpeedLimit( s, TR_UP ) );
    977     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_DL_LIMIT, tr_sessionGetAltSpeedLimit( s, TR_DOWN ) );
    978     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_BEGIN, tr_sessionGetAltSpeedLimitBegin( s ) );
    979     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_END, tr_sessionGetAltSpeedLimitEnd( s ) );
     973    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_UP, tr_sessionGetAltSpeed(s,TR_UP) );
     974    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_DOWN, tr_sessionGetAltSpeed(s,TR_DOWN) );
     975    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed(s) );
     976    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin(s) );
     977    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,tr_sessionGetAltSpeedEnd(s) );
     978    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime(s) );
    980979    tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
    981980    tr_bencDictAddInt( d, "blocklist-size", tr_blocklistGetRuleCount( s ) );
     
    989988    tr_bencDictAddInt( d, "rpc-version-minimum", 1 );
    990989    tr_bencDictAddInt( d, "speed-limit-up", tr_sessionGetSpeedLimit( s, TR_UP ) );
    991     tr_bencDictAddInt( d, "speed-limit-up-enabled", tr_sessionIsSpeedLimitEnabled( s, TR_UP ) );
     990    tr_bencDictAddInt( d, "speed-limit-up-enabled", tr_sessionIsSpeedLimited( s, TR_UP ) );
    992991    tr_bencDictAddInt( d, "speed-limit-down", tr_sessionGetSpeedLimit( s, TR_DOWN ) );
    993     tr_bencDictAddInt( d, "speed-limit-down-enabled", tr_sessionIsSpeedLimitEnabled( s, TR_DOWN ) );
     992    tr_bencDictAddInt( d, "speed-limit-down-enabled", tr_sessionIsSpeedLimited( s, TR_DOWN ) );
    994993    tr_bencDictAddDouble( d, "ratio-limit", tr_sessionGetRatioLimit( s ) );
    995994    tr_bencDictAddInt( d, "ratio-limit-enabled", tr_sessionIsRatioLimited( s ) );
  • trunk/libtransmission/session.c

    r8093 r8097  
    257257    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED,    TRUE );
    258258    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_PORT,                 atoi( TR_DEFAULT_RPC_PORT_STR ) );
    259     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_LIMIT_ENABLED,        FALSE );
    260     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_BEGIN,                1320 ); /* 10pm */
    261     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_END,                  300 ); /* 5am */
    262     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_DL_LIMIT,             200 ); /* double the regular default */
    263     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_UL_LIMIT,             200 ); /* double the regular default */
     259    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_ENABLED,        FALSE );
     260    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_UP,             50 ); /* half the regular */
     261    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_DOWN,           50 ); /* half the regular */
     262    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN,     540 ); /* 9am */
     263    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED,   FALSE );
     264    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,       1020 ); /* 5pm */
    264265    tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED,                   100 );
    265266    tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED,           0 );
     
    279280    tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR,             s->downloadDir );
    280281    tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED,                   tr_sessionGetSpeedLimit( s, TR_DOWN ) );
    281     tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED,           tr_sessionIsSpeedLimitEnabled( s, TR_DOWN ) );
     282    tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED,           tr_sessionIsSpeedLimited( s, TR_DOWN ) );
    282283    tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION,               s->encryptionMode );
    283284    tr_bencDictAddInt( d, TR_PREFS_KEY_LAZY_BITFIELD,            s->useLazyBitfield );
     
    310311    tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_WHITELIST,            freeme[n++] = tr_sessionGetRPCWhitelist( s ) );
    311312    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED,    tr_sessionGetRPCWhitelistEnabled( s ) );
    312     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_LIMIT_ENABLED,        tr_sessionIsAltSpeedLimitEnabled( s ) );
    313     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_BEGIN,                tr_sessionGetAltSpeedLimitBegin( s ) );
    314     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_END,                  tr_sessionGetAltSpeedLimitEnd( s ) );
    315     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_DL_LIMIT,             tr_sessionGetAltSpeedLimit( s, TR_DOWN ) );
    316     tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_UL_LIMIT,             tr_sessionGetAltSpeedLimit( s, TR_UP ) );
     313    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_ENABLED,        tr_sessionUsesAltSpeed( s ) );
     314    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_UP,             tr_sessionGetAltSpeed( s, TR_UP ) );
     315    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_DOWN,           tr_sessionGetAltSpeed( s, TR_DOWN ) );
     316    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN,     tr_sessionGetAltSpeedBegin( s ) );
     317    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED,   tr_sessionUsesAltSpeedTime( s ) );
     318    tr_bencDictAddInt( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,       tr_sessionGetAltSpeedEnd( s ) );
    317319    tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED,                   tr_sessionGetSpeedLimit( s, TR_UP ) );
    318     tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED,           tr_sessionIsSpeedLimitEnabled( s, TR_UP ) );
     320    tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED,           tr_sessionIsSpeedLimited( s, TR_UP ) );
    319321    tr_bencDictAddInt( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent );
    320322
     
    357359
    358360void
    359 tr_sessionSaveSettings( tr_session * session, const char * configDir, tr_benc * settings )
    360 {
    361     tr_benc fileSettings;
    362     char * filename;
    363 
    364     assert( tr_bencIsDict( settings ) );
    365 
    366     filename = tr_buildPath( configDir, "settings.json", NULL );
    367 
    368     tr_sessionGetSettings( session, settings );
    369 
    370     if( tr_bencLoadJSONFile( filename, &fileSettings ) ) {
    371         tr_bencSaveJSONFile( filename, settings );
    372     } else {
    373         tr_bencMergeDicts( &fileSettings, settings );
    374         tr_bencSaveJSONFile( filename, &fileSettings );
    375         tr_bencFree( &fileSettings );
    376     }
    377 
     361tr_sessionSaveSettings( tr_session    * session,
     362                        const char    * configDir,
     363                        const tr_benc * clientSettings )
     364{
     365    tr_benc settings;
     366    char * filename = tr_buildPath( configDir, "settings.json", NULL );
     367
     368    assert( tr_bencIsDict( clientSettings ) );
     369
     370    tr_bencInitDict( &settings, 0 );
     371
     372    /* the existing file settings are the fallback values */
     373    {
     374        tr_benc fileSettings;
     375        if( !tr_bencLoadJSONFile( filename, &fileSettings ) )
     376        {
     377            tr_bencMergeDicts( &settings, &fileSettings );
     378            tr_bencFree( &fileSettings );
     379        }
     380    }
     381
     382    /* the client's settings override the file settings */
     383    tr_bencMergeDicts( &settings, clientSettings );
     384
     385    /* the session's true values override the file & client settings */
     386    {
     387        tr_benc sessionSettings;
     388        tr_bencInitDict( &sessionSettings, 0 );
     389        tr_sessionGetSettings( session, &sessionSettings );
     390        tr_bencMergeDicts( &settings, &sessionSettings );
     391        tr_bencFree( &sessionSettings );
     392    }
     393
     394    /* save the result */
     395    tr_bencSaveJSONFile( filename, &settings );
    378396    tr_inf( "Saved \"%s\"", filename );
     397
     398    /* cleanup */
    379399    tr_free( filename );
     400    tr_bencFree( &settings );
    380401}
    381402
     
    383404static void tr_sessionInitImpl( void * );
    384405static void onAltTimer( int, short, void* );
    385 
    386 /* set the alt-speed timer to go off at the top of the minute */
    387 static void
    388 setAltTimer( tr_session * session )
    389 {
    390     const time_t now = time( NULL );
    391     struct tm tm;
    392     struct timeval tv;
    393 
    394     assert( tr_isSession( session ) );
    395     assert( session->altTimer != NULL );
    396 
    397     tr_localtime_r( &now, &tm );
    398     tv.tv_sec = 60 - tm.tm_sec;
    399     tv.tv_usec = 0;
    400     evtimer_add( session->altTimer, &tv );
    401 }
     406static void setAltTimer( tr_session * session );
    402407
    403408struct init_data
     
    590595    assert( found );
    591596    tr_sessionSetSpeedLimit( session, TR_UP, i );
    592     tr_sessionSetSpeedLimitEnabled( session, TR_UP, j );
     597    tr_sessionLimitSpeed( session, TR_UP, j!=0 );
    593598
    594599    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_DSPEED, &i )
     
    596601    assert( found );
    597602    tr_sessionSetSpeedLimit( session, TR_DOWN, i );
    598     tr_sessionSetSpeedLimitEnabled( session, TR_DOWN, j );
     603    tr_sessionLimitSpeed( session, TR_DOWN, j!=0 );
    599604
    600605    found = tr_bencDictFindDouble( &settings, TR_PREFS_KEY_RATIO, &d )
     
    605610
    606611    /**
    607     ***  Alternate speed limits for off-peak hours
     612    ***  Alternate speed limits
    608613    **/
    609     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_LIMIT_ENABLED, &i );
    610     assert( found );
    611     session->isAltSpeedLimited = i != 0;
    612 
    613     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_BEGIN, &i )
    614          && tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_END, &j );
    615     assert( found );
    616     session->altSpeedBeginTime = i;
    617     session->altSpeedEndTime = j;
    618 
    619     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_DL_LIMIT, &i )
    620          && tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_UL_LIMIT, &j );
    621     assert( found );
    622     session->altSpeedLimit[TR_DOWN] = i;
    623     session->altSpeedLimit[TR_UP] = j;
    624 
    625     /* initialize the blocklist */
     614
     615    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_UP, &i );
     616    assert( found );
     617    session->altSpeed[TR_UP] = i;
     618
     619    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i );
     620    assert( found );
     621    session->altSpeed[TR_DOWN] = i;
     622
     623    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i );
     624    assert( found );
     625    session->altSpeedTimeBegin = i;
     626
     627    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i );
     628    assert( found );
     629    session->altSpeedTimeEnd = i;
     630
     631    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &i );
     632    assert( found );
     633    tr_sessionUseAltSpeedTime( session, i!=0 );
     634
     635    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &i );
     636    assert( found );
     637    tr_sessionUseAltSpeed( session, i!=0 );
     638
     639
     640    /**
     641    ***  Blocklist
     642    **/
     643
    626644    filename = tr_buildPath( session->configDir, "blocklists", NULL );
    627645    tr_mkdirp( filename, 0777 );
     
    827845
    828846/***
    829 ****
     847****  SPEED LIMITS
    830848***/
    831849
     850tr_bool
     851tr_sessionGetActiveSpeedLimit( const tr_session * session, tr_direction dir, int * setme )
     852{
     853    int isLimited = TRUE;
     854
     855    if( tr_sessionUsesAltSpeed( session ) )
     856        *setme = tr_sessionGetAltSpeed( session, dir );
     857    else if( tr_sessionIsSpeedLimited( session, dir ) )
     858        *setme = tr_sessionGetSpeedLimit( session, dir );
     859    else
     860        isLimited = FALSE;
     861
     862    return isLimited;
     863}
     864
    832865static tr_bool
    833 isAltTime( const tr_session * session )
     866isAltTime( const tr_session * s )
     867{
     868    tr_bool is;
     869    int minutes;
     870    struct tm tm;
     871    const time_t now = time( NULL );
     872    const int begin = s->altSpeedTimeBegin;
     873    const int end = s->altSpeedTimeEnd;
     874
     875    tr_localtime_r( &now, &tm );
     876    minutes = tm.tm_hour*60 + tm.tm_min;
     877
     878    if( begin <= end )
     879        is = ( begin <= minutes ) && ( minutes < end );
     880    else /* goes past midnight */
     881        is = ( begin <= minutes ) || ( minutes < end );
     882
     883    return is;
     884}
     885
     886static void
     887updateBandwidth( tr_session * session, tr_direction dir )
     888{
     889    int limit;
     890    const tr_bool isLimited = tr_sessionGetActiveSpeedLimit( session, dir, &limit );
     891    const tr_bool zeroCase = isLimited && !limit;
     892
     893    tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase );
     894
     895    tr_bandwidthSetDesiredSpeed( session->bandwidth, dir, limit );
     896}
     897
     898static void
     899altSpeedToggled( void * vsession )
     900{
     901    tr_session * session = vsession;
     902
     903    assert( tr_isSession( session ) );
     904
     905    updateBandwidth( session, TR_UP );
     906    updateBandwidth( session, TR_DOWN );
     907
     908    if( session->altCallback != NULL )
     909        (*session->altCallback)( session, session->altSpeedEnabled, session->altCallbackUserData );
     910}
     911
     912/* tell the alt speed limit timer to fire again at the top of the minute */
     913static void
     914setAltTimer( tr_session * session )
    834915{
    835916    const time_t now = time( NULL );
    836917    struct tm tm;
    837     int minutes;
    838 
    839     if( !tr_sessionIsAltSpeedLimitEnabled( session ) )
    840         return FALSE;
     918    struct timeval tv;
     919
     920    assert( tr_isSession( session ) );
     921    assert( session->altTimer != NULL );
    841922
    842923    tr_localtime_r( &now, &tm );
    843     minutes = tm.tm_hour*60 + tm.tm_min;
    844 
    845     if( session->altSpeedBeginTime <= session->altSpeedEndTime )
    846     {
    847         return ( session->altSpeedBeginTime <= minutes )
    848             && ( minutes < session->altSpeedEndTime );
    849     }
    850     else /* goes past midnight */
    851     {
    852         return ( minutes >= session->altSpeedBeginTime )
    853             || ( minutes < session->altSpeedEndTime );
    854     }
    855 }
    856 
    857 static int
    858 getActiveSpeedLimit( const tr_session * session, tr_direction dir )
    859 {
    860     int val;
    861 
    862     if( tr_sessionIsAltSpeedLimitEnabled( session ) && session->isAltTime )
    863         val = tr_sessionGetAltSpeedLimit( session, dir );
    864     else if( tr_sessionIsSpeedLimitEnabled( session, dir ) )
    865         val = tr_sessionGetSpeedLimit( session, dir );
    866     else
    867         val = -1;
    868 
    869     return val;
    870 }
    871 
    872 static void
    873 updateBandwidth( tr_session * session, tr_direction dir )
    874 {
    875     const int limit = getActiveSpeedLimit( session, dir );
    876     const tr_bool isLimited = limit >= 0;
    877     const tr_bool zeroCase = isLimited && !limit;
    878 
    879     tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase );
    880 
    881     tr_bandwidthSetDesiredSpeed( session->bandwidth, dir, limit );
     924    tv.tv_sec = 60 - tm.tm_sec;
     925    tv.tv_usec = 0;
     926    evtimer_add( session->altTimer, &tv );
    882927}
    883928
     
    888933onAltTimer( int foo UNUSED, short bar UNUSED, void * vsession )
    889934{
    890     tr_bool wasAltTime;
    891935    tr_session * session = vsession;
    892936
    893937    assert( tr_isSession( session ) );
    894938
    895     wasAltTime = session->isAltTime;
    896     session->isAltTime = isAltTime( session );
    897 
    898     if( wasAltTime != session->isAltTime )
    899     {
    900         updateBandwidth( session, TR_UP );
    901         updateBandwidth( session, TR_DOWN );
    902 
    903         if( session->altCallback != NULL )
    904             (*session->altCallback)( session, session->isAltTime, session->altCallbackUserData );
     939    if( session->altSpeedTimeEnabled )
     940    {
     941        const time_t now = time( NULL );
     942        struct tm tm;
     943        int currentMinute;
     944        tr_localtime_r( &now, &tm );
     945        currentMinute = tm.tm_hour*60 + tm.tm_min;
     946
     947        if( currentMinute == session->altSpeedTimeBegin )
     948        {
     949            tr_sessionUseAltSpeed( session, TRUE );
     950        }
     951        else if( currentMinute == session->altSpeedTimeEnd )
     952        {
     953            tr_sessionUseAltSpeed( session, FALSE );
     954        }
    905955    }
    906956
     
    908958}
    909959
    910 void
    911 tr_sessionSetSpeedLimitEnabled( tr_session      * session,
    912                                 tr_direction      dir,
    913                                 tr_bool           isLimited )
    914 {
    915     assert( tr_isSession( session ) );
    916     assert( tr_isDirection( dir ) );
    917 
    918     session->isSpeedLimited[dir] = isLimited;
    919     updateBandwidth( session, dir );
    920 }
    921 
    922 void
    923 tr_sessionSetSpeedLimit( tr_session    * session,
    924                          tr_direction    dir,
    925                          int             desiredSpeed )
    926 {
    927     assert( tr_isSession( session ) );
    928     assert( tr_isDirection( dir ) );
    929 
    930     session->speedLimit[dir] = desiredSpeed;
    931     updateBandwidth( session, dir );
     960/***
     961****  Primary session speed limits
     962***/
     963
     964void
     965tr_sessionSetSpeedLimit( tr_session * s, tr_direction d, int KB_s )
     966{
     967    assert( tr_isSession( s ) );
     968    assert( tr_isDirection( d ) );
     969    assert( KB_s >= 0 );
     970
     971    s->speedLimit[d] = KB_s;
     972
     973    updateBandwidth( s, d );
     974}
     975
     976int
     977tr_sessionGetSpeedLimit( const tr_session * s, tr_direction d )
     978{
     979    assert( tr_isSession( s ) );
     980    assert( tr_isDirection( d ) );
     981
     982    return s->speedLimit[d];
     983}
     984
     985void
     986tr_sessionLimitSpeed( tr_session * s, tr_direction d, tr_bool b )
     987{
     988    assert( tr_isSession( s ) );
     989    assert( tr_isDirection( d ) );
     990    assert( tr_isBool( b ) );
     991
     992    s->speedLimitEnabled[d] = b;
     993
     994    updateBandwidth( s, d );
    932995}
    933996
    934997tr_bool
    935 tr_sessionIsSpeedLimitEnabled( const tr_session * session, tr_direction dir )
    936 {
    937     assert( tr_isSession( session ) );
    938     assert( tr_isDirection( dir ) );
    939 
    940     return session->isSpeedLimited[dir];
     998tr_sessionIsSpeedLimited( const tr_session * s, tr_direction d )
     999{
     1000    assert( tr_isSession( s ) );
     1001    assert( tr_isDirection( d ) );
     1002
     1003    return s->speedLimitEnabled[d];
     1004}
     1005
     1006/***
     1007****  Alternative speed limits that are used during scheduled times
     1008***/
     1009
     1010void
     1011tr_sessionSetAltSpeed( tr_session * s, tr_direction d, int KB_s )
     1012{
     1013    assert( tr_isSession( s ) );
     1014    assert( tr_isDirection( d ) );
     1015    assert( KB_s >= 0 );
     1016
     1017    s->altSpeed[d] = KB_s;
     1018
     1019    updateBandwidth( s, d );
    9411020}
    9421021
    9431022int
    944 tr_sessionGetSpeedLimit( const tr_session * session, tr_direction dir )
    945 {
    946     assert( tr_isSession( session ) );
    947     assert( tr_isDirection( dir ) );
    948 
    949     return session->speedLimit[dir];
    950 }
    951 
    952 static void
    953 checkAltTime( void * session )
    954 {
    955     onAltTimer( 0, 0, session );
    956 }
    957 
    958 void
    959 tr_sessionSetAltSpeedLimitEnabled( tr_session   * session,
    960                                    tr_bool        isEnabled )
    961 {
    962     assert( tr_isSession( session ) );
    963     assert( tr_isBool( isEnabled ) );
    964 
    965     session->isAltSpeedLimited = isEnabled;
    966 
    967     tr_runInEventThread( session, checkAltTime, session );
     1023tr_sessionGetAltSpeed( const tr_session * s, tr_direction d )
     1024{
     1025    assert( tr_isSession( s ) );
     1026    assert( tr_isDirection( d ) );
     1027
     1028    return s->altSpeed[d];
     1029}
     1030
     1031void
     1032tr_sessionUseAltSpeedTime( tr_session * s, tr_bool b )
     1033{
     1034    assert( tr_isSession( s ) );
     1035    assert( tr_isBool( b ) );
     1036
     1037    if( s->altSpeedTimeEnabled != b )
     1038    {
     1039        s->altSpeedTimeEnabled = b;
     1040
     1041        if( isAltTime( s ) )
     1042            tr_sessionUseAltSpeed( s, b );
     1043    }
    9681044}
    9691045
    9701046tr_bool
    971 tr_sessionIsAltSpeedLimitEnabled( const tr_session  * session )
    972 {
    973     assert( tr_isSession( session ) );
    974 
    975     return session->isAltSpeedLimited;
    976 }
    977 
    978 void
    979 tr_sessionSetAltSpeedLimit( tr_session        * session,
    980                             tr_direction        dir,
    981                             int                 desiredSpeed )
    982 {
    983     assert( tr_isSession( session ) );
    984     assert( tr_isDirection( dir ) );
    985     assert( desiredSpeed >= 0 );
    986 
    987     session->altSpeedLimit[dir] = desiredSpeed;
    988 
    989     updateBandwidth( session, dir );
     1047tr_sessionUsesAltSpeedTime( const tr_session * s )
     1048{
     1049    assert( tr_isSession( s ) );
     1050
     1051    return s->altSpeedTimeEnabled;
     1052}
     1053
     1054void
     1055tr_sessionSetAltSpeedBegin( tr_session * s, int minutes )
     1056{
     1057    assert( tr_isSession( s ) );
     1058    assert( 0<=minutes && minutes<(60*24) );
     1059
     1060    if( s->altSpeedTimeBegin != minutes )
     1061    {
     1062        s->altSpeedTimeBegin = minutes;
     1063
     1064        if( tr_sessionUsesAltSpeedTime( s ) )
     1065            tr_sessionUseAltSpeed( s, isAltTime( s ) );
     1066    }
    9901067}
    9911068
    9921069int
    993 tr_sessionGetAltSpeedLimit( const tr_session  * session,
    994                             tr_direction        dir )
    995 {
    996     assert( tr_isSession( session ) );
    997     assert( tr_isDirection( dir ) );
    998 
    999     return session->altSpeedLimit[dir];
    1000 }
    1001 
    1002 void
    1003 tr_sessionSetAltSpeedLimitBegin( tr_session * session, int minutesSinceMidnight )
    1004 {
    1005     assert( tr_isSession( session ) );
    1006 
    1007     session->altSpeedBeginTime = minutesSinceMidnight;
    1008 
    1009     tr_runInEventThread( session, checkAltTime, session );
     1070tr_sessionGetAltSpeedBegin( const tr_session * s )
     1071{
     1072    assert( tr_isSession( s ) );
     1073
     1074    return s->altSpeedTimeBegin;
     1075}
     1076
     1077void
     1078tr_sessionSetAltSpeedEnd( tr_session * s, int minutes )
     1079{
     1080    assert( tr_isSession( s ) );
     1081    assert( 0<=minutes && minutes<(60*24) );
     1082
     1083    if( s->altSpeedTimeEnd != minutes )
     1084    {
     1085        s->altSpeedTimeEnd = minutes;
     1086
     1087        if( tr_sessionUsesAltSpeedTime( s ) )
     1088            tr_sessionUseAltSpeed( s, isAltTime( s ) );
     1089    }
    10101090}
    10111091
    10121092int
    1013 tr_sessionGetAltSpeedLimitBegin( const tr_session * session )
    1014 {
    1015     assert( tr_isSession( session ) );
    1016 
    1017     return session->altSpeedBeginTime;
    1018 }
    1019 
    1020 void
    1021 tr_sessionSetAltSpeedLimitEnd( tr_session * session, int minutesSinceMidnight )
    1022 {
    1023     assert( tr_isSession( session ) );
    1024 
    1025     session->altSpeedEndTime = minutesSinceMidnight;
    1026 
    1027     tr_runInEventThread( session, checkAltTime, session );
    1028 }
    1029 
    1030 int
    1031 tr_sessionGetAltSpeedLimitEnd( const tr_session * session )
    1032 {
    1033     assert( tr_isSession( session ) );
    1034 
    1035     return session->altSpeedEndTime;
    1036 }
    1037 
    1038 void
    1039 tr_sessionSetAltSpeedCallback( tr_session         * session,
    1040                                tr_alt_speed_func    func,
    1041                                void               * userData )
     1093tr_sessionGetAltSpeedEnd( const tr_session * s )
     1094{
     1095    assert( tr_isSession( s ) );
     1096
     1097    return s->altSpeedTimeEnd;
     1098}
     1099
     1100void
     1101tr_sessionUseAltSpeed( tr_session * s, tr_bool b )
     1102{
     1103    assert( tr_isSession( s ) );
     1104    assert( tr_isBool( b ) );
     1105
     1106    if( s->altSpeedEnabled != b)
     1107    {
     1108        s->altSpeedEnabled = b;
     1109   
     1110        tr_runInEventThread( s, altSpeedToggled, s );
     1111    }
     1112}
     1113
     1114tr_bool
     1115tr_sessionUsesAltSpeed( const tr_session * s )
     1116{
     1117    assert( tr_isSession( s ) );
     1118
     1119    return s->altSpeedEnabled;
     1120}
     1121
     1122void
     1123tr_sessionSetAltSpeedFunc( tr_session       * session,
     1124                           tr_altSpeedFunc    func,
     1125                           void             * userData )
    10421126{
    10431127    assert( tr_isSession( session ) );
     
    10481132
    10491133void
    1050 tr_sessionClearAltSpeedCallback( tr_session * session )
    1051 {
    1052     tr_sessionSetAltSpeedCallback( session, NULL, NULL );
    1053 }
    1054 
     1134tr_sessionClearAltSpeedFunc( tr_session * session )
     1135{
     1136    tr_sessionSetAltSpeedFunc( session, NULL, NULL );
     1137}
    10551138
    10561139/***
  • trunk/libtransmission/session.h

    r8089 r8097  
    6969    tr_bool                      isRatioLimited;
    7070
    71     tr_bool                      isSpeedLimited[2];
     71   
    7272    int                          speedLimit[2];
    73     tr_bool                      isAltSpeedLimited;
    74     int                          altSpeedBeginTime;
    75     int                          altSpeedEndTime;
    76     int                          altSpeedLimit[2];
    77     tr_bool                      isAltTime;
    78     tr_alt_speed_func          * altCallback;
     73    tr_bool                      speedLimitEnabled[2];
     74
     75    int                          altSpeed[2];
     76    tr_bool                      altSpeedEnabled;
     77
     78    int                          altSpeedTimeBegin;
     79    int                          altSpeedTimeEnd;
     80    tr_bool                      altSpeedTimeEnabled;
     81
     82    tr_altSpeedFunc            * altCallback;
    7983    void                       * altCallbackUserData;
    8084
     
    146150};
    147151
     152tr_bool      tr_sessionGetActiveSpeedLimit( const tr_session  * session,
     153                                            tr_direction        dir,
     154                                            int               * setme );
     155
    148156const char * tr_sessionFindTorrentFile( const tr_session * session,
    149157                                        const char *       hashString );
  • trunk/libtransmission/torrent.c

    r8090 r8097  
    137137
    138138tr_bool
    139 tr_torrentIsUsingSpeedLimit( const tr_torrent * tor, tr_direction dir )
     139tr_torrentUsesSpeedLimit( const tr_torrent * tor, tr_direction dir )
    140140{
    141141    assert( tr_isTorrent( tor ) );
     
    146146
    147147void
    148 tr_torrentUseGlobalSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use )
    149 {
    150     assert( tr_isTorrent( tor ) );
    151     assert( tr_isDirection( dir ) );
    152 
    153     tr_bandwidthHonorParentLimits( tor->bandwidth, dir, do_use );
     148tr_torrentUseSessionLimits( tr_torrent * tor, tr_bool doUse )
     149{
     150    assert( tr_isTorrent( tor ) );
     151
     152    tr_bandwidthHonorParentLimits( tor->bandwidth, TR_UP, doUse );
     153    tr_bandwidthHonorParentLimits( tor->bandwidth, TR_DOWN, doUse );
    154154}
    155155
    156156tr_bool
    157 tr_torrentIsUsingGlobalSpeedLimit( const tr_torrent * tor, tr_direction dir )
    158 {
    159     assert( tr_isTorrent( tor ) );
    160     assert( tr_isDirection( dir ) );
    161 
    162     return tr_bandwidthAreParentLimitsHonored( tor->bandwidth, dir );
     157tr_torrentUsesSessionLimits( const tr_torrent * tor )
     158{
     159    assert( tr_isTorrent( tor ) );
     160
     161    return tr_bandwidthAreParentLimitsHonored( tor->bandwidth, TR_UP );
    163162}
    164163
     
    209208                                  tr_direction        direction )
    210209{
     210    int limit;
    211211    tr_bool allowed = TRUE;
    212212
    213     if( tr_torrentIsUsingSpeedLimit( tor, direction ) )
     213    if( tr_torrentUsesSpeedLimit( tor, direction ) )
    214214        if( tr_torrentGetSpeedLimit( tor, direction ) <= 0 )
    215215            allowed = FALSE;
    216216
    217     if( tr_torrentIsUsingGlobalSpeedLimit( tor, direction ) )
    218         if( tr_sessionIsSpeedLimitEnabled( tor->session, direction ) )
    219             if( tr_sessionGetSpeedLimit( tor->session, direction ) <= 0 )
     217    if( tr_torrentUsesSessionLimits( tor ) )
     218        if( tr_sessionGetActiveSpeedLimit( tor->session, direction, &limit ) )
     219            if( limit <= 0 )
    220220                allowed = FALSE;
    221221
     
    595595    if( !( loaded & TR_FR_SPEEDLIMIT ) )
    596596    {
    597         tr_torrentSetSpeedLimit( tor, TR_UP,
    598                                 tr_sessionGetSpeedLimit( tor->session, TR_UP ) );
    599         tr_torrentSetSpeedLimit( tor, TR_DOWN,
    600                                 tr_sessionGetSpeedLimit( tor->session, TR_DOWN ) );
     597        tr_torrentUseSpeedLimit( tor, TR_UP, FALSE );
     598        tr_torrentUseSpeedLimit( tor, TR_DOWN, FALSE );
     599        tr_torrentUseSessionLimits( tor, TRUE );
    601600    }
    602601
  • trunk/libtransmission/transmission.h

    r8093 r8097  
    152152#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "60"
    153153
    154 #define TR_PREFS_KEY_ALT_LIMIT_ENABLED          "alt-speed-limit-enabled"
    155 #define TR_PREFS_KEY_ALT_BEGIN                  "alt-speed-limit-begin"
    156 #define TR_PREFS_KEY_ALT_DL_LIMIT               "alt-speed-limit-down"
    157 #define TR_PREFS_KEY_ALT_END                    "alt-speed-limit-end"
    158 #define TR_PREFS_KEY_ALT_UL_LIMIT               "alt-speed-limit-up"
     154#define TR_PREFS_KEY_ALT_SPEED_ENABLED          "alt-speed-enabled"
     155#define TR_PREFS_KEY_ALT_SPEED_UP               "alt-speed-up"
     156#define TR_PREFS_KEY_ALT_SPEED_DOWN             "alt-speed-down"
     157#define TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN       "alt-speed-time-begin"
     158#define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED     "alt-speed-time-enabled"
     159#define TR_PREFS_KEY_ALT_SPEED_TIME_END         "alt-speed-time-end"
    159160#define TR_PREFS_KEY_BLOCKLIST_ENABLED          "blocklist-enabled"
    160161#define TR_PREFS_KEY_DOWNLOAD_DIR               "download-dir"
     
    257258 * @see tr_sessionLoadSettings()
    258259 */
    259 void tr_sessionSaveSettings( tr_session     * session,
    260                              const char     * configDir,
    261                              struct tr_benc * dictonary );
     260void tr_sessionSaveSettings( tr_session           * session,
     261                             const char           * configDir,
     262                             const struct tr_benc * dictonary );
    262263
    263264/**
     
    558559***/
    559560
    560 void       tr_sessionSetSpeedLimitEnabled ( tr_session        * session,
    561                                             tr_direction        direction,
    562                                             tr_bool             isEnabled );
    563 
    564 tr_bool    tr_sessionIsSpeedLimitEnabled  ( const tr_session  * session,
    565                                             tr_direction        direction );
    566 
    567 void       tr_sessionSetSpeedLimit        ( tr_session        * session,
    568                                             tr_direction        direction,
    569                                             int                 KiB_sec );
    570 
    571 int        tr_sessionGetSpeedLimit        ( const tr_session  * session,
    572                                             tr_direction        direction );
     561/***
     562****  Primary session speed limits
     563***/
     564
     565void     tr_sessionSetSpeedLimit      ( tr_session *, tr_direction, int KB_s );
     566int      tr_sessionGetSpeedLimit      ( const tr_session *, tr_direction );
     567
     568void     tr_sessionLimitSpeed         ( tr_session *, tr_direction, tr_bool );
     569tr_bool  tr_sessionIsSpeedLimited     ( const tr_session *, tr_direction );
     570
     571
     572/***
     573****  Alternative speed limits that are used during scheduled times
     574***/
     575
     576void     tr_sessionSetAltSpeed        ( tr_session *, tr_direction, int KB_s );
     577int      tr_sessionGetAltSpeed        ( const tr_session *, tr_direction );
     578
     579void     tr_sessionUseAltSpeed        ( tr_session *, tr_bool );
     580tr_bool  tr_sessionUsesAltSpeed       ( const tr_session * );
     581
     582void     tr_sessionUseAltSpeedTime    ( tr_session *, tr_bool );
     583tr_bool  tr_sessionUsesAltSpeedTime   ( const tr_session * );
     584
     585void     tr_sessionSetAltSpeedBegin   ( tr_session *, int minsSinceMidnight );
     586int      tr_sessionGetAltSpeedBegin   ( const tr_session * );
     587
     588void     tr_sessionSetAltSpeedEnd     ( tr_session *, int minsSinceMidnight );
     589int      tr_sessionGetAltSpeedEnd     ( const tr_session * );
     590
     591typedef void ( tr_altSpeedFunc )      ( tr_session *, tr_bool active, void * );
     592void     tr_sessionClearAltSpeedFunc  ( tr_session * );
     593void     tr_sessionSetAltSpeedFunc    ( tr_session *, tr_altSpeedFunc *, void * );
    573594
    574595/***
     
    576597***/
    577598
    578 typedef void ( tr_alt_speed_func )( tr_session * session,
    579                                     tr_bool      isAltActive,
    580                                     void       * userData );
    581 
    582 /**
    583  * Register to be notified whenever the alternate speed limits go on and off.
    584  *
    585  * func is invoked FROM LIBTRANSMISSION'S THREAD!
    586  * This means func must be fast (to avoid blocking peers),
    587  * shouldn't call libtransmission functions (to avoid deadlock),
    588  * and shouldn't modify client-level memory without using a mutex!
    589  */
    590 void tr_sessionSetAltSpeedCallback( tr_session         * session,
    591                                     tr_alt_speed_func    func,
    592                                     void               * userData );
    593 
    594 void tr_sessionClearAltSpeedCallback( tr_session * session );
    595 
    596 
    597 void       tr_sessionSetAltSpeedLimitEnabled( tr_session   * session,
    598                                               tr_bool        isEnabled );
    599 
    600 tr_bool    tr_sessionIsAltSpeedLimitEnabled( const tr_session  * session );
    601 
    602 void       tr_sessionSetAltSpeedLimitBegin( tr_session * session,
    603                                             int          minutesSinceMidnight );
    604 
    605 int        tr_sessionGetAltSpeedLimitBegin( const tr_session * session );
    606 
    607 void       tr_sessionSetAltSpeedLimitEnd( tr_session * session,
    608                                           int          minutesSinceMidnight );
    609 
    610 int        tr_sessionGetAltSpeedLimitEnd( const tr_session * session );
    611 
    612 void       tr_sessionSetAltSpeedLimit( tr_session        * session,
    613                                        tr_direction        direction,
    614                                        int                 KiB_sec );
    615 
    616 int        tr_sessionGetAltSpeedLimit( const tr_session  * session,
    617                                        tr_direction        direction );
    618 
    619 /***
    620 ****
    621 ***/
    622 
    623 void       tr_sessionSetRatioLimited      ( tr_session        * session,
    624                                             tr_bool             isEnabled );
    625 
    626 tr_bool    tr_sessionIsRatioLimited       ( const tr_session  * session);
    627 
    628 void       tr_sessionSetRatioLimit        ( tr_session        * session,
    629                                             double              desiredRatio);
    630 
    631 double     tr_sessionGetRatioLimit        ( const tr_session  * session);
    632 
    633 tr_bool    tr_torrentGetSeedRatio         ( const tr_torrent * tor, double * ratio );
    634 
    635 double     tr_sessionGetRawSpeed          ( const tr_session  * session,
    636                                            tr_direction         direction );
    637 
    638 double     tr_sessionGetPieceSpeed        ( const tr_session  * session,
    639                                             tr_direction        direction );
    640 
    641 
    642 void       tr_sessionSetPeerLimit( tr_session  * session,
    643                                    uint16_t      maxGlobalPeers );
    644 
    645 uint16_t   tr_sessionGetPeerLimit( const tr_session * session );
    646 
    647 void       tr_sessionSetPeerLimitPerTorrent( tr_session  * session,
    648                                              uint16_t      maxGlobalPeers );
    649 
    650 uint16_t   tr_sessionGetPeerLimitPerTorrent( const tr_session * session );
     599double     tr_sessionGetRawSpeed      ( const tr_session *, tr_direction );
     600double     tr_sessionGetPieceSpeed    ( const tr_session *, tr_direction );
     601
     602
     603void       tr_sessionSetRatioLimited  ( tr_session *, tr_bool isLimited );
     604tr_bool    tr_sessionIsRatioLimited   ( const tr_session * );
     605
     606void       tr_sessionSetRatioLimit    ( tr_session *, double desiredRatio );
     607double     tr_sessionGetRatioLimit    ( const tr_session * );
     608
     609void       tr_sessionSetPeerLimit( tr_session *, uint16_t maxGlobalPeers );
     610uint16_t   tr_sessionGetPeerLimit( const tr_session * );
     611
     612void       tr_sessionSetPeerLimitPerTorrent( tr_session *, uint16_t maxGlobalPeers );
     613uint16_t   tr_sessionGetPeerLimitPerTorrent( const tr_session * );
    651614
    652615
     
    927890int tr_torrentId( const tr_torrent * torrent );
    928891
    929 /****
    930 *****  Speed Limits
    931 ****/
    932 
    933 void     tr_torrentSetSpeedLimit( tr_torrent *, tr_direction, int KiB_sec );
    934 
    935 int      tr_torrentGetSpeedLimit( const tr_torrent *, tr_direction );
    936 
    937 void     tr_torrentUseSpeedLimit( tr_torrent *, tr_direction, tr_bool do_use );
    938 
    939 tr_bool  tr_torrentIsUsingSpeedLimit( const tr_torrent *, tr_direction );
    940 
    941 void     tr_torrentUseGlobalSpeedLimit( tr_torrent *, tr_direction, tr_bool do_use );
    942 
    943 tr_bool  tr_torrentIsUsingGlobalSpeedLimit ( const tr_torrent *, tr_direction );
     892/***
     893****  Torrent speed limits
     894****
     895***/
     896
     897void     tr_torrentSetSpeedLimit      ( tr_torrent *, tr_direction, int KB_s );
     898int      tr_torrentGetSpeedLimit      ( const tr_torrent *, tr_direction );
     899
     900void     tr_torrentUseSpeedLimit      ( tr_torrent *, tr_direction, tr_bool );
     901tr_bool  tr_torrentUsesSpeedLimit     ( const tr_torrent *, tr_direction );
     902
     903void     tr_torrentUseSessionLimits   ( tr_torrent *, tr_bool );
     904tr_bool  tr_torrentUsesSessionLimits  ( const tr_torrent * );
     905
    944906
    945907/****
     
    964926
    965927double        tr_torrentGetRatioLimit( const tr_torrent  * tor );
     928
     929
     930tr_bool       tr_torrentGetSeedRatio( const tr_torrent *, double * ratio );
    966931
    967932/****
Note: See TracChangeset for help on using the changeset viewer.