Ignore:
Timestamp:
Mar 30, 2009, 5:25:35 PM (13 years ago)
Author:
charles
Message:

(trunk) add a did-the-user-do-this flag to the "alt speed toggled" callback

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r8108 r8118  
    471471}
    472472
     473static void useAltSpeed( tr_session * session, tr_bool enabled, tr_bool byUser );
     474static void useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUser );
     475
    473476static void
    474477tr_sessionInitImpl( void * vdata )
     
    477480    int64_t j;
    478481    double  d;
    479     tr_bool useAltSpeedTime;
    480482    tr_bool found;
    481483    tr_bool boolVal;
     
    654656    found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal );
    655657    assert( found );
    656     useAltSpeedTime = boolVal;
    657     tr_sessionUseAltSpeedTime( session, useAltSpeedTime );
    658 
    659     if( !useAltSpeedTime )
     658    useAltSpeedTime( session, boolVal, FALSE );
     659
     660    if( !boolVal )
    660661    {
    661662        found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal );
    662663        assert( found );
    663         tr_sessionUseAltSpeed( session, boolVal );
     664        useAltSpeed( session, boolVal, FALSE );
    664665    }
    665666    else
    666         tr_sessionUseAltSpeed( session, isAltTime( session ) );
     667        useAltSpeed( session, isAltTime( session ), FALSE );
    667668
    668669    /**
     
    914915
    915916    if( session->altCallback != NULL )
    916         (*session->altCallback)( session, session->altSpeedEnabled, session->altCallbackUserData );
     917        (*session->altCallback)( session, session->altSpeedEnabled, session->altSpeedChangedByUser, session->altCallbackUserData );
    917918}
    918919
     
    954955        if( currentMinute == session->altSpeedTimeBegin )
    955956        {
    956             tr_sessionUseAltSpeed( session, TRUE );
     957            useAltSpeed( session, TRUE, FALSE );
    957958        }
    958959        else if( currentMinute == session->altSpeedTimeEnd )
    959960        {
    960             tr_sessionUseAltSpeed( session, FALSE );
     961            useAltSpeed( session, FALSE, FALSE );
    961962        }
    962963    }
     
    10371038
    10381039void
     1040useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUser )
     1041{
     1042    assert( tr_isSession( session ) );
     1043    assert( tr_isBool( enabled ) );
     1044    assert( tr_isBool( byUser ) );
     1045
     1046    if( session->altSpeedTimeEnabled != enabled )
     1047    {
     1048        const tr_bool isAlt = isAltTime( session );
     1049
     1050        session->altSpeedTimeEnabled = enabled;
     1051
     1052        if( enabled && session->altSpeedEnabled != isAlt )
     1053            useAltSpeed( session, isAlt, byUser );
     1054    }
     1055}
     1056void
    10391057tr_sessionUseAltSpeedTime( tr_session * s, tr_bool b )
    10401058{
    1041     assert( tr_isSession( s ) );
    1042     assert( tr_isBool( b ) );
    1043 
    1044     if( s->altSpeedTimeEnabled != b )
    1045     {
    1046         const tr_bool isAlt = isAltTime( s );
    1047 
    1048         s->altSpeedTimeEnabled = b;
    1049 
    1050         if( b && s->altSpeedEnabled != isAlt )
    1051             tr_sessionUseAltSpeed( s, isAlt );
    1052     }
     1059    useAltSpeedTime( s, b, TRUE );
    10531060}
    10541061
     
    10721079
    10731080        if( tr_sessionUsesAltSpeedTime( s ) )
    1074             tr_sessionUseAltSpeed( s, isAltTime( s ) );
     1081            useAltSpeed( s, isAltTime( s ), TRUE );
    10751082    }
    10761083}
     
    10951102
    10961103        if( tr_sessionUsesAltSpeedTime( s ) )
    1097             tr_sessionUseAltSpeed( s, isAltTime( s ) );
     1104            useAltSpeed( s, isAltTime( s ), TRUE );
    10981105    }
    10991106}
     
    11081115
    11091116void
    1110 tr_sessionUseAltSpeed( tr_session * s, tr_bool b )
     1117useAltSpeed( tr_session * s, tr_bool enabled, tr_bool byUser )
    11111118{
    11121119    assert( tr_isSession( s ) );
    1113     assert( tr_isBool( b ) );
    1114 
    1115     if( s->altSpeedEnabled != b)
    1116     {
    1117         s->altSpeedEnabled = b;
     1120    assert( tr_isBool( enabled ) );
     1121    assert( tr_isBool( byUser ) );
     1122
     1123    if( s->altSpeedEnabled != enabled)
     1124    {
     1125        s->altSpeedEnabled = enabled;
     1126        s->altSpeedChangedByUser = byUser;
    11181127   
    11191128        tr_runInEventThread( s, altSpeedToggled, s );
    11201129    }
     1130}
     1131void
     1132tr_sessionUseAltSpeed( tr_session * session, tr_bool enabled )
     1133{
     1134    useAltSpeed( session, enabled, TRUE );
    11211135}
    11221136
Note: See TracChangeset for help on using the changeset viewer.