Changeset 13499


Ignore:
Timestamp:
Sep 18, 2012, 12:58:10 AM (9 years ago)
Author:
livings124
Message:

#4201 Automatic limit can't be stopped

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r13361 r13499  
    13261326 */
    13271327static void
    1328 testTurtleTime( const struct tr_turtle_info * t,
    1329                 bool * enabled,
    1330                 bool * changed )
     1328testTurtleTime( const struct tr_turtle_info * t, bool * enabled )
    13311329{
    13321330    bool e;
     
    13461344    if( enabled != NULL )
    13471345        *enabled = e;
    1348 
    1349     if( changed != NULL )
    1350     {
    1351         const size_t prev = minute_of_the_week > 0 ? minute_of_the_week - 1
    1352                                                    : MINUTES_PER_WEEK - 1;
    1353         *changed = e != tr_bitfieldHas( &t->minutes, prev );
    1354     }
     1346}
     1347
     1348static inline tr_auto_switch_state_t
     1349autoSwitchState( bool enabled )
     1350{
     1351    return enabled ? TR_AUTO_SWITCH_ON : TR_AUTO_SWITCH_OFF;
    13551352}
    13561353
     
    13591356{
    13601357    bool enabled;
    1361     bool changed;
     1358    bool alreadySwitched;
     1359    tr_auto_switch_state_t newAutoTurtleState;
    13621360
    13631361    assert( t->isClockEnabled );
    13641362
    1365     testTurtleTime( t, &enabled, &changed );
    1366 
    1367     if( changed )
     1363    testTurtleTime( t, &enabled );
     1364    newAutoTurtleState = autoSwitchState( enabled );
     1365    alreadySwitched = ( t->autoTurtleState == newAutoTurtleState );
     1366
     1367    if( !alreadySwitched )
    13681368    {
    13691369        tr_inf( "Time to turn %s turtle mode!", (enabled?"on":"off") );
     1370        t->autoTurtleState = newAutoTurtleState;
    13701371        useAltSpeed( s, t, enabled, false );
    13711372    }
     
    13791380{
    13801381    turtle->changedByUser = false;
     1382    turtle->autoTurtleState = TR_AUTO_SWITCH_UNUSED;
    13811383
    13821384    tr_bitfieldConstruct( &turtle->minutes, MINUTES_PER_WEEK );
     
    13851387
    13861388    if( turtle->isClockEnabled )
    1387         testTurtleTime( turtle, &turtle->isEnabled, NULL );
     1389    {
     1390        testTurtleTime( turtle, &turtle->isEnabled );
     1391        turtle->autoTurtleState = autoSwitchState( turtle->isEnabled );
     1392    }
    13881393
    13891394    altSpeedToggled( session );
     1395
    13901396}
    13911397
     
    14851491    tr_dbg( "Refreshing the turtle mode clock due to user changes" );
    14861492
     1493    t->autoTurtleState = TR_AUTO_SWITCH_UNUSED;
     1494
    14871495    turtleUpdateTable( t );
    14881496
    14891497    if( t->isClockEnabled )
    14901498    {
    1491         bool enabled, changed;
    1492         testTurtleTime( t, &enabled, &changed );
     1499        bool enabled;
     1500        testTurtleTime( t, &enabled );
    14931501        useAltSpeed( s, t, enabled, true );
     1502        t->autoTurtleState = autoSwitchState( enabled );
    14941503    }
    14951504}
  • trunk/libtransmission/session.h

    r13361 r13499  
    3535typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
    3636
     37typedef enum {
     38    TR_AUTO_SWITCH_UNUSED,
     39    TR_AUTO_SWITCH_ON,
     40    TR_AUTO_SWITCH_OFF,
     41} tr_auto_switch_state_t;
     42
    3743enum
    3844{
     
    8894     * limits on or off at that given minute in the week. */
    8995    tr_bitfield minutes;
     96
     97    /* recent action that was done by turtle's automatic switch */
     98    tr_auto_switch_state_t autoTurtleState;
    9099};
    91100
Note: See TracChangeset for help on using the changeset viewer.