source: trunk/macosx/TrackerNode.m @ 10104

Last change on this file since 10104 was 10104, checked in by livings124, 12 years ago

specify timeouts in the tracker tab

  • Property svn:keywords set to Date Rev Author Id
File size: 6.7 KB
Line 
1/******************************************************************************
2 * $Id: TrackerNode.m 10104 2010-02-06 00:45:28Z livings124 $
3 *
4 * Copyright (c) 2009-2010 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "TrackerNode.h"
26#import "NSApplicationAdditions.h"
27#import "NSStringAdditions.h"
28
29@implementation TrackerNode
30
31- (id) initWithTrackerStat: (tr_tracker_stat *) stat
32{
33    if ((self = [super init]))
34    {
35        fStat = *stat;
36    }
37   
38    return self;
39}
40
41- (NSString *) description
42{
43    return [@"Tracker: " stringByAppendingString: [self fullAnnounceAddress]];
44}
45
46- (id) copyWithZone: (NSZone *) zone
47{
48    //this object is essentially immutable after initial setup
49    return [self retain];
50}
51
52- (NSString *) host
53{
54    return [NSString stringWithUTF8String: fStat.host];
55}
56
57- (NSString *) fullAnnounceAddress
58{
59    return [NSString stringWithUTF8String: fStat.announce];
60}
61
62- (NSInteger) tier
63{
64    return fStat.tier;
65}
66
67- (NSUInteger) identifier
68{
69    return fStat.id;
70}
71
72- (NSInteger) totalSeeders
73{
74    return fStat.seederCount;
75}
76
77- (NSInteger) totalLeechers
78{
79    return fStat.leecherCount;
80}
81
82- (NSInteger) totalDownloaded
83{
84    return fStat.downloadCount;
85}
86
87- (NSString *) lastAnnounceStatusString
88{
89    NSString * dateString;
90    if (fStat.hasAnnounced)
91    {
92        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
93        [dateFormatter setDateStyle: NSDateFormatterFullStyle];
94        [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
95       
96        if ([NSApp isOnSnowLeopardOrBetter])
97            [dateFormatter setDoesRelativeDateFormatting: YES];
98       
99        dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastAnnounceTime]];
100        [dateFormatter release];
101    }
102    else
103        dateString = NSLocalizedString(@"N/A", "Tracker last announce");
104   
105    NSString * baseString;
106    if (fStat.hasAnnounced && fStat.lastAnnounceTimedOut)
107    {
108        baseString = [NSLocalizedString(@"Announce timed out", "Tracker last announce") stringByAppendingFormat: @": %@", dateString];
109    }
110    else if (fStat.hasAnnounced && !fStat.lastAnnounceSucceeded)
111    {
112        baseString = NSLocalizedString(@"Announce error", "Tracker last announce");
113        NSString * errorString = [NSString stringWithUTF8String: fStat.lastAnnounceResult];
114       
115        if ([errorString isEqualToString: @""])
116            baseString = [baseString stringByAppendingFormat: @": %@", dateString];
117        else
118            baseString = [baseString stringByAppendingFormat: @": %@ - %@", errorString, dateString];
119    }
120    else
121    {
122        baseString = [NSLocalizedString(@"Last Announce", "Tracker last announce") stringByAppendingFormat: @": %@", dateString];
123        if (fStat.hasAnnounced && fStat.lastAnnounceSucceeded)
124        {
125            NSString * peerString;
126            if (fStat.lastAnnouncePeerCount == 1)
127                peerString = NSLocalizedString(@"got 1 peer", "Tracker last announce");
128            else
129                peerString = [NSString stringWithFormat: NSLocalizedString(@"got %d peers", "Tracker last announce"),
130                                        fStat.lastAnnouncePeerCount];
131            baseString = [baseString stringByAppendingFormat: @" (%@)", peerString];
132        }
133    }
134   
135    return baseString;
136}
137
138- (NSString *) nextAnnounceStatusString
139{
140    switch (fStat.announceState)
141    {
142        case TR_TRACKER_ACTIVE:
143            return [NSLocalizedString(@"Announce in progress", "Tracker next announce") stringByAppendingEllipsis];
144       
145        case TR_TRACKER_WAITING:
146            return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"),
147                    [NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]];
148       
149        case TR_TRACKER_QUEUED:
150            return [NSLocalizedString(@"Announce is queued", "Tracker next announce") stringByAppendingEllipsis];
151       
152        case TR_TRACKER_INACTIVE:
153            return fStat.isBackup ? NSLocalizedString(@"Tracker will be used as a backup", "Tracker next announce")
154                                    : NSLocalizedString(@"Announce not scheduled", "Tracker next announce");
155       
156        default:
157            NSAssert1(NO, @"unknown announce state: %d", fStat.announceState);
158            return nil;
159    }
160}
161
162- (NSString *) lastScrapeStatusString
163{
164    NSString * dateString;
165    if (fStat.hasScraped)
166    {
167        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
168        [dateFormatter setDateStyle: NSDateFormatterFullStyle];
169        [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
170       
171        if ([NSApp isOnSnowLeopardOrBetter])
172            [dateFormatter setDoesRelativeDateFormatting: YES];
173       
174        dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastScrapeTime]];
175        [dateFormatter release];
176    }
177    else
178        dateString = NSLocalizedString(@"N/A", "Tracker last scrape");
179   
180    NSString * baseString;
181    if (fStat.hasScraped && !fStat.lastScrapeSucceeded)
182    {
183        baseString = NSLocalizedString(@"Scrape error", "Tracker last scrape");
184        NSString * errorString = [NSString stringWithUTF8String: fStat.lastScrapeResult];
185       
186        if ([errorString isEqualToString: @""])
187            baseString = [baseString stringByAppendingFormat: @": %@", dateString];
188        else
189            baseString = [baseString stringByAppendingFormat: @": %@ - %@", errorString, dateString];
190    }
191    else
192        baseString = [NSLocalizedString(@"Last Scrape", "Tracker last scrape") stringByAppendingFormat: @": %@", dateString];
193   
194    return baseString;
195}
196
197@end
Note: See TracBrowser for help on using the repository browser.