From: Mitchell Livingston Date: Tue, 9 Mar 2010 02:26:52 +0000 (+0000) Subject: avoid setting views in the inspector until necessary X-Git-Tag: 2.00~364 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15c2279052e0e6a800eb1842aea4c2d4a0d8e8d1;p=transmission avoid setting views in the inspector until necessary --- diff --git a/macosx/InfoActivityViewController.h b/macosx/InfoActivityViewController.h index 4ff1af2b2..2ba5f2e52 100644 --- a/macosx/InfoActivityViewController.h +++ b/macosx/InfoActivityViewController.h @@ -31,6 +31,8 @@ { NSArray * fTorrents; + BOOL fSet; + IBOutlet NSTextField * fDateAddedField, * fDateCompletedField, * fDateActivityField, * fStateField, * fProgressField, * fHaveField, * fDownloadedTotalField, * fUploadedTotalField, * fFailedHashField, diff --git a/macosx/InfoActivityViewController.m b/macosx/InfoActivityViewController.m index 195451369..05bb5128b 100644 --- a/macosx/InfoActivityViewController.m +++ b/macosx/InfoActivityViewController.m @@ -31,6 +31,12 @@ #define PIECES_CONTROL_PROGRESS 0 #define PIECES_CONTROL_AVAILABLE 1 +@interface InfoActivityViewController (Private) + +- (void) setupInfo; + +@end + @implementation InfoActivityViewController - (id) init @@ -54,48 +60,14 @@ [fTorrents release]; fTorrents = [torrents retain]; - const NSUInteger count = [fTorrents count]; - if (count != 1) - { - if (count == 0) - { - [fHaveField setStringValue: @""]; - [fDownloadedTotalField setStringValue: @""]; - [fUploadedTotalField setStringValue: @""]; - [fFailedHashField setStringValue: @""]; - [fDateActivityField setStringValue: @""]; - [fRatioField setStringValue: @""]; - } - - [fStateField setStringValue: @""]; - [fProgressField setStringValue: @""]; - - [fErrorMessageView setString: @""]; - - [fDateAddedField setStringValue: @""]; - [fDateCompletedField setStringValue: @""]; - - [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE]; - [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS]; - [fPiecesControl setEnabled: NO]; - [fPiecesView setTorrent: nil]; - } - else - { - Torrent * torrent = [fTorrents objectAtIndex: 0]; - - [fDateAddedField setObjectValue: [torrent dateAdded]]; - - BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"]; - [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE]; - [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS]; - [fPiecesControl setEnabled: YES]; - [fPiecesView setTorrent: torrent]; - } + fSet = NO; } - (void) updateInfo { + if (!fSet) + [self setupInfo]; + const NSInteger numberSelected = [fTorrents count]; if (numberSelected == 0) return; @@ -182,3 +154,51 @@ } @end + +@implementation InfoActivityViewController (Private) + +- (void) setupInfo +{ + const NSUInteger count = [fTorrents count]; + if (count != 1) + { + if (count == 0) + { + [fHaveField setStringValue: @""]; + [fDownloadedTotalField setStringValue: @""]; + [fUploadedTotalField setStringValue: @""]; + [fFailedHashField setStringValue: @""]; + [fDateActivityField setStringValue: @""]; + [fRatioField setStringValue: @""]; + } + + [fStateField setStringValue: @""]; + [fProgressField setStringValue: @""]; + + [fErrorMessageView setString: @""]; + + [fDateAddedField setStringValue: @""]; + [fDateCompletedField setStringValue: @""]; + + [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE]; + [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS]; + [fPiecesControl setEnabled: NO]; + [fPiecesView setTorrent: nil]; + } + else + { + Torrent * torrent = [fTorrents objectAtIndex: 0]; + + [fDateAddedField setObjectValue: [torrent dateAdded]]; + + BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"]; + [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE]; + [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS]; + [fPiecesControl setEnabled: YES]; + [fPiecesView setTorrent: torrent]; + } + + fSet = YES; +} + +@end diff --git a/macosx/InfoFileViewController.h b/macosx/InfoFileViewController.h index e9b1ca37a..bd2e76832 100644 --- a/macosx/InfoFileViewController.h +++ b/macosx/InfoFileViewController.h @@ -30,6 +30,8 @@ { NSArray * fTorrents; + BOOL fSet; + IBOutlet FileOutlineController * fFileController; IBOutlet NSSearchField * fFileFilterField; diff --git a/macosx/InfoFileViewController.m b/macosx/InfoFileViewController.m index f61dde81f..33b814b46 100644 --- a/macosx/InfoFileViewController.m +++ b/macosx/InfoFileViewController.m @@ -30,6 +30,8 @@ @interface InfoFileViewController (Private) +- (void) setupInfo; + - (BOOL) canQuickLookFile: (FileListNode *) item; @end @@ -62,24 +64,14 @@ [fTorrents release]; fTorrents = [torrents retain]; - [fFileFilterField setStringValue: @""]; - - if ([fTorrents count] == 1) - { - Torrent * torrent = [fTorrents objectAtIndex: 0]; - - [fFileController setTorrent: torrent]; - [fFileFilterField setEnabled: [torrent isFolder]]; - } - else - { - [fFileController setTorrent: nil]; - [fFileFilterField setEnabled: NO]; - } + fSet = NO; } - (void) updateInfo { + if (!fSet) + [self setupInfo]; + if ([fTorrents count] == 1) [fFileController reloadData]; } @@ -158,6 +150,26 @@ @implementation InfoFileViewController (Private) +- (void) setupInfo +{ + [fFileFilterField setStringValue: @""]; + + if ([fTorrents count] == 1) + { + Torrent * torrent = [fTorrents objectAtIndex: 0]; + + [fFileController setTorrent: torrent]; + [fFileFilterField setEnabled: [torrent isFolder]]; + } + else + { + [fFileController setTorrent: nil]; + [fFileFilterField setEnabled: NO]; + } + + fSet = YES; +} + - (BOOL) canQuickLookFile: (FileListNode *) item { Torrent * torrent = [fTorrents objectAtIndex: 0]; diff --git a/macosx/InfoGeneralViewController.h b/macosx/InfoGeneralViewController.h index f4f052f67..2f5ad7383 100644 --- a/macosx/InfoGeneralViewController.h +++ b/macosx/InfoGeneralViewController.h @@ -28,6 +28,8 @@ { NSArray * fTorrents; + BOOL fSet; + IBOutlet NSTextField * fPiecesField, * fHashField, * fSecureField, * fDataLocationField, * fCreatorField, * fDateCreatedField; diff --git a/macosx/InfoGeneralViewController.m b/macosx/InfoGeneralViewController.m index bbcec59dc..4d39190cf 100644 --- a/macosx/InfoGeneralViewController.m +++ b/macosx/InfoGeneralViewController.m @@ -27,6 +27,12 @@ #import "NSStringAdditions.h" #import "Torrent.h" +@interface InfoGeneralViewController (Private) + +- (void) setupInfo; + +@end + @implementation InfoGeneralViewController - (id) init @@ -68,6 +74,48 @@ [fTorrents release]; fTorrents = [torrents retain]; + fSet = NO; +} + +- (void) updateInfo +{ + if (!fSet) + [self setupInfo]; + + if ([fTorrents count] != 1) + return; + + Torrent * torrent = [fTorrents objectAtIndex: 0]; + + NSString * location = [torrent dataLocation]; + [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""]; + [fDataLocationField setToolTip: location ? location : @""]; + + [fRevealDataButton setHidden: !location]; +} + +- (void) revealDataFile: (id) sender +{ + Torrent * torrent = [fTorrents objectAtIndex: 0]; + NSString * location = [torrent dataLocation]; + if (!location) + return; + + if ([NSApp isOnSnowLeopardOrBetter]) + { + NSURL * file = [NSURL fileURLWithPath: location]; + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]]; + } + else + [[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil]; +} + +@end + +@implementation InfoGeneralViewController (Private) + +- (void) setupInfo +{ if ([fTorrents count] == 1) { Torrent * torrent = [fTorrents objectAtIndex: 0]; @@ -106,36 +154,9 @@ [fRevealDataButton setHidden: YES]; } -} - -- (void) updateInfo -{ - if ([fTorrents count] != 1) - return; - Torrent * torrent = [fTorrents objectAtIndex: 0]; - - NSString * location = [torrent dataLocation]; - [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""]; - [fDataLocationField setToolTip: location ? location : @""]; - - [fRevealDataButton setHidden: !location]; -} - -- (void) revealDataFile: (id) sender -{ - Torrent * torrent = [fTorrents objectAtIndex: 0]; - NSString * location = [torrent dataLocation]; - if (!location) - return; - - if ([NSApp isOnSnowLeopardOrBetter]) - { - NSURL * file = [NSURL fileURLWithPath: location]; - [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]]; - } - else - [[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil]; + fSet = YES; } @end + diff --git a/macosx/InfoOptionsViewController.h b/macosx/InfoOptionsViewController.h index 9f773811f..8e053708d 100644 --- a/macosx/InfoOptionsViewController.h +++ b/macosx/InfoOptionsViewController.h @@ -28,6 +28,8 @@ { NSArray * fTorrents; + BOOL fSet; + IBOutlet NSPopUpButton * fPriorityPopUp, * fRatioPopUp; IBOutlet NSButton * fUploadLimitCheck, * fDownloadLimitCheck, * fGlobalLimitCheck; IBOutlet NSTextField * fUploadLimitField, * fDownloadLimitField, * fRatioLimitField, @@ -38,6 +40,7 @@ } - (void) setInfoForTorrents: (NSArray *) torrents; +- (void) updateInfo; - (void) updateOptions; - (void) setUseSpeedLimit: (id) sender; diff --git a/macosx/InfoOptionsViewController.m b/macosx/InfoOptionsViewController.m index 4cf34507b..f625deb81 100644 --- a/macosx/InfoOptionsViewController.m +++ b/macosx/InfoOptionsViewController.m @@ -35,6 +35,12 @@ #define INVALID -99 +@interface InfoOptionsViewController (Private) + +- (void) setupInfo; + +@end + @implementation InfoOptionsViewController - (id) init @@ -58,37 +64,15 @@ [fTorrents release]; fTorrents = [torrents retain]; - if ([fTorrents count] == 0) - { - [fUploadLimitCheck setEnabled: NO]; - [fUploadLimitCheck setState: NSOffState]; - [fUploadLimitField setEnabled: NO]; - [fUploadLimitLabel setEnabled: NO]; - [fUploadLimitField setStringValue: @""]; - - [fDownloadLimitCheck setEnabled: NO]; - [fDownloadLimitCheck setState: NSOffState]; - [fDownloadLimitField setEnabled: NO]; - [fDownloadLimitLabel setEnabled: NO]; - [fDownloadLimitField setStringValue: @""]; - - [fGlobalLimitCheck setEnabled: NO]; - [fGlobalLimitCheck setState: NSOffState]; - - [fPriorityPopUp setEnabled: NO]; - [fPriorityPopUp selectItemAtIndex: -1]; - - [fRatioPopUp setEnabled: NO]; - [fRatioPopUp selectItemAtIndex: -1]; - [fRatioLimitField setHidden: YES]; - [fRatioLimitField setStringValue: @""]; - - [fPeersConnectField setEnabled: NO]; - [fPeersConnectField setStringValue: @""]; - [fPeersConnectLabel setEnabled: NO]; - } - else - [self updateOptions]; + fSet = NO; +} + +- (void) updateInfo +{ + if (!fSet) + [self setupInfo]; + + fSet = YES; } - (void) updateOptions @@ -375,4 +359,39 @@ @implementation InfoOptionsViewController (Private) +- (void) setupInfo +{ + if ([fTorrents count] == 0) + { + [fUploadLimitCheck setEnabled: NO]; + [fUploadLimitCheck setState: NSOffState]; + [fUploadLimitField setEnabled: NO]; + [fUploadLimitLabel setEnabled: NO]; + [fUploadLimitField setStringValue: @""]; + + [fDownloadLimitCheck setEnabled: NO]; + [fDownloadLimitCheck setState: NSOffState]; + [fDownloadLimitField setEnabled: NO]; + [fDownloadLimitLabel setEnabled: NO]; + [fDownloadLimitField setStringValue: @""]; + + [fGlobalLimitCheck setEnabled: NO]; + [fGlobalLimitCheck setState: NSOffState]; + + [fPriorityPopUp setEnabled: NO]; + [fPriorityPopUp selectItemAtIndex: -1]; + + [fRatioPopUp setEnabled: NO]; + [fRatioPopUp selectItemAtIndex: -1]; + [fRatioLimitField setHidden: YES]; + [fRatioLimitField setStringValue: @""]; + + [fPeersConnectField setEnabled: NO]; + [fPeersConnectField setStringValue: @""]; + [fPeersConnectLabel setEnabled: NO]; + } + else + [self updateOptions]; +} + @end diff --git a/macosx/InfoPeersViewController.h b/macosx/InfoPeersViewController.h index 4baa9abbf..4372a69ce 100644 --- a/macosx/InfoPeersViewController.h +++ b/macosx/InfoPeersViewController.h @@ -28,6 +28,8 @@ { NSArray * fTorrents; + BOOL fSet; + NSMutableArray * fPeers, * fWebSeeds; IBOutlet NSTableView * fPeerTable, * fWebSeedTable; diff --git a/macosx/InfoPeersViewController.m b/macosx/InfoPeersViewController.m index edc0d7ab1..7087cc12c 100644 --- a/macosx/InfoPeersViewController.m +++ b/macosx/InfoPeersViewController.m @@ -30,7 +30,7 @@ @interface InfoPeersViewController (Private) -- (void) resetInfo; +- (void) setupInfo; - (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate; - (NSArray *) peerSortDescriptors; @@ -104,11 +104,14 @@ [fTorrents release]; fTorrents = [torrents retain]; - [self resetInfo]; + fSet = NO; } - (void) updateInfo { + if (!fSet) + [self setupInfo]; + if ([fTorrents count] == 0) return; @@ -441,7 +444,7 @@ @implementation InfoPeersViewController (Private) -- (void) resetInfo +- (void) setupInfo { BOOL hasWebSeeds = NO; @@ -470,6 +473,8 @@ [fWebSeedTable reloadData]; } [self setWebSeedTableHidden: !hasWebSeeds animate: YES]; + + fSet = YES; } - (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate diff --git a/macosx/InfoTrackersViewController.h b/macosx/InfoTrackersViewController.h index 319e0d46d..ffe70db6e 100644 --- a/macosx/InfoTrackersViewController.h +++ b/macosx/InfoTrackersViewController.h @@ -32,6 +32,8 @@ { NSArray * fTorrents; + BOOL fSet; + NSMutableArray * fTrackers; IBOutlet TrackerTableView * fTrackerTable; diff --git a/macosx/InfoTrackersViewController.m b/macosx/InfoTrackersViewController.m index 3ce31a1c3..5c5a78750 100644 --- a/macosx/InfoTrackersViewController.m +++ b/macosx/InfoTrackersViewController.m @@ -36,6 +36,8 @@ @interface InfoTrackersViewController (Private) +- (void) setupInfo; + - (void) addTrackers; - (void) removeTrackers; @@ -70,36 +72,14 @@ [fTorrents release]; fTorrents = [torrents retain]; - const NSUInteger numberSelected = [fTorrents count]; - if (numberSelected != 1) - { - if (numberSelected == 0) - { - [fTrackers release]; - fTrackers = nil; - - [fTrackerTable setTrackers: nil]; - [fTrackerTable reloadData]; - } - - [fTrackerTable setTorrent: nil]; - - [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_ADD_TAG]; - [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG]; - } - else - { - [fTrackerTable setTorrent: [fTorrents objectAtIndex: 0]]; - - [fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG]; - [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG]; - } - - [fTrackerTable deselectAll: self]; + fSet = NO; } - (void) updateInfo { + if (!fSet) + [self setupInfo]; + if ([fTorrents count] == 0) return; @@ -246,6 +226,38 @@ @implementation InfoTrackersViewController (Private) +- (void) setupInfo +{ + const NSUInteger numberSelected = [fTorrents count]; + if (numberSelected != 1) + { + if (numberSelected == 0) + { + [fTrackers release]; + fTrackers = nil; + + [fTrackerTable setTrackers: nil]; + [fTrackerTable reloadData]; + } + + [fTrackerTable setTorrent: nil]; + + [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_ADD_TAG]; + [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG]; + } + else + { + [fTrackerTable setTorrent: [fTorrents objectAtIndex: 0]]; + + [fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG]; + [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG]; + } + + [fTrackerTable deselectAll: self]; + + fSet = YES; +} + #warning doesn't like blank addresses - (void) addTrackers { diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 4f9e6e5c9..6e31d4153 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -77,13 +77,14 @@ typedef enum //window location and size NSPanel * window = (NSPanel *)[self window]; - CGFloat windowHeight = [window frame].size.height; + const CGFloat windowHeight = NSHeight([window frame]); + #warning check if this is still needed [window setFrameAutosaveName: @"InspectorWindow"]; [window setFrameUsingName: @"InspectorWindow"]; NSRect windowRect = [window frame]; - windowRect.origin.y -= windowHeight - windowRect.size.height; + windowRect.origin.y -= windowHeight - NSHeight(windowRect); windowRect.size.height = windowHeight; [window setFrame: windowRect display: NO]; @@ -196,6 +197,9 @@ typedef enum case TAB_FILE_TAG: [fFileViewController updateInfo]; break; + case TAB_OPTIONS_TAG: + [fOptionsViewController updateInfo]; + break; } } @@ -277,21 +281,30 @@ typedef enum { case TAB_GENERAL_TAG: if (!fGeneralViewController) + { fGeneralViewController = [[InfoGeneralViewController alloc] init]; + [fGeneralViewController setInfoForTorrents: fTorrents]; + } identifier = TAB_INFO_IDENT; title = NSLocalizedString(@"General Info", "Inspector -> title"); break; case TAB_ACTIVITY_TAG: if (!fActivityViewController) + { fActivityViewController = [[InfoActivityViewController alloc] init]; + [fActivityViewController setInfoForTorrents: fTorrents]; + } identifier = TAB_ACTIVITY_IDENT; title = NSLocalizedString(@"Activity", "Inspector -> title"); break; case TAB_TRACKERS_TAG: if (!fTrackersViewController) + { fTrackersViewController = [[InfoTrackersViewController alloc] init]; + [fTrackersViewController setInfoForTorrents: fTorrents]; + } identifier = TAB_TRACKER_IDENT; title = NSLocalizedString(@"Trackers", "Inspector -> title"); @@ -299,7 +312,10 @@ typedef enum break; case TAB_PEERS_TAG: if (!fPeersViewController) + { fPeersViewController = [[InfoPeersViewController alloc] init]; + [fPeersViewController setInfoForTorrents: fTorrents]; + } identifier = TAB_PEERS_IDENT; title = NSLocalizedString(@"Peers", "Inspector -> title"); @@ -307,7 +323,10 @@ typedef enum break; case TAB_FILE_TAG: if (!fFileViewController) + { fFileViewController = [[InfoFileViewController alloc] init]; + [fFileViewController setInfoForTorrents: fTorrents]; + } identifier = TAB_FILES_IDENT; title = NSLocalizedString(@"Files", "Inspector -> title"); @@ -315,7 +334,10 @@ typedef enum break; case TAB_OPTIONS_TAG: if (!fOptionsViewController) + { fOptionsViewController = [[InfoOptionsViewController alloc] init]; + [fOptionsViewController setInfoForTorrents: fTorrents]; + } identifier = TAB_OPTIONS_IDENT; title = NSLocalizedString(@"Options", "Inspector -> title"); @@ -336,14 +358,6 @@ typedef enum NSView * view = [self tabViewForTag: fCurrentTabTag]; - //if view was just loaded - has to be a better way - [fGeneralViewController setInfoForTorrents: fTorrents]; - [fActivityViewController setInfoForTorrents: fTorrents]; - [fTrackersViewController setInfoForTorrents: fTorrents]; - [fPeersViewController setInfoForTorrents: fTorrents]; - [fFileViewController setInfoForTorrents: fTorrents]; - [fOptionsViewController setInfoForTorrents: fTorrents]; - [self updateInfoStats]; NSRect windowRect = [window frame], viewRect = [view frame];