1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00
transmission/macosx/TorrentGroup.mm

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, total_size = 0;
for (Torrent* torrent in self.torrents)
{
uploaded += torrent.uploadedTotal;
total_size += torrent.totalSizeSelected;
}
return tr_getRatio(uploaded, total_size);
}
- (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