1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00
transmission/macosx/InfoWindowController.m
Eric Petit 7e244c6792 Merged Mitchell's changes, this includes:
Adds stop at ratio,
Adds sorting by name, date or state,
Seperates Info window into its own nib,
Adds option to enable or disabled autostarting downloads,
Seperates Network / Transfers in the Preferences
2006-05-25 12:22:19 +00:00

112 lines
3.3 KiB
Objective-C

//
// InfoWindowController.m
// Transmission
//
// Created by Mitchell Livingston on 5/22/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "InfoWindowController.h"
#import "StringAdditions.h"
@implementation InfoWindowController
- (void) awakeFromNib
{
fAppIcon = [[NSApp applicationIconImage] copy];
}
- (void) dealloc
{
[fAppIcon release];
[super dealloc];
}
- (void) updateInfoForTorrents: (NSArray *) torrents
{
int numberSelected = [torrents count];
if (numberSelected != 1)
{
[fImageView setImage: fAppIcon];
[fTracker setStringValue: @""];
[fAnnounce setStringValue: @""];
[fPieceSize setStringValue: @""];
[fPieces setStringValue: @""];
[fHash setStringValue: @""];
[fSeeders setStringValue: @""];
[fLeechers setStringValue: @""];
if (numberSelected > 0)
{
[fName setStringValue: [[NSString stringWithInt: numberSelected]
stringByAppendingString: @" Torrents Selected"]];
uint64_t size = 0;
NSEnumerator * enumerator = [torrents objectEnumerator];
Torrent * torrent;
while ((torrent = [enumerator nextObject]))
size += [torrent size];
[fSize setStringValue: [[NSString
stringForFileSize: size] stringByAppendingString: @" Total"]];
}
else
{
[fName setStringValue: @"No Torrents Selected"];
[fSize setStringValue: @""];
[fDownloaded setStringValue: @""];
[fUploaded setStringValue: @""];
}
}
else
{
Torrent * torrent = [torrents objectAtIndex: 0];
[fImageView setImage: [torrent iconNonFlipped]];
[fName setStringValue: [torrent name]];
[fSize setStringValue: [NSString stringForFileSize: [torrent size]]];
[fTracker setStringValue: [torrent tracker]];
[fAnnounce setStringValue: [torrent announce]];
[fPieceSize setStringValue: [NSString stringForFileSize: [torrent pieceSize]]];
[fPieces setIntValue: [torrent pieceCount]];
[fHash setStringValue: [torrent hash]];
}
[self updateInfoStatsForTorrents: torrents];
}
- (void) updateInfoStatsForTorrents: (NSArray *) torrents
{
int numberSelected = [torrents count];
if (numberSelected > 0)
{
Torrent * torrent;
if (numberSelected == 1)
{
torrent = [torrents objectAtIndex: 0];
int seeders = [torrent seeders], leechers = [torrent leechers];
[fSeeders setStringValue: seeders < 0 ?
@"?" : [NSString stringWithInt: seeders]];
[fLeechers setStringValue: leechers < 0 ?
@"?" : [NSString stringWithInt: leechers]];
}
uint64_t downloaded = 0, uploaded = 0;
NSEnumerator * enumerator = [torrents objectEnumerator];
while ((torrent = [enumerator nextObject]))
{
downloaded += [torrent downloaded];
uploaded += [torrent uploaded];
}
[fDownloaded setStringValue: [NSString stringForFileSize: downloaded]];
[fUploaded setStringValue: [NSString stringForFileSize: uploaded]];
}
}
@end