source: trunk/macosx/InfoActivityViewController.m @ 10389

Last change on this file since 10389 was 10389, checked in by charles, 12 years ago

(trunk) update svn properties for $Id$ in the new macosx/ files

  • Property svn:keywords set to Date Rev Author Id
File size: 7.0 KB
Line 
1/******************************************************************************
2 * $Id: InfoActivityViewController.m 10389 2010-03-16 00:45:52Z charles $
3 *
4 * Copyright (c) 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 "InfoActivityViewController.h"
26#import "NSStringAdditions.h"
27#import "PiecesView.h"
28#import "Torrent.h"
29#include "utils.h" //tr_getRatio()
30
31#define PIECES_CONTROL_PROGRESS 0
32#define PIECES_CONTROL_AVAILABLE 1
33
34@interface InfoActivityViewController (Private)
35
36- (void) setupInfo;
37
38@end
39
40@implementation InfoActivityViewController
41
42- (id) init
43{
44    if ((self = [super initWithNibName: @"InfoActivityView" bundle: nil]))
45    {
46        [self setTitle: NSLocalizedString(@"Activity", "Inspector view -> title")];
47    }
48   
49    return self;
50}
51
52- (void) dealloc
53{
54    [fTorrents release];
55   
56    [super dealloc];
57}
58
59- (void) setInfoForTorrents: (NSArray *) torrents
60{
61    if (fTorrents && [fTorrents isEqualToArray: torrents])
62        return;
63   
64    [fTorrents release];
65    fTorrents = [torrents retain];
66   
67    fSet = NO;
68}
69
70- (void) updateInfo
71{
72    if (!fSet)
73        [self setupInfo];
74   
75    const NSInteger numberSelected = [fTorrents count];
76    if (numberSelected == 0)
77        return;
78   
79    uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0;
80    NSDate * lastActivity = nil;
81    for (Torrent * torrent in fTorrents)
82    {
83        have += [torrent haveTotal];
84        haveVerified += [torrent haveVerified];
85        downloadedTotal += [torrent downloadedTotal];
86        uploadedTotal += [torrent uploadedTotal];
87        failedHash += [torrent failedHash];
88       
89        NSDate * nextLastActivity;
90        if ((nextLastActivity = [torrent dateActivity]))
91            lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity;
92    }
93   
94    if (have == 0)
95        [fHaveField setStringValue: [NSString stringForFileSize: 0]];
96    else
97    {
98        NSString * verifiedString = [NSString stringWithFormat: NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"),
99                                        [NSString stringForFileSize: haveVerified]];
100        if (have == haveVerified)
101            [fHaveField setStringValue: verifiedString];
102        else
103            [fHaveField setStringValue: [NSString stringWithFormat: @"%@ (%@)", [NSString stringForFileSize: have], verifiedString]];
104    }
105   
106    [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
107    [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
108    [fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]];
109   
110    [fDateActivityField setObjectValue: lastActivity];
111   
112    if (numberSelected == 1)
113    {
114        Torrent * torrent = [fTorrents objectAtIndex: 0];
115       
116        [fStateField setStringValue: [torrent stateString]];
117       
118        if ([torrent isFolder])
119            [fProgressField setStringValue: [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)",
120                "Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]];
121        else
122            [fProgressField setStringValue: [NSString localizedStringWithFormat: @"%.2f%%", 100.0 * [torrent progress]]];
123           
124        [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
125       
126        NSString * errorMessage = [torrent errorMessage];
127        if (![errorMessage isEqualToString: [fErrorMessageView string]])
128            [fErrorMessageView setString: errorMessage];
129       
130        [fDateCompletedField setObjectValue: [torrent dateCompleted]];
131       
132        [fPiecesView updateView];
133    }
134    else if (numberSelected > 1)
135    {
136        [fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]];
137    }
138    else;
139}
140
141- (void) setPiecesView: (id) sender
142{
143    [self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE];
144}
145
146- (void) setPiecesViewForAvailable: (BOOL) available
147{
148    [fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE];
149    [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS];
150   
151    [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"];
152    [fPiecesView updateView];
153}
154
155- (void) clearView
156{
157    [fPiecesView clearView];
158}
159
160@end
161
162@implementation InfoActivityViewController (Private)
163
164- (void) setupInfo
165{
166    const NSUInteger count = [fTorrents count];
167    if (count != 1)
168    {
169        if (count == 0)
170        {
171            [fHaveField setStringValue: @""];
172            [fDownloadedTotalField setStringValue: @""];
173            [fUploadedTotalField setStringValue: @""];
174            [fFailedHashField setStringValue: @""];
175            [fDateActivityField setStringValue: @""];
176            [fRatioField setStringValue: @""];
177        }
178   
179        [fStateField setStringValue: @""];
180        [fProgressField setStringValue: @""];
181       
182        [fErrorMessageView setString: @""];
183       
184        [fDateAddedField setStringValue: @""];
185        [fDateCompletedField setStringValue: @""];
186       
187        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE];
188        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS];
189        [fPiecesControl setEnabled: NO];
190        [fPiecesView setTorrent: nil];
191    }
192    else
193    {
194        Torrent * torrent = [fTorrents objectAtIndex: 0];
195       
196        [fDateAddedField setObjectValue: [torrent dateAdded]];
197       
198        BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
199        [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
200        [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
201        [fPiecesControl setEnabled: YES];
202        [fPiecesView setTorrent: torrent];
203    }
204   
205    fSet = YES;
206}
207
208@end
Note: See TracBrowser for help on using the repository browser.