INFOPLIST_PREFIX_HEADER = "$(SRCROOT)/libtransmission/version.h";
INFOPLIST_PREPROCESS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
+ ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "";
PREBINDING = NO;
Badger * fBadger;
IBOutlet NSMenu * fDockMenu;
- NSTimer * fSpeedLimitTimer;
-
NSMutableArray * fAutoImportedNames;
NSTimer * fAutoImportTimer;
- (void) toggleSpeedLimit: (id) sender;
- (void) speedLimitChanged: (id) sender;
-- (void) autoSpeedLimitChange: (NSNotification *) notification;
-- (void) autoSpeedLimit: (NSTimer *) timer;
-- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit;
+- (void) altSpeedToggledCallbackIsLimited: (NSNumber *) limited;
- (void) setLimitGlobalEnabled: (id) sender;
- (void) setQuickLimitGlobal: (id) sender;
#define TRAC_URL @"http://trac.transmissionbt.com/"
#define DONATE_URL @"http://www.transmissionbt.com/donate.php"
+static void altSpeedToggledCallback(tr_session * handle UNUSED, tr_bool active, void * controller)
+{
+ [(Controller *)controller performSelectorOnMainThread: @selector(altSpeedToggledCallbackIsLimited:)
+ withObject: [[NSNumber alloc] initWithBool: active] waitUntilDone: NO];
+}
+
static tr_rpc_callback_status rpcCallback(tr_session * handle UNUSED, tr_rpc_callback_type type, struct tr_torrent * torrentStruct, void * controller)
{
[(Controller *)controller rpcCallback: type forTorrentStruct: torrentStruct];
{
fDefaults = [NSUserDefaults standardUserDefaults];
+ //checks for old version speeds of -1
+ if ([fDefaults integerForKey: @"UploadLimit"] < 0)
+ {
+ [fDefaults removeObjectForKey: @"UploadLimit"];
+ [fDefaults setBool: NO forKey: @"CheckUpload"];
+ }
+ if ([fDefaults integerForKey: @"DownloadLimit"] < 0)
+ {
+ [fDefaults removeObjectForKey: @"DownloadLimit"];
+ [fDefaults setBool: NO forKey: @"CheckDownload"];
+ }
+
tr_benc settings;
- tr_bencInitDict(&settings, 22);
+ tr_bencInitDict(&settings, 28);
tr_sessionGetDefaultSettings(&settings);
+ #warning how to work with schedule?
+ if (![fDefaults boolForKey: @"SpeedLimitAuto"])
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, [fDefaults boolForKey: @"SpeedLimit"]);
+
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_ALT_SPEED_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_ALT_SPEED_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
+
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, [fDefaults boolForKey: @"SpeedLimitAuto"]);
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, [PrefsController dateToTimeSum:
+ [fDefaults objectForKey: @"SpeedLimitAutoOnDate"]]);
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, [PrefsController dateToTimeSum:
+ [fDefaults objectForKey: @"SpeedLimitAutoOffDate"]]);
+
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_DSPEED, [fDefaults integerForKey: @"DownloadLimit"]);
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_DSPEED_ENABLED, [fDefaults boolForKey: @"CheckDownload"]);
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_USPEED, [fDefaults integerForKey: @"UploadLimit"]);
+ tr_bencDictAddInt(&settings, TR_PREFS_KEY_USPEED_ENABLED, [fDefaults boolForKey: @"CheckUpload"]);
+
tr_bencDictAddInt(&settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, [fDefaults boolForKey: @"Blocklist"]);
#warning update when changing in prefs
fSoundPlaying = NO;
+ #warning needs to set before init
+ tr_sessionSetAltSpeedFunc(fLib, altSpeedToggledCallback, self);
+
tr_sessionSetRPCCallback(fLib, rpcCallback, self);
[GrowlApplicationBridge setGrowlDelegate: self];
[nc addObserver: self selector: @selector(torrentTableViewSelectionDidChange:)
name: NSOutlineViewSelectionDidChangeNotification object: fTableView];
- [nc addObserver: self selector: @selector(autoSpeedLimitChange:)
- name: @"AutoSpeedLimitChange" object: nil];
-
[nc addObserver: self selector: @selector(changeAutoImport)
name: @"AutoImportSettingChange" object: nil];
if ([fDefaults boolForKey: @"InfoVisible"])
[self showInfo: nil];
-
- //set up the speed limit
- [self autoSpeedLimitChange: nil];
}
- (void) applicationDidFinishLaunching: (NSNotification *) notification
[[NSNotificationCenter defaultCenter] removeObserver: self];
[fTimer invalidate];
- [fSpeedLimitTimer invalidate];
if (fAutoImportTimer)
{
- (void) speedLimitChanged: (id) sender
{
- [fPrefsController applySpeedSettings: nil];
-}
-
-- (void) autoSpeedLimitChange: (NSNotification *) notification
-{
- //clear timer here in case it's not being reset
- [fSpeedLimitTimer invalidate];
- fSpeedLimitTimer = nil;
-
- if (![fDefaults boolForKey: @"SpeedLimitAuto"])
- return;
-
- NSCalendar * calendar = [NSCalendar currentCalendar];
- NSDateComponents * nowComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: [NSDate date]],
- * onComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit
- fromDate: [fDefaults objectForKey: @"SpeedLimitAutoOnDate"]],
- * offComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit
- fromDate: [fDefaults objectForKey: @"SpeedLimitAutoOffDate"]];
-
- //check if should be on if within range
- NSInteger onTime = [onComponents hour] * 60 + [onComponents minute],
- offTime = [offComponents hour] * 60 + [offComponents minute],
- nowTime = [nowComponents hour] * 60 + [nowComponents minute];
-
- BOOL shouldBeOn = NO;
- if (onTime < offTime)
- shouldBeOn = onTime <= nowTime && nowTime < offTime;
- else if (onTime > offTime)
- shouldBeOn = onTime <= nowTime || nowTime < offTime;
- else;
-
- if ([fDefaults boolForKey: @"SpeedLimit"] != shouldBeOn)
- [self toggleSpeedLimit: nil];
-
- //no need to set the timer if both times are equal
- if (onTime == offTime)
- return;
-
- [self setAutoSpeedLimitTimer: !shouldBeOn];
+ tr_sessionUseAltSpeed(fLib, [fDefaults boolForKey: @"SpeedLimit"]);
+ [self updateSpeedFieldsToolTips];
}
-//only called by fSpeedLimitTimer
-- (void) autoSpeedLimit: (NSTimer *) timer
+//limited has been retained
+- (void) altSpeedToggledCallbackIsLimited: (NSNumber *) limited
{
- BOOL shouldLimit = [[timer userInfo] boolValue];
-
- if ([fDefaults boolForKey: @"SpeedLimit"] != shouldLimit)
- {
- [self toggleSpeedLimit: nil];
-
- [GrowlApplicationBridge notifyWithTitle: [fDefaults boolForKey: @"SpeedLimit"]
- ? NSLocalizedString(@"Speed Limit Auto Enabled", "Growl notification title")
- : NSLocalizedString(@"Speed Limit Auto Disabled", "Growl notification title")
- description: NSLocalizedString(@"Bandwidth settings changed", "Growl notification description")
- notificationName: GROWL_AUTO_SPEED_LIMIT iconData: nil priority: 0 isSticky: NO clickContext: nil];
- }
-
- [self setAutoSpeedLimitTimer: !shouldLimit];
-}
+ const BOOL isLimited = [limited boolValue];
-- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit
-{
- NSDate * timerDate = [fDefaults objectForKey: nextIsLimit ? @"SpeedLimitAutoOnDate" : @"SpeedLimitAutoOffDate"];
-
- //create date with combination of the current date and the date to go off
- NSCalendar * calendar = [NSCalendar currentCalendar];
- NSDateComponents * nowComponents = [calendar components: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit
- | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: [NSDate date]],
- * timerComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: timerDate];
-
- //check if should be the next day
- NSInteger nowTime = [nowComponents hour] * 60 + [nowComponents minute],
- timerTime = [timerComponents hour] * 60 + [timerComponents minute];
- if (timerTime < nowTime)
- [nowComponents setDay: [nowComponents day] + 1]; //properly goes to next month when appropriate
-
- [nowComponents setHour: [timerComponents hour]];
- [nowComponents setMinute: [timerComponents minute]];
- [nowComponents setSecond: 0];
-
- NSDate * dateToUse = [calendar dateFromComponents: nowComponents];
+ [fDefaults setBool: isLimited forKey: @"SpeedLimit"];
+ [self updateSpeedFieldsToolTips];
- fSpeedLimitTimer = [[NSTimer alloc] initWithFireDate: dateToUse interval: 0 target: self selector: @selector(autoSpeedLimit:)
- userInfo: [NSNumber numberWithBool: nextIsLimit] repeats: NO];
+ #warning don't show on startup or on manual changed
+ [GrowlApplicationBridge notifyWithTitle: isLimited
+ ? NSLocalizedString(@"Speed Limit Auto Enabled", "Growl notification title")
+ : NSLocalizedString(@"Speed Limit Auto Disabled", "Growl notification title")
+ description: NSLocalizedString(@"Bandwidth settings changed", "Growl notification description")
+ notificationName: GROWL_AUTO_SPEED_LIMIT iconData: nil priority: 0 isSticky: NO clickContext: nil];
- NSRunLoop * loop = [NSRunLoop mainRunLoop];
- [loop addTimer: fSpeedLimitTimer forMode: NSDefaultRunLoopMode];
- [loop addTimer: fSpeedLimitTimer forMode: NSModalPanelRunLoopMode];
- [loop addTimer: fSpeedLimitTimer forMode: NSEventTrackingRunLoopMode];
- [fSpeedLimitTimer release];
+ [limited release];
}
- (void) setLimitGlobalEnabled: (id) sender
case kIOMessageSystemHasPoweredOn:
//resume sleeping transfers after we wake up
[fTorrents makeObjectsPerformSelector: @selector(wakeUp)];
- [self autoSpeedLimitChange: nil];
+ #warning check speed limit timer?
+ //[self autoSpeedLimitChange: nil];
break;
}
}
- (void) setRatioStop: (id) sender;
- (void) applySpeedSettings: (id) sender;
+- (void) applyAltSpeedSettings;
- (void) updateLimitFields;
- (void) setGlobalLimit: (id) sender;
- (void) setSpeedLimit: (id) sender;
- (void) setAutoSpeedLimit: (id) sender;
+- (void) setAutoSpeedLimitTime: (id) sender;
++ (NSInteger) dateToTimeSum: (NSDate *) date;
- (void) setAutoImport: (id) sender;
- (void) importFolderSheetShow: (id) sender;
{
fDefaults = [NSUserDefaults standardUserDefaults];
- //checks for old version speeds of -1
- if ([fDefaults integerForKey: @"UploadLimit"] < 0)
- {
- [fDefaults removeObjectForKey: @"UploadLimit"];
- [fDefaults setBool: NO forKey: @"CheckUpload"];
- }
- if ([fDefaults integerForKey: @"DownloadLimit"] < 0)
- {
- [fDefaults removeObjectForKey: @"DownloadLimit"];
- [fDefaults setBool: NO forKey: @"CheckDownload"];
- }
-
//check for old version download location (before 1.1)
NSString * choice;
if ((choice = [fDefaults stringForKey: @"DownloadChoice"]))
//set encryption
[self setEncryptionMode: nil];
- //actually set bandwidth limits
- [self applySpeedSettings: nil];
-
//set proxy type
[self updateProxyType];
[self updateProxyPassword];
- (void) applySpeedSettings: (id) sender
{
- if ([fDefaults boolForKey: @"SpeedLimit"])
- {
- tr_sessionSetSpeedLimitEnabled(fHandle, TR_UP, 1);
- tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
-
- tr_sessionSetSpeedLimitEnabled(fHandle, TR_DOWN, 1);
- tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
- }
- else
- {
- tr_sessionSetSpeedLimitEnabled(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
- tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
-
- tr_sessionSetSpeedLimitEnabled(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
- tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"DownloadLimit"]);
- }
+ tr_sessionLimitSpeed(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
+ tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
+
+ tr_sessionLimitSpeed(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
+ tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"DownloadLimit"]);
[[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
}
+- (void) applyAltSpeedSettings
+{
+ tr_sessionSetAltSpeed(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
+ tr_sessionSetAltSpeed(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
+
+ [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
+}
+
- (void) applyRatioSetting: (id) sender
{
//[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
{
[fDefaults setInteger: [sender intValue] forKey: sender == fSpeedLimitUploadField
? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
- [self applySpeedSettings: self];
+ [self applyAltSpeedSettings];
}
- (void) setAutoSpeedLimit: (id) sender
{
- [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
+ tr_sessionUseAltSpeedTime(fHandle, [fDefaults boolForKey: @"SpeedLimitAuto"]);
+}
+
+- (void) setAutoSpeedLimitTime: (id) sender
+{
+ tr_sessionSetAltSpeedBegin(fHandle, [PrefsController dateToTimeSum: [fDefaults objectForKey: @"SpeedLimitAutoOnDate"]]);
+ tr_sessionSetAltSpeedEnd(fHandle, [PrefsController dateToTimeSum: [fDefaults objectForKey: @"SpeedLimitAutoOffDate"]]);
+}
+
++ (NSInteger) dateToTimeSum: (NSDate *) date
+{
+ NSCalendar * calendar = [NSCalendar currentCalendar];
+ NSDateComponents * components = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: date];
+ return [components hour] * 60 + [components minute];
}
- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
}
+#warning probably needs to be updated
- (void) rpcUpdatePrefs
{
//encryption
[self updatePortStatus];
//speed limit - down
- BOOL downLimitEnabled = tr_sessionIsSpeedLimitEnabled(fHandle, TR_DOWN);
+ BOOL downLimitEnabled = tr_sessionIsSpeedLimited(fHandle, TR_DOWN);
[fDefaults setBool: downLimitEnabled forKey: @"CheckDownload"];
int downLimit = tr_sessionGetSpeedLimit(fHandle, TR_DOWN);
[fDefaults setInteger: downLimit forKey: @"DownloadLimit"];
//speed limit - up
- BOOL upLimitEnabled = tr_sessionIsSpeedLimitEnabled(fHandle, TR_UP);
+ BOOL upLimitEnabled = tr_sessionIsSpeedLimited(fHandle, TR_UP);
[fDefaults setBool: upLimitEnabled forKey: @"CheckUpload"];
int upLimit = tr_sessionGetSpeedLimit(fHandle, TR_UP);
- (BOOL) usesSpeedLimit: (BOOL) upload
{
- return tr_torrentIsUsingSpeedLimit(fHandle, upload ? TR_UP : TR_DOWN);
+ return tr_torrentUsesSpeedLimit(fHandle, upload ? TR_UP : TR_DOWN);
}
- (void) setUseSpeedLimit: (BOOL) use upload: (BOOL) upload
- (BOOL) usesGlobalSpeedLimit
{
- const BOOL up = tr_torrentIsUsingGlobalSpeedLimit(fHandle, TR_UP);
- const BOOL down = tr_torrentIsUsingGlobalSpeedLimit(fHandle, TR_DOWN);
- NSAssert(up == down, @"upload and download global limit settings should have the same value");
- return up;
+ return tr_torrentUsesSessionLimits(fHandle);
}
- (void) setUseGlobalSpeedLimit: (BOOL) use
{
- tr_torrentUseGlobalSpeedLimit(fHandle, TR_UP, use);
- tr_torrentUseGlobalSpeedLimit(fHandle, TR_DOWN, use);
+ tr_torrentUseSessionLimits(fHandle, use);
}
- (void) setMaxPeerConnect: (uint16_t) count
</object>
<string key="NSFrame">{{1, 1}, {141, 169}}</string>
<reference key="NSSuperview" ref="544077474"/>
+ <reference key="NSNextKeyView" ref="638525082"/>
<reference key="NSDocView" ref="638525082"/>
<reference key="NSBGColor" ref="729660797"/>
<int key="NScvFlags">4</int>
</object>
<string key="NSFrame">{{20, 49}, {143, 171}}</string>
<reference key="NSSuperview" ref="284666863"/>
+ <reference key="NSNextKeyView" ref="568562479"/>
<int key="NSsFlags">530</int>
<reference key="NSVScroller" ref="287972127"/>
<reference key="NSHScroller" ref="781866080"/>
</object>
<string key="NSFrame">{{1, 1}, {291, 76}}</string>
<reference key="NSSuperview" ref="122119447"/>
+ <reference key="NSNextKeyView" ref="173651346"/>
<reference key="NSDocView" ref="173651346"/>
<reference key="NSBGColor" ref="729660797"/>
<int key="NScvFlags">4</int>
</object>
<string key="NSFrame">{{103, 96}, {308, 78}}</string>
<reference key="NSSuperview" ref="810116101"/>
+ <reference key="NSNextKeyView" ref="206862330"/>
<int key="NSsFlags">18</int>
<reference key="NSVScroller" ref="220703981"/>
<reference key="NSHScroller" ref="383062716"/>
</object>
<int key="connectionID">531</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">setAutoSpeedLimit:</string>
- <reference key="source" ref="511492310"/>
- <reference key="destination" ref="401711944"/>
- </object>
- <int key="connectionID">532</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">setAutoSpeedLimit:</string>
- <reference key="source" ref="511492310"/>
- <reference key="destination" ref="497078689"/>
- </object>
- <int key="connectionID">533</int>
- </object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: values.SpeedLimitAutoOnDate</string>
</object>
<int key="connectionID">1900</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">setAutoSpeedLimitTime:</string>
+ <reference key="source" ref="511492310"/>
+ <reference key="destination" ref="497078689"/>
+ </object>
+ <int key="connectionID">1902</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">setAutoSpeedLimitTime:</string>
+ <reference key="source" ref="511492310"/>
+ <reference key="destination" ref="401711944"/>
+ </object>
+ <int key="connectionID">1903</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">1901</int>
+ <int key="maxID">1903</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<string>setAutoImport:</string>
<string>setAutoSize:</string>
<string>setAutoSpeedLimit:</string>
+ <string>setAutoSpeedLimitTime:</string>
<string>setAutoUpdateToBeta:</string>
<string>setBadge:</string>
<string>setBlocklistAutoUpdate:</string>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">