2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-02 16:55:05 +00:00
|
|
|
* Copyright (c) 2005-2008 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 <IOKit/IOMessage.h>
|
|
|
|
|
|
|
|
#import "Controller.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
#import "TorrentCell.h"
|
|
|
|
#import "TorrentTableView.h"
|
|
|
|
#import "CreatorWindowController.h"
|
2007-11-19 18:13:41 +00:00
|
|
|
#import "StatsWindowController.h"
|
2008-05-21 15:23:26 +00:00
|
|
|
#import "QuickLookController.h"
|
2007-12-17 16:06:20 +00:00
|
|
|
#import "GroupsWindowController.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "AboutWindowController.h"
|
2007-11-29 01:05:11 +00:00
|
|
|
#import "ButtonToolbarItem.h"
|
2007-12-07 06:27:42 +00:00
|
|
|
#import "GroupToolbarItem.h"
|
2008-04-22 13:25:53 +00:00
|
|
|
#import "ToolbarSegmentedCell.h"
|
2007-10-29 18:59:23 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2007-12-17 16:06:20 +00:00
|
|
|
#import "NSMenuAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "ExpandedPathToPathTransformer.h"
|
|
|
|
#import "ExpandedPathToIconTransformer.h"
|
|
|
|
#import "SpeedLimitToTurtleIconTransformer.h"
|
2008-03-04 03:27:25 +00:00
|
|
|
#include "utils.h" //tr_getRatio()
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-06 01:53:15 +00:00
|
|
|
#import "UKKQueue.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import <Sparkle/Sparkle.h>
|
|
|
|
|
2007-12-06 17:21:42 +00:00
|
|
|
#define TOOLBAR_CREATE @"Toolbar Create"
|
2008-02-07 20:34:14 +00:00
|
|
|
#define TOOLBAR_OPEN_FILE @"Toolbar Open"
|
|
|
|
#define TOOLBAR_OPEN_WEB @"Toolbar Open Web"
|
2007-12-06 17:21:42 +00:00
|
|
|
#define TOOLBAR_REMOVE @"Toolbar Remove"
|
|
|
|
#define TOOLBAR_INFO @"Toolbar Info"
|
|
|
|
#define TOOLBAR_PAUSE_ALL @"Toolbar Pause All"
|
|
|
|
#define TOOLBAR_RESUME_ALL @"Toolbar Resume All"
|
|
|
|
#define TOOLBAR_PAUSE_RESUME_ALL @"Toolbar Pause / Resume All"
|
|
|
|
#define TOOLBAR_PAUSE_SELECTED @"Toolbar Pause Selected"
|
|
|
|
#define TOOLBAR_RESUME_SELECTED @"Toolbar Resume Selected"
|
|
|
|
#define TOOLBAR_PAUSE_RESUME_SELECTED @"Toolbar Pause / Resume Selected"
|
|
|
|
#define TOOLBAR_FILTER @"Toolbar Toggle Filter"
|
2008-05-21 16:02:38 +00:00
|
|
|
#define TOOLBAR_QUICKLOOK @"Toolbar QuickLook"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-06 20:25:38 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TOOLBAR_PAUSE_TAG = 0,
|
|
|
|
TOOLBAR_RESUME_TAG = 1
|
|
|
|
} toolbarGroupTag;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#define SORT_DATE @"Date"
|
|
|
|
#define SORT_NAME @"Name"
|
|
|
|
#define SORT_STATE @"State"
|
|
|
|
#define SORT_PROGRESS @"Progress"
|
|
|
|
#define SORT_TRACKER @"Tracker"
|
|
|
|
#define SORT_ORDER @"Order"
|
2007-11-21 18:32:41 +00:00
|
|
|
#define SORT_ACTIVITY @"Activity"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-11-07 05:02:43 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SORT_ORDER_TAG = 0,
|
|
|
|
SORT_DATE_TAG = 1,
|
|
|
|
SORT_NAME_TAG = 2,
|
|
|
|
SORT_PROGRESS_TAG = 3,
|
|
|
|
SORT_STATE_TAG = 4,
|
2007-11-21 18:32:41 +00:00
|
|
|
SORT_TRACKER_TAG = 5,
|
2007-11-21 20:10:49 +00:00
|
|
|
SORT_ACTIVITY_TAG = 6
|
2007-11-07 05:02:43 +00:00
|
|
|
} sortTag;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#define FILTER_NONE @"None"
|
2007-12-20 04:49:06 +00:00
|
|
|
#define FILTER_ACTIVE @"Active"
|
2007-09-16 01:02:06 +00:00
|
|
|
#define FILTER_DOWNLOAD @"Download"
|
|
|
|
#define FILTER_SEED @"Seed"
|
|
|
|
#define FILTER_PAUSE @"Pause"
|
|
|
|
|
|
|
|
#define FILTER_TYPE_NAME @"Name"
|
|
|
|
#define FILTER_TYPE_TRACKER @"Tracker"
|
|
|
|
|
|
|
|
#define FILTER_TYPE_TAG_NAME 401
|
|
|
|
#define FILTER_TYPE_TAG_TRACKER 402
|
|
|
|
|
2007-12-19 20:46:00 +00:00
|
|
|
#define GROUP_FILTER_ALL_TAG -2
|
|
|
|
|
2007-12-05 01:26:30 +00:00
|
|
|
#define STATUS_RATIO_TOTAL @"RatioTotal"
|
|
|
|
#define STATUS_RATIO_SESSION @"RatioSession"
|
|
|
|
#define STATUS_TRANSFER_TOTAL @"TransferTotal"
|
|
|
|
#define STATUS_TRANSFER_SESSION @"TransferSession"
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
STATUS_RATIO_TOTAL_TAG = 0,
|
|
|
|
STATUS_RATIO_SESSION_TAG = 1,
|
|
|
|
STATUS_TRANSFER_TOTAL_TAG = 2,
|
|
|
|
STATUS_TRANSFER_SESSION_TAG = 3
|
|
|
|
} statusTag;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#define GROWL_DOWNLOAD_COMPLETE @"Download Complete"
|
|
|
|
#define GROWL_SEEDING_COMPLETE @"Seeding Complete"
|
|
|
|
#define GROWL_AUTO_ADD @"Torrent Auto Added"
|
|
|
|
#define GROWL_AUTO_SPEED_LIMIT @"Speed Limit Auto Changed"
|
|
|
|
|
|
|
|
#define TORRENT_TABLE_VIEW_DATA_TYPE @"TorrentTableViewDataType"
|
|
|
|
|
2008-01-17 01:57:14 +00:00
|
|
|
#define ROW_HEIGHT_REGULAR 62.0
|
|
|
|
#define ROW_HEIGHT_SMALL 38.0
|
2007-09-16 01:02:06 +00:00
|
|
|
#define WINDOW_REGULAR_WIDTH 468.0
|
|
|
|
|
2007-12-20 05:12:23 +00:00
|
|
|
#define SEARCH_FILTER_MIN_WIDTH 48.0
|
2007-12-20 04:49:06 +00:00
|
|
|
#define SEARCH_FILTER_MAX_WIDTH 95.0
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-06-19 02:53:45 +00:00
|
|
|
#define UPDATE_UI_SECONDS 1.0
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
#define DOCK_SEEDING_TAG 101
|
|
|
|
#define DOCK_DOWNLOADING_TAG 102
|
|
|
|
|
2007-10-21 14:01:54 +00:00
|
|
|
#define SUPPORT_FOLDER @"/Library/Application Support/Transmission/Transfers.plist"
|
|
|
|
|
2007-12-30 18:53:44 +00:00
|
|
|
#define WEBSITE_URL @"http://www.transmissionbt.com/"
|
2008-01-06 17:00:38 +00:00
|
|
|
#define FORUM_URL @"http://forum.transmissionbt.com/"
|
2007-12-30 18:53:44 +00:00
|
|
|
#define DONATE_URL @"http://www.transmissionbt.com/donate.php"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
static void rpcCallback(tr_handle * handle UNUSED, tr_rpc_callback_type type, struct tr_torrent * torrentStruct, void * controller)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-20 15:16:34 +00:00
|
|
|
[(Controller *)controller rpcCallback: type forTorrentStruct: torrentStruct];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sleepCallback(void * controller, io_service_t y, natural_t messageType, void * messageArgument)
|
|
|
|
{
|
|
|
|
[(Controller *)controller sleepCallback: messageType argument: messageArgument];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@implementation Controller
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
//make sure another Transmission.app isn't running already
|
|
|
|
NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
|
|
|
|
int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
|
|
|
|
|
|
|
|
NSDictionary * dic;
|
|
|
|
NSEnumerator * enumerator = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator];
|
|
|
|
while ((dic = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
|
|
|
|
&& [[dic objectForKey: @"NSApplicationProcessIdentifier"] intValue] != processIdentifier)
|
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Quit", "Transmission already running alert -> button")];
|
|
|
|
[alert setMessageText: NSLocalizedString(@"Transmission is already running.",
|
|
|
|
"Transmission already running alert -> title")];
|
|
|
|
[alert setInformativeText: NSLocalizedString(@"There is already a copy of Transmission running. "
|
|
|
|
"This copy cannot be opened until that instance is quit.", "Transmission already running alert -> message")];
|
|
|
|
[alert setAlertStyle: NSWarningAlertStyle];
|
|
|
|
|
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
|
|
|
|
|
|
|
//kill ourselves right away
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary dictionaryWithContentsOfFile:
|
|
|
|
[[NSBundle mainBundle] pathForResource: @"Defaults" ofType: @"plist"]]];
|
|
|
|
|
|
|
|
//set custom value transformers
|
2008-03-29 23:38:38 +00:00
|
|
|
ExpandedPathToPathTransformer * pathTransformer = [[[ExpandedPathToPathTransformer alloc] init] autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
[NSValueTransformer setValueTransformer: pathTransformer forName: @"ExpandedPathToPathTransformer"];
|
|
|
|
|
2008-03-29 23:38:38 +00:00
|
|
|
ExpandedPathToIconTransformer * iconTransformer = [[[ExpandedPathToIconTransformer alloc] init] autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
[NSValueTransformer setValueTransformer: iconTransformer forName: @"ExpandedPathToIconTransformer"];
|
|
|
|
|
2008-03-29 23:38:38 +00:00
|
|
|
SpeedLimitToTurtleIconTransformer * speedLimitIconTransformer = [[[SpeedLimitToTurtleIconTransformer alloc] init] autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
[NSValueTransformer setValueTransformer: speedLimitIconTransformer forName: @"SpeedLimitToTurtleIconTransformer"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-12-24 15:29:29 +00:00
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2008-05-19 00:23:06 +00:00
|
|
|
fLib = tr_sessionInitFull(NULL, /* use default config directory (Application Support) */
|
|
|
|
"macosx",
|
2008-06-12 03:59:55 +00:00
|
|
|
NULL, /* download directory set when adding transfers */
|
2008-05-19 00:23:06 +00:00
|
|
|
[fDefaults boolForKey: @"PEXGlobal"],
|
|
|
|
[fDefaults boolForKey: @"NatTraversal"],
|
|
|
|
[fDefaults integerForKey: @"BindPort"],
|
|
|
|
TR_ENCRYPTION_PREFERRED, /* reset in prefs */
|
2008-06-09 21:20:01 +00:00
|
|
|
NO, /* reset in prefs */
|
2008-05-19 00:23:06 +00:00
|
|
|
-1, /* reset in prefs */
|
2008-06-09 21:20:01 +00:00
|
|
|
NO, /* reset in prefs */
|
2008-05-19 00:23:06 +00:00
|
|
|
-1, /* reset in prefs */
|
|
|
|
[fDefaults integerForKey: @"PeersTotal"],
|
|
|
|
[fDefaults integerForKey: @"MessageLevel"],
|
|
|
|
YES,
|
|
|
|
[fDefaults boolForKey: @"Blocklist"],
|
2008-06-09 21:20:01 +00:00
|
|
|
[fDefaults integerForKey: @"PeerSocketTOS"], /* hidden pref - default is TR_DEFAULT_PEER_SOCKET_TOS */
|
2008-05-19 01:05:14 +00:00
|
|
|
[fDefaults boolForKey: @"RPC"],
|
|
|
|
[fDefaults integerForKey: @"RPCPort"],
|
2008-06-08 04:16:06 +00:00
|
|
|
NULL, /* reset in prefs */
|
2008-06-05 16:32:44 +00:00
|
|
|
[fDefaults boolForKey: @"RPCAuthorize"],
|
|
|
|
[[fDefaults stringForKey: @"RPCUsername"] UTF8String],
|
2008-06-13 19:56:09 +00:00
|
|
|
"", /* reset in prefs - from Keychain */
|
2008-06-10 18:08:57 +00:00
|
|
|
[fDefaults boolForKey: @"Proxy"],
|
|
|
|
[[fDefaults stringForKey: @"ProxyAddress"] UTF8String],
|
2008-06-11 21:35:01 +00:00
|
|
|
TR_DEFAULT_PROXY_TYPE, /* reset in prefs */
|
2008-06-10 18:08:57 +00:00
|
|
|
[fDefaults boolForKey: @"ProxyAuthorize"],
|
|
|
|
[[fDefaults stringForKey: @"ProxyUsername"] UTF8String],
|
2008-06-15 20:47:24 +00:00
|
|
|
""); /* reset in prefs - from Keychain */
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-26 04:12:57 +00:00
|
|
|
[NSApp setDelegate: self];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
fTorrents = [[NSMutableArray alloc] init];
|
|
|
|
fDisplayedTorrents = [[NSMutableArray alloc] init];
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
fMessageController = [[MessageWindowController alloc] init];
|
|
|
|
fInfoController = [[InfoWindowController alloc] init];
|
|
|
|
fPrefsController = [[PrefsController alloc] initWithHandle: fLib];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
fBadger = [[Badger alloc] initWithLib: fLib];
|
2008-05-21 15:23:26 +00:00
|
|
|
[QuickLookController quickLookControllerInitializeWithController: self infoController: fInfoController];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-04-10 16:37:07 +00:00
|
|
|
fSoundPlaying = NO;
|
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
tr_sessionSetRPCCallback(fLib, rpcCallback, self);
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[GrowlApplicationBridge setGrowlDelegate: self];
|
|
|
|
[[UKKQueue sharedFileWatcher] setDelegate: self];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2007-12-06 17:21:42 +00:00
|
|
|
NSToolbar * toolbar = [[NSToolbar alloc] initWithIdentifier: @"TRMainToolbar"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[toolbar setDelegate: self];
|
|
|
|
[toolbar setAllowsUserCustomization: YES];
|
|
|
|
[toolbar setAutosavesConfiguration: YES];
|
2007-12-08 18:51:02 +00:00
|
|
|
[toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fWindow setToolbar: toolbar];
|
|
|
|
[toolbar release];
|
|
|
|
|
|
|
|
[fWindow setDelegate: self]; //do manually to avoid placement issue
|
|
|
|
|
|
|
|
[fWindow makeFirstResponder: fTableView];
|
|
|
|
[fWindow setExcludedFromWindowsMenu: YES];
|
|
|
|
|
|
|
|
//set table size
|
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
[fTableView setRowHeight: ROW_HEIGHT_SMALL];
|
|
|
|
|
|
|
|
//window min height
|
|
|
|
NSSize contentMinSize = [fWindow contentMinSize];
|
2008-02-06 23:45:44 +00:00
|
|
|
contentMinSize.height = [[fWindow contentView] frame].size.height - [[fTableView enclosingScrollView] frame].size.height
|
2007-09-16 01:02:06 +00:00
|
|
|
+ [fTableView rowHeight] + [fTableView intercellSpacing].height;
|
|
|
|
[fWindow setContentMinSize: contentMinSize];
|
|
|
|
|
2007-12-12 03:21:11 +00:00
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
2007-12-12 16:28:40 +00:00
|
|
|
{
|
2007-12-12 03:21:11 +00:00
|
|
|
[fWindow setContentBorderThickness: [[fTableView enclosingScrollView] frame].origin.y forEdge: NSMinYEdge];
|
2007-12-12 04:35:38 +00:00
|
|
|
[[fTotalTorrentsField cell] setBackgroundStyle: NSBackgroundStyleRaised];
|
2008-01-06 19:48:48 +00:00
|
|
|
|
|
|
|
[[[fActionButton menu] itemAtIndex: 0] setImage: [NSImage imageNamed: NSImageNameActionTemplate]]; //set in nib if Leopard-only
|
2008-02-08 13:37:15 +00:00
|
|
|
|
|
|
|
[fBottomTigerLine removeFromSuperview];
|
|
|
|
[fStatusTigerField removeFromSuperview];
|
|
|
|
[fStatusTigerImageView removeFromSuperview];
|
2007-12-12 16:28:40 +00:00
|
|
|
}
|
|
|
|
else
|
2007-12-12 01:51:21 +00:00
|
|
|
{
|
2007-12-15 21:29:47 +00:00
|
|
|
[fActionButton setBezelStyle: NSSmallSquareBezelStyle];
|
|
|
|
[fSpeedLimitButton setBezelStyle: NSSmallSquareBezelStyle];
|
|
|
|
|
2007-12-12 16:28:40 +00:00
|
|
|
//status bar
|
|
|
|
[fStatusButton setHidden: YES];
|
|
|
|
[fStatusTigerField setHidden: NO];
|
|
|
|
[fStatusTigerImageView setHidden: NO];
|
2007-12-21 17:41:27 +00:00
|
|
|
|
|
|
|
//filter bar
|
|
|
|
[fNoFilterButton sizeToFit];
|
|
|
|
|
|
|
|
NSRect activeRect = [fActiveFilterButton frame];
|
|
|
|
activeRect.origin.x = NSMaxX([fNoFilterButton frame]) + 1.0;
|
|
|
|
[fActiveFilterButton setFrame: activeRect];
|
2007-12-12 01:51:21 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 21:11:49 +00:00
|
|
|
[self updateGroupsFilterButton];
|
2007-12-19 20:46:00 +00:00
|
|
|
|
2007-12-12 05:01:31 +00:00
|
|
|
//set up filter bar
|
2007-09-16 01:02:06 +00:00
|
|
|
NSView * contentView = [fWindow contentView];
|
|
|
|
NSSize windowSize = [contentView convertSize: [fWindow frame].size fromView: nil];
|
|
|
|
[fFilterBar setHidden: YES];
|
|
|
|
|
|
|
|
NSRect filterBarFrame = [fFilterBar frame];
|
|
|
|
filterBarFrame.size.width = windowSize.width;
|
|
|
|
[fFilterBar setFrame: filterBarFrame];
|
|
|
|
|
|
|
|
[contentView addSubview: fFilterBar];
|
|
|
|
[fFilterBar setFrameOrigin: NSMakePoint(0, NSMaxY([contentView frame]))];
|
|
|
|
|
|
|
|
[self showFilterBar: [fDefaults boolForKey: @"FilterBar"] animate: NO];
|
|
|
|
|
|
|
|
//set up status bar
|
|
|
|
[fStatusBar setHidden: YES];
|
2007-12-12 15:53:37 +00:00
|
|
|
|
2007-12-01 17:31:52 +00:00
|
|
|
[fTotalDLField setToolTip: NSLocalizedString(@"Total download speed", "Status Bar -> speed tooltip")];
|
|
|
|
[fTotalULField setToolTip: NSLocalizedString(@"Total upload speed", "Status Bar -> speed tooltip")];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
NSRect statusBarFrame = [fStatusBar frame];
|
|
|
|
statusBarFrame.size.width = windowSize.width;
|
|
|
|
[fStatusBar setFrame: statusBarFrame];
|
2007-12-12 03:21:11 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[contentView addSubview: fStatusBar];
|
|
|
|
[fStatusBar setFrameOrigin: NSMakePoint(0, NSMaxY([contentView frame]))];
|
|
|
|
[self showStatusBar: [fDefaults boolForKey: @"StatusBar"] animate: NO];
|
2007-11-30 16:17:43 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fActionButton setToolTip: NSLocalizedString(@"Shortcuts for changing global settings.",
|
|
|
|
"Main window -> 1st bottom left button (action) tooltip")];
|
|
|
|
[fSpeedLimitButton setToolTip: NSLocalizedString(@"Speed Limit overrides the total bandwidth limits with its own limits.",
|
|
|
|
"Main window -> 2nd bottom left button (turtle) tooltip")];
|
|
|
|
|
|
|
|
[fPrefsController setUpdater: fUpdater];
|
|
|
|
|
2008-02-07 11:57:24 +00:00
|
|
|
[fTableView registerForDraggedTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fWindow registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, NSURLPboardType, nil]];
|
|
|
|
|
|
|
|
//register for sleep notifications
|
|
|
|
IONotificationPortRef notify;
|
|
|
|
io_object_t iterator;
|
2008-05-20 15:16:34 +00:00
|
|
|
if ((fRootPort = IORegisterForSystemPower(self, & notify, sleepCallback, &iterator)))
|
2007-09-16 01:02:06 +00:00
|
|
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopCommonModes);
|
|
|
|
else
|
|
|
|
NSLog(@"Could not IORegisterForSystemPower");
|
|
|
|
|
|
|
|
//load previous transfers
|
2007-10-21 14:01:54 +00:00
|
|
|
NSArray * history = [[NSArray alloc] initWithContentsOfFile: [NSHomeDirectory() stringByAppendingPathComponent: SUPPORT_FOLDER]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//old version saved transfer info in prefs file
|
|
|
|
if (!history)
|
|
|
|
{
|
|
|
|
if ((history = [fDefaults arrayForKey: @"History"]))
|
|
|
|
[history retain];
|
|
|
|
[fDefaults removeObjectForKey: @"History"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (history)
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSDictionary * historyItem;
|
|
|
|
NSEnumerator * enumerator = [history objectEnumerator];
|
|
|
|
while ((historyItem = [enumerator nextObject]))
|
|
|
|
if ((torrent = [[Torrent alloc] initWithHistory: historyItem lib: fLib]))
|
|
|
|
{
|
|
|
|
[fTorrents addObject: torrent];
|
|
|
|
[torrent release];
|
|
|
|
}
|
|
|
|
|
|
|
|
[history release];
|
|
|
|
}
|
|
|
|
|
|
|
|
//set filter
|
|
|
|
NSString * filterType = [fDefaults stringForKey: @"Filter"];
|
|
|
|
|
2007-11-06 20:52:11 +00:00
|
|
|
NSButton * currentFilterButton;
|
2007-12-20 04:49:06 +00:00
|
|
|
if ([filterType isEqualToString: FILTER_ACTIVE])
|
|
|
|
currentFilterButton = fActiveFilterButton;
|
|
|
|
else if ([filterType isEqualToString: FILTER_PAUSE])
|
2007-09-16 01:02:06 +00:00
|
|
|
currentFilterButton = fPauseFilterButton;
|
|
|
|
else if ([filterType isEqualToString: FILTER_SEED])
|
|
|
|
currentFilterButton = fSeedFilterButton;
|
|
|
|
else if ([filterType isEqualToString: FILTER_DOWNLOAD])
|
|
|
|
currentFilterButton = fDownloadFilterButton;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
|
|
|
if (![filterType isEqualToString: FILTER_NONE])
|
|
|
|
[fDefaults setObject: FILTER_NONE forKey: @"Filter"];
|
|
|
|
currentFilterButton = fNoFilterButton;
|
|
|
|
}
|
|
|
|
[currentFilterButton setState: NSOnState];
|
|
|
|
|
|
|
|
//set filter search type
|
|
|
|
NSString * filterSearchType = [fDefaults stringForKey: @"FilterSearchType"];
|
|
|
|
|
|
|
|
NSMenu * filterSearchMenu = [[fSearchFilterField cell] searchMenuTemplate];
|
|
|
|
NSString * filterSearchTypeTitle;
|
|
|
|
if ([filterSearchType isEqualToString: FILTER_TYPE_TRACKER])
|
|
|
|
filterSearchTypeTitle = [[filterSearchMenu itemWithTag: FILTER_TYPE_TAG_TRACKER] title];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
|
|
|
if (![filterType isEqualToString: FILTER_TYPE_NAME])
|
|
|
|
[fDefaults setObject: FILTER_TYPE_NAME forKey: @"FilterSearchType"];
|
|
|
|
filterSearchTypeTitle = [[filterSearchMenu itemWithTag: FILTER_TYPE_TAG_NAME] title];
|
|
|
|
}
|
|
|
|
[[fSearchFilterField cell] setPlaceholderString: filterSearchTypeTitle];
|
|
|
|
|
|
|
|
//observe notifications
|
|
|
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(updateUI)
|
|
|
|
name: @"UpdateUI" object: nil];
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(torrentFinishedDownloading:)
|
|
|
|
name: @"TorrentFinishedDownloading" object: nil];
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(torrentRestartedDownloading:)
|
|
|
|
name: @"TorrentRestartedDownloading" object: nil];
|
|
|
|
|
|
|
|
//avoids need of setting delegate
|
|
|
|
[nc addObserver: self selector: @selector(torrentTableViewSelectionDidChange:)
|
2008-02-06 23:45:44 +00:00
|
|
|
name: NSOutlineViewSelectionDidChangeNotification object: fTableView];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(prepareForUpdate:)
|
|
|
|
name: SUUpdaterWillRestartNotification object: nil];
|
|
|
|
fUpdateInProgress = NO;
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(autoSpeedLimitChange:)
|
|
|
|
name: @"AutoSpeedLimitChange" object: nil];
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(changeAutoImport)
|
|
|
|
name: @"AutoImportSettingChange" object: nil];
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(setWindowSizeToFit)
|
|
|
|
name: @"AutoSizeSettingChange" object: nil];
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
[nc addObserver: self selector: @selector(updateForExpandCollape)
|
|
|
|
name: @"OutlineExpandCollapse" object: nil];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[nc addObserver: fWindow selector: @selector(makeKeyWindow)
|
|
|
|
name: @"MakeWindowKey" object: nil];
|
|
|
|
|
|
|
|
//check if torrent should now start
|
|
|
|
[nc addObserver: self selector: @selector(torrentStoppedForRatio:)
|
|
|
|
name: @"TorrentStoppedForRatio" object: nil];
|
|
|
|
|
|
|
|
[nc addObserver: self selector: @selector(updateTorrentsInQueue)
|
|
|
|
name: @"UpdateQueue" object: nil];
|
|
|
|
|
|
|
|
//open newly created torrent file
|
|
|
|
[nc addObserver: self selector: @selector(beginCreateFile:)
|
|
|
|
name: @"BeginCreateTorrentFile" object: nil];
|
|
|
|
|
|
|
|
//open newly created torrent file
|
|
|
|
[nc addObserver: self selector: @selector(openCreatedFile:)
|
|
|
|
name: @"OpenCreatedTorrentFile" object: nil];
|
2007-12-19 21:11:49 +00:00
|
|
|
|
|
|
|
//update when groups change
|
|
|
|
[nc addObserver: self selector: @selector(updateGroupsFilters:)
|
|
|
|
name: @"UpdateGroups" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//timer to update the interface every second
|
|
|
|
[self updateUI];
|
|
|
|
fTimer = [NSTimer scheduledTimerWithTimeInterval: UPDATE_UI_SECONDS target: self
|
2008-06-22 01:31:50 +00:00
|
|
|
selector: @selector(updateUI) userInfo: nil repeats: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fTimer forMode: NSModalPanelRunLoopMode];
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fTimer forMode: NSEventTrackingRunLoopMode];
|
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fWindow makeKeyAndOrderFront: nil];
|
|
|
|
|
|
|
|
if ([fDefaults boolForKey: @"InfoVisible"])
|
|
|
|
[self showInfo: nil];
|
|
|
|
|
2008-06-19 02:53:45 +00:00
|
|
|
//set up the speed limit
|
2007-09-16 01:02:06 +00:00
|
|
|
[self autoSpeedLimitChange: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationDidFinishLaunching: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
[NSApp setServicesProvider: self];
|
|
|
|
|
|
|
|
//register for dock icon drags
|
2008-02-19 16:20:38 +00:00
|
|
|
[[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
|
2007-09-16 01:02:06 +00:00
|
|
|
forEventClass: kCoreEventClass andEventID: kAEOpenContents];
|
|
|
|
|
|
|
|
//auto importing
|
|
|
|
[self checkAutoImportDirectory];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) applicationShouldHandleReopen: (NSApplication *) app hasVisibleWindows: (BOOL) visibleWindows
|
|
|
|
{
|
|
|
|
if (![fWindow isVisible] && ![[fPrefsController window] isVisible])
|
|
|
|
[fWindow makeKeyAndOrderFront: nil];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) sender
|
|
|
|
{
|
2008-05-19 13:29:07 +00:00
|
|
|
if (!fUpdateInProgress && [fDefaults boolForKey: @"CheckQuit"])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
int active = 0, downloading = 0;
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-12-31 18:37:34 +00:00
|
|
|
if ([torrent isActive] && ![torrent isStalled])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
active++;
|
2007-10-14 14:24:34 +00:00
|
|
|
if (![torrent allDownloaded])
|
2007-09-16 01:02:06 +00:00
|
|
|
downloading++;
|
|
|
|
}
|
2007-10-14 14:24:34 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([fDefaults boolForKey: @"CheckQuitDownloading"] ? downloading > 0 : active > 0)
|
|
|
|
{
|
|
|
|
NSString * message = active == 1
|
2008-04-23 03:33:04 +00:00
|
|
|
? NSLocalizedString(@"There is an active transfer that will be paused on quit."
|
|
|
|
" The transfer will automatically resume on the next launch.", "Confirm Quit panel -> message")
|
|
|
|
: [NSString stringWithFormat: NSLocalizedString(@"There are %d active transfers that will be paused on quit."
|
|
|
|
" The transfers will automatically resume on the next launch.", "Confirm Quit panel -> message"), active];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-04-23 03:33:04 +00:00
|
|
|
NSBeginAlertSheet(NSLocalizedString(@"Are you sure you want to quit?", "Confirm Quit panel -> title"),
|
2007-09-16 01:02:06 +00:00
|
|
|
NSLocalizedString(@"Quit", "Confirm Quit panel -> button"),
|
|
|
|
NSLocalizedString(@"Cancel", "Confirm Quit panel -> button"), nil, fWindow, self,
|
|
|
|
@selector(quitSheetDidEnd:returnCode:contextInfo:), nil, nil, message);
|
|
|
|
return NSTerminateLater;
|
|
|
|
}
|
|
|
|
}
|
2007-11-29 01:44:33 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo
|
|
|
|
{
|
|
|
|
[NSApp replyToApplicationShouldTerminate: returnCode == NSAlertDefaultReturn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationWillTerminate: (NSNotification *) notification
|
|
|
|
{
|
2007-11-02 03:15:12 +00:00
|
|
|
//stop timers and notification checking
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
|
|
|
[fTimer invalidate];
|
|
|
|
[fSpeedLimitTimer invalidate];
|
2008-06-19 02:53:45 +00:00
|
|
|
|
2007-11-02 03:15:12 +00:00
|
|
|
if (fAutoImportTimer)
|
|
|
|
{
|
|
|
|
if ([fAutoImportTimer isValid])
|
|
|
|
[fAutoImportTimer invalidate];
|
|
|
|
[fAutoImportTimer release];
|
|
|
|
}
|
|
|
|
|
2007-12-20 01:42:30 +00:00
|
|
|
[fBadger setQuitting];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//remove all torrent downloads
|
|
|
|
if (fPendingTorrentDownloads)
|
|
|
|
{
|
2008-06-26 03:53:42 +00:00
|
|
|
NSEnumerator * downloadEnumerator = [fPendingTorrentDownloads objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
NSDictionary * downloadDict;
|
|
|
|
while ((downloadDict = [downloadEnumerator nextObject]))
|
|
|
|
{
|
2008-06-26 03:50:21 +00:00
|
|
|
NSURLDownload * download = [downloadDict objectForKey: @"Download"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[download cancel];
|
|
|
|
[download release];
|
|
|
|
}
|
|
|
|
[fPendingTorrentDownloads removeAllObjects];
|
|
|
|
}
|
|
|
|
|
|
|
|
//remember window states and close all windows
|
|
|
|
[fDefaults setBool: [[fInfoController window] isVisible] forKey: @"InfoVisible"];
|
|
|
|
[[NSApp windows] makeObjectsPerformSelector: @selector(close)];
|
|
|
|
[self showStatusBar: NO animate: NO];
|
|
|
|
[self showFilterBar: NO animate: NO];
|
|
|
|
|
|
|
|
//save history
|
|
|
|
[self updateTorrentHistory];
|
2008-02-07 21:26:04 +00:00
|
|
|
[fTableView saveCollapsedGroups];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-11-02 15:05:20 +00:00
|
|
|
//remaining calls the same as dealloc
|
2007-10-08 04:15:25 +00:00
|
|
|
[fInfoController release];
|
|
|
|
[fMessageController release];
|
|
|
|
[fPrefsController release];
|
|
|
|
|
|
|
|
[fTorrents release];
|
|
|
|
[fDisplayedTorrents release];
|
|
|
|
|
|
|
|
[fOverlayWindow release];
|
|
|
|
|
|
|
|
[fAutoImportedNames release];
|
|
|
|
[fPendingTorrentDownloads release];
|
2007-11-02 15:05:20 +00:00
|
|
|
|
2007-11-05 12:47:20 +00:00
|
|
|
//complete cleanup
|
2008-05-19 00:23:06 +00:00
|
|
|
tr_sessionClose(fLib);
|
2007-12-30 20:28:36 +00:00
|
|
|
|
|
|
|
[fBadger release]; //clears dock icon on 10.4
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) handleOpenContentsEvent: (NSAppleEventDescriptor *) event replyEvent: (NSAppleEventDescriptor *) replyEvent
|
|
|
|
{
|
|
|
|
NSString * urlString = nil;
|
|
|
|
|
|
|
|
NSAppleEventDescriptor * directObject = [event paramDescriptorForKeyword: keyDirectObject];
|
|
|
|
if ([directObject descriptorType] == typeAEList)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 1; i <= [directObject numberOfItems]; i++)
|
|
|
|
if ((urlString = [[directObject descriptorAtIndex: i] stringValue]))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
urlString = [directObject stringValue];
|
|
|
|
|
|
|
|
if (urlString)
|
2007-12-30 22:43:03 +00:00
|
|
|
[self openURL: [NSURL URLWithString: urlString]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) download: (NSURLDownload *) download decideDestinationWithSuggestedFilename: (NSString *) suggestedName
|
|
|
|
{
|
|
|
|
if ([[suggestedName pathExtension] caseInsensitiveCompare: @"torrent"] != NSOrderedSame)
|
|
|
|
{
|
|
|
|
[download cancel];
|
|
|
|
|
2008-04-24 01:55:33 +00:00
|
|
|
NSRunAlertPanel(NSLocalizedString(@"Torrent download failed", "Download not a torrent -> title"),
|
2008-04-23 12:44:11 +00:00
|
|
|
[NSString stringWithFormat: NSLocalizedString(@"It appears that the file \"%@\" from %@ is not a torrent file.",
|
2008-04-24 01:55:33 +00:00
|
|
|
"Download not a torrent -> message"), suggestedName,
|
2007-09-16 01:02:06 +00:00
|
|
|
[[[[download request] URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]],
|
2008-04-24 01:55:33 +00:00
|
|
|
NSLocalizedString(@"OK", "Download not a torrent -> button"), nil, nil);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[download release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[download setDestination: [NSTemporaryDirectory() stringByAppendingPathComponent: [suggestedName lastPathComponent]]
|
|
|
|
allowOverwrite: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) download: (NSURLDownload *) download didCreateDestination: (NSString *) path
|
|
|
|
{
|
|
|
|
if (!fPendingTorrentDownloads)
|
|
|
|
fPendingTorrentDownloads = [[NSMutableDictionary alloc] init];
|
|
|
|
|
|
|
|
[fPendingTorrentDownloads setObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
path, @"Path", download, @"Download", nil] forKey: [[download request] URL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) download: (NSURLDownload *) download didFailWithError: (NSError *) error
|
|
|
|
{
|
2008-04-24 01:55:33 +00:00
|
|
|
NSRunAlertPanel(NSLocalizedString(@"Torrent download failed", "Torrent download error -> title"),
|
|
|
|
[NSString stringWithFormat: NSLocalizedString(@"The torrent could not be downloaded from %@: %@.",
|
|
|
|
"Torrent download failed -> message"),
|
2007-09-16 01:02:06 +00:00
|
|
|
[[[[download request] URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
|
2008-04-24 01:55:33 +00:00
|
|
|
[error localizedDescription]], NSLocalizedString(@"OK", "Torrent download failed -> button"), nil, nil);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
|
2008-06-26 03:50:21 +00:00
|
|
|
if ([fPendingTorrentDownloads count] == 0)
|
|
|
|
{
|
|
|
|
[fPendingTorrentDownloads release];
|
|
|
|
fPendingTorrentDownloads = nil;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[download release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) downloadDidFinish: (NSURLDownload *) download
|
|
|
|
{
|
|
|
|
NSString * path = [[fPendingTorrentDownloads objectForKey: [[download request] URL]] objectForKey: @"Path"];
|
|
|
|
|
2008-01-05 02:48:10 +00:00
|
|
|
[self openFiles: [NSArray arrayWithObject: path] addType: ADD_URL forcePath: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-06-26 03:50:21 +00:00
|
|
|
[[NSFileManager defaultManager] removeFileAtPath: path handler: nil]; //delete the torrent file after opening
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
|
2008-06-26 03:50:21 +00:00
|
|
|
if ([fPendingTorrentDownloads count] == 0)
|
|
|
|
{
|
|
|
|
[fPendingTorrentDownloads release];
|
|
|
|
fPendingTorrentDownloads = nil;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-06-26 03:50:21 +00:00
|
|
|
[download release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) application: (NSApplication *) app openFiles: (NSArray *) filenames
|
|
|
|
{
|
2008-05-27 00:52:18 +00:00
|
|
|
[self openFiles: filenames addType: ADD_MANUAL forcePath: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-05 02:48:10 +00:00
|
|
|
- (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-19 05:37:16 +00:00
|
|
|
#warning checks could probably be removed, since location is checked when starting
|
2007-09-16 01:02:06 +00:00
|
|
|
if (!path && [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]
|
|
|
|
&& access([[[fDefaults stringForKey: @"IncompleteDownloadFolder"] stringByExpandingTildeInPath] UTF8String], 0))
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setPrompt: NSLocalizedString(@"Select", "Default incomplete folder cannot be used alert -> prompt")];
|
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setCanChooseFiles: NO];
|
|
|
|
[panel setCanChooseDirectories: YES];
|
|
|
|
[panel setCanCreateDirectories: YES];
|
|
|
|
|
|
|
|
[panel setMessage: NSLocalizedString(@"The incomplete folder cannot be used. Choose a new location or cancel for none.",
|
|
|
|
"Default incomplete folder cannot be used alert -> message")];
|
|
|
|
|
2008-01-05 02:48:10 +00:00
|
|
|
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: filenames, @"Filenames",
|
|
|
|
[NSNumber numberWithInt: type], @"AddType", nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
|
|
|
|
didEndSelector: @selector(incompleteChoiceClosed:returnCode:contextInfo:) contextInfo: dict];
|
|
|
|
return;
|
|
|
|
}
|
2008-01-04 02:35:23 +00:00
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
if (!path && [fDefaults boolForKey: @"DownloadLocationConstant"]
|
2007-09-16 01:02:06 +00:00
|
|
|
&& access([[[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath] UTF8String], 0))
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setPrompt: NSLocalizedString(@"Select", "Default folder cannot be used alert -> prompt")];
|
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setCanChooseFiles: NO];
|
|
|
|
[panel setCanChooseDirectories: YES];
|
|
|
|
[panel setCanCreateDirectories: YES];
|
|
|
|
|
|
|
|
[panel setMessage: NSLocalizedString(@"The download folder cannot be used. Choose a new location.",
|
|
|
|
"Default folder cannot be used alert -> message")];
|
|
|
|
|
2008-01-05 02:48:10 +00:00
|
|
|
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: filenames, @"Filenames",
|
|
|
|
[NSNumber numberWithInt: type], @"AddType", nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
|
|
|
|
didEndSelector: @selector(downloadChoiceClosed:returnCode:contextInfo:) contextInfo: dict];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-05 02:48:10 +00:00
|
|
|
torrentFileState deleteTorrentFile;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ADD_CREATED:
|
|
|
|
deleteTorrentFile = TORRENT_FILE_SAVE;
|
|
|
|
break;
|
|
|
|
case ADD_URL:
|
|
|
|
deleteTorrentFile = TORRENT_FILE_DELETE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
deleteTorrentFile = TORRENT_FILE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2008-01-08 05:31:20 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
NSString * torrentPath;
|
|
|
|
tr_info info;
|
|
|
|
NSEnumerator * enumerator = [filenames objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
while ((torrentPath = [enumerator nextObject]))
|
|
|
|
{
|
2008-01-08 05:31:20 +00:00
|
|
|
//ensure torrent doesn't already exist
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctor * ctor = tr_ctorNew(fLib);
|
|
|
|
tr_ctorSetMetainfoFromFile(ctor, [torrentPath UTF8String]);
|
2008-06-18 16:25:30 +00:00
|
|
|
int result = tr_torrentParse(fLib, ctor, &info);
|
|
|
|
if (result != TR_OK)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-06-18 16:25:30 +00:00
|
|
|
if (result == TR_EDUPLICATE)
|
|
|
|
[self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]];
|
|
|
|
else if (result == TR_EINVALID)
|
|
|
|
{
|
|
|
|
if (type != ADD_AUTO)
|
|
|
|
[self invalidOpenAlert: [torrentPath lastPathComponent]];
|
|
|
|
}
|
|
|
|
else //this shouldn't happen
|
2008-06-19 02:53:45 +00:00
|
|
|
NSLog(@"Unknown error code (%d) when attempting to open \"%@\"", result, torrentPath);
|
2008-06-18 16:25:30 +00:00
|
|
|
|
2008-01-14 04:34:45 +00:00
|
|
|
tr_ctorFree(ctor);
|
2007-09-16 01:02:06 +00:00
|
|
|
tr_metainfoFree(&info);
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-18 16:25:30 +00:00
|
|
|
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctorFree(ctor);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-08 05:31:20 +00:00
|
|
|
//determine download location
|
|
|
|
NSString * location;
|
|
|
|
if (path)
|
|
|
|
location = [path stringByExpandingTildeInPath];
|
|
|
|
else if ([fDefaults boolForKey: @"DownloadLocationConstant"])
|
|
|
|
location = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
|
|
|
|
else if (type != ADD_URL)
|
|
|
|
location = [torrentPath stringByDeletingLastPathComponent];
|
|
|
|
else
|
|
|
|
location = nil;
|
|
|
|
|
2008-01-14 04:22:24 +00:00
|
|
|
//determine to show the options window
|
|
|
|
BOOL showWindow = type == ADD_SHOW_OPTIONS || ([fDefaults boolForKey: @"DownloadAsk"]
|
2008-05-26 21:39:30 +00:00
|
|
|
&& (info.isMultifile || ![fDefaults boolForKey: @"DownloadAskMulti"])
|
|
|
|
&& (type != ADD_AUTO || ![fDefaults boolForKey: @"DownloadAskManual"]));
|
2008-01-14 04:22:24 +00:00
|
|
|
tr_metainfoFree(&info);
|
|
|
|
|
2008-01-04 06:31:41 +00:00
|
|
|
if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location
|
2008-01-05 02:48:10 +00:00
|
|
|
deleteTorrentFile: showWindow ? TORRENT_FILE_SAVE : deleteTorrentFile lib: fLib]))
|
2007-09-16 01:02:06 +00:00
|
|
|
continue;
|
|
|
|
|
2008-01-10 01:20:48 +00:00
|
|
|
//verify the data right away if it was newly created
|
|
|
|
if (type == ADD_CREATED)
|
|
|
|
[torrent resetCache];
|
|
|
|
|
2008-01-14 04:34:45 +00:00
|
|
|
//add it to the "File -> Open Recent" menu
|
|
|
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
|
|
|
|
|
2008-01-08 05:31:20 +00:00
|
|
|
//show the add window or add directly
|
|
|
|
if (showWindow || !location)
|
2008-01-04 06:31:41 +00:00
|
|
|
{
|
|
|
|
AddWindowController * addController = [[AddWindowController alloc] initWithTorrent: torrent destination: location
|
2008-01-05 02:48:10 +00:00
|
|
|
controller: self deleteTorrent: deleteTorrentFile];
|
2008-01-04 06:31:41 +00:00
|
|
|
[addController showWindow: self];
|
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
else
|
|
|
|
{
|
2008-01-04 04:54:26 +00:00
|
|
|
[torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];
|
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
[torrent update];
|
|
|
|
[fTorrents addObject: torrent];
|
|
|
|
[torrent release];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
|
|
|
}
|
|
|
|
|
2008-01-05 21:31:05 +00:00
|
|
|
- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2008-01-05 21:31:05 +00:00
|
|
|
Torrent * torrent = [addController torrent];
|
2008-01-08 05:31:20 +00:00
|
|
|
[addController release];
|
|
|
|
|
2008-01-05 21:31:05 +00:00
|
|
|
if (add)
|
|
|
|
{
|
2008-05-25 17:34:02 +00:00
|
|
|
[torrent setOrderValue: [fTorrents count]]; //ensure that queue order is always sequential
|
2008-01-05 21:31:05 +00:00
|
|
|
|
|
|
|
[torrent update];
|
|
|
|
[fTorrents addObject: torrent];
|
|
|
|
[torrent release];
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[torrent closeRemoveTorrent];
|
|
|
|
[torrent release];
|
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) openCreatedFile: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
NSDictionary * dict = [notification userInfo];
|
2008-01-05 02:48:10 +00:00
|
|
|
[self openFiles: [NSArray arrayWithObject: [dict objectForKey: @"File"]] addType: ADD_CREATED
|
|
|
|
forcePath: [dict objectForKey: @"Path"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[dict release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) incompleteChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (NSDictionary *) dictionary
|
|
|
|
{
|
|
|
|
if (code == NSOKButton)
|
|
|
|
[fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
|
|
|
|
else
|
|
|
|
[fDefaults setBool: NO forKey: @"UseIncompleteDownloadFolder"];
|
|
|
|
|
|
|
|
[self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) downloadChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (NSDictionary *) dictionary
|
|
|
|
{
|
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
|
|
|
[fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
|
|
|
|
[self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[dictionary release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openFilesWithDict: (NSDictionary *) dictionary
|
|
|
|
{
|
2008-01-10 17:30:49 +00:00
|
|
|
[self openFiles: [dictionary objectForKey: @"Filenames"] addType: [[dictionary objectForKey: @"AddType"] intValue] forcePath: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[dictionary release];
|
|
|
|
}
|
|
|
|
|
|
|
|
//called on by applescript
|
|
|
|
- (void) open: (NSArray *) files
|
|
|
|
{
|
2008-01-10 16:46:15 +00:00
|
|
|
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: files, @"Filenames",
|
2008-05-27 00:52:18 +00:00
|
|
|
[NSNumber numberWithInt: ADD_MANUAL], @"AddType", nil];
|
2008-01-10 16:46:15 +00:00
|
|
|
[self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dict waitUntilDone: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openShowSheet: (id) sender
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setAllowsMultipleSelection: YES];
|
|
|
|
[panel setCanChooseFiles: YES];
|
|
|
|
[panel setCanChooseDirectories: NO];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: [NSArray arrayWithObject: @"torrent"]
|
|
|
|
modalForWindow: fWindow modalDelegate: self didEndSelector: @selector(openSheetClosed:returnCode:contextInfo:)
|
|
|
|
contextInfo: [NSNumber numberWithBool: sender == fOpenIgnoreDownloadFolder]];
|
|
|
|
}
|
|
|
|
|
2008-01-05 02:48:10 +00:00
|
|
|
- (void) openSheetClosed: (NSOpenPanel *) panel returnCode: (int) code contextInfo: (NSNumber *) useOptions
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
2008-01-10 17:01:09 +00:00
|
|
|
NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: [panel filenames], @"Filenames",
|
2008-05-27 00:52:18 +00:00
|
|
|
[NSNumber numberWithInt: [useOptions boolValue] ? ADD_SHOW_OPTIONS : ADD_MANUAL], @"AddType", nil];
|
2008-01-10 16:46:15 +00:00
|
|
|
[self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-18 16:25:30 +00:00
|
|
|
- (void) invalidOpenAlert: (NSString *) filename
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: @"WarningInvalidOpen"])
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"\"%@\" is not a valid torrent file.",
|
|
|
|
"Open invalid alert -> title"), filename]];
|
|
|
|
[alert setInformativeText:
|
|
|
|
NSLocalizedString(@"The torrent file cannot be opened because it contains invalid data.",
|
|
|
|
"Open invalid alert -> message")];
|
|
|
|
[alert setAlertStyle: NSWarningAlertStyle];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Open invalid alert -> button")];
|
|
|
|
|
|
|
|
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
|
|
|
|
if (onLeopard)
|
|
|
|
[alert setShowsSuppressionButton: YES];
|
|
|
|
else
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Don't Alert Again", "Open duplicate alert -> button")];
|
|
|
|
|
|
|
|
NSInteger result = [alert runModal];
|
|
|
|
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertSecondButtonReturn))
|
|
|
|
[fDefaults setBool: NO forKey: @"WarningInvalidOpen"];
|
|
|
|
[alert release];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) duplicateOpenAlert: (NSString *) name
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: @"WarningDuplicate"])
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
2008-01-07 20:27:25 +00:00
|
|
|
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"A transfer of \"%@\" already exists.",
|
2007-09-16 01:02:06 +00:00
|
|
|
"Open duplicate alert -> title"), name]];
|
|
|
|
[alert setInformativeText:
|
2008-01-07 20:27:25 +00:00
|
|
|
NSLocalizedString(@"The torrent file cannot be opened because it is a duplicate of an already added transfer.",
|
2007-09-16 01:02:06 +00:00
|
|
|
"Open duplicate alert -> message")];
|
|
|
|
[alert setAlertStyle: NSWarningAlertStyle];
|
2007-10-29 19:45:34 +00:00
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Open duplicate alert -> button")];
|
|
|
|
|
|
|
|
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
|
|
|
|
if (onLeopard)
|
|
|
|
[alert setShowsSuppressionButton: YES];
|
|
|
|
else
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Don't Alert Again", "Open duplicate alert -> button")];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-29 19:45:34 +00:00
|
|
|
NSInteger result = [alert runModal];
|
|
|
|
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertSecondButtonReturn))
|
2007-09-16 01:02:06 +00:00
|
|
|
[fDefaults setBool: NO forKey: @"WarningDuplicate"];
|
|
|
|
[alert release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openURL: (NSURL *) url
|
|
|
|
{
|
|
|
|
[[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openURLShowSheet: (id) sender
|
|
|
|
{
|
|
|
|
[NSApp beginSheet: fURLSheetWindow modalForWindow: fWindow modalDelegate: self
|
|
|
|
didEndSelector: @selector(urlSheetDidEnd:returnCode:contextInfo:) contextInfo: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openURLEndSheet: (id) sender
|
|
|
|
{
|
|
|
|
[fURLSheetWindow orderOut: sender];
|
|
|
|
[NSApp endSheet: fURLSheetWindow returnCode: 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openURLCancelEndSheet: (id) sender
|
|
|
|
{
|
|
|
|
[fURLSheetWindow orderOut: sender];
|
|
|
|
[NSApp endSheet: fURLSheetWindow returnCode: 0];
|
|
|
|
}
|
|
|
|
|
2008-04-25 22:23:31 +00:00
|
|
|
- (void) controlTextDidChange: (NSNotification *) notification
|
|
|
|
{
|
2008-04-27 14:31:49 +00:00
|
|
|
if ([notification object] != fURLSheetTextField)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSString * string = [fURLSheetTextField stringValue];
|
|
|
|
BOOL enable = YES;
|
|
|
|
if ([string isEqualToString: @""])
|
|
|
|
enable = NO;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSRange prefixRange = [string rangeOfString: @"://"];
|
|
|
|
if (prefixRange.location != NSNotFound && [string length] == NSMaxRange(prefixRange))
|
|
|
|
enable = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fURLSheetOpenButton setEnabled: enable];
|
2008-04-25 22:23:31 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) urlSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo
|
|
|
|
{
|
|
|
|
[fURLSheetTextField selectText: self];
|
|
|
|
if (returnCode != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSString * urlString = [fURLSheetTextField stringValue];
|
2008-04-25 22:29:51 +00:00
|
|
|
if ([urlString rangeOfString: @"://"].location == NSNotFound)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-25 22:29:51 +00:00
|
|
|
if ([urlString rangeOfString: @"."].location == NSNotFound)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-25 22:29:51 +00:00
|
|
|
int beforeCom;
|
|
|
|
if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound)
|
|
|
|
urlString = [NSString stringWithFormat: @"http://www.%@.com/%@",
|
|
|
|
[urlString substringToIndex: beforeCom],
|
|
|
|
[urlString substringFromIndex: beforeCom + 1]];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-04-25 22:29:51 +00:00
|
|
|
urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-04-25 22:29:51 +00:00
|
|
|
else
|
|
|
|
urlString = [@"http://" stringByAppendingString: urlString];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-04-25 22:29:51 +00:00
|
|
|
|
|
|
|
NSURL * url = [NSURL URLWithString: urlString];
|
|
|
|
[self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) createFile: (id) sender
|
|
|
|
{
|
|
|
|
[CreatorWindowController createTorrentFile: fLib];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeSelectedTorrents: (id) sender
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
[self resumeTorrents: [fTableView selectedTorrents]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeAllTorrents: (id) sender
|
|
|
|
{
|
|
|
|
[self resumeTorrents: fTorrents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeTorrents: (NSArray *) torrents
|
|
|
|
{
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setWaitToStart: YES];
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeSelectedTorrentsNoWait: (id) sender
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
[self resumeTorrentsNoWait: [fTableView selectedTorrents]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeWaitingTorrents: (id) sender
|
|
|
|
{
|
|
|
|
NSMutableArray * torrents = [NSMutableArray arrayWithCapacity: [fTorrents count]];
|
|
|
|
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if (![torrent isActive] && [torrent waitingToStart])
|
|
|
|
[torrents addObject: torrent];
|
|
|
|
|
|
|
|
[self resumeTorrentsNoWait: torrents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeTorrentsNoWait: (NSArray *) torrents
|
|
|
|
{
|
|
|
|
//iterate through instead of all at once to ensure no conflicts
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent startTransfer];
|
|
|
|
|
|
|
|
[self updateUI];
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopSelectedTorrents: (id) sender
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
[self stopTorrents: [fTableView selectedTorrents]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopAllTorrents: (id) sender
|
|
|
|
{
|
|
|
|
[self stopTorrents: fTorrents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopTorrents: (NSArray *) torrents
|
|
|
|
{
|
|
|
|
//don't want any of these starting then stopping
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setWaitToStart: NO];
|
|
|
|
|
|
|
|
[torrents makeObjectsPerformSelector: @selector(stopTransfer)];
|
|
|
|
|
|
|
|
[self updateUI];
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeTorrents: (NSArray *) torrents deleteData: (BOOL) deleteData deleteTorrent: (BOOL) deleteTorrent
|
|
|
|
{
|
|
|
|
[torrents retain];
|
|
|
|
int active = 0, downloading = 0;
|
|
|
|
|
|
|
|
if ([fDefaults boolForKey: @"CheckRemove"])
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive])
|
|
|
|
{
|
|
|
|
active++;
|
|
|
|
if (![torrent isSeeding])
|
|
|
|
downloading++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([fDefaults boolForKey: @"CheckRemoveDownloading"] ? downloading > 0 : active > 0)
|
|
|
|
{
|
|
|
|
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
|
2007-12-21 20:39:43 +00:00
|
|
|
torrents, @"Torrents",
|
|
|
|
[NSNumber numberWithBool: deleteData], @"DeleteData",
|
|
|
|
[NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent", nil];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
NSString * title, * message;
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
int selected = [torrents count];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (selected == 1)
|
|
|
|
{
|
2008-01-23 02:51:58 +00:00
|
|
|
NSString * torrentName = [[torrents objectAtIndex: 0] name];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (!deleteData && !deleteTorrent)
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove \"%@\" from the transfer list?",
|
2007-09-16 01:02:06 +00:00
|
|
|
"Removal confirm panel -> title"), torrentName];
|
|
|
|
else if (deleteData && !deleteTorrent)
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove \"%@\" from the transfer list"
|
|
|
|
" and trash the data file?", "Removal confirm panel -> title"), torrentName];
|
2007-09-16 01:02:06 +00:00
|
|
|
else if (!deleteData && deleteTorrent)
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove \"%@\" from the transfer list"
|
|
|
|
" and trash the torrent file?", "Removal confirm panel -> title"), torrentName];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove \"%@\" from the transfer list"
|
|
|
|
" and trash both the data and torrent files?", "Removal confirm panel -> title"), torrentName];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
message = NSLocalizedString(@"This transfer is active."
|
2007-11-06 20:52:11 +00:00
|
|
|
" Once removed, continuing the transfer will require the torrent file.",
|
|
|
|
"Removal confirm panel -> message");
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!deleteData && !deleteTorrent)
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove %d transfers from the transfer list?",
|
|
|
|
"Removal confirm panel -> title"), selected];
|
2007-09-16 01:02:06 +00:00
|
|
|
else if (deleteData && !deleteTorrent)
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove %d transfers from the transfer list"
|
|
|
|
" and trash the data file?", "Removal confirm panel -> title"), selected];
|
2007-09-16 01:02:06 +00:00
|
|
|
else if (!deleteData && deleteTorrent)
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove %d transfers from the transfer list"
|
|
|
|
" and trash the torrent file?", "Removal confirm panel -> title"), selected];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-04-23 03:33:04 +00:00
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Are you sure you want to remove %d transfers from the transfer list"
|
|
|
|
" and trash both the data and torrent files?", "Removal confirm panel -> title"), selected];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (selected == active)
|
|
|
|
message = [NSString stringWithFormat: NSLocalizedString(@"There are %d active transfers.",
|
|
|
|
"Removal confirm panel -> message part 1"), active];
|
|
|
|
else
|
|
|
|
message = [NSString stringWithFormat: NSLocalizedString(@"There are %d transfers (%d active).",
|
|
|
|
"Removal confirm panel -> message part 1"), selected, active];
|
2008-04-23 03:33:04 +00:00
|
|
|
message = [message stringByAppendingFormat: @" %@",
|
|
|
|
NSLocalizedString(@"Once removed, continuing the transfers will require the torrent files.",
|
2007-11-06 20:52:11 +00:00
|
|
|
"Removal confirm panel -> message part 2")];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-21 20:39:43 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
NSBeginAlertSheet(title, NSLocalizedString(@"Remove", "Removal confirm panel -> button"),
|
|
|
|
NSLocalizedString(@"Cancel", "Removal confirm panel -> button"), nil, fWindow, self,
|
|
|
|
nil, @selector(removeSheetDidEnd:returnCode:contextInfo:), dict, message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-27 19:05:48 +00:00
|
|
|
[self confirmRemoveTorrents: torrents deleteData: deleteData deleteTorrent: deleteTorrent fromRPC: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (NSDictionary *) dict
|
|
|
|
{
|
|
|
|
NSArray * torrents = [dict objectForKey: @"Torrents"];
|
|
|
|
if (returnCode == NSAlertDefaultReturn)
|
2007-12-21 20:39:43 +00:00
|
|
|
[self confirmRemoveTorrents: torrents deleteData: [[dict objectForKey: @"DeleteData"] boolValue]
|
2008-05-27 19:05:48 +00:00
|
|
|
deleteTorrent: [[dict objectForKey: @"DeleteTorrent"] boolValue] fromRPC: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
[torrents release];
|
2007-12-21 20:39:43 +00:00
|
|
|
|
|
|
|
[dict release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) confirmRemoveTorrents: (NSArray *) torrents deleteData: (BOOL) deleteData deleteTorrent: (BOOL) deleteTorrent
|
2008-05-27 19:05:48 +00:00
|
|
|
fromRPC: (BOOL) rpc
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//don't want any of these starting then stopping
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setWaitToStart: NO];
|
2007-12-21 20:39:43 +00:00
|
|
|
|
|
|
|
[fTorrents removeObjectsInArray: torrents];
|
|
|
|
|
2008-01-10 20:59:56 +00:00
|
|
|
int lowestOrderValue = INT_MAX;
|
2007-09-16 01:02:06 +00:00
|
|
|
enumerator = [torrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
2008-06-11 04:24:34 +00:00
|
|
|
//let's expand all groups that have removed items - they either don't exist anymore, are already expanded, or are collapsed (rpc)
|
2008-02-07 02:11:26 +00:00
|
|
|
[fTableView removeCollapsedGroup: [torrent groupValue]];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (deleteData)
|
|
|
|
[torrent trashData];
|
|
|
|
if (deleteTorrent)
|
|
|
|
[torrent trashTorrent];
|
|
|
|
|
2008-01-10 17:30:49 +00:00
|
|
|
lowestOrderValue = MIN(lowestOrderValue, [torrent orderValue]);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-27 19:05:48 +00:00
|
|
|
if (rpc)
|
|
|
|
[torrent closeRemoveTorrentInterface];
|
|
|
|
else
|
|
|
|
[torrent closeRemoveTorrent];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-21 20:39:43 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[torrents release];
|
|
|
|
|
|
|
|
//reset the order values if necessary
|
2007-11-23 15:45:58 +00:00
|
|
|
if (lowestOrderValue < [fTorrents count])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-06-21 19:01:46 +00:00
|
|
|
for (i = lowestOrderValue; i < [fTorrents count]; i++)
|
|
|
|
[[fTorrents objectAtIndex: i] setOrderValue: i];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[fTableView deselectAll: nil];
|
|
|
|
|
2007-12-21 20:39:43 +00:00
|
|
|
[self updateTorrentsInQueue];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeNoDelete: (id) sender
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
[self removeTorrents: [fTableView selectedTorrents] deleteData: NO deleteTorrent: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeDeleteData: (id) sender
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
[self removeTorrents: [fTableView selectedTorrents] deleteData: YES deleteTorrent: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeDeleteTorrent: (id) sender
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
[self removeTorrents: [fTableView selectedTorrents] deleteData: NO deleteTorrent: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeDeleteDataAndTorrent: (id) sender
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
[self removeTorrents: [fTableView selectedTorrents] deleteData: YES deleteTorrent: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 17:05:48 +00:00
|
|
|
- (void) moveDataFilesSelected: (id) sender
|
|
|
|
{
|
|
|
|
[self moveDataFiles: [fTableView selectedTorrents]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) moveDataFiles: (NSArray *) torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
[panel setPrompt: NSLocalizedString(@"Select", "Move torrent -> prompt")];
|
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setCanChooseFiles: NO];
|
|
|
|
[panel setCanChooseDirectories: YES];
|
|
|
|
[panel setCanCreateDirectories: YES];
|
|
|
|
|
2008-03-22 17:05:48 +00:00
|
|
|
torrents = [torrents retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
int count = [torrents count];
|
|
|
|
if (count == 1)
|
|
|
|
[panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the new folder for \"%@\".",
|
|
|
|
"Move torrent -> select destination folder"), [[torrents objectAtIndex: 0] name]]];
|
|
|
|
else
|
|
|
|
[panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the new folder for %d data files.",
|
|
|
|
"Move torrent -> select destination folder"), count]];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil modalForWindow: fWindow modalDelegate: self
|
|
|
|
didEndSelector: @selector(moveDataFileChoiceClosed:returnCode:contextInfo:) contextInfo: torrents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) moveDataFileChoiceClosed: (NSOpenPanel *) panel returnCode: (int) code contextInfo: (NSArray *) torrents
|
|
|
|
{
|
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent moveTorrentDataFileTo: [[panel filenames] objectAtIndex: 0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[torrents release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) copyTorrentFiles: (id) sender
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
[self copyTorrentFileForTorrents: [[NSMutableArray alloc] initWithArray: [fTableView selectedTorrents]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents
|
|
|
|
{
|
|
|
|
if ([torrents count] <= 0)
|
|
|
|
{
|
|
|
|
[torrents release];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Torrent * torrent = [torrents objectAtIndex: 0];
|
|
|
|
|
|
|
|
//warn user if torrent file can't be found
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent torrentLocation]])
|
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Torrent file copy alert -> button")];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Copy of \"%@\" Cannot Be Created",
|
|
|
|
"Torrent file copy alert -> title"), [torrent name]]];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"The torrent file (%@) cannot be found.", "Torrent file copy alert -> message"),
|
|
|
|
[torrent torrentLocation]]];
|
|
|
|
[alert setAlertStyle: NSWarningAlertStyle];
|
|
|
|
|
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
|
|
|
|
|
|
|
[torrents removeObjectAtIndex: 0];
|
|
|
|
[self copyTorrentFileForTorrents: torrents];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSSavePanel * panel = [NSSavePanel savePanel];
|
|
|
|
[panel setRequiredFileType: @"torrent"];
|
|
|
|
[panel setCanSelectHiddenExtension: YES];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: [torrent name] modalForWindow: fWindow modalDelegate: self
|
|
|
|
didEndSelector: @selector(saveTorrentCopySheetClosed:returnCode:contextInfo:) contextInfo: torrents];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (int) code contextInfo: (NSMutableArray *) torrents
|
|
|
|
{
|
|
|
|
//copy torrent to new location with name of data file
|
|
|
|
if (code == NSOKButton)
|
|
|
|
[[torrents objectAtIndex: 0] copyTorrentFileTo: [panel filename]];
|
|
|
|
|
|
|
|
[torrents removeObjectAtIndex: 0];
|
|
|
|
[self performSelectorOnMainThread: @selector(copyTorrentFileForTorrents:) withObject: torrents waitUntilDone: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealFile: (id) sender
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent revealData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) announceSelectedTorrents: (id) sender
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if ([torrent canManualAnnounce])
|
|
|
|
[torrent manualAnnounce];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-27 19:04:38 +00:00
|
|
|
- (void) verifySelectedTorrents: (id) sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-27 19:04:38 +00:00
|
|
|
[self verifyTorrents: [fTableView selectedTorrents]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) verifyTorrents: (NSArray *) torrents
|
|
|
|
{
|
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent resetCache];
|
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showPreferenceWindow: (id) sender
|
|
|
|
{
|
|
|
|
NSWindow * window = [fPrefsController window];
|
|
|
|
if (![window isVisible])
|
|
|
|
[window center];
|
|
|
|
|
|
|
|
[window makeKeyAndOrderFront: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showAboutWindow: (id) sender
|
|
|
|
{
|
|
|
|
[[AboutWindowController aboutController] showWindow: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showInfo: (id) sender
|
|
|
|
{
|
|
|
|
if ([[fInfoController window] isVisible])
|
|
|
|
[fInfoController close];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fInfoController updateInfoStats];
|
|
|
|
[[fInfoController window] orderFront: nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-26 03:35:20 +00:00
|
|
|
- (void) resetInfo
|
|
|
|
{
|
|
|
|
[fInfoController setInfoForTorrents: [fTableView selectedTorrents]];
|
|
|
|
[[QuickLookController quickLook] updateQuickLook];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) setInfoTab: (id) sender
|
|
|
|
{
|
|
|
|
if (sender == fNextInfoTabItem)
|
|
|
|
[fInfoController setNextTab];
|
|
|
|
else
|
|
|
|
[fInfoController setPreviousTab];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showMessageWindow: (id) sender
|
|
|
|
{
|
|
|
|
[fMessageController showWindow: nil];
|
|
|
|
}
|
|
|
|
|
2007-11-19 18:13:41 +00:00
|
|
|
- (void) showStatsWindow: (id) sender
|
|
|
|
{
|
|
|
|
[[StatsWindowController statsWindow: fLib] showWindow: nil];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) updateUI
|
|
|
|
{
|
|
|
|
[fTorrents makeObjectsPerformSelector: @selector(update)];
|
|
|
|
|
2007-09-26 04:12:57 +00:00
|
|
|
if (![NSApp isHidden])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 04:12:57 +00:00
|
|
|
if ([fWindow isVisible])
|
|
|
|
{
|
2008-01-23 20:46:37 +00:00
|
|
|
[self sortTorrents];
|
2007-09-26 04:12:57 +00:00
|
|
|
|
2007-12-04 21:41:06 +00:00
|
|
|
//update status bar
|
2007-09-26 04:12:57 +00:00
|
|
|
if (![fStatusBar isHidden])
|
|
|
|
{
|
2007-12-04 21:41:06 +00:00
|
|
|
//set rates
|
2007-09-26 04:12:57 +00:00
|
|
|
float downloadRate, uploadRate;
|
2008-06-18 16:25:30 +00:00
|
|
|
tr_sessionGetSpeed(fLib, &downloadRate, &uploadRate);
|
2007-09-26 04:12:57 +00:00
|
|
|
|
2007-12-01 15:59:13 +00:00
|
|
|
[fTotalDLField setStringValue: [NSString stringForSpeed: downloadRate]];
|
|
|
|
[fTotalULField setStringValue: [NSString stringForSpeed: uploadRate]];
|
2007-12-04 21:41:06 +00:00
|
|
|
|
|
|
|
//set status button text
|
2007-12-05 01:26:30 +00:00
|
|
|
NSString * statusLabel = [fDefaults stringForKey: @"StatusLabel"], * statusString;
|
2007-12-05 01:42:53 +00:00
|
|
|
BOOL total;
|
|
|
|
if ((total = [statusLabel isEqualToString: STATUS_RATIO_TOTAL]) || [statusLabel isEqualToString: STATUS_RATIO_SESSION])
|
2007-12-05 01:26:30 +00:00
|
|
|
{
|
|
|
|
tr_session_stats stats;
|
2007-12-05 01:42:53 +00:00
|
|
|
if (total)
|
2008-05-22 20:44:41 +00:00
|
|
|
tr_sessionGetCumulativeStats(fLib, &stats);
|
2007-12-05 01:42:53 +00:00
|
|
|
else
|
2008-05-22 20:44:41 +00:00
|
|
|
tr_sessionGetStats(fLib, &stats);
|
2007-12-05 01:26:30 +00:00
|
|
|
|
2008-06-18 16:25:30 +00:00
|
|
|
statusString = [NSLocalizedString(@"Ratio", "status bar -> status label") stringByAppendingFormat: @": %@",
|
2008-03-18 21:59:17 +00:00
|
|
|
[NSString stringForRatio: stats.ratio]];
|
2007-12-05 01:26:30 +00:00
|
|
|
}
|
2008-03-15 14:57:42 +00:00
|
|
|
else //STATUS_TRANSFER_TOTAL or STATUS_TRANSFER_SESSION
|
2007-12-05 01:26:30 +00:00
|
|
|
{
|
2008-03-15 14:57:42 +00:00
|
|
|
total = [statusLabel isEqualToString: STATUS_TRANSFER_TOTAL];
|
|
|
|
|
2007-12-05 01:26:30 +00:00
|
|
|
tr_session_stats stats;
|
2007-12-05 01:42:53 +00:00
|
|
|
if (total)
|
2008-05-22 20:44:41 +00:00
|
|
|
tr_sessionGetCumulativeStats(fLib, &stats);
|
2007-12-05 01:42:53 +00:00
|
|
|
else
|
2008-05-22 20:44:41 +00:00
|
|
|
tr_sessionGetStats(fLib, &stats);
|
2007-12-05 01:26:30 +00:00
|
|
|
|
2008-03-18 21:59:17 +00:00
|
|
|
statusString = [NSString stringWithFormat: @"%@: %@ %@: %@",
|
|
|
|
NSLocalizedString(@"DL", "status bar -> status label"), [NSString stringForFileSize: stats.downloadedBytes],
|
|
|
|
NSLocalizedString(@"UL", "status bar -> status label"), [NSString stringForFileSize: stats.uploadedBytes]];
|
2007-12-05 01:26:30 +00:00
|
|
|
}
|
2007-12-04 21:41:06 +00:00
|
|
|
|
2007-12-12 16:28:40 +00:00
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
{
|
|
|
|
[fStatusButton setTitle: statusString];
|
2008-03-28 01:28:57 +00:00
|
|
|
[self resizeStatusButton];
|
2007-12-12 16:28:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[fStatusTigerField setStringValue: statusString];
|
2007-09-26 04:12:57 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-26 04:12:57 +00:00
|
|
|
//update non-constant parts of info window
|
|
|
|
if ([[fInfoController window] isVisible])
|
|
|
|
[fInfoController updateInfoStats];
|
|
|
|
}
|
2007-10-19 01:24:42 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//badge dock
|
2007-12-28 18:25:20 +00:00
|
|
|
[fBadger updateBadge];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-28 01:28:57 +00:00
|
|
|
- (void) resizeStatusButton
|
|
|
|
{
|
|
|
|
[fStatusButton sizeToFit];
|
|
|
|
|
|
|
|
//width ends up being too long
|
|
|
|
NSRect statusFrame = [fStatusButton frame];
|
|
|
|
statusFrame.size.width -= 25.0;
|
|
|
|
|
|
|
|
float difference = NSMaxX(statusFrame) + 5.0 - [fTotalDLImageView frame].origin.x;
|
|
|
|
if (difference > 0)
|
|
|
|
statusFrame.size.width -= difference;
|
|
|
|
|
|
|
|
[fStatusButton setFrame: statusFrame];
|
|
|
|
}
|
|
|
|
|
2008-03-21 20:28:04 +00:00
|
|
|
- (void) setBottomCountText: (BOOL) filtering
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
|
|
|
NSString * totalTorrentsString;
|
|
|
|
int totalCount = [fTorrents count];
|
|
|
|
if (totalCount != 1)
|
|
|
|
totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%d transfers", "Status bar transfer count"), totalCount];
|
|
|
|
else
|
|
|
|
totalTorrentsString = NSLocalizedString(@"1 transfer", "Status bar transfer count");
|
|
|
|
|
|
|
|
if (filtering)
|
|
|
|
{
|
2008-06-19 16:37:05 +00:00
|
|
|
int count = [fTableView numberOfRows]; //have to factor in collapsed rows
|
|
|
|
if (count > 0 && ![[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [Torrent class]])
|
|
|
|
count -= [fDisplayedTorrents count];
|
2008-02-06 23:45:44 +00:00
|
|
|
|
|
|
|
totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%d of %@", "Status bar transfer count"),
|
|
|
|
count, totalTorrentsString];
|
|
|
|
}
|
|
|
|
|
|
|
|
[fTotalTorrentsField setStringValue: totalTorrentsString];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) updateTorrentsInQueue
|
|
|
|
{
|
|
|
|
BOOL download = [fDefaults boolForKey: @"Queue"],
|
|
|
|
seed = [fDefaults boolForKey: @"QueueSeed"];
|
|
|
|
|
|
|
|
int desiredDownloadActive = [self numToStartFromQueue: YES],
|
|
|
|
desiredSeedActive = [self numToStartFromQueue: NO];
|
|
|
|
|
|
|
|
Torrent * torrent;
|
2008-06-21 19:01:46 +00:00
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if (![torrent isActive] && ![torrent isChecking] && [torrent waitingToStart])
|
|
|
|
{
|
|
|
|
if (![torrent allDownloaded])
|
|
|
|
{
|
|
|
|
if (!download || desiredDownloadActive > 0)
|
|
|
|
{
|
|
|
|
[torrent startTransfer];
|
|
|
|
if ([torrent isActive])
|
|
|
|
desiredDownloadActive--;
|
|
|
|
[torrent update];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!seed || desiredSeedActive > 0)
|
|
|
|
{
|
|
|
|
[torrent startTransfer];
|
|
|
|
if ([torrent isActive])
|
|
|
|
desiredSeedActive--;
|
|
|
|
[torrent update];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self updateUI];
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) numToStartFromQueue: (BOOL) downloadQueue
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: downloadQueue ? @"Queue" : @"QueueSeed"])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int desired = [fDefaults integerForKey: downloadQueue ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
|
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if ([torrent isChecking])
|
|
|
|
{
|
|
|
|
desired--;
|
|
|
|
if (desired <= 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
|
|
|
|
{
|
|
|
|
if ([torrent allDownloaded] != downloadQueue)
|
|
|
|
{
|
|
|
|
desired--;
|
|
|
|
if (desired <= 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
}
|
|
|
|
|
|
|
|
return desired;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) torrentFinishedDownloading: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
Torrent * torrent = [notification object];
|
2008-04-10 16:37:07 +00:00
|
|
|
|
2008-04-14 00:05:16 +00:00
|
|
|
if ([torrent isActive])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-14 00:05:16 +00:00
|
|
|
if (!fSoundPlaying && [fDefaults boolForKey: @"PlayDownloadSound"])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-14 00:05:16 +00:00
|
|
|
NSSound * sound;
|
|
|
|
if ((sound = [NSSound soundNamed: [fDefaults stringForKey: @"DownloadSound"]]))
|
|
|
|
{
|
|
|
|
[sound setDelegate: self];
|
|
|
|
fSoundPlaying = YES;
|
|
|
|
[sound play];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-04-14 00:05:16 +00:00
|
|
|
|
|
|
|
NSDictionary * clickContext = [NSDictionary dictionaryWithObjectsAndKeys: GROWL_DOWNLOAD_COMPLETE, @"Type",
|
|
|
|
[torrent dataLocation] , @"Location", nil];
|
|
|
|
[GrowlApplicationBridge notifyWithTitle: NSLocalizedString(@"Download Complete", "Growl notification title")
|
|
|
|
description: [torrent name] notificationName: GROWL_DOWNLOAD_COMPLETE
|
|
|
|
iconData: nil priority: 0 isSticky: NO clickContext: clickContext];
|
|
|
|
|
|
|
|
if (![fWindow isMainWindow])
|
|
|
|
[fBadger incrementCompleted];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([fDefaults boolForKey: @"QueueSeed"] && [self numToStartFromQueue: NO] <= 0)
|
|
|
|
{
|
|
|
|
[torrent stopTransfer];
|
|
|
|
[torrent setWaitToStart: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) torrentRestartedDownloading: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
Torrent * torrent = [notification object];
|
|
|
|
if ([torrent isActive])
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"Queue"] && [self numToStartFromQueue: YES] <= 0)
|
|
|
|
{
|
|
|
|
[torrent stopTransfer];
|
|
|
|
[torrent setWaitToStart: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
|
|
|
}
|
|
|
|
|
2008-04-14 00:05:16 +00:00
|
|
|
- (void) torrentStoppedForRatio: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
Torrent * torrent = [notification object];
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
2008-06-03 16:20:21 +00:00
|
|
|
|
2008-06-03 16:28:09 +00:00
|
|
|
if ([[fTableView selectedTorrents] containsObject: torrent])
|
|
|
|
{
|
|
|
|
[fInfoController updateInfoStats];
|
|
|
|
[fInfoController updateOptions];
|
|
|
|
}
|
2008-04-14 00:05:16 +00:00
|
|
|
|
|
|
|
if (!fSoundPlaying && [fDefaults boolForKey: @"PlaySeedingSound"])
|
|
|
|
{
|
|
|
|
NSSound * sound;
|
|
|
|
if ((sound = [NSSound soundNamed: [fDefaults stringForKey: @"SeedingSound"]]))
|
|
|
|
{
|
|
|
|
[sound setDelegate: self];
|
|
|
|
fSoundPlaying = YES;
|
|
|
|
[sound play];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSDictionary * clickContext = [NSDictionary dictionaryWithObjectsAndKeys: GROWL_SEEDING_COMPLETE, @"Type",
|
|
|
|
[torrent dataLocation], @"Location", nil];
|
|
|
|
[GrowlApplicationBridge notifyWithTitle: NSLocalizedString(@"Seeding Complete", "Growl notification title")
|
|
|
|
description: [torrent name] notificationName: GROWL_SEEDING_COMPLETE
|
|
|
|
iconData: nil priority: 0 isSticky: NO clickContext: clickContext];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) updateTorrentHistory
|
|
|
|
{
|
|
|
|
NSMutableArray * history = [NSMutableArray arrayWithCapacity: [fTorrents count]];
|
|
|
|
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[history addObject: [torrent history]];
|
|
|
|
|
2007-10-21 14:01:54 +00:00
|
|
|
[history writeToFile: [NSHomeDirectory() stringByAppendingPathComponent: SUPPORT_FOLDER] atomically: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 17:22:41 +00:00
|
|
|
- (void) setSort: (id) sender
|
|
|
|
{
|
|
|
|
NSString * sortType;
|
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case SORT_ORDER_TAG:
|
|
|
|
sortType = SORT_ORDER;
|
|
|
|
[fDefaults setBool: NO forKey: @"SortReverse"];
|
|
|
|
break;
|
|
|
|
case SORT_DATE_TAG:
|
|
|
|
sortType = SORT_DATE;
|
|
|
|
break;
|
|
|
|
case SORT_NAME_TAG:
|
|
|
|
sortType = SORT_NAME;
|
|
|
|
break;
|
|
|
|
case SORT_PROGRESS_TAG:
|
|
|
|
sortType = SORT_PROGRESS;
|
|
|
|
break;
|
|
|
|
case SORT_STATE_TAG:
|
|
|
|
sortType = SORT_STATE;
|
|
|
|
break;
|
|
|
|
case SORT_TRACKER_TAG:
|
|
|
|
sortType = SORT_TRACKER;
|
|
|
|
break;
|
|
|
|
case SORT_ACTIVITY_TAG:
|
|
|
|
sortType = SORT_ACTIVITY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setObject: sortType forKey: @"Sort"];
|
2008-01-23 20:46:37 +00:00
|
|
|
[self sortTorrents];
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSortByGroup: (id) sender
|
|
|
|
{
|
2008-02-07 02:15:24 +00:00
|
|
|
BOOL sortByGroup = ![fDefaults boolForKey: @"SortByGroup"];
|
|
|
|
[fDefaults setBool: sortByGroup forKey: @"SortByGroup"];
|
|
|
|
|
|
|
|
//expand all groups
|
|
|
|
if (sortByGroup)
|
|
|
|
[fTableView removeAllCollapsedGroups];
|
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSortReverse: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"SortReverse"] forKey: @"SortReverse"];
|
2008-01-23 20:46:37 +00:00
|
|
|
[self sortTorrents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) sortTorrents
|
|
|
|
{
|
|
|
|
NSArray * selectedValues = [fTableView selectedValues];
|
|
|
|
|
|
|
|
[self sortTorrentsIgnoreSelected]; //actually sort
|
|
|
|
|
|
|
|
[fTableView selectValues: selectedValues];
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 20:46:37 +00:00
|
|
|
- (void) sortTorrentsIgnoreSelected
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSString * sortType = [fDefaults stringForKey: @"Sort"];
|
|
|
|
BOOL asc = ![fDefaults boolForKey: @"SortReverse"];
|
|
|
|
|
2008-01-31 00:24:44 +00:00
|
|
|
NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" ascending: asc] autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSArray * descriptors;
|
2007-12-30 19:02:40 +00:00
|
|
|
if ([sortType isEqualToString: SORT_ORDER])
|
2007-12-30 18:53:44 +00:00
|
|
|
descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
|
2008-01-31 00:40:37 +00:00
|
|
|
else if ([sortType isEqualToString: SORT_NAME])
|
|
|
|
{
|
|
|
|
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
|
|
|
|
selector: @selector(caseInsensitiveCompare:)] autorelease];
|
|
|
|
|
|
|
|
descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, orderDescriptor, nil];
|
|
|
|
}
|
|
|
|
else if ([sortType isEqualToString: SORT_STATE])
|
|
|
|
{
|
|
|
|
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
|
|
|
|
selector: @selector(caseInsensitiveCompare:)] autorelease],
|
|
|
|
* stateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"stateSortKey" ascending: !asc] autorelease],
|
|
|
|
* progressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progress" ascending: !asc] autorelease],
|
|
|
|
* ratioDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"ratio" ascending: !asc] autorelease];
|
|
|
|
|
|
|
|
descriptors = [[NSArray alloc] initWithObjects: stateDescriptor, progressDescriptor, ratioDescriptor,
|
|
|
|
nameDescriptor, orderDescriptor, nil];
|
|
|
|
}
|
|
|
|
else if ([sortType isEqualToString: SORT_PROGRESS])
|
|
|
|
{
|
|
|
|
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
|
|
|
|
selector: @selector(caseInsensitiveCompare:)] autorelease],
|
|
|
|
* progressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progress" ascending: asc] autorelease],
|
|
|
|
* ratioProgressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progressStopRatio"
|
|
|
|
ascending: asc] autorelease],
|
|
|
|
* ratioDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"ratio" ascending: asc] autorelease];
|
|
|
|
|
|
|
|
descriptors = [[NSArray alloc] initWithObjects: progressDescriptor, ratioProgressDescriptor, ratioDescriptor,
|
|
|
|
nameDescriptor, orderDescriptor, nil];
|
|
|
|
}
|
|
|
|
else if ([sortType isEqualToString: SORT_TRACKER])
|
|
|
|
{
|
|
|
|
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
|
|
|
|
selector: @selector(caseInsensitiveCompare:)] autorelease],
|
2008-05-06 01:53:15 +00:00
|
|
|
* trackerDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"trackerAddressAnnounce" ascending: asc
|
2008-01-31 00:40:37 +00:00
|
|
|
selector: @selector(caseInsensitiveCompare:)] autorelease];
|
|
|
|
|
|
|
|
descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, orderDescriptor, nil];
|
|
|
|
}
|
|
|
|
else if ([sortType isEqualToString: SORT_ACTIVITY])
|
|
|
|
{
|
|
|
|
NSSortDescriptor * rateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"totalRate" ascending: !asc] autorelease];
|
|
|
|
NSSortDescriptor * activityDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"dateActivityOrAdd" ascending: !asc]
|
|
|
|
autorelease];
|
|
|
|
|
|
|
|
descriptors = [[NSArray alloc] initWithObjects: rateDescriptor, activityDescriptor, orderDescriptor, nil];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
2008-01-31 00:40:37 +00:00
|
|
|
NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"dateAdded" ascending: asc] autorelease];
|
|
|
|
|
|
|
|
descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
//on Tiger add the group sort descriptor to the front
|
|
|
|
if (![NSApp isOnLeopardOrBetter] && [fDefaults boolForKey: @"SortByGroup"])
|
|
|
|
{
|
|
|
|
NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" ascending: YES] autorelease];
|
2007-12-17 19:47:06 +00:00
|
|
|
|
2008-01-31 00:40:37 +00:00
|
|
|
NSMutableArray * temp = [[NSMutableArray alloc] initWithCapacity: [descriptors count]+1];
|
|
|
|
[temp addObject: groupDescriptor];
|
|
|
|
[temp addObjectsFromArray: descriptors];
|
2007-12-17 19:47:06 +00:00
|
|
|
|
2008-01-31 00:40:37 +00:00
|
|
|
[descriptors release];
|
|
|
|
descriptors = temp;
|
2007-12-17 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 20:31:04 +00:00
|
|
|
//actually sort
|
|
|
|
if ([fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter])
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator];
|
|
|
|
NSDictionary * dict;
|
|
|
|
while ((dict = [enumerator nextObject]))
|
|
|
|
[[dict objectForKey: @"Torrents"] sortUsingDescriptors: descriptors];
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
2008-01-23 20:31:04 +00:00
|
|
|
else
|
|
|
|
[fDisplayedTorrents sortUsingDescriptors: descriptors];
|
|
|
|
|
|
|
|
[descriptors release];
|
2008-01-23 02:51:58 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fTableView reloadData];
|
|
|
|
}
|
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
- (void) applyFilter: (id) sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
//get all the torrents in the table
|
2008-02-10 16:56:13 +00:00
|
|
|
NSMutableArray * previousTorrents;
|
2008-02-06 23:45:44 +00:00
|
|
|
if ([fDisplayedTorrents count] > 0 && ![[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [Torrent class]])
|
|
|
|
{
|
2008-02-10 16:56:13 +00:00
|
|
|
previousTorrents = [NSMutableArray array];
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator];
|
|
|
|
NSDictionary * dict;
|
|
|
|
while ((dict = [enumerator nextObject]))
|
|
|
|
[previousTorrents addObjectsFromArray: [dict objectForKey: @"Torrents"]];
|
|
|
|
}
|
|
|
|
else
|
2008-02-11 00:16:47 +00:00
|
|
|
previousTorrents = fDisplayedTorrents;
|
2007-12-29 15:54:05 +00:00
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
NSArray * selectedValues = [fTableView selectedValues];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-31 01:47:37 +00:00
|
|
|
int active = 0, downloading = 0, seeding = 0, paused = 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
NSString * filterType = [fDefaults stringForKey: @"Filter"];
|
2007-12-20 04:49:06 +00:00
|
|
|
BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterStatus = YES;
|
|
|
|
if ([filterType isEqualToString: FILTER_ACTIVE])
|
|
|
|
filterActive = YES;
|
|
|
|
else if ([filterType isEqualToString: FILTER_DOWNLOAD])
|
2007-12-20 01:06:55 +00:00
|
|
|
filterDownload = YES;
|
|
|
|
else if ([filterType isEqualToString: FILTER_SEED])
|
|
|
|
filterSeed = YES;
|
|
|
|
else if ([filterType isEqualToString: FILTER_PAUSE])
|
|
|
|
filterPause = YES;
|
|
|
|
else
|
|
|
|
filterStatus = NO;
|
2007-12-20 01:00:03 +00:00
|
|
|
|
2007-12-20 01:06:55 +00:00
|
|
|
int groupFilterValue = [fDefaults integerForKey: @"FilterGroup"];
|
|
|
|
BOOL filterGroup = groupFilterValue != GROUP_FILTER_ALL_TAG;
|
2007-12-20 01:00:03 +00:00
|
|
|
|
2007-12-20 01:06:55 +00:00
|
|
|
NSString * searchString = [fSearchFilterField stringValue];
|
|
|
|
BOOL filterText = [searchString length] > 0,
|
|
|
|
filterTracker = filterText && [[fDefaults stringForKey: @"FilterSearchType"] isEqualToString: FILTER_TYPE_TRACKER];
|
2007-12-20 01:00:03 +00:00
|
|
|
|
|
|
|
NSMutableIndexSet * indexes = [NSMutableIndexSet indexSet];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//get count of each type
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
2008-01-23 17:11:06 +00:00
|
|
|
int i = -1;
|
2007-09-16 01:02:06 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
2007-12-20 01:00:03 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
//check status
|
2008-03-19 18:03:02 +00:00
|
|
|
if ([torrent isActive] && ![torrent isCheckingWaiting])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if ([torrent isSeeding])
|
|
|
|
{
|
|
|
|
seeding++;
|
2008-02-06 23:45:44 +00:00
|
|
|
BOOL isActive = ![torrent isStalled];
|
2007-12-31 01:47:37 +00:00
|
|
|
if (isActive)
|
|
|
|
active++;
|
|
|
|
|
|
|
|
if (filterStatus && (!(filterActive && isActive) && !filterSeed))
|
2007-12-20 01:00:03 +00:00
|
|
|
continue;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
downloading++;
|
2008-02-06 23:45:44 +00:00
|
|
|
BOOL isActive = ![torrent isStalled];
|
2007-12-31 01:47:37 +00:00
|
|
|
if (isActive)
|
|
|
|
active++;
|
|
|
|
|
|
|
|
if (filterStatus && (!(filterActive && isActive) && !filterDownload))
|
2007-12-20 01:00:03 +00:00
|
|
|
continue;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
paused++;
|
2007-12-20 01:00:03 +00:00
|
|
|
if (filterStatus && !filterPause)
|
|
|
|
continue;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-19 20:46:00 +00:00
|
|
|
|
2007-12-20 01:00:03 +00:00
|
|
|
//checkGroup
|
|
|
|
if (filterGroup)
|
2007-12-20 01:06:55 +00:00
|
|
|
if ([torrent groupValue] != groupFilterValue)
|
2007-12-20 01:00:03 +00:00
|
|
|
continue;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-20 01:00:03 +00:00
|
|
|
//check text field
|
|
|
|
if (filterText)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-25 20:14:24 +00:00
|
|
|
if (filterTracker)
|
|
|
|
{
|
2007-12-20 01:42:30 +00:00
|
|
|
BOOL removeTextField = YES;
|
2008-03-21 21:07:31 +00:00
|
|
|
NSEnumerator * trackerEnumerator = [[torrent allTrackers: NO] objectEnumerator];
|
2008-03-22 17:05:48 +00:00
|
|
|
NSString * tracker;
|
2008-03-21 21:07:31 +00:00
|
|
|
while ((tracker = [trackerEnumerator nextObject]))
|
2007-10-25 20:14:24 +00:00
|
|
|
{
|
2008-03-21 21:07:31 +00:00
|
|
|
if ([tracker rangeOfString: searchString options: NSCaseInsensitiveSearch].location != NSNotFound)
|
2008-03-21 20:28:04 +00:00
|
|
|
{
|
|
|
|
removeTextField = NO;
|
|
|
|
break;
|
|
|
|
}
|
2007-10-25 20:14:24 +00:00
|
|
|
}
|
2007-12-20 01:00:03 +00:00
|
|
|
|
|
|
|
if (removeTextField)
|
|
|
|
continue;
|
2007-10-25 20:14:24 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2007-12-20 01:00:03 +00:00
|
|
|
{
|
|
|
|
if ([[torrent name] rangeOfString: searchString options: NSCaseInsensitiveSearch].location == NSNotFound)
|
|
|
|
continue;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-20 01:00:03 +00:00
|
|
|
|
|
|
|
[indexes addIndex: i];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-11 00:16:47 +00:00
|
|
|
NSArray * allTorrents = [fTorrents objectsAtIndexes: indexes];
|
2007-12-20 01:00:03 +00:00
|
|
|
|
|
|
|
//set button tooltips
|
|
|
|
[fNoFilterButton setCount: [fTorrents count]];
|
2007-12-31 01:47:37 +00:00
|
|
|
[fActiveFilterButton setCount: active];
|
2007-12-20 01:00:03 +00:00
|
|
|
[fDownloadFilterButton setCount: downloading];
|
|
|
|
[fSeedFilterButton setCount: seeding];
|
|
|
|
[fPauseFilterButton setCount: paused];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-23 17:03:42 +00:00
|
|
|
//clear display cache for not-shown torrents
|
2008-02-11 00:16:47 +00:00
|
|
|
[previousTorrents removeObjectsInArray: allTorrents];
|
2008-01-23 17:03:42 +00:00
|
|
|
enumerator = [previousTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2008-06-11 16:28:33 +00:00
|
|
|
[torrent setPreviousFinishedPieces: nil];
|
2008-01-23 17:03:42 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
//place torrents into groups
|
2008-02-07 16:52:38 +00:00
|
|
|
BOOL groupRows = [fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter];
|
|
|
|
if (groupRows)
|
2008-01-23 20:31:04 +00:00
|
|
|
{
|
2008-05-12 21:38:24 +00:00
|
|
|
[fDisplayedTorrents removeAllObjects];
|
|
|
|
|
2008-01-23 20:31:04 +00:00
|
|
|
NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" ascending: YES] autorelease];
|
2008-02-11 00:16:47 +00:00
|
|
|
allTorrents = [allTorrents sortedArrayUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
|
2008-01-23 20:31:04 +00:00
|
|
|
|
2008-05-12 21:38:24 +00:00
|
|
|
NSMutableArray * groupTorrents;
|
2008-02-07 01:26:12 +00:00
|
|
|
int oldGroupValue = -2;
|
2008-02-11 00:16:47 +00:00
|
|
|
for (i = 0; i < [allTorrents count]; i++)
|
2008-01-23 20:31:04 +00:00
|
|
|
{
|
2008-05-06 01:53:15 +00:00
|
|
|
torrent = [allTorrents objectAtIndex: i];
|
2008-02-06 23:45:44 +00:00
|
|
|
int groupValue = [torrent groupValue];
|
2008-01-30 22:14:19 +00:00
|
|
|
if (groupValue != oldGroupValue)
|
2008-01-23 20:31:04 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
groupTorrents = [NSMutableArray array];
|
|
|
|
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: groupValue], @"Group",
|
|
|
|
groupTorrents, @"Torrents", nil];
|
2008-05-12 21:38:24 +00:00
|
|
|
[fDisplayedTorrents addObject: dict];
|
2008-01-23 20:31:04 +00:00
|
|
|
|
2008-01-30 22:14:19 +00:00
|
|
|
oldGroupValue = groupValue;
|
2008-01-23 20:31:04 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
|
|
|
|
[groupTorrents addObject: torrent];
|
2008-01-23 20:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-11 00:16:47 +00:00
|
|
|
else
|
|
|
|
[fDisplayedTorrents setArray: allTorrents];
|
2008-01-23 20:31:04 +00:00
|
|
|
|
2008-01-23 20:46:37 +00:00
|
|
|
//actually sort
|
|
|
|
[self sortTorrentsIgnoreSelected];
|
2008-01-23 02:51:58 +00:00
|
|
|
[fTableView selectValues: selectedValues];
|
2008-06-26 03:35:20 +00:00
|
|
|
[self resetInfo]; //if group is already selected, but the torrents in it change
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-02-07 01:26:12 +00:00
|
|
|
//reset expanded/collapsed rows
|
2008-02-07 16:52:38 +00:00
|
|
|
if (groupRows)
|
2008-02-07 01:26:12 +00:00
|
|
|
{
|
|
|
|
enumerator = [fDisplayedTorrents objectEnumerator];
|
|
|
|
NSDictionary * dict;
|
|
|
|
while ((dict = [enumerator nextObject]))
|
|
|
|
{
|
2008-02-07 16:20:24 +00:00
|
|
|
if ([fTableView isGroupCollapsed: [[dict objectForKey: @"Group"] intValue]])
|
|
|
|
[fTableView collapseItem: dict];
|
2008-02-07 16:23:22 +00:00
|
|
|
else
|
|
|
|
[fTableView expandItem: dict];
|
2008-02-07 01:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-21 20:28:04 +00:00
|
|
|
[self setBottomCountText: groupRows || filterStatus || filterGroup || filterText];
|
2008-05-12 21:38:24 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setWindowSizeToFit];
|
|
|
|
}
|
|
|
|
|
|
|
|
//resets filter and sorts torrents
|
|
|
|
- (void) setFilter: (id) sender
|
|
|
|
{
|
|
|
|
NSString * oldFilterType = [fDefaults stringForKey: @"Filter"];
|
|
|
|
|
2007-11-06 20:52:11 +00:00
|
|
|
NSButton * prevFilterButton;
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([oldFilterType isEqualToString: FILTER_PAUSE])
|
|
|
|
prevFilterButton = fPauseFilterButton;
|
2007-12-20 04:49:06 +00:00
|
|
|
else if ([oldFilterType isEqualToString: FILTER_ACTIVE])
|
|
|
|
prevFilterButton = fActiveFilterButton;
|
2007-09-16 01:02:06 +00:00
|
|
|
else if ([oldFilterType isEqualToString: FILTER_SEED])
|
|
|
|
prevFilterButton = fSeedFilterButton;
|
|
|
|
else if ([oldFilterType isEqualToString: FILTER_DOWNLOAD])
|
|
|
|
prevFilterButton = fDownloadFilterButton;
|
|
|
|
else
|
|
|
|
prevFilterButton = fNoFilterButton;
|
|
|
|
|
|
|
|
if (sender != prevFilterButton)
|
|
|
|
{
|
|
|
|
[prevFilterButton setState: NSOffState];
|
|
|
|
[sender setState: NSOnState];
|
|
|
|
|
|
|
|
NSString * filterType;
|
2007-12-20 04:49:06 +00:00
|
|
|
if (sender == fActiveFilterButton)
|
|
|
|
filterType = FILTER_ACTIVE;
|
|
|
|
else if (sender == fDownloadFilterButton)
|
2007-09-16 01:02:06 +00:00
|
|
|
filterType = FILTER_DOWNLOAD;
|
|
|
|
else if (sender == fPauseFilterButton)
|
|
|
|
filterType = FILTER_PAUSE;
|
|
|
|
else if (sender == fSeedFilterButton)
|
|
|
|
filterType = FILTER_SEED;
|
|
|
|
else
|
|
|
|
filterType = FILTER_NONE;
|
|
|
|
|
|
|
|
[fDefaults setObject: filterType forKey: @"Filter"];
|
|
|
|
}
|
2007-11-16 22:03:59 +00:00
|
|
|
else
|
|
|
|
[sender setState: NSOnState];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFilterSearchType: (id) sender
|
|
|
|
{
|
|
|
|
NSString * oldFilterType = [fDefaults stringForKey: @"FilterSearchType"];
|
|
|
|
|
|
|
|
int prevTag, currentTag = [sender tag];
|
|
|
|
if ([oldFilterType isEqualToString: FILTER_TYPE_TRACKER])
|
|
|
|
prevTag = FILTER_TYPE_TAG_TRACKER;
|
|
|
|
else
|
|
|
|
prevTag = FILTER_TYPE_TAG_NAME;
|
|
|
|
|
|
|
|
if (currentTag != prevTag)
|
|
|
|
{
|
|
|
|
NSString * filterType;
|
|
|
|
if (currentTag == FILTER_TYPE_TAG_TRACKER)
|
|
|
|
filterType = FILTER_TYPE_TRACKER;
|
|
|
|
else
|
|
|
|
filterType = FILTER_TYPE_NAME;
|
|
|
|
|
|
|
|
[fDefaults setObject: filterType forKey: @"FilterSearchType"];
|
|
|
|
|
|
|
|
[[fSearchFilterField cell] setPlaceholderString: [sender title]];
|
|
|
|
}
|
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) switchFilter: (id) sender
|
|
|
|
{
|
|
|
|
NSString * filterType = [fDefaults stringForKey: @"Filter"];
|
|
|
|
|
2007-11-06 20:52:11 +00:00
|
|
|
NSButton * button;
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([filterType isEqualToString: FILTER_NONE])
|
2007-12-20 04:49:06 +00:00
|
|
|
button = sender == fNextFilterItem ? fActiveFilterButton : fPauseFilterButton;
|
|
|
|
else if ([filterType isEqualToString: FILTER_ACTIVE])
|
|
|
|
button = sender == fNextFilterItem ? fDownloadFilterButton : fNoFilterButton;
|
2007-09-16 01:02:06 +00:00
|
|
|
else if ([filterType isEqualToString: FILTER_DOWNLOAD])
|
2007-12-20 04:49:06 +00:00
|
|
|
button = sender == fNextFilterItem ? fSeedFilterButton : fActiveFilterButton;
|
2007-09-16 01:02:06 +00:00
|
|
|
else if ([filterType isEqualToString: FILTER_SEED])
|
|
|
|
button = sender == fNextFilterItem ? fPauseFilterButton : fDownloadFilterButton;
|
|
|
|
else if ([filterType isEqualToString: FILTER_PAUSE])
|
|
|
|
button = sender == fNextFilterItem ? fNoFilterButton : fSeedFilterButton;
|
|
|
|
else
|
|
|
|
button = fNoFilterButton;
|
|
|
|
|
|
|
|
[self setFilter: button];
|
|
|
|
}
|
|
|
|
|
2007-12-05 01:26:30 +00:00
|
|
|
- (void) setStatusLabel: (id) sender
|
|
|
|
{
|
|
|
|
NSString * statusLabel;
|
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case STATUS_RATIO_TOTAL_TAG:
|
|
|
|
statusLabel = STATUS_RATIO_TOTAL;
|
|
|
|
break;
|
|
|
|
case STATUS_RATIO_SESSION_TAG:
|
|
|
|
statusLabel = STATUS_RATIO_SESSION;
|
|
|
|
break;
|
|
|
|
case STATUS_TRANSFER_TOTAL_TAG:
|
|
|
|
statusLabel = STATUS_TRANSFER_TOTAL;
|
|
|
|
break;
|
|
|
|
case STATUS_TRANSFER_SESSION_TAG:
|
|
|
|
statusLabel = STATUS_TRANSFER_SESSION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setObject: statusLabel forKey: @"StatusLabel"];
|
|
|
|
[self updateUI];
|
|
|
|
}
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
- (void) showGroups: (id) sender
|
|
|
|
{
|
2008-03-23 00:56:43 +00:00
|
|
|
[[GroupsWindowController groupsWindow] showWindow: self];
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) menuNeedsUpdate: (NSMenu *) menu
|
|
|
|
{
|
2007-12-17 22:30:28 +00:00
|
|
|
if (menu == fGroupsSetMenu || menu == fGroupsSetContextMenu)
|
|
|
|
{
|
2008-01-05 22:32:34 +00:00
|
|
|
int i;
|
|
|
|
for (i = [menu numberOfItems]-1 - 2; i >= 0; i--)
|
2007-12-17 22:30:28 +00:00
|
|
|
[menu removeItemAtIndex: i];
|
|
|
|
|
2008-03-23 00:56:43 +00:00
|
|
|
NSMenu * groupMenu = [[GroupsController groups] groupMenuWithTarget: self action: @selector(setGroup:) isSmall: NO];
|
2007-12-17 22:30:28 +00:00
|
|
|
[menu appendItemsFromMenu: groupMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange:
|
|
|
|
NSMakeRange(0, [groupMenu numberOfItems])] atBottom: NO];
|
|
|
|
}
|
2007-12-19 20:46:00 +00:00
|
|
|
else if (menu == fGroupFilterMenu)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = [menu numberOfItems]-1; i >= 3; i--)
|
|
|
|
[menu removeItemAtIndex: i];
|
|
|
|
|
2008-03-23 00:56:43 +00:00
|
|
|
NSMenu * groupMenu = [[GroupsController groups] groupMenuWithTarget: self action: @selector(setGroupFilter:)
|
2007-12-19 20:46:00 +00:00
|
|
|
isSmall: YES];
|
|
|
|
[menu appendItemsFromMenu: groupMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange:
|
|
|
|
NSMakeRange(0, [groupMenu numberOfItems])] atBottom: YES];
|
|
|
|
}
|
2008-01-10 06:27:48 +00:00
|
|
|
else if (menu == fUploadMenu || menu == fDownloadMenu)
|
|
|
|
{
|
|
|
|
if ([menu numberOfItems] > 3)
|
|
|
|
return;
|
|
|
|
|
2008-01-10 07:00:56 +00:00
|
|
|
const int speedLimitActionValue[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 };
|
|
|
|
|
2008-01-10 06:27:48 +00:00
|
|
|
NSMenuItem * item;
|
|
|
|
int i;
|
2008-01-10 07:00:56 +00:00
|
|
|
for (i = 0; speedLimitActionValue[i] != -1; i++)
|
2008-01-10 06:27:48 +00:00
|
|
|
{
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s",
|
2008-01-10 07:00:56 +00:00
|
|
|
"Action menu -> upload/download limit"), speedLimitActionValue[i]] action: @selector(setQuickLimitGlobal:)
|
2008-01-10 06:27:48 +00:00
|
|
|
keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
2008-01-10 07:00:56 +00:00
|
|
|
[item setRepresentedObject: [NSNumber numberWithInt: speedLimitActionValue[i]]];
|
2008-01-10 06:27:48 +00:00
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (menu == fRatioStopMenu)
|
|
|
|
{
|
|
|
|
if ([menu numberOfItems] > 3)
|
|
|
|
return;
|
|
|
|
|
2008-01-10 07:00:56 +00:00
|
|
|
const float ratioLimitActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1 };
|
|
|
|
|
2008-01-10 06:27:48 +00:00
|
|
|
NSMenuItem * item;
|
|
|
|
int i;
|
2008-01-10 07:00:56 +00:00
|
|
|
for (i = 0; ratioLimitActionValue[i] != -1; i++)
|
2008-01-10 06:27:48 +00:00
|
|
|
{
|
2008-03-24 00:06:54 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSString localizedStringWithFormat: @"%.2f", ratioLimitActionValue[i]]
|
2008-01-10 15:53:02 +00:00
|
|
|
action: @selector(setQuickRatioGlobal:) keyEquivalent: @""];
|
2008-01-10 06:27:48 +00:00
|
|
|
[item setTarget: self];
|
2008-01-10 07:00:56 +00:00
|
|
|
[item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitActionValue[i]]];
|
2008-01-10 06:27:48 +00:00
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
}
|
|
|
|
}
|
2007-12-19 20:46:00 +00:00
|
|
|
else;
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setGroup: (id) sender
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-12-17 16:06:20 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2008-02-07 15:57:32 +00:00
|
|
|
{
|
|
|
|
[fTableView removeCollapsedGroup: [torrent groupValue]]; //remove old collapsed group
|
|
|
|
|
2007-12-19 15:35:23 +00:00
|
|
|
[torrent setGroupValue: [sender tag]];
|
2008-02-07 15:57:32 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-12-17 16:06:20 +00:00
|
|
|
[self updateUI];
|
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
2007-12-19 20:46:00 +00:00
|
|
|
- (void) setGroupFilter: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setInteger: [sender tag] forKey: @"FilterGroup"];
|
2007-12-19 21:11:49 +00:00
|
|
|
[self updateGroupsFilterButton];
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-12-19 20:46:00 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 21:11:49 +00:00
|
|
|
- (void) updateGroupsFilterButton
|
2007-12-19 20:46:00 +00:00
|
|
|
{
|
2008-05-06 01:53:15 +00:00
|
|
|
int groupIndex = [fDefaults integerForKey: @"FilterGroup"];
|
2007-12-19 20:46:00 +00:00
|
|
|
|
2008-06-04 17:15:24 +00:00
|
|
|
NSImage * icon;
|
2007-12-19 20:46:00 +00:00
|
|
|
NSString * toolTip;
|
2008-06-05 02:46:39 +00:00
|
|
|
if (groupIndex == GROUP_FILTER_ALL_TAG)
|
2007-12-19 20:46:00 +00:00
|
|
|
{
|
2008-06-05 02:46:39 +00:00
|
|
|
icon = [NSImage imageNamed: @"PinTemplate.png"];
|
|
|
|
toolTip = NSLocalizedString(@"All Groups", "Groups -> Button");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
icon = [[GroupsController groups] imageForIndex: groupIndex];
|
|
|
|
NSString * groupName = groupIndex != -1 ? [[GroupsController groups] nameForIndex: groupIndex]
|
|
|
|
: NSLocalizedString(@"None", "Groups -> Button");
|
2008-06-05 05:00:24 +00:00
|
|
|
toolTip = [NSLocalizedString(@"Group", "Groups -> Button") stringByAppendingFormat: @": %@", groupName];
|
2007-12-19 20:46:00 +00:00
|
|
|
}
|
2007-12-21 16:29:42 +00:00
|
|
|
|
2008-06-04 17:25:51 +00:00
|
|
|
//tiger doesn't have built-in image scaling in buttons
|
2008-06-04 17:15:24 +00:00
|
|
|
if (![NSApp isOnLeopardOrBetter])
|
|
|
|
{
|
|
|
|
icon = [[icon copy] autorelease];
|
|
|
|
[icon setScalesWhenResized: YES];
|
|
|
|
[icon setSize: NSMakeSize(12.0, 12.0)];
|
|
|
|
}
|
|
|
|
|
2007-12-21 16:29:42 +00:00
|
|
|
[[fGroupFilterMenu itemAtIndex: 0] setImage: icon];
|
2007-12-19 20:46:00 +00:00
|
|
|
[fGroupsButton setToolTip: toolTip];
|
|
|
|
}
|
|
|
|
|
2007-12-19 21:11:49 +00:00
|
|
|
- (void) updateGroupsFilters: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
[self updateGroupsFilterButton];
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-12-19 21:11:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) toggleSpeedLimit: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"SpeedLimit"] forKey: @"SpeedLimit"];
|
2007-10-30 20:19:22 +00:00
|
|
|
[fPrefsController applySpeedSettings: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) autoSpeedLimitChange: (NSNotification *) notification
|
|
|
|
{
|
2008-06-19 02:53:45 +00:00
|
|
|
//clear timer here in case its not being reset
|
|
|
|
[fSpeedLimitTimer invalidate];
|
|
|
|
fSpeedLimitTimer = nil;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (![fDefaults boolForKey: @"SpeedLimitAuto"])
|
|
|
|
return;
|
2008-06-19 15:54:59 +00:00
|
|
|
|
2008-06-19 20:53:08 +00:00
|
|
|
NSCalendar * calendar = [NSCalendar currentCalendar];
|
2008-06-19 16:37:05 +00:00
|
|
|
NSDateComponents * nowComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: [NSDate date]],
|
2008-06-19 15:54:59 +00:00
|
|
|
* onComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit
|
|
|
|
fromDate: [fDefaults objectForKey: @"SpeedLimitAutoOnDate"]],
|
|
|
|
* offComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit
|
|
|
|
fromDate: [fDefaults objectForKey: @"SpeedLimitAutoOffDate"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//check if should be on if within range
|
2008-06-19 15:54:59 +00:00
|
|
|
int onTime = [onComponents hour] * 60 + [onComponents minute],
|
|
|
|
offTime = [offComponents hour] * 60 + [offComponents minute],
|
|
|
|
nowTime = [nowComponents hour] * 60 + [nowComponents minute];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-19 01:24:42 +00:00
|
|
|
BOOL shouldBeOn = NO;
|
|
|
|
if (onTime < offTime)
|
2007-09-16 01:02:06 +00:00
|
|
|
shouldBeOn = onTime <= nowTime && nowTime < offTime;
|
2007-10-19 01:24:42 +00:00
|
|
|
else if (onTime > offTime)
|
2007-09-16 01:02:06 +00:00
|
|
|
shouldBeOn = onTime <= nowTime || nowTime < offTime;
|
2007-10-19 01:24:42 +00:00
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if ([fDefaults boolForKey: @"SpeedLimit"] != shouldBeOn)
|
|
|
|
[self toggleSpeedLimit: nil];
|
|
|
|
|
2008-06-19 15:54:59 +00:00
|
|
|
//no need to set the timer if both times are equal
|
2008-06-19 02:53:45 +00:00
|
|
|
if (onTime == offTime)
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-19 02:53:45 +00:00
|
|
|
[self setAutoSpeedLimitTimer: !shouldBeOn];
|
|
|
|
}
|
|
|
|
|
2008-06-19 15:54:59 +00:00
|
|
|
//only called by fSpeedLimitTimer
|
2008-06-19 02:53:45 +00:00
|
|
|
- (void) autoSpeedLimit: (NSTimer *) timer
|
|
|
|
{
|
2008-06-19 03:47:11 +00:00
|
|
|
BOOL shouldLimit = [[timer userInfo] boolValue];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-06-19 03:47:11 +00:00
|
|
|
if ([fDefaults boolForKey: @"SpeedLimit"] != shouldLimit)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
[self toggleSpeedLimit: nil];
|
|
|
|
|
|
|
|
[GrowlApplicationBridge notifyWithTitle: [fDefaults boolForKey: @"SpeedLimit"]
|
|
|
|
? NSLocalizedString(@"Speed Limit Auto Enabled", "Growl notification title")
|
|
|
|
: NSLocalizedString(@"Speed Limit Auto Disabled", "Growl notification title")
|
|
|
|
description: NSLocalizedString(@"Bandwidth settings changed", "Growl notification description")
|
|
|
|
notificationName: GROWL_AUTO_SPEED_LIMIT iconData: nil priority: 0 isSticky: NO clickContext: nil];
|
|
|
|
}
|
2008-06-19 02:53:45 +00:00
|
|
|
|
2008-06-19 03:47:11 +00:00
|
|
|
[self setAutoSpeedLimitTimer: !shouldLimit];
|
2008-06-19 02:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-06-19 03:47:11 +00:00
|
|
|
- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit
|
2008-06-19 02:53:45 +00:00
|
|
|
{
|
2008-06-19 15:54:59 +00:00
|
|
|
NSDate * timerDate = [fDefaults objectForKey: nextIsLimit ? @"SpeedLimitAutoOnDate" : @"SpeedLimitAutoOffDate"];
|
2008-06-19 02:53:45 +00:00
|
|
|
|
|
|
|
//create date with combination of the current date and the date to go off
|
2008-06-19 20:53:08 +00:00
|
|
|
NSCalendar * calendar = [NSCalendar currentCalendar];
|
2008-06-19 03:23:50 +00:00
|
|
|
NSDateComponents * nowComponents = [calendar components: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit
|
2008-06-19 15:54:59 +00:00
|
|
|
| NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: [NSDate date]],
|
|
|
|
* timerComponents = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: timerDate];
|
2008-06-19 03:23:50 +00:00
|
|
|
|
2008-06-19 15:54:59 +00:00
|
|
|
//check if should be the next day
|
2008-06-19 03:23:50 +00:00
|
|
|
int nowTime = [nowComponents hour] * 60 + [nowComponents minute],
|
|
|
|
timerTime = [timerComponents hour] * 60 + [timerComponents minute];
|
2008-06-19 15:54:59 +00:00
|
|
|
if (timerTime < nowTime)
|
|
|
|
[nowComponents setDay: [nowComponents day] + 1]; //properly goes to next month when appropriate
|
2008-06-19 03:23:50 +00:00
|
|
|
|
|
|
|
[nowComponents setHour: [timerComponents hour]];
|
|
|
|
[nowComponents setMinute: [timerComponents minute]];
|
|
|
|
[nowComponents setSecond: 0];
|
|
|
|
|
|
|
|
NSDate * dateToUse = [calendar dateFromComponents: nowComponents];
|
2008-06-19 02:53:45 +00:00
|
|
|
|
|
|
|
fSpeedLimitTimer = [[NSTimer alloc] initWithFireDate: dateToUse interval: 0 target: self selector: @selector(autoSpeedLimit:)
|
2008-06-19 03:47:11 +00:00
|
|
|
userInfo: [NSNumber numberWithBool: nextIsLimit] repeats: NO];
|
2008-06-19 02:53:45 +00:00
|
|
|
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fSpeedLimitTimer forMode: NSDefaultRunLoopMode];
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fSpeedLimitTimer forMode: NSModalPanelRunLoopMode];
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fSpeedLimitTimer forMode: NSEventTrackingRunLoopMode];
|
|
|
|
[fSpeedLimitTimer release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setLimitGlobalEnabled: (id) sender
|
|
|
|
{
|
2008-01-28 14:06:02 +00:00
|
|
|
BOOL upload = [sender menu] == fUploadMenu;
|
|
|
|
[fDefaults setBool: sender == (upload ? fUploadLimitItem : fDownloadLimitItem) forKey: upload ? @"CheckUpload" : @"CheckDownload"];
|
2007-12-20 20:53:55 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fPrefsController applySpeedSettings: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickLimitGlobal: (id) sender
|
|
|
|
{
|
2008-01-28 14:06:02 +00:00
|
|
|
BOOL upload = [sender menu] == fUploadMenu;
|
|
|
|
[fDefaults setInteger: [[sender representedObject] intValue] forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
|
|
|
|
[fDefaults setBool: YES forKey: upload ? @"CheckUpload" : @"CheckDownload"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fPrefsController updateLimitFields];
|
|
|
|
[fPrefsController applySpeedSettings: nil];
|
|
|
|
}
|
|
|
|
|
2007-12-20 20:53:55 +00:00
|
|
|
- (void) setRatioGlobalEnabled: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setBool: sender == fCheckRatioItem forKey: @"RatioCheck"];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) setQuickRatioGlobal: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setBool: YES forKey: @"RatioCheck"];
|
2008-01-10 06:27:48 +00:00
|
|
|
[fDefaults setFloat: [[sender representedObject] floatValue] forKey: @"RatioLimit"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fPrefsController updateRatioStopField];
|
|
|
|
}
|
|
|
|
|
2008-04-10 16:37:07 +00:00
|
|
|
- (void) sound: (NSSound *) sound didFinishPlaying: (BOOL) finishedPlaying
|
|
|
|
{
|
|
|
|
fSoundPlaying = NO;
|
|
|
|
}
|
|
|
|
|
2008-04-25 22:23:31 +00:00
|
|
|
- (void) watcher: (id<UKFileWatcher>) watcher receivedNotification: (NSString *) notification forPath: (NSString *) path
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if ([notification isEqualToString: UKFileWatcherWriteNotification])
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: @"AutoImport"] || ![fDefaults stringForKey: @"AutoImportDirectory"])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fAutoImportTimer)
|
|
|
|
{
|
|
|
|
if ([fAutoImportTimer isValid])
|
|
|
|
[fAutoImportTimer invalidate];
|
|
|
|
[fAutoImportTimer release];
|
|
|
|
fAutoImportTimer = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check again in 10 seconds in case torrent file wasn't complete
|
|
|
|
fAutoImportTimer = [[NSTimer scheduledTimerWithTimeInterval: 10.0 target: self
|
|
|
|
selector: @selector(checkAutoImportDirectory) userInfo: nil repeats: NO] retain];
|
|
|
|
|
|
|
|
[self checkAutoImportDirectory];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) changeAutoImport
|
|
|
|
{
|
|
|
|
if (fAutoImportTimer)
|
|
|
|
{
|
|
|
|
if ([fAutoImportTimer isValid])
|
|
|
|
[fAutoImportTimer invalidate];
|
|
|
|
[fAutoImportTimer release];
|
|
|
|
fAutoImportTimer = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fAutoImportedNames)
|
2008-01-21 19:47:01 +00:00
|
|
|
{
|
|
|
|
[fAutoImportedNames release];
|
|
|
|
fAutoImportedNames = nil;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self checkAutoImportDirectory];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) checkAutoImportDirectory
|
|
|
|
{
|
|
|
|
NSString * path;
|
|
|
|
if (![fDefaults boolForKey: @"AutoImport"] || !(path = [fDefaults stringForKey: @"AutoImportDirectory"]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
path = [path stringByExpandingTildeInPath];
|
|
|
|
|
|
|
|
NSArray * importedNames;
|
|
|
|
if (!(importedNames = [[NSFileManager defaultManager] directoryContentsAtPath: path]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//only check files that have not been checked yet
|
|
|
|
NSMutableArray * newNames = [importedNames mutableCopy];
|
|
|
|
|
|
|
|
if (fAutoImportedNames)
|
|
|
|
[newNames removeObjectsInArray: fAutoImportedNames];
|
|
|
|
else
|
|
|
|
fAutoImportedNames = [[NSMutableArray alloc] init];
|
|
|
|
[fAutoImportedNames setArray: importedNames];
|
|
|
|
|
|
|
|
NSString * file;
|
|
|
|
int i;
|
|
|
|
for (i = [newNames count] - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
file = [newNames objectAtIndex: i];
|
|
|
|
if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] != NSOrderedSame)
|
|
|
|
[newNames removeObjectAtIndex: i];
|
|
|
|
else
|
|
|
|
[newNames replaceObjectAtIndex: i withObject: [path stringByAppendingPathComponent: file]];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSEnumerator * enumerator = [newNames objectEnumerator];
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctor * ctor;
|
2007-09-16 01:02:06 +00:00
|
|
|
while ((file = [enumerator nextObject]))
|
|
|
|
{
|
2007-12-22 03:39:52 +00:00
|
|
|
ctor = tr_ctorNew(fLib);
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
|
|
|
|
|
2007-12-22 18:43:40 +00:00
|
|
|
switch (tr_torrentParse(fLib, ctor, NULL))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-22 03:39:52 +00:00
|
|
|
case TR_OK:
|
2008-05-26 21:39:30 +00:00
|
|
|
[self openFiles: [NSArray arrayWithObject: file] addType: ADD_AUTO forcePath: nil];
|
2007-12-22 03:39:52 +00:00
|
|
|
|
2008-01-21 16:52:36 +00:00
|
|
|
[GrowlApplicationBridge notifyWithTitle: NSLocalizedString(@"Torrent File Auto Added", "Growl notification title")
|
|
|
|
description: [file lastPathComponent] notificationName: GROWL_AUTO_ADD iconData: nil priority: 0 isSticky: NO
|
|
|
|
clickContext: nil];
|
2007-12-22 03:39:52 +00:00
|
|
|
break;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-22 03:39:52 +00:00
|
|
|
case TR_EINVALID:
|
|
|
|
[fAutoImportedNames removeObject: [file lastPathComponent]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-22 03:39:52 +00:00
|
|
|
|
|
|
|
tr_ctorFree(ctor);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[newNames release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) beginCreateFile: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: @"AutoImport"])
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSString * location = [notification object],
|
|
|
|
* path = [fDefaults stringForKey: @"AutoImportDirectory"];
|
|
|
|
|
|
|
|
if (location && path && [[[location stringByDeletingLastPathComponent] stringByExpandingTildeInPath]
|
|
|
|
isEqualToString: [path stringByExpandingTildeInPath]])
|
|
|
|
[fAutoImportedNames addObject: [location lastPathComponent]];
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
if (item)
|
|
|
|
return [[item objectForKey: @"Torrents"] count];
|
|
|
|
else
|
|
|
|
return [fDisplayedTorrents count];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item
|
2007-10-27 02:00:43 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
if (item)
|
|
|
|
return [[item objectForKey: @"Torrents"] objectAtIndex: index];
|
|
|
|
else
|
|
|
|
return [fDisplayedTorrents objectAtIndex: index];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item
|
|
|
|
{
|
|
|
|
return ![item isKindOfClass: [Torrent class]];
|
2007-10-27 02:00:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
|
|
|
|
{
|
2008-06-05 02:46:39 +00:00
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
|
|
|
return [item hashString];
|
|
|
|
else
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2008-02-18 19:42:46 +00:00
|
|
|
NSString * ident = [tableColumn identifier];
|
|
|
|
if ([ident isEqualToString: @"Group"])
|
|
|
|
{
|
|
|
|
int group = [[item objectForKey: @"Group"] intValue];
|
2008-03-23 00:56:43 +00:00
|
|
|
return group != -1 ? [[GroupsController groups] nameForIndex: group]
|
2008-02-18 19:42:46 +00:00
|
|
|
: NSLocalizedString(@"No Group", "Group table row");
|
|
|
|
}
|
2008-02-19 01:58:36 +00:00
|
|
|
else if ([ident isEqualToString: @"Color"])
|
2008-02-19 05:39:56 +00:00
|
|
|
{
|
|
|
|
int group = [[item objectForKey: @"Group"] intValue];
|
2008-06-05 02:46:39 +00:00
|
|
|
return [[GroupsController groups] imageForIndex: group];
|
2008-02-19 05:39:56 +00:00
|
|
|
}
|
2008-02-18 19:42:46 +00:00
|
|
|
else if ([ident isEqualToString: @"DL Image"])
|
2008-02-28 16:40:14 +00:00
|
|
|
return [NSImage imageNamed: @"DownArrowGroupTemplate.png"];
|
2008-02-28 02:17:17 +00:00
|
|
|
else if ([ident isEqualToString: @"UL Image"])
|
|
|
|
return [NSImage imageNamed: [fDefaults boolForKey: @"DisplayGroupRowRatio"]
|
2008-02-28 16:15:34 +00:00
|
|
|
? @"YingYangGroupTemplate.png" : @"UpArrowGroupTemplate.png"];
|
2008-02-18 19:42:46 +00:00
|
|
|
else
|
|
|
|
{
|
2008-02-28 02:17:17 +00:00
|
|
|
if ([fDefaults boolForKey: @"DisplayGroupRowRatio"])
|
|
|
|
{
|
|
|
|
uint64_t uploaded = 0, downloaded = 0;
|
|
|
|
NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
uploaded += [torrent uploadedTotal];
|
|
|
|
downloaded += [torrent downloadedTotal];
|
|
|
|
}
|
|
|
|
|
2008-03-04 03:27:25 +00:00
|
|
|
return [NSString stringForRatio: tr_getRatio(uploaded, downloaded)];
|
2008-02-28 02:17:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-28 16:40:14 +00:00
|
|
|
BOOL upload = [ident isEqualToString: @"UL"];
|
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
float rate = 0.0;
|
|
|
|
NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
rate += upload ? [torrent uploadRate] : [torrent downloadRate];
|
|
|
|
|
|
|
|
return [NSString stringForSpeed: rate];
|
|
|
|
}
|
2008-02-18 19:42:46 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:57:24 +00:00
|
|
|
- (BOOL) outlineView: (NSOutlineView *) outlineView writeItems: (NSArray *) items toPasteboard: (NSPasteboard *) pasteboard
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-11-09 23:38:35 +00:00
|
|
|
//only allow reordering of rows if sorting by order
|
2008-05-12 21:57:37 +00:00
|
|
|
if (([fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter])
|
|
|
|
|| [[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-07 11:57:24 +00:00
|
|
|
NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];
|
|
|
|
NSEnumerator * enumerator = [items objectEnumerator];
|
2008-05-11 21:38:40 +00:00
|
|
|
id torrent;
|
2008-02-07 11:57:24 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
|
|
|
if (![torrent isKindOfClass: [Torrent class]])
|
|
|
|
return NO;
|
|
|
|
|
2008-02-07 11:57:24 +00:00
|
|
|
[indexSet addIndex: [fTableView rowForItem: torrent]];
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
2008-02-07 11:57:24 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
[pasteboard declareTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE] owner: self];
|
2008-02-07 11:57:24 +00:00
|
|
|
[pasteboard setData: [NSKeyedArchiver archivedDataWithRootObject: indexSet] forType: TORRENT_TABLE_VIEW_DATA_TYPE];
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:57:24 +00:00
|
|
|
- (NSDragOperation) outlineView: (NSOutlineView *) outlineView validateDrop: (id < NSDraggingInfo >) info proposedItem: (id) item
|
|
|
|
proposedChildIndex: (NSInteger) index
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSPasteboard * pasteboard = [info draggingPasteboard];
|
|
|
|
if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
|
|
|
|
{
|
2008-05-11 21:38:40 +00:00
|
|
|
if ([fDefaults boolForKey: @"SortByGroup"])
|
|
|
|
{
|
|
|
|
if (!item)
|
|
|
|
return NSDragOperationNone;
|
2008-05-12 22:38:50 +00:00
|
|
|
|
|
|
|
if ([[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2008-05-12 22:38:50 +00:00
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
|
|
|
{
|
|
|
|
NSDictionary * group = [fTableView parentForItem: item];
|
2008-05-12 21:57:37 +00:00
|
|
|
index = [[group objectForKey: @"Torrents"] indexOfObject: item] + 1;
|
2008-05-12 22:38:50 +00:00
|
|
|
item = group;
|
|
|
|
}
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
2008-05-12 21:57:37 +00:00
|
|
|
else
|
|
|
|
{
|
2008-05-12 22:38:50 +00:00
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
|
|
|
item = [fTableView parentForItem: item];
|
|
|
|
index = NSOutlineViewDropOnItemIndex;
|
2008-05-12 21:57:37 +00:00
|
|
|
}
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
index = [fTableView rowForItem: item] + 1;
|
|
|
|
item = nil;
|
|
|
|
}
|
|
|
|
}
|
2008-02-07 11:57:24 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
[fTableView setDropItem: item dropChildIndex: index];
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:57:24 +00:00
|
|
|
- (BOOL) outlineView: (NSOutlineView *) outlineView acceptDrop: (id < NSDraggingInfo >) info item: (id) item
|
|
|
|
childIndex: (NSInteger) newRow
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSPasteboard * pasteboard = [info draggingPasteboard];
|
|
|
|
if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
|
|
|
|
{
|
2008-02-07 15:57:32 +00:00
|
|
|
//remember selected rows
|
2008-01-23 02:51:58 +00:00
|
|
|
NSArray * selectedValues = [fTableView selectedValues];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
//get the torrents to move
|
|
|
|
NSMutableArray * movingTorrents = [NSMutableArray arrayWithCapacity: [indexes count]];
|
|
|
|
int i;
|
|
|
|
for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
|
|
|
[movingTorrents addObject: [fTableView itemAtRow: i]];
|
2007-11-09 23:38:35 +00:00
|
|
|
|
2008-05-12 01:49:48 +00:00
|
|
|
//reset groups
|
2008-05-12 21:38:24 +00:00
|
|
|
if (item)
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2008-05-12 01:49:48 +00:00
|
|
|
//change groups
|
|
|
|
int groupValue = [[item objectForKey: @"Group"] intValue];
|
|
|
|
NSEnumerator * enumerator = [movingTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2008-05-12 21:38:24 +00:00
|
|
|
{
|
|
|
|
//have to reset objects here to avoid weird crash
|
|
|
|
[[[fTableView parentForItem: torrent] objectForKey: @"Torrent"] removeObject: torrent];
|
|
|
|
[[item objectForKey: @"Torrent"] addObject: torrent];
|
|
|
|
|
2008-05-12 01:49:48 +00:00
|
|
|
[torrent setGroupValue: groupValue];
|
2008-05-12 21:38:24 +00:00
|
|
|
}
|
2008-05-12 21:57:37 +00:00
|
|
|
//part 2 of avoiding weird crash
|
2008-05-12 21:38:24 +00:00
|
|
|
[fTableView reloadItem: nil reloadChildren: YES];
|
|
|
|
}
|
|
|
|
|
2008-05-12 21:57:37 +00:00
|
|
|
//reorder queue order
|
2008-05-14 18:09:51 +00:00
|
|
|
if (newRow != NSOutlineViewDropOnItemIndex)
|
2008-05-12 21:57:37 +00:00
|
|
|
{
|
|
|
|
//find torrent to place under
|
|
|
|
NSArray * groupTorrents = item ? [item objectForKey: @"Torrents"] : fDisplayedTorrents;
|
|
|
|
Torrent * topTorrent = nil;
|
|
|
|
for (i = newRow-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
Torrent * tempTorrent = [groupTorrents objectAtIndex: i];
|
|
|
|
if (![movingTorrents containsObject: tempTorrent])
|
|
|
|
{
|
|
|
|
topTorrent = tempTorrent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//remove objects to reinsert
|
|
|
|
[fTorrents removeObjectsInArray: movingTorrents];
|
|
|
|
|
|
|
|
//insert objects at new location
|
|
|
|
int insertIndex = topTorrent ? [fTorrents indexOfObject: topTorrent] + 1 : 0;
|
|
|
|
for (i = 0; i < [movingTorrents count]; i++)
|
|
|
|
[fTorrents insertObject: [movingTorrents objectAtIndex: i] atIndex: insertIndex + i];
|
|
|
|
|
|
|
|
//redo order values
|
|
|
|
for (i = 0; i < [fTorrents count]; i++)
|
|
|
|
[[fTorrents objectAtIndex: i] setOrderValue: i];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-30 21:55:39 +00:00
|
|
|
[self applyFilter: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-20 18:28:28 +00:00
|
|
|
//set selected rows
|
2008-01-23 02:51:58 +00:00
|
|
|
[fTableView selectValues: selectedValues];
|
2008-06-26 03:35:20 +00:00
|
|
|
[self resetInfo]; //if group is already selected, but the torrents in it change
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) torrentTableViewSelectionDidChange: (NSNotification *) notification
|
|
|
|
{
|
2008-06-26 03:35:20 +00:00
|
|
|
[self resetInfo];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) info
|
|
|
|
{
|
|
|
|
NSPasteboard * pasteboard = [info draggingPasteboard];
|
|
|
|
if ([[pasteboard types] containsObject: NSFilenamesPboardType])
|
|
|
|
{
|
|
|
|
//check if any torrent files can be added
|
|
|
|
NSArray * files = [pasteboard propertyListForType: NSFilenamesPboardType];
|
|
|
|
NSEnumerator * enumerator = [files objectEnumerator];
|
|
|
|
NSString * file;
|
|
|
|
BOOL torrent = NO;
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctor * ctor;
|
2007-09-16 01:02:06 +00:00
|
|
|
while ((file = [enumerator nextObject]))
|
|
|
|
{
|
2007-11-13 00:56:58 +00:00
|
|
|
if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-22 03:31:22 +00:00
|
|
|
ctor = tr_ctorNew(fLib);
|
|
|
|
tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
|
2007-12-22 18:43:40 +00:00
|
|
|
switch (tr_torrentParse(fLib, ctor, NULL))
|
2007-11-13 00:56:58 +00:00
|
|
|
{
|
|
|
|
case TR_OK:
|
|
|
|
if (!fOverlayWindow)
|
|
|
|
fOverlayWindow = [[DragOverlayWindow alloc] initWithLib: fLib forWindow: fWindow];
|
|
|
|
[fOverlayWindow setTorrents: files];
|
|
|
|
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
|
|
|
|
case TR_EDUPLICATE:
|
|
|
|
torrent = YES;
|
|
|
|
}
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctorFree(ctor);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//create a torrent file if a single file
|
|
|
|
if (!torrent && [files count] == 1)
|
|
|
|
{
|
|
|
|
if (!fOverlayWindow)
|
|
|
|
fOverlayWindow = [[DragOverlayWindow alloc] initWithLib: fLib forWindow: fWindow];
|
|
|
|
[fOverlayWindow setFile: [[files objectAtIndex: 0] lastPathComponent]];
|
|
|
|
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ([[pasteboard types] containsObject: NSURLPboardType])
|
|
|
|
{
|
|
|
|
if (!fOverlayWindow)
|
|
|
|
fOverlayWindow = [[DragOverlayWindow alloc] initWithLib: fLib forWindow: fWindow];
|
|
|
|
[fOverlayWindow setURL: [[NSURL URLFromPasteboard: pasteboard] relativeString]];
|
|
|
|
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) draggingExited: (id <NSDraggingInfo>) info
|
|
|
|
{
|
|
|
|
if (fOverlayWindow)
|
|
|
|
[fOverlayWindow fadeOut];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>) info
|
|
|
|
{
|
|
|
|
if (fOverlayWindow)
|
|
|
|
[fOverlayWindow fadeOut];
|
|
|
|
|
|
|
|
NSPasteboard * pasteboard = [info draggingPasteboard];
|
|
|
|
if ([[pasteboard types] containsObject: NSFilenamesPboardType])
|
|
|
|
{
|
|
|
|
BOOL torrent = NO, accept = YES;
|
|
|
|
|
|
|
|
//create an array of files that can be opened
|
|
|
|
NSMutableArray * filesToOpen = [[NSMutableArray alloc] init];
|
|
|
|
NSArray * files = [pasteboard propertyListForType: NSFilenamesPboardType];
|
|
|
|
NSEnumerator * enumerator = [files objectEnumerator];
|
|
|
|
NSString * file;
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctor * ctor;
|
2007-09-16 01:02:06 +00:00
|
|
|
while ((file = [enumerator nextObject]))
|
|
|
|
{
|
2007-11-13 00:56:58 +00:00
|
|
|
if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-22 03:31:22 +00:00
|
|
|
ctor = tr_ctorNew(fLib);
|
|
|
|
tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
|
2007-12-22 18:43:40 +00:00
|
|
|
switch (tr_torrentParse(fLib, ctor, NULL))
|
2007-11-13 00:56:58 +00:00
|
|
|
{
|
|
|
|
case TR_OK:
|
|
|
|
[filesToOpen addObject: file];
|
|
|
|
torrent = YES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_EDUPLICATE:
|
|
|
|
torrent = YES;
|
|
|
|
}
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctorFree(ctor);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([filesToOpen count] > 0)
|
|
|
|
[self application: NSApp openFiles: filesToOpen];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!torrent && [files count] == 1)
|
|
|
|
[CreatorWindowController createTorrentFile: fLib forFile: [files objectAtIndex: 0]];
|
|
|
|
else
|
|
|
|
accept = NO;
|
|
|
|
}
|
|
|
|
[filesToOpen release];
|
|
|
|
|
|
|
|
return accept;
|
|
|
|
}
|
|
|
|
else if ([[pasteboard types] containsObject: NSURLPboardType])
|
|
|
|
{
|
|
|
|
NSURL * url;
|
|
|
|
if ((url = [NSURL URLFromPasteboard: pasteboard]))
|
|
|
|
{
|
|
|
|
[self openURL: url];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) toggleSmallView: (id) sender
|
|
|
|
{
|
2007-10-29 18:59:23 +00:00
|
|
|
BOOL makeSmall = ![fDefaults boolForKey: @"SmallView"];
|
2007-10-30 19:55:47 +00:00
|
|
|
[fDefaults setBool: makeSmall forKey: @"SmallView"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fTableView setRowHeight: makeSmall ? ROW_HEIGHT_SMALL : ROW_HEIGHT_REGULAR];
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
[fTableView noteHeightOfRowsWithIndexesChanged: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTableView numberOfRows])]];
|
2008-01-24 14:43:50 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//window min height
|
|
|
|
NSSize contentMinSize = [fWindow contentMinSize],
|
|
|
|
contentSize = [[fWindow contentView] frame].size;
|
2008-02-06 23:45:44 +00:00
|
|
|
contentMinSize.height = contentSize.height - [[fTableView enclosingScrollView] frame].size.height
|
2007-09-16 01:02:06 +00:00
|
|
|
+ [fTableView rowHeight] + [fTableView intercellSpacing].height;
|
|
|
|
[fWindow setContentMinSize: contentMinSize];
|
|
|
|
|
|
|
|
//resize for larger min height if not set to auto size
|
|
|
|
if (![fDefaults boolForKey: @"AutoSize"])
|
|
|
|
{
|
|
|
|
if (!makeSmall && contentSize.height < contentMinSize.height)
|
|
|
|
{
|
|
|
|
NSRect frame = [fWindow frame];
|
|
|
|
float heightChange = contentMinSize.height - contentSize.height;
|
|
|
|
frame.size.height += heightChange;
|
|
|
|
frame.origin.y -= heightChange;
|
|
|
|
|
|
|
|
[fWindow setFrame: frame display: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self setWindowSizeToFit];
|
|
|
|
}
|
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
- (void) togglePiecesBar: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"PiecesBar"] forKey: @"PiecesBar"];
|
2008-01-16 19:30:12 +00:00
|
|
|
[fTableView togglePiecesBar];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
2007-11-11 16:59:32 +00:00
|
|
|
- (void) toggleAvailabilityBar: (id) sender
|
|
|
|
{
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"DisplayProgressBarAvailable"] forKey: @"DisplayProgressBarAvailable"];
|
|
|
|
[fTableView display];
|
|
|
|
}
|
|
|
|
|
2008-05-10 19:24:28 +00:00
|
|
|
- (void) toggleStatusString: (id) sender
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"DisplaySmallStatusRegular"] forKey: @"DisplaySmallStatusRegular"];
|
|
|
|
else
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"DisplayStatusProgressSelected"] forKey: @"DisplayStatusProgressSelected"];
|
|
|
|
|
|
|
|
[fTableView reloadData];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSRect) windowFrameByAddingHeight: (float) height checkLimits: (BOOL) check
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
NSScrollView * scrollView = [fTableView enclosingScrollView];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//convert pixels to points
|
|
|
|
NSRect windowFrame = [fWindow frame];
|
2008-02-06 23:45:44 +00:00
|
|
|
NSSize windowSize = [scrollView convertSize: windowFrame.size fromView: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
windowSize.height += height;
|
|
|
|
|
|
|
|
if (check)
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
NSSize minSize = [scrollView convertSize: [fWindow minSize] fromView: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (windowSize.height < minSize.height)
|
|
|
|
windowSize.height = minSize.height;
|
|
|
|
else
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
NSSize maxSize = [scrollView convertSize: [[fWindow screen] visibleFrame].size fromView: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([fStatusBar isHidden])
|
|
|
|
maxSize.height -= [fStatusBar frame].size.height;
|
|
|
|
if ([fFilterBar isHidden])
|
|
|
|
maxSize.height -= [fFilterBar frame].size.height;
|
|
|
|
if (windowSize.height > maxSize.height)
|
|
|
|
windowSize.height = maxSize.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//convert points to pixels
|
2008-02-06 23:45:44 +00:00
|
|
|
windowSize = [scrollView convertSize: windowSize toView: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
windowFrame.origin.y -= (windowSize.height - windowFrame.size.height);
|
|
|
|
windowFrame.size.height = windowSize.height;
|
|
|
|
return windowFrame;
|
|
|
|
}
|
|
|
|
|
2008-03-16 14:24:27 +00:00
|
|
|
- (void) toggleStatusBar: (id) sender
|
|
|
|
{
|
|
|
|
[self showStatusBar: [fStatusBar isHidden] animate: YES];
|
|
|
|
[fDefaults setBool: ![fStatusBar isHidden] forKey: @"StatusBar"];
|
|
|
|
}
|
|
|
|
|
|
|
|
//doesn't save shown state
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) showStatusBar: (BOOL) show animate: (BOOL) animate
|
|
|
|
{
|
|
|
|
if (show != [fStatusBar isHidden])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
[fStatusBar setHidden: NO];
|
|
|
|
|
|
|
|
NSRect frame;
|
|
|
|
float heightChange = [fStatusBar frame].size.height;
|
|
|
|
if (!show)
|
|
|
|
heightChange *= -1;
|
|
|
|
|
|
|
|
//allow bar to show even if not enough room
|
|
|
|
if (show && ![fDefaults boolForKey: @"AutoSize"])
|
|
|
|
{
|
|
|
|
frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
|
|
|
|
float change = [[fWindow screen] visibleFrame].size.height - frame.size.height;
|
|
|
|
if (change < 0.0)
|
|
|
|
{
|
|
|
|
frame = [fWindow frame];
|
|
|
|
frame.size.height += change;
|
|
|
|
frame.origin.y -= change;
|
|
|
|
[fWindow setFrame: frame display: NO animate: NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self updateUI];
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
NSScrollView * scrollView = [fTableView enclosingScrollView];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set views to not autoresize
|
|
|
|
unsigned int statsMask = [fStatusBar autoresizingMask];
|
|
|
|
unsigned int filterMask = [fFilterBar autoresizingMask];
|
2008-02-06 23:45:44 +00:00
|
|
|
unsigned int scrollMask = [scrollView autoresizingMask];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fStatusBar setAutoresizingMask: NSViewNotSizable];
|
|
|
|
[fFilterBar setAutoresizingMask: NSViewNotSizable];
|
2008-02-06 23:45:44 +00:00
|
|
|
[scrollView setAutoresizingMask: NSViewNotSizable];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
|
|
|
|
[fWindow setFrame: frame display: YES animate: animate];
|
|
|
|
|
|
|
|
//re-enable autoresize
|
|
|
|
[fStatusBar setAutoresizingMask: statsMask];
|
|
|
|
[fFilterBar setAutoresizingMask: filterMask];
|
2008-02-06 23:45:44 +00:00
|
|
|
[scrollView setAutoresizingMask: scrollMask];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//change min size
|
|
|
|
NSSize minSize = [fWindow contentMinSize];
|
|
|
|
minSize.height += heightChange;
|
|
|
|
[fWindow setContentMinSize: minSize];
|
|
|
|
|
|
|
|
if (!show)
|
|
|
|
[fStatusBar setHidden: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) toggleFilterBar: (id) sender
|
|
|
|
{
|
|
|
|
//disable filtering when hiding
|
|
|
|
if (![fFilterBar isHidden])
|
|
|
|
{
|
|
|
|
[fSearchFilterField setStringValue: @""];
|
|
|
|
[self setFilter: fNoFilterButton];
|
2007-12-19 20:46:00 +00:00
|
|
|
[self setGroupFilter: [fGroupFilterMenu itemWithTag: GROUP_FILTER_ALL_TAG]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self showFilterBar: [fFilterBar isHidden] animate: YES];
|
|
|
|
[fDefaults setBool: ![fFilterBar isHidden] forKey: @"FilterBar"];
|
|
|
|
}
|
|
|
|
|
2008-03-16 14:24:27 +00:00
|
|
|
//doesn't save shown state
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) showFilterBar: (BOOL) show animate: (BOOL) animate
|
|
|
|
{
|
|
|
|
if (show != [fFilterBar isHidden])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
[fFilterBar setHidden: NO];
|
|
|
|
|
|
|
|
NSRect frame;
|
|
|
|
float heightChange = [fFilterBar frame].size.height;
|
|
|
|
if (!show)
|
|
|
|
heightChange *= -1;
|
|
|
|
|
|
|
|
//allow bar to show even if not enough room
|
|
|
|
if (show && ![fDefaults boolForKey: @"AutoSize"])
|
|
|
|
{
|
|
|
|
frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
|
|
|
|
float change = [[fWindow screen] visibleFrame].size.height - frame.size.height;
|
|
|
|
if (change < 0.0)
|
|
|
|
{
|
|
|
|
frame = [fWindow frame];
|
|
|
|
frame.size.height += change;
|
|
|
|
frame.origin.y -= change;
|
|
|
|
[fWindow setFrame: frame display: NO animate: NO];
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
|
|
|
|
NSScrollView * scrollView = [fTableView enclosingScrollView];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//set views to not autoresize
|
|
|
|
unsigned int filterMask = [fFilterBar autoresizingMask];
|
2008-02-06 23:45:44 +00:00
|
|
|
unsigned int scrollMask = [scrollView autoresizingMask];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fFilterBar setAutoresizingMask: NSViewNotSizable];
|
2008-02-06 23:45:44 +00:00
|
|
|
[scrollView setAutoresizingMask: NSViewNotSizable];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
|
|
|
|
[fWindow setFrame: frame display: YES animate: animate];
|
|
|
|
|
|
|
|
//re-enable autoresize
|
|
|
|
[fFilterBar setAutoresizingMask: filterMask];
|
2008-02-06 23:45:44 +00:00
|
|
|
[scrollView setAutoresizingMask: scrollMask];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//change min size
|
|
|
|
NSSize minSize = [fWindow contentMinSize];
|
|
|
|
minSize.height += heightChange;
|
|
|
|
[fWindow setContentMinSize: minSize];
|
|
|
|
|
|
|
|
if (!show)
|
|
|
|
{
|
|
|
|
[fFilterBar setHidden: YES];
|
|
|
|
[fWindow makeFirstResponder: fTableView];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-16 14:24:27 +00:00
|
|
|
- (void) focusFilterField
|
|
|
|
{
|
|
|
|
[fWindow makeFirstResponder: fSearchFilterField];
|
|
|
|
if ([fFilterBar isHidden])
|
|
|
|
[self toggleFilterBar: self];
|
|
|
|
}
|
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
- (ButtonToolbarItem *) standardToolbarButtonWithIdentifier: (NSString *) ident
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-06 20:54:26 +00:00
|
|
|
ButtonToolbarItem * item = [[ButtonToolbarItem alloc] initWithItemIdentifier: ident];
|
2007-11-29 01:05:11 +00:00
|
|
|
|
|
|
|
NSButton * button = [[NSButton alloc] initWithFrame: NSZeroRect];
|
|
|
|
[button setBezelStyle: NSTexturedRoundedBezelStyle];
|
|
|
|
[button setStringValue: @""];
|
|
|
|
|
2007-12-04 01:46:27 +00:00
|
|
|
[item setView: button];
|
|
|
|
[button release];
|
|
|
|
|
2007-11-30 18:18:35 +00:00
|
|
|
NSSize buttonSize = NSMakeSize(36.0, 25.0);
|
2007-11-29 01:05:11 +00:00
|
|
|
[item setMinSize: buttonSize];
|
|
|
|
[item setMaxSize: buttonSize];
|
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
return [item autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
|
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([ident isEqualToString: TOOLBAR_CREATE])
|
|
|
|
{
|
2007-12-06 20:54:26 +00:00
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Create", "Create toolbar item -> label")];
|
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Create Torrent File", "Create toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Create torrent file", "Create toolbar item -> tooltip")];
|
2007-12-04 01:46:27 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Create.png"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector(createFile:)];
|
|
|
|
[item setAutovalidates: NO];
|
2007-12-06 20:54:26 +00:00
|
|
|
|
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-02-07 20:34:14 +00:00
|
|
|
else if ([ident isEqualToString: TOOLBAR_OPEN_FILE])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-06 20:54:26 +00:00
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Open", "Open toolbar item -> label")];
|
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Open Torrent Files", "Open toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Open torrent files", "Open toolbar item -> tooltip")];
|
2007-12-04 01:46:27 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Open.png"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector(openShowSheet:)];
|
|
|
|
[item setAutovalidates: NO];
|
2007-12-06 20:54:26 +00:00
|
|
|
|
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-02-07 20:34:14 +00:00
|
|
|
else if ([ident isEqualToString: TOOLBAR_OPEN_WEB])
|
|
|
|
{
|
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
|
|
|
[item setLabel: NSLocalizedString(@"Open Address", "Open address toolbar item -> label")];
|
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Open Torrent Address", "Open address toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Open torrent web address", "Open address toolbar item -> tooltip")];
|
2008-02-07 20:54:14 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"OpenWeb.png"]];
|
2008-02-07 20:34:14 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector(openURLShowSheet:)];
|
|
|
|
[item setAutovalidates: NO];
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else if ([ident isEqualToString: TOOLBAR_REMOVE])
|
|
|
|
{
|
2007-12-06 20:54:26 +00:00
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Remove", "Remove toolbar item -> label")];
|
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Remove Selected", "Remove toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Remove selected transfers", "Remove toolbar item -> tooltip")];
|
2007-12-04 01:46:27 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Remove.png"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector(removeNoDelete:)];
|
2007-12-06 20:54:26 +00:00
|
|
|
|
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: TOOLBAR_INFO])
|
|
|
|
{
|
2007-12-06 20:54:26 +00:00
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Inspector", "Inspector toolbar item -> label")];
|
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Toggle Inspector", "Inspector toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Toggle the torrent inspector", "Inspector toolbar item -> tooltip")];
|
2007-12-04 01:46:27 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Info.png"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector(showInfo:)];
|
2007-12-06 20:54:26 +00:00
|
|
|
|
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
else if ([ident isEqualToString: TOOLBAR_PAUSE_RESUME_ALL])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-07 06:27:42 +00:00
|
|
|
GroupToolbarItem * groupItem = [[GroupToolbarItem alloc] initWithItemIdentifier: ident];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2008-04-22 13:25:53 +00:00
|
|
|
NSSegmentedControl * segmentedControl = [[NSSegmentedControl alloc] initWithFrame: NSZeroRect];
|
|
|
|
[segmentedControl setCell: [[[ToolbarSegmentedCell alloc] init] autorelease]];
|
2007-12-06 17:21:42 +00:00
|
|
|
[groupItem setView: segmentedControl];
|
2007-12-07 03:49:46 +00:00
|
|
|
NSSegmentedCell * segmentedCell = (NSSegmentedCell *)[segmentedControl cell];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
|
|
|
[segmentedControl setSegmentCount: 2];
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setTrackingMode: NSSegmentSwitchTrackingMomentary];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2008-01-07 00:07:03 +00:00
|
|
|
NSSize groupSize = NSMakeSize(72.0, 25.0);
|
|
|
|
[groupItem setMinSize: groupSize];
|
|
|
|
[groupItem setMaxSize: groupSize];
|
|
|
|
|
2007-12-06 17:21:42 +00:00
|
|
|
[groupItem setLabel: NSLocalizedString(@"Apply All", "All toolbar item -> label")];
|
|
|
|
[groupItem setPaletteLabel: NSLocalizedString(@"Pause / Resume All", "All toolbar item -> palette label")];
|
|
|
|
[groupItem setTarget: self];
|
|
|
|
[groupItem setAction: @selector(allToolbarClicked:)];
|
|
|
|
|
|
|
|
[groupItem setIdentifiers: [NSArray arrayWithObjects: TOOLBAR_PAUSE_ALL, TOOLBAR_RESUME_ALL, nil]];
|
|
|
|
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setTag: TOOLBAR_PAUSE_TAG forSegment: TOOLBAR_PAUSE_TAG];
|
2007-12-06 20:25:38 +00:00
|
|
|
[segmentedControl setImage: [NSImage imageNamed: @"PauseAll.png"] forSegment: TOOLBAR_PAUSE_TAG];
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setToolTip: NSLocalizedString(@"Pause all transfers",
|
|
|
|
"All toolbar item -> tooltip") forSegment: TOOLBAR_PAUSE_TAG];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setTag: TOOLBAR_RESUME_TAG forSegment: TOOLBAR_RESUME_TAG];
|
2007-12-06 20:25:38 +00:00
|
|
|
[segmentedControl setImage: [NSImage imageNamed: @"ResumeAll.png"] forSegment: TOOLBAR_RESUME_TAG];
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setToolTip: NSLocalizedString(@"Resume all transfers",
|
|
|
|
"All toolbar item -> tooltip") forSegment: TOOLBAR_RESUME_TAG];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-12-06 20:46:58 +00:00
|
|
|
[groupItem createMenu: [NSArray arrayWithObjects: NSLocalizedString(@"Pause All", "All toolbar item -> label"),
|
|
|
|
NSLocalizedString(@"Resume All", "All toolbar item -> label"), nil]];
|
|
|
|
|
2007-12-06 17:21:42 +00:00
|
|
|
[segmentedControl release];
|
2007-12-06 20:54:26 +00:00
|
|
|
return [groupItem autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
else if ([ident isEqualToString: TOOLBAR_PAUSE_RESUME_SELECTED])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-07 06:27:42 +00:00
|
|
|
GroupToolbarItem * groupItem = [[GroupToolbarItem alloc] initWithItemIdentifier: ident];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2008-04-22 13:25:53 +00:00
|
|
|
NSSegmentedControl * segmentedControl = [[NSSegmentedControl alloc] initWithFrame: NSZeroRect];
|
|
|
|
[segmentedControl setCell: [[[ToolbarSegmentedCell alloc] init] autorelease]];
|
2007-12-06 17:21:42 +00:00
|
|
|
[groupItem setView: segmentedControl];
|
2007-12-07 03:49:46 +00:00
|
|
|
NSSegmentedCell * segmentedCell = (NSSegmentedCell *)[segmentedControl cell];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
|
|
|
[segmentedControl setSegmentCount: 2];
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setTrackingMode: NSSegmentSwitchTrackingMomentary];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
|
|
|
NSSize groupSize = NSMakeSize(72.0, 25.0);
|
|
|
|
[groupItem setMinSize: groupSize];
|
|
|
|
[groupItem setMaxSize: groupSize];
|
|
|
|
|
|
|
|
[groupItem setLabel: NSLocalizedString(@"Apply Selected", "Selected toolbar item -> label")];
|
|
|
|
[groupItem setPaletteLabel: NSLocalizedString(@"Pause / Resume Selected", "Selected toolbar item -> palette label")];
|
|
|
|
[groupItem setTarget: self];
|
|
|
|
[groupItem setAction: @selector(selectedToolbarClicked:)];
|
|
|
|
|
|
|
|
[groupItem setIdentifiers: [NSArray arrayWithObjects: TOOLBAR_PAUSE_SELECTED, TOOLBAR_RESUME_SELECTED, nil]];
|
|
|
|
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setTag: TOOLBAR_PAUSE_TAG forSegment: TOOLBAR_PAUSE_TAG];
|
2007-12-06 20:25:38 +00:00
|
|
|
[segmentedControl setImage: [NSImage imageNamed: @"PauseSelected.png"] forSegment: TOOLBAR_PAUSE_TAG];
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setToolTip: NSLocalizedString(@"Pause selected transfers",
|
|
|
|
"Selected toolbar item -> tooltip") forSegment: TOOLBAR_PAUSE_TAG];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setTag: TOOLBAR_RESUME_TAG forSegment: TOOLBAR_RESUME_TAG];
|
2007-12-06 20:25:38 +00:00
|
|
|
[segmentedControl setImage: [NSImage imageNamed: @"ResumeSelected.png"] forSegment: TOOLBAR_RESUME_TAG];
|
2007-12-07 03:49:46 +00:00
|
|
|
[segmentedCell setToolTip: NSLocalizedString(@"Resume selected transfers",
|
|
|
|
"Selected toolbar item -> tooltip") forSegment: TOOLBAR_RESUME_TAG];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-12-06 20:46:58 +00:00
|
|
|
[groupItem createMenu: [NSArray arrayWithObjects: NSLocalizedString(@"Pause Selected", "Selected toolbar item -> label"),
|
|
|
|
NSLocalizedString(@"Resume Selected", "Selected toolbar item -> label"), nil]];
|
|
|
|
|
2007-12-06 17:21:42 +00:00
|
|
|
[segmentedControl release];
|
2007-12-06 20:54:26 +00:00
|
|
|
return [groupItem autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: TOOLBAR_FILTER])
|
|
|
|
{
|
2007-12-06 20:54:26 +00:00
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Filter", "Filter toolbar item -> label")];
|
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Toggle Filter", "Filter toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Toggle the filter bar", "Filter toolbar item -> tooltip")];
|
2007-12-04 01:46:27 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Filter.png"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector(toggleFilterBar:)];
|
2007-12-06 20:54:26 +00:00
|
|
|
|
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-05-21 16:02:38 +00:00
|
|
|
else if ([ident isEqualToString: TOOLBAR_QUICKLOOK])
|
|
|
|
{
|
|
|
|
ButtonToolbarItem * item = [self standardToolbarButtonWithIdentifier: ident];
|
|
|
|
|
2008-05-29 00:56:58 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Quick Look", "QuickLook toolbar item -> label")];
|
2008-05-21 16:02:38 +00:00
|
|
|
[item setPaletteLabel: NSLocalizedString(@"Quick Look", "QuickLook toolbar item -> palette label")];
|
|
|
|
[item setToolTip: NSLocalizedString(@"Quick Look", "QuickLook toolbar item -> tooltip")];
|
|
|
|
[item setImage: [NSImage imageNamed: NSImageNameQuickLookTemplate]];
|
|
|
|
[item setTarget: self];
|
2008-05-21 16:28:21 +00:00
|
|
|
[item setAction: @selector(toggleQuickLook:)];
|
2008-05-21 16:02:38 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
return nil;
|
2007-12-06 17:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) allToolbarClicked: (id) sender
|
|
|
|
{
|
2007-12-07 03:41:46 +00:00
|
|
|
int tagValue = [sender isKindOfClass: [NSSegmentedControl class]]
|
|
|
|
? [(NSSegmentedCell *)[sender cell] tagForSegment: [sender selectedSegment]] : [sender tag];
|
|
|
|
switch (tagValue)
|
2007-12-06 20:25:38 +00:00
|
|
|
{
|
|
|
|
case TOOLBAR_PAUSE_TAG:
|
|
|
|
[self stopAllTorrents: sender];
|
|
|
|
break;
|
|
|
|
case TOOLBAR_RESUME_TAG:
|
|
|
|
[self resumeAllTorrents: sender];
|
|
|
|
break;
|
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) selectedToolbarClicked: (id) sender
|
|
|
|
{
|
2007-12-07 03:41:46 +00:00
|
|
|
int tagValue = [sender isKindOfClass: [NSSegmentedControl class]]
|
|
|
|
? [(NSSegmentedCell *)[sender cell] tagForSegment: [sender selectedSegment]] : [sender tag];
|
|
|
|
switch (tagValue)
|
2007-12-06 20:25:38 +00:00
|
|
|
{
|
|
|
|
case TOOLBAR_PAUSE_TAG:
|
|
|
|
[self stopSelectedTorrents: sender];
|
|
|
|
break;
|
|
|
|
case TOOLBAR_RESUME_TAG:
|
|
|
|
[self resumeSelectedTorrents: sender];
|
|
|
|
break;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 01:05:11 +00:00
|
|
|
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-21 16:02:38 +00:00
|
|
|
NSMutableArray * idents = [NSMutableArray arrayWithObjects:
|
|
|
|
TOOLBAR_CREATE, TOOLBAR_OPEN_FILE, TOOLBAR_OPEN_WEB,
|
|
|
|
TOOLBAR_REMOVE, TOOLBAR_PAUSE_RESUME_SELECTED, TOOLBAR_PAUSE_RESUME_ALL,
|
|
|
|
TOOLBAR_FILTER, TOOLBAR_INFO,
|
|
|
|
NSToolbarSeparatorItemIdentifier,
|
|
|
|
NSToolbarSpaceItemIdentifier,
|
|
|
|
NSToolbarFlexibleSpaceItemIdentifier,
|
|
|
|
NSToolbarCustomizeToolbarItemIdentifier, nil];
|
|
|
|
|
|
|
|
//allow quicklook on leopard
|
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
[idents insertObject: TOOLBAR_QUICKLOOK atIndex: 6];
|
|
|
|
|
|
|
|
return idents;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 01:05:11 +00:00
|
|
|
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-21 16:08:41 +00:00
|
|
|
return [NSArray arrayWithObjects:
|
|
|
|
TOOLBAR_CREATE, TOOLBAR_OPEN_FILE, TOOLBAR_REMOVE,
|
|
|
|
NSToolbarSeparatorItemIdentifier,
|
|
|
|
TOOLBAR_PAUSE_RESUME_ALL,
|
|
|
|
NSToolbarFlexibleSpaceItemIdentifier,
|
|
|
|
TOOLBAR_FILTER, TOOLBAR_INFO, nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
|
|
|
|
{
|
|
|
|
NSString * ident = [toolbarItem itemIdentifier];
|
2007-12-06 17:21:42 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable remove item
|
|
|
|
if ([ident isEqualToString: TOOLBAR_REMOVE])
|
|
|
|
return [fTableView numberOfSelectedRows] > 0;
|
|
|
|
|
|
|
|
//enable pause all item
|
|
|
|
if ([ident isEqualToString: TOOLBAR_PAUSE_ALL])
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive] || [torrent waitingToStart])
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume all item
|
|
|
|
if ([ident isEqualToString: TOOLBAR_RESUME_ALL])
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-20 21:27:46 +00:00
|
|
|
if (![torrent isActive] && ![torrent waitingToStart])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable pause item
|
|
|
|
if ([ident isEqualToString: TOOLBAR_PAUSE_SELECTED])
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive] || [torrent waitingToStart])
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume item
|
|
|
|
if ([ident isEqualToString: TOOLBAR_RESUME_SELECTED])
|
|
|
|
{
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-20 21:27:46 +00:00
|
|
|
if (![torrent isActive] && ![torrent waitingToStart])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
2007-12-09 03:25:33 +00:00
|
|
|
|
|
|
|
//set info image
|
|
|
|
if ([ident isEqualToString: TOOLBAR_INFO])
|
|
|
|
{
|
2007-12-22 19:57:12 +00:00
|
|
|
[toolbarItem setImage: [[fInfoController window] isVisible] ? [NSImage imageNamed: @"InfoBlue.png"]
|
|
|
|
: [NSImage imageNamed: @"Info.png"]];
|
2007-12-09 03:25:33 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set filter image
|
|
|
|
if ([ident isEqualToString: TOOLBAR_FILTER])
|
|
|
|
{
|
2007-12-22 19:57:12 +00:00
|
|
|
[toolbarItem setImage: ![fFilterBar isHidden] ? [NSImage imageNamed: @"FilterBlue.png"] : [NSImage imageNamed: @"Filter.png"]];
|
2007-12-09 03:25:33 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2008-05-21 18:59:18 +00:00
|
|
|
|
|
|
|
//enable quicklook item
|
|
|
|
if ([ident isEqualToString: TOOLBAR_QUICKLOOK])
|
|
|
|
return [[QuickLookController quickLook] canQuickLook];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
|
|
|
|
{
|
|
|
|
SEL action = [menuItem action];
|
2007-10-30 19:55:47 +00:00
|
|
|
|
2007-10-30 20:19:22 +00:00
|
|
|
if (action == @selector(toggleSpeedLimit:))
|
|
|
|
{
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"SpeedLimit"] ? NSOnState : NSOffState];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//only enable some items if it is in a context menu or the window is useable
|
|
|
|
BOOL canUseTable = [fWindow isKeyWindow] || [[menuItem menu] supermenu] != [NSApp mainMenu];
|
|
|
|
|
|
|
|
//enable open items
|
|
|
|
if (action == @selector(openShowSheet:) || action == @selector(openURLShowSheet:))
|
|
|
|
return [fWindow attachedSheet] == nil;
|
|
|
|
|
2007-11-04 16:45:17 +00:00
|
|
|
//enable sort options
|
2007-11-04 15:01:34 +00:00
|
|
|
if (action == @selector(setSort:))
|
2007-11-07 05:02:43 +00:00
|
|
|
{
|
|
|
|
NSString * sortType;
|
|
|
|
switch ([menuItem tag])
|
|
|
|
{
|
|
|
|
case SORT_ORDER_TAG:
|
|
|
|
sortType = SORT_ORDER;
|
|
|
|
break;
|
|
|
|
case SORT_DATE_TAG:
|
|
|
|
sortType = SORT_DATE;
|
|
|
|
break;
|
|
|
|
case SORT_NAME_TAG:
|
|
|
|
sortType = SORT_NAME;
|
|
|
|
break;
|
|
|
|
case SORT_PROGRESS_TAG:
|
|
|
|
sortType = SORT_PROGRESS;
|
|
|
|
break;
|
|
|
|
case SORT_STATE_TAG:
|
|
|
|
sortType = SORT_STATE;
|
|
|
|
break;
|
|
|
|
case SORT_TRACKER_TAG:
|
|
|
|
sortType = SORT_TRACKER;
|
|
|
|
break;
|
2007-11-21 18:32:41 +00:00
|
|
|
case SORT_ACTIVITY_TAG:
|
|
|
|
sortType = SORT_ACTIVITY;
|
2007-11-07 05:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[menuItem setState: [sortType isEqualToString: [fDefaults stringForKey: @"Sort"]] ? NSOnState : NSOffState];
|
2007-10-30 19:55:47 +00:00
|
|
|
return [fWindow isVisible];
|
2007-11-07 05:02:43 +00:00
|
|
|
}
|
2007-10-30 19:55:47 +00:00
|
|
|
|
2007-12-05 01:26:30 +00:00
|
|
|
//enable sort options
|
|
|
|
if (action == @selector(setStatusLabel:))
|
|
|
|
{
|
|
|
|
NSString * statusLabel;
|
|
|
|
switch ([menuItem tag])
|
|
|
|
{
|
|
|
|
case STATUS_RATIO_TOTAL_TAG:
|
|
|
|
statusLabel = STATUS_RATIO_TOTAL;
|
|
|
|
break;
|
|
|
|
case STATUS_RATIO_SESSION_TAG:
|
|
|
|
statusLabel = STATUS_RATIO_SESSION;
|
|
|
|
break;
|
|
|
|
case STATUS_TRANSFER_TOTAL_TAG:
|
|
|
|
statusLabel = STATUS_TRANSFER_TOTAL;
|
|
|
|
break;
|
|
|
|
case STATUS_TRANSFER_SESSION_TAG:
|
|
|
|
statusLabel = STATUS_TRANSFER_SESSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
[menuItem setState: [statusLabel isEqualToString: [fDefaults stringForKey: @"StatusLabel"]] ? NSOnState : NSOffState];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-12-17 16:32:32 +00:00
|
|
|
if (action == @selector(setGroup:))
|
|
|
|
{
|
|
|
|
BOOL checked = NO;
|
|
|
|
|
2007-12-19 15:35:23 +00:00
|
|
|
int index = [menuItem tag];
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-12-17 16:32:32 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if (index == [torrent groupValue])
|
|
|
|
{
|
|
|
|
checked = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[menuItem setState: checked ? NSOnState : NSOffState];
|
|
|
|
return canUseTable && [fTableView numberOfSelectedRows] > 0;
|
|
|
|
}
|
2007-12-19 20:46:00 +00:00
|
|
|
|
|
|
|
if (action == @selector(setGroupFilter:))
|
|
|
|
{
|
|
|
|
[menuItem setState: [menuItem tag] == [fDefaults integerForKey: @"FilterGroup"] ? NSOnState : NSOffState];
|
|
|
|
return YES;
|
|
|
|
}
|
2007-12-17 16:32:32 +00:00
|
|
|
|
2007-10-30 19:55:47 +00:00
|
|
|
if (action == @selector(toggleSmallView:))
|
|
|
|
{
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"SmallView"] ? NSOnState : NSOffState];
|
2007-09-16 01:02:06 +00:00
|
|
|
return [fWindow isVisible];
|
2007-10-30 19:55:47 +00:00
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
|
|
|
|
if (action == @selector(togglePiecesBar:))
|
|
|
|
{
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"PiecesBar"] ? NSOnState : NSOffState];
|
|
|
|
return [fWindow isVisible];
|
|
|
|
}
|
2007-11-11 16:59:32 +00:00
|
|
|
|
2008-05-10 19:24:28 +00:00
|
|
|
if (action == @selector(toggleStatusString:))
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
{
|
|
|
|
[menuItem setTitle: NSLocalizedString(@"Remaining Time", "Action menu -> status string toggle")];
|
|
|
|
[menuItem setState: ![fDefaults boolForKey: @"DisplaySmallStatusRegular"] ? NSOnState : NSOffState];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[menuItem setTitle: NSLocalizedString(@"Status of Selected Files", "Action menu -> status string toggle")];
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"DisplayStatusProgressSelected"] ? NSOnState : NSOffState];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [fWindow isVisible];
|
|
|
|
}
|
|
|
|
|
2007-11-11 16:59:32 +00:00
|
|
|
if (action == @selector(toggleAvailabilityBar:))
|
|
|
|
{
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"DisplayProgressBarAvailable"] ? NSOnState : NSOffState];
|
|
|
|
return [fWindow isVisible];
|
|
|
|
}
|
2007-12-20 19:57:42 +00:00
|
|
|
|
|
|
|
if (action == @selector(setLimitGlobalEnabled:))
|
2007-12-20 20:11:01 +00:00
|
|
|
{
|
2007-12-20 19:57:42 +00:00
|
|
|
BOOL upload = [menuItem menu] == fUploadMenu;
|
2007-12-20 20:11:01 +00:00
|
|
|
BOOL limit = menuItem == (upload ? fUploadLimitItem : fDownloadLimitItem);
|
|
|
|
if (limit)
|
|
|
|
[menuItem setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
|
2008-01-10 06:27:48 +00:00
|
|
|
"Action menu -> upload/download limit"),
|
2007-12-20 20:11:01 +00:00
|
|
|
[fDefaults integerForKey: upload ? @"UploadLimit" : @"DownloadLimit"]]];
|
2007-12-20 19:57:42 +00:00
|
|
|
|
2007-12-20 20:11:01 +00:00
|
|
|
[menuItem setState: [fDefaults boolForKey: upload ? @"CheckUpload" : @"CheckDownload"] ? limit : !limit];
|
2007-12-20 19:57:42 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2007-12-20 20:53:55 +00:00
|
|
|
|
|
|
|
if (action == @selector(setRatioGlobalEnabled:))
|
|
|
|
{
|
|
|
|
BOOL check = menuItem == fCheckRatioItem;
|
|
|
|
if (check)
|
2008-03-24 00:06:54 +00:00
|
|
|
[menuItem setTitle: [NSString localizedStringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
|
2008-01-10 06:27:48 +00:00
|
|
|
"Action menu -> ratio stop"), [fDefaults floatForKey: @"RatioLimit"]]];
|
2007-12-20 20:53:55 +00:00
|
|
|
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"RatioCheck"] ? check : !check];
|
|
|
|
return YES;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//enable show info
|
|
|
|
if (action == @selector(showInfo:))
|
|
|
|
{
|
2007-10-17 23:33:22 +00:00
|
|
|
NSString * title = [[fInfoController window] isVisible] ? NSLocalizedString(@"Hide Inspector", "View menu -> Inspector")
|
|
|
|
: NSLocalizedString(@"Show Inspector", "View menu -> Inspector");
|
2007-10-21 13:53:29 +00:00
|
|
|
[menuItem setTitle: title];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable prev/next inspector tab
|
|
|
|
if (action == @selector(setInfoTab:))
|
|
|
|
return [[fInfoController window] isVisible];
|
|
|
|
|
|
|
|
//enable toggle status bar
|
|
|
|
if (action == @selector(toggleStatusBar:))
|
|
|
|
{
|
|
|
|
NSString * title = [fStatusBar isHidden] ? NSLocalizedString(@"Show Status Bar", "View menu -> Status Bar")
|
|
|
|
: NSLocalizedString(@"Hide Status Bar", "View menu -> Status Bar");
|
2007-10-21 13:53:29 +00:00
|
|
|
[menuItem setTitle: title];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return [fWindow isVisible];
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable toggle filter bar
|
|
|
|
if (action == @selector(toggleFilterBar:))
|
|
|
|
{
|
|
|
|
NSString * title = [fFilterBar isHidden] ? NSLocalizedString(@"Show Filter Bar", "View menu -> Filter Bar")
|
|
|
|
: NSLocalizedString(@"Hide Filter Bar", "View menu -> Filter Bar");
|
2007-10-21 13:53:29 +00:00
|
|
|
[menuItem setTitle: title];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return [fWindow isVisible];
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable prev/next filter button
|
|
|
|
if (action == @selector(switchFilter:))
|
|
|
|
return [fWindow isVisible] && ![fFilterBar isHidden];
|
2008-05-21 18:59:18 +00:00
|
|
|
|
|
|
|
//enable quicklook item
|
|
|
|
if (action == @selector(toggleQuickLook:))
|
|
|
|
return [[QuickLookController quickLook] canQuickLook];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable reveal in finder
|
|
|
|
if (action == @selector(revealFile:))
|
|
|
|
return canUseTable && [fTableView numberOfSelectedRows] > 0;
|
|
|
|
|
|
|
|
//enable remove items
|
|
|
|
if (action == @selector(removeNoDelete:) || action == @selector(removeDeleteData:)
|
|
|
|
|| action == @selector(removeDeleteTorrent:) || action == @selector(removeDeleteDataAndTorrent:))
|
|
|
|
{
|
|
|
|
BOOL warning = NO,
|
|
|
|
onlyDownloading = [fDefaults boolForKey: @"CheckRemoveDownloading"],
|
|
|
|
canDelete = action != @selector(removeDeleteTorrent:) && action != @selector(removeDeleteDataAndTorrent:);
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if (!warning && [torrent isActive])
|
|
|
|
{
|
|
|
|
warning = onlyDownloading ? ![torrent isSeeding] : YES;
|
|
|
|
if (warning && canDelete)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!canDelete && [torrent publicTorrent])
|
|
|
|
{
|
|
|
|
canDelete = YES;
|
|
|
|
if (warning)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//append or remove ellipsis when needed
|
|
|
|
NSString * title = [menuItem title], * ellipsis = [NSString ellipsis];
|
|
|
|
if (warning && [fDefaults boolForKey: @"CheckRemove"])
|
|
|
|
{
|
|
|
|
if (![title hasSuffix: ellipsis])
|
|
|
|
[menuItem setTitle: [title stringByAppendingEllipsis]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([title hasSuffix: ellipsis])
|
|
|
|
[menuItem setTitle: [title substringToIndex: [title rangeOfString: ellipsis].location]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return canUseTable && canDelete && [fTableView numberOfSelectedRows] > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable pause all item
|
|
|
|
if (action == @selector(stopAllTorrents:))
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive] || [torrent waitingToStart])
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume all item
|
|
|
|
if (action == @selector(resumeAllTorrents:))
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-20 21:27:46 +00:00
|
|
|
if (![torrent isActive] && ![torrent waitingToStart])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume all waiting item
|
|
|
|
if (action == @selector(resumeWaitingTorrents:))
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: @"Queue"] && ![fDefaults boolForKey: @"QueueSeed"])
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-20 21:27:46 +00:00
|
|
|
if (![torrent isActive] && [torrent waitingToStart])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume selected waiting item
|
|
|
|
if (action == @selector(resumeSelectedTorrentsNoWait:))
|
|
|
|
{
|
2008-01-02 04:33:26 +00:00
|
|
|
if (!canUseTable)
|
|
|
|
return NO;
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-20 21:27:46 +00:00
|
|
|
if (![torrent isActive])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable pause item
|
|
|
|
if (action == @selector(stopSelectedTorrents:))
|
|
|
|
{
|
|
|
|
if (!canUseTable)
|
|
|
|
return NO;
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive] || [torrent waitingToStart])
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume item
|
|
|
|
if (action == @selector(resumeSelectedTorrents:))
|
|
|
|
{
|
|
|
|
if (!canUseTable)
|
|
|
|
return NO;
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-20 21:27:46 +00:00
|
|
|
if (![torrent isActive] && ![torrent waitingToStart])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable manual announce item
|
|
|
|
if (action == @selector(announceSelectedTorrents:))
|
|
|
|
{
|
|
|
|
if (!canUseTable)
|
|
|
|
return NO;
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent canManualAnnounce])
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable reset cache item
|
2008-02-27 19:04:38 +00:00
|
|
|
if (action == @selector(verifySelectedTorrents:))
|
2007-09-16 01:02:06 +00:00
|
|
|
return canUseTable && [fTableView numberOfSelectedRows] > 0;
|
|
|
|
|
|
|
|
//enable move torrent file item
|
2008-03-22 17:05:48 +00:00
|
|
|
if (action == @selector(moveDataFilesSelected:))
|
2007-09-16 01:02:06 +00:00
|
|
|
return canUseTable && [fTableView numberOfSelectedRows] > 0;
|
|
|
|
|
|
|
|
//enable copy torrent file item
|
|
|
|
if (action == @selector(copyTorrentFiles:))
|
|
|
|
return canUseTable && [fTableView numberOfSelectedRows] > 0;
|
|
|
|
|
|
|
|
//enable reverse sort item
|
|
|
|
if (action == @selector(setSortReverse:))
|
2007-10-30 19:55:47 +00:00
|
|
|
{
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"SortReverse"] ? NSOnState : NSOffState];
|
|
|
|
return ![[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-17 19:47:06 +00:00
|
|
|
//enable group sort item
|
|
|
|
if (action == @selector(setSortByGroup:))
|
|
|
|
{
|
|
|
|
[menuItem setState: [fDefaults boolForKey: @"SortByGroup"] ? NSOnState : NSOffState];
|
2008-05-11 21:38:40 +00:00
|
|
|
return YES;
|
2007-12-17 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//check proper filter search item
|
|
|
|
if (action == @selector(setFilterSearchType:))
|
|
|
|
{
|
|
|
|
NSString * filterType = [fDefaults stringForKey: @"FilterSearchType"];
|
|
|
|
|
|
|
|
BOOL state;
|
2007-10-21 13:53:29 +00:00
|
|
|
if ([menuItem tag] == FILTER_TYPE_TAG_TRACKER)
|
2007-09-16 01:02:06 +00:00
|
|
|
state = [filterType isEqualToString: FILTER_TYPE_TRACKER];
|
|
|
|
else
|
|
|
|
state = [filterType isEqualToString: FILTER_TYPE_NAME];
|
|
|
|
|
|
|
|
[menuItem setState: state ? NSOnState : NSOffState];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
- (void) sleepCallback: (natural_t) messageType argument: (void *) messageArgument
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSEnumerator * enumerator;
|
|
|
|
Torrent * torrent;
|
|
|
|
|
|
|
|
switch (messageType)
|
|
|
|
{
|
|
|
|
case kIOMessageSystemWillSleep:
|
2008-04-25 22:23:31 +00:00
|
|
|
//if there are any running transfers, wait 15 seconds for them to stop
|
2007-09-16 01:02:06 +00:00
|
|
|
enumerator = [fTorrents objectEnumerator];
|
2008-04-25 22:23:31 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-25 22:23:31 +00:00
|
|
|
//stop all transfers (since some are active) before going to sleep and remember to resume when we wake up
|
|
|
|
[fTorrents makeObjectsPerformSelector: @selector(sleep)];
|
|
|
|
sleep(15);
|
|
|
|
break;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IOAllowPowerChange(fRootPort, (long) messageArgument);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kIOMessageCanSystemSleep:
|
|
|
|
if ([fDefaults boolForKey: @"SleepPrevent"])
|
|
|
|
{
|
|
|
|
//prevent idle sleep unless no torrents are active
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
|
|
|
|
{
|
2008-04-25 22:23:31 +00:00
|
|
|
IOCancelPowerChange(fRootPort, (long) messageArgument);
|
|
|
|
return;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-27 14:31:49 +00:00
|
|
|
|
2008-04-25 22:23:31 +00:00
|
|
|
IOAllowPowerChange(fRootPort, (long) messageArgument);
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kIOMessageSystemHasPoweredOn:
|
|
|
|
//resume sleeping transfers after we wake up
|
|
|
|
[fTorrents makeObjectsPerformSelector: @selector(wakeUp)];
|
|
|
|
[self autoSpeedLimitChange: nil];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMenu *) applicationDockMenu: (NSApplication *) sender
|
|
|
|
{
|
|
|
|
int seeding = 0, downloading = 0;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if ([torrent isSeeding])
|
|
|
|
seeding++;
|
|
|
|
else if ([torrent isActive])
|
|
|
|
downloading++;
|
|
|
|
else;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMenuItem * seedingItem = [fDockMenu itemWithTag: DOCK_SEEDING_TAG],
|
|
|
|
* downloadingItem = [fDockMenu itemWithTag: DOCK_DOWNLOADING_TAG];
|
|
|
|
|
|
|
|
BOOL hasSeparator = seedingItem || downloadingItem;
|
|
|
|
|
|
|
|
if (seeding > 0)
|
|
|
|
{
|
2008-03-24 00:06:54 +00:00
|
|
|
NSString * title = [NSString stringWithFormat: NSLocalizedString(@"%d Seeding", "Dock item - Seeding"), seeding];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (!seedingItem)
|
|
|
|
{
|
|
|
|
seedingItem = [[[NSMenuItem alloc] initWithTitle: title action: nil keyEquivalent: @""] autorelease];
|
|
|
|
[seedingItem setTag: DOCK_SEEDING_TAG];
|
|
|
|
[fDockMenu insertItem: seedingItem atIndex: 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[seedingItem setTitle: title];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (seedingItem)
|
|
|
|
[fDockMenu removeItem: seedingItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (downloading > 0)
|
|
|
|
{
|
2008-03-24 00:06:54 +00:00
|
|
|
NSString * title = [NSString stringWithFormat: NSLocalizedString(@"%d Downloading", "Dock item - Downloading"), downloading];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (!downloadingItem)
|
|
|
|
{
|
|
|
|
downloadingItem = [[[NSMenuItem alloc] initWithTitle: title action: nil keyEquivalent: @""] autorelease];
|
|
|
|
[downloadingItem setTag: DOCK_DOWNLOADING_TAG];
|
|
|
|
[fDockMenu insertItem: downloadingItem atIndex: seeding > 0 ? 1 : 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[downloadingItem setTitle: title];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (downloadingItem)
|
|
|
|
[fDockMenu removeItem: downloadingItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seeding > 0 || downloading > 0)
|
|
|
|
{
|
|
|
|
if (!hasSeparator)
|
|
|
|
[fDockMenu insertItem: [NSMenuItem separatorItem] atIndex: seeding > 0 && downloading > 0 ? 2 : 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (hasSeparator)
|
|
|
|
[fDockMenu removeItemAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return fDockMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
|
|
|
|
{
|
|
|
|
//if auto size is enabled, the current frame shouldn't need to change
|
|
|
|
NSRect frame = [fDefaults boolForKey: @"AutoSize"] ? [window frame] : [self sizedWindowFrame];
|
|
|
|
|
|
|
|
frame.size.width = [fDefaults boolForKey: @"SmallView"] ? [fWindow minSize].width : WINDOW_REGULAR_WIDTH;
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWindowSizeToFit
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"AutoSize"])
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
NSScrollView * scrollView = [fTableView enclosingScrollView];
|
|
|
|
|
|
|
|
[scrollView setHasVerticalScroller: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fWindow setFrame: [self sizedWindowFrame] display: YES animate: YES];
|
2008-02-06 23:45:44 +00:00
|
|
|
[scrollView setHasVerticalScroller: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) sizedWindowFrame
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
int groups = ([fDisplayedTorrents count] > 0 && ![[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [Torrent class]])
|
|
|
|
? [fDisplayedTorrents count] : 0;
|
|
|
|
|
|
|
|
float heightChange = (GROUP_SEPARATOR_HEIGHT + [fTableView intercellSpacing].height) * groups
|
|
|
|
+ ([fTableView rowHeight] + [fTableView intercellSpacing].height) * ([fTableView numberOfRows] - groups)
|
|
|
|
- [[fTableView enclosingScrollView] frame].size.height;
|
2008-01-23 02:51:58 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return [self windowFrameByAddingHeight: heightChange checkLimits: YES];
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (void) updateForExpandCollape
|
|
|
|
{
|
|
|
|
[self setWindowSizeToFit];
|
2008-03-21 20:28:04 +00:00
|
|
|
[self setBottomCountText: YES];
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) showMainWindow: (id) sender
|
|
|
|
{
|
|
|
|
[fWindow makeKeyAndOrderFront: nil];
|
|
|
|
}
|
|
|
|
|
2007-11-01 19:18:26 +00:00
|
|
|
- (void) windowDidBecomeMain: (NSNotification *) notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
[fBadger clearCompleted];
|
2007-09-26 04:12:57 +00:00
|
|
|
[self updateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize) windowWillResize: (NSWindow *) sender toSize: (NSSize) proposedFrameSize
|
|
|
|
{
|
|
|
|
//only resize horizontally if autosize is enabled
|
|
|
|
if ([fDefaults boolForKey: @"AutoSize"])
|
|
|
|
proposedFrameSize.height = [fWindow frame].size.height;
|
|
|
|
return proposedFrameSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) windowDidResize: (NSNotification *) notification
|
|
|
|
{
|
2008-03-28 01:28:57 +00:00
|
|
|
if (![fStatusBar isHidden])
|
|
|
|
[self resizeStatusButton];
|
|
|
|
|
2007-12-20 18:58:53 +00:00
|
|
|
if ([fFilterBar isHidden])
|
|
|
|
return;
|
|
|
|
|
2007-12-20 04:49:06 +00:00
|
|
|
//replace all buttons
|
|
|
|
[fActiveFilterButton sizeToFit];
|
|
|
|
[fDownloadFilterButton sizeToFit];
|
|
|
|
[fSeedFilterButton sizeToFit];
|
|
|
|
[fPauseFilterButton sizeToFit];
|
|
|
|
|
|
|
|
NSRect activeRect = [fActiveFilterButton frame];
|
|
|
|
|
|
|
|
NSRect downloadRect = [fDownloadFilterButton frame];
|
2007-12-20 05:12:23 +00:00
|
|
|
downloadRect.origin.x = NSMaxX(activeRect) + 1.0;
|
2007-12-20 04:49:06 +00:00
|
|
|
|
|
|
|
NSRect seedRect = [fSeedFilterButton frame];
|
2007-12-20 05:12:23 +00:00
|
|
|
seedRect.origin.x = NSMaxX(downloadRect) + 1.0;
|
2007-12-20 04:49:06 +00:00
|
|
|
|
|
|
|
NSRect pauseRect = [fPauseFilterButton frame];
|
2007-12-20 05:12:23 +00:00
|
|
|
pauseRect.origin.x = NSMaxX(seedRect) + 1.0;
|
2007-12-20 04:49:06 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//size search filter to not overlap buttons
|
2007-12-20 04:49:06 +00:00
|
|
|
NSRect searchFrame = [fSearchFilterField frame];
|
|
|
|
searchFrame.origin.x = NSMaxX(pauseRect) + 5.0;
|
|
|
|
searchFrame.size.width = [fStatusBar frame].size.width - searchFrame.origin.x - 5.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-20 04:49:06 +00:00
|
|
|
//make sure it is not too long
|
|
|
|
if (searchFrame.size.width > SEARCH_FILTER_MAX_WIDTH)
|
|
|
|
{
|
|
|
|
searchFrame.origin.x += searchFrame.size.width - SEARCH_FILTER_MAX_WIDTH;
|
|
|
|
searchFrame.size.width = SEARCH_FILTER_MAX_WIDTH;
|
|
|
|
}
|
|
|
|
else if (searchFrame.size.width < SEARCH_FILTER_MIN_WIDTH)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-20 04:49:06 +00:00
|
|
|
searchFrame.origin.x += searchFrame.size.width - SEARCH_FILTER_MIN_WIDTH;
|
|
|
|
searchFrame.size.width = SEARCH_FILTER_MIN_WIDTH;
|
|
|
|
|
2008-03-27 03:32:40 +00:00
|
|
|
//resize the buttons so they don't overlay
|
2008-03-27 03:43:44 +00:00
|
|
|
int difference = (NSMaxX(pauseRect) + 5.0) - searchFrame.origin.x - 1; //subtract 1, since 0 will be counted
|
2008-03-27 03:32:40 +00:00
|
|
|
|
|
|
|
//decrease downloading by 8, seeding by 1, paused by 1, active by 1, repeat
|
|
|
|
int download = (difference / 11 * 8) + MIN(difference % 11 + 1, 8); //8 for every 11
|
|
|
|
int seed = (difference / 11) + (difference % 11 >= 8 ? 1 : 0);
|
|
|
|
int paused = (difference / 11) + (difference % 11 >= 9 ? 1 : 0);
|
|
|
|
int active = (difference / 11) + (difference % 11 >= 10 ? 1 : 0);
|
|
|
|
|
|
|
|
activeRect.size.width -= active;
|
|
|
|
|
|
|
|
downloadRect.origin.x -= active;
|
2008-03-28 01:28:57 +00:00
|
|
|
downloadRect.size.width -= download;
|
2008-03-27 03:32:40 +00:00
|
|
|
|
|
|
|
seedRect.origin.x -= active + download;
|
2008-03-28 01:28:57 +00:00
|
|
|
seedRect.size.width -= seed;
|
2008-03-27 03:32:40 +00:00
|
|
|
|
|
|
|
pauseRect.origin.x -= active + download + seed;
|
2008-03-28 01:28:57 +00:00
|
|
|
pauseRect.size.width -= paused;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-20 04:49:06 +00:00
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-12-20 17:39:05 +00:00
|
|
|
[fActiveFilterButton setFrame: activeRect];
|
|
|
|
[fDownloadFilterButton setFrame: downloadRect];
|
|
|
|
[fSeedFilterButton setFrame: seedRect];
|
|
|
|
[fPauseFilterButton setFrame: pauseRect];
|
|
|
|
|
2007-12-20 04:49:06 +00:00
|
|
|
[fSearchFilterField setFrame: searchFrame];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 04:12:57 +00:00
|
|
|
- (void) applicationWillUnhide: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
[self updateUI];
|
|
|
|
}
|
|
|
|
|
2008-05-21 15:45:27 +00:00
|
|
|
- (NSArray *) quickLookURLs
|
|
|
|
{
|
|
|
|
NSArray * selectedTorrents = [fTableView selectedTorrents];
|
|
|
|
NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]];
|
|
|
|
NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2008-06-22 01:31:50 +00:00
|
|
|
if ([self canQuickLookTorrent: torrent])
|
2008-05-21 15:49:37 +00:00
|
|
|
[urlArray addObject: [NSURL fileURLWithPath: [torrent dataLocation]]];
|
2008-05-21 15:45:27 +00:00
|
|
|
|
|
|
|
return urlArray;
|
|
|
|
}
|
|
|
|
|
2008-05-21 18:59:18 +00:00
|
|
|
- (BOOL) canQuickLook
|
|
|
|
{
|
|
|
|
NSArray * selectedTorrents = [fTableView selectedTorrents];
|
|
|
|
NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2008-06-22 01:31:50 +00:00
|
|
|
if ([self canQuickLookTorrent: torrent])
|
2008-05-21 18:59:18 +00:00
|
|
|
return YES;
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2008-06-22 01:31:50 +00:00
|
|
|
- (BOOL) canQuickLookTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent dataLocation]])
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
return [torrent isFolder] || [torrent isComplete];
|
|
|
|
}
|
|
|
|
|
2008-05-21 15:45:27 +00:00
|
|
|
- (NSRect) quickLookFrameWithURL: (NSURL *) url
|
|
|
|
{
|
2008-05-21 16:32:26 +00:00
|
|
|
if ([fWindow isVisible])
|
2008-05-21 15:45:27 +00:00
|
|
|
{
|
2008-05-21 16:32:26 +00:00
|
|
|
NSString * fullPath = [url path];
|
|
|
|
NSRange visibleRows = [fTableView rowsInRect: [fTableView bounds]];
|
|
|
|
|
|
|
|
int row;
|
2008-05-21 21:15:15 +00:00
|
|
|
for (row = 0; row < NSMaxRange(visibleRows); row++)
|
2008-05-21 15:45:27 +00:00
|
|
|
{
|
2008-05-21 16:32:26 +00:00
|
|
|
id item = [fTableView itemAtRow: row];
|
|
|
|
if ([item isKindOfClass: [Torrent class]] && [[(Torrent *)item dataLocation] isEqualToString: fullPath])
|
|
|
|
{
|
2008-05-21 22:09:05 +00:00
|
|
|
NSRect frame = [fTableView iconRectForRow: row];
|
2008-05-21 16:32:26 +00:00
|
|
|
frame.origin = [fTableView convertPoint: frame.origin toView: nil];
|
|
|
|
frame.origin = [fWindow convertBaseToScreen: frame.origin];
|
|
|
|
frame.origin.y -= frame.size.height;
|
|
|
|
return frame;
|
|
|
|
}
|
2008-05-21 15:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
2008-05-21 16:28:21 +00:00
|
|
|
- (void) toggleQuickLook: (id) sender
|
2008-05-21 16:02:38 +00:00
|
|
|
{
|
|
|
|
[[QuickLookController quickLook] toggleQuickLook];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) linkHomepage: (id) sender
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: WEBSITE_URL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) linkForums: (id) sender
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FORUM_URL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) linkDonate: (id) sender
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: DONATE_URL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) prepareForUpdate: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
fUpdateInProgress = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) registrationDictionaryForGrowl
|
|
|
|
{
|
|
|
|
NSArray * notifications = [NSArray arrayWithObjects: GROWL_DOWNLOAD_COMPLETE, GROWL_SEEDING_COMPLETE,
|
|
|
|
GROWL_AUTO_ADD, GROWL_AUTO_SPEED_LIMIT, nil];
|
|
|
|
return [NSDictionary dictionaryWithObjectsAndKeys: notifications, GROWL_NOTIFICATIONS_ALL,
|
|
|
|
notifications, GROWL_NOTIFICATIONS_DEFAULT, nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) growlNotificationWasClicked: (id) clickContext
|
|
|
|
{
|
|
|
|
if (!clickContext || ![clickContext isKindOfClass: [NSDictionary class]])
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSString * type = [clickContext objectForKey: @"Type"], * location;
|
|
|
|
if (([type isEqualToString: GROWL_DOWNLOAD_COMPLETE] || [type isEqualToString: GROWL_SEEDING_COMPLETE])
|
|
|
|
&& (location = [clickContext objectForKey: @"Location"]))
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
- (void) rpcCallback: (tr_rpc_callback_type) type forTorrentStruct: (struct tr_torrent *) torrentStruct
|
|
|
|
{
|
2008-05-25 17:34:02 +00:00
|
|
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
//get the torrent
|
2008-06-03 17:55:43 +00:00
|
|
|
Torrent * torrent = nil;
|
2008-05-27 00:52:18 +00:00
|
|
|
if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED))
|
2008-05-20 15:16:34 +00:00
|
|
|
{
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
if (torrentStruct == [torrent torrentStruct])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!torrent)
|
|
|
|
{
|
2008-05-22 20:00:22 +00:00
|
|
|
NSLog(@"No torrent found matching the given torrent struct from the RPC callback!");
|
2008-05-20 15:16:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-27 19:05:48 +00:00
|
|
|
|
|
|
|
[torrent retain];
|
2008-05-20 15:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TR_RPC_TORRENT_ADDED:
|
2008-05-27 00:52:18 +00:00
|
|
|
[self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
|
|
|
|
[[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
|
2008-05-20 15:16:34 +00:00
|
|
|
break;
|
2008-06-03 16:20:21 +00:00
|
|
|
|
2008-06-03 16:22:31 +00:00
|
|
|
case TR_RPC_TORRENT_STARTED:
|
|
|
|
case TR_RPC_TORRENT_STOPPED:
|
2008-06-03 16:20:21 +00:00
|
|
|
[self performSelectorOnMainThread: @selector(rpcStartedStoppedTorrent:) withObject: torrent waitUntilDone: NO];
|
2008-05-20 15:16:34 +00:00
|
|
|
break;
|
2008-06-03 16:20:21 +00:00
|
|
|
|
2008-06-03 16:22:31 +00:00
|
|
|
case TR_RPC_TORRENT_REMOVING:
|
2008-05-27 19:05:48 +00:00
|
|
|
[self performSelectorOnMainThread: @selector(rpcRemoveTorrent:) withObject: torrent waitUntilDone: NO];
|
2008-05-20 15:16:34 +00:00
|
|
|
break;
|
2008-06-03 16:20:21 +00:00
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
case TR_RPC_TORRENT_CHANGED:
|
2008-06-03 16:20:21 +00:00
|
|
|
[self performSelectorOnMainThread: @selector(rpcChangedTorrent:) withObject: torrent waitUntilDone: NO];
|
2008-05-20 15:16:34 +00:00
|
|
|
break;
|
2008-06-03 16:20:21 +00:00
|
|
|
|
2008-05-20 15:16:34 +00:00
|
|
|
case TR_RPC_SESSION_CHANGED:
|
2008-06-03 17:55:43 +00:00
|
|
|
[fPrefsController performSelectorOnMainThread: @selector(rpcUpdatePrefs) withObject: nil waitUntilDone: NO];
|
2008-05-20 15:16:34 +00:00
|
|
|
break;
|
2008-06-03 16:20:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
NSLog(@"Unknown RPC command received!");
|
2008-06-03 17:55:43 +00:00
|
|
|
[torrent release];
|
2008-05-20 15:16:34 +00:00
|
|
|
}
|
2008-05-25 17:34:02 +00:00
|
|
|
|
|
|
|
[pool release];
|
2008-05-20 15:16:34 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:52:18 +00:00
|
|
|
- (void) rpcAddTorrentStruct: (NSValue *) torrentStructPtr
|
|
|
|
{
|
|
|
|
tr_torrent * torrentStruct = (tr_torrent *)[torrentStructPtr pointerValue];
|
|
|
|
[torrentStructPtr release];
|
|
|
|
|
|
|
|
NSString * location = nil;
|
|
|
|
if (tr_torrentGetDownloadDir(torrentStruct) != NULL)
|
|
|
|
location = [NSString stringWithUTF8String: tr_torrentGetDownloadDir(torrentStruct)];
|
|
|
|
|
|
|
|
Torrent * torrent = [[Torrent alloc] initWithTorrentStruct: torrentStruct location: location lib: fLib];
|
|
|
|
|
|
|
|
[torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];
|
|
|
|
|
|
|
|
[torrent update];
|
|
|
|
[fTorrents addObject: torrent];
|
|
|
|
[torrent release];
|
|
|
|
|
|
|
|
[self updateTorrentsInQueue];
|
|
|
|
}
|
|
|
|
|
2008-05-27 19:05:48 +00:00
|
|
|
- (void) rpcRemoveTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
[self confirmRemoveTorrents: [[NSArray arrayWithObject: torrent] retain] deleteData: NO deleteTorrent: NO fromRPC: YES];
|
|
|
|
[torrent release];
|
|
|
|
}
|
|
|
|
|
2008-06-03 16:20:21 +00:00
|
|
|
- (void) rpcStartedStoppedTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
[torrent update];
|
|
|
|
[torrent release];
|
|
|
|
|
|
|
|
[self updateUI];
|
|
|
|
[self applyFilter: nil];
|
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) rpcChangedTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
[torrent update];
|
|
|
|
|
2008-06-03 16:28:09 +00:00
|
|
|
if ([[fTableView selectedTorrents] containsObject: torrent])
|
|
|
|
{
|
2008-06-03 18:00:51 +00:00
|
|
|
[fInfoController updateInfoStats]; //this will reload the file table
|
2008-06-03 16:28:09 +00:00
|
|
|
[fInfoController updateOptions];
|
|
|
|
}
|
|
|
|
|
|
|
|
[torrent release];
|
2008-06-03 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|