source: trunk/macosx/TrackerNode.m @ 9203

Last change on this file since 9203 was 9203, checked in by livings124, 13 years ago

fix favicons

File size: 5.1 KB
Line 
1/******************************************************************************
2 * $Id$
3 *
4 * Copyright (c) 2009 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- (id) copyWithZone: (NSZone *) zone
42{
43    //this object is essentially immutable after initial setup
44    return [self retain];
45}
46
47- (NSString *) host
48{
49    return [NSString stringWithUTF8String: fStat.host];
50}
51
52- (NSString *) fullAnnounceAddress
53{
54    return [NSString stringWithUTF8String: fStat.announce];
55}
56
57- (NSString *) lastAnnounceStatusString
58{
59    NSString * dateString;
60    if (fStat.hasAnnounced && fStat.lastAnnounceTime != 0)
61    {
62        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
63        [dateFormatter setDateStyle: NSDateFormatterFullStyle];
64        [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
65       
66        if ([NSApp isOnSnowLeopardOrBetter])
67            [dateFormatter setDoesRelativeDateFormatting: YES];
68       
69        dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastAnnounceTime]];
70        [dateFormatter release];
71    }
72    else
73        dateString = NSLocalizedString(@"N/A", "Tracker last announce");
74   
75    if (fStat.hasAnnounced && !fStat.lastAnnounceSucceeded)
76        dateString = [NSString stringWithFormat: @"%@: %@ - %@", NSLocalizedString(@"Announce error", "Tracker last announce"),
77                        [NSString stringWithUTF8String: fStat.lastAnnounceResult], dateString];
78    else
79    {
80        dateString = [NSString stringWithFormat: NSLocalizedString(@"Last Announce: %@", "Tracker last announce"),
81                        dateString];
82        if (fStat.hasAnnounced && fStat.lastAnnounceSucceeded)
83        {
84            NSString * peerString = [NSString stringWithFormat: NSLocalizedString(@"got %d peers", "Tracker last announce"),
85                                        fStat.lastAnnouncePeerCount];
86            dateString = [dateString stringByAppendingFormat: @" (%@)", peerString];
87        }
88    }
89   
90    return dateString;
91}
92
93- (NSString *) nextAnnounceStatusString
94{
95    if (fStat.isAnnouncing)
96        return [NSLocalizedString(@"Announce in progress", "Tracker next announce") stringByAppendingEllipsis];
97    else if (fStat.willAnnounce)
98        return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"),
99                [NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]];
100    else if (fStat.isActive)
101        return NSLocalizedString(@"Announce not scheduled", "Tracker next announce");
102    else
103        return NSLocalizedString(@"Tracker will be used as a backup", "Tracker next announce");
104}
105
106- (NSString *) lastScrapeStatusString
107{
108    NSString * dateString;
109    if (fStat.hasScraped && fStat.lastScrapeTime != 0)
110    {
111        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
112        [dateFormatter setDateStyle: NSDateFormatterFullStyle];
113        [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
114       
115        if ([NSApp isOnSnowLeopardOrBetter])
116            [dateFormatter setDoesRelativeDateFormatting: YES];
117       
118        dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeIntervalSince1970: fStat.lastScrapeTime]];
119        [dateFormatter release];
120    }
121    else
122        dateString = NSLocalizedString(@"N/A", "Tracker last announce");
123   
124    if (fStat.hasScraped && !fStat.lastScrapeSucceeded)
125        dateString = [NSString stringWithFormat: @"%@: %@ - %@", NSLocalizedString(@"Scrape error", "Tracker last announce"),
126                        [NSString stringWithUTF8String: fStat.lastScrapeResult], dateString];
127    else
128        dateString = [NSString stringWithFormat: NSLocalizedString(@"Last Scrape: %@", "Tracker last announce"), dateString];
129   
130    return dateString;
131}
132
133@end
Note: See TracBrowser for help on using the repository browser.