make the per-torrent action menus dynamic as well

This commit is contained in:
Mitchell Livingston 2008-01-10 06:52:13 +00:00
parent 80064189fa
commit fe50c35474
3 changed files with 2136 additions and 3163 deletions

View File

@ -109,8 +109,8 @@ typedef enum
STATUS_TRANSFER_SESSION_TAG = 3 STATUS_TRANSFER_SESSION_TAG = 3
} statusTag; } statusTag;
int speedLimitsActionMenu[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 }; int speedLimitGlobalActionValue[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 };
float ratioLimitsActionMenu[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1 }; float ratioLimitGlobalActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1 };
#define GROWL_DOWNLOAD_COMPLETE @"Download Complete" #define GROWL_DOWNLOAD_COMPLETE @"Download Complete"
#define GROWL_SEEDING_COMPLETE @"Seeding Complete" #define GROWL_SEEDING_COMPLETE @"Seeding Complete"
@ -2089,13 +2089,13 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
NSMenuItem * item; NSMenuItem * item;
int i; int i;
for (i = 0; speedLimitsActionMenu[i] != -1; i++) for (i = 0; speedLimitGlobalActionValue[i] != -1; i++)
{ {
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s", item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s",
"Action menu -> upload/download limit"), speedLimitsActionMenu[i]] action: @selector(setQuickLimitGlobal:) "Action menu -> upload/download limit"), speedLimitGlobalActionValue[i]] action: @selector(setQuickLimitGlobal:)
keyEquivalent: @""]; keyEquivalent: @""];
[item setTarget: self]; [item setTarget: self];
[item setRepresentedObject: [NSNumber numberWithInt: speedLimitsActionMenu[i]]]; [item setRepresentedObject: [NSNumber numberWithInt: speedLimitGlobalActionValue[i]]];
[menu addItem: item]; [menu addItem: item];
[item release]; [item release];
} }
@ -2107,13 +2107,13 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
NSMenuItem * item; NSMenuItem * item;
int i; int i;
for (i = 0; ratioLimitsActionMenu[i] != -1; i++) for (i = 0; ratioLimitGlobalActionValue[i] != -1; i++)
{ {
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%.2f", item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%.2f",
"Action menu -> ratio stop"), ratioLimitsActionMenu[i]] action: @selector(setQuickRatioGlobal:) "Action menu -> ratio stop"), ratioLimitGlobalActionValue[i]] action: @selector(setQuickRatioGlobal:)
keyEquivalent: @""]; keyEquivalent: @""];
[item setTarget: self]; [item setTarget: self];
[item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitsActionMenu[i]]]; [item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitGlobalActionValue[i]]];
[menu addItem: item]; [menu addItem: item];
[item release]; [item release];
} }

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,9 @@
#define ACTION_MENU_UNLIMITED_TAG 102 #define ACTION_MENU_UNLIMITED_TAG 102
#define ACTION_MENU_LIMIT_TAG 103 #define ACTION_MENU_LIMIT_TAG 103
int speedLimitActionValue[] = { 0, 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 };
float ratioLimitActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1.0 };
@interface TorrentTableView (Private) @interface TorrentTableView (Private)
- (NSRect) pauseRectForRow: (int) row; - (NSRect) pauseRectForRow: (int) row;
@ -371,13 +374,29 @@
if (menu == fUploadMenu || menu == fDownloadMenu) if (menu == fUploadMenu || menu == fDownloadMenu)
{ {
NSMenuItem * item;
if ([menu numberOfItems] == 4)
{
int i;
for (i = 0; speedLimitActionValue[i] != -1; i++)
{
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s",
"Action menu -> upload/download limit"), speedLimitActionValue[i]] action: @selector(setQuickLimit:)
keyEquivalent: @""];
[item setTarget: self];
[item setRepresentedObject: [NSNumber numberWithInt: speedLimitActionValue[i]]];
[menu addItem: item];
[item release];
}
}
BOOL upload = menu == fUploadMenu; BOOL upload = menu == fUploadMenu;
int mode = [fMenuTorrent speedMode: upload]; int mode = [fMenuTorrent speedMode: upload];
NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG]; item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
[item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState]; [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
[item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)", [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
"torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]]; "torrent action menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG]; item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
[item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState]; [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
@ -387,12 +406,28 @@
} }
else if (menu == fRatioMenu) else if (menu == fRatioMenu)
{ {
NSMenuItem * item;
if ([menu numberOfItems] == 4)
{
int i;
for (i = 0; ratioLimitActionValue[i] != -1.0; i++)
{
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%.2f",
"Action menu -> ratio stop"), ratioLimitActionValue[i]] action: @selector(setQuickRatio:)
keyEquivalent: @""];
[item setTarget: self];
[item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitActionValue[i]]];
[menu addItem: item];
[item release];
}
}
int mode = [fMenuTorrent ratioSetting]; int mode = [fMenuTorrent ratioSetting];
NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG]; item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
[item setState: mode == NSOnState ? NSOnState : NSOffState]; [item setState: mode == NSOnState ? NSOnState : NSOffState];
[item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)", [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)", "torrent action menu -> ratio stop"),
"torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]]; [fMenuTorrent ratioLimit]]];
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG]; item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
[item setState: mode == NSOffState ? NSOnState : NSOffState]; [item setState: mode == NSOffState ? NSOnState : NSOffState];
@ -436,7 +471,7 @@
{ {
BOOL upload = [sender menu] == fUploadMenu; BOOL upload = [sender menu] == fUploadMenu;
[fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload]; [fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
[fMenuTorrent setSpeedLimit: [[sender title] intValue] upload: upload]; [fMenuTorrent setSpeedLimit: [[sender representedObject] intValue] upload: upload];
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil]; [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
} }
@ -467,7 +502,7 @@
- (void) setQuickRatio: (id) sender - (void) setQuickRatio: (id) sender
{ {
[fMenuTorrent setRatioSetting: NSOnState]; [fMenuTorrent setRatioSetting: NSOnState];
[fMenuTorrent setRatioLimit: [[sender title] floatValue]]; [fMenuTorrent setRatioLimit: [[sender representedObject] floatValue]];
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil]; [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
} }