source: trunk/macosx/InfoWindowController.m @ 261

Last change on this file since 261 was 261, checked in by titer, 16 years ago

Updated svn:keywords

  • Property svn:keywords set to Date Rev Author Id
File size: 4.4 KB
Line 
1/******************************************************************************
2 * $Id: InfoWindowController.m 261 2006-05-29 21:27:31Z titer $
3 *
4 * Copyright (c) 2006 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 "InfoWindowController.h"
26#import "StringAdditions.h"
27
28@implementation InfoWindowController
29
30- (void) awakeFromNib
31{
32    fAppIcon = [[NSApp applicationIconImage] copy];
33}
34
35- (void) dealloc
36{
37    [fAppIcon release];
38    [super dealloc];
39}
40
41- (void) updateInfoForTorrents: (NSArray *) torrents
42{
43    int numberSelected = [torrents count];
44    if (numberSelected != 1)
45    {
46        [fImageView setImage: fAppIcon];
47
48        [fTracker setStringValue: @""];
49        [fAnnounce setStringValue: @""];
50        [fPieceSize setStringValue: @""];
51        [fPieces setStringValue: @""];
52        [fHash setStringValue: @""];
53       
54        [fSeeders setStringValue: @""];
55        [fLeechers setStringValue: @""];
56       
57        if (numberSelected > 0)
58        {
59            [fName setStringValue: [[NSString stringWithInt: numberSelected]
60                                    stringByAppendingString: @" Torrents Selected"]];
61       
62            uint64_t size = 0;
63            NSEnumerator * enumerator = [torrents objectEnumerator];
64            Torrent * torrent;
65            while ((torrent = [enumerator nextObject]))
66                size += [torrent size];
67           
68            [fSize setStringValue: [[NSString
69                stringForFileSize: size] stringByAppendingString: @" Total"]];
70        }
71        else
72        {
73            [fName setStringValue: @"No Torrents Selected"];
74
75            [fSize setStringValue: @""];
76            [fDownloaded setStringValue: @""];
77            [fUploaded setStringValue: @""];
78        }
79    }
80    else
81    {   
82        Torrent * torrent = [torrents objectAtIndex: 0];
83       
84        [fImageView setImage: [torrent iconNonFlipped]];
85       
86        [fName setStringValue: [torrent name]];
87        [fSize setStringValue: [NSString stringForFileSize: [torrent size]]];
88        [fTracker setStringValue: [torrent tracker]];
89        [fAnnounce setStringValue: [torrent announce]];
90        [fPieceSize setStringValue: [NSString stringForFileSize: [torrent pieceSize]]];
91        [fPieces setIntValue: [torrent pieceCount]];
92        [fHash setStringValue: [torrent hash]];
93    }
94
95    [self updateInfoStatsForTorrents: torrents];
96}
97
98- (void) updateInfoStatsForTorrents: (NSArray *) torrents
99{
100    int numberSelected = [torrents count];
101    if (numberSelected > 0)
102    {
103        Torrent * torrent;
104        if (numberSelected == 1)
105        {   
106            torrent = [torrents objectAtIndex: 0];
107           
108            int seeders = [torrent seeders], leechers = [torrent leechers];
109            [fSeeders setStringValue: seeders < 0 ?
110                @"?" : [NSString stringWithInt: seeders]];
111            [fLeechers setStringValue: leechers < 0 ?
112                @"?" : [NSString stringWithInt: leechers]];
113        }
114   
115        uint64_t downloaded = 0, uploaded = 0;
116        NSEnumerator * enumerator = [torrents objectEnumerator];
117        while ((torrent = [enumerator nextObject]))
118        {
119            downloaded += [torrent downloaded];
120            uploaded += [torrent uploaded];
121        }
122       
123        [fDownloaded setStringValue: [NSString stringForFileSize: downloaded]];
124        [fUploaded setStringValue: [NSString stringForFileSize: uploaded]];
125    }
126}
127
128@end
Note: See TracBrowser for help on using the repository browser.