source: trunk/macosx/TrackerNode.m @ 10053

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

remove a few 1.8 -> 1.9 warnings

  • Property svn:keywords set to Date Rev Author Id
File size: 6.5 KB
Line 
1/******************************************************************************
2 * $Id: TrackerNode.m 10053 2010-01-31 21:25:49Z 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.lastAnnounceSucceeded)
107    {
108        baseString = NSLocalizedString(@"Announce error", "Tracker last announce");
109        NSString * errorString = [NSString stringWithUTF8String: fStat.lastAnnounceResult];
110       
111        if ([errorString isEqualToString: @""])
112            baseString = [baseString stringByAppendingFormat: @": %@", dateString];
113        else
114            baseString = [baseString stringByAppendingFormat: @": %@ - %@", errorString, dateString];
115    }
116    else
117    {
118        baseString = [NSLocalizedString(@"Last Announce", "Tracker last announce") stringByAppendingFormat: @": %@", dateString];
119        if (fStat.hasAnnounced && fStat.lastAnnounceSucceeded)
120        {
121            NSString * peerString;
122            if (fStat.lastAnnouncePeerCount == 1)
123                peerString = NSLocalizedString(@"got 1 peer", "Tracker last announce");
124            else
125                peerString = [NSString stringWithFormat: NSLocalizedString(@"got %d peers", "Tracker last announce"),
126                                        fStat.lastAnnouncePeerCount];
127            baseString = [baseString stringByAppendingFormat: @" (%@)", peerString];
128        }
129    }
130   
131    return baseString;
132}
133
134- (NSString *) nextAnnounceStatusString
135{
136    switch (fStat.announceState)
137    {
138        case TR_TRACKER_ACTIVE:
139            return [NSLocalizedString(@"Announce in progress", "Tracker next announce") stringByAppendingEllipsis];
140       
141        case TR_TRACKER_WAITING:
142            return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"),
143                    [NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]];
144       
145        case TR_TRACKER_QUEUED:
146            return [NSLocalizedString(@"Announce is queued", "Tracker next announce") stringByAppendingEllipsis];
147       
148        case TR_TRACKER_INACTIVE:
149            return fStat.isBackup ? NSLocalizedString(@"Tracker will be used as a backup", "Tracker next announce")
150                                    : NSLocalizedString(@"Announce not scheduled", "Tracker next announce");
151       
152        default:
153            NSAssert1(NO, @"unknown announce state: %d", fStat.announceState);
154            return nil;
155    }
156}
157
158- (NSString *) lastScrapeStatusString
159{
160    NSString * dateString;
161    if (fStat.hasScraped)
162    {
163        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
164        [dateFormatter setDateStyle: NSDateFormatterFullStyle];
165        [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
166       
167        if ([NSApp isOnSnowLeopardOrBetter])
168            [dateFormatter setDoesRelativeDateFormatting: YES];
169       
170        dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastScrapeTime]];
171        [dateFormatter release];
172    }
173    else
174        dateString = NSLocalizedString(@"N/A", "Tracker last scrape");
175   
176    NSString * baseString;
177    if (fStat.hasScraped && !fStat.lastScrapeSucceeded)
178    {
179        baseString = NSLocalizedString(@"Scrape error", "Tracker last scrape");
180        NSString * errorString = [NSString stringWithUTF8String: fStat.lastScrapeResult];
181       
182        if ([errorString isEqualToString: @""])
183            baseString = [baseString stringByAppendingFormat: @": %@", dateString];
184        else
185            baseString = [baseString stringByAppendingFormat: @": %@ - %@", errorString, dateString];
186    }
187    else
188        baseString = [NSLocalizedString(@"Last Scrape", "Tracker last scrape") stringByAppendingFormat: @": %@", dateString];
189   
190    return baseString;
191}
192
193@end
Note: See TracBrowser for help on using the repository browser.