clicking on the group speed rates will toggle with ratio

This commit is contained in:
Mitchell Livingston 2008-02-28 02:17:17 +00:00
parent f00dd3cbd3
commit af2339bb9e
3 changed files with 56 additions and 11 deletions

View File

@ -42,6 +42,7 @@
#import "ExpandedPathToPathTransformer.h" #import "ExpandedPathToPathTransformer.h"
#import "ExpandedPathToIconTransformer.h" #import "ExpandedPathToIconTransformer.h"
#import "SpeedLimitToTurtleIconTransformer.h" #import "SpeedLimitToTurtleIconTransformer.h"
#include "utils.h" //tr_getRatio()
#import <Sparkle/Sparkle.h> #import <Sparkle/Sparkle.h>
@ -2495,21 +2496,40 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
return group != -1 ? [[GroupsWindowController groups] imageForIndex: group isSmall: YES] return group != -1 ? [[GroupsWindowController groups] imageForIndex: group isSmall: YES]
: [NSImage imageNamed: NSImageNameStopProgressTemplate]; : [NSImage imageNamed: NSImageNameStopProgressTemplate];
} }
else if ([ident isEqualToString: @"UL Image"])
return [NSImage imageNamed: @"UpArrowGroupTemplate.png"];
else if ([ident isEqualToString: @"DL Image"]) else if ([ident isEqualToString: @"DL Image"])
return [NSImage imageNamed: @"DownArrowGroupTemplate.png"]; return ![fDefaults boolForKey: @"DisplayGroupRowRatio"] ? [NSImage imageNamed: @"DownArrowGroupTemplate.png"] : nil;
else if ([ident isEqualToString: @"UL Image"])
return [NSImage imageNamed: [fDefaults boolForKey: @"DisplayGroupRowRatio"]
? @"YingYangTemplate.png" : @"UpArrowGroupTemplate.png"];
else else
{ {
BOOL upload = [ident isEqualToString: @"UL"]; BOOL upload = [ident isEqualToString: @"UL"];
if ([fDefaults boolForKey: @"DisplayGroupRowRatio"])
float rate = 0.0; {
NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator]; if (!upload)
Torrent * torrent; return nil;
while ((torrent = [enumerator nextObject]))
rate += upload ? [torrent uploadRate] : [torrent downloadRate]; uint64_t uploaded = 0, downloaded = 0;
NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator];
return [NSString stringForSpeed: rate]; Torrent * torrent;
while ((torrent = [enumerator nextObject]))
{
uploaded += [torrent uploadedTotal];
downloaded += [torrent downloadedTotal];
}
return [NSString stringForRatio: tr_getRatio(uploaded, downloaded)];
}
else
{
float rate = 0.0;
NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator];
Torrent * torrent;
while ((torrent = [enumerator nextObject]))
rate += upload ? [torrent uploadRate] : [torrent downloadRate];
return [NSString stringForSpeed: rate];
}
} }
} }
else else

View File

@ -34,6 +34,8 @@
<string>~/Desktop</string> <string>~/Desktop</string>
<key>DeleteOriginalTorrent</key> <key>DeleteOriginalTorrent</key>
<false/> <false/>
<key>DisplayGroupRowRatio</key>
<false/>
<key>DisplayPeerProgressBarNumber</key> <key>DisplayPeerProgressBarNumber</key>
<false/> <false/>
<key>DisplayProgressBarAvailable</key> <key>DisplayProgressBarAvailable</key>

View File

@ -45,6 +45,9 @@
- (BOOL) pointInProgressRect: (NSPoint) point; - (BOOL) pointInProgressRect: (NSPoint) point;
- (BOOL) pointInMinimalStatusRect: (NSPoint) point; - (BOOL) pointInMinimalStatusRect: (NSPoint) point;
- (BOOL) pointInGroupStatusRect: (NSPoint) point;
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files; - (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
- (void) resizePiecesBarIncrement; - (void) resizePiecesBarIncrement;
@ -338,6 +341,14 @@
{ {
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil]; NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
//check to toggle group status before anything else
if ([self pointInGroupStatusRect: point])
{
[fDefaults setBool: ![fDefaults boolForKey: @"DisplayGroupRowRatio"] forKey: @"DisplayGroupRowRatio"];
[self reloadData];
return;
}
BOOL pushed = [self pointInControlRect: point] || [self pointInRevealRect: point] || [self pointInActionRect: point] BOOL pushed = [self pointInControlRect: point] || [self pointInRevealRect: point] || [self pointInActionRect: point]
|| [self pointInProgressRect: point] || [self pointInMinimalStatusRect: point]; || [self pointInProgressRect: point] || [self pointInMinimalStatusRect: point];
@ -753,6 +764,18 @@
return NSPointInRect(point, [cell minimalStatusRectForBounds: [self rectOfRow: row]]); return NSPointInRect(point, [cell minimalStatusRectForBounds: [self rectOfRow: row]]);
} }
- (BOOL) pointInGroupStatusRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0 || [[self itemAtRow: row] isKindOfClass: [Torrent class]])
return NO;
NSString * ident = [[[self tableColumns] objectAtIndex: [self columnAtPoint: point]] identifier];
return [ident isEqualToString: @"UL"] || [ident isEqualToString: @"UL Image"]
|| (([ident isEqualToString: @"DL"] || [ident isEqualToString: @"DL Image"])
&& ![fDefaults boolForKey: @"DisplayGroupRowRatio"]);
}
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files - (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
{ {
BOOL create = [menu numberOfItems] <= 0; BOOL create = [menu numberOfItems] <= 0;