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 work in peer count? |
---|
53 | #warning consider "isActive" |
---|
54 | - (NSString *) lastAnnounceStatusString |
---|
55 | { |
---|
56 | NSString * dateString; |
---|
57 | if (fStat.hasAnnounced && fStat.lastAnnounceTime != 0) |
---|
58 | { |
---|
59 | NSDate * announceDate = [NSDate dateWithTimeIntervalSince1970: fStat.lastAnnounceTime]; |
---|
60 | if ([NSApp isOnSnowLeopardOrBetter]) |
---|
61 | dateString = [NSDateFormatter localizedStringFromDate: announceDate dateStyle: NSDateFormatterFullStyle |
---|
62 | timeStyle: NSDateFormatterShortStyle]; |
---|
63 | else |
---|
64 | { |
---|
65 | NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; |
---|
66 | [dateFormatter setDateStyle: NSDateFormatterFullStyle]; |
---|
67 | [dateFormatter setTimeStyle: NSDateFormatterShortStyle]; |
---|
68 | |
---|
69 | dateString = [dateFormatter stringFromDate: announceDate]; |
---|
70 | [dateFormatter release]; |
---|
71 | } |
---|
72 | } |
---|
73 | else |
---|
74 | dateString = NSLocalizedString(@"N/A", "Tracker last announce"); |
---|
75 | |
---|
76 | if (fStat.hasAnnounced && !fStat.lastAnnounceSucceeded) |
---|
77 | dateString = [NSString stringWithFormat: @"%@: %@ - %@", NSLocalizedString(@"Announce error", "Tracker last announce"), |
---|
78 | [NSString stringWithUTF8String: fStat.lastAnnounceResult], dateString]; |
---|
79 | else |
---|
80 | dateString = [NSString stringWithFormat: NSLocalizedString(@"Last Announce: %@", "Tracker last announce"), dateString]; |
---|
81 | |
---|
82 | return dateString; |
---|
83 | } |
---|
84 | |
---|
85 | - (NSString *) nextAnnounceStatusString |
---|
86 | { |
---|
87 | if (fStat.isAnnouncing) |
---|
88 | return [NSLocalizedString(@"Announce in progress", "Tracker next announce") stringByAppendingEllipsis]; |
---|
89 | else if (fStat.willAnnounce) |
---|
90 | return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"), |
---|
91 | [NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]]; |
---|
92 | else |
---|
93 | return NSLocalizedString(@"Announce not scheduled", "Tracker next announce"); |
---|
94 | } |
---|
95 | |
---|
96 | - (NSString *) lastScrapeStatusString |
---|
97 | { |
---|
98 | NSString * dateString; |
---|
99 | if (fStat.hasScraped && fStat.lastScrapeTime != 0) |
---|
100 | { |
---|
101 | NSDate * scrapeDate = [NSDate dateWithTimeIntervalSince1970: fStat.lastScrapeTime]; |
---|
102 | if ([NSApp isOnSnowLeopardOrBetter]) |
---|
103 | dateString = [NSDateFormatter localizedStringFromDate: scrapeDate dateStyle: NSDateFormatterFullStyle |
---|
104 | timeStyle: NSDateFormatterShortStyle]; |
---|
105 | else |
---|
106 | { |
---|
107 | NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; |
---|
108 | [dateFormatter setDateStyle: NSDateFormatterFullStyle]; |
---|
109 | [dateFormatter setTimeStyle: NSDateFormatterShortStyle]; |
---|
110 | |
---|
111 | dateString = [dateFormatter stringFromDate: scrapeDate]; |
---|
112 | [dateFormatter release]; |
---|
113 | } |
---|
114 | } |
---|
115 | else |
---|
116 | dateString = NSLocalizedString(@"N/A", "Tracker last announce"); |
---|
117 | |
---|
118 | if (fStat.hasScraped && !fStat.lastScrapeSucceeded) |
---|
119 | dateString = [NSString stringWithFormat: @"%@: %@ - %@", NSLocalizedString(@"Scrape error", "Tracker last announce"), |
---|
120 | [NSString stringWithUTF8String: fStat.lastScrapeResult], dateString]; |
---|
121 | else |
---|
122 | dateString = [NSString stringWithFormat: NSLocalizedString(@"Last Scrape: %@", "Tracker last announce"), dateString]; |
---|
123 | |
---|
124 | return dateString; |
---|
125 | } |
---|
126 | |
---|
127 | @end |
---|