2009-09-26 04:02:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-01-01 21:12:04 +00:00
|
|
|
* Copyright (c) 2009-2010 Transmission authors and contributors
|
2009-09-26 04:02:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "TrackerNode.h"
|
2009-09-28 01:57:35 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
|
|
|
#import "NSStringAdditions.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
|
|
|
|
@implementation TrackerNode
|
|
|
|
|
2009-09-26 16:46:14 +00:00
|
|
|
- (id) initWithTrackerStat: (tr_tracker_stat *) stat
|
2009-09-26 04:02:39 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2009-09-26 16:46:14 +00:00
|
|
|
fStat = *stat;
|
2009-09-26 04:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-01-09 00:57:30 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [@"Tracker: " stringByAppendingString: [self fullAnnounceAddress]];
|
|
|
|
}
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
- (id) copyWithZone: (NSZone *) zone
|
|
|
|
{
|
|
|
|
//this object is essentially immutable after initial setup
|
|
|
|
return [self retain];
|
|
|
|
}
|
|
|
|
|
2009-09-26 04:02:39 +00:00
|
|
|
- (NSString *) host
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fStat.host];
|
|
|
|
}
|
|
|
|
|
2009-09-28 02:55:16 +00:00
|
|
|
- (NSString *) fullAnnounceAddress
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fStat.announce];
|
|
|
|
}
|
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
- (NSInteger) tier
|
|
|
|
{
|
|
|
|
return fStat.tier;
|
|
|
|
}
|
|
|
|
|
2010-01-10 02:34:00 +00:00
|
|
|
- (NSUInteger) identifier
|
|
|
|
{
|
2010-01-13 22:40:07 +00:00
|
|
|
return fStat.id;
|
2010-01-10 02:34:00 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 14:13:20 +00:00
|
|
|
- (NSInteger) totalSeeders
|
|
|
|
{
|
|
|
|
return fStat.seederCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger) totalLeechers
|
|
|
|
{
|
|
|
|
return fStat.leecherCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger) totalDownloaded
|
|
|
|
{
|
|
|
|
return fStat.downloadCount;
|
|
|
|
}
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
- (NSString *) lastAnnounceStatusString
|
|
|
|
{
|
|
|
|
NSString * dateString;
|
2009-10-09 22:29:34 +00:00
|
|
|
if (fStat.hasAnnounced)
|
2009-09-28 01:57:35 +00:00
|
|
|
{
|
2009-09-28 02:36:16 +00:00
|
|
|
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
[dateFormatter setDateStyle: NSDateFormatterFullStyle];
|
|
|
|
[dateFormatter setTimeStyle: NSDateFormatterShortStyle];
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
2009-09-28 02:36:16 +00:00
|
|
|
[dateFormatter setDoesRelativeDateFormatting: YES];
|
|
|
|
|
|
|
|
dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastAnnounceTime]];
|
|
|
|
[dateFormatter release];
|
2009-09-28 01:57:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
dateString = NSLocalizedString(@"N/A", "Tracker last announce");
|
|
|
|
|
2009-11-21 18:23:54 +00:00
|
|
|
NSString * baseString;
|
2010-02-06 00:45:28 +00:00
|
|
|
if (fStat.hasAnnounced && fStat.lastAnnounceTimedOut)
|
|
|
|
baseString = [NSLocalizedString(@"Announce timed out", "Tracker last announce") stringByAppendingFormat: @": %@", dateString];
|
|
|
|
else if (fStat.hasAnnounced && !fStat.lastAnnounceSucceeded)
|
2009-11-21 18:23:54 +00:00
|
|
|
{
|
|
|
|
baseString = NSLocalizedString(@"Announce error", "Tracker last announce");
|
|
|
|
|
2010-02-06 02:35:27 +00:00
|
|
|
NSString * errorString = [NSString stringWithUTF8String: fStat.lastAnnounceResult];
|
2009-11-21 18:23:54 +00:00
|
|
|
if ([errorString isEqualToString: @""])
|
|
|
|
baseString = [baseString stringByAppendingFormat: @": %@", dateString];
|
|
|
|
else
|
|
|
|
baseString = [baseString stringByAppendingFormat: @": %@ - %@", errorString, dateString];
|
|
|
|
}
|
2009-09-28 01:57:35 +00:00
|
|
|
else
|
2009-09-28 02:27:38 +00:00
|
|
|
{
|
2009-11-21 18:23:54 +00:00
|
|
|
baseString = [NSLocalizedString(@"Last Announce", "Tracker last announce") stringByAppendingFormat: @": %@", dateString];
|
2009-09-28 02:27:38 +00:00
|
|
|
if (fStat.hasAnnounced && fStat.lastAnnounceSucceeded)
|
2009-09-28 03:19:11 +00:00
|
|
|
{
|
2010-01-05 04:34:31 +00:00
|
|
|
NSString * peerString;
|
2010-01-31 21:25:49 +00:00
|
|
|
if (fStat.lastAnnouncePeerCount == 1)
|
2010-01-05 04:34:31 +00:00
|
|
|
peerString = NSLocalizedString(@"got 1 peer", "Tracker last announce");
|
|
|
|
else
|
|
|
|
peerString = [NSString stringWithFormat: NSLocalizedString(@"got %d peers", "Tracker last announce"),
|
2009-09-28 03:19:11 +00:00
|
|
|
fStat.lastAnnouncePeerCount];
|
2009-11-21 18:23:54 +00:00
|
|
|
baseString = [baseString stringByAppendingFormat: @" (%@)", peerString];
|
2009-09-28 03:19:11 +00:00
|
|
|
}
|
2009-09-28 02:27:38 +00:00
|
|
|
}
|
2009-09-28 01:57:35 +00:00
|
|
|
|
2009-11-21 18:23:54 +00:00
|
|
|
return baseString;
|
2009-09-28 01:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) nextAnnounceStatusString
|
|
|
|
{
|
2009-10-09 22:29:34 +00:00
|
|
|
switch (fStat.announceState)
|
|
|
|
{
|
|
|
|
case TR_TRACKER_ACTIVE:
|
|
|
|
return [NSLocalizedString(@"Announce in progress", "Tracker next announce") stringByAppendingEllipsis];
|
|
|
|
|
|
|
|
case TR_TRACKER_WAITING:
|
|
|
|
return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"),
|
|
|
|
[NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]];
|
|
|
|
|
|
|
|
case TR_TRACKER_QUEUED:
|
|
|
|
return [NSLocalizedString(@"Announce is queued", "Tracker next announce") stringByAppendingEllipsis];
|
|
|
|
|
|
|
|
case TR_TRACKER_INACTIVE:
|
2009-10-10 00:30:04 +00:00
|
|
|
return fStat.isBackup ? NSLocalizedString(@"Tracker will be used as a backup", "Tracker next announce")
|
|
|
|
: NSLocalizedString(@"Announce not scheduled", "Tracker next announce");
|
2009-10-09 22:29:34 +00:00
|
|
|
|
|
|
|
default:
|
2009-10-10 00:16:57 +00:00
|
|
|
NSAssert1(NO, @"unknown announce state: %d", fStat.announceState);
|
2009-10-09 22:29:34 +00:00
|
|
|
return nil;
|
|
|
|
}
|
2009-09-28 01:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) lastScrapeStatusString
|
|
|
|
{
|
|
|
|
NSString * dateString;
|
2009-10-09 23:02:10 +00:00
|
|
|
if (fStat.hasScraped)
|
2009-09-28 01:57:35 +00:00
|
|
|
{
|
2009-09-28 02:36:16 +00:00
|
|
|
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
[dateFormatter setDateStyle: NSDateFormatterFullStyle];
|
|
|
|
[dateFormatter setTimeStyle: NSDateFormatterShortStyle];
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
2009-09-28 02:36:16 +00:00
|
|
|
[dateFormatter setDoesRelativeDateFormatting: YES];
|
|
|
|
|
|
|
|
dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastScrapeTime]];
|
|
|
|
[dateFormatter release];
|
2009-09-28 01:57:35 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-28 14:51:13 +00:00
|
|
|
dateString = NSLocalizedString(@"N/A", "Tracker last scrape");
|
2009-09-28 01:57:35 +00:00
|
|
|
|
2009-11-21 18:23:54 +00:00
|
|
|
NSString * baseString;
|
2009-09-28 01:57:35 +00:00
|
|
|
if (fStat.hasScraped && !fStat.lastScrapeSucceeded)
|
2009-11-21 18:23:54 +00:00
|
|
|
{
|
|
|
|
baseString = NSLocalizedString(@"Scrape error", "Tracker last scrape");
|
|
|
|
|
2010-02-06 02:35:27 +00:00
|
|
|
NSString * errorString = [NSString stringWithUTF8String: fStat.lastScrapeResult];
|
2009-11-21 18:23:54 +00:00
|
|
|
if ([errorString isEqualToString: @""])
|
|
|
|
baseString = [baseString stringByAppendingFormat: @": %@", dateString];
|
|
|
|
else
|
|
|
|
baseString = [baseString stringByAppendingFormat: @": %@ - %@", errorString, dateString];
|
|
|
|
}
|
2009-09-28 01:57:35 +00:00
|
|
|
else
|
2009-11-21 18:23:54 +00:00
|
|
|
baseString = [NSLocalizedString(@"Last Scrape", "Tracker last scrape") stringByAppendingFormat: @": %@", dateString];
|
2009-09-28 01:57:35 +00:00
|
|
|
|
2009-11-21 18:23:54 +00:00
|
|
|
return baseString;
|
2009-09-28 01:57:35 +00:00
|
|
|
}
|
|
|
|
|
2009-09-26 04:02:39 +00:00
|
|
|
@end
|