2006-05-29 21:21:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Transmission authors and contributors
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
2006-05-25 12:22:19 +00:00
|
|
|
|
|
|
|
#import "InfoWindowController.h"
|
|
|
|
#import "StringAdditions.h"
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
#define RATIO_NO_CHECK_TAG 0
|
|
|
|
#define RATIO_GLOBAL_TAG 1
|
|
|
|
#define RATIO_CHECK_TAG 2
|
|
|
|
|
2006-06-20 00:06:08 +00:00
|
|
|
#define MIN_WINDOW_WIDTH 270
|
|
|
|
#define MAX_WINDOW_WIDTH 2000
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
#define TAB_INFO_IDENT @"Info"
|
2006-06-20 17:19:15 +00:00
|
|
|
#define TAB_ACTIVITY_IDENT @"Activity"
|
2006-06-06 18:05:57 +00:00
|
|
|
#define TAB_OPTIONS_IDENT @"Options"
|
|
|
|
#define TAB_FILES_IDENT @"Files"
|
|
|
|
|
2006-06-14 03:00:27 +00:00
|
|
|
//15 spacing at the bottom of each tab
|
2006-06-23 19:00:07 +00:00
|
|
|
#define TAB_INFO_HEIGHT 182.0
|
|
|
|
#define TAB_ACTIVITY_HEIGHT 198.0
|
|
|
|
#define TAB_OPTIONS_HEIGHT 116.0
|
2006-06-06 18:05:57 +00:00
|
|
|
#define TAB_FILES_HEIGHT 250.0
|
|
|
|
|
2006-06-22 00:10:37 +00:00
|
|
|
@interface InfoWindowController (Private)
|
|
|
|
|
|
|
|
- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-05-25 12:22:19 +00:00
|
|
|
@implementation InfoWindowController
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
fAppIcon = [[NSApp applicationIconImage] copy];
|
2006-06-06 18:05:57 +00:00
|
|
|
|
2006-06-22 02:51:59 +00:00
|
|
|
fTorrents = [[NSArray alloc] init];
|
2006-06-06 18:05:57 +00:00
|
|
|
fFiles = [[NSMutableArray alloc] initWithCapacity: 6];
|
|
|
|
[fFileTable setDoubleAction: @selector(revealFile:)];
|
|
|
|
|
|
|
|
//window location and size
|
2006-06-10 20:51:15 +00:00
|
|
|
NSPanel * window = (NSPanel *)[self window];
|
|
|
|
|
|
|
|
[window setBecomesKeyOnlyIfNeeded: YES];
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
[window setFrameAutosaveName: @"InspectorWindowFrame"];
|
2006-06-20 03:54:35 +00:00
|
|
|
[window setFrameUsingName: @"InspectorWindowFrame"];
|
2006-06-06 18:05:57 +00:00
|
|
|
|
2006-06-22 00:10:37 +00:00
|
|
|
NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InfoTab"];
|
|
|
|
[fTabView selectTabViewItemWithIdentifier: identifier];
|
|
|
|
[self setWindowForTab: identifier animate: NO];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-06-22 02:51:59 +00:00
|
|
|
[fTorrents release];
|
2006-06-06 18:05:57 +00:00
|
|
|
[fFiles release];
|
|
|
|
|
2006-05-25 12:22:19 +00:00
|
|
|
[fAppIcon release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfoForTorrents: (NSArray *) torrents
|
|
|
|
{
|
2006-06-22 02:51:59 +00:00
|
|
|
[fTorrents release];
|
2006-06-06 18:05:57 +00:00
|
|
|
fTorrents = [torrents retain];
|
|
|
|
|
|
|
|
int numberSelected = [fTorrents count];
|
2006-05-25 12:22:19 +00:00
|
|
|
if (numberSelected != 1)
|
|
|
|
{
|
|
|
|
if (numberSelected > 0)
|
|
|
|
{
|
2006-06-06 18:05:57 +00:00
|
|
|
[fNameField setStringValue: [NSString stringWithFormat:
|
|
|
|
@"%d Torrents Selected", numberSelected]];
|
2006-05-25 12:22:19 +00:00
|
|
|
|
|
|
|
uint64_t size = 0;
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
size += [torrent size];
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
[fSizeField setStringValue: [[NSString stringForFileSize: size]
|
|
|
|
stringByAppendingString: @" Total"]];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-06 18:05:57 +00:00
|
|
|
[fNameField setStringValue: @"No Torrents Selected"];
|
|
|
|
[fSizeField setStringValue: @""];
|
|
|
|
|
2006-06-20 17:10:35 +00:00
|
|
|
/*
|
2006-06-06 18:05:57 +00:00
|
|
|
[fDownloadRateField setStringValue: @""];
|
|
|
|
[fUploadRateField setStringValue: @""];
|
2006-06-20 17:10:35 +00:00
|
|
|
*/
|
2006-06-14 03:00:27 +00:00
|
|
|
[fDownloadedValidField setStringValue: @""];
|
|
|
|
[fDownloadedTotalField setStringValue: @""];
|
|
|
|
[fUploadedTotalField setStringValue: @""];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
2006-06-06 18:05:57 +00:00
|
|
|
|
|
|
|
[fImageView setImage: fAppIcon];
|
|
|
|
|
|
|
|
[fNameField setToolTip: nil];
|
|
|
|
|
|
|
|
[fTrackerField setStringValue: @""];
|
|
|
|
[fTrackerField setToolTip: nil];
|
|
|
|
[fAnnounceField setStringValue: @""];
|
|
|
|
[fAnnounceField setToolTip: nil];
|
|
|
|
[fPieceSizeField setStringValue: @""];
|
|
|
|
[fPiecesField setStringValue: @""];
|
|
|
|
[fHashField setStringValue: @""];
|
2006-06-20 02:57:48 +00:00
|
|
|
[fHashField setToolTip: nil];
|
2006-06-06 18:05:57 +00:00
|
|
|
|
|
|
|
[fTorrentLocationField setStringValue: @""];
|
|
|
|
[fTorrentLocationField setToolTip: nil];
|
|
|
|
[fDataLocationField setStringValue: @""];
|
|
|
|
[fDataLocationField setToolTip: nil];
|
|
|
|
[fDateStartedField setStringValue: @""];
|
|
|
|
|
2006-06-20 17:10:35 +00:00
|
|
|
/*
|
2006-06-06 18:05:57 +00:00
|
|
|
[fStateField setStringValue: @""];
|
|
|
|
[fPercentField setStringValue: @""];
|
2006-06-20 17:10:35 +00:00
|
|
|
*/
|
2006-06-06 18:05:57 +00:00
|
|
|
[fRatioField setStringValue: @""];
|
|
|
|
|
|
|
|
[fSeedersField setStringValue: @""];
|
|
|
|
[fLeechersField setStringValue: @""];
|
|
|
|
[fConnectedPeersField setStringValue: @""];
|
|
|
|
[fDownloadingFromField setStringValue: @""];
|
|
|
|
[fUploadingToField setStringValue: @""];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-06 18:05:57 +00:00
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2006-05-25 12:22:19 +00:00
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
[fImageView setImage: [torrent icon]];
|
2006-05-25 12:22:19 +00:00
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
NSString * name = [torrent name];
|
|
|
|
[fNameField setStringValue: name];
|
|
|
|
[fNameField setToolTip: name];
|
|
|
|
[fSizeField setStringValue: [NSString stringForFileSize: [torrent size]]];
|
|
|
|
|
2006-06-20 02:57:48 +00:00
|
|
|
NSString * tracker = [torrent tracker],
|
|
|
|
* announce = [torrent announce],
|
|
|
|
* hashString = [torrent hashString];
|
2006-06-06 18:05:57 +00:00
|
|
|
[fTrackerField setStringValue: tracker];
|
|
|
|
[fTrackerField setToolTip: tracker];
|
|
|
|
[fAnnounceField setStringValue: announce];
|
|
|
|
[fAnnounceField setToolTip: announce];
|
|
|
|
[fPieceSizeField setStringValue: [NSString stringForFileSize: [torrent pieceSize]]];
|
|
|
|
[fPiecesField setIntValue: [torrent pieceCount]];
|
2006-06-20 02:57:48 +00:00
|
|
|
[fHashField setStringValue: hashString];
|
|
|
|
[fHashField setToolTip: hashString];
|
2006-06-06 18:05:57 +00:00
|
|
|
|
2006-06-20 03:00:39 +00:00
|
|
|
[fTorrentLocationField setStringValue: [torrent torrentLocationString]];
|
2006-06-06 18:05:57 +00:00
|
|
|
[fTorrentLocationField setToolTip: [torrent torrentLocation]];
|
2006-06-20 03:00:39 +00:00
|
|
|
[fDataLocationField setStringValue: [[torrent dataLocation] stringByAbbreviatingWithTildeInPath]];
|
2006-06-06 18:05:57 +00:00
|
|
|
[fDataLocationField setToolTip: [torrent dataLocation]];
|
|
|
|
[fDateStartedField setObjectValue: [torrent date]];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
2006-06-06 18:05:57 +00:00
|
|
|
[self updateInfoStats];
|
2006-05-25 12:22:19 +00:00
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
//set file table
|
|
|
|
[fFiles removeAllObjects];
|
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[fFiles addObjectsFromArray: [torrent fileList]];
|
|
|
|
|
|
|
|
[fFileTable deselectAll: nil];
|
|
|
|
[fFileTable reloadData];
|
|
|
|
|
2006-06-23 19:00:07 +00:00
|
|
|
//set wait to start
|
2006-07-01 21:34:53 +00:00
|
|
|
BOOL waiting = NO, notWaiting = NO, canEnableWaiting = numberSelected > 0,
|
|
|
|
waitingSettingOn = [[[NSUserDefaults standardUserDefaults] stringForKey: @"StartSetting"]
|
|
|
|
isEqualToString: @"Wait"];
|
|
|
|
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2006-06-23 19:00:07 +00:00
|
|
|
{
|
2006-07-01 21:34:53 +00:00
|
|
|
if ([torrent waitingToStart])
|
|
|
|
waiting = YES;
|
|
|
|
else
|
|
|
|
notWaiting = YES;
|
|
|
|
|
|
|
|
if (canEnableWaiting && !(![torrent isActive] && [torrent progress] < 1.0 && waitingSettingOn))
|
|
|
|
canEnableWaiting = NO;
|
2006-06-23 19:00:07 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 21:34:53 +00:00
|
|
|
[fWaitToStartButton setState: waiting && notWaiting ? NSMixedState : (waiting ? NSOnState : NSOffState)];
|
|
|
|
[fWaitToStartButton setEnabled: canEnableWaiting];
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
//set ratio settings
|
|
|
|
if (numberSelected > 0)
|
|
|
|
{
|
2006-07-01 21:34:53 +00:00
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
2006-06-06 18:05:57 +00:00
|
|
|
const int INVALID = -99;
|
|
|
|
int ratioSetting = [torrent stopRatioSetting];
|
|
|
|
float ratioLimit = [torrent ratioLimit];
|
|
|
|
|
|
|
|
while ((ratioSetting != INVALID || ratioLimit != INVALID)
|
|
|
|
&& (torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if (ratioSetting != INVALID && ratioSetting != [torrent stopRatioSetting])
|
|
|
|
ratioSetting = INVALID;
|
|
|
|
|
|
|
|
if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
|
|
|
|
ratioLimit = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fRatioMatrix setEnabled: YES];
|
|
|
|
|
|
|
|
if (ratioSetting == RATIO_CHECK)
|
|
|
|
{
|
|
|
|
[fRatioMatrix selectCellWithTag: RATIO_CHECK_TAG];
|
|
|
|
[fRatioLimitField setEnabled: YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ratioSetting == RATIO_NO_CHECK)
|
|
|
|
[fRatioMatrix selectCellWithTag: RATIO_NO_CHECK_TAG];
|
|
|
|
else if (ratioSetting == RATIO_GLOBAL)
|
|
|
|
[fRatioMatrix selectCellWithTag: RATIO_GLOBAL_TAG];
|
|
|
|
else
|
|
|
|
[fRatioMatrix deselectAllCells];
|
|
|
|
|
|
|
|
[fRatioLimitField setEnabled: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ratioLimit != INVALID)
|
|
|
|
[fRatioLimitField setFloatValue: ratioLimit];
|
|
|
|
else
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fRatioMatrix deselectAllCells];
|
|
|
|
[fRatioMatrix setEnabled: NO];
|
|
|
|
|
|
|
|
[fRatioLimitField setEnabled: NO];
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
|
|
|
}
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
- (void) updateInfoStats
|
2006-05-25 12:22:19 +00:00
|
|
|
{
|
2006-06-06 18:05:57 +00:00
|
|
|
int numberSelected = [fTorrents count];
|
2006-05-25 12:22:19 +00:00
|
|
|
if (numberSelected > 0)
|
|
|
|
{
|
2006-06-20 17:10:35 +00:00
|
|
|
//float downloadRate = 0, uploadRate = 0;
|
|
|
|
float downloadedValid = 0;
|
2006-06-14 03:00:27 +00:00
|
|
|
uint64_t downloadedTotal = 0, uploadedTotal = 0;
|
2006-05-25 12:22:19 +00:00
|
|
|
Torrent * torrent;
|
2006-06-06 18:05:57 +00:00
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
2006-06-20 17:10:35 +00:00
|
|
|
/*downloadRate += [torrent downloadRate];
|
2006-06-06 18:05:57 +00:00
|
|
|
uploadRate += [torrent uploadRate];
|
2006-06-20 17:10:35 +00:00
|
|
|
*/
|
2006-06-14 03:00:27 +00:00
|
|
|
downloadedValid += [torrent downloadedValid];
|
|
|
|
downloadedTotal += [torrent downloadedTotal];
|
|
|
|
uploadedTotal += [torrent uploadedTotal];
|
2006-06-06 18:05:57 +00:00
|
|
|
}
|
2006-06-20 17:10:35 +00:00
|
|
|
/*
|
2006-06-06 18:05:57 +00:00
|
|
|
[fDownloadRateField setStringValue: [NSString stringForSpeed: downloadRate]];
|
|
|
|
[fUploadRateField setStringValue: [NSString stringForSpeed: uploadRate]];
|
2006-06-20 17:10:35 +00:00
|
|
|
*/
|
2006-06-14 03:00:27 +00:00
|
|
|
[fDownloadedValidField setStringValue: [NSString stringForFileSize: downloadedValid]];
|
|
|
|
[fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
|
|
|
|
[fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
|
2006-06-06 18:05:57 +00:00
|
|
|
|
2006-05-25 12:22:19 +00:00
|
|
|
if (numberSelected == 1)
|
2006-06-06 18:05:57 +00:00
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: 0];
|
2006-06-20 17:10:35 +00:00
|
|
|
/*
|
2006-06-06 18:05:57 +00:00
|
|
|
[fStateField setStringValue: [torrent state]];
|
|
|
|
[fPercentField setStringValue: [NSString stringWithFormat:
|
2006-06-16 00:35:11 +00:00
|
|
|
@"%.2f%%", 100.0 * [torrent progress]]];
|
2006-06-20 17:10:35 +00:00
|
|
|
*/
|
2006-05-25 12:22:19 +00:00
|
|
|
int seeders = [torrent seeders], leechers = [torrent leechers];
|
2006-06-06 18:05:57 +00:00
|
|
|
[fSeedersField setStringValue: seeders < 0 ?
|
|
|
|
@"N/A" : [NSString stringWithInt: seeders]];
|
|
|
|
[fLeechersField setStringValue: leechers < 0 ?
|
|
|
|
@"N/A" : [NSString stringWithInt: leechers]];
|
|
|
|
|
|
|
|
BOOL active = [torrent isActive];
|
|
|
|
|
|
|
|
[fConnectedPeersField setStringValue: active ? [NSString
|
|
|
|
stringWithInt: [torrent totalPeers]] : @"N/A"];
|
|
|
|
[fDownloadingFromField setStringValue: active ? [NSString
|
|
|
|
stringWithInt: [torrent peersUploading]] : @"N/A"];
|
|
|
|
[fUploadingToField setStringValue: active ? [NSString
|
|
|
|
stringWithInt: [torrent peersDownloading]] : @"N/A"];
|
|
|
|
|
|
|
|
[fRatioField setStringValue: [NSString stringForRatioWithDownload:
|
2006-06-14 03:00:27 +00:00
|
|
|
downloadedTotal upload: uploadedTotal]];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
2006-06-06 18:05:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
|
|
|
|
{
|
|
|
|
SEL action = [menuItem action];
|
2006-05-25 12:22:19 +00:00
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
if (action == @selector(revealFile:))
|
|
|
|
return [fFileTable numberOfSelectedRows] > 0 &&
|
|
|
|
[[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-06-20 00:36:51 +00:00
|
|
|
- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
|
|
|
|
{
|
2006-06-20 03:08:46 +00:00
|
|
|
NSRect windowRect = [window frame];
|
2006-06-22 02:51:59 +00:00
|
|
|
windowRect.size.width = [window minSize].width;
|
2006-06-20 03:08:46 +00:00
|
|
|
return windowRect;
|
2006-06-20 00:36:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
- (void) tabView: (NSTabView *) tabView didSelectTabViewItem: (NSTabViewItem *) tabViewItem
|
2006-06-22 00:10:37 +00:00
|
|
|
{
|
|
|
|
NSString * identifier = [tabViewItem identifier];
|
|
|
|
[self setWindowForTab: identifier animate: YES];
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InfoTab"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate
|
2006-06-06 18:05:57 +00:00
|
|
|
{
|
|
|
|
float height;
|
2006-06-22 00:10:37 +00:00
|
|
|
if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
|
2006-06-20 17:19:15 +00:00
|
|
|
height = TAB_ACTIVITY_HEIGHT;
|
2006-06-06 18:05:57 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
|
|
|
|
height = TAB_OPTIONS_HEIGHT;
|
2006-06-22 00:10:37 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_FILES_IDENT])
|
2006-06-06 18:05:57 +00:00
|
|
|
height = TAB_FILES_HEIGHT;
|
2006-06-22 00:10:37 +00:00
|
|
|
else
|
|
|
|
height = TAB_INFO_HEIGHT;
|
2006-06-06 18:05:57 +00:00
|
|
|
|
2006-06-22 02:51:59 +00:00
|
|
|
NSWindow * window = [self window];
|
|
|
|
NSRect frame = [window frame];
|
2006-06-22 00:10:37 +00:00
|
|
|
NSView * view = [[fTabView selectedTabViewItem] view];
|
2006-06-22 02:51:59 +00:00
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
float difference = height - [view frame].size.height;
|
|
|
|
frame.origin.y -= difference;
|
|
|
|
frame.size.height += difference;
|
|
|
|
|
2006-06-22 00:10:37 +00:00
|
|
|
if (animate)
|
|
|
|
{
|
|
|
|
[view setHidden: YES];
|
|
|
|
[window setFrame: frame display: YES animate: YES];
|
|
|
|
[view setHidden: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[window setFrame: frame display: YES];
|
2006-06-20 00:36:51 +00:00
|
|
|
|
|
|
|
[window setMinSize: NSMakeSize(MIN_WINDOW_WIDTH, frame.size.height)];
|
|
|
|
[window setMaxSize: NSMakeSize(MAX_WINDOW_WIDTH, frame.size.height)];
|
2006-06-06 18:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNextTab
|
|
|
|
{
|
|
|
|
if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]]
|
|
|
|
== [fTabView numberOfTabViewItems] - 1)
|
|
|
|
[fTabView selectFirstTabViewItem: nil];
|
|
|
|
else
|
|
|
|
[fTabView selectNextTabViewItem: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPreviousTab
|
|
|
|
{
|
|
|
|
if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == 0)
|
|
|
|
[fTabView selectLastTabViewItem: nil];
|
|
|
|
else
|
|
|
|
[fTabView selectPreviousTabViewItem: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) numberOfRowsInTableView: (NSTableView *) tableView
|
|
|
|
{
|
|
|
|
return [fFiles count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn:
|
|
|
|
(NSTableColumn *) column row: (int) row
|
|
|
|
{
|
|
|
|
NSString * file = [fFiles objectAtIndex: row];
|
|
|
|
if ([[column identifier] isEqualToString: @"Icon"])
|
|
|
|
return [[NSWorkspace sharedWorkspace] iconForFileType: [file pathExtension]];
|
|
|
|
else
|
|
|
|
return [file lastPathComponent];
|
|
|
|
}
|
|
|
|
|
|
|
|
//only called on >= 10.4
|
|
|
|
- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell
|
|
|
|
rect: (NSRectPointer) rect tableColumn: (NSTableColumn *) column
|
|
|
|
row: (int) row mouseLocation: (NSPoint) mouseLocation
|
|
|
|
{
|
|
|
|
return [fFiles objectAtIndex: row];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealFile: (id) sender
|
|
|
|
{
|
2006-06-15 05:44:01 +00:00
|
|
|
NSIndexSet * indexSet = [fFileTable selectedRowIndexes];
|
|
|
|
unsigned int i;
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: [fFiles objectAtIndex: i]
|
2006-06-06 18:05:57 +00:00
|
|
|
inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioCheck: (id) sender
|
|
|
|
{
|
2006-06-23 15:06:27 +00:00
|
|
|
int ratioSetting, tag = [[fRatioMatrix selectedCell] tag];
|
|
|
|
if (tag == RATIO_CHECK_TAG)
|
2006-06-06 18:05:57 +00:00
|
|
|
ratioSetting = RATIO_CHECK;
|
2006-06-23 15:06:27 +00:00
|
|
|
else if (tag == RATIO_NO_CHECK_TAG)
|
2006-06-06 18:05:57 +00:00
|
|
|
ratioSetting = RATIO_NO_CHECK;
|
|
|
|
else
|
|
|
|
ratioSetting = RATIO_GLOBAL;
|
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setStopRatioSetting: ratioSetting];
|
|
|
|
|
|
|
|
[self setRatioLimit: fRatioLimitField];
|
2006-06-23 15:06:27 +00:00
|
|
|
[fRatioLimitField setEnabled: tag == RATIO_CHECK_TAG];
|
2006-06-06 18:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioLimit: (id) sender
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
|
|
|
|
float ratioLimit = [sender floatValue];
|
2006-06-20 17:19:15 +00:00
|
|
|
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]]
|
2006-06-06 18:05:57 +00:00
|
|
|
|| ratioLimit < 0)
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
float ratioLimit = [[enumerator nextObject] ratioLimit]; //use first torrent
|
2006-05-25 12:22:19 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
2006-06-06 18:05:57 +00:00
|
|
|
if (ratioLimit != [torrent ratioLimit])
|
|
|
|
{
|
|
|
|
[sender setStringValue: @""];
|
|
|
|
return;
|
|
|
|
}
|
2006-05-25 12:22:19 +00:00
|
|
|
|
2006-06-06 18:05:57 +00:00
|
|
|
[sender setFloatValue: ratioLimit];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setRatioLimit: ratioLimit];
|
2006-05-25 12:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-23 19:00:07 +00:00
|
|
|
- (void) setWaitToStart: (id) sender
|
|
|
|
{
|
2006-07-01 21:34:53 +00:00
|
|
|
int state = [sender state];
|
|
|
|
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setWaitToStart: state];
|
2006-06-23 19:00:07 +00:00
|
|
|
|
2006-07-01 21:34:53 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStartSettingChange" object: fTorrents];
|
2006-06-23 19:00:07 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 12:22:19 +00:00
|
|
|
@end
|