1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 19:46:56 +00:00
transmission/macosx/TorrentGroup.mm
2022-02-22 10:04:20 -06:00

68 lines
1.4 KiB
Text

// This file Copyright © 2008-2022 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
#include <libtransmission/transmission.h>
#include <libtransmission/utils.h> // tr_getRatio()
#import "TorrentGroup.h"
#import "GroupsController.h"
#import "Torrent.h"
@implementation TorrentGroup
- (instancetype)initWithGroup:(NSInteger)group
{
if ((self = [super init]))
{
_groupIndex = group;
_torrents = [[NSMutableArray alloc] init];
}
return self;
}
- (NSString*)description
{
return [NSString stringWithFormat:@"Torrent Group %ld: %@", self.groupIndex, self.torrents];
}
- (NSInteger)groupOrderValue
{
return [GroupsController.groups rowValueForIndex:self.groupIndex];
}
- (CGFloat)ratio
{
uint64_t uploaded = 0, downloaded = 0;
for (Torrent* torrent in self.torrents)
{
uploaded += torrent.uploadedTotal;
downloaded += torrent.downloadedTotal;
}
return tr_getRatio(uploaded, downloaded);
}
- (CGFloat)uploadRate
{
CGFloat rate = 0.0;
for (Torrent* torrent in self.torrents)
{
rate += torrent.uploadRate;
}
return rate;
}
- (CGFloat)downloadRate
{
CGFloat rate = 0.0;
for (Torrent* torrent in self.torrents)
{
rate += torrent.downloadRate;
}
return rate;
}
@end