2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2006-2012 Transmission authors and contributors
|
2007-09-16 01:02:06 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "InfoWindowController.h"
|
2010-03-14 01:42:49 +00:00
|
|
|
#import "InfoViewController.h"
|
2010-03-06 23:12:30 +00:00
|
|
|
#import "InfoGeneralViewController.h"
|
|
|
|
#import "InfoActivityViewController.h"
|
|
|
|
#import "InfoTrackersViewController.h"
|
|
|
|
#import "InfoPeersViewController.h"
|
|
|
|
#import "InfoFileViewController.h"
|
|
|
|
#import "InfoOptionsViewController.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
#import "InfoTabButtonCell.h"
|
2012-07-25 12:48:13 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
#import "Torrent.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
#define TAB_INFO_IDENT @"Info"
|
|
|
|
#define TAB_ACTIVITY_IDENT @"Activity"
|
2008-02-22 01:36:30 +00:00
|
|
|
#define TAB_TRACKER_IDENT @"Tracker"
|
2007-09-16 01:02:06 +00:00
|
|
|
#define TAB_PEERS_IDENT @"Peers"
|
|
|
|
#define TAB_FILES_IDENT @"Files"
|
|
|
|
#define TAB_OPTIONS_IDENT @"Options"
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
#define TAB_MIN_HEIGHT 250
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
#define INVALID -99
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
TAB_GENERAL_TAG = 0,
|
2007-12-17 16:06:20 +00:00
|
|
|
TAB_ACTIVITY_TAG = 1,
|
2010-03-06 23:12:30 +00:00
|
|
|
TAB_TRACKERS_TAG = 2,
|
2008-02-22 01:36:30 +00:00
|
|
|
TAB_PEERS_TAG = 3,
|
2010-03-06 23:12:30 +00:00
|
|
|
TAB_FILE_TAG = 4,
|
2008-02-22 01:36:30 +00:00
|
|
|
TAB_OPTIONS_TAG = 5
|
2007-10-06 22:23:44 +00:00
|
|
|
} tabTag;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface InfoWindowController (Private)
|
|
|
|
|
2009-11-27 16:55:36 +00:00
|
|
|
- (void) resetInfo;
|
2009-12-05 16:10:59 +00:00
|
|
|
- (void) resetInfoForTorrent: (NSNotification *) notification;
|
2009-11-27 16:55:36 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoWindowController
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
self = [super initWithWindowNibName: @"InfoWindow"];
|
2009-09-28 01:57:35 +00:00
|
|
|
return self;
|
2007-10-07 12:24:26 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 02:25:58 +00:00
|
|
|
- (void) awakeFromNib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-02-12 03:53:23 +00:00
|
|
|
[fNoneSelectedField setStringValue: NSLocalizedString(@"No Torrents Selected", "Inspector -> selected torrents")];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//window location and size
|
|
|
|
NSPanel * window = (NSPanel *)[self window];
|
|
|
|
|
2011-10-24 02:02:19 +00:00
|
|
|
[window setFloatingPanel: NO];
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
const CGFloat windowHeight = NSHeight([window frame]);
|
2007-10-07 12:24:26 +00:00
|
|
|
|
|
|
|
[window setFrameAutosaveName: @"InspectorWindow"];
|
|
|
|
[window setFrameUsingName: @"InspectorWindow"];
|
|
|
|
|
|
|
|
NSRect windowRect = [window frame];
|
2010-03-09 02:26:52 +00:00
|
|
|
windowRect.origin.y -= windowHeight - NSHeight(windowRect);
|
2007-10-07 12:24:26 +00:00
|
|
|
windowRect.size.height = windowHeight;
|
|
|
|
[window setFrame: windowRect display: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[window setBecomesKeyOnlyIfNeeded: YES];
|
|
|
|
|
2010-03-06 23:24:42 +00:00
|
|
|
//set tab tooltips
|
2010-03-06 23:31:40 +00:00
|
|
|
[fTabMatrix setToolTip: NSLocalizedString(@"General Info", "Inspector -> tab") forCell: [fTabMatrix cellWithTag: TAB_GENERAL_TAG]];
|
|
|
|
[fTabMatrix setToolTip: NSLocalizedString(@"Activity", "Inspector -> tab") forCell: [fTabMatrix cellWithTag: TAB_ACTIVITY_TAG]];
|
|
|
|
[fTabMatrix setToolTip: NSLocalizedString(@"Trackers", "Inspector -> tab") forCell: [fTabMatrix cellWithTag: TAB_TRACKERS_TAG]];
|
|
|
|
[fTabMatrix setToolTip: NSLocalizedString(@"Peers", "Inspector -> tab") forCell: [fTabMatrix cellWithTag: TAB_PEERS_TAG]];
|
|
|
|
[fTabMatrix setToolTip: NSLocalizedString(@"Files", "Inspector -> tab") forCell: [fTabMatrix cellWithTag: TAB_FILE_TAG]];
|
|
|
|
[fTabMatrix setToolTip: NSLocalizedString(@"Options", "Inspector -> tab") forCell: [fTabMatrix cellWithTag: TAB_OPTIONS_TAG]];
|
2010-03-06 23:24:42 +00:00
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
//set selected tab
|
2007-10-07 02:25:39 +00:00
|
|
|
fCurrentTabTag = INVALID;
|
2007-09-16 01:02:06 +00:00
|
|
|
NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InspectorSelected"];
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger tag;
|
2007-10-06 22:23:44 +00:00
|
|
|
if ([identifier isEqualToString: TAB_INFO_IDENT])
|
2010-03-06 23:12:30 +00:00
|
|
|
tag = TAB_GENERAL_TAG;
|
2007-10-06 22:23:44 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
|
|
|
|
tag = TAB_ACTIVITY_TAG;
|
2008-02-22 01:36:30 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_TRACKER_IDENT])
|
2010-03-06 23:12:30 +00:00
|
|
|
tag = TAB_TRACKERS_TAG;
|
2007-10-06 22:23:44 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_PEERS_IDENT])
|
|
|
|
tag = TAB_PEERS_TAG;
|
|
|
|
else if ([identifier isEqualToString: TAB_FILES_IDENT])
|
2010-03-06 23:12:30 +00:00
|
|
|
tag = TAB_FILE_TAG;
|
2007-10-06 22:23:44 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
|
|
|
|
tag = TAB_OPTIONS_TAG;
|
|
|
|
else //safety
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject: TAB_INFO_IDENT forKey: @"InspectorSelected"];
|
2010-03-06 23:12:30 +00:00
|
|
|
tag = TAB_GENERAL_TAG;
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//set blank inspector
|
2007-10-29 18:07:09 +00:00
|
|
|
[self setInfoForTorrents: [NSArray array]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//allow for update notifications
|
|
|
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
2009-12-05 16:10:59 +00:00
|
|
|
[nc addObserver: self selector: @selector(resetInfoForTorrent:) name: @"ResetInspector" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
[nc addObserver: self selector: @selector(updateInfoStats) name: @"UpdateStats" object: nil];
|
2007-10-29 18:07:09 +00:00
|
|
|
[nc addObserver: self selector: @selector(updateOptions) name: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
2010-03-14 02:53:22 +00:00
|
|
|
if ([fViewController respondsToSelector: @selector(saveViewSize)])
|
|
|
|
[fViewController saveViewSize];
|
|
|
|
|
2012-03-13 02:55:15 +00:00
|
|
|
[fGeneralViewController release];
|
|
|
|
[fActivityViewController release];
|
|
|
|
[fTrackersViewController release];
|
|
|
|
[fPeersViewController release];
|
|
|
|
[fFileViewController release];
|
|
|
|
[fOptionsViewController release];
|
2010-03-14 02:14:03 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[fTorrents release];
|
2009-09-04 04:10:46 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[super dealloc];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
- (void) setInfoForTorrents: (NSArray *) torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-27 13:59:26 +00:00
|
|
|
if (fTorrents && [fTorrents isEqualToArray: torrents])
|
|
|
|
return;
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[fTorrents release];
|
|
|
|
fTorrents = [torrents retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-11-27 16:55:36 +00:00
|
|
|
[self resetInfo];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-07 15:55:27 +00:00
|
|
|
NSRect windowRect = [window frame];
|
|
|
|
windowRect.size.width = [window minSize].width;
|
|
|
|
return windowRect;
|
|
|
|
}
|
|
|
|
|
2010-03-07 02:28:50 +00:00
|
|
|
- (NSSize) windowWillResize: (NSWindow *) window toSize: (NSSize) proposedFrameSize
|
2008-06-08 04:11:29 +00:00
|
|
|
{
|
2010-03-07 02:28:50 +00:00
|
|
|
//this is an edge-case - just stop the animation
|
|
|
|
[fPeersViewController stopWebSeedAnimation];
|
2008-06-08 05:36:49 +00:00
|
|
|
|
|
|
|
return proposedFrameSize;
|
2010-03-07 02:28:50 +00:00
|
|
|
}
|
2008-06-08 04:11:29 +00:00
|
|
|
|
2009-10-11 23:50:13 +00:00
|
|
|
- (void) windowWillClose: (NSNotification *) notification
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
if (fCurrentTabTag == TAB_FILE_TAG && ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]))
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
2009-10-11 23:50:13 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (void) setTab: (id) sender
|
|
|
|
{
|
2009-09-04 04:10:46 +00:00
|
|
|
const NSInteger oldTabTag = fCurrentTabTag;
|
2008-02-27 02:06:46 +00:00
|
|
|
fCurrentTabTag = [fTabMatrix selectedTag];
|
|
|
|
if (fCurrentTabTag == oldTabTag)
|
|
|
|
return;
|
2008-02-27 01:57:13 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
//take care of old view
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat oldHeight = 0;
|
2008-02-27 01:57:13 +00:00
|
|
|
if (oldTabTag != INVALID)
|
2008-02-27 02:06:46 +00:00
|
|
|
{
|
|
|
|
//deselect old tab item
|
|
|
|
[(InfoTabButtonCell *)[fTabMatrix cellWithTag: oldTabTag] setSelectedTab: NO];
|
|
|
|
|
2010-03-14 02:53:22 +00:00
|
|
|
if ([fViewController respondsToSelector: @selector(saveViewSize)])
|
|
|
|
[fViewController saveViewSize];
|
|
|
|
|
2010-03-14 01:52:45 +00:00
|
|
|
if ([fViewController respondsToSelector: @selector(clearView)])
|
|
|
|
[fViewController clearView];
|
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
NSView * oldView = [fViewController view];
|
2010-03-14 01:52:45 +00:00
|
|
|
oldHeight = NSHeight([oldView frame]);
|
2008-02-27 02:06:46 +00:00
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
//remove old view
|
2008-02-27 02:06:46 +00:00
|
|
|
[oldView removeFromSuperview];
|
|
|
|
}
|
2008-02-27 01:57:13 +00:00
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
//set new tab item
|
2010-03-14 03:09:12 +00:00
|
|
|
NSString * identifier;
|
2007-10-07 15:55:27 +00:00
|
|
|
switch (fCurrentTabTag)
|
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
case TAB_GENERAL_TAG:
|
2010-03-07 01:40:32 +00:00
|
|
|
if (!fGeneralViewController)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
fGeneralViewController = [[InfoGeneralViewController alloc] init];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fGeneralViewController setInfoForTorrents: fTorrents];
|
|
|
|
}
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
fViewController = fGeneralViewController;
|
2007-10-07 15:55:27 +00:00
|
|
|
identifier = TAB_INFO_IDENT;
|
|
|
|
break;
|
|
|
|
case TAB_ACTIVITY_TAG:
|
2010-03-07 01:40:32 +00:00
|
|
|
if (!fActivityViewController)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
fActivityViewController = [[InfoActivityViewController alloc] init];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fActivityViewController setInfoForTorrents: fTorrents];
|
|
|
|
}
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
fViewController = fActivityViewController;
|
2007-10-07 15:55:27 +00:00
|
|
|
identifier = TAB_ACTIVITY_IDENT;
|
|
|
|
break;
|
2010-03-06 23:12:30 +00:00
|
|
|
case TAB_TRACKERS_TAG:
|
2010-03-07 01:40:32 +00:00
|
|
|
if (!fTrackersViewController)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
fTrackersViewController = [[InfoTrackersViewController alloc] init];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fTrackersViewController setInfoForTorrents: fTorrents];
|
|
|
|
}
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
fViewController = fTrackersViewController;
|
2008-02-22 01:36:30 +00:00
|
|
|
identifier = TAB_TRACKER_IDENT;
|
|
|
|
break;
|
2007-10-07 15:55:27 +00:00
|
|
|
case TAB_PEERS_TAG:
|
2010-03-07 01:40:32 +00:00
|
|
|
if (!fPeersViewController)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
fPeersViewController = [[InfoPeersViewController alloc] init];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fPeersViewController setInfoForTorrents: fTorrents];
|
|
|
|
}
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
fViewController = fPeersViewController;
|
2007-10-07 15:55:27 +00:00
|
|
|
identifier = TAB_PEERS_IDENT;
|
|
|
|
break;
|
2010-03-06 23:12:30 +00:00
|
|
|
case TAB_FILE_TAG:
|
2010-03-07 01:40:32 +00:00
|
|
|
if (!fFileViewController)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
fFileViewController = [[InfoFileViewController alloc] init];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fFileViewController setInfoForTorrents: fTorrents];
|
|
|
|
}
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
fViewController = fFileViewController;
|
2007-10-07 15:55:27 +00:00
|
|
|
identifier = TAB_FILES_IDENT;
|
|
|
|
break;
|
|
|
|
case TAB_OPTIONS_TAG:
|
2010-03-07 01:40:32 +00:00
|
|
|
if (!fOptionsViewController)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2010-03-07 01:40:32 +00:00
|
|
|
fOptionsViewController = [[InfoOptionsViewController alloc] init];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fOptionsViewController setInfoForTorrents: fTorrents];
|
|
|
|
}
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
fViewController = fOptionsViewController;
|
2007-10-07 15:55:27 +00:00
|
|
|
identifier = TAB_OPTIONS_IDENT;
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-13 00:52:04 +00:00
|
|
|
NSAssert1(NO, @"Unknown info tab selected: %ld", fCurrentTabTag);
|
2007-10-07 15:55:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-27 02:06:46 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
NSWindow * window = [self window];
|
|
|
|
|
2010-03-14 03:09:12 +00:00
|
|
|
[window setTitle: [NSString stringWithFormat: @"%@ - %@", [fViewController title],
|
|
|
|
NSLocalizedString(@"Torrent Inspector", "Inspector -> title")]];
|
2007-10-10 02:35:16 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
//selected tab item
|
|
|
|
[(InfoTabButtonCell *)[fTabMatrix selectedCell] setSelectedTab: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
NSView * view = [fViewController view];
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
[fViewController updateInfo];
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
NSRect windowRect = [window frame], viewRect = [view frame];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2011-12-25 22:05:18 +00:00
|
|
|
const CGFloat difference = (NSHeight(viewRect) - oldHeight) * [window userSpaceScaleFactor];
|
2007-10-06 22:23:44 +00:00
|
|
|
windowRect.origin.y -= difference;
|
|
|
|
windowRect.size.height += difference;
|
|
|
|
|
2010-03-14 02:59:37 +00:00
|
|
|
if ([fViewController respondsToSelector: @selector(saveViewSize)]) //a little bit hacky, but avoids requiring an extra method
|
2007-10-06 22:23:44 +00:00
|
|
|
{
|
2011-12-25 22:15:13 +00:00
|
|
|
if ([window screen])
|
2011-12-25 22:05:18 +00:00
|
|
|
{
|
2011-12-25 22:15:13 +00:00
|
|
|
const CGFloat screenHeight = NSHeight([[window screen] visibleFrame]);
|
|
|
|
if (NSHeight(windowRect) > screenHeight)
|
|
|
|
{
|
|
|
|
const CGFloat difference = (screenHeight - NSHeight(windowRect)) * [window userSpaceScaleFactor];
|
|
|
|
windowRect.origin.y -= difference;
|
|
|
|
windowRect.size.height += difference;
|
|
|
|
|
|
|
|
viewRect.size.height += difference;
|
|
|
|
}
|
2011-12-25 22:05:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 02:53:22 +00:00
|
|
|
[window setMinSize: NSMakeSize([window minSize].width, NSHeight(windowRect) - NSHeight(viewRect) + TAB_MIN_HEIGHT)];
|
|
|
|
[window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-14 02:53:22 +00:00
|
|
|
[window setMinSize: NSMakeSize([window minSize].width, NSHeight(windowRect))];
|
|
|
|
[window setMaxSize: NSMakeSize(FLT_MAX, NSHeight(windowRect))];
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 02:59:37 +00:00
|
|
|
viewRect.size.width = NSWidth(windowRect);
|
2007-10-06 22:23:44 +00:00
|
|
|
[view setFrame: viewRect];
|
|
|
|
|
2007-10-07 03:05:55 +00:00
|
|
|
[window setFrame: windowRect display: YES animate: oldTabTag != INVALID];
|
2007-10-06 22:23:44 +00:00
|
|
|
[[window contentView] addSubview: view];
|
2010-03-07 01:40:32 +00:00
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
if ((fCurrentTabTag == TAB_FILE_TAG || oldTabTag == TAB_FILE_TAG)
|
|
|
|
&& ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]))
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNextTab
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger tag = [fTabMatrix selectedTag]+1;
|
2007-10-06 22:23:44 +00:00
|
|
|
if (tag >= [fTabMatrix numberOfColumns])
|
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPreviousTab
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger tag = [fTabMatrix selectedTag]-1;
|
2007-10-06 22:23:44 +00:00
|
|
|
if (tag < 0)
|
|
|
|
tag = [fTabMatrix numberOfColumns]-1;
|
|
|
|
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 03:52:54 +00:00
|
|
|
- (void) swipeWithEvent: (NSEvent *) event
|
2010-10-15 23:39:14 +00:00
|
|
|
{
|
|
|
|
if ([event deltaX] < 0.0)
|
|
|
|
[self setNextTab];
|
|
|
|
else if ([event deltaX] > 0.0)
|
|
|
|
[self setPreviousTab];
|
|
|
|
}
|
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
- (void) updateInfoStats
|
|
|
|
{
|
|
|
|
[fViewController updateInfo];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (void) updateOptions
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
[fOptionsViewController updateOptions];
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 23:16:46 +00:00
|
|
|
- (NSArray *) quickLookURLs
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return [fFileViewController quickLookURLs];
|
2009-09-04 04:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 23:16:46 +00:00
|
|
|
- (BOOL) canQuickLook
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
if (fCurrentTabTag != TAB_FILE_TAG || ![[self window] isVisible])
|
2009-10-11 23:16:46 +00:00
|
|
|
return NO;
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return [fFileViewController canQuickLook];
|
2009-09-04 04:10:46 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
- (NSRect) quickLookSourceFrameForPreviewItem: (id <QLPreviewItem>) item
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return [fFileViewController quickLookSourceFrameForPreviewItem: item];
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoWindowController (Private)
|
|
|
|
|
2009-11-27 16:55:36 +00:00
|
|
|
- (void) resetInfo
|
|
|
|
{
|
2009-11-27 20:47:03 +00:00
|
|
|
const NSUInteger numberSelected = [fTorrents count];
|
2009-11-27 16:55:36 +00:00
|
|
|
if (numberSelected != 1)
|
|
|
|
{
|
|
|
|
if (numberSelected > 0)
|
|
|
|
{
|
|
|
|
[fImageView setImage: [NSImage imageNamed: NSImageNameMultipleDocuments]];
|
|
|
|
|
2010-11-14 21:04:25 +00:00
|
|
|
[fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ Torrents Selected",
|
|
|
|
"Inspector -> selected torrents"),
|
|
|
|
[NSString formattedUInteger: numberSelected]]];
|
2011-02-12 03:53:23 +00:00
|
|
|
[fNameField setHidden: NO];
|
2009-11-27 16:55:36 +00:00
|
|
|
|
|
|
|
uint64_t size = 0;
|
2009-11-27 20:47:03 +00:00
|
|
|
NSUInteger fileCount = 0, magnetCount = 0;
|
2009-11-27 16:55:36 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
{
|
|
|
|
size += [torrent size];
|
|
|
|
fileCount += [torrent fileCount];
|
2009-11-27 20:47:03 +00:00
|
|
|
if ([torrent isMagnet])
|
|
|
|
++magnetCount;
|
2009-11-27 16:55:36 +00:00
|
|
|
}
|
|
|
|
|
2009-11-27 20:47:03 +00:00
|
|
|
NSMutableArray * fileStrings = [NSMutableArray arrayWithCapacity: 2];
|
|
|
|
if (fileCount > 0)
|
|
|
|
{
|
|
|
|
NSString * fileString;
|
|
|
|
if (fileCount == 1)
|
|
|
|
fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents");
|
|
|
|
else
|
2010-11-14 21:04:25 +00:00
|
|
|
fileString = [NSString stringWithFormat: NSLocalizedString(@"%@ files", "Inspector -> selected torrents"),
|
|
|
|
[NSString formattedUInteger: fileCount]];
|
2009-11-27 20:47:03 +00:00
|
|
|
[fileStrings addObject: fileString];
|
|
|
|
}
|
|
|
|
if (magnetCount > 0)
|
|
|
|
{
|
|
|
|
NSString * magnetString;
|
|
|
|
if (magnetCount == 1)
|
|
|
|
magnetString = NSLocalizedString(@"1 magnetized transfer", "Inspector -> selected torrents");
|
|
|
|
else
|
2010-11-14 21:04:25 +00:00
|
|
|
magnetString = [NSString stringWithFormat: NSLocalizedString(@"%@ magnetized transfers",
|
|
|
|
"Inspector -> selected torrents"), [NSString formattedUInteger: magnetCount]];
|
2009-11-27 20:47:03 +00:00
|
|
|
[fileStrings addObject: magnetString];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString * fileString = [fileStrings componentsJoinedByString: @" + "];
|
|
|
|
|
|
|
|
if (magnetCount < numberSelected)
|
|
|
|
{
|
|
|
|
[fBasicInfoField setStringValue: [NSString stringWithFormat: @"%@, %@", fileString,
|
|
|
|
[NSString stringWithFormat: NSLocalizedString(@"%@ total", "Inspector -> selected torrents"),
|
|
|
|
[NSString stringForFileSize: size]]]];
|
2012-07-25 12:48:13 +00:00
|
|
|
|
|
|
|
NSString * byteString;
|
|
|
|
if ([NSApp isOnMountainLionOrBetter])
|
|
|
|
{
|
|
|
|
NSByteCountFormatter * formatter = [[NSByteCountFormatterMtLion alloc] init];
|
|
|
|
[formatter setAllowedUnits: NSByteCountFormatterUseBytes];
|
|
|
|
byteString = [formatter stringFromByteCount: size];
|
|
|
|
[formatter release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
byteString = [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "Inspector -> selected torrents"), [NSString formattedUInteger: size]];
|
|
|
|
[fBasicInfoField setToolTip: byteString];
|
2009-11-27 20:47:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fBasicInfoField setStringValue: fileString];
|
|
|
|
[fBasicInfoField setToolTip: nil];
|
|
|
|
}
|
2011-02-12 03:53:23 +00:00
|
|
|
[fBasicInfoField setHidden: NO];
|
|
|
|
|
|
|
|
[fNoneSelectedField setHidden: YES];
|
2009-11-27 16:55:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
[fImageView setImage: [NSImage imageNamed: NSImageNameApplicationIcon]];
|
2011-02-12 03:53:23 +00:00
|
|
|
[fNoneSelectedField setHidden: NO];
|
2009-11-27 16:55:36 +00:00
|
|
|
|
2011-02-12 03:53:23 +00:00
|
|
|
[fNameField setHidden: YES];
|
|
|
|
[fBasicInfoField setHidden: YES];
|
2009-11-27 16:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[fNameField setToolTip: nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
[fImageView setImage: [torrent icon]];
|
2009-11-27 16:55:36 +00:00
|
|
|
|
|
|
|
NSString * name = [torrent name];
|
|
|
|
[fNameField setStringValue: name];
|
|
|
|
[fNameField setToolTip: name];
|
2011-02-12 03:53:23 +00:00
|
|
|
[fNameField setHidden: NO];
|
2009-11-27 16:55:36 +00:00
|
|
|
|
2009-11-27 20:47:03 +00:00
|
|
|
if (![torrent isMagnet])
|
2009-11-27 16:55:36 +00:00
|
|
|
{
|
2009-11-27 20:47:03 +00:00
|
|
|
NSString * basicString = [NSString stringForFileSize: [torrent size]];
|
|
|
|
if ([torrent isFolder])
|
|
|
|
{
|
|
|
|
NSString * fileString;
|
2010-11-20 16:09:48 +00:00
|
|
|
const NSUInteger fileCount = [torrent fileCount];
|
2009-11-27 20:47:03 +00:00
|
|
|
if (fileCount == 1)
|
|
|
|
fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents");
|
|
|
|
else
|
2010-11-20 16:09:48 +00:00
|
|
|
fileString= [NSString stringWithFormat: NSLocalizedString(@"%@ files", "Inspector -> selected torrents"),
|
|
|
|
[NSString formattedUInteger: fileCount]];
|
2009-11-27 20:47:03 +00:00
|
|
|
basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString];
|
|
|
|
}
|
|
|
|
[fBasicInfoField setStringValue: basicString];
|
2012-07-25 12:48:13 +00:00
|
|
|
|
|
|
|
NSString * byteString;
|
|
|
|
if ([NSApp isOnMountainLionOrBetter])
|
|
|
|
{
|
|
|
|
NSByteCountFormatter * formatter = [[NSByteCountFormatterMtLion alloc] init];
|
|
|
|
[formatter setAllowedUnits: NSByteCountFormatterUseBytes];
|
|
|
|
byteString = [formatter stringFromByteCount: [torrent size]];
|
|
|
|
[formatter release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
byteString = [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "Inspector -> selected torrents"), [NSString formattedUInteger: [torrent size]]];
|
|
|
|
[fBasicInfoField setToolTip: byteString];
|
2009-11-27 20:47:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fBasicInfoField setStringValue: NSLocalizedString(@"Magnetized transfer", "Inspector -> selected torrents")];
|
|
|
|
[fBasicInfoField setToolTip: nil];
|
2009-11-27 16:55:36 +00:00
|
|
|
}
|
2011-02-12 03:53:23 +00:00
|
|
|
[fBasicInfoField setHidden: NO];
|
|
|
|
|
|
|
|
[fNoneSelectedField setHidden: YES];
|
2010-02-06 15:42:18 +00:00
|
|
|
}
|
2010-02-06 03:52:32 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fGeneralViewController setInfoForTorrents: fTorrents];
|
|
|
|
[fActivityViewController setInfoForTorrents: fTorrents];
|
|
|
|
[fTrackersViewController setInfoForTorrents: fTorrents];
|
|
|
|
[fPeersViewController setInfoForTorrents: fTorrents];
|
|
|
|
[fFileViewController setInfoForTorrents: fTorrents];
|
|
|
|
[fOptionsViewController setInfoForTorrents: fTorrents];
|
2010-02-06 03:52:32 +00:00
|
|
|
|
2010-03-14 01:42:49 +00:00
|
|
|
[fViewController updateInfo];
|
2009-11-27 16:55:36 +00:00
|
|
|
}
|
|
|
|
|
2009-12-05 16:10:59 +00:00
|
|
|
- (void) resetInfoForTorrent: (NSNotification *) notification
|
|
|
|
{
|
2013-01-26 19:52:08 +00:00
|
|
|
Torrent * torrent = [[notification userInfo] objectForKey: @"Torrent"];
|
2013-01-22 03:54:51 +00:00
|
|
|
if (fTorrents && (!torrent || [fTorrents containsObject: torrent]))
|
2009-12-05 16:10:59 +00:00
|
|
|
[self resetInfo];
|
|
|
|
}
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
@end
|