source: trunk/macosx/TrackerNode.m @ 9198

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

add lastAnnouncePeerCount to tracker info tab

File size: 5.2 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#warning consider "isActive"
53- (NSString *) lastAnnounceStatusString
54{
55    NSString * dateString;
56    if (fStat.hasAnnounced && fStat.lastAnnounceTime != 0)
57    {
58        NSDate * announceDate = [NSDate dateWithTimeIntervalSince1970: fStat.lastAnnounceTime];
59        if ([NSApp isOnSnowLeopardOrBetter])
60            dateString = [NSDateFormatter localizedStringFromDate: announceDate dateStyle: NSDateFormatterFullStyle
61                            timeStyle: NSDateFormatterShortStyle];
62        else
63        {
64            NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
65            [dateFormatter setDateStyle: NSDateFormatterFullStyle];
66            [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
67           
68            dateString = [dateFormatter stringFromDate: announceDate];
69            [dateFormatter release];
70        }
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            dateString = [dateString stringByAppendingFormat: NSLocalizedString(@" (got %d peers)", "Tracker last announce"),
84                            fStat.lastAnnouncePeerCount];
85    }
86   
87    return dateString;
88}
89
90- (NSString *) nextAnnounceStatusString
91{
92    if (fStat.isAnnouncing)
93        return [NSLocalizedString(@"Announce in progress", "Tracker next announce") stringByAppendingEllipsis];
94    else if (fStat.willAnnounce)
95        return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"),
96                [NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]];
97    else
98        return NSLocalizedString(@"Announce not scheduled", "Tracker next announce");
99}
100
101- (NSString *) lastScrapeStatusString
102{
103    NSString * dateString;
104    if (fStat.hasScraped && fStat.lastScrapeTime != 0)
105    {
106        NSDate * scrapeDate = [NSDate dateWithTimeIntervalSince1970: fStat.lastScrapeTime];
107        if ([NSApp isOnSnowLeopardOrBetter])
108            dateString = [NSDateFormatter localizedStringFromDate: scrapeDate dateStyle: NSDateFormatterFullStyle
109                            timeStyle: NSDateFormatterShortStyle];
110        else
111        {
112            NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
113            [dateFormatter setDateStyle: NSDateFormatterFullStyle];
114            [dateFormatter setTimeStyle: NSDateFormatterShortStyle];
115           
116            dateString = [dateFormatter stringFromDate: scrapeDate];
117            [dateFormatter release];
118        }
119    }
120    else
121        dateString = NSLocalizedString(@"N/A", "Tracker last announce");
122   
123    if (fStat.hasScraped && !fStat.lastScrapeSucceeded)
124        dateString = [NSString stringWithFormat: @"%@: %@ - %@", NSLocalizedString(@"Scrape error", "Tracker last announce"),
125                        [NSString stringWithUTF8String: fStat.lastScrapeResult], dateString];
126    else
127        dateString = [NSString stringWithFormat: NSLocalizedString(@"Last Scrape: %@", "Tracker last announce"), dateString];
128   
129    return dateString;
130}
131
132@end
Note: See TracBrowser for help on using the repository browser.