1 | /****************************************************************************** |
---|
2 | * $Id: InfoWindowController.m 5866 2008-05-20 23:45:07Z livings124 $ |
---|
3 | * |
---|
4 | * Copyright (c) 2006-2008 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 "InfoTabButtonCell.h" |
---|
27 | #import "NSApplicationAdditions.h" |
---|
28 | #import "NSStringAdditions.h" |
---|
29 | |
---|
30 | #import "QuickLook.h" |
---|
31 | #define QLPreviewPanel NSClassFromString(@"QLPreviewPanel") |
---|
32 | |
---|
33 | #define TAB_INFO_IDENT @"Info" |
---|
34 | #define TAB_ACTIVITY_IDENT @"Activity" |
---|
35 | #define TAB_TRACKER_IDENT @"Tracker" |
---|
36 | #define TAB_PEERS_IDENT @"Peers" |
---|
37 | #define TAB_FILES_IDENT @"Files" |
---|
38 | #define TAB_OPTIONS_IDENT @"Options" |
---|
39 | |
---|
40 | #define TAB_MIN_HEIGHT 250 |
---|
41 | |
---|
42 | #define PIECES_CONTROL_PROGRESS 0 |
---|
43 | #define PIECES_CONTROL_AVAILABLE 1 |
---|
44 | |
---|
45 | #define OPTION_POPUP_GLOBAL 0 |
---|
46 | #define OPTION_POPUP_NO_LIMIT 1 |
---|
47 | #define OPTION_POPUP_LIMIT 2 |
---|
48 | |
---|
49 | #define INVALID -99 |
---|
50 | |
---|
51 | typedef enum |
---|
52 | { |
---|
53 | TAB_INFO_TAG = 0, |
---|
54 | TAB_ACTIVITY_TAG = 1, |
---|
55 | TAB_TRACKER_TAG = 2, |
---|
56 | TAB_PEERS_TAG = 3, |
---|
57 | TAB_FILES_TAG = 4, |
---|
58 | TAB_OPTIONS_TAG = 5 |
---|
59 | } tabTag; |
---|
60 | |
---|
61 | @interface InfoWindowController (Private) |
---|
62 | |
---|
63 | - (void) updateInfoGeneral; |
---|
64 | - (void) updateInfoActivity; |
---|
65 | - (void) updateInfoTracker; |
---|
66 | - (void) updateInfoPeers; |
---|
67 | - (void) updateInfoFiles; |
---|
68 | |
---|
69 | - (NSView *) tabViewForTag: (int) tag; |
---|
70 | - (NSArray *) peerSortDescriptors; |
---|
71 | |
---|
72 | @end |
---|
73 | |
---|
74 | @implementation InfoWindowController |
---|
75 | |
---|
76 | - (id) init |
---|
77 | { |
---|
78 | return [super initWithWindowNibName: @"InfoWindow"]; |
---|
79 | } |
---|
80 | |
---|
81 | - (void) awakeFromNib |
---|
82 | { |
---|
83 | //window location and size |
---|
84 | NSPanel * window = (NSPanel *)[self window]; |
---|
85 | |
---|
86 | float windowHeight = [window frame].size.height; |
---|
87 | |
---|
88 | [window setFrameAutosaveName: @"InspectorWindow"]; |
---|
89 | [window setFrameUsingName: @"InspectorWindow"]; |
---|
90 | |
---|
91 | NSRect windowRect = [window frame]; |
---|
92 | windowRect.origin.y -= windowHeight - windowRect.size.height; |
---|
93 | windowRect.size.height = windowHeight; |
---|
94 | [window setFrame: windowRect display: NO]; |
---|
95 | |
---|
96 | [window setBecomesKeyOnlyIfNeeded: YES]; |
---|
97 | |
---|
98 | //set tab images and tooltips |
---|
99 | [[fTabMatrix cellWithTag: TAB_INFO_TAG] setIcon: [NSImage imageNamed: @"InfoGeneral.png"]]; |
---|
100 | [[fTabMatrix cellWithTag: TAB_ACTIVITY_TAG] setIcon: [NSImage imageNamed: @"InfoActivity.png"]]; |
---|
101 | [[fTabMatrix cellWithTag: TAB_TRACKER_TAG] setIcon: [NSImage imageNamed: @"InfoTracker.png"]]; |
---|
102 | [[fTabMatrix cellWithTag: TAB_PEERS_TAG] setIcon: [NSImage imageNamed: @"InfoPeers.png"]]; |
---|
103 | [[fTabMatrix cellWithTag: TAB_FILES_TAG] setIcon: [NSImage imageNamed: @"InfoFiles.png"]]; |
---|
104 | [[fTabMatrix cellWithTag: TAB_OPTIONS_TAG] setIcon: [NSImage imageNamed: @"InfoOptions.png"]]; |
---|
105 | |
---|
106 | //set selected tab |
---|
107 | fCurrentTabTag = INVALID; |
---|
108 | NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InspectorSelected"]; |
---|
109 | int tag; |
---|
110 | if ([identifier isEqualToString: TAB_INFO_IDENT]) |
---|
111 | tag = TAB_INFO_TAG; |
---|
112 | else if ([identifier isEqualToString: TAB_ACTIVITY_IDENT]) |
---|
113 | tag = TAB_ACTIVITY_TAG; |
---|
114 | else if ([identifier isEqualToString: TAB_TRACKER_IDENT]) |
---|
115 | tag = TAB_TRACKER_TAG; |
---|
116 | else if ([identifier isEqualToString: TAB_PEERS_IDENT]) |
---|
117 | tag = TAB_PEERS_TAG; |
---|
118 | else if ([identifier isEqualToString: TAB_FILES_IDENT]) |
---|
119 | tag = TAB_FILES_TAG; |
---|
120 | else if ([identifier isEqualToString: TAB_OPTIONS_IDENT]) |
---|
121 | tag = TAB_OPTIONS_TAG; |
---|
122 | else //safety |
---|
123 | { |
---|
124 | [[NSUserDefaults standardUserDefaults] setObject: TAB_INFO_IDENT forKey: @"InspectorSelected"]; |
---|
125 | tag = TAB_INFO_TAG; |
---|
126 | } |
---|
127 | [fTabMatrix selectCellWithTag: tag]; |
---|
128 | [self setTab: nil]; |
---|
129 | |
---|
130 | //reset images for reveal buttons, since the images are also used in the main table |
---|
131 | NSImage * revealOn = [[NSImage imageNamed: @"RevealOn.png"] copy], |
---|
132 | * revealOff = [[NSImage imageNamed: @"RevealOff.png"] copy]; |
---|
133 | [revealOn setFlipped: NO]; |
---|
134 | [revealOff setFlipped: NO]; |
---|
135 | |
---|
136 | [fRevealDataButton setImage: revealOff]; |
---|
137 | [fRevealDataButton setAlternateImage: revealOn]; |
---|
138 | [fRevealTorrentButton setImage: revealOff]; |
---|
139 | [fRevealTorrentButton setAlternateImage: revealOn]; |
---|
140 | |
---|
141 | [revealOn release]; |
---|
142 | [revealOff release]; |
---|
143 | |
---|
144 | //load the QuickLook framework and set the delegate, no point on trying this on Tiger |
---|
145 | //animation types: 0 = none; 1 = fade; 2 = zoom |
---|
146 | fQuickLookAvailable = [[NSBundle bundleWithPath: @"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load]; |
---|
147 | if (fQuickLookAvailable) |
---|
148 | [[[QLPreviewPanel sharedPreviewPanel] windowController] setDelegate: self]; |
---|
149 | |
---|
150 | //initially sort peer table by IP |
---|
151 | if ([[fPeerTable sortDescriptors] count] == 0) |
---|
152 | [fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"] |
---|
153 | sortDescriptorPrototype]]]; |
---|
154 | |
---|
155 | //set table header tool tips |
---|
156 | if ([NSApp isOnLeopardOrBetter]) |
---|
157 | { |
---|
158 | [[fPeerTable tableColumnWithIdentifier: @"Encryption"] setHeaderToolTip: NSLocalizedString(@"Encrypted Connection", |
---|
159 | "inspector -> peer table -> header tool tip")]; |
---|
160 | [[fPeerTable tableColumnWithIdentifier: @"Progress"] setHeaderToolTip: NSLocalizedString(@"Available", |
---|
161 | "inspector -> peer table -> header tool tip")]; |
---|
162 | [[fPeerTable tableColumnWithIdentifier: @"UL To"] setHeaderToolTip: NSLocalizedString(@"Uploading To Peer", |
---|
163 | "inspector -> peer table -> header tool tip")]; |
---|
164 | [[fPeerTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Peer", |
---|
165 | "inspector -> peer table -> header tool tip")]; |
---|
166 | } |
---|
167 | |
---|
168 | //set blank inspector |
---|
169 | [self setInfoForTorrents: [NSArray array]]; |
---|
170 | |
---|
171 | //allow for update notifications |
---|
172 | NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; |
---|
173 | [nc addObserver: self selector: @selector(updateInfoStats) name: @"UpdateStats" object: nil]; |
---|
174 | [nc addObserver: self selector: @selector(updateOptions) name: @"UpdateOptions" object: nil]; |
---|
175 | [nc addObserver: self selector: @selector(updateQuickLook) name: @"UpdateQuickLook" object: nil]; |
---|
176 | } |
---|
177 | |
---|
178 | - (void) dealloc |
---|
179 | { |
---|
180 | //save resizeable view height |
---|
181 | NSString * resizeSaveKey = nil; |
---|
182 | switch (fCurrentTabTag) |
---|
183 | { |
---|
184 | case TAB_TRACKER_TAG: |
---|
185 | resizeSaveKey = @"InspectorContentHeightTracker"; |
---|
186 | break; |
---|
187 | case TAB_PEERS_TAG: |
---|
188 | resizeSaveKey = @"InspectorContentHeightPeers"; |
---|
189 | break; |
---|
190 | case TAB_FILES_TAG: |
---|
191 | resizeSaveKey = @"InspectorContentHeightFiles"; |
---|
192 | break; |
---|
193 | } |
---|
194 | if (resizeSaveKey) |
---|
195 | [[NSUserDefaults standardUserDefaults] setFloat: [[self tabViewForTag: fCurrentTabTag] frame].size.height forKey: resizeSaveKey]; |
---|
196 | |
---|
197 | [[NSNotificationCenter defaultCenter] removeObserver: self]; |
---|
198 | |
---|
199 | [fTorrents release]; |
---|
200 | [fPeers release]; |
---|
201 | [fTrackers release]; |
---|
202 | |
---|
203 | [super dealloc]; |
---|
204 | } |
---|
205 | |
---|
206 | - (void) setInfoForTorrents: (NSArray *) torrents |
---|
207 | { |
---|
208 | if (fTorrents && [fTorrents isEqualToArray: torrents]) |
---|
209 | return; |
---|
210 | |
---|
211 | [fTorrents release]; |
---|
212 | fTorrents = [torrents retain]; |
---|
213 | |
---|
214 | int numberSelected = [fTorrents count]; |
---|
215 | if (numberSelected != 1) |
---|
216 | { |
---|
217 | if (numberSelected > 0) |
---|
218 | { |
---|
219 | [fImageView setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter] |
---|
220 | ? NSImageNameMultipleDocuments : @"NSApplicationIcon"]]; |
---|
221 | |
---|
222 | [fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d Torrents Selected", |
---|
223 | "Inspector -> selected torrents"), numberSelected]]; |
---|
224 | |
---|
225 | uint64_t size = 0; |
---|
226 | int fileCount = 0; |
---|
227 | NSEnumerator * enumerator = [torrents objectEnumerator]; |
---|
228 | Torrent * torrent; |
---|
229 | while ((torrent = [enumerator nextObject])) |
---|
230 | { |
---|
231 | size += [torrent size]; |
---|
232 | fileCount += [torrent fileCount]; |
---|
233 | } |
---|
234 | |
---|
235 | [fBasicInfoField setStringValue: [NSString stringWithFormat: @"%@, %@", |
---|
236 | [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount], |
---|
237 | [NSString stringWithFormat: NSLocalizedString(@"%@ total", "Inspector -> selected torrents"), |
---|
238 | [NSString stringForFileSize: size]]]]; |
---|
239 | [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%u bytes", "Inspector -> selected torrents"), |
---|
240 | size]]; |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | [fImageView setImage: [NSImage imageNamed: @"NSApplicationIcon"]]; |
---|
245 | |
---|
246 | [fNameField setStringValue: NSLocalizedString(@"No Torrents Selected", "Inspector -> selected torrents")]; |
---|
247 | [fBasicInfoField setStringValue: @""]; |
---|
248 | [fBasicInfoField setToolTip: @""]; |
---|
249 | |
---|
250 | [fHaveField setStringValue: @""]; |
---|
251 | [fDownloadedTotalField setStringValue: @""]; |
---|
252 | [fUploadedTotalField setStringValue: @""]; |
---|
253 | [fFailedHashField setStringValue: @""]; |
---|
254 | [fDateActivityField setStringValue: @""]; |
---|
255 | |
---|
256 | //options fields |
---|
257 | [fUploadLimitPopUp setEnabled: NO]; |
---|
258 | [fUploadLimitPopUp selectItemAtIndex: -1]; |
---|
259 | [fUploadLimitField setHidden: YES]; |
---|
260 | [fUploadLimitLabel setHidden: YES]; |
---|
261 | [fUploadLimitField setStringValue: @""]; |
---|
262 | |
---|
263 | [fDownloadLimitPopUp setEnabled: NO]; |
---|
264 | [fDownloadLimitPopUp selectItemAtIndex: -1]; |
---|
265 | [fDownloadLimitField setHidden: YES]; |
---|
266 | [fDownloadLimitLabel setHidden: YES]; |
---|
267 | [fDownloadLimitField setStringValue: @""]; |
---|
268 | |
---|
269 | [fRatioPopUp setEnabled: NO]; |
---|
270 | [fRatioPopUp selectItemAtIndex: -1]; |
---|
271 | [fRatioLimitField setHidden: YES]; |
---|
272 | [fRatioLimitField setStringValue: @""]; |
---|
273 | |
---|
274 | [fPeersConnectField setEnabled: NO]; |
---|
275 | [fPeersConnectField setStringValue: @""]; |
---|
276 | } |
---|
277 | |
---|
278 | [fFileController setTorrent: nil]; |
---|
279 | |
---|
280 | [fNameField setToolTip: nil]; |
---|
281 | |
---|
282 | [fTrackerField setStringValue: @""]; |
---|
283 | [fPiecesField setStringValue: @""]; |
---|
284 | [fHashField setStringValue: @""]; |
---|
285 | [fHashField setToolTip: nil]; |
---|
286 | [fSecureField setStringValue: @""]; |
---|
287 | [fCommentView setString: @""]; |
---|
288 | |
---|
289 | [fCreatorField setStringValue: @""]; |
---|
290 | [fDateCreatedField setStringValue: @""]; |
---|
291 | [fCommentView setSelectable: NO]; |
---|
292 | |
---|
293 | [fTorrentLocationField setStringValue: @""]; |
---|
294 | [fTorrentLocationField setToolTip: nil]; |
---|
295 | [fDataLocationField setStringValue: @""]; |
---|
296 | [fDataLocationField setToolTip: nil]; |
---|
297 | |
---|
298 | [fRevealDataButton setHidden: YES]; |
---|
299 | [fRevealTorrentButton setHidden: YES]; |
---|
300 | |
---|
301 | //don't allow empty fields to be selected |
---|
302 | [fTrackerField setSelectable: NO]; |
---|
303 | [fHashField setSelectable: NO]; |
---|
304 | [fCreatorField setSelectable: NO]; |
---|
305 | [fTorrentLocationField setSelectable: NO]; |
---|
306 | [fDataLocationField setSelectable: NO]; |
---|
307 | |
---|
308 | [fStateField setStringValue: @""]; |
---|
309 | [fProgressField setStringValue: @""]; |
---|
310 | [fRatioField setStringValue: @""]; |
---|
311 | |
---|
312 | [fSwarmSpeedField setStringValue: @""]; |
---|
313 | [fErrorMessageView setString: @""]; |
---|
314 | [fErrorMessageView setSelectable: NO]; |
---|
315 | |
---|
316 | [fAnnounceAddressField setStringValue: @""]; |
---|
317 | [fAnnounceAddressField setToolTip: nil]; |
---|
318 | [fAnnounceAddressField setSelectable: NO]; |
---|
319 | [fAnnounceLastField setStringValue: @""]; |
---|
320 | [fAnnounceResponseField setStringValue: @""]; |
---|
321 | [fAnnounceResponseField setToolTip: nil]; |
---|
322 | [fAnnounceResponseField setSelectable: NO]; |
---|
323 | [fAnnounceNextField setStringValue: @""]; |
---|
324 | |
---|
325 | [fScrapeAddressField setStringValue: @""]; |
---|
326 | [fScrapeAddressField setToolTip: nil]; |
---|
327 | [fScrapeAddressField setSelectable: NO]; |
---|
328 | [fScrapeLastField setStringValue: @""]; |
---|
329 | [fScrapeResponseField setStringValue: @""]; |
---|
330 | [fScrapeResponseField setToolTip: nil]; |
---|
331 | [fScrapeResponseField setSelectable: NO]; |
---|
332 | [fScrapeNextField setStringValue: @""]; |
---|
333 | |
---|
334 | [fConnectedPeersField setStringValue: @""]; |
---|
335 | [fDownloadingFromField setStringValue: @""]; |
---|
336 | [fUploadingToField setStringValue: @""]; |
---|
337 | [fKnownField setStringValue: @""]; |
---|
338 | [fSeedersField setStringValue: @""]; |
---|
339 | [fLeechersField setStringValue: @""]; |
---|
340 | [fCompletedFromTrackerField setStringValue: @""]; |
---|
341 | |
---|
342 | [fDateAddedField setStringValue: @""]; |
---|
343 | [fDateCompletedField setStringValue: @""]; |
---|
344 | |
---|
345 | [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE]; |
---|
346 | [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS]; |
---|
347 | [fPiecesControl setEnabled: NO]; |
---|
348 | [fPiecesView setTorrent: nil]; |
---|
349 | |
---|
350 | [fPeers release]; |
---|
351 | fPeers = nil; |
---|
352 | |
---|
353 | [fTrackers release]; |
---|
354 | fTrackers = nil; |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
359 | |
---|
360 | [fFileController setTorrent: torrent]; |
---|
361 | |
---|
362 | NSImage * icon = [[torrent icon] copy]; |
---|
363 | [icon setFlipped: NO]; |
---|
364 | [fImageView setImage: icon]; |
---|
365 | [icon release]; |
---|
366 | |
---|
367 | NSString * name = [torrent name]; |
---|
368 | [fNameField setStringValue: name]; |
---|
369 | [fNameField setToolTip: name]; |
---|
370 | |
---|
371 | NSString * basicString = [NSString stringForFileSize: [torrent size]]; |
---|
372 | if ([torrent folder]) |
---|
373 | { |
---|
374 | NSString * fileString; |
---|
375 | int fileCount = [torrent fileCount]; |
---|
376 | if (fileCount == 1) |
---|
377 | fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents"); |
---|
378 | else |
---|
379 | fileString= [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount]; |
---|
380 | basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString]; |
---|
381 | } |
---|
382 | [fBasicInfoField setStringValue: basicString]; |
---|
383 | [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%u bytes", "Inspector -> selected torrents"), |
---|
384 | [torrent size]]]; |
---|
385 | |
---|
386 | NSString * hashString = [torrent hashString]; |
---|
387 | [fPiecesField setStringValue: [NSString stringWithFormat: @"%d, %@", [torrent pieceCount], |
---|
388 | [NSString stringForFileSize: [torrent pieceSize]]]]; |
---|
389 | [fHashField setStringValue: hashString]; |
---|
390 | [fHashField setToolTip: hashString]; |
---|
391 | [fSecureField setStringValue: [torrent privateTorrent] |
---|
392 | ? NSLocalizedString(@"Private Torrent, PEX automatically disabled", "Inspector -> private torrent") |
---|
393 | : NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")]; |
---|
394 | |
---|
395 | NSString * commentString = [torrent comment]; |
---|
396 | [fCommentView setString: commentString]; |
---|
397 | |
---|
398 | NSString * creatorString = [torrent creator]; |
---|
399 | [fCreatorField setStringValue: creatorString]; |
---|
400 | [fDateCreatedField setObjectValue: [torrent dateCreated]]; |
---|
401 | |
---|
402 | BOOL publicTorrent = [torrent publicTorrent]; |
---|
403 | [fTorrentLocationField setStringValue: publicTorrent |
---|
404 | ? [[torrent publicTorrentLocation] stringByAbbreviatingWithTildeInPath] |
---|
405 | : NSLocalizedString(@"Transmission Support Folder", "Torrent -> location when deleting original")]; |
---|
406 | if (publicTorrent) |
---|
407 | [fTorrentLocationField setToolTip: [[torrent publicTorrentLocation] stringByAppendingFormat: @"\n\n%@", |
---|
408 | [torrent torrentLocation]]]; |
---|
409 | else |
---|
410 | [fTorrentLocationField setToolTip: [torrent torrentLocation]]; |
---|
411 | |
---|
412 | [fDateAddedField setObjectValue: [torrent dateAdded]]; |
---|
413 | |
---|
414 | [fRevealDataButton setHidden: NO]; |
---|
415 | [fRevealTorrentButton setHidden: ![torrent publicTorrent]]; |
---|
416 | |
---|
417 | //allow these fields to be selected |
---|
418 | [fTrackerField setSelectable: YES]; |
---|
419 | [fHashField setSelectable: YES]; |
---|
420 | [fCommentView setSelectable: ![commentString isEqualToString: @""]]; |
---|
421 | [fCreatorField setSelectable: ![creatorString isEqualToString: @""]]; |
---|
422 | [fTorrentLocationField setSelectable: YES]; |
---|
423 | [fDataLocationField setSelectable: YES]; |
---|
424 | [fAnnounceAddressField setSelectable: YES]; |
---|
425 | [fScrapeAddressField setSelectable: YES]; |
---|
426 | |
---|
427 | //set pieces view |
---|
428 | BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"]; |
---|
429 | [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE]; |
---|
430 | [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS]; |
---|
431 | [fPiecesControl setEnabled: YES]; |
---|
432 | [fPiecesView setTorrent: torrent]; |
---|
433 | |
---|
434 | //get trackers for table |
---|
435 | [fTrackers release]; |
---|
436 | fTrackers = [[torrent allTrackers: YES] retain]; |
---|
437 | } |
---|
438 | |
---|
439 | //update stats and settings |
---|
440 | [self updateInfoStats]; |
---|
441 | [self updateOptions]; |
---|
442 | |
---|
443 | [fTrackerTable reloadData]; |
---|
444 | [fPeerTable reloadData]; |
---|
445 | |
---|
446 | [self updateQuickLook]; |
---|
447 | } |
---|
448 | |
---|
449 | - (void) updateInfoStats |
---|
450 | { |
---|
451 | switch ([fTabMatrix selectedTag]) |
---|
452 | { |
---|
453 | case TAB_INFO_TAG: |
---|
454 | [self updateInfoGeneral]; |
---|
455 | break; |
---|
456 | case TAB_ACTIVITY_TAG: |
---|
457 | [self updateInfoActivity]; |
---|
458 | break; |
---|
459 | case TAB_TRACKER_TAG: |
---|
460 | [self updateInfoTracker]; |
---|
461 | break; |
---|
462 | case TAB_PEERS_TAG: |
---|
463 | [self updateInfoPeers]; |
---|
464 | break; |
---|
465 | case TAB_FILES_TAG: |
---|
466 | [self updateInfoFiles]; |
---|
467 | break; |
---|
468 | } |
---|
469 | } |
---|
470 | |
---|
471 | - (void) updateOptions |
---|
472 | { |
---|
473 | if ([fTorrents count] == 0) |
---|
474 | return; |
---|
475 | |
---|
476 | //get bandwidth info |
---|
477 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
478 | Torrent * torrent = [enumerator nextObject]; //first torrent |
---|
479 | |
---|
480 | int uploadSpeedMode = [torrent speedMode: YES], |
---|
481 | uploadSpeedLimit = [torrent speedLimit: YES], |
---|
482 | downloadSpeedMode = [torrent speedMode: NO], |
---|
483 | downloadSpeedLimit = [torrent speedLimit: NO]; |
---|
484 | |
---|
485 | while ((torrent = [enumerator nextObject]) |
---|
486 | && (uploadSpeedMode != INVALID || uploadSpeedLimit != INVALID |
---|
487 | || downloadSpeedMode != INVALID || downloadSpeedLimit != INVALID)) |
---|
488 | { |
---|
489 | if (uploadSpeedMode != INVALID && uploadSpeedMode != [torrent speedMode: YES]) |
---|
490 | uploadSpeedMode = INVALID; |
---|
491 | |
---|
492 | if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES]) |
---|
493 | uploadSpeedLimit = INVALID; |
---|
494 | |
---|
495 | if (downloadSpeedMode != INVALID && downloadSpeedMode != [torrent speedMode: NO]) |
---|
496 | downloadSpeedMode = INVALID; |
---|
497 | |
---|
498 | if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO]) |
---|
499 | downloadSpeedLimit = INVALID; |
---|
500 | } |
---|
501 | |
---|
502 | //set upload view |
---|
503 | int index; |
---|
504 | if (uploadSpeedMode == TR_SPEEDLIMIT_SINGLE) |
---|
505 | index = OPTION_POPUP_LIMIT; |
---|
506 | else if (uploadSpeedMode == TR_SPEEDLIMIT_UNLIMITED) |
---|
507 | index = OPTION_POPUP_NO_LIMIT; |
---|
508 | else if (uploadSpeedMode == TR_SPEEDLIMIT_GLOBAL) |
---|
509 | index = OPTION_POPUP_GLOBAL; |
---|
510 | else |
---|
511 | index = -1; |
---|
512 | [fUploadLimitPopUp selectItemAtIndex: index]; |
---|
513 | [fUploadLimitPopUp setEnabled: YES]; |
---|
514 | |
---|
515 | [fUploadLimitLabel setHidden: uploadSpeedMode != TR_SPEEDLIMIT_SINGLE]; |
---|
516 | [fUploadLimitField setHidden: uploadSpeedMode != TR_SPEEDLIMIT_SINGLE]; |
---|
517 | if (uploadSpeedLimit != INVALID) |
---|
518 | [fUploadLimitField setIntValue: uploadSpeedLimit]; |
---|
519 | else |
---|
520 | [fUploadLimitField setStringValue: @""]; |
---|
521 | |
---|
522 | //set download view |
---|
523 | if (downloadSpeedMode == TR_SPEEDLIMIT_SINGLE) |
---|
524 | index = OPTION_POPUP_LIMIT; |
---|
525 | else if (downloadSpeedMode == TR_SPEEDLIMIT_UNLIMITED) |
---|
526 | index = OPTION_POPUP_NO_LIMIT; |
---|
527 | else if (downloadSpeedMode == TR_SPEEDLIMIT_GLOBAL) |
---|
528 | index = OPTION_POPUP_GLOBAL; |
---|
529 | else |
---|
530 | index = -1; |
---|
531 | [fDownloadLimitPopUp selectItemAtIndex: index]; |
---|
532 | [fDownloadLimitPopUp setEnabled: YES]; |
---|
533 | |
---|
534 | [fDownloadLimitLabel setHidden: downloadSpeedMode != TR_SPEEDLIMIT_SINGLE]; |
---|
535 | [fDownloadLimitField setHidden: downloadSpeedMode != TR_SPEEDLIMIT_SINGLE]; |
---|
536 | if (downloadSpeedLimit != INVALID) |
---|
537 | [fDownloadLimitField setIntValue: downloadSpeedLimit]; |
---|
538 | else |
---|
539 | [fDownloadLimitField setStringValue: @""]; |
---|
540 | |
---|
541 | //get ratio info |
---|
542 | enumerator = [fTorrents objectEnumerator]; |
---|
543 | torrent = [enumerator nextObject]; //first torrent |
---|
544 | |
---|
545 | int checkRatio = [torrent ratioSetting]; |
---|
546 | float ratioLimit = [torrent ratioLimit]; |
---|
547 | |
---|
548 | while ((torrent = [enumerator nextObject]) && (checkRatio != INVALID || checkRatio != INVALID)) |
---|
549 | { |
---|
550 | if (checkRatio != INVALID && checkRatio != [torrent ratioSetting]) |
---|
551 | checkRatio = INVALID; |
---|
552 | |
---|
553 | if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit]) |
---|
554 | ratioLimit = INVALID; |
---|
555 | } |
---|
556 | |
---|
557 | //set ratio view |
---|
558 | if (checkRatio == NSOnState) |
---|
559 | index = OPTION_POPUP_LIMIT; |
---|
560 | else if (checkRatio == NSOffState) |
---|
561 | index = OPTION_POPUP_NO_LIMIT; |
---|
562 | else if (checkRatio == NSMixedState) |
---|
563 | index = OPTION_POPUP_GLOBAL; |
---|
564 | else |
---|
565 | index = -1; |
---|
566 | [fRatioPopUp selectItemAtIndex: index]; |
---|
567 | [fRatioPopUp setEnabled: YES]; |
---|
568 | |
---|
569 | [fRatioLimitField setHidden: checkRatio != NSOnState]; |
---|
570 | if (ratioLimit != INVALID) |
---|
571 | [fRatioLimitField setFloatValue: ratioLimit]; |
---|
572 | else |
---|
573 | [fRatioLimitField setStringValue: @""]; |
---|
574 | |
---|
575 | //get peer info |
---|
576 | enumerator = [fTorrents objectEnumerator]; |
---|
577 | torrent = [enumerator nextObject]; //first torrent |
---|
578 | |
---|
579 | int maxPeers = [torrent maxPeerConnect]; |
---|
580 | |
---|
581 | while ((torrent = [enumerator nextObject])) |
---|
582 | { |
---|
583 | if (maxPeers != [torrent maxPeerConnect]) |
---|
584 | { |
---|
585 | maxPeers = INVALID; |
---|
586 | break; |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | //set peer view |
---|
591 | [fPeersConnectField setEnabled: YES]; |
---|
592 | if (maxPeers != INVALID) |
---|
593 | [fPeersConnectField setIntValue: maxPeers]; |
---|
594 | else |
---|
595 | [fPeersConnectField setStringValue: @""]; |
---|
596 | } |
---|
597 | |
---|
598 | - (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame |
---|
599 | { |
---|
600 | NSRect windowRect = [window frame]; |
---|
601 | windowRect.size.width = [window minSize].width; |
---|
602 | return windowRect; |
---|
603 | } |
---|
604 | |
---|
605 | - (void) windowWillClose: (NSNotification *) notification |
---|
606 | { |
---|
607 | if (fQuickLookAvailable) |
---|
608 | [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 0]; |
---|
609 | } |
---|
610 | |
---|
611 | - (void) setTab: (id) sender |
---|
612 | { |
---|
613 | int oldTabTag = fCurrentTabTag; |
---|
614 | fCurrentTabTag = [fTabMatrix selectedTag]; |
---|
615 | if (fCurrentTabTag == oldTabTag) |
---|
616 | return; |
---|
617 | |
---|
618 | [self updateInfoStats]; |
---|
619 | |
---|
620 | //take care of old view |
---|
621 | float oldHeight = 0; |
---|
622 | NSString * oldResizeSaveKey = nil; |
---|
623 | if (oldTabTag != INVALID) |
---|
624 | { |
---|
625 | //deselect old tab item |
---|
626 | [(InfoTabButtonCell *)[fTabMatrix cellWithTag: oldTabTag] setSelectedTab: NO]; |
---|
627 | |
---|
628 | switch (oldTabTag) |
---|
629 | { |
---|
630 | case TAB_TRACKER_TAG: |
---|
631 | oldResizeSaveKey = @"InspectorContentHeightTracker"; |
---|
632 | break; |
---|
633 | case TAB_PEERS_TAG: |
---|
634 | [fPeers release]; |
---|
635 | fPeers = nil; |
---|
636 | |
---|
637 | oldResizeSaveKey = @"InspectorContentHeightPeers"; |
---|
638 | break; |
---|
639 | case TAB_FILES_TAG: |
---|
640 | [self updateQuickLook]; |
---|
641 | |
---|
642 | oldResizeSaveKey = @"InspectorContentHeightFiles"; |
---|
643 | break; |
---|
644 | } |
---|
645 | |
---|
646 | NSView * oldView = [self tabViewForTag: oldTabTag]; |
---|
647 | oldHeight = [oldView frame].size.height; |
---|
648 | if (oldResizeSaveKey) |
---|
649 | [[NSUserDefaults standardUserDefaults] setFloat: oldHeight forKey: oldResizeSaveKey]; |
---|
650 | |
---|
651 | //remove old view |
---|
652 | [oldView setHidden: YES]; |
---|
653 | [oldView removeFromSuperview]; |
---|
654 | } |
---|
655 | |
---|
656 | //set new tab item |
---|
657 | NSView * view = [self tabViewForTag: fCurrentTabTag]; |
---|
658 | |
---|
659 | NSString * resizeSaveKey = nil; |
---|
660 | NSString * identifier, * title; |
---|
661 | switch (fCurrentTabTag) |
---|
662 | { |
---|
663 | case TAB_INFO_TAG: |
---|
664 | identifier = TAB_INFO_IDENT; |
---|
665 | title = NSLocalizedString(@"General Info", "Inspector -> title"); |
---|
666 | break; |
---|
667 | case TAB_ACTIVITY_TAG: |
---|
668 | identifier = TAB_ACTIVITY_IDENT; |
---|
669 | title = NSLocalizedString(@"Activity", "Inspector -> title"); |
---|
670 | |
---|
671 | [fPiecesView updateView: YES]; |
---|
672 | break; |
---|
673 | case TAB_TRACKER_TAG: |
---|
674 | identifier = TAB_TRACKER_IDENT; |
---|
675 | title = NSLocalizedString(@"Tracker", "Inspector -> title"); |
---|
676 | resizeSaveKey = @"InspectorContentHeightTracker"; |
---|
677 | break; |
---|
678 | case TAB_PEERS_TAG: |
---|
679 | identifier = TAB_PEERS_IDENT; |
---|
680 | title = NSLocalizedString(@"Peers", "Inspector -> title"); |
---|
681 | resizeSaveKey = @"InspectorContentHeightPeers"; |
---|
682 | break; |
---|
683 | case TAB_FILES_TAG: |
---|
684 | identifier = TAB_FILES_IDENT; |
---|
685 | title = NSLocalizedString(@"Files", "Inspector -> title"); |
---|
686 | resizeSaveKey = @"InspectorContentHeightFiles"; |
---|
687 | break; |
---|
688 | case TAB_OPTIONS_TAG: |
---|
689 | identifier = TAB_OPTIONS_IDENT; |
---|
690 | title = NSLocalizedString(@"Options", "Inspector -> title"); |
---|
691 | break; |
---|
692 | default: |
---|
693 | return; |
---|
694 | } |
---|
695 | |
---|
696 | [[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"]; |
---|
697 | |
---|
698 | NSWindow * window = [self window]; |
---|
699 | |
---|
700 | [window setTitle: [NSString stringWithFormat: @"%@ - %@", title, NSLocalizedString(@"Torrent Inspector", "Inspector -> title")]]; |
---|
701 | |
---|
702 | //selected tab item |
---|
703 | [(InfoTabButtonCell *)[fTabMatrix selectedCell] setSelectedTab: YES]; |
---|
704 | |
---|
705 | NSRect windowRect = [window frame], viewRect = [view frame]; |
---|
706 | |
---|
707 | if (resizeSaveKey) |
---|
708 | { |
---|
709 | float height = [[NSUserDefaults standardUserDefaults] floatForKey: resizeSaveKey]; |
---|
710 | if (height != 0) |
---|
711 | viewRect.size.height = MAX(height, TAB_MIN_HEIGHT); |
---|
712 | } |
---|
713 | |
---|
714 | float difference = (viewRect.size.height - oldHeight) * [window userSpaceScaleFactor]; |
---|
715 | windowRect.origin.y -= difference; |
---|
716 | windowRect.size.height += difference; |
---|
717 | |
---|
718 | if (resizeSaveKey) |
---|
719 | { |
---|
720 | if (!oldResizeSaveKey) |
---|
721 | { |
---|
722 | [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height - viewRect.size.height + TAB_MIN_HEIGHT)]; |
---|
723 | [window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)]; |
---|
724 | } |
---|
725 | } |
---|
726 | else |
---|
727 | { |
---|
728 | [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height)]; |
---|
729 | [window setMaxSize: NSMakeSize(FLT_MAX, windowRect.size.height)]; |
---|
730 | } |
---|
731 | |
---|
732 | viewRect.size.width = windowRect.size.width; |
---|
733 | [view setFrame: viewRect]; |
---|
734 | |
---|
735 | [window setFrame: windowRect display: YES animate: oldTabTag != INVALID]; |
---|
736 | [[window contentView] addSubview: view]; |
---|
737 | [view setHidden: NO]; |
---|
738 | } |
---|
739 | |
---|
740 | - (void) setNextTab |
---|
741 | { |
---|
742 | int tag = [fTabMatrix selectedTag]+1; |
---|
743 | if (tag >= [fTabMatrix numberOfColumns]) |
---|
744 | tag = 0; |
---|
745 | |
---|
746 | [fTabMatrix selectCellWithTag: tag]; |
---|
747 | [self setTab: nil]; |
---|
748 | } |
---|
749 | |
---|
750 | - (void) setPreviousTab |
---|
751 | { |
---|
752 | int tag = [fTabMatrix selectedTag]-1; |
---|
753 | if (tag < 0) |
---|
754 | tag = [fTabMatrix numberOfColumns]-1; |
---|
755 | |
---|
756 | [fTabMatrix selectCellWithTag: tag]; |
---|
757 | [self setTab: nil]; |
---|
758 | } |
---|
759 | |
---|
760 | - (int) numberOfRowsInTableView: (NSTableView *) tableView |
---|
761 | { |
---|
762 | if (tableView == fPeerTable) |
---|
763 | return fPeers ? [fPeers count] : 0; |
---|
764 | else if (tableView == fTrackerTable) |
---|
765 | return fTrackers ? [fTrackers count] : 0; |
---|
766 | return 0; |
---|
767 | } |
---|
768 | |
---|
769 | - (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (int) row |
---|
770 | { |
---|
771 | if (tableView == fPeerTable) |
---|
772 | { |
---|
773 | NSString * ident = [column identifier]; |
---|
774 | NSDictionary * peer = [fPeers objectAtIndex: row]; |
---|
775 | |
---|
776 | if ([ident isEqualToString: @"Encryption"]) |
---|
777 | return [[peer objectForKey: @"Encryption"] boolValue] ? [NSImage imageNamed: @"Lock.png"] : nil; |
---|
778 | else if ([ident isEqualToString: @"Client"]) |
---|
779 | return [peer objectForKey: @"Client"]; |
---|
780 | else if ([ident isEqualToString: @"Progress"]) |
---|
781 | return [peer objectForKey: @"Progress"]; |
---|
782 | else if ([ident isEqualToString: @"UL To"]) |
---|
783 | { |
---|
784 | NSNumber * rate; |
---|
785 | return (rate = [peer objectForKey: @"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @""; |
---|
786 | } |
---|
787 | else if ([ident isEqualToString: @"DL From"]) |
---|
788 | { |
---|
789 | NSNumber * rate; |
---|
790 | return (rate = [peer objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @""; |
---|
791 | } |
---|
792 | else |
---|
793 | return [peer objectForKey: @"IP"]; |
---|
794 | } |
---|
795 | else if (tableView == fTrackerTable) |
---|
796 | { |
---|
797 | id item = [fTrackers objectAtIndex: row]; |
---|
798 | if ([item isKindOfClass: [NSNumber class]]) |
---|
799 | return [NSString stringWithFormat: NSLocalizedString(@"Tier %d", "Inspector -> tracker table"), [item intValue]+1]; |
---|
800 | else |
---|
801 | return item; |
---|
802 | } |
---|
803 | return nil; |
---|
804 | } |
---|
805 | |
---|
806 | - (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn |
---|
807 | { |
---|
808 | if (tableView == fPeerTable) |
---|
809 | { |
---|
810 | if (fPeers) |
---|
811 | { |
---|
812 | NSArray * oldPeers = fPeers; |
---|
813 | fPeers = [[fPeers sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain]; |
---|
814 | [oldPeers release]; |
---|
815 | [tableView reloadData]; |
---|
816 | } |
---|
817 | } |
---|
818 | } |
---|
819 | |
---|
820 | - (BOOL) tableView: (NSTableView *) tableView shouldSelectRow: (int) row |
---|
821 | { |
---|
822 | return NO; |
---|
823 | } |
---|
824 | |
---|
825 | - (BOOL) tableView: (NSTableView *) tableView isGroupRow: (NSInteger) row |
---|
826 | { |
---|
827 | if (tableView == fTrackerTable) |
---|
828 | return [[fTrackers objectAtIndex: row] isKindOfClass: [NSNumber class]]; |
---|
829 | return NO; |
---|
830 | } |
---|
831 | |
---|
832 | - (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect |
---|
833 | tableColumn: (NSTableColumn *) column row: (int) row mouseLocation: (NSPoint) mouseLocation |
---|
834 | { |
---|
835 | if (tableView == fPeerTable) |
---|
836 | { |
---|
837 | NSDictionary * peer = [fPeers objectAtIndex: row]; |
---|
838 | NSMutableArray * components = [NSMutableArray arrayWithCapacity: 5]; |
---|
839 | |
---|
840 | [components addObject: [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%", |
---|
841 | "Inspector -> Peers tab -> table row tooltip"), [[peer objectForKey: @"Progress"] floatValue] * 100.0]]; |
---|
842 | |
---|
843 | if ([[peer objectForKey: @"Encryption"] boolValue]) |
---|
844 | [components addObject: NSLocalizedString(@"Encrypted Connection", "Inspector -> Peers tab -> table row tooltip")]; |
---|
845 | |
---|
846 | NSString * portString; |
---|
847 | int port; |
---|
848 | if ((port = [[peer objectForKey: @"Port"] intValue]) > 0) |
---|
849 | portString = [NSString stringWithFormat: @"%d", port]; |
---|
850 | else |
---|
851 | portString = NSLocalizedString(@"N/A", "Inspector -> Peers tab -> table row tooltip"); |
---|
852 | [components addObject: [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Port", |
---|
853 | "Inspector -> Peers tab -> table row tooltip"), portString]]; |
---|
854 | |
---|
855 | switch ([[peer objectForKey: @"From"] intValue]) |
---|
856 | { |
---|
857 | case TR_PEER_FROM_TRACKER: |
---|
858 | [components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")]; |
---|
859 | break; |
---|
860 | case TR_PEER_FROM_INCOMING: |
---|
861 | [components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")]; |
---|
862 | break; |
---|
863 | case TR_PEER_FROM_CACHE: |
---|
864 | [components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")]; |
---|
865 | break; |
---|
866 | case TR_PEER_FROM_PEX: |
---|
867 | [components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")]; |
---|
868 | break; |
---|
869 | } |
---|
870 | |
---|
871 | //determing status strings from flags |
---|
872 | NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 3]; |
---|
873 | NSString * flags = [peer objectForKey: @"Flags"]; |
---|
874 | |
---|
875 | if ([flags rangeOfString: @"D"].location != NSNotFound) |
---|
876 | [statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)", |
---|
877 | "Inspector -> peer -> status")]; |
---|
878 | else if ([flags rangeOfString: @"d"].location != NSNotFound) |
---|
879 | [statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)", |
---|
880 | "Inspector -> peer -> status")]; |
---|
881 | else; |
---|
882 | |
---|
883 | if ([flags rangeOfString: @"U"].location != NSNotFound) |
---|
884 | [statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)", |
---|
885 | "Inspector -> peer -> status")]; |
---|
886 | else if ([flags rangeOfString: @"u"].location != NSNotFound) |
---|
887 | [statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)", |
---|
888 | "Inspector -> peer -> status")]; |
---|
889 | else; |
---|
890 | |
---|
891 | if ([flags rangeOfString: @"K"].location != NSNotFound) |
---|
892 | [statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested", |
---|
893 | "Inspector -> peer -> status")]; |
---|
894 | |
---|
895 | if ([flags rangeOfString: @"?"].location != NSNotFound) |
---|
896 | [statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested", |
---|
897 | "Inspector -> peer -> status")]; |
---|
898 | |
---|
899 | if ([statusArray count] > 0) |
---|
900 | [components addObject: [@"\n" stringByAppendingString: [statusArray componentsJoinedByString: @"\n\n"]]]; |
---|
901 | |
---|
902 | return [components componentsJoinedByString: @"\n"]; |
---|
903 | } |
---|
904 | return nil; |
---|
905 | } |
---|
906 | |
---|
907 | // This is the QuickLook delegate method |
---|
908 | // It should return the frame for the item represented by the URL |
---|
909 | // If an empty frame is returned then the panel will fade in/out instead |
---|
910 | - (NSRect) previewPanel: (NSPanel *) panel frameForURL: (NSURL *) url |
---|
911 | { |
---|
912 | if (fCurrentTabTag == TAB_FILES_TAG && [[fFileController outlineView] numberOfSelectedRows] > 0) |
---|
913 | { |
---|
914 | int row = [self visibleRowWithURL: url]; |
---|
915 | if (row != -1) |
---|
916 | { |
---|
917 | FileOutlineView * fileOutlineView = [fFileController outlineView]; |
---|
918 | |
---|
919 | NSRect frame = [fileOutlineView rectOfRow: row]; |
---|
920 | frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil]; |
---|
921 | frame.origin = [[self window] convertBaseToScreen: frame.origin]; |
---|
922 | frame.origin.y -= frame.size.height; |
---|
923 | return frame; |
---|
924 | } |
---|
925 | else |
---|
926 | return NSZeroRect; |
---|
927 | } |
---|
928 | else |
---|
929 | { |
---|
930 | NSRect frame = [fImageView frame]; |
---|
931 | frame.origin = [[self window] convertBaseToScreen: frame.origin]; |
---|
932 | return frame; |
---|
933 | } |
---|
934 | } |
---|
935 | |
---|
936 | #warning needed? |
---|
937 | - (int) visibleRowWithURL: (NSURL *) url |
---|
938 | { |
---|
939 | FileOutlineView * fileOutlineView = [fFileController outlineView]; |
---|
940 | |
---|
941 | NSString * fullPath = [url path]; |
---|
942 | NSString * folder = [[fTorrents objectAtIndex: 0] downloadFolder]; |
---|
943 | NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]]; |
---|
944 | |
---|
945 | int row; |
---|
946 | for (row = visibleRows.location; row <= row + visibleRows.length; row++) |
---|
947 | { |
---|
948 | id rowItem = [fileOutlineView itemAtRow: row]; |
---|
949 | if ([[folder stringByAppendingPathComponent: [rowItem objectForKey: @"Path"]] isEqualToString: fullPath]) |
---|
950 | return row; |
---|
951 | } |
---|
952 | return -1; |
---|
953 | } |
---|
954 | |
---|
955 | - (BOOL) quickLookSelectItems |
---|
956 | { |
---|
957 | if (!fQuickLookAvailable) |
---|
958 | return NO; |
---|
959 | |
---|
960 | NSMutableArray * urlArray = nil; |
---|
961 | |
---|
962 | FileOutlineView * fileOutlineView = [fFileController outlineView]; |
---|
963 | if (fCurrentTabTag == TAB_FILES_TAG && [fileOutlineView numberOfSelectedRows] > 0) |
---|
964 | { |
---|
965 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
966 | NSString * folder = [torrent downloadFolder]; |
---|
967 | NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; |
---|
968 | urlArray = [NSMutableArray arrayWithCapacity: [indexes count]]; |
---|
969 | |
---|
970 | int i; |
---|
971 | for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) |
---|
972 | { |
---|
973 | NSDictionary * item = [fileOutlineView itemAtRow: i]; |
---|
974 | if ([[item objectForKey: @"IsFolder"] boolValue] |
---|
975 | || [torrent fileProgress: [[item objectForKey: @"Indexes"] firstIndex]] == 1.0) |
---|
976 | [urlArray addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [item objectForKey: @"Path"]]]]; |
---|
977 | } |
---|
978 | } |
---|
979 | else |
---|
980 | { |
---|
981 | if ([fTorrents count] > 0) |
---|
982 | { |
---|
983 | urlArray = [NSMutableArray arrayWithCapacity: [fTorrents count]]; |
---|
984 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
985 | Torrent * torrent; |
---|
986 | while ((torrent = [enumerator nextObject])) |
---|
987 | { |
---|
988 | if ([torrent folder] || [torrent progress] == 1.0) |
---|
989 | [urlArray addObject: [NSURL fileURLWithPath: [torrent dataLocation]]]; |
---|
990 | } |
---|
991 | } |
---|
992 | } |
---|
993 | |
---|
994 | if (urlArray && [urlArray count] > 0) |
---|
995 | { |
---|
996 | [[QLPreviewPanel sharedPreviewPanel] setURLs: urlArray currentIndex: 0 preservingDisplayState: YES]; |
---|
997 | return YES; |
---|
998 | } |
---|
999 | else |
---|
1000 | return NO; |
---|
1001 | } |
---|
1002 | |
---|
1003 | - (void) toggleQuickLook: (id) sender |
---|
1004 | { |
---|
1005 | if (!fQuickLookAvailable) |
---|
1006 | return; |
---|
1007 | |
---|
1008 | if ([[QLPreviewPanel sharedPreviewPanel] isOpen]) |
---|
1009 | [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 2]; |
---|
1010 | else |
---|
1011 | { |
---|
1012 | if ([self quickLookSelectItems]) |
---|
1013 | { |
---|
1014 | [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFrontWithEffect: 2]; |
---|
1015 | // Restore the focus to our window to demo the selection changing, scrolling (left/right) |
---|
1016 | // and closing (space) functionality |
---|
1017 | [[self window] makeKeyWindow]; |
---|
1018 | } |
---|
1019 | } |
---|
1020 | } |
---|
1021 | |
---|
1022 | - (void) updateQuickLook |
---|
1023 | { |
---|
1024 | if (!fQuickLookAvailable || ![[QLPreviewPanel sharedPreviewPanel] isOpen]) |
---|
1025 | return; |
---|
1026 | |
---|
1027 | //if the user changes the selection while the panel is open then update the current items |
---|
1028 | if (![self quickLookSelectItems]) |
---|
1029 | [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 1]; |
---|
1030 | } |
---|
1031 | |
---|
1032 | - (void) quickLookPressLeft |
---|
1033 | { |
---|
1034 | if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen]) |
---|
1035 | [[QLPreviewPanel sharedPreviewPanel] selectPreviousItem]; |
---|
1036 | } |
---|
1037 | |
---|
1038 | - (void) quickLookPressRight |
---|
1039 | { |
---|
1040 | if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen]) |
---|
1041 | [[QLPreviewPanel sharedPreviewPanel] selectNextItem]; |
---|
1042 | } |
---|
1043 | |
---|
1044 | - (void) keyDown: (NSEvent *) event |
---|
1045 | { |
---|
1046 | unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0]; |
---|
1047 | if (firstChar == ' ') |
---|
1048 | [self toggleQuickLook: nil]; |
---|
1049 | else if (firstChar == NSRightArrowFunctionKey) |
---|
1050 | [self quickLookPressRight]; |
---|
1051 | else if (firstChar == NSLeftArrowFunctionKey) |
---|
1052 | [self quickLookPressLeft]; |
---|
1053 | else |
---|
1054 | [super keyDown: event]; |
---|
1055 | } |
---|
1056 | |
---|
1057 | - (void) setPiecesView: (id) sender |
---|
1058 | { |
---|
1059 | [self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE]; |
---|
1060 | } |
---|
1061 | |
---|
1062 | - (void) setPiecesViewForAvailable: (BOOL) available |
---|
1063 | { |
---|
1064 | [fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE]; |
---|
1065 | [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS]; |
---|
1066 | |
---|
1067 | [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"]; |
---|
1068 | [fPiecesView updateView: YES]; |
---|
1069 | } |
---|
1070 | |
---|
1071 | - (void) revealTorrentFile: (id) sender |
---|
1072 | { |
---|
1073 | if ([fTorrents count] > 0) |
---|
1074 | [[fTorrents objectAtIndex: 0] revealPublicTorrent]; |
---|
1075 | } |
---|
1076 | |
---|
1077 | - (void) revealDataFile: (id) sender |
---|
1078 | { |
---|
1079 | if ([fTorrents count] > 0) |
---|
1080 | [[fTorrents objectAtIndex: 0] revealData]; |
---|
1081 | } |
---|
1082 | |
---|
1083 | - (void) setSpeedMode: (id) sender |
---|
1084 | { |
---|
1085 | BOOL upload = sender == fUploadLimitPopUp; |
---|
1086 | int mode; |
---|
1087 | switch ([sender indexOfSelectedItem]) |
---|
1088 | { |
---|
1089 | case OPTION_POPUP_LIMIT: |
---|
1090 | mode = TR_SPEEDLIMIT_SINGLE; |
---|
1091 | break; |
---|
1092 | case OPTION_POPUP_NO_LIMIT: |
---|
1093 | mode = TR_SPEEDLIMIT_UNLIMITED; |
---|
1094 | break; |
---|
1095 | case OPTION_POPUP_GLOBAL: |
---|
1096 | mode = TR_SPEEDLIMIT_GLOBAL; |
---|
1097 | break; |
---|
1098 | default: |
---|
1099 | return; |
---|
1100 | } |
---|
1101 | |
---|
1102 | Torrent * torrent; |
---|
1103 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
1104 | while ((torrent = [enumerator nextObject])) |
---|
1105 | [torrent setSpeedMode: mode upload: upload]; |
---|
1106 | |
---|
1107 | NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField; |
---|
1108 | |
---|
1109 | BOOL single = mode == TR_SPEEDLIMIT_SINGLE; |
---|
1110 | [field setHidden: !single]; |
---|
1111 | if (single) |
---|
1112 | { |
---|
1113 | [field selectText: self]; |
---|
1114 | [[self window] makeKeyAndOrderFront:self]; |
---|
1115 | } |
---|
1116 | |
---|
1117 | NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel; |
---|
1118 | [label setHidden: !single]; |
---|
1119 | } |
---|
1120 | |
---|
1121 | - (void) setSpeedLimit: (id) sender |
---|
1122 | { |
---|
1123 | BOOL upload = sender == fUploadLimitField; |
---|
1124 | int limit = [sender intValue]; |
---|
1125 | |
---|
1126 | Torrent * torrent; |
---|
1127 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
1128 | |
---|
1129 | while ((torrent = [enumerator nextObject])) |
---|
1130 | [torrent setSpeedLimit: limit upload: upload]; |
---|
1131 | } |
---|
1132 | |
---|
1133 | - (void) setRatioSetting: (id) sender |
---|
1134 | { |
---|
1135 | int setting; |
---|
1136 | switch ([sender indexOfSelectedItem]) |
---|
1137 | { |
---|
1138 | case OPTION_POPUP_LIMIT: |
---|
1139 | setting = NSOnState; |
---|
1140 | break; |
---|
1141 | case OPTION_POPUP_NO_LIMIT: |
---|
1142 | setting = NSOffState; |
---|
1143 | break; |
---|
1144 | case OPTION_POPUP_GLOBAL: |
---|
1145 | setting = NSMixedState; |
---|
1146 | break; |
---|
1147 | default: |
---|
1148 | return; |
---|
1149 | } |
---|
1150 | |
---|
1151 | Torrent * torrent; |
---|
1152 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
1153 | while ((torrent = [enumerator nextObject])) |
---|
1154 | [torrent setRatioSetting: setting]; |
---|
1155 | |
---|
1156 | BOOL single = setting == NSOnState; |
---|
1157 | [fRatioLimitField setHidden: !single]; |
---|
1158 | if (single) |
---|
1159 | { |
---|
1160 | [fRatioLimitField selectText: self]; |
---|
1161 | [[self window] makeKeyAndOrderFront:self]; |
---|
1162 | } |
---|
1163 | |
---|
1164 | [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; |
---|
1165 | } |
---|
1166 | |
---|
1167 | - (void) setRatioLimit: (id) sender |
---|
1168 | { |
---|
1169 | float limit = [sender floatValue]; |
---|
1170 | |
---|
1171 | Torrent * torrent; |
---|
1172 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
1173 | while ((torrent = [enumerator nextObject])) |
---|
1174 | [torrent setRatioLimit: limit]; |
---|
1175 | } |
---|
1176 | |
---|
1177 | - (void) setPeersConnectLimit: (id) sender |
---|
1178 | { |
---|
1179 | int limit = [sender intValue]; |
---|
1180 | |
---|
1181 | Torrent * torrent; |
---|
1182 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
1183 | while ((torrent = [enumerator nextObject])) |
---|
1184 | [torrent setMaxPeerConnect: limit]; |
---|
1185 | } |
---|
1186 | |
---|
1187 | |
---|
1188 | - (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor |
---|
1189 | { |
---|
1190 | [fInitialString release]; |
---|
1191 | fInitialString = [[control stringValue] retain]; |
---|
1192 | |
---|
1193 | return YES; |
---|
1194 | } |
---|
1195 | |
---|
1196 | - (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error |
---|
1197 | { |
---|
1198 | NSBeep(); |
---|
1199 | if (fInitialString) |
---|
1200 | { |
---|
1201 | [control setStringValue: fInitialString]; |
---|
1202 | [fInitialString release]; |
---|
1203 | fInitialString = nil; |
---|
1204 | } |
---|
1205 | return NO; |
---|
1206 | } |
---|
1207 | |
---|
1208 | @end |
---|
1209 | |
---|
1210 | @implementation InfoWindowController (Private) |
---|
1211 | |
---|
1212 | - (void) updateInfoGeneral |
---|
1213 | { |
---|
1214 | if ([fTorrents count] != 1) |
---|
1215 | return; |
---|
1216 | |
---|
1217 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1218 | |
---|
1219 | [fTrackerField setStringValue: [torrent trackerAddressAnnounce]]; |
---|
1220 | |
---|
1221 | NSString * location = [torrent dataLocation]; |
---|
1222 | [fDataLocationField setStringValue: [location stringByAbbreviatingWithTildeInPath]]; |
---|
1223 | [fDataLocationField setToolTip: location]; |
---|
1224 | } |
---|
1225 | |
---|
1226 | - (void) updateInfoActivity |
---|
1227 | { |
---|
1228 | int numberSelected = [fTorrents count]; |
---|
1229 | if (numberSelected == 0) |
---|
1230 | return; |
---|
1231 | |
---|
1232 | uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0; |
---|
1233 | NSDate * lastActivity = nil; |
---|
1234 | Torrent * torrent; |
---|
1235 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
1236 | while ((torrent = [enumerator nextObject])) |
---|
1237 | { |
---|
1238 | have += [torrent haveTotal]; |
---|
1239 | haveVerified += [torrent haveVerified]; |
---|
1240 | downloadedTotal += [torrent downloadedTotal]; |
---|
1241 | uploadedTotal += [torrent uploadedTotal]; |
---|
1242 | failedHash += [torrent failedHash]; |
---|
1243 | |
---|
1244 | NSDate * nextLastActivity; |
---|
1245 | if ((nextLastActivity = [torrent dateActivity])) |
---|
1246 | lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity; |
---|
1247 | } |
---|
1248 | |
---|
1249 | if (have == 0) |
---|
1250 | [fHaveField setStringValue: [NSString stringForFileSize: 0]]; |
---|
1251 | else |
---|
1252 | { |
---|
1253 | NSString * verifiedString = [NSString stringWithFormat: NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"), |
---|
1254 | [NSString stringForFileSize: haveVerified]]; |
---|
1255 | if (have == haveVerified) |
---|
1256 | [fHaveField setStringValue: verifiedString]; |
---|
1257 | else |
---|
1258 | [fHaveField setStringValue: [NSString stringWithFormat: @"%@ (%@)", [NSString stringForFileSize: have], verifiedString]]; |
---|
1259 | } |
---|
1260 | |
---|
1261 | [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]]; |
---|
1262 | [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]]; |
---|
1263 | [fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]]; |
---|
1264 | |
---|
1265 | [fDateActivityField setObjectValue: lastActivity]; |
---|
1266 | |
---|
1267 | if (numberSelected == 1) |
---|
1268 | { |
---|
1269 | torrent = [fTorrents objectAtIndex: 0]; |
---|
1270 | |
---|
1271 | [fStateField setStringValue: [torrent stateString]]; |
---|
1272 | |
---|
1273 | if ([torrent folder]) |
---|
1274 | [fProgressField setStringValue: [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)", |
---|
1275 | "Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]]; |
---|
1276 | else |
---|
1277 | [fProgressField setStringValue: [NSString localizedStringWithFormat: @"%.2f%%", 100.0 * [torrent progress]]]; |
---|
1278 | |
---|
1279 | [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]]; |
---|
1280 | [fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""]; |
---|
1281 | |
---|
1282 | NSString * errorMessage = [torrent errorMessage]; |
---|
1283 | if (![errorMessage isEqualToString: [fErrorMessageView string]]) |
---|
1284 | { |
---|
1285 | [fErrorMessageView setString: errorMessage]; |
---|
1286 | [fErrorMessageView setSelectable: ![errorMessage isEqualToString: @""]]; |
---|
1287 | } |
---|
1288 | |
---|
1289 | [fDateCompletedField setObjectValue: [torrent dateCompleted]]; |
---|
1290 | |
---|
1291 | [fPiecesView updateView: NO]; |
---|
1292 | } |
---|
1293 | } |
---|
1294 | |
---|
1295 | #warning reload table when necessary? |
---|
1296 | - (void) updateInfoTracker |
---|
1297 | { |
---|
1298 | if ([fTorrents count] != 1) |
---|
1299 | return; |
---|
1300 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1301 | |
---|
1302 | //announce fields |
---|
1303 | NSString * announceAddress = [torrent trackerAddressAnnounce]; |
---|
1304 | [fAnnounceAddressField setStringValue: announceAddress]; |
---|
1305 | [fAnnounceAddressField setToolTip: announceAddress]; |
---|
1306 | |
---|
1307 | [fAnnounceLastField setObjectValue: [torrent lastAnnounceTime]]; |
---|
1308 | |
---|
1309 | NSString * announceResponse = [torrent announceResponse]; |
---|
1310 | [fAnnounceResponseField setStringValue: announceResponse]; |
---|
1311 | [fAnnounceResponseField setToolTip: announceResponse]; |
---|
1312 | [fAnnounceResponseField setSelectable: ![announceResponse isEqualToString: @""]]; |
---|
1313 | |
---|
1314 | int announceNext = [torrent nextAnnounceTime]; |
---|
1315 | [fAnnounceNextField setStringValue: announceNext > 0 ? [NSString timeString: announceNext showSeconds: YES] : @""]; |
---|
1316 | |
---|
1317 | //scrape fields |
---|
1318 | NSString * scrapeAddress; |
---|
1319 | if ((scrapeAddress = [torrent trackerAddressScrape])) |
---|
1320 | { |
---|
1321 | [fScrapeAddressField setStringValue: scrapeAddress]; |
---|
1322 | [fScrapeAddressField setToolTip: scrapeAddress]; |
---|
1323 | } |
---|
1324 | else |
---|
1325 | { |
---|
1326 | [fScrapeAddressField setStringValue: @""]; |
---|
1327 | [fScrapeAddressField setToolTip: @""]; |
---|
1328 | } |
---|
1329 | |
---|
1330 | [fScrapeLastField setObjectValue: [torrent lastScrapeTime]]; |
---|
1331 | |
---|
1332 | NSString * scrapeResponse = [torrent scrapeResponse]; |
---|
1333 | [fScrapeResponseField setStringValue: scrapeResponse]; |
---|
1334 | [fScrapeResponseField setToolTip: scrapeResponse]; |
---|
1335 | [fScrapeResponseField setSelectable: ![scrapeResponse isEqualToString: @""]]; |
---|
1336 | |
---|
1337 | int scrapeNext = [torrent nextScrapeTime]; |
---|
1338 | [fScrapeNextField setStringValue: scrapeNext > 0 ? [NSString timeString: scrapeNext showSeconds: YES] : @""]; |
---|
1339 | } |
---|
1340 | |
---|
1341 | - (void) updateInfoPeers |
---|
1342 | { |
---|
1343 | if ([fTorrents count] != 1) |
---|
1344 | return; |
---|
1345 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1346 | |
---|
1347 | int seeders = [torrent seeders], leechers = [torrent leechers], completed = [torrent completedFromTracker]; |
---|
1348 | [fSeedersField setStringValue: seeders >= 0 ? [NSString stringWithFormat: @"%d", seeders] : @""]; |
---|
1349 | [fLeechersField setStringValue: leechers >= 0 ? [NSString stringWithFormat: @"%d", leechers] : @""]; |
---|
1350 | [fCompletedFromTrackerField setStringValue: completed >= 0 ? [NSString stringWithFormat: @"%d", completed] : @""]; |
---|
1351 | |
---|
1352 | BOOL active = [torrent isActive]; |
---|
1353 | |
---|
1354 | if (active) |
---|
1355 | { |
---|
1356 | int total = [torrent totalPeersConnected]; |
---|
1357 | NSString * connected = [NSString stringWithFormat: |
---|
1358 | NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"), total]; |
---|
1359 | |
---|
1360 | if (total > 0) |
---|
1361 | { |
---|
1362 | NSMutableArray * components = [NSMutableArray arrayWithCapacity: 4]; |
---|
1363 | int count; |
---|
1364 | if ((count = [torrent totalPeersTracker]) > 0) |
---|
1365 | [components addObject: [NSString stringWithFormat: |
---|
1366 | NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), count]]; |
---|
1367 | if ((count = [torrent totalPeersIncoming]) > 0) |
---|
1368 | [components addObject: [NSString stringWithFormat: |
---|
1369 | NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), count]]; |
---|
1370 | if ((count = [torrent totalPeersPex]) > 0) |
---|
1371 | [components addObject: [NSString stringWithFormat: |
---|
1372 | NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), count]]; |
---|
1373 | if ((count = [torrent totalPeersCache]) > 0) |
---|
1374 | [components addObject: [NSString stringWithFormat: |
---|
1375 | NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]]; |
---|
1376 | |
---|
1377 | connected = [connected stringByAppendingFormat: @": %@", [components componentsJoinedByString: @", "]]; |
---|
1378 | } |
---|
1379 | |
---|
1380 | [fConnectedPeersField setStringValue: connected]; |
---|
1381 | |
---|
1382 | [fDownloadingFromField setIntValue: [torrent peersSendingToUs]]; |
---|
1383 | [fUploadingToField setIntValue: [torrent peersGettingFromUs]]; |
---|
1384 | } |
---|
1385 | else |
---|
1386 | { |
---|
1387 | [fConnectedPeersField setStringValue: @""]; |
---|
1388 | [fDownloadingFromField setStringValue: @""]; |
---|
1389 | [fUploadingToField setStringValue: @""]; |
---|
1390 | } |
---|
1391 | |
---|
1392 | [fKnownField setIntValue: [torrent totalPeersKnown]]; |
---|
1393 | |
---|
1394 | [fPeers release]; |
---|
1395 | fPeers = [[[torrent peers] sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain]; |
---|
1396 | |
---|
1397 | [fPeerTable reloadData]; |
---|
1398 | } |
---|
1399 | |
---|
1400 | - (void) updateInfoFiles |
---|
1401 | { |
---|
1402 | if ([fTorrents count] == 1) |
---|
1403 | [fFileController reloadData]; |
---|
1404 | } |
---|
1405 | |
---|
1406 | - (NSView *) tabViewForTag: (int) tag |
---|
1407 | { |
---|
1408 | switch (tag) |
---|
1409 | { |
---|
1410 | case TAB_INFO_TAG: |
---|
1411 | return fInfoView; |
---|
1412 | case TAB_ACTIVITY_TAG: |
---|
1413 | return fActivityView; |
---|
1414 | case TAB_TRACKER_TAG: |
---|
1415 | return fTrackerView; |
---|
1416 | case TAB_PEERS_TAG: |
---|
1417 | return fPeersView; |
---|
1418 | case TAB_FILES_TAG: |
---|
1419 | return fFilesView; |
---|
1420 | case TAB_OPTIONS_TAG: |
---|
1421 | return fOptionsView; |
---|
1422 | default: |
---|
1423 | return nil; |
---|
1424 | } |
---|
1425 | } |
---|
1426 | |
---|
1427 | - (NSArray *) peerSortDescriptors |
---|
1428 | { |
---|
1429 | NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2]; |
---|
1430 | |
---|
1431 | NSArray * oldDescriptors = [fPeerTable sortDescriptors]; |
---|
1432 | BOOL useSecond = YES, asc = YES; |
---|
1433 | if ([oldDescriptors count] > 0) |
---|
1434 | { |
---|
1435 | NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0]; |
---|
1436 | [descriptors addObject: descriptor]; |
---|
1437 | |
---|
1438 | if ((useSecond = ![[descriptor key] isEqualToString: @"IP"])) |
---|
1439 | asc = [descriptor ascending]; |
---|
1440 | } |
---|
1441 | |
---|
1442 | //sort by IP after primary sort |
---|
1443 | if (useSecond) |
---|
1444 | { |
---|
1445 | NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc |
---|
1446 | selector: @selector(compareIP:)]; |
---|
1447 | [descriptors addObject: secondDescriptor]; |
---|
1448 | [secondDescriptor release]; |
---|
1449 | } |
---|
1450 | |
---|
1451 | return descriptors; |
---|
1452 | } |
---|
1453 | |
---|
1454 | @end |
---|