1 | /****************************************************************************** |
---|
2 | * $Id: InfoWindowController.m 10113 2010-02-06 15:58:35Z livings124 $ |
---|
3 | * |
---|
4 | * Copyright (c) 2006-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 "InfoWindowController.h" |
---|
26 | #import "FileListNode.h" |
---|
27 | #import "FileOutlineController.h" |
---|
28 | #import "FileOutlineView.h" |
---|
29 | #import "InfoTabButtonCell.h" |
---|
30 | #import "NSApplicationAdditions.h" |
---|
31 | #import "NSStringAdditions.h" |
---|
32 | #import "PeerProgressIndicatorCell.h" |
---|
33 | #import "PiecesView.h" |
---|
34 | #import "Torrent.h" |
---|
35 | #import "TrackerCell.h" |
---|
36 | #import "TrackerNode.h" |
---|
37 | #import "TrackerTableView.h" |
---|
38 | #include "utils.h" //tr_getRatio() |
---|
39 | |
---|
40 | #define TAB_INFO_IDENT @"Info" |
---|
41 | #define TAB_ACTIVITY_IDENT @"Activity" |
---|
42 | #define TAB_TRACKER_IDENT @"Tracker" |
---|
43 | #define TAB_PEERS_IDENT @"Peers" |
---|
44 | #define TAB_FILES_IDENT @"Files" |
---|
45 | #define TAB_OPTIONS_IDENT @"Options" |
---|
46 | |
---|
47 | #define TAB_MIN_HEIGHT 250 |
---|
48 | |
---|
49 | #define TRACKER_GROUP_SEPARATOR_HEIGHT 14.0 |
---|
50 | |
---|
51 | #define PIECES_CONTROL_PROGRESS 0 |
---|
52 | #define PIECES_CONTROL_AVAILABLE 1 |
---|
53 | |
---|
54 | #define OPTION_POPUP_GLOBAL 0 |
---|
55 | #define OPTION_POPUP_NO_LIMIT 1 |
---|
56 | #define OPTION_POPUP_LIMIT 2 |
---|
57 | |
---|
58 | #define OPTION_POPUP_PRIORITY_HIGH 0 |
---|
59 | #define OPTION_POPUP_PRIORITY_NORMAL 1 |
---|
60 | #define OPTION_POPUP_PRIORITY_LOW 2 |
---|
61 | |
---|
62 | #define INVALID -99 |
---|
63 | |
---|
64 | #define TRACKER_ADD_TAG 0 |
---|
65 | #define TRACKER_REMOVE_TAG 1 |
---|
66 | |
---|
67 | typedef enum |
---|
68 | { |
---|
69 | TAB_INFO_TAG = 0, |
---|
70 | TAB_ACTIVITY_TAG = 1, |
---|
71 | TAB_TRACKER_TAG = 2, |
---|
72 | TAB_PEERS_TAG = 3, |
---|
73 | TAB_FILES_TAG = 4, |
---|
74 | TAB_OPTIONS_TAG = 5 |
---|
75 | } tabTag; |
---|
76 | |
---|
77 | @interface InfoWindowController (Private) |
---|
78 | |
---|
79 | - (void) resetInfo; |
---|
80 | - (void) resetInfoForTorrent: (NSNotification *) notification; |
---|
81 | |
---|
82 | - (void) updateInfoGeneral; |
---|
83 | - (void) updateInfoActivity; |
---|
84 | - (void) updateInfoTracker; |
---|
85 | - (void) updateInfoPeers; |
---|
86 | - (void) updateInfoFiles; |
---|
87 | |
---|
88 | - (NSView *) tabViewForTag: (NSInteger) tag; |
---|
89 | - (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate; |
---|
90 | - (NSArray *) peerSortDescriptors; |
---|
91 | |
---|
92 | - (BOOL) canQuickLookFile: (FileListNode *) item; |
---|
93 | |
---|
94 | - (void) addTrackers; |
---|
95 | - (void) removeTrackers; |
---|
96 | |
---|
97 | @end |
---|
98 | |
---|
99 | @implementation InfoWindowController |
---|
100 | |
---|
101 | - (id) init |
---|
102 | { |
---|
103 | if ((self = [super initWithWindowNibName: @"InfoWindow"])) |
---|
104 | { |
---|
105 | fTrackerCell = [[TrackerCell alloc] init]; |
---|
106 | } |
---|
107 | |
---|
108 | return self; |
---|
109 | } |
---|
110 | |
---|
111 | - (void) awakeFromNib |
---|
112 | { |
---|
113 | //window location and size |
---|
114 | NSPanel * window = (NSPanel *)[self window]; |
---|
115 | |
---|
116 | CGFloat windowHeight = [window frame].size.height; |
---|
117 | |
---|
118 | [window setFrameAutosaveName: @"InspectorWindow"]; |
---|
119 | [window setFrameUsingName: @"InspectorWindow"]; |
---|
120 | |
---|
121 | NSRect windowRect = [window frame]; |
---|
122 | windowRect.origin.y -= windowHeight - windowRect.size.height; |
---|
123 | windowRect.size.height = windowHeight; |
---|
124 | [window setFrame: windowRect display: NO]; |
---|
125 | |
---|
126 | [window setBecomesKeyOnlyIfNeeded: YES]; |
---|
127 | |
---|
128 | //set tab images and tooltips |
---|
129 | [[fTabMatrix cellWithTag: TAB_INFO_TAG] setIcon: [NSImage imageNamed: @"InfoGeneral.png"]]; |
---|
130 | [[fTabMatrix cellWithTag: TAB_ACTIVITY_TAG] setIcon: [NSImage imageNamed: @"InfoActivity.png"]]; |
---|
131 | [[fTabMatrix cellWithTag: TAB_TRACKER_TAG] setIcon: [NSImage imageNamed: @"InfoTracker.png"]]; |
---|
132 | [[fTabMatrix cellWithTag: TAB_PEERS_TAG] setIcon: [NSImage imageNamed: @"InfoPeers.png"]]; |
---|
133 | [[fTabMatrix cellWithTag: TAB_FILES_TAG] setIcon: [NSImage imageNamed: @"InfoFiles.png"]]; |
---|
134 | [[fTabMatrix cellWithTag: TAB_OPTIONS_TAG] setIcon: [NSImage imageNamed: @"InfoOptions.png"]]; |
---|
135 | |
---|
136 | //set selected tab |
---|
137 | fCurrentTabTag = INVALID; |
---|
138 | NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InspectorSelected"]; |
---|
139 | NSInteger tag; |
---|
140 | if ([identifier isEqualToString: TAB_INFO_IDENT]) |
---|
141 | tag = TAB_INFO_TAG; |
---|
142 | else if ([identifier isEqualToString: TAB_ACTIVITY_IDENT]) |
---|
143 | tag = TAB_ACTIVITY_TAG; |
---|
144 | else if ([identifier isEqualToString: TAB_TRACKER_IDENT]) |
---|
145 | tag = TAB_TRACKER_TAG; |
---|
146 | else if ([identifier isEqualToString: TAB_PEERS_IDENT]) |
---|
147 | tag = TAB_PEERS_TAG; |
---|
148 | else if ([identifier isEqualToString: TAB_FILES_IDENT]) |
---|
149 | tag = TAB_FILES_TAG; |
---|
150 | else if ([identifier isEqualToString: TAB_OPTIONS_IDENT]) |
---|
151 | tag = TAB_OPTIONS_TAG; |
---|
152 | else //safety |
---|
153 | { |
---|
154 | [[NSUserDefaults standardUserDefaults] setObject: TAB_INFO_IDENT forKey: @"InspectorSelected"]; |
---|
155 | tag = TAB_INFO_TAG; |
---|
156 | } |
---|
157 | [fTabMatrix selectCellWithTag: tag]; |
---|
158 | [self setTab: nil]; |
---|
159 | |
---|
160 | if (![NSApp isOnSnowLeopardOrBetter]) |
---|
161 | { |
---|
162 | //reset images for reveal button, since the images are also used in the main table |
---|
163 | NSImage * revealOn = [[NSImage imageNamed: @"RevealOn.png"] copy], |
---|
164 | * revealOff = [[NSImage imageNamed: @"RevealOff.png"] copy]; |
---|
165 | |
---|
166 | [revealOn setFlipped: NO]; |
---|
167 | [revealOff setFlipped: NO]; |
---|
168 | |
---|
169 | [fRevealDataButton setImage: revealOff]; |
---|
170 | [fRevealDataButton setAlternateImage: revealOn]; |
---|
171 | |
---|
172 | [revealOn release]; |
---|
173 | [revealOff release]; |
---|
174 | } |
---|
175 | |
---|
176 | //initially sort peer table by IP |
---|
177 | if ([[fPeerTable sortDescriptors] count] == 0) |
---|
178 | [fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"] |
---|
179 | sortDescriptorPrototype]]]; |
---|
180 | |
---|
181 | //initially sort webseed table by address |
---|
182 | if ([[fWebSeedTable sortDescriptors] count] == 0) |
---|
183 | [fWebSeedTable setSortDescriptors: [NSArray arrayWithObject: [[fWebSeedTable tableColumnWithIdentifier: @"Address"] |
---|
184 | sortDescriptorPrototype]]]; |
---|
185 | |
---|
186 | //set table header tool tips |
---|
187 | [[fPeerTable tableColumnWithIdentifier: @"Encryption"] setHeaderToolTip: NSLocalizedString(@"Encrypted Connection", |
---|
188 | "inspector -> peer table -> header tool tip")]; |
---|
189 | [[fPeerTable tableColumnWithIdentifier: @"Progress"] setHeaderToolTip: NSLocalizedString(@"Available", |
---|
190 | "inspector -> peer table -> header tool tip")]; |
---|
191 | [[fPeerTable tableColumnWithIdentifier: @"UL To"] setHeaderToolTip: NSLocalizedString(@"Uploading To Peer", |
---|
192 | "inspector -> peer table -> header tool tip")]; |
---|
193 | [[fPeerTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Peer", |
---|
194 | "inspector -> peer table -> header tool tip")]; |
---|
195 | |
---|
196 | [[fWebSeedTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Web Seed", |
---|
197 | "inspector -> web seed table -> header tool tip")]; |
---|
198 | |
---|
199 | //prepare for animating peer table and web seed table |
---|
200 | NSRect webSeedTableFrame = [[fWebSeedTable enclosingScrollView] frame]; |
---|
201 | fWebSeedTableHeight = webSeedTableFrame.size.height; |
---|
202 | fSpaceBetweenWebSeedAndPeer = webSeedTableFrame.origin.y - NSMaxY([[fPeerTable enclosingScrollView] frame]); |
---|
203 | |
---|
204 | [self setWebSeedTableHidden: YES animate: NO]; |
---|
205 | |
---|
206 | //set blank inspector |
---|
207 | [self setInfoForTorrents: [NSArray array]]; |
---|
208 | |
---|
209 | //allow for update notifications |
---|
210 | NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; |
---|
211 | [nc addObserver: self selector: @selector(resetInfoForTorrent:) name: @"ResetInspector" object: nil]; |
---|
212 | [nc addObserver: self selector: @selector(updateInfoStats) name: @"UpdateStats" object: nil]; |
---|
213 | [nc addObserver: self selector: @selector(updateOptions) name: @"UpdateOptions" object: nil]; |
---|
214 | } |
---|
215 | |
---|
216 | - (void) dealloc |
---|
217 | { |
---|
218 | //save resizeable view height |
---|
219 | NSString * resizeSaveKey = nil; |
---|
220 | switch (fCurrentTabTag) |
---|
221 | { |
---|
222 | case TAB_TRACKER_TAG: |
---|
223 | resizeSaveKey = @"InspectorContentHeightTracker"; |
---|
224 | break; |
---|
225 | case TAB_PEERS_TAG: |
---|
226 | resizeSaveKey = @"InspectorContentHeightPeers"; |
---|
227 | break; |
---|
228 | case TAB_FILES_TAG: |
---|
229 | resizeSaveKey = @"InspectorContentHeightFiles"; |
---|
230 | break; |
---|
231 | } |
---|
232 | if (resizeSaveKey) |
---|
233 | [[NSUserDefaults standardUserDefaults] setFloat: [[self tabViewForTag: fCurrentTabTag] frame].size.height forKey: resizeSaveKey]; |
---|
234 | |
---|
235 | [[NSNotificationCenter defaultCenter] removeObserver: self]; |
---|
236 | |
---|
237 | [fTorrents release]; |
---|
238 | [fPeers release]; |
---|
239 | [fWebSeeds release]; |
---|
240 | [fTrackers release]; |
---|
241 | |
---|
242 | [fWebSeedTableAnimation release]; |
---|
243 | |
---|
244 | [fTrackerCell release]; |
---|
245 | |
---|
246 | [fPreviewPanel release]; |
---|
247 | |
---|
248 | [super dealloc]; |
---|
249 | } |
---|
250 | |
---|
251 | - (void) setInfoForTorrents: (NSArray *) torrents |
---|
252 | { |
---|
253 | if (fTorrents && [fTorrents isEqualToArray: torrents]) |
---|
254 | return; |
---|
255 | |
---|
256 | [fTorrents release]; |
---|
257 | fTorrents = [torrents retain]; |
---|
258 | |
---|
259 | [self resetInfo]; |
---|
260 | } |
---|
261 | |
---|
262 | - (void) updateInfoStats |
---|
263 | { |
---|
264 | switch ([fTabMatrix selectedTag]) |
---|
265 | { |
---|
266 | case TAB_INFO_TAG: |
---|
267 | [self updateInfoGeneral]; |
---|
268 | break; |
---|
269 | case TAB_ACTIVITY_TAG: |
---|
270 | [self updateInfoActivity]; |
---|
271 | break; |
---|
272 | case TAB_TRACKER_TAG: |
---|
273 | [self updateInfoTracker]; |
---|
274 | break; |
---|
275 | case TAB_PEERS_TAG: |
---|
276 | [self updateInfoPeers]; |
---|
277 | break; |
---|
278 | case TAB_FILES_TAG: |
---|
279 | [self updateInfoFiles]; |
---|
280 | break; |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | - (void) updateOptions |
---|
285 | { |
---|
286 | if ([fTorrents count] == 0) |
---|
287 | return; |
---|
288 | |
---|
289 | //get bandwidth info |
---|
290 | NSEnumerator * enumerator = [fTorrents objectEnumerator]; |
---|
291 | Torrent * torrent = [enumerator nextObject]; //first torrent |
---|
292 | |
---|
293 | NSInteger uploadUseSpeedLimit = [torrent usesSpeedLimit: YES] ? NSOnState : NSOffState, |
---|
294 | uploadSpeedLimit = [torrent speedLimit: YES], |
---|
295 | downloadUseSpeedLimit = [torrent usesSpeedLimit: NO] ? NSOnState : NSOffState, |
---|
296 | downloadSpeedLimit = [torrent speedLimit: NO], |
---|
297 | globalUseSpeedLimit = [torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState; |
---|
298 | |
---|
299 | while ((torrent = [enumerator nextObject]) |
---|
300 | && (uploadUseSpeedLimit != NSMixedState || uploadSpeedLimit != INVALID |
---|
301 | || downloadUseSpeedLimit != NSMixedState || downloadSpeedLimit != INVALID |
---|
302 | || globalUseSpeedLimit != NSMixedState)) |
---|
303 | { |
---|
304 | if (uploadUseSpeedLimit != NSMixedState && uploadUseSpeedLimit != ([torrent usesSpeedLimit: YES] ? NSOnState : NSOffState)) |
---|
305 | uploadUseSpeedLimit = NSMixedState; |
---|
306 | |
---|
307 | if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES]) |
---|
308 | uploadSpeedLimit = INVALID; |
---|
309 | |
---|
310 | if (downloadUseSpeedLimit != NSMixedState && downloadUseSpeedLimit != ([torrent usesSpeedLimit: NO] ? NSOnState : NSOffState)) |
---|
311 | downloadUseSpeedLimit = NSMixedState; |
---|
312 | |
---|
313 | if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO]) |
---|
314 | downloadSpeedLimit = INVALID; |
---|
315 | |
---|
316 | if (globalUseSpeedLimit != NSMixedState && globalUseSpeedLimit != ([torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState)) |
---|
317 | globalUseSpeedLimit = NSMixedState; |
---|
318 | } |
---|
319 | |
---|
320 | //set upload view |
---|
321 | [fUploadLimitCheck setState: uploadUseSpeedLimit]; |
---|
322 | [fUploadLimitCheck setEnabled: YES]; |
---|
323 | |
---|
324 | [fUploadLimitLabel setEnabled: uploadUseSpeedLimit == NSOnState]; |
---|
325 | [fUploadLimitField setEnabled: uploadUseSpeedLimit == NSOnState]; |
---|
326 | if (uploadSpeedLimit != INVALID) |
---|
327 | [fUploadLimitField setIntValue: uploadSpeedLimit]; |
---|
328 | else |
---|
329 | [fUploadLimitField setStringValue: @""]; |
---|
330 | |
---|
331 | //set download view |
---|
332 | [fDownloadLimitCheck setState: downloadUseSpeedLimit]; |
---|
333 | [fDownloadLimitCheck setEnabled: YES]; |
---|
334 | |
---|
335 | [fDownloadLimitLabel setEnabled: downloadUseSpeedLimit == NSOnState]; |
---|
336 | [fDownloadLimitField setEnabled: downloadUseSpeedLimit == NSOnState]; |
---|
337 | if (downloadSpeedLimit != INVALID) |
---|
338 | [fDownloadLimitField setIntValue: downloadSpeedLimit]; |
---|
339 | else |
---|
340 | [fDownloadLimitField setStringValue: @""]; |
---|
341 | |
---|
342 | //set global check |
---|
343 | [fGlobalLimitCheck setState: globalUseSpeedLimit]; |
---|
344 | [fGlobalLimitCheck setEnabled: YES]; |
---|
345 | |
---|
346 | //get ratio info |
---|
347 | enumerator = [fTorrents objectEnumerator]; |
---|
348 | torrent = [enumerator nextObject]; //first torrent |
---|
349 | |
---|
350 | NSInteger checkRatio = [torrent ratioSetting]; |
---|
351 | CGFloat ratioLimit = [torrent ratioLimit]; |
---|
352 | |
---|
353 | while ((torrent = [enumerator nextObject]) && (checkRatio != INVALID || ratioLimit != INVALID)) |
---|
354 | { |
---|
355 | if (checkRatio != INVALID && checkRatio != [torrent ratioSetting]) |
---|
356 | checkRatio = INVALID; |
---|
357 | |
---|
358 | if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit]) |
---|
359 | ratioLimit = INVALID; |
---|
360 | } |
---|
361 | |
---|
362 | //set ratio view |
---|
363 | NSInteger index; |
---|
364 | if (checkRatio == TR_RATIOLIMIT_SINGLE) |
---|
365 | index = OPTION_POPUP_LIMIT; |
---|
366 | else if (checkRatio == TR_RATIOLIMIT_UNLIMITED) |
---|
367 | index = OPTION_POPUP_NO_LIMIT; |
---|
368 | else if (checkRatio == TR_RATIOLIMIT_GLOBAL) |
---|
369 | index = OPTION_POPUP_GLOBAL; |
---|
370 | else |
---|
371 | index = -1; |
---|
372 | [fRatioPopUp selectItemAtIndex: index]; |
---|
373 | [fRatioPopUp setEnabled: YES]; |
---|
374 | |
---|
375 | [fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE]; |
---|
376 | if (ratioLimit != INVALID) |
---|
377 | [fRatioLimitField setFloatValue: ratioLimit]; |
---|
378 | else |
---|
379 | [fRatioLimitField setStringValue: @""]; |
---|
380 | |
---|
381 | //get priority info |
---|
382 | enumerator = [fTorrents objectEnumerator]; |
---|
383 | torrent = [enumerator nextObject]; //first torrent |
---|
384 | |
---|
385 | NSInteger priority = [torrent priority]; |
---|
386 | |
---|
387 | while ((torrent = [enumerator nextObject]) && priority != INVALID) |
---|
388 | { |
---|
389 | if (priority != INVALID && priority != [torrent priority]) |
---|
390 | priority = INVALID; |
---|
391 | } |
---|
392 | |
---|
393 | //set priority view |
---|
394 | if (priority == TR_PRI_HIGH) |
---|
395 | index = OPTION_POPUP_PRIORITY_HIGH; |
---|
396 | else if (priority == TR_PRI_NORMAL) |
---|
397 | index = OPTION_POPUP_PRIORITY_NORMAL; |
---|
398 | else if (priority == TR_PRI_LOW) |
---|
399 | index = OPTION_POPUP_PRIORITY_LOW; |
---|
400 | else |
---|
401 | index = -1; |
---|
402 | [fPriorityPopUp selectItemAtIndex: index]; |
---|
403 | [fPriorityPopUp setEnabled: YES]; |
---|
404 | |
---|
405 | //get peer info |
---|
406 | enumerator = [fTorrents objectEnumerator]; |
---|
407 | torrent = [enumerator nextObject]; //first torrent |
---|
408 | |
---|
409 | NSInteger maxPeers = [torrent maxPeerConnect]; |
---|
410 | |
---|
411 | while ((torrent = [enumerator nextObject])) |
---|
412 | { |
---|
413 | if (maxPeers != [torrent maxPeerConnect]) |
---|
414 | { |
---|
415 | maxPeers = INVALID; |
---|
416 | break; |
---|
417 | } |
---|
418 | } |
---|
419 | |
---|
420 | //set peer view |
---|
421 | [fPeersConnectField setEnabled: YES]; |
---|
422 | [fPeersConnectLabel setEnabled: YES]; |
---|
423 | if (maxPeers != INVALID) |
---|
424 | [fPeersConnectField setIntValue: maxPeers]; |
---|
425 | else |
---|
426 | [fPeersConnectField setStringValue: @""]; |
---|
427 | } |
---|
428 | |
---|
429 | - (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame |
---|
430 | { |
---|
431 | NSRect windowRect = [window frame]; |
---|
432 | windowRect.size.width = [window minSize].width; |
---|
433 | return windowRect; |
---|
434 | } |
---|
435 | |
---|
436 | - (void) animationDidEnd: (NSAnimation *) animation |
---|
437 | { |
---|
438 | if (animation == fWebSeedTableAnimation) |
---|
439 | { |
---|
440 | [fWebSeedTableAnimation release]; |
---|
441 | fWebSeedTableAnimation = nil; |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | - (NSSize) windowWillResize: (NSWindow *) window toSize: (NSSize) proposedFrameSize |
---|
446 | { |
---|
447 | //this is an edge-case - just stop the animation (stopAnimation jumps to end frame) |
---|
448 | if (fWebSeedTableAnimation) |
---|
449 | { |
---|
450 | [fWebSeedTableAnimation stopAnimation]; |
---|
451 | [fWebSeedTableAnimation release]; |
---|
452 | fWebSeedTableAnimation = nil; |
---|
453 | } |
---|
454 | |
---|
455 | return proposedFrameSize; |
---|
456 | } |
---|
457 | |
---|
458 | - (void) windowWillClose: (NSNotification *) notification |
---|
459 | { |
---|
460 | if ([NSApp isOnSnowLeopardOrBetter] && fCurrentTabTag == TAB_FILES_TAG |
---|
461 | && ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible])) |
---|
462 | [[QLPreviewPanelSL sharedPreviewPanel] reloadData]; |
---|
463 | } |
---|
464 | |
---|
465 | - (void) setTab: (id) sender |
---|
466 | { |
---|
467 | const NSInteger oldTabTag = fCurrentTabTag; |
---|
468 | fCurrentTabTag = [fTabMatrix selectedTag]; |
---|
469 | if (fCurrentTabTag == oldTabTag) |
---|
470 | return; |
---|
471 | |
---|
472 | [self updateInfoStats]; |
---|
473 | |
---|
474 | //take care of old view |
---|
475 | CGFloat oldHeight = 0; |
---|
476 | NSString * oldResizeSaveKey = nil; |
---|
477 | if (oldTabTag != INVALID) |
---|
478 | { |
---|
479 | //deselect old tab item |
---|
480 | [(InfoTabButtonCell *)[fTabMatrix cellWithTag: oldTabTag] setSelectedTab: NO]; |
---|
481 | |
---|
482 | switch (oldTabTag) |
---|
483 | { |
---|
484 | case TAB_ACTIVITY_TAG: |
---|
485 | [fPiecesView clearView]; |
---|
486 | break; |
---|
487 | |
---|
488 | case TAB_TRACKER_TAG: |
---|
489 | [fTrackers release]; |
---|
490 | fTrackers = nil; |
---|
491 | |
---|
492 | oldResizeSaveKey = @"InspectorContentHeightTracker"; |
---|
493 | break; |
---|
494 | |
---|
495 | case TAB_PEERS_TAG: |
---|
496 | //if in the middle of animating, just stop and resize immediately |
---|
497 | if (fWebSeedTableAnimation) |
---|
498 | [self setWebSeedTableHidden: !fWebSeeds animate: NO]; |
---|
499 | |
---|
500 | [fPeers release]; |
---|
501 | fPeers = nil; |
---|
502 | [fWebSeeds release]; |
---|
503 | fWebSeeds = nil; |
---|
504 | |
---|
505 | oldResizeSaveKey = @"InspectorContentHeightPeers"; |
---|
506 | break; |
---|
507 | |
---|
508 | case TAB_FILES_TAG: |
---|
509 | oldResizeSaveKey = @"InspectorContentHeightFiles"; |
---|
510 | break; |
---|
511 | } |
---|
512 | |
---|
513 | NSView * oldView = [self tabViewForTag: oldTabTag]; |
---|
514 | oldHeight = [oldView frame].size.height; |
---|
515 | if (oldResizeSaveKey) |
---|
516 | [[NSUserDefaults standardUserDefaults] setFloat: oldHeight forKey: oldResizeSaveKey]; |
---|
517 | |
---|
518 | //remove old view |
---|
519 | [oldView setHidden: YES]; |
---|
520 | [oldView removeFromSuperview]; |
---|
521 | } |
---|
522 | |
---|
523 | //set new tab item |
---|
524 | NSView * view = [self tabViewForTag: fCurrentTabTag]; |
---|
525 | |
---|
526 | NSString * resizeSaveKey = nil; |
---|
527 | NSString * identifier, * title; |
---|
528 | switch (fCurrentTabTag) |
---|
529 | { |
---|
530 | case TAB_INFO_TAG: |
---|
531 | identifier = TAB_INFO_IDENT; |
---|
532 | title = NSLocalizedString(@"General Info", "Inspector -> title"); |
---|
533 | break; |
---|
534 | case TAB_ACTIVITY_TAG: |
---|
535 | identifier = TAB_ACTIVITY_IDENT; |
---|
536 | title = NSLocalizedString(@"Activity", "Inspector -> title"); |
---|
537 | break; |
---|
538 | case TAB_TRACKER_TAG: |
---|
539 | identifier = TAB_TRACKER_IDENT; |
---|
540 | title = NSLocalizedString(@"Trackers", "Inspector -> title"); |
---|
541 | resizeSaveKey = @"InspectorContentHeightTracker"; |
---|
542 | break; |
---|
543 | case TAB_PEERS_TAG: |
---|
544 | identifier = TAB_PEERS_IDENT; |
---|
545 | title = NSLocalizedString(@"Peers", "Inspector -> title"); |
---|
546 | resizeSaveKey = @"InspectorContentHeightPeers"; |
---|
547 | break; |
---|
548 | case TAB_FILES_TAG: |
---|
549 | identifier = TAB_FILES_IDENT; |
---|
550 | title = NSLocalizedString(@"Files", "Inspector -> title"); |
---|
551 | resizeSaveKey = @"InspectorContentHeightFiles"; |
---|
552 | break; |
---|
553 | case TAB_OPTIONS_TAG: |
---|
554 | identifier = TAB_OPTIONS_IDENT; |
---|
555 | title = NSLocalizedString(@"Options", "Inspector -> title"); |
---|
556 | break; |
---|
557 | default: |
---|
558 | NSAssert1(NO, @"Unknown info tab selected: %d", fCurrentTabTag); |
---|
559 | return; |
---|
560 | } |
---|
561 | |
---|
562 | [[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"]; |
---|
563 | |
---|
564 | NSWindow * window = [self window]; |
---|
565 | |
---|
566 | [window setTitle: [NSString stringWithFormat: @"%@ - %@", title, NSLocalizedString(@"Torrent Inspector", "Inspector -> title")]]; |
---|
567 | |
---|
568 | //selected tab item |
---|
569 | [(InfoTabButtonCell *)[fTabMatrix selectedCell] setSelectedTab: YES]; |
---|
570 | |
---|
571 | NSRect windowRect = [window frame], viewRect = [view frame]; |
---|
572 | |
---|
573 | if (resizeSaveKey) |
---|
574 | { |
---|
575 | CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: resizeSaveKey]; |
---|
576 | if (height != 0.0) |
---|
577 | viewRect.size.height = MAX(height, TAB_MIN_HEIGHT); |
---|
578 | } |
---|
579 | |
---|
580 | CGFloat difference = (viewRect.size.height - oldHeight) * [window userSpaceScaleFactor]; |
---|
581 | windowRect.origin.y -= difference; |
---|
582 | windowRect.size.height += difference; |
---|
583 | |
---|
584 | if (resizeSaveKey) |
---|
585 | { |
---|
586 | if (!oldResizeSaveKey) |
---|
587 | { |
---|
588 | [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height - viewRect.size.height + TAB_MIN_HEIGHT)]; |
---|
589 | [window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)]; |
---|
590 | } |
---|
591 | } |
---|
592 | else |
---|
593 | { |
---|
594 | [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height)]; |
---|
595 | [window setMaxSize: NSMakeSize(FLT_MAX, windowRect.size.height)]; |
---|
596 | } |
---|
597 | |
---|
598 | viewRect.size.width = windowRect.size.width; |
---|
599 | [view setFrame: viewRect]; |
---|
600 | |
---|
601 | [window setFrame: windowRect display: YES animate: oldTabTag != INVALID]; |
---|
602 | [[window contentView] addSubview: view]; |
---|
603 | [view setHidden: NO]; |
---|
604 | |
---|
605 | if ([NSApp isOnSnowLeopardOrBetter] && (fCurrentTabTag == TAB_FILES_TAG || oldTabTag == TAB_FILES_TAG) |
---|
606 | && ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible])) |
---|
607 | [[QLPreviewPanelSL sharedPreviewPanel] reloadData]; |
---|
608 | } |
---|
609 | |
---|
610 | - (void) setNextTab |
---|
611 | { |
---|
612 | NSInteger tag = [fTabMatrix selectedTag]+1; |
---|
613 | if (tag >= [fTabMatrix numberOfColumns]) |
---|
614 | tag = 0; |
---|
615 | |
---|
616 | [fTabMatrix selectCellWithTag: tag]; |
---|
617 | [self setTab: nil]; |
---|
618 | } |
---|
619 | |
---|
620 | - (void) setPreviousTab |
---|
621 | { |
---|
622 | NSInteger tag = [fTabMatrix selectedTag]-1; |
---|
623 | if (tag < 0) |
---|
624 | tag = [fTabMatrix numberOfColumns]-1; |
---|
625 | |
---|
626 | [fTabMatrix selectCellWithTag: tag]; |
---|
627 | [self setTab: nil]; |
---|
628 | } |
---|
629 | |
---|
630 | - (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView |
---|
631 | { |
---|
632 | if (tableView == fPeerTable) |
---|
633 | return fPeers ? [fPeers count] : 0; |
---|
634 | else if (tableView == fWebSeedTable) |
---|
635 | return fWebSeeds ? [fWebSeeds count] : 0; |
---|
636 | else if (tableView == fTrackerTable) |
---|
637 | return fTrackers ? [fTrackers count] : 0; |
---|
638 | return 0; |
---|
639 | } |
---|
640 | |
---|
641 | - (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (NSInteger) row |
---|
642 | { |
---|
643 | if (tableView == fPeerTable) |
---|
644 | { |
---|
645 | NSString * ident = [column identifier]; |
---|
646 | NSDictionary * peer = [fPeers objectAtIndex: row]; |
---|
647 | |
---|
648 | if ([ident isEqualToString: @"Encryption"]) |
---|
649 | return [[peer objectForKey: @"Encryption"] boolValue] ? [NSImage imageNamed: @"Lock.png"] : nil; |
---|
650 | else if ([ident isEqualToString: @"Client"]) |
---|
651 | return [peer objectForKey: @"Client"]; |
---|
652 | else if ([ident isEqualToString: @"Progress"]) |
---|
653 | return [peer objectForKey: @"Progress"]; |
---|
654 | else if ([ident isEqualToString: @"UL To"]) |
---|
655 | { |
---|
656 | NSNumber * rate; |
---|
657 | return (rate = [peer objectForKey: @"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @""; |
---|
658 | } |
---|
659 | else if ([ident isEqualToString: @"DL From"]) |
---|
660 | { |
---|
661 | NSNumber * rate; |
---|
662 | return (rate = [peer objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @""; |
---|
663 | } |
---|
664 | else |
---|
665 | return [peer objectForKey: @"IP"]; |
---|
666 | } |
---|
667 | else if (tableView == fWebSeedTable) |
---|
668 | { |
---|
669 | NSString * ident = [column identifier]; |
---|
670 | NSDictionary * webSeed = [fWebSeeds objectAtIndex: row]; |
---|
671 | |
---|
672 | if ([ident isEqualToString: @"DL From"]) |
---|
673 | { |
---|
674 | NSNumber * rate; |
---|
675 | return (rate = [webSeed objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @""; |
---|
676 | } |
---|
677 | else |
---|
678 | return [webSeed objectForKey: @"Address"]; |
---|
679 | } |
---|
680 | else if (tableView == fTrackerTable) |
---|
681 | { |
---|
682 | id item = [fTrackers objectAtIndex: row]; |
---|
683 | |
---|
684 | if (![item isKindOfClass: [TrackerNode class]]) |
---|
685 | { |
---|
686 | NSString * tierString = [NSString stringWithFormat: NSLocalizedString(@"Tier %d", "Inspector -> tracker table"), |
---|
687 | [[item objectForKey: @"Tier"] integerValue]]; |
---|
688 | if ([fTorrents count] > 1) |
---|
689 | tierString = [tierString stringByAppendingFormat: @" - %@", [item objectForKey: @"Name"]]; |
---|
690 | return tierString; |
---|
691 | } |
---|
692 | else |
---|
693 | return item; |
---|
694 | } |
---|
695 | return nil; |
---|
696 | } |
---|
697 | |
---|
698 | - (NSCell *) tableView: (NSTableView *) tableView dataCellForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row |
---|
699 | { |
---|
700 | if (tableView == fTrackerTable) |
---|
701 | { |
---|
702 | const BOOL tracker = [[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]]; |
---|
703 | return tracker ? fTrackerCell : [tableColumn dataCellForRow: row]; |
---|
704 | } |
---|
705 | |
---|
706 | return nil; |
---|
707 | } |
---|
708 | |
---|
709 | - (CGFloat) tableView: (NSTableView *) tableView heightOfRow: (NSInteger) row |
---|
710 | { |
---|
711 | if (tableView == fTrackerTable) |
---|
712 | { |
---|
713 | if (![[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]] && [tableView editedRow] != row) |
---|
714 | return TRACKER_GROUP_SEPARATOR_HEIGHT; |
---|
715 | } |
---|
716 | |
---|
717 | return [tableView rowHeight]; |
---|
718 | } |
---|
719 | |
---|
720 | - (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn |
---|
721 | row: (NSInteger) row |
---|
722 | { |
---|
723 | if (tableView == fPeerTable) |
---|
724 | { |
---|
725 | NSString * ident = [tableColumn identifier]; |
---|
726 | |
---|
727 | if ([ident isEqualToString: @"Progress"]) |
---|
728 | { |
---|
729 | NSDictionary * peer = [fPeers objectAtIndex: row]; |
---|
730 | [(PeerProgressIndicatorCell *)cell setSeed: [[peer objectForKey: @"Seed"] boolValue]]; |
---|
731 | } |
---|
732 | } |
---|
733 | } |
---|
734 | |
---|
735 | - (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn |
---|
736 | { |
---|
737 | if (tableView == fPeerTable) |
---|
738 | { |
---|
739 | if (fPeers) |
---|
740 | { |
---|
741 | [fPeers sortUsingDescriptors: [self peerSortDescriptors]]; |
---|
742 | [tableView reloadData]; |
---|
743 | } |
---|
744 | } |
---|
745 | else if (tableView == fWebSeedTable) |
---|
746 | { |
---|
747 | if (fWebSeeds) |
---|
748 | { |
---|
749 | [fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]]; |
---|
750 | [tableView reloadData]; |
---|
751 | } |
---|
752 | } |
---|
753 | else; |
---|
754 | } |
---|
755 | |
---|
756 | - (BOOL) tableView: (NSTableView *) tableView shouldSelectRow: (NSInteger) row |
---|
757 | { |
---|
758 | return tableView == fTrackerTable; |
---|
759 | } |
---|
760 | |
---|
761 | - (void) tableViewSelectionDidChange: (NSNotification *) notification |
---|
762 | { |
---|
763 | if ([notification object] == fTrackerTable) |
---|
764 | [fTrackerAddRemoveControl setEnabled: [fTorrents count] == 1 && [fTrackerTable numberOfSelectedRows] > 0 |
---|
765 | forSegment: TRACKER_REMOVE_TAG]; |
---|
766 | } |
---|
767 | |
---|
768 | - (BOOL) tableView: (NSTableView *) tableView isGroupRow: (NSInteger) row |
---|
769 | { |
---|
770 | if (tableView == fTrackerTable) |
---|
771 | return ![[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]] && [tableView editedRow] != row; |
---|
772 | return NO; |
---|
773 | } |
---|
774 | |
---|
775 | - (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect |
---|
776 | tableColumn: (NSTableColumn *) column row: (NSInteger) row mouseLocation: (NSPoint) mouseLocation |
---|
777 | { |
---|
778 | if (tableView == fPeerTable) |
---|
779 | { |
---|
780 | const BOOL multiple = [fTorrents count] > 1; |
---|
781 | |
---|
782 | NSDictionary * peer = [fPeers objectAtIndex: row]; |
---|
783 | NSMutableArray * components = [NSMutableArray arrayWithCapacity: multiple ? 6 : 5]; |
---|
784 | |
---|
785 | if (multiple) |
---|
786 | [components addObject: [peer objectForKey: @"Name"]]; |
---|
787 | |
---|
788 | const CGFloat progress = [[peer objectForKey: @"Progress"] floatValue]; |
---|
789 | NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%", |
---|
790 | "Inspector -> Peers tab -> table row tooltip"), progress * 100.0]; |
---|
791 | if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue]) |
---|
792 | progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed", |
---|
793 | "Inspector -> Peers tab -> table row tooltip")]; |
---|
794 | [components addObject: progressString]; |
---|
795 | |
---|
796 | if ([[peer objectForKey: @"Encryption"] boolValue]) |
---|
797 | [components addObject: NSLocalizedString(@"Encrypted Connection", "Inspector -> Peers tab -> table row tooltip")]; |
---|
798 | |
---|
799 | NSString * portString; |
---|
800 | NSInteger port; |
---|
801 | if ((port = [[peer objectForKey: @"Port"] intValue]) > 0) |
---|
802 | portString = [NSString stringWithFormat: @"%d", port]; |
---|
803 | else |
---|
804 | portString = NSLocalizedString(@"N/A", "Inspector -> Peers tab -> table row tooltip"); |
---|
805 | [components addObject: [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Port", |
---|
806 | "Inspector -> Peers tab -> table row tooltip"), portString]]; |
---|
807 | |
---|
808 | const NSInteger peerFrom = [[peer objectForKey: @"From"] integerValue]; |
---|
809 | switch (peerFrom) |
---|
810 | { |
---|
811 | case TR_PEER_FROM_TRACKER: |
---|
812 | [components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")]; |
---|
813 | break; |
---|
814 | case TR_PEER_FROM_INCOMING: |
---|
815 | [components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")]; |
---|
816 | break; |
---|
817 | case TR_PEER_FROM_RESUME: |
---|
818 | [components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")]; |
---|
819 | break; |
---|
820 | case TR_PEER_FROM_PEX: |
---|
821 | [components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")]; |
---|
822 | break; |
---|
823 | case TR_PEER_FROM_DHT: |
---|
824 | [components addObject: NSLocalizedString(@"From: distributed hash table", "Inspector -> Peers tab -> table row tooltip")]; |
---|
825 | break; |
---|
826 | case TR_PEER_FROM_LTEP: |
---|
827 | [components addObject: NSLocalizedString(@"From: libtorrent extension protocol handshake", |
---|
828 | "Inspector -> Peers tab -> table row tooltip")]; |
---|
829 | break; |
---|
830 | default: |
---|
831 | NSAssert1(NO, @"Peer from unknown source: %d", peerFrom); |
---|
832 | } |
---|
833 | |
---|
834 | //determing status strings from flags |
---|
835 | NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 6]; |
---|
836 | NSString * flags = [peer objectForKey: @"Flags"]; |
---|
837 | |
---|
838 | if ([flags rangeOfString: @"D"].location != NSNotFound) |
---|
839 | [statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)", |
---|
840 | "Inspector -> peer -> status")]; |
---|
841 | if ([flags rangeOfString: @"d"].location != NSNotFound) |
---|
842 | [statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)", |
---|
843 | "Inspector -> peer -> status")]; |
---|
844 | if ([flags rangeOfString: @"U"].location != NSNotFound) |
---|
845 | [statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)", |
---|
846 | "Inspector -> peer -> status")]; |
---|
847 | if ([flags rangeOfString: @"u"].location != NSNotFound) |
---|
848 | [statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)", |
---|
849 | "Inspector -> peer -> status")]; |
---|
850 | if ([flags rangeOfString: @"K"].location != NSNotFound) |
---|
851 | [statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested", |
---|
852 | "Inspector -> peer -> status")]; |
---|
853 | if ([flags rangeOfString: @"?"].location != NSNotFound) |
---|
854 | [statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested", |
---|
855 | "Inspector -> peer -> status")]; |
---|
856 | |
---|
857 | if ([statusArray count] > 0) |
---|
858 | { |
---|
859 | NSString * statusStrings = [statusArray componentsJoinedByString: @"\n\n"]; |
---|
860 | [components addObject: [@"\n" stringByAppendingString: statusStrings]]; |
---|
861 | } |
---|
862 | |
---|
863 | return [components componentsJoinedByString: @"\n"]; |
---|
864 | } |
---|
865 | else if (tableView == fTrackerTable) |
---|
866 | { |
---|
867 | id node = [fTrackers objectAtIndex: row]; |
---|
868 | if ([node isKindOfClass: [TrackerNode class]]) |
---|
869 | return [(TrackerNode *)node fullAnnounceAddress]; |
---|
870 | } |
---|
871 | else if (tableView == fWebSeedTable) |
---|
872 | { |
---|
873 | if ([fTorrents count] > 1) |
---|
874 | return [[fWebSeeds objectAtIndex: row] objectForKey: @"Name"]; |
---|
875 | } |
---|
876 | |
---|
877 | return nil; |
---|
878 | } |
---|
879 | |
---|
880 | - (void) tableView: (NSTableView *) tableView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn |
---|
881 | row: (NSInteger) row |
---|
882 | { |
---|
883 | if (tableView != fTrackerTable) |
---|
884 | return; |
---|
885 | |
---|
886 | Torrent * torrent= [fTorrents objectAtIndex: 0]; |
---|
887 | |
---|
888 | BOOL added = NO; |
---|
889 | for (NSString * tracker in [object componentsSeparatedByString: @"\n"]) |
---|
890 | if ([torrent addTrackerToNewTier: tracker]) |
---|
891 | added = YES; |
---|
892 | |
---|
893 | if (!added) |
---|
894 | NSBeep(); |
---|
895 | |
---|
896 | //reset table with either new or old value |
---|
897 | [fTrackers release]; |
---|
898 | fTrackers = [[torrent allTrackerStats] retain]; |
---|
899 | |
---|
900 | [fTrackerTable setTrackers: fTrackers]; |
---|
901 | [fTrackerTable reloadData]; |
---|
902 | [fTrackerTable deselectAll: self]; |
---|
903 | |
---|
904 | [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker |
---|
905 | } |
---|
906 | |
---|
907 | - (void) addRemoveTracker: (id) sender |
---|
908 | { |
---|
909 | //don't allow add/remove when currently adding - it leads to weird results |
---|
910 | if ([fTrackerTable editedRow] != -1) |
---|
911 | return; |
---|
912 | |
---|
913 | if ([[sender cell] tagForSegment: [sender selectedSegment]] == TRACKER_REMOVE_TAG) |
---|
914 | [self removeTrackers]; |
---|
915 | else |
---|
916 | [self addTrackers]; |
---|
917 | } |
---|
918 | |
---|
919 | - (NSArray *) quickLookURLs |
---|
920 | { |
---|
921 | FileOutlineView * fileOutlineView = [fFileController outlineView]; |
---|
922 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
923 | NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; |
---|
924 | NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]]; |
---|
925 | |
---|
926 | for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) |
---|
927 | { |
---|
928 | FileListNode * item = [fileOutlineView itemAtRow: i]; |
---|
929 | if ([self canQuickLookFile: item]) |
---|
930 | [urlArray addObject: [NSURL fileURLWithPath: [torrent fileLocation: item]]]; |
---|
931 | } |
---|
932 | |
---|
933 | return urlArray; |
---|
934 | } |
---|
935 | |
---|
936 | - (BOOL) canQuickLook |
---|
937 | { |
---|
938 | if (fCurrentTabTag != TAB_FILES_TAG || ![[self window] isVisible] || [fTorrents count] != 1 || ![NSApp isOnSnowLeopardOrBetter]) |
---|
939 | return NO; |
---|
940 | |
---|
941 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
942 | if (![torrent isFolder]) |
---|
943 | return NO; |
---|
944 | |
---|
945 | FileOutlineView * fileOutlineView = [fFileController outlineView]; |
---|
946 | NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; |
---|
947 | |
---|
948 | for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) |
---|
949 | if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]]) |
---|
950 | return YES; |
---|
951 | |
---|
952 | return NO; |
---|
953 | } |
---|
954 | |
---|
955 | #warning uncomment (in header too) |
---|
956 | - (NSRect) quickLookSourceFrameForPreviewItem: (id /*<QLPreviewItem>*/) item |
---|
957 | { |
---|
958 | FileOutlineView * fileOutlineView = [fFileController outlineView]; |
---|
959 | |
---|
960 | NSString * fullPath = [(NSURL *)item path]; |
---|
961 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
962 | NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]]; |
---|
963 | |
---|
964 | for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++) |
---|
965 | { |
---|
966 | FileListNode * rowItem = [fileOutlineView itemAtRow: row]; |
---|
967 | if ([[torrent fileLocation: rowItem] isEqualToString: fullPath]) |
---|
968 | { |
---|
969 | NSRect frame = [fileOutlineView iconRectForRow: row]; |
---|
970 | |
---|
971 | if (!NSIntersectsRect([fileOutlineView visibleRect], frame)) |
---|
972 | return NSZeroRect; |
---|
973 | |
---|
974 | frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil]; |
---|
975 | frame.origin = [[self window] convertBaseToScreen: frame.origin]; |
---|
976 | frame.origin.y -= frame.size.height; |
---|
977 | return frame; |
---|
978 | } |
---|
979 | } |
---|
980 | |
---|
981 | return NSZeroRect; |
---|
982 | } |
---|
983 | |
---|
984 | - (void) setPiecesView: (id) sender |
---|
985 | { |
---|
986 | [self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE]; |
---|
987 | } |
---|
988 | |
---|
989 | - (void) setPiecesViewForAvailable: (BOOL) available |
---|
990 | { |
---|
991 | [fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE]; |
---|
992 | [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS]; |
---|
993 | |
---|
994 | [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"]; |
---|
995 | [fPiecesView updateView]; |
---|
996 | } |
---|
997 | |
---|
998 | - (void) revealDataFile: (id) sender |
---|
999 | { |
---|
1000 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1001 | NSString * location = [torrent dataLocation]; |
---|
1002 | if (!location) |
---|
1003 | return; |
---|
1004 | |
---|
1005 | if ([NSApp isOnSnowLeopardOrBetter]) |
---|
1006 | { |
---|
1007 | NSURL * file = [NSURL fileURLWithPath: location]; |
---|
1008 | [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]]; |
---|
1009 | } |
---|
1010 | else |
---|
1011 | [[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil]; |
---|
1012 | } |
---|
1013 | |
---|
1014 | - (void) setFileFilterText: (id) sender |
---|
1015 | { |
---|
1016 | [fFileController setFilterText: [sender stringValue]]; |
---|
1017 | } |
---|
1018 | |
---|
1019 | - (void) setUseSpeedLimit: (id) sender |
---|
1020 | { |
---|
1021 | const BOOL upload = sender == fUploadLimitCheck; |
---|
1022 | |
---|
1023 | if ([sender state] == NSMixedState) |
---|
1024 | [sender setState: NSOnState]; |
---|
1025 | const BOOL limit = [sender state] == NSOnState; |
---|
1026 | |
---|
1027 | for (Torrent * torrent in fTorrents) |
---|
1028 | [torrent setUseSpeedLimit: limit upload: upload]; |
---|
1029 | |
---|
1030 | NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField; |
---|
1031 | [field setEnabled: limit]; |
---|
1032 | if (limit) |
---|
1033 | { |
---|
1034 | [field selectText: self]; |
---|
1035 | [[self window] makeKeyAndOrderFront: self]; |
---|
1036 | } |
---|
1037 | |
---|
1038 | NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel; |
---|
1039 | [label setEnabled: limit]; |
---|
1040 | } |
---|
1041 | |
---|
1042 | - (void) setUseGlobalSpeedLimit: (id) sender |
---|
1043 | { |
---|
1044 | if ([sender state] == NSMixedState) |
---|
1045 | [sender setState: NSOnState]; |
---|
1046 | const BOOL limit = [sender state] == NSOnState; |
---|
1047 | |
---|
1048 | for (Torrent * torrent in fTorrents) |
---|
1049 | [torrent setUseGlobalSpeedLimit: limit]; |
---|
1050 | } |
---|
1051 | |
---|
1052 | - (void) setSpeedLimit: (id) sender |
---|
1053 | { |
---|
1054 | const BOOL upload = sender == fUploadLimitField; |
---|
1055 | const NSInteger limit = [sender intValue]; |
---|
1056 | |
---|
1057 | for (Torrent * torrent in fTorrents) |
---|
1058 | [torrent setSpeedLimit: limit upload: upload]; |
---|
1059 | } |
---|
1060 | |
---|
1061 | - (void) setRatioSetting: (id) sender |
---|
1062 | { |
---|
1063 | NSInteger setting; |
---|
1064 | bool single = NO; |
---|
1065 | switch ([sender indexOfSelectedItem]) |
---|
1066 | { |
---|
1067 | case OPTION_POPUP_LIMIT: |
---|
1068 | setting = TR_RATIOLIMIT_SINGLE; |
---|
1069 | single = YES; |
---|
1070 | break; |
---|
1071 | case OPTION_POPUP_NO_LIMIT: |
---|
1072 | setting = TR_RATIOLIMIT_UNLIMITED; |
---|
1073 | break; |
---|
1074 | case OPTION_POPUP_GLOBAL: |
---|
1075 | setting = TR_RATIOLIMIT_GLOBAL; |
---|
1076 | break; |
---|
1077 | default: |
---|
1078 | NSAssert1(NO, @"Unknown option selected in ratio popup: %d", [sender indexOfSelectedItem]); |
---|
1079 | return; |
---|
1080 | } |
---|
1081 | |
---|
1082 | for (Torrent * torrent in fTorrents) |
---|
1083 | [torrent setRatioSetting: setting]; |
---|
1084 | |
---|
1085 | [fRatioLimitField setHidden: !single]; |
---|
1086 | if (single) |
---|
1087 | { |
---|
1088 | [fRatioLimitField selectText: self]; |
---|
1089 | [[self window] makeKeyAndOrderFront: self]; |
---|
1090 | } |
---|
1091 | } |
---|
1092 | |
---|
1093 | - (void) setRatioLimit: (id) sender |
---|
1094 | { |
---|
1095 | CGFloat limit = [sender floatValue]; |
---|
1096 | |
---|
1097 | for (Torrent * torrent in fTorrents) |
---|
1098 | [torrent setRatioLimit: limit]; |
---|
1099 | } |
---|
1100 | |
---|
1101 | - (void) setPriority: (id) sender |
---|
1102 | { |
---|
1103 | tr_priority_t priority; |
---|
1104 | switch ([sender indexOfSelectedItem]) |
---|
1105 | { |
---|
1106 | case OPTION_POPUP_PRIORITY_HIGH: |
---|
1107 | priority = TR_PRI_HIGH; |
---|
1108 | break; |
---|
1109 | case OPTION_POPUP_PRIORITY_NORMAL: |
---|
1110 | priority = TR_PRI_NORMAL; |
---|
1111 | break; |
---|
1112 | case OPTION_POPUP_PRIORITY_LOW: |
---|
1113 | priority = TR_PRI_LOW; |
---|
1114 | break; |
---|
1115 | default: |
---|
1116 | NSAssert1(NO, @"Unknown option selected in priority popup: %d", [sender indexOfSelectedItem]); |
---|
1117 | return; |
---|
1118 | } |
---|
1119 | |
---|
1120 | for (Torrent * torrent in fTorrents) |
---|
1121 | [torrent setPriority: priority]; |
---|
1122 | |
---|
1123 | [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; |
---|
1124 | } |
---|
1125 | |
---|
1126 | - (void) setPeersConnectLimit: (id) sender |
---|
1127 | { |
---|
1128 | NSInteger limit = [sender intValue]; |
---|
1129 | |
---|
1130 | for (Torrent * torrent in fTorrents) |
---|
1131 | [torrent setMaxPeerConnect: limit]; |
---|
1132 | } |
---|
1133 | |
---|
1134 | - (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor |
---|
1135 | { |
---|
1136 | [fInitialString release]; |
---|
1137 | fInitialString = [[control stringValue] retain]; |
---|
1138 | |
---|
1139 | return YES; |
---|
1140 | } |
---|
1141 | |
---|
1142 | - (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error |
---|
1143 | { |
---|
1144 | NSBeep(); |
---|
1145 | if (fInitialString) |
---|
1146 | { |
---|
1147 | [control setStringValue: fInitialString]; |
---|
1148 | [fInitialString release]; |
---|
1149 | fInitialString = nil; |
---|
1150 | } |
---|
1151 | return NO; |
---|
1152 | } |
---|
1153 | |
---|
1154 | @end |
---|
1155 | |
---|
1156 | @implementation InfoWindowController (Private) |
---|
1157 | |
---|
1158 | - (void) resetInfo |
---|
1159 | { |
---|
1160 | const NSUInteger numberSelected = [fTorrents count]; |
---|
1161 | if (numberSelected != 1) |
---|
1162 | { |
---|
1163 | if (numberSelected > 0) |
---|
1164 | { |
---|
1165 | [fImageView setImage: [NSImage imageNamed: NSImageNameMultipleDocuments]]; |
---|
1166 | |
---|
1167 | [fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d Torrents Selected", |
---|
1168 | "Inspector -> selected torrents"), numberSelected]]; |
---|
1169 | |
---|
1170 | uint64_t size = 0; |
---|
1171 | NSUInteger fileCount = 0, magnetCount = 0; |
---|
1172 | for (Torrent * torrent in fTorrents) |
---|
1173 | { |
---|
1174 | size += [torrent size]; |
---|
1175 | fileCount += [torrent fileCount]; |
---|
1176 | if ([torrent isMagnet]) |
---|
1177 | ++magnetCount; |
---|
1178 | } |
---|
1179 | |
---|
1180 | NSMutableArray * fileStrings = [NSMutableArray arrayWithCapacity: 2]; |
---|
1181 | if (fileCount > 0) |
---|
1182 | { |
---|
1183 | NSString * fileString; |
---|
1184 | if (fileCount == 1) |
---|
1185 | fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents"); |
---|
1186 | else |
---|
1187 | fileString = [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount]; |
---|
1188 | [fileStrings addObject: fileString]; |
---|
1189 | } |
---|
1190 | if (magnetCount > 0) |
---|
1191 | { |
---|
1192 | NSString * magnetString; |
---|
1193 | if (magnetCount == 1) |
---|
1194 | magnetString = NSLocalizedString(@"1 magnetized transfer", "Inspector -> selected torrents"); |
---|
1195 | else |
---|
1196 | magnetString = [NSString stringWithFormat: NSLocalizedString(@"%d magnetized transfers", |
---|
1197 | "Inspector -> selected torrents"), magnetCount]; |
---|
1198 | [fileStrings addObject: magnetString]; |
---|
1199 | } |
---|
1200 | |
---|
1201 | NSString * fileString = [fileStrings componentsJoinedByString: @" + "]; |
---|
1202 | |
---|
1203 | if (magnetCount < numberSelected) |
---|
1204 | { |
---|
1205 | [fBasicInfoField setStringValue: [NSString stringWithFormat: @"%@, %@", fileString, |
---|
1206 | [NSString stringWithFormat: NSLocalizedString(@"%@ total", "Inspector -> selected torrents"), |
---|
1207 | [NSString stringForFileSize: size]]]]; |
---|
1208 | [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"), |
---|
1209 | size]]; |
---|
1210 | } |
---|
1211 | else |
---|
1212 | { |
---|
1213 | [fBasicInfoField setStringValue: fileString]; |
---|
1214 | [fBasicInfoField setToolTip: nil]; |
---|
1215 | } |
---|
1216 | } |
---|
1217 | else |
---|
1218 | { |
---|
1219 | [fImageView setImage: [NSImage imageNamed: @"NSApplicationIcon"]]; |
---|
1220 | |
---|
1221 | [fNameField setStringValue: NSLocalizedString(@"No Torrents Selected", "Inspector -> selected torrents")]; |
---|
1222 | [fBasicInfoField setStringValue: @""]; |
---|
1223 | [fBasicInfoField setToolTip: @""]; |
---|
1224 | |
---|
1225 | [fHaveField setStringValue: @""]; |
---|
1226 | [fDownloadedTotalField setStringValue: @""]; |
---|
1227 | [fUploadedTotalField setStringValue: @""]; |
---|
1228 | [fFailedHashField setStringValue: @""]; |
---|
1229 | [fDateActivityField setStringValue: @""]; |
---|
1230 | [fRatioField setStringValue: @""]; |
---|
1231 | |
---|
1232 | //options fields |
---|
1233 | [fUploadLimitCheck setEnabled: NO]; |
---|
1234 | [fUploadLimitCheck setState: NSOffState]; |
---|
1235 | [fUploadLimitField setEnabled: NO]; |
---|
1236 | [fUploadLimitLabel setEnabled: NO]; |
---|
1237 | [fUploadLimitField setStringValue: @""]; |
---|
1238 | |
---|
1239 | [fDownloadLimitCheck setEnabled: NO]; |
---|
1240 | [fDownloadLimitCheck setState: NSOffState]; |
---|
1241 | [fDownloadLimitField setEnabled: NO]; |
---|
1242 | [fDownloadLimitLabel setEnabled: NO]; |
---|
1243 | [fDownloadLimitField setStringValue: @""]; |
---|
1244 | |
---|
1245 | [fGlobalLimitCheck setEnabled: NO]; |
---|
1246 | [fGlobalLimitCheck setState: NSOffState]; |
---|
1247 | |
---|
1248 | [fPriorityPopUp setEnabled: NO]; |
---|
1249 | [fPriorityPopUp selectItemAtIndex: -1]; |
---|
1250 | |
---|
1251 | [fRatioPopUp setEnabled: NO]; |
---|
1252 | [fRatioPopUp selectItemAtIndex: -1]; |
---|
1253 | [fRatioLimitField setHidden: YES]; |
---|
1254 | [fRatioLimitField setStringValue: @""]; |
---|
1255 | |
---|
1256 | [fPeersConnectField setEnabled: NO]; |
---|
1257 | [fPeersConnectField setStringValue: @""]; |
---|
1258 | [fPeersConnectLabel setEnabled: NO]; |
---|
1259 | |
---|
1260 | [fPeers release]; |
---|
1261 | fPeers = nil; |
---|
1262 | [fPeerTable reloadData]; |
---|
1263 | |
---|
1264 | [fTrackers release]; |
---|
1265 | fTrackers = nil; |
---|
1266 | |
---|
1267 | [fTrackerTable setTrackers: nil]; |
---|
1268 | [fTrackerTable reloadData]; |
---|
1269 | } |
---|
1270 | |
---|
1271 | [fFileController setTorrent: nil]; |
---|
1272 | |
---|
1273 | [fNameField setToolTip: nil]; |
---|
1274 | |
---|
1275 | [fPiecesField setStringValue: @""]; |
---|
1276 | [fHashField setStringValue: @""]; |
---|
1277 | [fHashField setToolTip: nil]; |
---|
1278 | [fSecureField setStringValue: @""]; |
---|
1279 | [fCommentView setString: @""]; |
---|
1280 | |
---|
1281 | [fCreatorField setStringValue: @""]; |
---|
1282 | [fDateCreatedField setStringValue: @""]; |
---|
1283 | |
---|
1284 | [fDataLocationField setStringValue: @""]; |
---|
1285 | [fDataLocationField setToolTip: nil]; |
---|
1286 | |
---|
1287 | [fRevealDataButton setHidden: YES]; |
---|
1288 | |
---|
1289 | [fStateField setStringValue: @""]; |
---|
1290 | [fProgressField setStringValue: @""]; |
---|
1291 | |
---|
1292 | [fErrorMessageView setString: @""]; |
---|
1293 | |
---|
1294 | [fConnectedPeersField setStringValue: @""]; |
---|
1295 | |
---|
1296 | [fDateAddedField setStringValue: @""]; |
---|
1297 | [fDateCompletedField setStringValue: @""]; |
---|
1298 | |
---|
1299 | [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE]; |
---|
1300 | [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS]; |
---|
1301 | [fPiecesControl setEnabled: NO]; |
---|
1302 | [fPiecesView setTorrent: nil]; |
---|
1303 | |
---|
1304 | [fTrackerTable setTorrent: nil]; |
---|
1305 | |
---|
1306 | [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_ADD_TAG]; |
---|
1307 | [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG]; |
---|
1308 | |
---|
1309 | [fFileFilterField setEnabled: NO]; |
---|
1310 | } |
---|
1311 | else |
---|
1312 | { |
---|
1313 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1314 | |
---|
1315 | [fFileController setTorrent: torrent]; |
---|
1316 | |
---|
1317 | if ([NSApp isOnSnowLeopardOrBetter]) |
---|
1318 | [fImageView setImage: [torrent icon]]; |
---|
1319 | else |
---|
1320 | { |
---|
1321 | NSImage * icon = [[torrent icon] copy]; |
---|
1322 | [icon setFlipped: NO]; |
---|
1323 | [fImageView setImage: icon]; |
---|
1324 | [icon release]; |
---|
1325 | } |
---|
1326 | |
---|
1327 | NSString * name = [torrent name]; |
---|
1328 | [fNameField setStringValue: name]; |
---|
1329 | [fNameField setToolTip: name]; |
---|
1330 | |
---|
1331 | if (![torrent isMagnet]) |
---|
1332 | { |
---|
1333 | NSString * basicString = [NSString stringForFileSize: [torrent size]]; |
---|
1334 | if ([torrent isFolder]) |
---|
1335 | { |
---|
1336 | NSString * fileString; |
---|
1337 | NSInteger fileCount = [torrent fileCount]; |
---|
1338 | if (fileCount == 1) |
---|
1339 | fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents"); |
---|
1340 | else |
---|
1341 | fileString= [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount]; |
---|
1342 | basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString]; |
---|
1343 | } |
---|
1344 | [fBasicInfoField setStringValue: basicString]; |
---|
1345 | [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"), |
---|
1346 | [torrent size]]]; |
---|
1347 | } |
---|
1348 | else |
---|
1349 | { |
---|
1350 | [fBasicInfoField setStringValue: NSLocalizedString(@"Magnetized transfer", "Inspector -> selected torrents")]; |
---|
1351 | [fBasicInfoField setToolTip: nil]; |
---|
1352 | } |
---|
1353 | |
---|
1354 | NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%d, %@", [torrent pieceCount], |
---|
1355 | [NSString stringForFileSize: [torrent pieceSize]]] : @""; |
---|
1356 | [fPiecesField setStringValue: piecesString]; |
---|
1357 | |
---|
1358 | NSString * hashString = [torrent hashString]; |
---|
1359 | [fHashField setStringValue: hashString]; |
---|
1360 | [fHashField setToolTip: hashString]; |
---|
1361 | [fSecureField setStringValue: [torrent privateTorrent] |
---|
1362 | ? NSLocalizedString(@"Private Torrent, PEX and DHT automatically disabled", "Inspector -> private torrent") |
---|
1363 | : NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")]; |
---|
1364 | |
---|
1365 | NSString * commentString = [torrent comment]; |
---|
1366 | [fCommentView setString: commentString]; |
---|
1367 | |
---|
1368 | NSString * creatorString = [torrent creator]; |
---|
1369 | [fCreatorField setStringValue: creatorString]; |
---|
1370 | [fDateCreatedField setObjectValue: [torrent dateCreated]]; |
---|
1371 | |
---|
1372 | [fDateAddedField setObjectValue: [torrent dateAdded]]; |
---|
1373 | |
---|
1374 | //set pieces view |
---|
1375 | BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"]; |
---|
1376 | [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE]; |
---|
1377 | [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS]; |
---|
1378 | [fPiecesControl setEnabled: YES]; |
---|
1379 | [fPiecesView setTorrent: torrent]; |
---|
1380 | |
---|
1381 | [fTrackerTable setTorrent: torrent]; |
---|
1382 | [fTrackerTable deselectAll: self]; |
---|
1383 | [fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG]; |
---|
1384 | [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG]; |
---|
1385 | |
---|
1386 | [fFileFilterField setEnabled: [torrent isFolder]]; |
---|
1387 | } |
---|
1388 | |
---|
1389 | [fFileFilterField setStringValue: @""]; |
---|
1390 | |
---|
1391 | //reset webseeds here, since it might be hidden regardless of number selected |
---|
1392 | BOOL hasWebSeeds = NO; |
---|
1393 | for (Torrent * torrent in fTorrents) |
---|
1394 | { |
---|
1395 | if ([torrent webSeedCount] > 0) |
---|
1396 | { |
---|
1397 | hasWebSeeds = YES; |
---|
1398 | break; |
---|
1399 | } |
---|
1400 | } |
---|
1401 | |
---|
1402 | if (!hasWebSeeds) |
---|
1403 | { |
---|
1404 | [fWebSeeds release]; |
---|
1405 | fWebSeeds = nil; |
---|
1406 | [fWebSeedTable reloadData]; |
---|
1407 | } |
---|
1408 | [self setWebSeedTableHidden: !hasWebSeeds animate: YES]; |
---|
1409 | |
---|
1410 | //update stats and settings |
---|
1411 | [self updateInfoStats]; |
---|
1412 | [self updateOptions]; |
---|
1413 | } |
---|
1414 | |
---|
1415 | - (void) resetInfoForTorrent: (NSNotification *) notification |
---|
1416 | { |
---|
1417 | if (fTorrents && [fTorrents containsObject: [notification object]]) |
---|
1418 | [self resetInfo]; |
---|
1419 | } |
---|
1420 | |
---|
1421 | - (void) updateInfoGeneral |
---|
1422 | { |
---|
1423 | if ([fTorrents count] != 1) |
---|
1424 | return; |
---|
1425 | |
---|
1426 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1427 | |
---|
1428 | NSString * location = [torrent dataLocation]; |
---|
1429 | [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""]; |
---|
1430 | [fDataLocationField setToolTip: location ? location : @""]; |
---|
1431 | |
---|
1432 | [fRevealDataButton setHidden: !location]; |
---|
1433 | } |
---|
1434 | |
---|
1435 | - (void) updateInfoActivity |
---|
1436 | { |
---|
1437 | NSInteger numberSelected = [fTorrents count]; |
---|
1438 | if (numberSelected == 0) |
---|
1439 | return; |
---|
1440 | |
---|
1441 | uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0; |
---|
1442 | NSDate * lastActivity = nil; |
---|
1443 | for (Torrent * torrent in fTorrents) |
---|
1444 | { |
---|
1445 | have += [torrent haveTotal]; |
---|
1446 | haveVerified += [torrent haveVerified]; |
---|
1447 | downloadedTotal += [torrent downloadedTotal]; |
---|
1448 | uploadedTotal += [torrent uploadedTotal]; |
---|
1449 | failedHash += [torrent failedHash]; |
---|
1450 | |
---|
1451 | NSDate * nextLastActivity; |
---|
1452 | if ((nextLastActivity = [torrent dateActivity])) |
---|
1453 | lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity; |
---|
1454 | } |
---|
1455 | |
---|
1456 | if (have == 0) |
---|
1457 | [fHaveField setStringValue: [NSString stringForFileSize: 0]]; |
---|
1458 | else |
---|
1459 | { |
---|
1460 | NSString * verifiedString = [NSString stringWithFormat: NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"), |
---|
1461 | [NSString stringForFileSize: haveVerified]]; |
---|
1462 | if (have == haveVerified) |
---|
1463 | [fHaveField setStringValue: verifiedString]; |
---|
1464 | else |
---|
1465 | [fHaveField setStringValue: [NSString stringWithFormat: @"%@ (%@)", [NSString stringForFileSize: have], verifiedString]]; |
---|
1466 | } |
---|
1467 | |
---|
1468 | [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]]; |
---|
1469 | [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]]; |
---|
1470 | [fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]]; |
---|
1471 | |
---|
1472 | [fDateActivityField setObjectValue: lastActivity]; |
---|
1473 | |
---|
1474 | if (numberSelected == 1) |
---|
1475 | { |
---|
1476 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1477 | |
---|
1478 | [fStateField setStringValue: [torrent stateString]]; |
---|
1479 | |
---|
1480 | if ([torrent isFolder]) |
---|
1481 | [fProgressField setStringValue: [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)", |
---|
1482 | "Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]]; |
---|
1483 | else |
---|
1484 | [fProgressField setStringValue: [NSString localizedStringWithFormat: @"%.2f%%", 100.0 * [torrent progress]]]; |
---|
1485 | |
---|
1486 | [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]]; |
---|
1487 | |
---|
1488 | NSString * errorMessage = [torrent errorMessage]; |
---|
1489 | if (![errorMessage isEqualToString: [fErrorMessageView string]]) |
---|
1490 | [fErrorMessageView setString: errorMessage]; |
---|
1491 | |
---|
1492 | [fDateCompletedField setObjectValue: [torrent dateCompleted]]; |
---|
1493 | |
---|
1494 | [fPiecesView updateView]; |
---|
1495 | } |
---|
1496 | else if (numberSelected > 1) |
---|
1497 | { |
---|
1498 | [fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]]; |
---|
1499 | } |
---|
1500 | else; |
---|
1501 | } |
---|
1502 | |
---|
1503 | - (void) updateInfoTracker |
---|
1504 | { |
---|
1505 | if ([fTorrents count] == 0) |
---|
1506 | return; |
---|
1507 | |
---|
1508 | //get updated tracker stats |
---|
1509 | if ([fTrackerTable editedRow] == -1) |
---|
1510 | { |
---|
1511 | [fTrackers release]; |
---|
1512 | |
---|
1513 | if ([fTorrents count] == 1) |
---|
1514 | fTrackers = [[[fTorrents objectAtIndex: 0] allTrackerStats] retain]; |
---|
1515 | else |
---|
1516 | { |
---|
1517 | fTrackers = [[NSMutableArray alloc] init]; |
---|
1518 | for (Torrent * torrent in fTorrents) |
---|
1519 | [fTrackers addObjectsFromArray: [torrent allTrackerStats]]; |
---|
1520 | } |
---|
1521 | |
---|
1522 | [fTrackerTable setTrackers: fTrackers]; |
---|
1523 | [fTrackerTable reloadData]; |
---|
1524 | } |
---|
1525 | else |
---|
1526 | { |
---|
1527 | NSAssert1([fTorrents count] == 1, @"Attempting to add tracker with %d transfers selected", [fTorrents count]); |
---|
1528 | |
---|
1529 | if ([NSApp isOnSnowLeopardOrBetter]) |
---|
1530 | { |
---|
1531 | NSIndexSet * addedIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange([fTrackers count]-2, 2)]; |
---|
1532 | NSArray * tierAndTrackerBeingAdded = [fTrackers objectsAtIndexes: addedIndexes]; |
---|
1533 | |
---|
1534 | [fTrackers release]; |
---|
1535 | fTrackers = [[[fTorrents objectAtIndex: 0] allTrackerStats] retain]; |
---|
1536 | [fTrackers addObjectsFromArray: tierAndTrackerBeingAdded]; |
---|
1537 | |
---|
1538 | [fTrackerTable setTrackers: fTrackers]; |
---|
1539 | |
---|
1540 | NSIndexSet * updateIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTrackers count]-2)], |
---|
1541 | * columnIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [[fTrackerTable tableColumns] count])]; |
---|
1542 | [fTrackerTable reloadDataForRowIndexes: updateIndexes columnIndexes: columnIndexes]; |
---|
1543 | } |
---|
1544 | } |
---|
1545 | } |
---|
1546 | |
---|
1547 | - (void) updateInfoPeers |
---|
1548 | { |
---|
1549 | if ([fTorrents count] == 0) |
---|
1550 | return; |
---|
1551 | |
---|
1552 | if (!fPeers) |
---|
1553 | fPeers = [[NSMutableArray alloc] init]; |
---|
1554 | else |
---|
1555 | [fPeers removeAllObjects]; |
---|
1556 | |
---|
1557 | NSUInteger known = 0, connected = 0, tracker = 0, incoming = 0, cache = 0, pex = 0, dht = 0, ltep = 0, |
---|
1558 | toUs = 0, fromUs = 0; |
---|
1559 | BOOL anyActive = false; |
---|
1560 | for (Torrent * torrent in fTorrents) |
---|
1561 | { |
---|
1562 | [fPeers addObjectsFromArray: [torrent peers]]; |
---|
1563 | |
---|
1564 | known += [torrent totalPeersKnown]; |
---|
1565 | |
---|
1566 | if ([torrent isActive]) |
---|
1567 | { |
---|
1568 | anyActive = YES; |
---|
1569 | const NSUInteger connectedThis = [torrent totalPeersConnected]; |
---|
1570 | if (connectedThis > 0) |
---|
1571 | { |
---|
1572 | connected += [torrent totalPeersConnected]; |
---|
1573 | tracker += [torrent totalPeersTracker]; |
---|
1574 | incoming += [torrent totalPeersIncoming]; |
---|
1575 | cache += [torrent totalPeersCache]; |
---|
1576 | pex += [torrent totalPeersPex]; |
---|
1577 | dht += [torrent totalPeersDHT]; |
---|
1578 | ltep += [torrent totalPeersLTEP]; |
---|
1579 | |
---|
1580 | toUs += [torrent peersSendingToUs]; |
---|
1581 | fromUs += [torrent peersGettingFromUs]; |
---|
1582 | } |
---|
1583 | } |
---|
1584 | } |
---|
1585 | |
---|
1586 | NSString * knownString = [NSString stringWithFormat: NSLocalizedString(@"%d known", "Inspector -> Peers tab -> peers"), known]; |
---|
1587 | if (anyActive) |
---|
1588 | { |
---|
1589 | NSString * connectedText = [NSString stringWithFormat: NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"), |
---|
1590 | connected]; |
---|
1591 | |
---|
1592 | if (connected > 0) |
---|
1593 | { |
---|
1594 | NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 6]; |
---|
1595 | if (tracker > 0) |
---|
1596 | [fromComponents addObject: [NSString stringWithFormat: |
---|
1597 | NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]]; |
---|
1598 | if (incoming > 0) |
---|
1599 | [fromComponents addObject: [NSString stringWithFormat: |
---|
1600 | NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), incoming]]; |
---|
1601 | if (cache > 0) |
---|
1602 | [fromComponents addObject: [NSString stringWithFormat: |
---|
1603 | NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), cache]]; |
---|
1604 | if (pex > 0) |
---|
1605 | [fromComponents addObject: [NSString stringWithFormat: |
---|
1606 | NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), pex]]; |
---|
1607 | if (dht > 0) |
---|
1608 | [fromComponents addObject: [NSString stringWithFormat: |
---|
1609 | NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), dht]]; |
---|
1610 | if (ltep > 0) |
---|
1611 | [fromComponents addObject: [NSString stringWithFormat: |
---|
1612 | NSLocalizedString(@"%d LTEP", "Inspector -> Peers tab -> peers"), ltep]]; |
---|
1613 | |
---|
1614 | NSMutableArray * upDownComponents = [NSMutableArray arrayWithCapacity: 3]; |
---|
1615 | if (toUs > 0) |
---|
1616 | [upDownComponents addObject: [NSString stringWithFormat: |
---|
1617 | NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), toUs]]; |
---|
1618 | if (fromUs > 0) |
---|
1619 | [upDownComponents addObject: [NSString stringWithFormat: |
---|
1620 | NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), fromUs]]; |
---|
1621 | [upDownComponents addObject: knownString]; |
---|
1622 | |
---|
1623 | connectedText = [connectedText stringByAppendingFormat: @": %@\n%@", [fromComponents componentsJoinedByString: @", "], |
---|
1624 | [upDownComponents componentsJoinedByString: @", "]]; |
---|
1625 | } |
---|
1626 | else |
---|
1627 | connectedText = [connectedText stringByAppendingFormat: @"\n%@", knownString]; |
---|
1628 | |
---|
1629 | [fConnectedPeersField setStringValue: connectedText]; |
---|
1630 | } |
---|
1631 | else |
---|
1632 | { |
---|
1633 | NSString * activeString; |
---|
1634 | if ([fTorrents count] == 1) |
---|
1635 | activeString = NSLocalizedString(@"Transfer Not Active", "Inspector -> Peers tab -> peers"); |
---|
1636 | else |
---|
1637 | activeString = NSLocalizedString(@"Transfers Not Active", "Inspector -> Peers tab -> peers"); |
---|
1638 | |
---|
1639 | NSString * connectedText = [NSString stringWithFormat: @"%@\n%@", activeString, knownString]; |
---|
1640 | [fConnectedPeersField setStringValue: connectedText]; |
---|
1641 | } |
---|
1642 | |
---|
1643 | [fPeers sortUsingDescriptors: [self peerSortDescriptors]]; |
---|
1644 | [fPeerTable reloadData]; |
---|
1645 | |
---|
1646 | if (!fWebSeeds) |
---|
1647 | fWebSeeds = [[NSMutableArray alloc] init]; |
---|
1648 | else |
---|
1649 | [fWebSeeds removeAllObjects]; |
---|
1650 | |
---|
1651 | for (Torrent * torrent in fTorrents) |
---|
1652 | [fWebSeeds addObjectsFromArray: [torrent webSeeds]]; |
---|
1653 | |
---|
1654 | [fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]]; |
---|
1655 | [fWebSeedTable reloadData]; |
---|
1656 | } |
---|
1657 | |
---|
1658 | - (void) updateInfoFiles |
---|
1659 | { |
---|
1660 | if ([fTorrents count] == 1) |
---|
1661 | [fFileController reloadData]; |
---|
1662 | } |
---|
1663 | |
---|
1664 | - (NSView *) tabViewForTag: (NSInteger) tag |
---|
1665 | { |
---|
1666 | switch (tag) |
---|
1667 | { |
---|
1668 | case TAB_INFO_TAG: |
---|
1669 | return fInfoView; |
---|
1670 | case TAB_ACTIVITY_TAG: |
---|
1671 | return fActivityView; |
---|
1672 | case TAB_TRACKER_TAG: |
---|
1673 | return fTrackerView; |
---|
1674 | case TAB_PEERS_TAG: |
---|
1675 | return fPeersView; |
---|
1676 | case TAB_FILES_TAG: |
---|
1677 | return fFilesView; |
---|
1678 | case TAB_OPTIONS_TAG: |
---|
1679 | return fOptionsView; |
---|
1680 | default: |
---|
1681 | NSAssert1(NO, @"Unknown tab view for tag: %d", tag); |
---|
1682 | return nil; |
---|
1683 | } |
---|
1684 | } |
---|
1685 | |
---|
1686 | - (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate |
---|
1687 | { |
---|
1688 | if (fCurrentTabTag != TAB_PEERS_TAG || ![[self window] isVisible]) |
---|
1689 | animate = NO; |
---|
1690 | |
---|
1691 | if (fWebSeedTableAnimation) |
---|
1692 | { |
---|
1693 | [fWebSeedTableAnimation stopAnimation]; |
---|
1694 | [fWebSeedTableAnimation release]; |
---|
1695 | fWebSeedTableAnimation = nil; |
---|
1696 | } |
---|
1697 | |
---|
1698 | NSRect webSeedFrame = [[fWebSeedTable enclosingScrollView] frame]; |
---|
1699 | NSRect peerFrame = [[fPeerTable enclosingScrollView] frame]; |
---|
1700 | |
---|
1701 | if (hide) |
---|
1702 | { |
---|
1703 | CGFloat webSeedFrameMaxY = NSMaxY(webSeedFrame); |
---|
1704 | webSeedFrame.size.height = 0; |
---|
1705 | webSeedFrame.origin.y = webSeedFrameMaxY; |
---|
1706 | |
---|
1707 | peerFrame.size.height = webSeedFrameMaxY - peerFrame.origin.y; |
---|
1708 | } |
---|
1709 | else |
---|
1710 | { |
---|
1711 | webSeedFrame.origin.y -= fWebSeedTableHeight - webSeedFrame.size.height; |
---|
1712 | webSeedFrame.size.height = fWebSeedTableHeight; |
---|
1713 | |
---|
1714 | peerFrame.size.height = (webSeedFrame.origin.y - fSpaceBetweenWebSeedAndPeer) - peerFrame.origin.y; |
---|
1715 | } |
---|
1716 | |
---|
1717 | [[fWebSeedTable enclosingScrollView] setHidden: NO]; //this is needed for some reason |
---|
1718 | |
---|
1719 | //actually resize tables |
---|
1720 | if (animate) |
---|
1721 | { |
---|
1722 | NSDictionary * webSeedDict = [NSDictionary dictionaryWithObjectsAndKeys: |
---|
1723 | [fWebSeedTable enclosingScrollView], NSViewAnimationTargetKey, |
---|
1724 | [NSValue valueWithRect: [[fWebSeedTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey, |
---|
1725 | [NSValue valueWithRect: webSeedFrame], NSViewAnimationEndFrameKey, nil], |
---|
1726 | * peerDict = [NSDictionary dictionaryWithObjectsAndKeys: |
---|
1727 | [fPeerTable enclosingScrollView], NSViewAnimationTargetKey, |
---|
1728 | [NSValue valueWithRect: [[fPeerTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey, |
---|
1729 | [NSValue valueWithRect: peerFrame], NSViewAnimationEndFrameKey, nil]; |
---|
1730 | |
---|
1731 | fWebSeedTableAnimation = [[NSViewAnimation alloc] initWithViewAnimations: |
---|
1732 | [NSArray arrayWithObjects: webSeedDict, peerDict, nil]]; |
---|
1733 | [fWebSeedTableAnimation setDuration: 0.125]; |
---|
1734 | [fWebSeedTableAnimation setAnimationBlockingMode: NSAnimationNonblocking]; |
---|
1735 | [fWebSeedTableAnimation setDelegate: self]; |
---|
1736 | |
---|
1737 | [fWebSeedTableAnimation startAnimation]; |
---|
1738 | } |
---|
1739 | else |
---|
1740 | { |
---|
1741 | [[fWebSeedTable enclosingScrollView] setFrame: webSeedFrame]; |
---|
1742 | [[fPeerTable enclosingScrollView] setFrame: peerFrame]; |
---|
1743 | } |
---|
1744 | } |
---|
1745 | |
---|
1746 | - (NSArray *) peerSortDescriptors |
---|
1747 | { |
---|
1748 | NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2]; |
---|
1749 | |
---|
1750 | NSArray * oldDescriptors = [fPeerTable sortDescriptors]; |
---|
1751 | BOOL useSecond = YES, asc = YES; |
---|
1752 | if ([oldDescriptors count] > 0) |
---|
1753 | { |
---|
1754 | NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0]; |
---|
1755 | [descriptors addObject: descriptor]; |
---|
1756 | |
---|
1757 | if ((useSecond = ![[descriptor key] isEqualToString: @"IP"])) |
---|
1758 | asc = [descriptor ascending]; |
---|
1759 | } |
---|
1760 | |
---|
1761 | //sort by IP after primary sort |
---|
1762 | if (useSecond) |
---|
1763 | { |
---|
1764 | NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc |
---|
1765 | selector: @selector(compareNumeric:)]; |
---|
1766 | [descriptors addObject: secondDescriptor]; |
---|
1767 | [secondDescriptor release]; |
---|
1768 | } |
---|
1769 | |
---|
1770 | return descriptors; |
---|
1771 | } |
---|
1772 | |
---|
1773 | - (BOOL) canQuickLookFile: (FileListNode *) item |
---|
1774 | { |
---|
1775 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1776 | return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item]; |
---|
1777 | } |
---|
1778 | |
---|
1779 | #warning doesn't like blank addresses |
---|
1780 | - (void) addTrackers |
---|
1781 | { |
---|
1782 | [[self window] makeKeyWindow]; |
---|
1783 | |
---|
1784 | [fTrackers addObject: NSLocalizedString(@"New Tier", "inspector -> add tracker")]; |
---|
1785 | [fTrackers addObject: @""]; |
---|
1786 | |
---|
1787 | [fTrackerTable setTrackers: fTrackers]; |
---|
1788 | [fTrackerTable reloadData]; |
---|
1789 | [fTrackerTable selectRowIndexes: [NSIndexSet indexSetWithIndex: [fTrackers count]-1] byExtendingSelection: NO]; |
---|
1790 | [fTrackerTable editColumn: [fTrackerTable columnWithIdentifier: @"Tracker"] row: [fTrackers count]-1 withEvent: nil select: YES]; |
---|
1791 | } |
---|
1792 | |
---|
1793 | - (void) removeTrackers |
---|
1794 | { |
---|
1795 | NSMutableIndexSet * removeIdentifiers = [NSMutableIndexSet indexSet]; |
---|
1796 | |
---|
1797 | NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes]; |
---|
1798 | BOOL groupSelected = NO; |
---|
1799 | for (NSUInteger i = 0; i < [fTrackers count]; ++i) |
---|
1800 | { |
---|
1801 | id object = [fTrackers objectAtIndex: i]; |
---|
1802 | if ([object isKindOfClass: [TrackerNode class]]) |
---|
1803 | { |
---|
1804 | if (groupSelected || [selectedIndexes containsIndex: i]) |
---|
1805 | [removeIdentifiers addIndex: [(TrackerNode *)object identifier]]; |
---|
1806 | } |
---|
1807 | else |
---|
1808 | { |
---|
1809 | groupSelected = [selectedIndexes containsIndex: i]; |
---|
1810 | if (!groupSelected && i > [selectedIndexes lastIndex]) |
---|
1811 | break; |
---|
1812 | } |
---|
1813 | } |
---|
1814 | |
---|
1815 | NSAssert([removeIdentifiers count] > 0, @"Trying to remove no trackers."); |
---|
1816 | |
---|
1817 | if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveTrackers"]) |
---|
1818 | { |
---|
1819 | NSAlert * alert = [[NSAlert alloc] init]; |
---|
1820 | |
---|
1821 | if ([removeIdentifiers count] > 1) |
---|
1822 | { |
---|
1823 | [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?", |
---|
1824 | "Remove trackers alert -> title"), [removeIdentifiers count]]]; |
---|
1825 | [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them." |
---|
1826 | " This cannot be undone.", "Remove trackers alert -> message")]; |
---|
1827 | } |
---|
1828 | else |
---|
1829 | { |
---|
1830 | [alert setMessageText: NSLocalizedString(@"Are you sure you want to remove this tracker?", "Remove trackers alert -> title")]; |
---|
1831 | [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact it." |
---|
1832 | " This cannot be undone.", "Remove trackers alert -> message")]; |
---|
1833 | } |
---|
1834 | |
---|
1835 | [alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove trackers alert -> button")]; |
---|
1836 | [alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove trackers alert -> button")]; |
---|
1837 | |
---|
1838 | [alert setShowsSuppressionButton: YES]; |
---|
1839 | |
---|
1840 | NSInteger result = [alert runModal]; |
---|
1841 | if ([[alert suppressionButton] state] == NSOnState) |
---|
1842 | [[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningRemoveTrackers"]; |
---|
1843 | [alert release]; |
---|
1844 | |
---|
1845 | if (result != NSAlertFirstButtonReturn) |
---|
1846 | return; |
---|
1847 | } |
---|
1848 | |
---|
1849 | Torrent * torrent = [fTorrents objectAtIndex: 0]; |
---|
1850 | [torrent removeTrackersWithIdentifiers: removeIdentifiers]; |
---|
1851 | |
---|
1852 | //reset table with either new or old value |
---|
1853 | [fTrackers release]; |
---|
1854 | fTrackers = [[torrent allTrackerStats] retain]; |
---|
1855 | |
---|
1856 | [fTrackerTable setTrackers: fTrackers]; |
---|
1857 | [fTrackerTable reloadData]; |
---|
1858 | [fTrackerTable deselectAll: self]; |
---|
1859 | |
---|
1860 | [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker |
---|
1861 | } |
---|
1862 | |
---|
1863 | @end |
---|