2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2005-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-06-29 00:15:52 +00:00
|
|
|
@import IOKit;
|
|
|
|
@import IOKit.pwr_mgt;
|
|
|
|
@import Carbon;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-06-29 00:15:52 +00:00
|
|
|
@import Sparkle;
|
2018-09-30 10:37:30 +00:00
|
|
|
|
2021-11-03 06:00:52 +00:00
|
|
|
#include <atomic> /* atomic, atomic_fetch_add_explicit, memory_order_relaxed */
|
|
|
|
|
2018-09-30 10:37:30 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2022-03-17 00:23:44 +00:00
|
|
|
|
|
|
|
#include <libtransmission/log.h>
|
2021-12-26 03:12:32 +00:00
|
|
|
#include <libtransmission/torrent-metainfo.h>
|
2018-09-30 10:37:30 +00:00
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
#include <libtransmission/variant.h>
|
|
|
|
|
|
|
|
#import "VDKQueue.h"
|
|
|
|
|
2022-04-24 20:34:30 +00:00
|
|
|
#import "CocoaCompatibility.h"
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "Controller.h"
|
|
|
|
#import "Torrent.h"
|
2008-07-01 01:28:19 +00:00
|
|
|
#import "TorrentGroup.h"
|
2022-06-16 17:55:33 +00:00
|
|
|
#import "TorrentTableView.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "CreatorWindowController.h"
|
2007-11-19 18:13:41 +00:00
|
|
|
#import "StatsWindowController.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "InfoWindowController.h"
|
|
|
|
#import "PrefsController.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "AboutWindowController.h"
|
2011-02-10 00:51:25 +00:00
|
|
|
#import "URLSheetWindowController.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "AddWindowController.h"
|
2010-04-12 00:55:31 +00:00
|
|
|
#import "AddMagnetWindowController.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "MessageWindowController.h"
|
2011-07-23 15:54:02 +00:00
|
|
|
#import "GlobalOptionsPopoverViewController.h"
|
2007-11-29 01:05:11 +00:00
|
|
|
#import "ButtonToolbarItem.h"
|
2007-12-07 06:27:42 +00:00
|
|
|
#import "GroupToolbarItem.h"
|
2014-01-09 16:23:54 +00:00
|
|
|
#import "ShareToolbarItem.h"
|
2014-01-10 17:50:05 +00:00
|
|
|
#import "ShareTorrentFileHelper.h"
|
2022-06-24 05:26:36 +00:00
|
|
|
#import "Toolbar.h"
|
2008-04-22 13:25:53 +00:00
|
|
|
#import "ToolbarSegmentedCell.h"
|
2008-08-31 20:26:41 +00:00
|
|
|
#import "BlocklistDownloader.h"
|
2022-06-16 17:55:33 +00:00
|
|
|
#import "StatusBarController.h"
|
|
|
|
#import "FilterBarController.h"
|
2013-01-22 00:09:48 +00:00
|
|
|
#import "FileRenameSheetController.h"
|
2008-12-06 01:18:25 +00:00
|
|
|
#import "BonjourController.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "Badger.h"
|
|
|
|
#import "DragOverlayWindow.h"
|
2022-04-24 20:34:30 +00:00
|
|
|
#import "NSImageAdditions.h"
|
2012-01-04 05:16:07 +00:00
|
|
|
#import "NSMutableArrayAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "ExpandedPathToPathTransformer.h"
|
|
|
|
#import "ExpandedPathToIconTransformer.h"
|
2010-04-23 16:59:14 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define TOOLBAR_CREATE @"Toolbar Create"
|
|
|
|
#define TOOLBAR_OPEN_FILE @"Toolbar Open"
|
|
|
|
#define TOOLBAR_OPEN_WEB @"Toolbar Open Web"
|
|
|
|
#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"
|
|
|
|
#define TOOLBAR_QUICKLOOK @"Toolbar QuickLook"
|
|
|
|
#define TOOLBAR_SHARE @"Toolbar Share"
|
|
|
|
|
|
|
|
typedef NS_ENUM(unsigned int, toolbarGroupTag) { //
|
2007-12-06 20:25:38 +00:00
|
|
|
TOOLBAR_PAUSE_TAG = 0,
|
|
|
|
TOOLBAR_RESUME_TAG = 1
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2007-12-06 20:25:38 +00:00
|
|
|
|
2021-08-15 09:41:48 +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"
|
|
|
|
#define SORT_ACTIVITY @"Activity"
|
|
|
|
#define SORT_SIZE @"Size"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
typedef NS_ENUM(unsigned int, sortTag) {
|
2007-11-07 05:02:43 +00:00
|
|
|
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,
|
2011-07-04 19:47:15 +00:00
|
|
|
SORT_ACTIVITY_TAG = 6,
|
|
|
|
SORT_SIZE_TAG = 7
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2007-11-07 05:02:43 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
typedef NS_ENUM(unsigned int, sortOrderTag) { //
|
2011-01-06 04:09:04 +00:00
|
|
|
SORT_ASC_TAG = 0,
|
|
|
|
SORT_DESC_TAG = 1
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2011-01-06 04:09:04 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define TORRENT_TABLE_VIEW_DATA_TYPE @"TorrentTableViewDataType"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define ROW_HEIGHT_REGULAR 62.0
|
|
|
|
#define ROW_HEIGHT_SMALL 22.0
|
2022-06-16 17:55:33 +00:00
|
|
|
|
|
|
|
#define STATUS_BAR_HEIGHT 21.0
|
|
|
|
#define FILTER_BAR_HEIGHT 23.0
|
2022-06-16 19:59:54 +00:00
|
|
|
#define BOTTOM_BAR_HEIGHT 24.0
|
2011-03-08 00:20:58 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define UPDATE_UI_SECONDS 1.0
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define TRANSFER_PLIST @"Transfers.plist"
|
2007-10-21 14:01:54 +00:00
|
|
|
|
2016-10-31 09:00:11 +00:00
|
|
|
#define WEBSITE_URL @"https://transmissionbt.com/"
|
2021-08-15 09:41:48 +00:00
|
|
|
#define FORUM_URL @"https://forum.transmissionbt.com/"
|
|
|
|
#define GITHUB_URL @"https://github.com/transmission/transmission"
|
|
|
|
#define DONATE_URL @"https://transmissionbt.com/donate/"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-08-14 01:11:13 +00:00
|
|
|
#define DONATE_NAG_TIME (60 * 60 * 24 * 7)
|
|
|
|
|
2021-10-10 16:52:26 +00:00
|
|
|
static void altSpeedToggledCallback([[maybe_unused]] tr_session* handle, bool active, bool byUser, void* controller)
|
2009-03-28 17:18:43 +00:00
|
|
|
{
|
2022-06-29 04:20:42 +00:00
|
|
|
NSDictionary* dict = @{@"Active" : @(active), @"ByUser" : @(byUser)};
|
2021-08-15 09:41:48 +00:00
|
|
|
[(__bridge Controller*)controller performSelectorOnMainThread:@selector(altSpeedToggledCallbackIsLimited:) withObject:dict
|
|
|
|
waitUntilDone:NO];
|
2009-03-28 17:18:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 16:52:26 +00:00
|
|
|
static tr_rpc_callback_status rpcCallback([[maybe_unused]] tr_session* handle, tr_rpc_callback_type type, struct tr_torrent* torrentStruct, void* controller)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[(__bridge Controller*)controller rpcCallback:type forTorrentStruct:torrentStruct];
|
2008-08-14 02:18:14 +00:00
|
|
|
return TR_RPC_NOREMOVE; //we'll do the remove manually
|
2008-05-20 15:16:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static void sleepCallback(void* controller, io_service_t y, natural_t messageType, void* messageArgument)
|
2008-05-20 15:16:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[(__bridge Controller*)controller sleepCallback:messageType argument:messageArgument];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 19:45:41 +00:00
|
|
|
// 2.90 was infected with ransomware which we now check for and attempt to remove
|
|
|
|
static void removeKeRangerRansomware()
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* krBinaryResourcePath = [NSBundle.mainBundle pathForResource:@"General" ofType:@"rtf"];
|
2016-03-06 19:45:41 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* userLibraryDirPath = [NSHomeDirectory() stringByAppendingString:@"/Library"];
|
|
|
|
NSString* krLibraryKernelServicePath = [userLibraryDirPath stringByAppendingString:@"/kernel_service"];
|
2016-03-06 19:45:41 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSFileManager* fileManager = NSFileManager.defaultManager;
|
2016-03-06 19:45:41 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray<NSString*>* krFilePaths = @[
|
2016-03-06 19:45:41 +00:00
|
|
|
krBinaryResourcePath ? krBinaryResourcePath : @"",
|
2021-08-15 09:41:48 +00:00
|
|
|
[userLibraryDirPath stringByAppendingString:@"/.kernel_pid"],
|
|
|
|
[userLibraryDirPath stringByAppendingString:@"/.kernel_time"],
|
|
|
|
[userLibraryDirPath stringByAppendingString:@"/.kernel_complete"],
|
2016-03-06 19:45:41 +00:00
|
|
|
krLibraryKernelServicePath
|
|
|
|
];
|
|
|
|
|
|
|
|
BOOL foundKrFiles = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* krFilePath in krFilePaths)
|
2016-03-06 19:45:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (krFilePath.length == 0 || ![fileManager fileExistsAtPath:krFilePath])
|
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-06 19:45:41 +00:00
|
|
|
|
|
|
|
foundKrFiles = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundKrFiles)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-06 19:45:41 +00:00
|
|
|
|
|
|
|
NSLog(@"Detected OSX.KeRanger.A ransomware, trying to remove it");
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fileManager fileExistsAtPath:krLibraryKernelServicePath])
|
2016-03-06 19:45:41 +00:00
|
|
|
{
|
|
|
|
// The forgiving way: kill process which has the file opened
|
2021-08-15 09:41:48 +00:00
|
|
|
NSTask* lsofTask = [[NSTask alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
lsofTask.launchPath = @"/usr/sbin/lsof";
|
2021-08-15 09:41:48 +00:00
|
|
|
lsofTask.arguments = @[ @"-F", @"pid", @"--", krLibraryKernelServicePath ];
|
2021-08-07 07:27:56 +00:00
|
|
|
lsofTask.standardOutput = [NSPipe pipe];
|
|
|
|
lsofTask.standardInput = [NSPipe pipe];
|
|
|
|
lsofTask.standardError = lsofTask.standardOutput;
|
2016-03-06 19:45:41 +00:00
|
|
|
[lsofTask launch];
|
2022-04-21 14:28:38 +00:00
|
|
|
NSData* lsofOutputData = [[lsofTask.standardOutput fileHandleForReading] readDataToEndOfFile];
|
2016-03-06 19:45:41 +00:00
|
|
|
[lsofTask waitUntilExit];
|
2022-04-21 14:28:38 +00:00
|
|
|
NSString* lsofOutput = [[NSString alloc] initWithData:lsofOutputData encoding:NSUTF8StringEncoding];
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* line in [lsofOutput componentsSeparatedByString:@"\n"])
|
2016-03-06 19:45:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![line hasPrefix:@"p"])
|
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
pid_t const krProcessId = [line substringFromIndex:1].intValue;
|
2016-03-06 19:45:41 +00:00
|
|
|
if (kill(krProcessId, SIGKILL) == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
NSLog(@"Unable to forcibly terminate ransomware process (kernel_service, pid %d), please do so manually", (int)krProcessId);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-06 19:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The harsh way: kill all processes with matching name
|
2021-08-15 09:41:48 +00:00
|
|
|
NSTask* killTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall" arguments:@[ @"-9", @"kernel_service" ]];
|
2016-03-06 19:45:41 +00:00
|
|
|
[killTask waitUntilExit];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (killTask.terminationStatus != 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
NSLog(@"Unable to forcibly terminate ransomware process (kernel_service), please do so manually if it's currently running");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-06 19:45:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* krFilePath in krFilePaths)
|
2016-03-06 19:45:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (krFilePath.length == 0 || ![fileManager fileExistsAtPath:krFilePath])
|
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fileManager removeItemAtPath:krFilePath error:NULL])
|
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
NSLog(@"Unable to remove ransomware file at %@, please do so manually", krFilePath);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-06 19:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"OSX.KeRanger.A ransomware removal completed, proceeding to normal operation");
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
@interface Controller ()
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSWindow* fWindow;
|
2022-06-16 19:59:54 +00:00
|
|
|
@property(nonatomic) IBOutlet NSStackView* fStackView;
|
|
|
|
@property(nonatomic) NSArray* fStackViewHeightConstraints;
|
2022-06-16 17:55:33 +00:00
|
|
|
@property(nonatomic) IBOutlet TorrentTableView* fTableView;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSMenuItem* fOpenIgnoreDownloadFolder;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fActionButton;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fSpeedLimitButton;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fClearCompletedButton;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fTotalTorrentsField;
|
|
|
|
@property(nonatomic) IBOutlet NSMenuItem* fNextFilterItem;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSMenuItem* fNextInfoTabItem;
|
|
|
|
@property(nonatomic) IBOutlet NSMenuItem* fPrevInfoTabItem;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fSortMenu;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fGroupsSetMenu;
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fGroupsSetContextMenu;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fShareMenu;
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fShareContextMenu;
|
|
|
|
@property(nonatomic) IBOutlet NSMenuItem* fShareMenuItem; // remove when dropping 10.6
|
|
|
|
@property(nonatomic) IBOutlet NSMenuItem* fShareContextMenuItem; // remove when dropping 10.6
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) tr_session* fLib;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSMutableArray<Torrent*>* fTorrents;
|
|
|
|
@property(nonatomic, readonly) NSMutableArray* fDisplayedTorrents;
|
|
|
|
@property(nonatomic, readonly) NSMutableDictionary<NSString*, Torrent*>* fTorrentHashes;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) InfoWindowController* fInfoController;
|
|
|
|
@property(nonatomic) MessageWindowController* fMessageController;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSUserDefaults* fDefaults;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSString* fConfigDirectory;
|
|
|
|
|
|
|
|
@property(nonatomic) DragOverlayWindow* fOverlayWindow;
|
|
|
|
|
|
|
|
@property(nonatomic) io_connect_t fRootPort;
|
|
|
|
@property(nonatomic) NSTimer* fTimer;
|
|
|
|
|
|
|
|
@property(nonatomic) StatusBarController* fStatusBar;
|
|
|
|
|
|
|
|
@property(nonatomic) FilterBarController* fFilterBar;
|
|
|
|
|
|
|
|
@property(nonatomic) QLPreviewPanel* fPreviewPanel;
|
|
|
|
@property(nonatomic) BOOL fQuitting;
|
|
|
|
@property(nonatomic) BOOL fQuitRequested;
|
|
|
|
@property(nonatomic, readonly) BOOL fPauseOnLaunch;
|
|
|
|
|
|
|
|
@property(nonatomic) Badger* fBadger;
|
|
|
|
|
|
|
|
@property(nonatomic) NSMutableArray<NSString*>* fAutoImportedNames;
|
|
|
|
@property(nonatomic) NSTimer* fAutoImportTimer;
|
|
|
|
|
|
|
|
@property(nonatomic) NSMutableDictionary<NSURL*, id>* fPendingTorrentDownloads;
|
|
|
|
|
|
|
|
@property(nonatomic) NSMutableSet<Torrent*>* fAddingTransfers;
|
|
|
|
|
|
|
|
@property(nonatomic) NSMutableSet<NSWindowController*>* fAddWindows;
|
|
|
|
@property(nonatomic) URLSheetWindowController* fUrlSheetController;
|
|
|
|
|
|
|
|
@property(nonatomic) BOOL fGlobalPopoverShown;
|
|
|
|
@property(nonatomic) NSView* fPositioningView;
|
|
|
|
@property(nonatomic) BOOL fSoundPlaying;
|
|
|
|
@property(nonatomic) id fNoNapActivity;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@implementation Controller
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (void)initialize
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2016-03-06 19:45:41 +00:00
|
|
|
removeKeRangerRansomware();
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//make sure another Transmission.app isn't running already
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:NSBundle.mainBundle.bundleIdentifier];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (apps.count > 1)
|
2009-10-10 00:00:46 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Transmission already running alert -> button")];
|
|
|
|
alert.messageText = NSLocalizedString(@"Transmission is already running.", "Transmission already running alert -> title");
|
|
|
|
alert.informativeText = NSLocalizedString(
|
|
|
|
@"There is already a copy of Transmission running. "
|
|
|
|
"This copy cannot be opened until that instance is quit.",
|
|
|
|
"Transmission already running alert -> message");
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleCritical;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-10 00:00:46 +00:00
|
|
|
[alert runModal];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-10 00:00:46 +00:00
|
|
|
//kill ourselves right away
|
|
|
|
exit(0);
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults
|
|
|
|
registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"Defaults" ofType:@"plist"]]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set custom value transformers
|
2021-08-15 09:41:48 +00:00
|
|
|
ExpandedPathToPathTransformer* pathTransformer = [[ExpandedPathToPathTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:pathTransformer forName:@"ExpandedPathToPathTransformer"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
ExpandedPathToIconTransformer* iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:iconTransformer forName:@"ExpandedPathToIconTransformer"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-02 21:51:09 +00:00
|
|
|
//cover our asses
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([NSUserDefaults.standardUserDefaults boolForKey:@"WarningLegal"])
|
2009-10-02 21:51:09 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"I Accept", "Legal alert -> button")];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Quit", "Legal alert -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"Welcome to Transmission", "Legal alert -> title");
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.informativeText = NSLocalizedString(
|
|
|
|
@"Transmission is a file-sharing program."
|
|
|
|
" When you run a torrent, its data will be made available to others by means of upload."
|
|
|
|
" You and you alone are fully responsible for exercising proper judgement and abiding by your local laws.",
|
2021-08-07 07:27:56 +00:00
|
|
|
"Legal alert -> message");
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleInformational;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-02 21:51:09 +00:00
|
|
|
if ([alert runModal] == NSAlertSecondButtonReturn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-02 21:51:09 +00:00
|
|
|
exit(0);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningLegal"];
|
2009-10-02 21:51:09 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-23 06:04:34 +00:00
|
|
|
void onStartQueue(tr_session* session, tr_torrent* tor, void* vself)
|
|
|
|
{
|
|
|
|
auto* controller = (__bridge Controller*)(vself);
|
|
|
|
auto const hashstr = @(tr_torrentView(tor).hash_string);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
auto* const torrent = [controller torrentForHash:hashstr];
|
|
|
|
[torrent startQueue];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void onIdleLimitHit(tr_session* session, tr_torrent* tor, void* vself)
|
|
|
|
{
|
|
|
|
auto* const controller = (__bridge Controller*)(vself);
|
|
|
|
auto const hashstr = @(tr_torrentView(tor).hash_string);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
auto* const torrent = [controller torrentForHash:hashstr];
|
|
|
|
[torrent idleLimitHit];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void onRatioLimitHit(tr_session* session, tr_torrent* tor, void* vself)
|
|
|
|
{
|
|
|
|
auto* const controller = (__bridge Controller*)(vself);
|
|
|
|
auto const hashstr = @(tr_torrentView(tor).hash_string);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
auto* const torrent = [controller torrentForHash:hashstr];
|
|
|
|
[torrent ratioLimitHit];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void onMetadataCompleted(tr_session* session, tr_torrent* tor, void* vself)
|
|
|
|
{
|
|
|
|
auto* const controller = (__bridge Controller*)(vself);
|
|
|
|
auto const hashstr = @(tr_torrentView(tor).hash_string);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
auto* const torrent = [controller torrentForHash:hashstr];
|
|
|
|
[torrent metadataRetrieved];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool wasRunning, void* vself)
|
|
|
|
{
|
|
|
|
auto* const controller = (__bridge Controller*)(vself);
|
|
|
|
auto const hashstr = @(tr_torrentView(tor).hash_string);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
auto* const torrent = [controller torrentForHash:hashstr];
|
|
|
|
[torrent completenessChange:status wasRunning:wasRunning];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDefaults = NSUserDefaults.standardUserDefaults;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-03-28 17:18:43 +00:00
|
|
|
//checks for old version speeds of -1
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([_fDefaults integerForKey:@"UploadLimit"] < 0)
|
2009-03-28 17:18:43 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fDefaults removeObjectForKey:@"UploadLimit"];
|
|
|
|
[_fDefaults setBool:NO forKey:@"CheckUpload"];
|
2009-03-28 17:18:43 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([_fDefaults integerForKey:@"DownloadLimit"] < 0)
|
2009-03-28 17:18:43 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fDefaults removeObjectForKey:@"DownloadLimit"];
|
|
|
|
[_fDefaults setBool:NO forKey:@"CheckDownload"];
|
2009-03-28 17:18:43 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-27 01:32:46 +00:00
|
|
|
//upgrading from versions < 2.40: clear recent items
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSDocumentController.sharedDocumentController clearRecentDocuments:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant settings;
|
|
|
|
tr_variantInitDict(&settings, 41);
|
2011-03-21 16:28:44 +00:00
|
|
|
tr_sessionGetDefaultSettings(&settings);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const usesSpeedLimitSched = [_fDefaults boolForKey:@"SpeedLimitAuto"];
|
2009-03-29 23:10:36 +00:00
|
|
|
if (!usesSpeedLimitSched)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_alt_speed_enabled, [_fDefaults boolForKey:@"SpeedLimit"]);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_alt_speed_up, [_fDefaults integerForKey:@"SpeedLimitUploadLimit"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_alt_speed_down, [_fDefaults integerForKey:@"SpeedLimitDownloadLimit"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_alt_speed_time_enabled, [_fDefaults boolForKey:@"SpeedLimitAuto"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_alt_speed_time_begin, [PrefsController dateToTimeSum:[_fDefaults objectForKey:@"SpeedLimitAutoOnDate"]]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_alt_speed_time_end, [PrefsController dateToTimeSum:[_fDefaults objectForKey:@"SpeedLimitAutoOffDate"]]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_alt_speed_time_day, [_fDefaults integerForKey:@"SpeedLimitAutoDay"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_speed_limit_down, [_fDefaults integerForKey:@"DownloadLimit"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_speed_limit_down_enabled, [_fDefaults boolForKey:@"CheckDownload"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_speed_limit_up, [_fDefaults integerForKey:@"UploadLimit"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_speed_limit_up_enabled, [_fDefaults boolForKey:@"CheckUpload"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-20 21:59:19 +00:00
|
|
|
//hidden prefs
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([_fDefaults objectForKey:@"BindAddressIPv4"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_bind_address_ipv4, [_fDefaults stringForKey:@"BindAddressIPv4"].UTF8String);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([_fDefaults objectForKey:@"BindAddressIPv6"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_bind_address_ipv6, [_fDefaults stringForKey:@"BindAddressIPv6"].UTF8String);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_blocklist_enabled, [_fDefaults boolForKey:@"BlocklistNew"]);
|
|
|
|
if ([_fDefaults objectForKey:@"BlocklistURL"])
|
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_blocklist_url, [_fDefaults stringForKey:@"BlocklistURL"].UTF8String);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_dht_enabled, [_fDefaults boolForKey:@"DHTGlobal"]);
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_variantDictAddStr(
|
|
|
|
&settings,
|
|
|
|
TR_KEY_download_dir,
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fDefaults stringForKey:@"DownloadFolder"].stringByExpandingTildeInPath.UTF8String);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_download_queue_enabled, [_fDefaults boolForKey:@"Queue"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_download_queue_size, [_fDefaults integerForKey:@"QueueDownloadNumber"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_idle_seeding_limit, [_fDefaults integerForKey:@"IdleLimitMinutes"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_idle_seeding_limit_enabled, [_fDefaults boolForKey:@"IdleLimitCheck"]);
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_variantDictAddStr(
|
|
|
|
&settings,
|
|
|
|
TR_KEY_incomplete_dir,
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fDefaults stringForKey:@"IncompleteDownloadFolder"].stringByExpandingTildeInPath.UTF8String);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_incomplete_dir_enabled, [_fDefaults boolForKey:@"UseIncompleteDownloadFolder"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_lpd_enabled, [_fDefaults boolForKey:@"LocalPeerDiscoveryGlobal"]);
|
2013-01-26 19:17:58 +00:00
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_message_level, TR_LOG_DEBUG);
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_peer_limit_global, [_fDefaults integerForKey:@"PeersTotal"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_peer_limit_per_torrent, [_fDefaults integerForKey:@"PeersTorrent"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const randomPort = [_fDefaults boolForKey:@"RandomPort"];
|
2012-12-23 03:17:18 +00:00
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_peer_port_random_on_start, randomPort);
|
2008-12-14 00:31:33 +00:00
|
|
|
if (!randomPort)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_peer_port, [_fDefaults integerForKey:@"BindPort"]);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-14 00:31:33 +00:00
|
|
|
//hidden pref
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([_fDefaults objectForKey:@"PeerSocketTOS"])
|
|
|
|
{
|
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_peer_socket_tos, [_fDefaults stringForKey:@"PeerSocketTOS"].UTF8String);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_pex_enabled, [_fDefaults boolForKey:@"PEXGlobal"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_port_forwarding_enabled, [_fDefaults boolForKey:@"NatTraversal"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_queue_stalled_enabled, [_fDefaults boolForKey:@"CheckStalled"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_queue_stalled_minutes, [_fDefaults integerForKey:@"StalledMinutes"]);
|
|
|
|
tr_variantDictAddReal(&settings, TR_KEY_ratio_limit, [_fDefaults floatForKey:@"RatioLimit"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_ratio_limit_enabled, [_fDefaults boolForKey:@"RatioCheck"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_rename_partial_files, [_fDefaults boolForKey:@"RenamePartialFiles"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_rpc_authentication_required, [_fDefaults boolForKey:@"RPCAuthorize"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_rpc_enabled, [_fDefaults boolForKey:@"RPC"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_rpc_port, [_fDefaults integerForKey:@"RPCPort"]);
|
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_rpc_username, [_fDefaults stringForKey:@"RPCUsername"].UTF8String);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_rpc_whitelist_enabled, [_fDefaults boolForKey:@"RPCUseWhitelist"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_rpc_host_whitelist_enabled, [_fDefaults boolForKey:@"RPCUseHostWhitelist"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_seed_queue_enabled, [_fDefaults boolForKey:@"QueueSeed"]);
|
|
|
|
tr_variantDictAddInt(&settings, TR_KEY_seed_queue_size, [_fDefaults integerForKey:@"QueueSeedNumber"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_start_added_torrents, [_fDefaults boolForKey:@"AutoStartDownload"]);
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_utp_enabled, [_fDefaults boolForKey:@"UTPGlobal"]);
|
|
|
|
|
|
|
|
tr_variantDictAddBool(&settings, TR_KEY_script_torrent_done_enabled, [_fDefaults boolForKey:@"DoneScriptEnabled"]);
|
|
|
|
NSString* prefs_string = [_fDefaults stringForKey:@"DoneScriptPath"];
|
2021-10-20 22:43:31 +00:00
|
|
|
if (prefs_string != nil)
|
|
|
|
{
|
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_script_torrent_done_filename, prefs_string.UTF8String);
|
|
|
|
}
|
|
|
|
|
2018-01-16 21:46:54 +00:00
|
|
|
// TODO: Add to GUI
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([_fDefaults objectForKey:@"RPCHostWhitelist"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_variantDictAddStr(&settings, TR_KEY_rpc_host_whitelist, [_fDefaults stringForKey:@"RPCHostWhitelist"].UTF8String);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSByteCountFormatter* unitFormatter = [[NSByteCountFormatter alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
unitFormatter.includesCount = NO;
|
|
|
|
unitFormatter.allowsNonnumericFormatting = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
unitFormatter.allowedUnits = NSByteCountFormatterUseKB;
|
2021-08-15 09:41:48 +00:00
|
|
|
// use a random value to avoid possible pluralization issues with 1 or 0 (an example is if we use 1 for bytes,
|
|
|
|
// we'd get "byte" when we'd want "bytes" for the generic libtransmission value at least)
|
|
|
|
NSString* kbString = [unitFormatter stringFromByteCount:17];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
unitFormatter.allowedUnits = NSByteCountFormatterUseMB;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* mbString = [unitFormatter stringFromByteCount:17];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
unitFormatter.allowedUnits = NSByteCountFormatterUseGB;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* gbString = [unitFormatter stringFromByteCount:17];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
unitFormatter.allowedUnits = NSByteCountFormatterUseTB;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* tbString = [unitFormatter stringFromByteCount:17];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_formatter_size_init(1000, kbString.UTF8String, mbString.UTF8String, gbString.UTF8String, tbString.UTF8String);
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_formatter_speed_init(
|
|
|
|
1000,
|
|
|
|
NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)").UTF8String,
|
|
|
|
NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)").UTF8String,
|
|
|
|
NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)").UTF8String,
|
|
|
|
NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)").UTF8String); //why not?
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_formatter_mem_init(1000, kbString.UTF8String, mbString.UTF8String, gbString.UTF8String, tbString.UTF8String);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-08-17 00:28:57 +00:00
|
|
|
auto const default_config_dir = tr_getDefaultConfigDir("Transmission");
|
|
|
|
_fLib = tr_sessionInit(default_config_dir.c_str(), YES, &settings);
|
2022-08-18 01:25:42 +00:00
|
|
|
tr_variantClear(&settings);
|
2022-08-17 00:28:57 +00:00
|
|
|
_fConfigDirectory = @(default_config_dir.c_str());
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 06:04:34 +00:00
|
|
|
tr_sessionSetIdleLimitHitCallback(_fLib, onIdleLimitHit, (__bridge void*)(self));
|
|
|
|
tr_sessionSetQueueStartCallback(_fLib, onStartQueue, (__bridge void*)(self));
|
|
|
|
tr_sessionSetRatioLimitHitCallback(_fLib, onRatioLimitHit, (__bridge void*)(self));
|
|
|
|
tr_sessionSetMetadataCallback(_fLib, onMetadataCompleted, (__bridge void*)(self));
|
|
|
|
tr_sessionSetCompletenessCallback(_fLib, onTorrentCompletenessChanged, (__bridge void*)(self));
|
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSApp.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-01-23 00:36:18 +00:00
|
|
|
//register for magnet URLs (has to be in init)
|
2021-08-15 09:41:48 +00:00
|
|
|
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
|
|
|
|
andSelector:@selector(handleOpenContentsEvent:replyEvent:)
|
|
|
|
forEventClass:kInternetEventClass
|
|
|
|
andEventID:kAEGetURL];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fTorrents = [[NSMutableArray alloc] init];
|
|
|
|
_fDisplayedTorrents = [[NSMutableArray alloc] init];
|
2022-03-02 23:11:04 +00:00
|
|
|
_fTorrentHashes = [[NSMutableDictionary alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fInfoController = [[InfoWindowController alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-01-19 05:03:00 +00:00
|
|
|
//needs to be done before init-ing the prefs controller
|
2021-01-18 02:52:38 +00:00
|
|
|
_fileWatcherQueue = [[VDKQueue alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
_fileWatcherQueue.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_prefsController = [[PrefsController alloc] initWithHandle:_fLib];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fQuitting = NO;
|
|
|
|
_fGlobalPopoverShown = NO;
|
|
|
|
_fSoundPlaying = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionSetAltSpeedFunc(_fLib, altSpeedToggledCallback, (__bridge void*)(self));
|
2009-03-29 23:10:36 +00:00
|
|
|
if (usesSpeedLimitSched)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fDefaults setBool:tr_sessionUsesAltSpeed(_fLib) forKey:@"SpeedLimit"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionSetRPCCallback(_fLib, rpcCallback, (__bridge void*)(self));
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[SUUpdater sharedUpdater].delegate = self;
|
2022-02-22 16:04:20 +00:00
|
|
|
_fQuitRequested = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fPauseOnLaunch = (GetCurrentKeyModifiers() & (optionKey | rightOptionKey)) != 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-06-24 05:26:36 +00:00
|
|
|
Toolbar* toolbar = [[Toolbar alloc] initWithIdentifier:@"TRMainToolbar"];
|
2021-08-07 07:27:56 +00:00
|
|
|
toolbar.delegate = self;
|
|
|
|
toolbar.allowsUserCustomization = YES;
|
|
|
|
toolbar.autosavesConfiguration = YES;
|
|
|
|
toolbar.displayMode = NSToolbarDisplayModeIconOnly;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fWindow.toolbar = toolbar;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-09 07:37:11 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
self.fWindow.toolbarStyle = NSWindowToolbarStyleUnified;
|
|
|
|
self.fWindow.titleVisibility = NSWindowTitleHidden;
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fWindow.delegate = self; //do manually to avoid placement issue
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow makeFirstResponder:self.fTableView];
|
|
|
|
self.fWindow.excludedFromWindowsMenu = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
//make window primary view in fullscreen
|
2022-06-29 04:20:42 +00:00
|
|
|
self.fWindow.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
|
2022-06-16 19:59:54 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set table size
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const small = [self.fDefaults boolForKey:@"SmallView"];
|
2011-06-13 23:02:38 +00:00
|
|
|
if (small)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTableView.rowHeight = ROW_HEIGHT_SMALL;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTableView.usesAlternatingRowBackgroundColors = !small;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow setContentBorderThickness:NSMinY(self.fTableView.enclosingScrollView.frame) forEdge:NSMinYEdge];
|
|
|
|
self.fWindow.movableByWindowBackground = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTotalTorrentsField.cell.backgroundStyle = NSBackgroundStyleRaised;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fActionButton.toolTip = NSLocalizedString(@"Shortcuts for changing global settings.", "Main window -> 1st bottom left button (action) tooltip");
|
|
|
|
self.fSpeedLimitButton.toolTip = NSLocalizedString(
|
2021-08-15 09:41:48 +00:00
|
|
|
@"Speed Limit overrides the total bandwidth limits with its own limits.",
|
2021-08-07 07:27:56 +00:00
|
|
|
"Main window -> 2nd bottom left button (turtle) tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fClearCompletedButton.toolTip = NSLocalizedString(
|
2021-08-15 09:41:48 +00:00
|
|
|
@"Remove all transfers that have completed seeding.",
|
2021-08-07 07:27:56 +00:00
|
|
|
"Main window -> 3rd bottom left button (remove all) tooltip");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView registerForDraggedTypes:@[ TORRENT_TABLE_VIEW_DATA_TYPE ]];
|
|
|
|
[self.fWindow registerForDraggedTypes:@[ NSFilenamesPboardType, NSURLPboardType ]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-30 00:14:43 +00:00
|
|
|
//sort the sort menu items (localization is from strings file)
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* sortMenuItems = [NSMutableArray arrayWithCapacity:7];
|
2012-01-30 00:14:43 +00:00
|
|
|
NSUInteger sortMenuIndex = 0;
|
|
|
|
BOOL foundSortItem = NO;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (NSMenuItem* item in self.fSortMenu.itemArray)
|
2012-01-30 00:14:43 +00:00
|
|
|
{
|
2012-01-31 04:22:51 +00:00
|
|
|
//assume all sort items are together and the Queue Order item is first
|
2021-08-07 07:27:56 +00:00
|
|
|
if (item.action == @selector(setSort:) && item.tag != SORT_ORDER_TAG)
|
2012-01-30 00:14:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[sortMenuItems addObject:item];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fSortMenu removeItemAtIndex:sortMenuIndex];
|
2012-01-30 00:14:43 +00:00
|
|
|
foundSortItem = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (foundSortItem)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-30 00:14:43 +00:00
|
|
|
break;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-30 00:14:43 +00:00
|
|
|
++sortMenuIndex;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[sortMenuItems sortUsingDescriptors:@[ [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES
|
|
|
|
selector:@selector(localizedCompare:)] ]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSMenuItem* item in sortMenuItems)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fSortMenu insertItem:item atIndex:sortMenuIndex++];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
//you would think this would be called later in this method from updateUI, but it's not reached in awakeFromNib
|
|
|
|
//this must be called after showStatusBar:
|
|
|
|
[self.fStatusBar updateWithDownload:0.0 upload:0.0];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//register for sleep notifications
|
|
|
|
IONotificationPortRef notify;
|
|
|
|
io_object_t iterator;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((self.fRootPort = IORegisterForSystemPower((__bridge void*)(self), ¬ify, sleepCallback, &iterator)))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopCommonModes);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
NSLog(@"Could not IORegisterForSystemPower");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-03-30 21:52:23 +00:00
|
|
|
|
2022-03-02 23:11:04 +00:00
|
|
|
auto* const session = self.fLib;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//load previous transfers
|
2022-03-02 23:11:04 +00:00
|
|
|
tr_ctor* ctor = tr_ctorNew(session);
|
|
|
|
tr_ctorSetPaused(ctor, TR_FORCE, true); // paused by default; unpause below after checking state history
|
2022-08-18 14:14:12 +00:00
|
|
|
auto const n_torrents = tr_sessionLoadTorrents(session, ctor);
|
2022-03-02 23:11:04 +00:00
|
|
|
tr_ctorFree(ctor);
|
2022-03-30 21:52:23 +00:00
|
|
|
|
2022-03-02 23:11:04 +00:00
|
|
|
// process the loaded torrents
|
2022-08-18 14:14:12 +00:00
|
|
|
auto torrents = std::vector<tr_torrent*>{};
|
|
|
|
torrents.resize(n_torrents);
|
|
|
|
tr_sessionGetAllTorrents(session, std::data(torrents), std::size(torrents));
|
|
|
|
for (auto* tor : torrents)
|
2022-03-02 23:11:04 +00:00
|
|
|
{
|
|
|
|
NSString* location;
|
|
|
|
if (tr_torrentGetDownloadDir(tor) != NULL)
|
|
|
|
{
|
|
|
|
location = @(tr_torrentGetDownloadDir(tor));
|
|
|
|
}
|
|
|
|
Torrent* torrent = [[Torrent alloc] initWithTorrentStruct:tor location:location lib:self.fLib];
|
|
|
|
[self.fTorrents addObject:torrent];
|
|
|
|
self.fTorrentHashes[torrent.hashString] = torrent;
|
|
|
|
}
|
2022-03-30 21:52:23 +00:00
|
|
|
|
2022-03-02 23:11:04 +00:00
|
|
|
//update previous transfers state by recreating a torrent from history
|
|
|
|
//and comparing to torrents already loaded via tr_sessionLoadTorrents
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* historyFile = [self.fConfigDirectory stringByAppendingPathComponent:TRANSFER_PLIST];
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* history = [NSArray arrayWithContentsOfFile:historyFile];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (!history)
|
|
|
|
{
|
2010-02-09 13:15:52 +00:00
|
|
|
//old version saved transfer info in prefs file
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((history = [self.fDefaults arrayForKey:@"History"]))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults removeObjectForKey:@"History"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (history)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
// theoretical max without doing a lot of work
|
|
|
|
NSMutableArray* waitToStartTorrents = [NSMutableArray
|
2022-02-22 16:04:20 +00:00
|
|
|
arrayWithCapacity:((history.count > 0 && !self.fPauseOnLaunch) ? history.count - 1 : 0)];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
Torrent* t = [[Torrent alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSDictionary* historyItem in history)
|
2008-12-26 07:06:02 +00:00
|
|
|
{
|
2022-03-30 21:52:23 +00:00
|
|
|
NSString* hash = historyItem[@"TorrentHash"];
|
|
|
|
if ([self.fTorrentHashes.allKeys containsObject:hash])
|
|
|
|
{
|
|
|
|
Torrent* torrent = self.fTorrentHashes[hash];
|
2022-03-02 23:11:04 +00:00
|
|
|
[t setResumeStatusForTorrent:torrent withHistory:historyItem forcePause:self.fPauseOnLaunch];
|
2022-03-30 21:52:23 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSNumber* waitToStart;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fPauseOnLaunch && (waitToStart = historyItem[@"WaitToStart"]) && waitToStart.boolValue)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[waitToStartTorrents addObject:torrent];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-12-26 07:06:02 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-02 12:43:26 +00:00
|
|
|
//now that all are loaded, let's set those in the queue to waiting
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in waitToStartTorrents)
|
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
[torrent startTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fBadger = [[Badger alloc] initWithLib:self.fLib];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//observe notifications
|
2021-08-15 09:41:48 +00:00
|
|
|
NSNotificationCenter* nc = NSNotificationCenter.defaultCenter;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(updateUI) name:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(torrentFinishedDownloading:) name:@"TorrentFinishedDownloading" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(torrentRestartedDownloading:) name:@"TorrentRestartedDownloading" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(torrentFinishedSeeding:) name:@"TorrentFinishedSeeding" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(applyFilter) name:kTorrentDidChangeGroupNotification object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//avoids need of setting delegate
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(torrentTableViewSelectionDidChange:)
|
|
|
|
name:NSOutlineViewSelectionDidChangeNotification
|
2022-02-22 16:04:20 +00:00
|
|
|
object:self.fTableView];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(changeAutoImport) name:@"AutoImportSettingChange" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(updateForAutoSize) name:@"AutoSizeSettingChange" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-21 14:28:38 +00:00
|
|
|
[nc addObserver:self selector:@selector(updateForExpandCollapse) name:@"OutlineExpandCollapse" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[nc addObserver:self.fWindow selector:@selector(makeKeyWindow) name:@"MakeWindowKey" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning rename
|
|
|
|
[nc addObserver:self selector:@selector(fullUpdateUI) name:@"UpdateQueue" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
[nc addObserver:self selector:@selector(applyFilter) name:@"ApplyFilter" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//open newly created torrent file
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(beginCreateFile:) name:@"BeginCreateTorrentFile" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//open newly created torrent file
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(openCreatedFile:) name:@"OpenCreatedTorrentFile" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[nc addObserver:self selector:@selector(applyFilter) name:@"UpdateGroups" object:nil];
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-06-24 05:26:36 +00:00
|
|
|
[nc addObserver:self selector:@selector(updateWindowAfterToolbarChange) name:@"ToolbarDidChange" object:nil];
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
[self updateMainWindow];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//timer to update the interface every second
|
|
|
|
[self updateUI];
|
2022-03-30 21:52:23 +00:00
|
|
|
self.fTimer = [NSTimer scheduledTimerWithTimeInterval:UPDATE_UI_SECONDS target:self selector:@selector(updateUI)
|
|
|
|
userInfo:nil
|
|
|
|
repeats:YES];
|
2022-02-22 16:04:20 +00:00
|
|
|
[NSRunLoop.currentRunLoop addTimer:self.fTimer forMode:NSModalPanelRunLoopMode];
|
|
|
|
[NSRunLoop.currentRunLoop addTimer:self.fTimer forMode:NSEventTrackingRunLoopMode];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow makeKeyAndOrderFront:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"InfoVisible"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self showInfo:nil];
|
|
|
|
}
|
2009-08-14 03:14:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification*)notification
|
2009-08-14 03:14:37 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSApp.servicesProvider = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 06:57:20 +00:00
|
|
|
self.fNoNapActivity = [NSProcessInfo.processInfo beginActivityWithOptions:NSActivityUserInitiatedAllowingIdleSystemSleep
|
2022-06-04 23:42:32 +00:00
|
|
|
reason:@"No napping on the job!"];
|
2022-05-14 06:57:20 +00:00
|
|
|
|
2010-01-23 00:05:40 +00:00
|
|
|
//register for dock icon drags (has to be in applicationDidFinishLaunching: to work)
|
2021-08-15 09:41:48 +00:00
|
|
|
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleOpenContentsEvent:replyEvent:)
|
|
|
|
forEventClass:kCoreEventClass
|
|
|
|
andEventID:kAEOpenContents];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-07-25 12:49:11 +00:00
|
|
|
//if we were opened from a user notification, do the corresponding action
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUserNotification* launchNotification = notification.userInfo[NSApplicationLaunchUserNotificationKey];
|
2017-02-05 19:29:20 +00:00
|
|
|
if (launchNotification)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-06-07 19:27:40 +00:00
|
|
|
[self userNotificationCenter:NSUserNotificationCenter.defaultUserNotificationCenter didActivateNotification:launchNotification];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-08-14 03:14:37 +00:00
|
|
|
//auto importing
|
|
|
|
[self checkAutoImportDirectory];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-08-14 03:14:37 +00:00
|
|
|
//registering the Web UI to Bonjour
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"RPC"] && [self.fDefaults boolForKey:@"RPCWebDiscovery"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[BonjourController.defaultController startWithPort:[self.fDefaults integerForKey:@"RPCPort"]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-08-14 01:11:13 +00:00
|
|
|
//shamelessly ask for donations
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"WarningDonate"])
|
2009-08-14 01:11:13 +00:00
|
|
|
{
|
2022-07-28 23:56:40 +00:00
|
|
|
BOOL const firstLaunch = tr_sessionGetCumulativeStats(self.fLib).sessionCount <= 1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSDate* lastDonateDate = [self.fDefaults objectForKey:@"DonateAskDate"];
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const timePassed = !lastDonateDate || (-1 * lastDonateDate.timeIntervalSinceNow) >= DONATE_NAG_TIME;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-08-19 00:38:53 +00:00
|
|
|
if (!firstLaunch && timePassed)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setObject:[NSDate date] forKey:@"DonateAskDate"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"Support open-source indie software", "Donation beg -> title");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* donateMessage = [NSString
|
|
|
|
stringWithFormat:@"%@\n\n%@",
|
|
|
|
NSLocalizedString(
|
|
|
|
@"Transmission is a full-featured torrent application."
|
|
|
|
" A lot of time and effort have gone into development, coding, and refinement."
|
|
|
|
" If you enjoy using it, please consider showing your love with a donation.",
|
|
|
|
"Donation beg -> message"),
|
|
|
|
NSLocalizedString(@"Donate or not, there will be no difference to your torrenting experience.", "Donation beg -> message")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.informativeText = donateMessage;
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleInformational;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:[NSLocalizedString(@"Donate", "Donation beg -> button") stringByAppendingEllipsis]];
|
|
|
|
NSButton* noDonateButton = [alert addButtonWithTitle:NSLocalizedString(@"Nope", "Donation beg -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
noDonateButton.keyEquivalent = @"\e"; //escape key
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
// hide the "don't show again" check the first time - give them time to try the app
|
|
|
|
BOOL const allowNeverAgain = lastDonateDate != nil;
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = allowNeverAgain;
|
2009-08-19 00:38:53 +00:00
|
|
|
if (allowNeverAgain)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.suppressionButton.title = NSLocalizedString(@"Don't bug me about this ever again.", "Donation beg -> button");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const donateResult = [alert runModal];
|
2009-08-19 00:38:53 +00:00
|
|
|
if (donateResult == NSAlertFirstButtonReturn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self linkDonate:self];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-08-19 00:38:53 +00:00
|
|
|
if (allowNeverAgain)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:(alert.suppressionButton.state != NSControlStateValueOn) forKey:@"WarningDonate"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-08-19 00:38:53 +00:00
|
|
|
}
|
2009-08-14 01:11:13 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)applicationShouldHandleReopen:(NSApplication*)app hasVisibleWindows:(BOOL)visibleWindows
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSWindow* mainWindow = NSApp.mainWindow;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!mainWindow || !mainWindow.visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow makeKeyAndOrderFront:nil];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-07-02 21:38:27 +00:00
|
|
|
if (self.fQuitRequested || ![self.fDefaults boolForKey:@"CheckQuit"])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-07-02 21:38:27 +00:00
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSUInteger active = 0, downloading = 0;
|
|
|
|
for (Torrent* torrent in self.fTorrents)
|
|
|
|
{
|
|
|
|
if (torrent.active && !torrent.stalled)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-07-02 21:38:27 +00:00
|
|
|
active++;
|
|
|
|
if (!torrent.allDownloaded)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-07-02 21:38:27 +00:00
|
|
|
downloading++;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-07-02 21:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL preventedByTransfer = [self.fDefaults boolForKey:@"CheckQuitDownloading"] ? downloading > 0 : active > 0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-02 21:38:27 +00:00
|
|
|
if (!preventedByTransfer)
|
|
|
|
{
|
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
alert.alertStyle = NSAlertStyleInformational;
|
|
|
|
alert.messageText = NSLocalizedString(@"Are you sure you want to quit?", "Confirm Quit panel -> title");
|
|
|
|
alert.informativeText = active == 1 ?
|
|
|
|
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 %lu active transfers that will be paused on quit."
|
|
|
|
" The transfers will automatically resume on the next launch.",
|
|
|
|
"Confirm Quit panel -> message"),
|
|
|
|
active];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Quit", "Confirm Quit panel -> button")];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Confirm Quit panel -> button")];
|
|
|
|
alert.showsSuppressionButton = YES;
|
|
|
|
|
|
|
|
[alert beginSheetModalForWindow:self.fWindow completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-07-02 21:38:27 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"CheckQuit"];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2022-07-02 21:38:27 +00:00
|
|
|
[NSApp replyToApplicationShouldTerminate:returnCode == NSAlertFirstButtonReturn];
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-02 21:38:27 +00:00
|
|
|
return NSTerminateLater;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applicationWillTerminate:(NSNotification*)notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fQuitting = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 06:57:20 +00:00
|
|
|
[NSProcessInfo.processInfo endActivity:self.fNoNapActivity];
|
|
|
|
|
2008-12-06 01:18:25 +00:00
|
|
|
//stop the Bonjour service
|
2021-08-07 07:27:56 +00:00
|
|
|
if (BonjourController.defaultControllerExists)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[BonjourController.defaultController stop];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2008-08-31 20:26:41 +00:00
|
|
|
//stop blocklist download
|
2021-08-07 07:27:56 +00:00
|
|
|
if (BlocklistDownloader.isRunning)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-08-31 20:48:10 +00:00
|
|
|
[[BlocklistDownloader downloader] cancelDownload];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-11-02 03:15:12 +00:00
|
|
|
//stop timers and notification checking
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTimer invalidate];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAutoImportTimer)
|
2017-01-24 17:53:16 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAutoImportTimer.valid)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAutoImportTimer invalidate];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-11-02 03:15:12 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//remove all torrent downloads
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fPendingTorrentDownloads)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (NSDictionary* downloadDict in self.fPendingTorrentDownloads)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURLDownload* download = downloadDict[@"Download"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[download cancel];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//remember window states and close all windows
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:self.fInfoController.window.visible forKey:@"InfoVisible"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([QLPreviewPanel sharedPreviewPanelExists] && [QLPreviewPanel sharedPreviewPanel].visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
[[QLPreviewPanel sharedPreviewPanel] updateController];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSWindow* window in NSApp.windows)
|
|
|
|
{
|
2010-01-16 22:57:21 +00:00
|
|
|
[window close];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//save history
|
|
|
|
[self updateTorrentHistory];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView saveCollapsedGroups];
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2021-01-18 02:52:38 +00:00
|
|
|
_fileWatcherQueue = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-11-05 12:47:20 +00:00
|
|
|
//complete cleanup
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionClose(self.fLib);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (tr_session*)sessionHandle
|
2012-05-27 22:31:58 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fLib;
|
2012-05-27 22:31:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)handleOpenContentsEvent:(NSAppleEventDescriptor*)event replyEvent:(NSAppleEventDescriptor*)replyEvent
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* urlString = nil;
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAppleEventDescriptor* directObject = [event paramDescriptorForKeyword:keyDirectObject];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (directObject.descriptorType == typeAEList)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
for (NSInteger i = 1; i <= directObject.numberOfItems; i++)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
if ((urlString = [directObject descriptorAtIndex:i].stringValue))
|
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
urlString = directObject.stringValue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (urlString)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self openURL:urlString];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)download:(NSURLDownload*)download decideDestinationWithSuggestedFilename:(NSString*)suggestedName
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([suggestedName.pathExtension caseInsensitiveCompare:@"torrent"] != NSOrderedSame)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
[download cancel];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPendingTorrentDownloads removeObjectForKey:download.request.URL];
|
|
|
|
if (self.fPendingTorrentDownloads.count == 0)
|
2012-03-13 03:39:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPendingTorrentDownloads = nil;
|
2012-03-13 03:39:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* message = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"It appears that the file \"%@\" from %@ is not a torrent file.", "Download not a torrent -> message"),
|
|
|
|
suggestedName,
|
2022-06-29 04:20:42 +00:00
|
|
|
download.request.URL.absoluteString.stringByRemovingPercentEncoding];
|
2020-09-10 05:42:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Download not a torrent -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"Torrent download failed", "Download not a torrent -> title");
|
|
|
|
alert.informativeText = message;
|
2020-09-10 05:42:53 +00:00
|
|
|
[alert runModal];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[download setDestination:[NSTemporaryDirectory() stringByAppendingPathComponent:suggestedName.lastPathComponent]
|
|
|
|
allowOverwrite:NO];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)download:(NSURLDownload*)download didCreateDestination:(NSString*)path
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableDictionary* dict = self.fPendingTorrentDownloads[download.request.URL];
|
2017-07-08 14:38:47 +00:00
|
|
|
dict[@"Path"] = path;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)download:(NSURLDownload*)download didFailWithError:(NSError*)error
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* message = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"The torrent could not be downloaded from %@: %@.", "Torrent download failed -> message"),
|
2022-06-29 04:20:42 +00:00
|
|
|
download.request.URL.absoluteString.stringByRemovingPercentEncoding,
|
2021-08-15 09:41:48 +00:00
|
|
|
error.localizedDescription];
|
2020-09-10 05:42:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Torrent download failed -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"Torrent download failed", "Torrent download error -> title");
|
|
|
|
alert.informativeText = message;
|
2020-09-10 05:42:53 +00:00
|
|
|
[alert runModal];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPendingTorrentDownloads removeObjectForKey:download.request.URL];
|
|
|
|
if (self.fPendingTorrentDownloads.count == 0)
|
2012-03-13 02:52:11 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPendingTorrentDownloads = nil;
|
2012-03-13 02:52:11 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)downloadDidFinish:(NSURLDownload*)download
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* path = self.fPendingTorrentDownloads[download.request.URL][@"Path"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self openFiles:@[ path ] addType:ADD_URL forcePath:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-27 01:34:49 +00:00
|
|
|
//delete the torrent file after opening
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSFileManager.defaultManager removeItemAtPath:path error:NULL];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPendingTorrentDownloads removeObjectForKey:download.request.URL];
|
|
|
|
if (self.fPendingTorrentDownloads.count == 0)
|
2012-03-13 02:52:11 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPendingTorrentDownloads = nil;
|
2012-03-13 02:52:11 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)application:(NSApplication*)app openFiles:(NSArray*)filenames
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self openFiles:filenames addType:ADD_MANUAL forcePath:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openFiles:(NSArray*)filenames addType:(addType)type forcePath:(NSString*)path
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-07-20 00:40:01 +00:00
|
|
|
BOOL deleteTorrentFile, canToggleDelete = NO;
|
2008-01-05 02:48:10 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case ADD_CREATED:
|
|
|
|
deleteTorrentFile = NO;
|
|
|
|
break;
|
|
|
|
case ADD_URL:
|
|
|
|
deleteTorrentFile = YES;
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-22 16:04:20 +00:00
|
|
|
deleteTorrentFile = [self.fDefaults boolForKey:@"DeleteOriginalTorrent"];
|
2021-08-15 09:41:48 +00:00
|
|
|
canToggleDelete = YES;
|
2008-01-05 02:48:10 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* torrentPath in filenames)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-12-26 03:12:32 +00:00
|
|
|
auto metainfo = tr_torrent_metainfo{};
|
|
|
|
if (!metainfo.parseTorrentFile(torrentPath.UTF8String)) // invalid torrent
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-12-26 03:12:32 +00:00
|
|
|
if (type != ADD_AUTO)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-26 03:12:32 +00:00
|
|
|
[self invalidOpenAlert:torrentPath.lastPathComponent];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-12-26 03:12:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-21 21:47:57 +00:00
|
|
|
auto foundTorrent = tr_torrentFindFromMetainfo(self.fLib, &metainfo);
|
|
|
|
if (foundTorrent != nullptr) // dupe torrent
|
2021-12-26 03:12:32 +00:00
|
|
|
{
|
2022-06-21 21:47:57 +00:00
|
|
|
if (tr_torrentHasMetadata(foundTorrent))
|
|
|
|
{
|
|
|
|
[self duplicateOpenAlert:@(metainfo.name().c_str())];
|
|
|
|
}
|
|
|
|
// foundTorrent is a magnet, fill it with file's metainfo
|
|
|
|
else if (!tr_torrentSetMetainfoFromFile(foundTorrent, &metainfo, torrentPath.UTF8String))
|
|
|
|
{
|
|
|
|
[self duplicateOpenAlert:@(metainfo.name().c_str())];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-08 05:31:20 +00:00
|
|
|
//determine download location
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location;
|
2008-12-13 22:49:46 +00:00
|
|
|
BOOL lockDestination = NO; //don't override the location with a group location if it has a hardcoded path
|
2008-01-08 05:31:20 +00:00
|
|
|
if (path)
|
2008-12-13 22:49:46 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
location = path.stringByExpandingTildeInPath;
|
2008-12-13 22:49:46 +00:00
|
|
|
lockDestination = YES;
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if ([self.fDefaults boolForKey:@"DownloadLocationConstant"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
location = [self.fDefaults stringForKey:@"DownloadFolder"].stringByExpandingTildeInPath;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-08 05:31:20 +00:00
|
|
|
else if (type != ADD_URL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
location = torrentPath.stringByDeletingLastPathComponent;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-08 05:31:20 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-08 05:31:20 +00:00
|
|
|
location = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-14 04:22:24 +00:00
|
|
|
//determine to show the options window
|
2022-01-08 18:53:35 +00:00
|
|
|
auto const is_multifile = metainfo.fileCount() > 1;
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const showWindow = type == ADD_SHOW_OPTIONS ||
|
2022-02-22 16:04:20 +00:00
|
|
|
([self.fDefaults boolForKey:@"DownloadAsk"] && (is_multifile || ![self.fDefaults boolForKey:@"DownloadAskMulti"]) &&
|
|
|
|
(type != ADD_AUTO || ![self.fDefaults boolForKey:@"DownloadAskManual"]));
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent;
|
|
|
|
if (!(torrent = [[Torrent alloc] initWithPath:torrentPath location:location
|
|
|
|
deleteTorrentFile:showWindow ? NO : deleteTorrentFile
|
2022-02-22 16:04:20 +00:00
|
|
|
lib:self.fLib]))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
//change the location if the group calls for it (this has to wait until after the torrent is created)
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!lockDestination && [GroupsController.groups usesCustomDownloadLocationForIndex:torrent.groupValue])
|
2008-12-13 22:49:46 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
location = [GroupsController.groups customDownloadLocationForIndex:torrent.groupValue];
|
|
|
|
[torrent changeDownloadFolderBeforeUsing:location determinationType:TorrentDeterminationAutomatic];
|
2008-12-13 22:49:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-10 01:20:48 +00:00
|
|
|
//verify the data right away if it was newly created
|
|
|
|
if (type == ADD_CREATED)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-10 01:20:48 +00:00
|
|
|
[torrent resetCache];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
AddWindowController* addController = [[AddWindowController alloc] initWithTorrent:torrent destination:location
|
|
|
|
lockDestination:lockDestination
|
|
|
|
controller:self
|
|
|
|
torrentFile:torrentPath
|
|
|
|
deleteTorrentCheckEnableInitially:deleteTorrentFile
|
|
|
|
canToggleDelete:canToggleDelete];
|
|
|
|
[addController showWindow:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddWindows)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddWindows = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddWindows addObject:addController];
|
2008-01-04 06:31:41 +00:00
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"AutoStartDownload"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
[torrent startTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
[torrent update];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddingTransfers)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddingTransfers = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddingTransfers addObject:torrent];
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
[self fullUpdateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)askOpenConfirmed:(AddWindowController*)addController add:(BOOL)add
|
2010-04-12 00:55:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = addController.torrent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-12 00:55:31 +00:00
|
|
|
if (add)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
torrent.queuePosition = self.fTorrents.count;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-12 00:55:31 +00:00
|
|
|
[torrent update];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddingTransfers)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddingTransfers = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddingTransfers addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
[self fullUpdateUI];
|
2010-04-12 00:55:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[torrent closeRemoveTorrent:NO];
|
2010-04-12 00:55:31 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddWindows removeObject:addController];
|
|
|
|
if (self.fAddWindows.count == 0)
|
2012-03-13 03:20:09 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddWindows = nil;
|
2012-03-13 03:20:09 +00:00
|
|
|
}
|
2010-04-12 00:55:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openMagnet:(NSString*)address
|
2009-11-25 04:11:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_torrent* duplicateTorrent;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((duplicateTorrent = tr_torrentFindFromMagnetLink(self.fLib, address.UTF8String)))
|
2010-02-02 01:47:22 +00:00
|
|
|
{
|
2021-12-14 21:59:44 +00:00
|
|
|
NSString* name = @(tr_torrentName(duplicateTorrent));
|
2021-08-15 09:41:48 +00:00
|
|
|
[self duplicateOpenMagnetAlert:address transferName:name];
|
2010-02-02 01:47:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-24 16:50:18 +00:00
|
|
|
//determine download location
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = nil;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"DownloadLocationConstant"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
location = [self.fDefaults stringForKey:@"DownloadFolder"].stringByExpandingTildeInPath;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!(torrent = [[Torrent alloc] initWithMagnetAddress:address location:location lib:self.fLib]))
|
2009-11-25 04:11:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self invalidOpenMagnetAlert:address];
|
2009-11-25 04:11:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-28 17:44:47 +00:00
|
|
|
//change the location if the group calls for it (this has to wait until after the torrent is created)
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([GroupsController.groups usesCustomDownloadLocationForIndex:torrent.groupValue])
|
2009-11-28 17:44:47 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
location = [GroupsController.groups customDownloadLocationForIndex:torrent.groupValue];
|
|
|
|
[torrent changeDownloadFolderBeforeUsing:location determinationType:TorrentDeterminationAutomatic];
|
2009-11-28 17:44:47 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"MagnetOpenAsk"] || !location)
|
2010-04-12 00:55:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
AddMagnetWindowController* addController = [[AddMagnetWindowController alloc] initWithTorrent:torrent destination:location
|
|
|
|
controller:self];
|
|
|
|
[addController showWindow:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddWindows)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddWindows = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddWindows addObject:addController];
|
2010-04-12 00:55:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"AutoStartDownload"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
[torrent startTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-12 00:55:31 +00:00
|
|
|
[torrent update];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddingTransfers)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddingTransfers = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddingTransfers addObject:torrent];
|
2010-04-12 00:55:31 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
[self fullUpdateUI];
|
2009-11-25 04:11:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)askOpenMagnetConfirmed:(AddMagnetWindowController*)addController add:(BOOL)add
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = addController.torrent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-05 21:31:05 +00:00
|
|
|
if (add)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
torrent.queuePosition = self.fTorrents.count;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-05 21:31:05 +00:00
|
|
|
[torrent update];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddingTransfers)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddingTransfers = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddingTransfers addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
[self fullUpdateUI];
|
2008-01-05 21:31:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[torrent closeRemoveTorrent:NO];
|
2008-01-05 21:31:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddWindows removeObject:addController];
|
|
|
|
if (self.fAddWindows.count == 0)
|
2012-03-13 03:20:09 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddWindows = nil;
|
2012-03-13 03:20:09 +00:00
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openCreatedFile:(NSNotification*)notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* dict = notification.userInfo;
|
|
|
|
[self openFiles:@[ dict[@"File"] ] addType:ADD_CREATED forcePath:dict[@"Path"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openFilesWithDict:(NSDictionary*)dictionary
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-09-24 12:56:57 +00:00
|
|
|
[self openFiles:dictionary[@"Filenames"] addType:static_cast<addType>([dictionary[@"AddType"] intValue]) forcePath:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//called on by applescript
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)open:(NSArray*)files
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-06-29 04:20:42 +00:00
|
|
|
NSDictionary* dict = @{ @"Filenames" : files, @"AddType" : @(ADD_MANUAL) };
|
2021-08-15 09:41:48 +00:00
|
|
|
[self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dict waitUntilDone:NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openShowSheet:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.allowsMultipleSelection = YES;
|
|
|
|
panel.canChooseFiles = YES;
|
|
|
|
panel.canChooseDirectories = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
panel.allowedFileTypes = @[ @"org.bittorrent.torrent", @"torrent" ];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[panel beginSheetModalForWindow:self.fWindow completionHandler:^(NSInteger result) {
|
2021-10-31 15:18:27 +00:00
|
|
|
if (result == NSModalResponseOK)
|
2011-12-11 22:31:01 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* filenames = [NSMutableArray arrayWithCapacity:panel.URLs.count];
|
|
|
|
for (NSURL* url in panel.URLs)
|
|
|
|
{
|
|
|
|
[filenames addObject:url.path];
|
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
|
2022-06-29 04:20:42 +00:00
|
|
|
NSDictionary* dictionary = @{
|
|
|
|
@"Filenames" : filenames,
|
|
|
|
@"AddType" : sender == self.fOpenIgnoreDownloadFolder ? @(ADD_SHOW_OPTIONS) : @(ADD_MANUAL)
|
|
|
|
};
|
2021-08-15 09:41:48 +00:00
|
|
|
[self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dictionary waitUntilDone:NO];
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)invalidOpenAlert:(NSString*)filename
|
2008-06-18 16:25:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"WarningInvalidOpen"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-06-18 16:25:30 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
alert.messageText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"\"%@\" is not a valid torrent file.", "Open invalid alert -> title"), filename];
|
|
|
|
alert.informativeText = NSLocalizedString(@"The torrent file cannot be opened because it contains invalid data.", "Open invalid alert -> message");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Open invalid alert -> button")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[alert runModal];
|
2021-10-31 15:18:27 +00:00
|
|
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"WarningInvalidOpen"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-18 16:25:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)invalidOpenMagnetAlert:(NSString*)address
|
2009-12-02 00:27:07 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"WarningInvalidOpen"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-12-02 00:27:07 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"Adding magnetized transfer failed.", "Magnet link failed -> title");
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(
|
|
|
|
@"There was an error when adding the magnet link \"%@\"."
|
|
|
|
" The transfer will not occur.",
|
|
|
|
"Magnet link failed -> message"),
|
|
|
|
address];
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Magnet link failed -> button")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-02 00:27:07 +00:00
|
|
|
[alert runModal];
|
2021-10-31 15:18:27 +00:00
|
|
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"WarningInvalidOpen"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-12-02 00:27:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)duplicateOpenAlert:(NSString*)name
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"WarningDuplicate"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
alert.messageText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"A transfer of \"%@\" already exists.", "Open duplicate alert -> title"), name];
|
|
|
|
alert.informativeText = NSLocalizedString(
|
|
|
|
@"The transfer cannot be added because it is a duplicate of an already existing transfer.",
|
2021-08-07 07:27:56 +00:00
|
|
|
"Open duplicate alert -> message");
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Open duplicate alert -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[alert runModal];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (alert.suppressionButton.state)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"WarningDuplicate"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)duplicateOpenMagnetAlert:(NSString*)address transferName:(NSString*)name
|
2010-02-02 01:47:22 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"WarningDuplicate"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-02-02 01:47:22 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2010-02-02 01:47:22 +00:00
|
|
|
if (name)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
alert.messageText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"A transfer of \"%@\" already exists.", "Open duplicate magnet alert -> title"), name];
|
|
|
|
}
|
2010-02-02 01:47:22 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
alert.messageText = NSLocalizedString(@"Magnet link is a duplicate of an existing transfer.", "Open duplicate magnet alert -> title");
|
|
|
|
}
|
|
|
|
alert.informativeText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(
|
|
|
|
@"The magnet link \"%@\" cannot be added because it is a duplicate of an already existing transfer.",
|
|
|
|
"Open duplicate magnet alert -> message"),
|
|
|
|
address];
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Open duplicate magnet alert -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-02-02 01:47:22 +00:00
|
|
|
[alert runModal];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (alert.suppressionButton.state)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"WarningDuplicate"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-02-02 01:47:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openURL:(NSString*)urlString
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([urlString rangeOfString:@"magnet:" options:(NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
|
|
|
|
{
|
|
|
|
[self openMagnet:urlString];
|
|
|
|
}
|
2009-11-26 16:38:21 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([urlString rangeOfString:@"://"].location == NSNotFound)
|
2009-11-26 16:38:21 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([urlString rangeOfString:@"."].location == NSNotFound)
|
2009-11-26 16:38:21 +00:00
|
|
|
{
|
|
|
|
NSInteger beforeCom;
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((beforeCom = [urlString rangeOfString:@"/"].location) != NSNotFound)
|
|
|
|
{
|
|
|
|
urlString = [NSString stringWithFormat:@"http://www.%@.com/%@",
|
|
|
|
[urlString substringToIndex:beforeCom],
|
|
|
|
[urlString substringFromIndex:beforeCom + 1]];
|
|
|
|
}
|
2009-11-26 16:38:21 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
urlString = [NSString stringWithFormat:@"http://www.%@.com/", urlString];
|
|
|
|
}
|
2009-11-26 16:38:21 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
urlString = [@"http://" stringByAppendingString:urlString];
|
|
|
|
}
|
2009-11-26 16:38:21 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
NSURL* url = [NSURL URLWithString:urlString];
|
2019-04-18 19:28:45 +00:00
|
|
|
if (url == nil)
|
|
|
|
{
|
2019-04-19 08:41:02 +00:00
|
|
|
NSLog(@"Detected non-URL string \"%@\". Ignoring.", urlString);
|
2019-04-18 19:28:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
|
|
|
|
timeoutInterval:60];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fPendingTorrentDownloads[request.URL])
|
2012-03-13 03:39:56 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSLog(@"Already downloading %@", request.URL);
|
2012-03-13 03:39:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURLDownload* download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fPendingTorrentDownloads)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPendingTorrentDownloads = [[NSMutableDictionary alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithObject:download forKey:@"Download"];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPendingTorrentDownloads[request.URL] = dict;
|
2009-11-26 16:38:21 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)openURLShowSheet:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fUrlSheetController)
|
2012-03-13 03:39:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fUrlSheetController = [[URLSheetWindowController alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow beginSheet:self.fUrlSheetController.window completionHandler:^(NSModalResponse returnCode) {
|
2021-01-03 04:29:08 +00:00
|
|
|
if (returnCode == 1)
|
|
|
|
{
|
2022-06-29 04:20:42 +00:00
|
|
|
NSString* urlString = self.fUrlSheetController.urlString;
|
2022-04-16 04:02:25 +00:00
|
|
|
urlString = [urlString stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
2021-01-03 04:29:08 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self openURL:urlString];
|
2021-01-03 04:29:08 +00:00
|
|
|
});
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fUrlSheetController = nil;
|
2021-01-03 04:29:08 +00:00
|
|
|
}];
|
2012-03-13 03:39:56 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)createFile:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[CreatorWindowController createTorrentFile:self.fLib];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resumeSelectedTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self resumeTorrents:self.fTableView.selectedTorrents];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resumeAllTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableArray* torrents = [NSMutableArray arrayWithCapacity:self.fTorrents.count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.finishedSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrents addObject:torrent];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self resumeTorrents:torrents];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resumeTorrents:(NSArray*)torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
[torrent startTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-04 02:03:58 +00:00
|
|
|
[self fullUpdateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resumeSelectedTorrentsNoWait:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self resumeTorrentsNoWait:self.fTableView.selectedTorrents];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resumeWaitingTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableArray* torrents = [NSMutableArray arrayWithCapacity:self.fTorrents.count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrents addObject:torrent];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self resumeTorrentsNoWait:torrents];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)resumeTorrentsNoWait:(NSArray<Torrent*>*)torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//iterate through instead of all at once to ensure no conflicts
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
[torrent startTransferNoQueue];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-04 02:03:58 +00:00
|
|
|
[self fullUpdateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)stopSelectedTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self stopTorrents:self.fTableView.selectedTorrents];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)stopAllTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self stopTorrents:self.fTorrents];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)stopTorrents:(NSArray<Torrent*>*)torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//don't want any of these starting then stopping
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
|
|
|
if (torrent.waitingToStart)
|
|
|
|
{
|
|
|
|
[torrent stopTransfer];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
2011-08-04 00:36:02 +00:00
|
|
|
[torrent stopTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-04 02:03:58 +00:00
|
|
|
[self fullUpdateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)removeTorrents:(NSArray<Torrent*>*)torrents deleteData:(BOOL)deleteData
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"CheckRemove"])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-03-17 01:06:31 +00:00
|
|
|
NSUInteger active = 0, downloading = 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-03-17 01:06:31 +00:00
|
|
|
++active;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.seeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-03-17 01:06:31 +00:00
|
|
|
++downloading;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"CheckRemoveDownloading"] ? downloading > 0 : active > 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString *title, *message;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger const selected = torrents.count;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (selected == 1)
|
|
|
|
{
|
2022-04-29 22:51:40 +00:00
|
|
|
NSString* torrentName = torrents[0].name;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-07-19 19:14:01 +00:00
|
|
|
if (deleteData)
|
2021-08-15 09:41:48 +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
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
title = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"Are you sure you want to remove \"%@\" from the transfer list?", "Removal confirm panel -> title"),
|
|
|
|
torrentName];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
message = NSLocalizedString(
|
|
|
|
@"This transfer is active."
|
|
|
|
" Once removed, continuing the transfer will require the torrent file or magnet link.",
|
|
|
|
"Removal confirm panel -> message");
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-19 19:14:01 +00:00
|
|
|
if (deleteData)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
title = [NSString stringWithFormat:NSLocalizedString(
|
2022-05-14 05:31:24 +00:00
|
|
|
@"Are you sure you want to remove %lu transfers from the transfer list"
|
2021-08-15 09:41:48 +00:00
|
|
|
" and trash the data files?",
|
|
|
|
"Removal confirm panel -> title"),
|
2022-05-14 05:31:24 +00:00
|
|
|
selected];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
title = [NSString stringWithFormat:NSLocalizedString(
|
2022-05-14 05:31:24 +00:00
|
|
|
@"Are you sure you want to remove %lu transfers from the transfer list?",
|
2021-08-15 09:41:48 +00:00
|
|
|
"Removal confirm panel -> title"),
|
2022-05-14 05:31:24 +00:00
|
|
|
selected];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (selected == active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
message = [NSString stringWithFormat:NSLocalizedString(@"There are %lu active transfers.", "Removal confirm panel -> message part 1"),
|
|
|
|
active];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
message = [NSString stringWithFormat:NSLocalizedString(@"There are %1$lu transfers (%2$lu active).", "Removal confirm panel -> message part 1"),
|
|
|
|
selected,
|
|
|
|
active];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
message = [message stringByAppendingFormat:@" %@",
|
|
|
|
NSLocalizedString(
|
|
|
|
@"Once removed, continuing the transfers will require the torrent files or magnet links.",
|
|
|
|
"Removal confirm panel -> message part 2")];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2018-12-26 15:15:33 +00:00
|
|
|
alert.alertStyle = NSAlertStyleInformational;
|
|
|
|
alert.messageText = title;
|
|
|
|
alert.informativeText = message;
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Remove", "Removal confirm panel -> button")];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Removal confirm panel -> button")];
|
2019-02-16 07:50:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[alert beginSheetModalForWindow:self.fWindow completionHandler:^(NSModalResponse returnCode) {
|
2021-08-15 09:41:48 +00:00
|
|
|
if (returnCode == NSAlertFirstButtonReturn)
|
|
|
|
{
|
|
|
|
[self confirmRemoveTorrents:torrents deleteData:deleteData];
|
|
|
|
}
|
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self confirmRemoveTorrents:torrents deleteData:deleteData];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)confirmRemoveTorrents:(NSArray<Torrent*>*)torrents deleteData:(BOOL)deleteData
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
//miscellaneous
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
|
|
|
//don't want any of these starting then stopping
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-06 15:31:19 +00:00
|
|
|
[torrent stopTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//let's expand all groups that have removed items - they either don't exist anymore, are already expanded, or are collapsed (rpc)
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeCollapsedGroup:torrent.groupValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//we can't assume the window is active - RPC removal, for example
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fBadger removeTorrent:torrent];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-11-24 03:34:45 +00:00
|
|
|
//#5106 - don't try to remove torrents that have already been removed (fix for a bug, but better safe than crash anyway)
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexesToRemove = [torrents indexesOfObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
passingTest:^BOOL(Torrent* torrent, NSUInteger idx, BOOL* stop) {
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.fTorrents indexOfObjectIdenticalTo:torrent] != NSNotFound;
|
2021-08-15 09:41:48 +00:00
|
|
|
}];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrents.count != indexesToRemove.count)
|
2012-11-24 03:34:45 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSLog(
|
|
|
|
@"trying to remove %ld transfers, but %ld have already been removed",
|
|
|
|
torrents.count,
|
|
|
|
torrents.count - indexesToRemove.count);
|
|
|
|
torrents = [torrents objectsAtIndexes:indexesToRemove];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (indexesToRemove.count == 0)
|
2012-11-24 03:34:45 +00:00
|
|
|
{
|
|
|
|
[self fullUpdateUI];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents removeObjectsInArray:torrents];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//set up helpers to remove from the table
|
|
|
|
__block BOOL beganUpdate = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
void (^doTableRemoval)(NSMutableArray*, id) = ^(NSMutableArray* displayedTorrents, id parent) {
|
|
|
|
NSIndexSet* indexes = [displayedTorrents indexesOfObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
passingTest:^(id obj, NSUInteger idx, BOOL* stop) {
|
|
|
|
return [torrents containsObject:obj];
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (indexes.count > 0)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
if (!beganUpdate)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
[NSAnimationContext beginGrouping]; //this has to be before we set the completion handler (#4874)
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
//we can't closeRemoveTorrent: until it's no longer in the GUI at all
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAnimationContext.currentContext.completionHandler = ^{
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
|
|
|
[torrent closeRemoveTorrent:deleteData];
|
|
|
|
}
|
2022-06-16 19:59:54 +00:00
|
|
|
|
|
|
|
[self fullUpdateUI];
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2016-01-06 11:05:37 +00:00
|
|
|
beganUpdate = YES;
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeItemsAtIndexes:indexes inParent:parent withAnimation:NSTableViewAnimationSlideLeft];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[displayedTorrents removeObjectsAtIndexes:indexes];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
|
|
|
};
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//if not removed from the displayed torrents here, fullUpdateUI might cause a crash
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fDisplayedTorrents.count > 0)
|
2009-12-14 23:35:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDisplayedTorrents[0] isKindOfClass:[TorrentGroup class]])
|
2009-12-14 23:35:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (TorrentGroup* group in self.fDisplayedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
doTableRemoval(group.torrents, group);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-12-14 23:35:55 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
doTableRemoval(self.fDisplayedTorrents, nil);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
if (beganUpdate)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView endUpdates];
|
2012-01-07 15:46:42 +00:00
|
|
|
[NSAnimationContext endGrouping];
|
|
|
|
}
|
2009-12-14 23:35:55 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
if (!beganUpdate)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
//do here if we're not doing it at the end of the animation
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
|
|
|
[torrent closeRemoveTorrent:deleteData];
|
|
|
|
}
|
2022-06-13 14:48:09 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeNoDelete:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self removeTorrents:self.fTableView.selectedTorrents deleteData:NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeDeleteData:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self removeTorrents:self.fTableView.selectedTorrents deleteData:YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)clearCompleted:(id)sender
|
2011-02-13 02:02:13 +00:00
|
|
|
{
|
2022-04-29 22:51:40 +00:00
|
|
|
NSMutableArray<Torrent*>* torrents = [NSMutableArray array];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.finishedSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrents addObject:torrent];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"WarningRemoveCompleted"])
|
2011-03-17 01:06:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString *message, *info;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrents.count == 1)
|
2011-03-17 01:06:31 +00:00
|
|
|
{
|
2022-04-29 22:51:40 +00:00
|
|
|
NSString* torrentName = torrents[0].name;
|
2021-08-15 09:41:48 +00:00
|
|
|
message = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"Are you sure you want to remove \"%@\" from the transfer list?", "Remove completed confirm panel -> title"),
|
|
|
|
torrentName];
|
|
|
|
|
|
|
|
info = NSLocalizedString(
|
|
|
|
@"Once removed, continuing the transfer will require the torrent file or magnet link.",
|
|
|
|
"Remove completed confirm panel -> message");
|
2011-03-17 01:06:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
message = [NSString stringWithFormat:NSLocalizedString(
|
2022-05-14 05:31:24 +00:00
|
|
|
@"Are you sure you want to remove %lu completed transfers from the transfer list?",
|
2021-08-15 09:41:48 +00:00
|
|
|
"Remove completed confirm panel -> title"),
|
2022-05-14 05:31:24 +00:00
|
|
|
torrents.count];
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
info = NSLocalizedString(
|
|
|
|
@"Once removed, continuing the transfers will require the torrent files or magnet links.",
|
|
|
|
"Remove completed confirm panel -> message");
|
2011-03-17 01:06:31 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = message;
|
|
|
|
alert.informativeText = info;
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Remove", "Remove completed confirm panel -> button")];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Remove completed confirm panel -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const returnCode = [alert runModal];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (alert.suppressionButton.state)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"WarningRemoveCompleted"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-17 01:06:31 +00:00
|
|
|
if (returnCode != NSAlertFirstButtonReturn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-03-17 01:06:31 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-03-17 01:06:31 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self confirmRemoveTorrents:torrents deleteData:NO];
|
2011-02-13 02:02:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)moveDataFilesSelected:(id)sender
|
2008-03-22 17:05:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self moveDataFiles:self.fTableView.selectedTorrents];
|
2008-03-22 17:05:48 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)moveDataFiles:(NSArray<Torrent*>*)torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Move torrent -> prompt");
|
|
|
|
panel.allowsMultipleSelection = NO;
|
|
|
|
panel.canChooseFiles = NO;
|
|
|
|
panel.canChooseDirectories = YES;
|
|
|
|
panel.canCreateDirectories = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
NSUInteger count = torrents.count;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (count == 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
panel.message = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"Select the new folder for \"%@\".", "Move torrent -> select destination folder"),
|
2022-04-29 22:51:40 +00:00
|
|
|
torrents[0].name];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
panel.message = [NSString
|
2022-05-14 05:31:24 +00:00
|
|
|
stringWithFormat:NSLocalizedString(@"Select the new folder for %lu data files.", "Move torrent -> select destination folder"), count];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[panel beginSheetModalForWindow:self.fWindow completionHandler:^(NSInteger result) {
|
2021-10-31 15:18:27 +00:00
|
|
|
if (result == NSModalResponseOK)
|
2011-12-11 22:31:01 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
|
|
|
[torrent moveTorrentDataFileTo:panel.URLs[0].path];
|
|
|
|
}
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)copyTorrentFiles:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self copyTorrentFileForTorrents:[[NSMutableArray alloc] initWithArray:self.fTableView.selectedTorrents]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)copyTorrentFileForTorrents:(NSMutableArray<Torrent*>*)torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrents.count == 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = torrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!torrent.magnet && [NSFileManager.defaultManager fileExistsAtPath:torrent.torrentLocation])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSavePanel* panel = [NSSavePanel savePanel];
|
|
|
|
panel.allowedFileTypes = @[ @"org.bittorrent.torrent", @"torrent" ];
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.extensionHidden = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.nameFieldStringValue = torrent.name;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[panel beginSheetModalForWindow:self.fWindow completionHandler:^(NSInteger result) {
|
2011-12-11 22:31:01 +00:00
|
|
|
//copy torrent to new location with name of data file
|
2021-10-31 15:18:27 +00:00
|
|
|
if (result == NSModalResponseOK)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrent copyTorrentFileTo:panel.URL.path];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[torrents removeObjectAtIndex:0];
|
|
|
|
[self performSelectorOnMainThread:@selector(copyTorrentFileForTorrents:) withObject:torrents waitUntilDone:NO];
|
2011-12-11 22:31:01 +00:00
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2010-01-17 17:57:54 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.magnet)
|
2010-01-17 17:57:54 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Torrent file copy alert -> button")];
|
|
|
|
alert.messageText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"Copy of \"%@\" Cannot Be Created", "Torrent file copy alert -> title"),
|
|
|
|
torrent.name];
|
|
|
|
alert.informativeText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"The torrent file (%@) cannot be found.", "Torrent file copy alert -> message"),
|
|
|
|
torrent.torrentLocation];
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-01-17 17:57:54 +00:00
|
|
|
[alert runModal];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[torrents removeObjectAtIndex:0];
|
|
|
|
[self copyTorrentFileForTorrents:torrents];
|
2010-01-17 17:57:54 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)copyMagnetLinks:(id)sender
|
2009-12-04 13:35:15 +00:00
|
|
|
{
|
2022-05-16 17:08:20 +00:00
|
|
|
[self.fTableView copy:sender];
|
2009-12-04 13:35:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)revealFile:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* selected = self.fTableView.selectedTorrents;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* paths = [NSMutableArray arrayWithCapacity:selected.count];
|
|
|
|
for (Torrent* torrent in selected)
|
2009-08-30 17:50:05 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = torrent.dataLocation;
|
2011-10-06 00:30:40 +00:00
|
|
|
if (location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[paths addObject:[NSURL fileURLWithPath:location]];
|
|
|
|
}
|
2009-08-30 17:50:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (paths.count > 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:paths];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)renameSelected:(id)sender
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* selected = self.fTableView.selectedTorrents;
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAssert(selected.count == 1, @"1 transfer needs to be selected to rename, but %ld are selected", selected.count);
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = selected[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[FileRenameSheetController presentSheetForTorrent:torrent modalForWindow:self.fWindow completionHandler:^(BOOL didRename) {
|
2013-01-22 00:44:58 +00:00
|
|
|
if (didRename)
|
|
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self fullUpdateUI];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ResetInspector" object:self
|
|
|
|
userInfo:@{ @"Torrent" : torrent }];
|
2013-01-22 00:44:58 +00:00
|
|
|
});
|
|
|
|
}
|
2013-01-22 00:09:48 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)announceSelectedTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.canManualAnnounce)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
[torrent manualAnnounce];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)verifySelectedTorrents:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self verifyTorrents:self.fTableView.selectedTorrents];
|
2008-02-27 19:04:38 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)verifyTorrents:(NSArray<Torrent*>*)torrents
|
2008-02-27 19:04:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in torrents)
|
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
[torrent resetCache];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
[self applyFilter];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSArray<Torrent*>*)selectedTorrents
|
2014-01-09 16:23:54 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fTableView.selectedTorrents;
|
2014-01-09 16:23:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showPreferenceWindow:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSWindow* window = _prefsController.window;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!window.visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
[window center];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[window makeKeyAndOrderFront:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showAboutWindow:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[AboutWindowController.aboutController showWindow:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showInfo:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInfoController.window.visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController close];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2009-10-12 00:19:04 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController updateInfoStats];
|
|
|
|
[self.fInfoController.window orderFront:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
if (self.fInfoController.canQuickLook && [QLPreviewPanel sharedPreviewPanelExists] &&
|
|
|
|
[QLPreviewPanel sharedPreviewPanel].visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow.toolbar validateVisibleItems];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resetInfo
|
2008-06-26 03:35:20 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController setInfoForTorrents:self.fTableView.selectedTorrents];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([QLPreviewPanel sharedPreviewPanelExists] && [QLPreviewPanel sharedPreviewPanel].visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-26 03:35:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setInfoTab:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (sender == self.fNextInfoTabItem)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController setNextTab];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController setPreviousTab];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (MessageWindowController*)messageWindowController
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fMessageController)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fMessageController = [[MessageWindowController alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fMessageController;
|
2012-05-27 22:31:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showMessageWindow:(id)sender
|
2012-05-27 22:31:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self.messageWindowController showWindow:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showStatsWindow:(id)sender
|
2007-11-19 18:13:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[StatsWindowController.statsWindow showWindow:nil];
|
2007-11-19 18:13:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateUI
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-01-23 18:23:52 +00:00
|
|
|
CGFloat dlRate = 0.0, ulRate = 0.0;
|
2012-05-23 00:54:58 +00:00
|
|
|
BOOL anyCompleted = NO;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2011-01-23 18:23:52 +00:00
|
|
|
{
|
2011-08-21 16:00:28 +00:00
|
|
|
[torrent update];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-21 16:00:28 +00:00
|
|
|
//pull the upload and download speeds - most consistent by using current stats
|
2021-08-07 07:27:56 +00:00
|
|
|
dlRate += torrent.downloadRate;
|
|
|
|
ulRate += torrent.uploadRate;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
anyCompleted |= torrent.finishedSeeding;
|
2011-01-23 18:23:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!NSApp.hidden)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fWindow.visible)
|
2007-09-26 04:12:57 +00:00
|
|
|
{
|
2022-05-14 19:00:55 +00:00
|
|
|
[self sortTorrentsAndIncludeQueueOrder:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fStatusBar updateWithDownload:dlRate upload:ulRate];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fClearCompletedButton.hidden = !anyCompleted;
|
2007-09-26 04:12:57 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-26 04:12:57 +00:00
|
|
|
//update non-constant parts of info window
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInfoController.window.visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController updateInfoStats];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-26 04:12:57 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//badge dock
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fBadger updateBadgeWithDownload:dlRate upload:ulRate];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 02:03:58 +00:00
|
|
|
#warning can this be removed or refined?
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)fullUpdateUI
|
2011-08-04 02:03:58 +00:00
|
|
|
{
|
|
|
|
[self updateUI];
|
|
|
|
[self applyFilter];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow.toolbar validateVisibleItems];
|
2011-08-04 02:03:58 +00:00
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setBottomCountText:(BOOL)filtering
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* totalTorrentsString;
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger totalCount = self.fTorrents.count;
|
2008-02-06 23:45:44 +00:00
|
|
|
if (totalCount != 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
totalTorrentsString = [NSString stringWithFormat:NSLocalizedString(@"%lu transfers", "Status bar transfer count"), totalCount];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
totalTorrentsString = NSLocalizedString(@"1 transfer", "Status bar transfer count");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
if (filtering)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger count = self.fTableView.numberOfRows; //have to factor in collapsed rows
|
|
|
|
if (count > 0 && ![self.fDisplayedTorrents[0] isKindOfClass:[Torrent class]])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
count -= self.fDisplayedTorrents.count;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
totalTorrentsString = [NSString stringWithFormat:NSLocalizedString(@"%@ of %@", "Status bar transfer count"),
|
|
|
|
[NSString formattedUInteger:count],
|
|
|
|
totalTorrentsString];
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTotalTorrentsField.stringValue = totalTorrentsString;
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center shouldPresentNotification:(NSUserNotification*)notification
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center didActivateNotification:(NSUserNotification*)notification
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!notification.userInfo)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-07-25 12:49:11 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) //reveal
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = [self torrentForHash:notification.userInfo[@"Hash"]];
|
|
|
|
NSString* location = torrent.dataLocation;
|
2012-07-25 12:49:11 +00:00
|
|
|
if (!location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
location = notification.userInfo[@"Location"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-07-25 12:49:11 +00:00
|
|
|
if (location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[ [NSURL fileURLWithPath:location] ]];
|
|
|
|
}
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (notification.activationType == NSUserNotificationActivationTypeContentsClicked)
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = [self torrentForHash:notification.userInfo[@"Hash"]];
|
2022-05-14 19:00:55 +00:00
|
|
|
if (!torrent)
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
2022-05-14 19:00:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//select in the table - first see if it's already shown
|
|
|
|
NSInteger row = [self.fTableView rowForItem:torrent];
|
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
//if it's not shown, see if it's in a collapsed row
|
|
|
|
if ([self.fDefaults boolForKey:@"SortByGroup"])
|
|
|
|
{
|
|
|
|
__block TorrentGroup* parent = nil;
|
|
|
|
[self.fDisplayedTorrents enumerateObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
usingBlock:^(TorrentGroup* group, NSUInteger idx, BOOL* stop) {
|
|
|
|
if ([group.torrents containsObject:torrent])
|
|
|
|
{
|
|
|
|
parent = group;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
[[self.fTableView animator] expandItem:parent];
|
|
|
|
row = [self.fTableView rowForItem:torrent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 12:49:11 +00:00
|
|
|
if (row == -1)
|
|
|
|
{
|
2022-05-14 19:00:55 +00:00
|
|
|
//not found - must be filtering
|
|
|
|
NSAssert([self.fDefaults boolForKey:@"FilterBar"], @"expected the filter to be enabled");
|
|
|
|
[self.fFilterBar reset:YES];
|
|
|
|
|
|
|
|
row = [self.fTableView rowForItem:torrent];
|
|
|
|
|
|
|
|
//if it's not shown, it has to be in a collapsed row...again
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"SortByGroup"])
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
__block TorrentGroup* parent = nil;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents enumerateObjectsWithOptions:NSEnumerationConcurrent
|
2022-03-30 21:52:23 +00:00
|
|
|
usingBlock:^(TorrentGroup* group, NSUInteger idx, BOOL* stop) {
|
|
|
|
if ([group.torrents containsObject:torrent])
|
|
|
|
{
|
|
|
|
parent = group;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
2012-07-25 12:49:11 +00:00
|
|
|
if (parent)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[[self.fTableView animator] expandItem:parent];
|
|
|
|
row = [self.fTableView rowForItem:torrent];
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-14 19:00:55 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 19:00:55 +00:00
|
|
|
NSAssert1(row != -1, @"expected a row to be found for torrent %@", torrent);
|
2016-03-03 17:57:08 +00:00
|
|
|
|
2022-05-14 19:00:55 +00:00
|
|
|
[self showMainWindow:nil];
|
|
|
|
[self.fTableView selectAndScrollToRow:row];
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (Torrent*)torrentForHash:(NSString*)hash
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
|
|
|
NSParameterAssert(hash != nil);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
__block Torrent* torrent = nil;
|
2022-04-29 22:51:40 +00:00
|
|
|
[self.fTorrents enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(Torrent* obj, NSUInteger idx, BOOL* stop) {
|
|
|
|
if ([obj.hashString isEqualToString:hash])
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
|
|
|
torrent = obj;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
return torrent;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)torrentFinishedDownloading:(NSNotification*)notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = notification.object;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([notification.userInfo[@"WasRunning"] boolValue])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fSoundPlaying && [self.fDefaults boolForKey:@"PlayDownloadSound"])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSound* sound;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((sound = [NSSound soundNamed:[self.fDefaults stringForKey:@"DownloadSound"]]))
|
2008-04-14 00:05:16 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
sound.delegate = self;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSoundPlaying = YES;
|
2008-04-14 00:05:16 +00:00
|
|
|
[sound play];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = torrent.dataLocation;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* notificationTitle = NSLocalizedString(@"Download Complete", "notification title");
|
|
|
|
NSUserNotification* notification = [[NSUserNotification alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
notification.title = notificationTitle;
|
|
|
|
notification.informativeText = torrent.name;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
notification.hasActionButton = YES;
|
|
|
|
notification.actionButtonTitle = NSLocalizedString(@"Show", "notification button");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* userInfo = [NSMutableDictionary dictionaryWithObject:torrent.hashString forKey:@"Hash"];
|
2017-02-05 19:29:20 +00:00
|
|
|
if (location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
userInfo[@"Location"] = location;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
notification.userInfo = userInfo;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fWindow.mainWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fBadger addCompletedTorrent:torrent];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-05-09 17:11:21 +00:00
|
|
|
//bounce download stack
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSDistributedNotificationCenter.defaultCenter postNotificationName:@"com.apple.DownloadFileFinished"
|
|
|
|
object:torrent.dataLocation];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-04 02:03:58 +00:00
|
|
|
[self fullUpdateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)torrentRestartedDownloading:(NSNotification*)notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-08-04 02:03:58 +00:00
|
|
|
[self fullUpdateUI];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)torrentFinishedSeeding:(NSNotification*)notification
|
2008-04-14 00:05:16 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = notification.object;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fSoundPlaying && [self.fDefaults boolForKey:@"PlaySeedingSound"])
|
2008-04-14 00:05:16 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSound* sound;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((sound = [NSSound soundNamed:[self.fDefaults stringForKey:@"SeedingSound"]]))
|
2008-04-14 00:05:16 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
sound.delegate = self;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSoundPlaying = YES;
|
2008-04-14 00:05:16 +00:00
|
|
|
[sound play];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = torrent.dataLocation;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* notificationTitle = NSLocalizedString(@"Seeding Complete", "notification title");
|
|
|
|
NSUserNotification* userNotification = [[NSUserNotification alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
userNotification.title = notificationTitle;
|
|
|
|
userNotification.informativeText = torrent.name;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
userNotification.hasActionButton = YES;
|
|
|
|
userNotification.actionButtonTitle = NSLocalizedString(@"Show", "notification button");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* userInfo = [NSMutableDictionary dictionaryWithObject:torrent.hashString forKey:@"Hash"];
|
2017-02-05 19:29:20 +00:00
|
|
|
if (location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
userInfo[@"Location"] = location;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
userNotification.userInfo = userInfo;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:userNotification];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-10-15 02:12:44 +00:00
|
|
|
//removing from the list calls fullUpdateUI
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.removeWhenFinishSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self confirmRemoveTorrents:@[ torrent ] deleteData:NO];
|
|
|
|
}
|
2012-07-07 01:47:12 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fWindow.mainWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fBadger addCompletedTorrent:torrent];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-07-07 01:47:12 +00:00
|
|
|
[self fullUpdateUI];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fTableView.selectedTorrents containsObject:torrent])
|
2012-07-07 01:47:12 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController updateInfoStats];
|
|
|
|
[self.fInfoController updateOptions];
|
2012-07-07 01:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-14 00:05:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateTorrentHistory
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableArray* history = [NSMutableArray arrayWithCapacity:self.fTorrents.count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[history addObject:torrent.history];
|
2022-03-02 23:11:04 +00:00
|
|
|
self.fTorrentHashes[torrent.hashString] = torrent;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* historyFile = [self.fConfigDirectory stringByAppendingPathComponent:TRANSFER_PLIST];
|
2021-08-15 09:41:48 +00:00
|
|
|
[history writeToFile:historyFile atomically:YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSort:(id)sender
|
2008-01-23 17:22:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* sortType;
|
|
|
|
NSMenuItem* senderMenuItem = sender;
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (senderMenuItem.tag)
|
2008-01-23 17:22:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case SORT_ORDER_TAG:
|
|
|
|
sortType = SORT_ORDER;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"SortReverse"];
|
2021-08-15 09:41:48 +00:00
|
|
|
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;
|
|
|
|
case SORT_SIZE_TAG:
|
|
|
|
sortType = SORT_SIZE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown sort tag received: %ld", senderMenuItem.tag);
|
|
|
|
return;
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setObject:sortType forKey:@"Sort"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 19:00:55 +00:00
|
|
|
[self sortTorrentsAndIncludeQueueOrder:YES];
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSortByGroup:(id)sender
|
2008-01-23 17:22:41 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL sortByGroup = ![self.fDefaults boolForKey:@"SortByGroup"];
|
|
|
|
[self.fDefaults setBool:sortByGroup forKey:@"SortByGroup"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
[self applyFilter];
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSortReverse:(id)sender
|
2008-01-23 17:22:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const setReverse = ((NSMenuItem*)sender).tag == SORT_DESC_TAG;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (setReverse != [self.fDefaults boolForKey:@"SortReverse"])
|
2011-01-06 04:09:04 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:setReverse forKey:@"SortReverse"];
|
2022-05-14 19:00:55 +00:00
|
|
|
[self sortTorrentsAndIncludeQueueOrder:NO];
|
2011-01-06 04:09:04 +00:00
|
|
|
}
|
2008-01-23 20:46:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 19:00:55 +00:00
|
|
|
- (void)sortTorrentsAndIncludeQueueOrder:(BOOL)includeQueueOrder
|
2008-01-23 20:46:37 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
//actually sort
|
2021-08-15 09:41:48 +00:00
|
|
|
[self sortTorrentsCallUpdates:YES includeQueueOrder:includeQueueOrder];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTableView.needsDisplay = YES;
|
2008-01-23 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)sortTorrentsCallUpdates:(BOOL)callUpdates includeQueueOrder:(BOOL)includeQueueOrder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const asc = ![self.fDefaults boolForKey:@"SortReverse"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* descriptors;
|
|
|
|
NSSortDescriptor* nameDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:asc
|
|
|
|
selector:@selector(localizedStandardCompare:)];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* sortType = [self.fDefaults stringForKey:@"Sort"];
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([sortType isEqualToString:SORT_STATE])
|
2008-01-31 00:40:37 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* stateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"stateSortKey" ascending:!asc];
|
|
|
|
NSSortDescriptor* progressDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"progress" ascending:!asc];
|
|
|
|
NSSortDescriptor* ratioDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"ratio" ascending:!asc];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ stateDescriptor, progressDescriptor, ratioDescriptor, nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([sortType isEqualToString:SORT_PROGRESS])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* progressDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"progress" ascending:asc];
|
|
|
|
NSSortDescriptor* ratioProgressDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"progressStopRatio" ascending:asc];
|
|
|
|
NSSortDescriptor* ratioDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"ratio" ascending:asc];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ progressDescriptor, ratioProgressDescriptor, ratioDescriptor, nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([sortType isEqualToString:SORT_TRACKER])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* trackerDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"trackerSortKey" ascending:asc
|
|
|
|
selector:@selector(localizedCaseInsensitiveCompare:)];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ trackerDescriptor, nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([sortType isEqualToString:SORT_ACTIVITY])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* rateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"totalRate" ascending:!asc];
|
|
|
|
NSSortDescriptor* activityDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dateActivityOrAdd" ascending:!asc];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ rateDescriptor, activityDescriptor, nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([sortType isEqualToString:SORT_DATE])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dateAdded" ascending:asc];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ dateDescriptor, nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([sortType isEqualToString:SORT_SIZE])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* sizeDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"size" ascending:asc];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ sizeDescriptor, nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([sortType isEqualToString:SORT_NAME])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ nameDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAssert1([sortType isEqualToString:SORT_ORDER], @"Unknown sort type received: %@", sortType);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
if (!includeQueueOrder)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-18 01:40:34 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* orderDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"queuePosition" ascending:asc];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
descriptors = @[ orderDescriptor ];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
BOOL beganTableUpdate = !callUpdates;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-04 05:16:07 +00:00
|
|
|
//actually sort
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"SortByGroup"])
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (TorrentGroup* group in self.fDisplayedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self rearrangeTorrentTableArray:group.torrents forParent:group withSortDescriptors:descriptors
|
|
|
|
beganTableUpdate:&beganTableUpdate];
|
|
|
|
}
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self rearrangeTorrentTableArray:self.fDisplayedTorrents forParent:nil withSortDescriptors:descriptors
|
2021-08-15 09:41:48 +00:00
|
|
|
beganTableUpdate:&beganTableUpdate];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
if (beganTableUpdate && callUpdates)
|
2012-01-04 23:40:23 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView endUpdates];
|
2012-01-04 23:40:23 +00:00
|
|
|
}
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
#warning redo so that we search a copy once again (best explained by changing sorting from ascending to descending)
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rearrangeTorrentTableArray:(NSMutableArray*)rearrangeArray
|
|
|
|
forParent:parent
|
|
|
|
withSortDescriptors:(NSArray*)descriptors
|
|
|
|
beganTableUpdate:(BOOL*)beganTableUpdate
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
for (NSUInteger currentIndex = 1; currentIndex < rearrangeArray.count; ++currentIndex)
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
//manually do the sorting in-place
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger const insertIndex = [rearrangeArray indexOfObject:rearrangeArray[currentIndex]
|
|
|
|
inSortedRange:NSMakeRange(0, currentIndex)
|
|
|
|
options:(NSBinarySearchingInsertionIndex | NSBinarySearchingLastEqual)
|
|
|
|
usingComparator:^NSComparisonResult(id obj1, id obj2) {
|
|
|
|
for (NSSortDescriptor* descriptor in descriptors)
|
|
|
|
{
|
|
|
|
NSComparisonResult const result = [descriptor compareObject:obj1
|
|
|
|
toObject:obj2];
|
|
|
|
if (result != NSOrderedSame)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSOrderedSame;
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
if (insertIndex != currentIndex)
|
2012-01-04 05:16:07 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
if (!*beganTableUpdate)
|
2012-01-04 23:40:23 +00:00
|
|
|
{
|
|
|
|
*beganTableUpdate = YES;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2012-01-04 23:40:23 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[rearrangeArray moveObjectAtIndex:currentIndex toIndex:insertIndex];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView moveItemAtIndex:currentIndex inParent:parent toIndex:insertIndex inParent:parent];
|
2012-01-04 05:16:07 +00:00
|
|
|
}
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAssert2(
|
|
|
|
[rearrangeArray isEqualToArray:[rearrangeArray sortedArrayUsingDescriptors:descriptors]],
|
|
|
|
@"Torrent rearranging didn't work! %@ %@",
|
|
|
|
rearrangeArray,
|
|
|
|
[rearrangeArray sortedArrayUsingDescriptors:descriptors]);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applyFilter
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* filterType = [self.fDefaults stringForKey:@"Filter"];
|
2022-03-07 06:01:01 +00:00
|
|
|
BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterError = NO, filterStatus = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([filterType isEqualToString:FILTER_ACTIVE])
|
|
|
|
{
|
2007-12-20 04:49:06 +00:00
|
|
|
filterActive = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_DOWNLOAD])
|
|
|
|
{
|
2007-12-20 01:06:55 +00:00
|
|
|
filterDownload = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_SEED])
|
|
|
|
{
|
2007-12-20 01:06:55 +00:00
|
|
|
filterSeed = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_PAUSE])
|
|
|
|
{
|
2007-12-20 01:06:55 +00:00
|
|
|
filterPause = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-03-07 06:01:01 +00:00
|
|
|
else if ([filterType isEqualToString:FILTER_ERROR])
|
|
|
|
{
|
|
|
|
filterError = YES;
|
|
|
|
}
|
2007-12-20 01:06:55 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-12-20 01:06:55 +00:00
|
|
|
filterStatus = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger const groupFilterValue = [self.fDefaults integerForKey:@"FilterGroup"];
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const filterGroup = groupFilterValue != GROUP_FILTER_ALL_TAG;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* searchStrings = self.fFilterBar.searchStrings;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (searchStrings && searchStrings.count == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-09-19 00:48:30 +00:00
|
|
|
searchStrings = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const filterTracker = searchStrings && [[self.fDefaults stringForKey:@"FilterSearchType"] isEqualToString:FILTER_TYPE_TRACKER];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
std::atomic<int32_t> active{ 0 }, downloading{ 0 }, seeding{ 0 }, paused{ 0 }, error{ 0 };
|
2021-11-03 06:00:52 +00:00
|
|
|
// Pointers to be captured by Obj-C Block as const*
|
|
|
|
auto* activeRef = &active;
|
|
|
|
auto* downloadingRef = &downloading;
|
|
|
|
auto* seedingRef = &seeding;
|
|
|
|
auto* pausedRef = &paused;
|
2022-03-07 06:01:01 +00:00
|
|
|
auto* errorRef = &error;
|
2012-01-08 19:28:59 +00:00
|
|
|
//filter & get counts of each type
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexesOfNonFilteredTorrents = [self.fTorrents
|
2021-08-15 09:41:48 +00:00
|
|
|
indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(Torrent* torrent, NSUInteger idx, BOOL* stop) {
|
|
|
|
//check status
|
|
|
|
if (torrent.active && !torrent.checkingWaiting)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const isActive = !torrent.stalled;
|
|
|
|
if (isActive)
|
|
|
|
{
|
2021-11-03 06:00:52 +00:00
|
|
|
std::atomic_fetch_add_explicit(activeRef, 1, std::memory_order_relaxed);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (torrent.seeding)
|
|
|
|
{
|
2021-11-03 06:00:52 +00:00
|
|
|
std::atomic_fetch_add_explicit(seedingRef, 1, std::memory_order_relaxed);
|
2021-08-15 09:41:48 +00:00
|
|
|
if (filterStatus && !((filterActive && isActive) || filterSeed))
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-03 06:00:52 +00:00
|
|
|
std::atomic_fetch_add_explicit(downloadingRef, 1, std::memory_order_relaxed);
|
2021-08-15 09:41:48 +00:00
|
|
|
if (filterStatus && !((filterActive && isActive) || filterDownload))
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2022-03-30 21:52:23 +00:00
|
|
|
else if (torrent.error)
|
|
|
|
{
|
2022-03-07 06:01:01 +00:00
|
|
|
std::atomic_fetch_add_explicit(errorRef, 1, std::memory_order_relaxed);
|
|
|
|
if (filterStatus && !filterError)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
2021-11-03 06:00:52 +00:00
|
|
|
std::atomic_fetch_add_explicit(pausedRef, 1, std::memory_order_relaxed);
|
2021-08-15 09:41:48 +00:00
|
|
|
if (filterStatus && !filterPause)
|
|
|
|
{
|
2012-01-08 19:28:59 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
//checkGroup
|
|
|
|
if (filterGroup)
|
|
|
|
if (torrent.groupValue != groupFilterValue)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
//check text field
|
|
|
|
if (searchStrings)
|
2007-10-25 20:14:24 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
__block BOOL removeTextField = NO;
|
|
|
|
if (filterTracker)
|
|
|
|
{
|
|
|
|
NSArray* trackers = torrent.allTrackersFlat;
|
|
|
|
|
|
|
|
//to count, we need each string in at least 1 tracker
|
|
|
|
[searchStrings enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id searchString, NSUInteger idx, BOOL* stop) {
|
|
|
|
__block BOOL found = NO;
|
2022-04-29 22:51:40 +00:00
|
|
|
[trackers enumerateObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
usingBlock:^(NSString* tracker, NSUInteger idx, BOOL* stopTracker) {
|
|
|
|
if ([tracker rangeOfString:searchString
|
|
|
|
options:(NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)]
|
|
|
|
.location != NSNotFound)
|
|
|
|
{
|
|
|
|
found = YES;
|
|
|
|
*stopTracker = YES;
|
|
|
|
}
|
|
|
|
}];
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!found)
|
2011-09-19 00:48:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
removeTextField = YES;
|
|
|
|
*stop = YES;
|
2011-09-19 00:48:30 +00:00
|
|
|
}
|
2012-01-08 05:37:18 +00:00
|
|
|
}];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[searchStrings enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id searchString, NSUInteger idx, BOOL* stop) {
|
|
|
|
if ([torrent.name rangeOfString:searchString options:(NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)]
|
|
|
|
.location == NSNotFound)
|
|
|
|
{
|
|
|
|
removeTextField = YES;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (removeTextField)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return YES;
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
NSArray<Torrent*>* allTorrents = [self.fTorrents objectsAtIndexes:indexesOfNonFilteredTorrents];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-20 01:00:03 +00:00
|
|
|
//set button tooltips
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fFilterBar)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.fFilterBar setCountAll:self.fTorrents.count active:active.load() downloading:downloading.load()
|
2022-02-22 16:04:20 +00:00
|
|
|
seeding:seeding.load()
|
2022-03-07 06:01:01 +00:00
|
|
|
paused:paused.load()
|
|
|
|
error:error.load()];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
//if either the previous or current lists are blank, set its value to the other
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const groupRows = allTorrents.count > 0 ?
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults boolForKey:@"SortByGroup"] :
|
|
|
|
(self.fDisplayedTorrents.count > 0 && [self.fDisplayedTorrents[0] isKindOfClass:[TorrentGroup class]]);
|
|
|
|
BOOL const wasGroupRows = self.fDisplayedTorrents.count > 0 ? [self.fDisplayedTorrents[0] isKindOfClass:[TorrentGroup class]] : groupRows;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning could probably be merged with later code somehow
|
2008-01-23 17:03:42 +00:00
|
|
|
//clear display cache for not-shown torrents
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fDisplayedTorrents.count > 0)
|
2012-01-07 17:08:28 +00:00
|
|
|
{
|
|
|
|
//for each torrent, removes the previous piece info if it's not in allTorrents, and keeps track of which torrents we already found in allTorrents
|
2021-08-15 09:41:48 +00:00
|
|
|
void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL*) = ^(Torrent* torrent, NSUInteger idx, BOOL* stop) {
|
2012-01-08 19:58:58 +00:00
|
|
|
//we used to keep track of which torrents we already found in allTorrents, but it wasn't safe fo concurrent enumeration
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![allTorrents containsObject:torrent])
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.previousFinishedPieces = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-07 17:08:28 +00:00
|
|
|
};
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
if (wasGroupRows)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id obj, NSUInteger idx, BOOL* stop) {
|
2021-08-15 09:41:48 +00:00
|
|
|
[((TorrentGroup*)obj).torrents enumerateObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
usingBlock:removePreviousFinishedPieces];
|
2012-01-07 17:40:18 +00:00
|
|
|
}];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-07 17:08:28 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:removePreviousFinishedPieces];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-07 17:08:28 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
BOOL beganUpdates = NO;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
//don't animate torrents when first launching
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAnimationContext.currentContext.duration = 0;
|
2016-01-06 11:05:37 +00:00
|
|
|
});
|
|
|
|
[NSAnimationContext beginGrouping];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
//add/remove torrents (and rearrange for groups), one by one
|
2012-01-07 15:46:42 +00:00
|
|
|
if (!groupRows && !wasGroupRows)
|
2008-01-23 20:31:04 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* addIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
NSMutableIndexSet* removePreviousIndexes = [NSMutableIndexSet
|
2022-02-22 16:04:20 +00:00
|
|
|
indexSetWithIndexesInRange:NSMakeRange(0, self.fDisplayedTorrents.count)];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 18:46:03 +00:00
|
|
|
//for each of the torrents to add, find if it already exists (and keep track of those we've already added & those we need to remove)
|
2021-08-15 09:41:48 +00:00
|
|
|
[allTorrents enumerateObjectsWithOptions:0 usingBlock:^(id objAll, NSUInteger previousIndex, BOOL* stop) {
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger const currentIndex = [self.fDisplayedTorrents indexOfObjectAtIndexes:removePreviousIndexes
|
2022-03-30 21:52:23 +00:00
|
|
|
options:NSEnumerationConcurrent
|
|
|
|
passingTest:^(id objDisplay, NSUInteger idx, BOOL* stop) {
|
|
|
|
return (BOOL)(objAll == objDisplay);
|
|
|
|
}];
|
2012-01-07 15:46:42 +00:00
|
|
|
if (currentIndex == NSNotFound)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[addIndexes addIndex:previousIndex];
|
|
|
|
}
|
2012-01-07 15:46:42 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[removePreviousIndexes removeIndex:currentIndex];
|
|
|
|
}
|
2012-01-07 18:46:03 +00:00
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (addIndexes.count > 0 || removePreviousIndexes.count > 0)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
|
|
|
beganUpdates = YES;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//remove torrents we didn't find
|
2021-08-07 07:27:56 +00:00
|
|
|
if (removePreviousIndexes.count > 0)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents removeObjectsAtIndexes:removePreviousIndexes];
|
|
|
|
[self.fTableView removeItemsAtIndexes:removePreviousIndexes inParent:nil withAnimation:NSTableViewAnimationSlideDown];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//add new torrents
|
2021-08-07 07:27:56 +00:00
|
|
|
if (addIndexes.count > 0)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2012-01-08 00:51:05 +00:00
|
|
|
//slide new torrents in differently
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAddingTransfers)
|
2012-01-08 00:51:05 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* newAddIndexes = [allTorrents indexesOfObjectsAtIndexes:addIndexes options:NSEnumerationConcurrent
|
2022-04-29 22:51:40 +00:00
|
|
|
passingTest:^BOOL(Torrent* obj, NSUInteger idx, BOOL* stop) {
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.fAddingTransfers containsObject:obj];
|
2021-08-15 09:41:48 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
[addIndexes removeIndexes:newAddIndexes];
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents addObjectsFromArray:[allTorrents objectsAtIndexes:newAddIndexes]];
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.fTableView insertItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(
|
|
|
|
self.fDisplayedTorrents.count -
|
|
|
|
newAddIndexes.count,
|
|
|
|
newAddIndexes.count)]
|
|
|
|
inParent:nil
|
|
|
|
withAnimation:NSTableViewAnimationSlideLeft];
|
2012-01-08 00:51:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents addObjectsFromArray:[allTorrents objectsAtIndexes:addIndexes]];
|
|
|
|
[self.fTableView
|
2021-08-15 09:41:48 +00:00
|
|
|
insertItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDisplayedTorrents.count - addIndexes.count,
|
2021-08-15 09:41:48 +00:00
|
|
|
addIndexes.count)]
|
|
|
|
inParent:nil
|
|
|
|
withAnimation:NSTableViewAnimationSlideDown];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 23:59:57 +00:00
|
|
|
else if (groupRows && wasGroupRows)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
|
|
|
NSAssert(groupRows && wasGroupRows, @"Should have had group rows and should remain with group rows");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning don't always do?
|
2012-01-07 15:46:42 +00:00
|
|
|
beganUpdates = YES;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* unusedAllTorrentsIndexes = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, allTorrents.count)];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableDictionary* groupsByIndex = [NSMutableDictionary dictionaryWithCapacity:self.fDisplayedTorrents.count];
|
|
|
|
for (TorrentGroup* group in self.fDisplayedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
groupsByIndex[@(group.groupIndex)] = group;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger const originalGroupCount = self.fDisplayedTorrents.count;
|
2012-01-07 15:46:42 +00:00
|
|
|
for (NSUInteger index = 0; index < originalGroupCount; ++index)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
TorrentGroup* group = self.fDisplayedTorrents[index];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* removeIndexes = [NSMutableIndexSet indexSet];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//needs to be a signed integer
|
2021-08-07 07:27:56 +00:00
|
|
|
for (NSUInteger indexInGroup = 0; indexInGroup < group.torrents.count; ++indexInGroup)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = group.torrents[indexInGroup];
|
|
|
|
NSUInteger const allIndex = [allTorrents indexOfObjectAtIndexes:unusedAllTorrentsIndexes options:NSEnumerationConcurrent
|
|
|
|
passingTest:^(id obj, NSUInteger idx, BOOL* stop) {
|
|
|
|
return (BOOL)(obj == torrent);
|
|
|
|
}];
|
2012-01-07 15:46:42 +00:00
|
|
|
if (allIndex == NSNotFound)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[removeIndexes addIndex:indexInGroup];
|
|
|
|
}
|
2012-01-07 15:46:42 +00:00
|
|
|
else
|
2008-12-26 00:16:19 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
BOOL markTorrentAsUsed = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupValue = torrent.groupValue;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (groupValue != group.groupIndex)
|
2008-12-26 00:16:19 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* newGroup = groupsByIndex[@(groupValue)];
|
2012-01-07 15:46:42 +00:00
|
|
|
if (!newGroup)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
newGroup = [[TorrentGroup alloc] initWithGroup:groupValue];
|
2017-07-08 14:38:47 +00:00
|
|
|
groupsByIndex[@(groupValue)] = newGroup;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents addObject:newGroup];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.fTableView insertItemsAtIndexes:[NSIndexSet indexSetWithIndex:self.fDisplayedTorrents.count - 1]
|
|
|
|
inParent:nil
|
|
|
|
withAnimation:NSTableViewAnimationEffectFade];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView isGroupCollapsed:groupValue] ? [self.fTableView collapseItem:newGroup] :
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.fTableView expandItem:newGroup];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
|
|
|
else //if we haven't processed the other group yet, we have to make sure we don't flag it for removal the next time
|
|
|
|
{
|
|
|
|
//ugggh, but shouldn't happen too often
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDisplayedTorrents indexOfObject:newGroup
|
2022-03-30 21:52:23 +00:00
|
|
|
inRange:NSMakeRange(index + 1, originalGroupCount - (index + 1))] != NSNotFound)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-07 15:46:42 +00:00
|
|
|
markTorrentAsUsed = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[group.torrents removeObjectAtIndex:indexInGroup];
|
|
|
|
[newGroup.torrents addObject:torrent];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView moveItemAtIndex:indexInGroup inParent:group toIndex:newGroup.torrents.count - 1
|
2022-03-30 21:52:23 +00:00
|
|
|
inParent:newGroup];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
--indexInGroup;
|
2008-12-26 00:16:19 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
if (markTorrentAsUsed)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[unusedAllTorrentsIndexes removeIndex:allIndex];
|
|
|
|
}
|
2008-12-26 00:16:19 +00:00
|
|
|
}
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (removeIndexes.count > 0)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[group.torrents removeObjectsAtIndexes:removeIndexes];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeItemsAtIndexes:removeIndexes inParent:group withAnimation:NSTableViewAnimationEffectFade];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//add remaining new torrents
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in [allTorrents objectsAtIndexes:unusedAllTorrentsIndexes])
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupValue = torrent.groupValue;
|
|
|
|
TorrentGroup* group = groupsByIndex[@(groupValue)];
|
2012-01-07 15:46:42 +00:00
|
|
|
if (!group)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
group = [[TorrentGroup alloc] initWithGroup:groupValue];
|
2017-07-08 14:38:47 +00:00
|
|
|
groupsByIndex[@(groupValue)] = group;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents addObject:group];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView insertItemsAtIndexes:[NSIndexSet indexSetWithIndex:self.fDisplayedTorrents.count - 1] inParent:nil
|
2022-03-30 21:52:23 +00:00
|
|
|
withAnimation:NSTableViewAnimationEffectFade];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView isGroupCollapsed:groupValue] ? [self.fTableView collapseItem:group] : [self.fTableView expandItem:group];
|
2008-01-23 20:31:04 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[group.torrents addObject:torrent];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const newTorrent = self.fAddingTransfers && [self.fAddingTransfers containsObject:torrent];
|
|
|
|
[self.fTableView insertItemsAtIndexes:[NSIndexSet indexSetWithIndex:group.torrents.count - 1] inParent:group
|
2022-03-30 21:52:23 +00:00
|
|
|
withAnimation:newTorrent ? NSTableViewAnimationSlideLeft : NSTableViewAnimationSlideDown];
|
2012-01-07 15:46:42 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//remove empty groups
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* removeGroupIndexes = [self.fDisplayedTorrents
|
2021-08-15 09:41:48 +00:00
|
|
|
indexesOfObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, originalGroupCount)]
|
|
|
|
options:NSEnumerationConcurrent passingTest:^BOOL(id obj, NSUInteger idx, BOOL* stop) {
|
|
|
|
return ((TorrentGroup*)obj).torrents.count == 0;
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (removeGroupIndexes.count > 0)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents removeObjectsAtIndexes:removeGroupIndexes];
|
|
|
|
[self.fTableView removeItemsAtIndexes:removeGroupIndexes inParent:nil withAnimation:NSTableViewAnimationEffectFade];
|
2008-01-23 20:31:04 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//now that all groups are there, sort them - don't insert on the fly in case groups were reordered in prefs
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* groupDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"groupOrderValue" ascending:YES];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self rearrangeTorrentTableArray:self.fDisplayedTorrents forParent:nil withSortDescriptors:@[ groupDescriptor ]
|
2021-08-15 09:41:48 +00:00
|
|
|
beganTableUpdate:&beganUpdates];
|
2008-01-23 20:31:04 +00:00
|
|
|
}
|
2012-01-09 23:59:57 +00:00
|
|
|
else
|
|
|
|
{
|
2012-01-12 00:12:17 +00:00
|
|
|
NSAssert(groupRows != wasGroupRows, @"Trying toggling group-torrent reordering when we weren't expecting to.");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-14 20:07:26 +00:00
|
|
|
//set all groups as expanded
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeAllCollapsedGroups];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
//since we're not doing this the right way (boo buggy animation), we need to remember selected values
|
|
|
|
#warning when Lion-only and using views instead of cells, this likely won't be needed
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* selectedValues = self.fTableView.selectedValues;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-09 23:59:57 +00:00
|
|
|
beganUpdates = YES;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fDisplayedTorrents.count)]
|
2022-03-30 21:52:23 +00:00
|
|
|
inParent:nil
|
|
|
|
withAnimation:NSTableViewAnimationSlideDown];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-09 23:59:57 +00:00
|
|
|
if (groupRows)
|
|
|
|
{
|
|
|
|
//a map for quickly finding groups
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* groupsByIndex = [NSMutableDictionary dictionaryWithCapacity:GroupsController.groups.numberOfGroups];
|
|
|
|
for (Torrent* torrent in allTorrents)
|
2012-01-09 23:59:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupValue = torrent.groupValue;
|
|
|
|
TorrentGroup* group = groupsByIndex[@(groupValue)];
|
2012-01-09 23:59:57 +00:00
|
|
|
if (!group)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
group = [[TorrentGroup alloc] initWithGroup:groupValue];
|
2017-07-08 14:38:47 +00:00
|
|
|
groupsByIndex[@(groupValue)] = group;
|
2012-01-09 23:59:57 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[group.torrents addObject:torrent];
|
2012-01-09 23:59:57 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents setArray:groupsByIndex.allValues];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-09 23:59:57 +00:00
|
|
|
//we need the groups to be sorted, and we can do it without moving items in the table, too!
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* groupDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"groupOrderValue" ascending:YES];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents sortUsingDescriptors:@[ groupDescriptor ]];
|
2012-01-09 23:59:57 +00:00
|
|
|
}
|
|
|
|
else
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDisplayedTorrents setArray:allTorrents];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView insertItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fDisplayedTorrents.count)]
|
|
|
|
inParent:nil
|
|
|
|
withAnimation:NSTableViewAnimationEffectFade];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
|
|
|
if (groupRows)
|
|
|
|
{
|
|
|
|
//actually expand group rows
|
2022-02-22 16:04:20 +00:00
|
|
|
for (TorrentGroup* group in self.fDisplayedTorrents)
|
|
|
|
[self.fTableView expandItem:group];
|
2017-01-24 17:53:16 +00:00
|
|
|
}
|
|
|
|
|
2012-01-14 19:53:08 +00:00
|
|
|
if (selectedValues)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView selectValues:selectedValues];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-09 23:59:57 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//sort the torrents (won't sort the groups, though)
|
2021-08-15 09:41:48 +00:00
|
|
|
[self sortTorrentsCallUpdates:!beganUpdates includeQueueOrder:YES];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
if (beganUpdates)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView endUpdates];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
[NSAnimationContext endGrouping];
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
//reloaddata, otherwise the tableview has a bunch of empty cells
|
|
|
|
[self.fTableView reloadData];
|
|
|
|
|
2009-01-06 02:07:55 +00:00
|
|
|
[self resetInfo]; //if group is already selected, but the torrents in it change
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setBottomCountText:groupRows || filterStatus || filterGroup || searchStrings];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setWindowSizeToFit];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAddingTransfers)
|
2012-01-08 00:51:05 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddingTransfers = nil;
|
2012-01-08 00:51:05 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)switchFilter:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFilterBar switchFilter:sender == self.fNextFilterItem];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)showGlobalPopover:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fGlobalPopoverShown)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPopover* popover = [[NSPopover alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
popover.behavior = NSPopoverBehaviorTransient;
|
2022-02-22 16:04:20 +00:00
|
|
|
GlobalOptionsPopoverViewController* viewController = [[GlobalOptionsPopoverViewController alloc] initWithHandle:self.fLib];
|
2021-08-07 07:27:56 +00:00
|
|
|
popover.contentViewController = viewController;
|
|
|
|
popover.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSView* senderView = sender;
|
2022-06-13 17:26:30 +00:00
|
|
|
CGFloat width = NSWidth(senderView.frame);
|
|
|
|
|
|
|
|
if (NSMinX(self.fWindow.frame) < width || NSMaxX(self.fWindow.screen.frame) - NSMinX(self.fWindow.frame) < width * 2)
|
|
|
|
{
|
|
|
|
// Ugly hack to hide NSPopover arrow.
|
|
|
|
self.fPositioningView = [[NSView alloc] initWithFrame:senderView.bounds];
|
|
|
|
self.fPositioningView.identifier = @"positioningView";
|
|
|
|
[senderView addSubview:self.fPositioningView];
|
|
|
|
[popover showRelativeToRect:self.fPositioningView.bounds ofView:self.fPositioningView preferredEdge:NSMaxYEdge];
|
|
|
|
self.fPositioningView.bounds = NSOffsetRect(self.fPositioningView.bounds, 0, NSHeight(self.fPositioningView.bounds));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[popover showRelativeToRect:senderView.frame ofView:senderView preferredEdge:NSMaxYEdge];
|
|
|
|
}
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 03:38:01 +00:00
|
|
|
//don't show multiple popovers when clicking the gear button repeatedly
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)popoverWillShow:(NSNotification*)notification
|
2011-07-27 03:38:01 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fGlobalPopoverShown = YES;
|
2011-07-27 03:38:01 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 17:26:30 +00:00
|
|
|
- (void)popoverDidClose:(NSNotification*)notification
|
2011-07-27 03:38:01 +00:00
|
|
|
{
|
2022-06-13 17:26:30 +00:00
|
|
|
[self.fPositioningView removeFromSuperview];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fGlobalPopoverShown = NO;
|
2011-07-27 03:38:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)menuNeedsUpdate:(NSMenu*)menu
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (menu == self.fGroupsSetMenu || menu == self.fGroupsSetContextMenu)
|
2007-12-17 22:30:28 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSInteger i = menu.numberOfItems - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
[menu removeItemAtIndex:i];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenu* groupMenu = [GroupsController.groups groupMenuWithTarget:self action:@selector(setGroup:) isSmall:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupMenuCount = groupMenu.numberOfItems;
|
2008-12-17 02:13:49 +00:00
|
|
|
for (NSInteger i = 0; i < groupMenuCount; i++)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* item = [groupMenu itemAtIndex:0];
|
|
|
|
[groupMenu removeItemAtIndex:0];
|
|
|
|
[menu addItem:item];
|
2008-12-17 02:13:49 +00:00
|
|
|
}
|
2007-12-19 20:46:00 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (menu == self.fShareMenu || menu == self.fShareContextMenu)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2014-01-10 17:50:05 +00:00
|
|
|
[menu removeAllItems];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSMenuItem* item in ShareTorrentFileHelper.sharedHelper.menuItems)
|
2014-01-10 17:50:05 +00:00
|
|
|
{
|
|
|
|
[menu addItem:item];
|
|
|
|
}
|
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroup:(id)sender
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2008-02-07 15:57:32 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeCollapsedGroup:torrent.groupValue]; //remove old collapsed group
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[torrent setGroupValue:((NSMenuItem*)sender).tag determinationType:TorrentDeterminationUserSpecified];
|
2008-02-07 15:57:32 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
[self applyFilter];
|
2007-12-17 16:06:20 +00:00
|
|
|
[self updateUI];
|
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleSpeedLimit:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:![self.fDefaults boolForKey:@"SpeedLimit"] forKey:@"SpeedLimit"];
|
2021-08-15 09:41:48 +00:00
|
|
|
[self speedLimitChanged:sender];
|
2009-01-02 03:57:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)speedLimitChanged:(id)sender
|
2009-01-02 03:57:28 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionUseAltSpeed(self.fLib, [self.fDefaults boolForKey:@"SpeedLimit"]);
|
|
|
|
[self.fStatusBar updateSpeedFieldsToolTips];
|
2008-06-19 02:53:45 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)altSpeedToggledCallbackIsLimited:(NSDictionary*)dict
|
2008-06-19 02:53:45 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const isLimited = [dict[@"Active"] boolValue];
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:isLimited forKey:@"SpeedLimit"];
|
|
|
|
[self.fStatusBar updateSpeedFieldsToolTips];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![dict[@"ByUser"] boolValue])
|
|
|
|
{
|
|
|
|
NSUserNotification* notification = [[NSUserNotification alloc] init];
|
|
|
|
notification.title = isLimited ? NSLocalizedString(@"Speed Limit Auto Enabled", "notification title") :
|
|
|
|
NSLocalizedString(@"Speed Limit Auto Disabled", "notification title");
|
2017-08-26 12:55:45 +00:00
|
|
|
notification.informativeText = NSLocalizedString(@"Bandwidth settings changed", "notification description");
|
|
|
|
notification.hasActionButton = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
2017-08-26 12:55:45 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)sound:(NSSound*)sound didFinishPlaying:(BOOL)finishedPlaying
|
2008-04-10 16:37:07 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSoundPlaying = NO;
|
2008-04-10 16:37:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)VDKQueue:(VDKQueue*)queue receivedNotification:(NSString*)notification forPath:(NSString*)fpath
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2013-02-08 13:31:38 +00:00
|
|
|
//don't assume that just because we're watching for write notification, we'll only receive write notifications
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"AutoImport"] || ![self.fDefaults stringForKey:@"AutoImportDirectory"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2013-01-19 05:03:00 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAutoImportTimer.valid)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAutoImportTimer invalidate];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-01-19 05:03:00 +00:00
|
|
|
//check again in 10 seconds in case torrent file wasn't complete
|
2022-03-30 21:52:23 +00:00
|
|
|
self.fAutoImportTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self
|
|
|
|
selector:@selector(checkAutoImportDirectory)
|
|
|
|
userInfo:nil
|
|
|
|
repeats:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-01-19 05:03:00 +00:00
|
|
|
[self checkAutoImportDirectory];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)changeAutoImport
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAutoImportTimer.valid)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAutoImportTimer invalidate];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoImportTimer = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoImportedNames = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self checkAutoImportDirectory];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)checkAutoImportDirectory
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"AutoImport"] || !(path = [self.fDefaults stringForKey:@"AutoImportDirectory"]))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
path = path.stringByExpandingTildeInPath;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
NSArray<NSString*>* importedNames;
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!(importedNames = [NSFileManager.defaultManager contentsOfDirectoryAtPath:path error:NULL]))
|
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//only check files that have not been checked yet
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* newNames = [importedNames mutableCopy];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fAutoImportedNames)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[newNames removeObjectsInArray:self.fAutoImportedNames];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoImportedNames = [[NSMutableArray alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAutoImportedNames setArray:importedNames];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* file in newNames)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([file hasPrefix:@"."])
|
|
|
|
{
|
2009-05-23 19:01:57 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* fullFile = [path stringByAppendingPathComponent:file];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!([[NSWorkspace.sharedWorkspace typeOfFile:fullFile error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
|
|
|
|
[fullFile.pathExtension caseInsensitiveCompare:@"torrent"] == NSOrderedSame))
|
|
|
|
{
|
2009-05-23 19:01:57 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-26 03:12:32 +00:00
|
|
|
auto metainfo = tr_torrent_metainfo{};
|
|
|
|
if (!metainfo.parseTorrentFile(fullFile.UTF8String))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-26 03:12:32 +00:00
|
|
|
[self openFiles:@[ fullFile ] addType:ADD_AUTO forcePath:nil];
|
|
|
|
|
|
|
|
NSString* notificationTitle = NSLocalizedString(@"Torrent File Auto Added", "notification title");
|
|
|
|
NSUserNotification* notification = [[NSUserNotification alloc] init];
|
|
|
|
notification.title = notificationTitle;
|
|
|
|
notification.informativeText = file;
|
|
|
|
notification.hasActionButton = NO;
|
|
|
|
|
|
|
|
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)beginCreateFile:(NSNotification*)notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"AutoImport"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString *location = ((NSURL*)notification.object).path, *path = [self.fDefaults stringForKey:@"AutoImportDirectory"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (location && path && [location.stringByDeletingLastPathComponent.stringByExpandingTildeInPath isEqualToString:path.stringByExpandingTildeInPath])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAutoImportedNames addObject:location.lastPathComponent];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return ((TorrentGroup*)item).torrents.count;
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fDisplayedTorrents.count;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return ((TorrentGroup*)item).torrents[index];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fDisplayedTorrents[index];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return ![item isKindOfClass:[Torrent class]];
|
2007-10-27 02:00:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)tableColumn byItem:(id)item
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
2011-06-07 23:40:10 +00:00
|
|
|
if (tableColumn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-06-07 23:40:10 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
return ((Torrent*)item).hashString;
|
2011-06-07 23:40:10 +00:00
|
|
|
}
|
2008-06-05 02:46:39 +00:00
|
|
|
else
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* ident = tableColumn.identifier;
|
|
|
|
TorrentGroup* group = (TorrentGroup*)item;
|
|
|
|
if ([ident isEqualToString:@"Group"])
|
2008-02-18 19:42:46 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger groupIndex = group.groupIndex;
|
2021-08-15 09:41:48 +00:00
|
|
|
return groupIndex != -1 ? [GroupsController.groups nameForIndex:groupIndex] : NSLocalizedString(@"No Group", "Group table row");
|
2008-02-18 19:42:46 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:@"Color"])
|
2008-02-19 05:39:56 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger groupIndex = group.groupIndex;
|
2021-08-15 09:41:48 +00:00
|
|
|
return [GroupsController.groups imageForIndex:groupIndex];
|
|
|
|
}
|
|
|
|
else if ([ident isEqualToString:@"DL Image"])
|
|
|
|
{
|
|
|
|
return [NSImage imageNamed:@"DownArrowGroupTemplate"];
|
|
|
|
}
|
|
|
|
else if ([ident isEqualToString:@"UL Image"])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return [NSImage imageNamed:[self.fDefaults boolForKey:@"DisplayGroupRowRatio"] ? @"YingYangGroupTemplate" : @"UpArrowGroupTemplate"];
|
2008-02-19 05:39:56 +00:00
|
|
|
}
|
2008-02-18 19:42:46 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"DisplayGroupRowRatio"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [NSString stringForRatio:group.ratio];
|
|
|
|
}
|
2008-02-28 02:17:17 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat rate = [ident isEqualToString:@"UL"] ? group.uploadRate : group.downloadRate;
|
|
|
|
return [NSString stringForSpeed:rate];
|
2008-02-28 02:17:17 +00:00
|
|
|
}
|
2008-02-18 19:42:46 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"SortByGroup"] || [[self.fDefaults stringForKey:@"Sort"] isEqualToString:SORT_ORDER])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
|
2008-12-26 07:06:02 +00:00
|
|
|
for (id torrent in items)
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![torrent isKindOfClass:[Torrent class]])
|
|
|
|
{
|
2008-05-11 21:38:40 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[indexSet addIndex:[self.fTableView rowForItem:torrent]];
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[pasteboard declareTypes:@[ TORRENT_TABLE_VIEW_DATA_TYPE ] owner:self];
|
|
|
|
[pasteboard setData:[NSKeyedArchiver archivedDataWithRootObject:indexSet] forType:TORRENT_TABLE_VIEW_DATA_TYPE];
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDragOperation)outlineView:(NSOutlineView*)outlineView
|
|
|
|
validateDrop:(id<NSDraggingInfo>)info
|
|
|
|
proposedItem:(id)item
|
|
|
|
proposedChildIndex:(NSInteger)index
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPasteboard* pasteboard = info.draggingPasteboard;
|
|
|
|
if ([pasteboard.types containsObject:TORRENT_TABLE_VIEW_DATA_TYPE])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"SortByGroup"])
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
|
|
|
if (!item)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-05-11 21:38:40 +00:00
|
|
|
return NSDragOperationNone;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([[self.fDefaults stringForKey:@"Sort"] isEqualToString:SORT_ORDER])
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
2008-05-12 22:38:50 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
TorrentGroup* group = [self.fTableView parentForItem:item];
|
2021-08-15 09:41:48 +00:00
|
|
|
index = [group.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
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
item = [self.fTableView parentForItem:item];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-05-12 22:38:50 +00:00
|
|
|
index = NSOutlineViewDropOnItemIndex;
|
2008-05-12 21:57:37 +00:00
|
|
|
}
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-07 16:01:28 +00:00
|
|
|
if (index == NSOutlineViewDropOnItemIndex)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-07 16:01:28 +00:00
|
|
|
return NSDragOperationNone;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
if (item)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
index = [self.fTableView rowForItem:item] + 1;
|
2008-05-11 21:38:40 +00:00
|
|
|
item = nil;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView setDropItem:item dropChildIndex:index];
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)outlineView:(NSOutlineView*)outlineView acceptDrop:(id<NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)newRow
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPasteboard* pasteboard = info.draggingPasteboard;
|
|
|
|
if ([pasteboard.types containsObject:TORRENT_TABLE_VIEW_DATA_TYPE])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-06-18 14:26:45 +00:00
|
|
|
NSIndexSet* indexes = [NSKeyedUnarchiver unarchivedObjectOfClass:NSIndexSet.class fromData:[pasteboard dataForType:TORRENT_TABLE_VIEW_DATA_TYPE]
|
|
|
|
error:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-02 23:55:10 +00:00
|
|
|
//get the torrents to move
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* movingTorrents = [NSMutableArray arrayWithCapacity:indexes.count];
|
|
|
|
for (NSUInteger i = indexes.firstIndex; i != NSNotFound; i = [indexes indexGreaterThanIndex:i])
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
Torrent* torrent = [self.fTableView itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
[movingTorrents addObject:torrent];
|
2017-07-04 19:59:55 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-04 19:59:55 +00:00
|
|
|
//change groups
|
|
|
|
if (item)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = (TorrentGroup*)item;
|
|
|
|
NSInteger const groupIndex = group.groupIndex;
|
2017-07-04 19:59:55 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in movingTorrents)
|
|
|
|
{
|
|
|
|
[torrent setGroupValue:groupIndex determinationType:TorrentDeterminationUserSpecified];
|
|
|
|
}
|
2008-05-12 21:38:24 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = (TorrentGroup*)item;
|
2008-05-12 21:57:37 +00:00
|
|
|
//find torrent to place under
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* groupTorrents = group ? group.torrents : self.fDisplayedTorrents;
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* topTorrent = nil;
|
|
|
|
for (NSInteger i = newRow - 1; i >= 0; i--)
|
2008-05-12 21:57:37 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* tempTorrent = groupTorrents[i];
|
|
|
|
if (![movingTorrents containsObject:tempTorrent])
|
2008-05-12 21:57:37 +00:00
|
|
|
{
|
|
|
|
topTorrent = tempTorrent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-12 21:57:37 +00:00
|
|
|
//remove objects to reinsert
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents removeObjectsInArray:movingTorrents];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-12 21:57:37 +00:00
|
|
|
//insert objects at new location
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger const insertIndex = topTorrent ? [self.fTorrents indexOfObject:topTorrent] + 1 : 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* insertIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(insertIndex, movingTorrents.count)];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents insertObjects:movingTorrents atIndexes:insertIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 15:46:42 +00:00
|
|
|
//we need to make sure the queue order is updated in the Torrent object before we sort - safest to just reset all queue positions
|
|
|
|
NSUInteger i = 0;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2012-01-07 15:46:42 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.queuePosition = i++;
|
2012-01-07 15:46:42 +00:00
|
|
|
[torrent update];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 21:05:02 +00:00
|
|
|
//do the drag animation here so that the dragged torrents are the ones that are animated as moving, and not the torrents around them
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger insertDisplayIndex = topTorrent ? [groupTorrents indexOfObject:topTorrent] + 1 : 0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in movingTorrents)
|
2012-01-07 21:05:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
TorrentGroup* oldParent = item ? [self.fTableView parentForItem:torrent] : nil;
|
|
|
|
NSMutableArray* oldTorrents = oldParent ? oldParent.torrents : self.fDisplayedTorrents;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger const oldIndex = [oldTorrents indexOfObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 21:05:02 +00:00
|
|
|
if (item == oldParent)
|
|
|
|
{
|
|
|
|
if (oldIndex < insertDisplayIndex)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-07 21:05:02 +00:00
|
|
|
--insertDisplayIndex;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
[oldTorrents moveObjectAtIndex:oldIndex toIndex:insertDisplayIndex];
|
2012-01-07 21:05:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-07 22:06:23 +00:00
|
|
|
NSAssert(item && oldParent, @"Expected to be dragging between group rows");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* newTorrents = ((TorrentGroup*)item).torrents;
|
|
|
|
[newTorrents insertObject:torrent atIndex:insertDisplayIndex];
|
|
|
|
[oldTorrents removeObjectAtIndex:oldIndex];
|
2012-01-07 21:05:02 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView moveItemAtIndex:oldIndex inParent:oldParent toIndex:insertDisplayIndex inParent:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-07 21:05:02 +00:00
|
|
|
++insertDisplayIndex;
|
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView endUpdates];
|
2008-05-12 21:57:37 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
[self applyFilter];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)torrentTableViewSelectionDidChange:(NSNotification*)notification
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-06-26 03:35:20 +00:00
|
|
|
[self resetInfo];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow.toolbar validateVisibleItems];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPasteboard* pasteboard = info.draggingPasteboard;
|
|
|
|
if ([pasteboard.types containsObject:NSFilenamesPboardType])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//check if any torrent files can be added
|
|
|
|
BOOL torrent = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
for (NSString* file in files)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([[NSWorkspace.sharedWorkspace typeOfFile:file error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
|
|
|
|
[file.pathExtension caseInsensitiveCompare:@"torrent"] == NSOrderedSame)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-05-25 21:07:12 +00:00
|
|
|
torrent = YES;
|
2021-12-26 03:12:32 +00:00
|
|
|
auto metainfo = tr_torrent_metainfo{};
|
|
|
|
if (metainfo.parseTorrentFile(file.UTF8String))
|
2007-11-13 00:56:58 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fOverlayWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOverlayWindow = [[DragOverlayWindow alloc] initWithLib:self.fLib forWindow:self.fWindow];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOverlayWindow setTorrents:files];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-05-25 21:07:12 +00:00
|
|
|
return NSDragOperationCopy;
|
2007-11-13 00:56:58 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//create a torrent file if a single file
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent && files.count == 1)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fOverlayWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOverlayWindow = [[DragOverlayWindow alloc] initWithLib:self.fLib forWindow:self.fWindow];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOverlayWindow setFile:[files[0] lastPathComponent]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([pasteboard.types containsObject:NSURLPboardType])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fOverlayWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOverlayWindow = [[DragOverlayWindow alloc] initWithLib:self.fLib forWindow:self.fWindow];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOverlayWindow setURL:[NSURL URLFromPasteboard:pasteboard].relativeString];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)draggingExited:(id<NSDraggingInfo>)info
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fOverlayWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOverlayWindow fadeOut];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)performDragOperation:(id<NSDraggingInfo>)info
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fOverlayWindow)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOverlayWindow fadeOut];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPasteboard* pasteboard = info.draggingPasteboard;
|
|
|
|
if ([pasteboard.types containsObject:NSFilenamesPboardType])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
BOOL torrent = NO, accept = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//create an array of files that can be opened
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
NSMutableArray* filesToOpen = [NSMutableArray arrayWithCapacity:files.count];
|
|
|
|
for (NSString* file in files)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([[NSWorkspace.sharedWorkspace typeOfFile:file error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
|
|
|
|
[file.pathExtension caseInsensitiveCompare:@"torrent"] == NSOrderedSame)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-05-25 21:07:12 +00:00
|
|
|
torrent = YES;
|
2021-12-26 03:12:32 +00:00
|
|
|
auto metainfo = tr_torrent_metainfo{};
|
|
|
|
if (metainfo.parseTorrentFile(file.UTF8String))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[filesToOpen addObject:file];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (filesToOpen.count > 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self application:NSApp openFiles:filesToOpen];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent && files.count == 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[CreatorWindowController createTorrentFile:self.fLib forFile:[NSURL fileURLWithPath:files[0]]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
accept = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return accept;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([pasteboard.types containsObject:NSURLPboardType])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURL* url;
|
|
|
|
if ((url = [NSURL URLFromPasteboard:pasteboard]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self openURL:url.absoluteString];
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleSmallView:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL makeSmall = ![self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
[self.fDefaults setBool:makeSmall forKey:@"SmallView"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTableView.usesAlternatingRowBackgroundColors = !makeSmall;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTableView.rowHeight = makeSmall ? ROW_HEIGHT_SMALL : ROW_HEIGHT_REGULAR;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.fTableView
|
|
|
|
noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fTableView.numberOfRows)]];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
//reloaddata, otherwise the tableview has a bunch of empty cells
|
|
|
|
[self.fTableView reloadData];
|
|
|
|
[self updateForAutoSize];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)togglePiecesBar:(id)sender
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:![self.fDefaults boolForKey:@"PiecesBar"] forKey:@"PiecesBar"];
|
|
|
|
[self.fTableView togglePiecesBar];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleAvailabilityBar:(id)sender
|
2007-11-11 16:59:32 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:![self.fDefaults boolForKey:@"DisplayProgressBarAvailable"] forKey:@"DisplayProgressBarAvailable"];
|
|
|
|
[self.fTableView display];
|
2007-11-11 16:59:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleStatusBar:(id)sender
|
2008-03-16 14:24:27 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const show = self.fStatusBar == nil;
|
|
|
|
[self.fDefaults setBool:show forKey:@"StatusBar"];
|
2022-06-16 19:59:54 +00:00
|
|
|
[self updateMainWindow];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleFilterBar:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const show = self.fFilterBar == nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
//disable filtering when hiding (have to do before updateMainWindow:)
|
2013-09-21 16:24:40 +00:00
|
|
|
if (!show)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFilterBar reset:NO];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:show forKey:@"FilterBar"];
|
2022-06-16 19:59:54 +00:00
|
|
|
[self updateMainWindow];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)focusFilterField
|
2008-03-16 14:24:27 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fFilterBar)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self toggleFilterBar:self];
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFilterBar focusSearchField];
|
2008-03-16 14:24:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return !self.fQuitting;
|
2009-10-11 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPreviewPanel = panel;
|
|
|
|
self.fPreviewPanel.delegate = self;
|
|
|
|
self.fPreviewPanel.dataSource = self;
|
2009-10-11 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPreviewPanel = nil;
|
2022-06-28 23:19:06 +00:00
|
|
|
[self.fWindow.toolbar validateVisibleItems];
|
2009-10-11 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)quickLookableTorrents
|
2009-10-11 23:27:53 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* selectedTorrents = self.fTableView.selectedTorrents;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* qlArray = [NSMutableArray arrayWithCapacity:selectedTorrents.count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in selectedTorrents)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if ((torrent.folder || torrent.complete) && torrent.dataLocation)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[qlArray addObject:torrent];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-11 23:27:53 +00:00
|
|
|
return qlArray;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInfoController.canQuickLook)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fInfoController.quickLookURLs.count;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-11 23:27:53 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return [self quickLookableTorrents].count;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-11 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id<QLPreviewItem>)previewPanel:(QLPreviewPanel*)panel previewItemAtIndex:(NSInteger)index
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInfoController.canQuickLook)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fInfoController.quickLookURLs[index];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-11 23:16:46 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
return [self quickLookableTorrents][index];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-11 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)previewPanel:(QLPreviewPanel*)panel handleEvent:(NSEvent*)event
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
|
|
|
/*if ([event type] == NSKeyDown)
|
2012-09-09 12:58:53 +00:00
|
|
|
{
|
|
|
|
[super keyDown: event];
|
|
|
|
return YES;
|
|
|
|
}*/
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-11 23:16:46 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)previewPanel:(QLPreviewPanel*)panel sourceFrameOnScreenForPreviewItem:(id<QLPreviewItem>)item
|
2009-10-11 23:16:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInfoController.canQuickLook)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.fInfoController quickLookSourceFrameForPreviewItem:item];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-11 23:16:46 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fWindow.visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-12 00:19:04 +00:00
|
|
|
return NSZeroRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger const row = [self.fTableView rowForItem:item];
|
2009-10-11 23:16:46 +00:00
|
|
|
if (row == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-11 23:16:46 +00:00
|
|
|
return NSZeroRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSRect frame = [self.fTableView iconRectForRow:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!NSIntersectsRect(self.fTableView.visibleRect, frame))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-15 23:18:39 +00:00
|
|
|
return NSZeroRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
frame.origin = [self.fTableView convertPoint:frame.origin toView:nil];
|
|
|
|
frame = [self.fWindow convertRectToScreen:frame];
|
2009-10-11 23:16:46 +00:00
|
|
|
frame.origin.y -= frame.size.height;
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showToolbarShare:(id)sender
|
2014-01-09 16:23:54 +00:00
|
|
|
{
|
|
|
|
NSParameterAssert([sender isKindOfClass:[NSButton class]]);
|
2021-08-15 09:41:48 +00:00
|
|
|
NSButton* senderButton = sender;
|
|
|
|
|
|
|
|
NSSharingServicePicker* picker = [[NSSharingServicePicker alloc] initWithItems:ShareTorrentFileHelper.sharedHelper.shareTorrentURLs];
|
2014-01-09 16:23:54 +00:00
|
|
|
picker.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[picker showRelativeToRect:senderButton.bounds ofView:senderButton preferredEdge:NSMinYEdge];
|
2014-01-09 16:23:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id<NSSharingServiceDelegate>)sharingServicePicker:(NSSharingServicePicker*)sharingServicePicker
|
|
|
|
delegateForSharingService:(NSSharingService*)sharingService
|
2014-01-09 16:23:54 +00:00
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSWindow*)sharingService:(NSSharingService*)sharingService
|
|
|
|
sourceWindowForShareItems:(NSArray*)items
|
|
|
|
sharingContentScope:(NSSharingContentScope*)sharingContentScope
|
2014-01-09 16:23:54 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fWindow;
|
2014-01-09 16:23:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (ButtonToolbarItem*)standardToolbarButtonWithIdentifier:(NSString*)ident
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [self toolbarButtonWithIdentifier:ident forToolbarButtonClass:[ButtonToolbarItem class]];
|
2014-01-09 16:23:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 12:56:57 +00:00
|
|
|
- (id)toolbarButtonWithIdentifier:(NSString*)ident forToolbarButtonClass:(Class)klass
|
2014-01-09 16:23:54 +00:00
|
|
|
{
|
2021-09-24 12:56:57 +00:00
|
|
|
ButtonToolbarItem* item = [[klass alloc] initWithItemIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSButton* button = [[NSButton alloc] init];
|
2021-10-31 15:18:27 +00:00
|
|
|
button.bezelStyle = NSBezelStyleTexturedRounded;
|
2021-08-07 07:27:56 +00:00
|
|
|
button.stringValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.view = button;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-12 00:45:50 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
//standard button sizes
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSSize const buttonSize = NSMakeSize(36.0, 25.0);
|
|
|
|
item.minSize = buttonSize;
|
|
|
|
item.maxSize = buttonSize;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return item;
|
2007-12-06 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar itemForItemIdentifier:(NSString*)ident willBeInsertedIntoToolbar:(BOOL)flag
|
2007-12-06 20:54:26 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_CREATE])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Create", "Create toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Create Torrent File", "Create toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Create torrent file", "Create toolbar item -> tooltip");
|
2022-04-24 20:34:30 +00:00
|
|
|
item.image = [NSImage systemSymbol:@"doc.badge.plus" withFallback:@"ToolbarCreateTemplate"];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(createFile:);
|
|
|
|
item.autovalidates = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_OPEN_FILE])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Open", "Open toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Open Torrent Files", "Open toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Open torrent files", "Open toolbar item -> tooltip");
|
2022-04-24 20:34:30 +00:00
|
|
|
item.image = [NSImage systemSymbol:@"folder" withFallback:@"ToolbarOpenTemplate"];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(openShowSheet:);
|
|
|
|
item.autovalidates = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_OPEN_WEB])
|
2008-02-07 20:34:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Open Address", "Open address toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Open Torrent Address", "Open address toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Open torrent web address", "Open address toolbar item -> tooltip");
|
2022-04-24 20:34:30 +00:00
|
|
|
item.image = [NSImage systemSymbol:@"globe" withFallback:@"ToolbarOpenWebTemplate"];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(openURLShowSheet:);
|
|
|
|
item.autovalidates = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-07 20:34:14 +00:00
|
|
|
return item;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_REMOVE])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Remove", "Remove toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Remove Selected", "Remove toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Remove selected transfers", "Remove toolbar item -> tooltip");
|
2022-04-24 20:34:30 +00:00
|
|
|
item.image = [NSImage systemSymbol:@"nosign" withFallback:@"ToolbarRemoveTemplate"];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(removeNoDelete:);
|
|
|
|
item.visibilityPriority = NSToolbarItemVisibilityPriorityHigh;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_INFO])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
|
|
|
((NSButtonCell*)((NSButton*)item.view).cell).showsStateBy = NSContentsCellMask; //blue when enabled
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Inspector", "Inspector toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Toggle Inspector", "Inspector toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Toggle the torrent inspector", "Inspector toolbar item -> tooltip");
|
2022-04-24 20:34:30 +00:00
|
|
|
item.image = [NSImage systemSymbol:@"info.circle" withFallback:@"ToolbarInfoTemplate"];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(showInfo:);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_PAUSE_RESUME_ALL])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
GroupToolbarItem* groupItem = [[GroupToolbarItem alloc] initWithItemIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSToolbarItem* itemPause = [self standardToolbarButtonWithIdentifier:TOOLBAR_PAUSE_ALL];
|
|
|
|
NSToolbarItem* itemResume = [self standardToolbarButtonWithIdentifier:TOOLBAR_RESUME_ALL];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSSegmentedControl* segmentedControl = [[NSSegmentedControl alloc] initWithFrame:NSZeroRect];
|
|
|
|
segmentedControl.segmentStyle = NSSegmentStyleTexturedRounded;
|
|
|
|
segmentedControl.trackingMode = NSSegmentSwitchTrackingMomentary;
|
2021-08-07 07:27:56 +00:00
|
|
|
segmentedControl.segmentCount = 2;
|
2022-07-23 19:37:57 +00:00
|
|
|
|
|
|
|
[segmentedControl setTag:TOOLBAR_PAUSE_TAG forSegment:TOOLBAR_PAUSE_TAG];
|
|
|
|
[segmentedControl setImage:[NSImage systemSymbol:@"pause.circle.fill" withFallback:@"ToolbarPauseAllTemplate"]
|
|
|
|
forSegment:TOOLBAR_PAUSE_TAG];
|
|
|
|
[segmentedControl setToolTip:NSLocalizedString(@"Pause all transfers", "All toolbar item -> tooltip")
|
|
|
|
forSegment:TOOLBAR_PAUSE_TAG];
|
|
|
|
|
|
|
|
[segmentedControl setTag:TOOLBAR_RESUME_TAG forSegment:TOOLBAR_RESUME_TAG];
|
|
|
|
[segmentedControl setImage:[NSImage systemSymbol:@"arrow.clockwise.circle.fill" withFallback:@"ToolbarResumeAllTemplate"]
|
|
|
|
forSegment:TOOLBAR_RESUME_TAG];
|
|
|
|
[segmentedControl setToolTip:NSLocalizedString(@"Resume all transfers", "All toolbar item -> tooltip")
|
|
|
|
forSegment:TOOLBAR_RESUME_TAG];
|
|
|
|
|
|
|
|
groupItem.label = NSLocalizedString(@"Apply All", "All toolbar item -> label");
|
|
|
|
groupItem.paletteLabel = NSLocalizedString(@"Pause / Resume All", "All toolbar item -> palette label");
|
|
|
|
groupItem.visibilityPriority = NSToolbarItemVisibilityPriorityHigh;
|
|
|
|
groupItem.subitems = @[ itemPause, itemResume ];
|
|
|
|
groupItem.view = segmentedControl;
|
|
|
|
groupItem.target = self;
|
|
|
|
groupItem.action = @selector(allToolbarClicked:);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-12 00:45:50 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
//standard segment size
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSSize const groupSize = NSMakeSize(72.0, 25.0);
|
|
|
|
groupItem.minSize = groupSize;
|
|
|
|
groupItem.maxSize = groupSize;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[groupItem createMenu:@[
|
|
|
|
NSLocalizedString(@"Pause All", "All toolbar item -> label"),
|
|
|
|
NSLocalizedString(@"Resume All", "All toolbar item -> label")
|
|
|
|
]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return groupItem;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_PAUSE_RESUME_SELECTED])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
GroupToolbarItem* groupItem = [[GroupToolbarItem alloc] initWithItemIdentifier:ident];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSToolbarItem* itemPause = [self standardToolbarButtonWithIdentifier:TOOLBAR_PAUSE_SELECTED];
|
|
|
|
NSToolbarItem* itemResume = [self standardToolbarButtonWithIdentifier:TOOLBAR_RESUME_SELECTED];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-23 19:37:57 +00:00
|
|
|
NSSegmentedControl* segmentedControl = [[NSSegmentedControl alloc] initWithFrame:NSZeroRect];
|
|
|
|
segmentedControl.segmentStyle = NSSegmentStyleTexturedRounded;
|
|
|
|
segmentedControl.trackingMode = NSSegmentSwitchTrackingMomentary;
|
2021-08-07 07:27:56 +00:00
|
|
|
segmentedControl.segmentCount = 2;
|
2022-07-23 19:37:57 +00:00
|
|
|
|
|
|
|
[segmentedControl setTag:TOOLBAR_PAUSE_TAG forSegment:TOOLBAR_PAUSE_TAG];
|
|
|
|
[segmentedControl setImage:[NSImage systemSymbol:@"pause" withFallback:@"ToolbarPauseSelectedTemplate"]
|
|
|
|
forSegment:TOOLBAR_PAUSE_TAG];
|
|
|
|
[segmentedControl setToolTip:NSLocalizedString(@"Pause selected transfers", "Selected toolbar item -> tooltip")
|
|
|
|
forSegment:TOOLBAR_PAUSE_TAG];
|
|
|
|
|
|
|
|
[segmentedControl setTag:TOOLBAR_RESUME_TAG forSegment:TOOLBAR_RESUME_TAG];
|
|
|
|
[segmentedControl setImage:[NSImage systemSymbol:@"arrow.clockwise" withFallback:@"ToolbarResumeSelectedTemplate"]
|
|
|
|
forSegment:TOOLBAR_RESUME_TAG];
|
|
|
|
[segmentedControl setToolTip:NSLocalizedString(@"Resume selected transfers", "Selected toolbar item -> tooltip")
|
|
|
|
forSegment:TOOLBAR_RESUME_TAG];
|
|
|
|
|
|
|
|
groupItem.view = segmentedControl;
|
|
|
|
groupItem.label = NSLocalizedString(@"Apply Selected", "Selected toolbar item -> label");
|
|
|
|
groupItem.paletteLabel = NSLocalizedString(@"Pause / Resume Selected", "Selected toolbar item -> palette label");
|
|
|
|
groupItem.visibilityPriority = NSToolbarItemVisibilityPriorityHigh;
|
|
|
|
groupItem.subitems = @[ itemPause, itemResume ];
|
|
|
|
groupItem.view = segmentedControl;
|
|
|
|
groupItem.target = self;
|
|
|
|
groupItem.action = @selector(selectedToolbarClicked:);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-07-12 00:45:50 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
//standard segment size
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSSize const groupSize = NSMakeSize(72.0, 25.0);
|
|
|
|
groupItem.minSize = groupSize;
|
|
|
|
groupItem.maxSize = groupSize;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[groupItem createMenu:@[
|
|
|
|
NSLocalizedString(@"Pause Selected", "Selected toolbar item -> label"),
|
|
|
|
NSLocalizedString(@"Resume Selected", "Selected toolbar item -> label")
|
|
|
|
]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return groupItem;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_FILTER])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
|
|
|
((NSButtonCell*)((NSButton*)item.view).cell).showsStateBy = NSContentsCellMask; //blue when enabled
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Filter", "Filter toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Toggle Filter", "Filter toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Toggle the filter bar", "Filter toolbar item -> tooltip");
|
2022-04-24 20:34:30 +00:00
|
|
|
item.image = [NSImage systemSymbol:@"magnifyingglass" withFallback:@"ToolbarFilterTemplate"];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(toggleFilterBar:);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 20:54:26 +00:00
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_QUICKLOOK])
|
2008-05-21 16:02:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ButtonToolbarItem* item = [self standardToolbarButtonWithIdentifier:ident];
|
|
|
|
((NSButtonCell*)((NSButton*)item.view).cell).showsStateBy = NSContentsCellMask; //blue when enabled
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Quick Look", "QuickLook toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Quick Look", "QuickLook toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Quick Look", "QuickLook toolbar item -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
item.image = [NSImage imageNamed:NSImageNameQuickLookTemplate];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(toggleQuickLook:);
|
|
|
|
item.visibilityPriority = NSToolbarItemVisibilityPriorityLow;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-21 16:02:38 +00:00
|
|
|
return item;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_SHARE])
|
2014-01-09 16:23:54 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ShareToolbarItem* item = [self toolbarButtonWithIdentifier:ident forToolbarButtonClass:[ShareToolbarItem class]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Share", "Share toolbar item -> label");
|
|
|
|
item.paletteLabel = NSLocalizedString(@"Share", "Share toolbar item -> palette label");
|
|
|
|
item.toolTip = NSLocalizedString(@"Share torrent file", "Share toolbar item -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
item.image = [NSImage imageNamed:NSImageNameShareTemplate];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.visibilityPriority = NSToolbarItemVisibilityPriorityLow;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSButton* itemButton = (NSButton*)item.view;
|
2021-08-07 07:27:56 +00:00
|
|
|
itemButton.target = self;
|
|
|
|
itemButton.action = @selector(showToolbarShare:);
|
2021-10-31 15:18:27 +00:00
|
|
|
[itemButton sendActionOn:NSEventMaskLeftMouseDown];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2014-01-09 16:23:54 +00:00
|
|
|
return item;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)allToolbarClicked:(id)sender
|
2007-12-06 17:21:42 +00:00
|
|
|
{
|
2022-07-23 19:37:57 +00:00
|
|
|
NSInteger tagValue = [sender isKindOfClass:[NSSegmentedControl class]] ? [(NSSegmentedControl*)sender selectedTag] :
|
|
|
|
((NSControl*)sender).tag;
|
2007-12-07 03:41:46 +00:00
|
|
|
switch (tagValue)
|
2007-12-06 20:25:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TOOLBAR_PAUSE_TAG:
|
|
|
|
[self stopAllTorrents:sender];
|
|
|
|
break;
|
|
|
|
case TOOLBAR_RESUME_TAG:
|
|
|
|
[self resumeAllTorrents:sender];
|
|
|
|
break;
|
2007-12-06 20:25:38 +00:00
|
|
|
}
|
2007-12-06 17:21:42 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)selectedToolbarClicked:(id)sender
|
2007-12-06 17:21:42 +00:00
|
|
|
{
|
2022-07-23 19:37:57 +00:00
|
|
|
NSInteger tagValue = [sender isKindOfClass:[NSSegmentedControl class]] ? [(NSSegmentedControl*)sender selectedTag] :
|
|
|
|
((NSControl*)sender).tag;
|
2007-12-07 03:41:46 +00:00
|
|
|
switch (tagValue)
|
2007-12-06 20:25:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TOOLBAR_PAUSE_TAG:
|
|
|
|
[self stopSelectedTorrents:sender];
|
|
|
|
break;
|
|
|
|
case TOOLBAR_RESUME_TAG:
|
|
|
|
[self resumeSelectedTorrents:sender];
|
|
|
|
break;
|
2007-12-06 20:25:38 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return @[
|
|
|
|
TOOLBAR_CREATE,
|
|
|
|
TOOLBAR_OPEN_FILE,
|
|
|
|
TOOLBAR_OPEN_WEB,
|
|
|
|
TOOLBAR_REMOVE,
|
|
|
|
TOOLBAR_PAUSE_RESUME_SELECTED,
|
|
|
|
TOOLBAR_PAUSE_RESUME_ALL,
|
|
|
|
TOOLBAR_SHARE,
|
|
|
|
TOOLBAR_QUICKLOOK,
|
|
|
|
TOOLBAR_FILTER,
|
|
|
|
TOOLBAR_INFO,
|
|
|
|
NSToolbarSpaceItemIdentifier,
|
|
|
|
NSToolbarFlexibleSpaceItemIdentifier
|
|
|
|
];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return @[
|
|
|
|
TOOLBAR_CREATE,
|
|
|
|
TOOLBAR_OPEN_FILE,
|
|
|
|
TOOLBAR_REMOVE,
|
|
|
|
NSToolbarSpaceItemIdentifier,
|
|
|
|
TOOLBAR_PAUSE_RESUME_ALL,
|
|
|
|
NSToolbarFlexibleSpaceItemIdentifier,
|
|
|
|
TOOLBAR_SHARE,
|
|
|
|
TOOLBAR_QUICKLOOK,
|
|
|
|
TOOLBAR_FILTER,
|
|
|
|
TOOLBAR_INFO
|
|
|
|
];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)validateToolbarItem:(NSToolbarItem*)toolbarItem
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* ident = toolbarItem.itemIdentifier;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable remove item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_REMOVE])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fTableView.numberOfSelectedRows > 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable pause all item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_PAUSE_ALL])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active || torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable resume all item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_RESUME_ALL])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.active && !torrent.waitingToStart && !torrent.finishedSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable pause item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_PAUSE_SELECTED])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active || torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable resume item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_RESUME_SELECTED])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.active && !torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-10 01:36:51 +00:00
|
|
|
//set info item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_INFO])
|
2007-12-09 03:25:33 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
((NSButton*)toolbarItem.view).state = self.fInfoController.window.visible;
|
2007-12-09 03:25:33 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-10 01:36:51 +00:00
|
|
|
//set filter item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_FILTER])
|
2007-12-09 03:25:33 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
((NSButton*)toolbarItem.view).state = self.fFilterBar != nil;
|
2007-12-09 03:25:33 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-10 01:36:51 +00:00
|
|
|
//set quick look item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_QUICKLOOK])
|
2009-10-12 01:59:52 +00:00
|
|
|
{
|
2022-06-28 23:19:06 +00:00
|
|
|
((NSButton*)toolbarItem.view).state = self.fPreviewPanel != nil;
|
|
|
|
return self.fTableView.numberOfSelectedRows > 0;
|
2009-10-12 01:59:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2014-01-09 16:23:54 +00:00
|
|
|
//enable share item
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_SHARE])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fTableView.numberOfSelectedRows > 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
SEL action = menuItem.action;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-30 20:19:22 +00:00
|
|
|
if (action == @selector(toggleSpeedLimit:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
menuItem.state = [self.fDefaults boolForKey:@"SpeedLimit"] ? NSControlStateValueOn : NSControlStateValueOff;
|
2007-10-30 20:19:22 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//only enable some items if it is in a context menu or the window is useable
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL canUseTable = self.fWindow.keyWindow || menuItem.menu.supermenu != NSApp.mainMenu;
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable open items
|
|
|
|
if (action == @selector(openShowSheet:) || action == @selector(openURLShowSheet:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fWindow.attachedSheet == nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* sortType;
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (menuItem.tag)
|
2007-11-07 05:02:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
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;
|
|
|
|
case SORT_ACTIVITY_TAG:
|
|
|
|
sortType = SORT_ACTIVITY;
|
|
|
|
break;
|
|
|
|
case SORT_SIZE_TAG:
|
|
|
|
sortType = SORT_SIZE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown sort tag received: %ld", [menuItem tag]);
|
|
|
|
sortType = SORT_ORDER;
|
2007-11-07 05:02:43 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
menuItem.state = [sortType isEqualToString:[self.fDefaults stringForKey:@"Sort"]] ? NSControlStateValueOn : NSControlStateValueOff;
|
|
|
|
return self.fWindow.visible;
|
2007-11-07 05:02:43 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 16:32:32 +00:00
|
|
|
if (action == @selector(setGroup:))
|
|
|
|
{
|
|
|
|
BOOL checked = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = menuItem.tag;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (index == torrent.groupValue)
|
2007-12-17 16:32:32 +00:00
|
|
|
{
|
|
|
|
checked = YES;
|
|
|
|
break;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
menuItem.state = checked ? NSControlStateValueOn : NSControlStateValueOff;
|
2022-02-22 16:04:20 +00:00
|
|
|
return canUseTable && self.fTableView.numberOfSelectedRows > 0;
|
2007-12-17 16:32:32 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-30 19:55:47 +00:00
|
|
|
if (action == @selector(toggleSmallView:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
menuItem.state = [self.fDefaults boolForKey:@"SmallView"] ? NSControlStateValueOn : NSControlStateValueOff;
|
|
|
|
return self.fWindow.visible;
|
2007-10-30 19:55:47 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
if (action == @selector(togglePiecesBar:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
menuItem.state = [self.fDefaults boolForKey:@"PiecesBar"] ? NSControlStateValueOn : NSControlStateValueOff;
|
|
|
|
return self.fWindow.visible;
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-11-11 16:59:32 +00:00
|
|
|
if (action == @selector(toggleAvailabilityBar:))
|
|
|
|
{
|
2022-03-30 21:52:23 +00:00
|
|
|
menuItem.state = [self.fDefaults boolForKey:@"DisplayProgressBarAvailable"] ? NSControlStateValueOn : NSControlStateValueOff;
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fWindow.visible;
|
2007-11-11 16:59:32 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable show info
|
|
|
|
if (action == @selector(showInfo:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* title = self.fInfoController.window.visible ? NSLocalizedString(@"Hide Inspector", "View menu -> Inspector") :
|
2022-03-30 21:52:23 +00:00
|
|
|
NSLocalizedString(@"Show Inspector", "View menu -> Inspector");
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.title = title;
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable prev/next inspector tab
|
|
|
|
if (action == @selector(setInfoTab:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fInfoController.window.visible;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable toggle status bar
|
|
|
|
if (action == @selector(toggleStatusBar:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* title = !self.fStatusBar ? NSLocalizedString(@"Show Status Bar", "View menu -> Status Bar") :
|
2022-03-30 21:52:23 +00:00
|
|
|
NSLocalizedString(@"Hide Status Bar", "View menu -> Status Bar");
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.title = title;
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fWindow.visible;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable toggle filter bar
|
|
|
|
if (action == @selector(toggleFilterBar:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* title = !self.fFilterBar ? NSLocalizedString(@"Show Filter Bar", "View menu -> Filter Bar") :
|
2022-03-30 21:52:23 +00:00
|
|
|
NSLocalizedString(@"Hide Filter Bar", "View menu -> Filter Bar");
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.title = title;
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fWindow.visible;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable prev/next filter button
|
|
|
|
if (action == @selector(switchFilter:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fWindow.visible && self.fFilterBar;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable reveal in finder
|
|
|
|
if (action == @selector(revealFile:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return canUseTable && self.fTableView.numberOfSelectedRows > 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-01-22 00:09:48 +00:00
|
|
|
//enable renaming file/folder
|
2013-01-22 00:50:28 +00:00
|
|
|
if (action == @selector(renameSelected:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return canUseTable && self.fTableView.numberOfSelectedRows == 1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable remove items
|
2009-07-19 19:14:01 +00:00
|
|
|
if (action == @selector(removeNoDelete:) || action == @selector(removeDeleteData:))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-07-19 19:14:01 +00:00
|
|
|
BOOL warning = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"CheckRemoveDownloading"] ? !torrent.seeding : YES)
|
2009-07-19 19:14:01 +00:00
|
|
|
{
|
|
|
|
warning = YES;
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
2009-07-19 19:14:01 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//append or remove ellipsis when needed
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString *title = menuItem.title, *ellipsis = NSString.ellipsis;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (warning && [self.fDefaults boolForKey:@"CheckRemove"])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![title hasSuffix:ellipsis])
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.title = [title stringByAppendingEllipsis];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([title hasSuffix:ellipsis])
|
|
|
|
{
|
|
|
|
menuItem.title = [title substringToIndex:[title rangeOfString:ellipsis].location];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return canUseTable && self.fTableView.numberOfSelectedRows > 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-14 23:46:53 +00:00
|
|
|
//remove all completed transfers item
|
2011-02-13 02:02:13 +00:00
|
|
|
if (action == @selector(clearCompleted:))
|
|
|
|
{
|
2011-03-17 01:06:31 +00:00
|
|
|
//append or remove ellipsis when needed
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString *title = menuItem.title, *ellipsis = NSString.ellipsis;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"WarningRemoveCompleted"])
|
2011-03-17 01:06:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![title hasSuffix:ellipsis])
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.title = [title stringByAppendingEllipsis];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-03-17 01:06:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([title hasSuffix:ellipsis])
|
|
|
|
{
|
|
|
|
menuItem.title = [title substringToIndex:[title rangeOfString:ellipsis].location];
|
|
|
|
}
|
2011-03-17 01:06:31 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.finishedSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-13 02:02:13 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-13 02:02:13 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable pause all item
|
|
|
|
if (action == @selector(stopAllTorrents:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active || torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable resume all item
|
|
|
|
if (action == @selector(resumeAllTorrents:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.active && !torrent.waitingToStart && !torrent.finishedSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable resume all waiting item
|
|
|
|
if (action == @selector(resumeWaitingTorrents:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"Queue"] && ![self.fDefaults boolForKey:@"QueueSeed"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable resume selected waiting item
|
|
|
|
if (action == @selector(resumeSelectedTorrentsNoWait:))
|
|
|
|
{
|
2008-01-02 04:33:26 +00:00
|
|
|
if (!canUseTable)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-02 04:33:26 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable pause item
|
|
|
|
if (action == @selector(stopSelectedTorrents:))
|
|
|
|
{
|
|
|
|
if (!canUseTable)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active || torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable resume item
|
|
|
|
if (action == @selector(resumeSelectedTorrents:))
|
|
|
|
{
|
|
|
|
if (!canUseTable)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.active && !torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable manual announce item
|
|
|
|
if (action == @selector(announceSelectedTorrents:))
|
|
|
|
{
|
|
|
|
if (!canUseTable)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.canManualAnnounce)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable reset cache item
|
2008-02-27 19:04:38 +00:00
|
|
|
if (action == @selector(verifySelectedTorrents:))
|
2010-01-23 21:51:04 +00:00
|
|
|
{
|
|
|
|
if (!canUseTable)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-01-23 21:51:04 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.magnet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-01-23 21:51:04 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-23 21:51:04 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable move torrent file item
|
2008-03-22 17:05:48 +00:00
|
|
|
if (action == @selector(moveDataFilesSelected:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return canUseTable && self.fTableView.numberOfSelectedRows > 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable copy torrent file item
|
|
|
|
if (action == @selector(copyTorrentFiles:))
|
2010-01-17 17:57:54 +00:00
|
|
|
{
|
|
|
|
if (!canUseTable)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-01-17 17:57:54 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTableView.selectedTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.magnet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-01-17 17:57:54 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-17 17:57:54 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-04 13:35:15 +00:00
|
|
|
//enable copy torrent file item
|
|
|
|
if (action == @selector(copyMagnetLinks:))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return canUseTable && self.fTableView.numberOfSelectedRows > 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//enable reverse sort item
|
|
|
|
if (action == @selector(setSortReverse:))
|
2007-10-30 19:55:47 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const isReverse = menuItem.tag == SORT_DESC_TAG;
|
2022-03-30 21:52:23 +00:00
|
|
|
menuItem.state = (isReverse == [self.fDefaults boolForKey:@"SortReverse"]) ? NSControlStateValueOn : NSControlStateValueOff;
|
2022-02-22 16:04:20 +00:00
|
|
|
return ![[self.fDefaults stringForKey:@"Sort"] isEqualToString:SORT_ORDER];
|
2007-10-30 19:55:47 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 19:47:06 +00:00
|
|
|
//enable group sort item
|
|
|
|
if (action == @selector(setSortByGroup:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
menuItem.state = [self.fDefaults boolForKey:@"SortByGroup"] ? NSControlStateValueOn : NSControlStateValueOff;
|
2008-05-11 21:38:40 +00:00
|
|
|
return YES;
|
2007-12-17 19:47:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-09-07 15:07:00 +00:00
|
|
|
if (action == @selector(toggleQuickLook:))
|
2009-10-12 01:59:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const visible = [QLPreviewPanel sharedPreviewPanelExists] && [QLPreviewPanel sharedPreviewPanel].visible;
|
2009-10-12 01:59:52 +00:00
|
|
|
//text consistent with Finder
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* title = !visible ? NSLocalizedString(@"Quick Look", "View menu -> Quick Look") :
|
|
|
|
NSLocalizedString(@"Close Quick Look", "View menu -> Quick Look");
|
2021-08-07 07:27:56 +00:00
|
|
|
menuItem.title = title;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-28 23:19:06 +00:00
|
|
|
return self.fTableView.numberOfSelectedRows > 0;
|
2009-10-12 01:59:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)sleepCallback:(natural_t)messageType argument:(void*)messageArgument
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
switch (messageType)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case kIOMessageSystemWillSleep:
|
2012-11-04 19:28:51 +00:00
|
|
|
{
|
|
|
|
//stop all transfers (since some are active) before going to sleep and remember to resume when we wake up
|
|
|
|
BOOL anyActive = NO;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2012-11-04 19:28:51 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-11-04 19:28:51 +00:00
|
|
|
anyActive = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-11-04 19:28:51 +00:00
|
|
|
[torrent sleep]; //have to call on all, regardless if they are active
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-11-04 19:28:51 +00:00
|
|
|
//if there are any running transfers, wait 15 seconds for them to stop
|
|
|
|
if (anyActive)
|
|
|
|
{
|
|
|
|
sleep(15);
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
IOAllowPowerChange(self.fRootPort, (long)messageArgument);
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
2012-11-04 19:28:51 +00:00
|
|
|
}
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case kIOMessageCanSystemSleep:
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"SleepPrevent"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
//prevent idle sleep unless no torrents are active
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (torrent.active && !torrent.stalled && !torrent.error)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
IOCancelPowerChange(self.fRootPort, (long)messageArgument);
|
2021-08-15 09:41:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
IOAllowPowerChange(self.fRootPort, (long)messageArgument);
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
2012-09-09 12:58:53 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case kIOMessageSystemHasPoweredOn:
|
|
|
|
//resume sleeping transfers after we wake up
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrent wakeUp];
|
|
|
|
}
|
|
|
|
break;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMenu*)applicationDockMenu:(NSApplication*)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fQuitting)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-05 23:21:34 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
NSUInteger seeding = 0, downloading = 0;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.seeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-05 23:21:34 +00:00
|
|
|
seeding++;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (torrent.active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-05 23:21:34 +00:00
|
|
|
downloading++;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenu* menu = [[NSMenu alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (seeding > 0)
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
NSString* title = [NSString stringWithFormat:NSLocalizedString(@"%lu Seeding", "Dock item - Seeding"), seeding];
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItemWithTitle:title action:nil keyEquivalent:@""];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (downloading > 0)
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
NSString* title = [NSString stringWithFormat:NSLocalizedString(@"%lu Downloading", "Dock item - Downloading"), downloading];
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItemWithTitle:title action:nil keyEquivalent:@""];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (seeding > 0 || downloading > 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItemWithTitle:NSLocalizedString(@"Pause All", "Dock item") action:@selector(stopAllTorrents:) keyEquivalent:@""];
|
|
|
|
[menu addItemWithTitle:NSLocalizedString(@"Resume All", "Dock item") action:@selector(resumeAllTorrents:) keyEquivalent:@""];
|
|
|
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
|
|
[menu addItemWithTitle:NSLocalizedString(@"Speed Limit", "Dock item") action:@selector(toggleSpeedLimit:) keyEquivalent:@""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return menu;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
- (void)updateMainWindow
|
2022-06-16 17:55:33 +00:00
|
|
|
{
|
2022-06-16 19:59:54 +00:00
|
|
|
NSArray* subViews = self.fStackView.arrangedSubviews;
|
|
|
|
NSUInteger idx = 0;
|
2022-06-16 17:55:33 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
//update layout
|
|
|
|
if ([self.fDefaults boolForKey:@"StatusBar"])
|
|
|
|
{
|
|
|
|
if (self.fStatusBar == nil)
|
|
|
|
{
|
|
|
|
self.fStatusBar = [[StatusBarController alloc] initWithLib:self.fLib];
|
|
|
|
}
|
2022-06-16 17:55:33 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
[self.fStackView insertArrangedSubview:self.fStatusBar.view atIndex:idx];
|
|
|
|
|
|
|
|
NSDictionary* views = @{ @"fStatusBar" : self.fStatusBar.view };
|
|
|
|
[self.fStackView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[fStatusBar(==21)]" options:0
|
|
|
|
metrics:nil
|
|
|
|
views:views]];
|
|
|
|
idx = 1;
|
|
|
|
}
|
|
|
|
else
|
2022-06-16 17:55:33 +00:00
|
|
|
{
|
2022-06-16 19:59:54 +00:00
|
|
|
if ([subViews containsObject:self.fStatusBar.view])
|
|
|
|
{
|
|
|
|
[self.fStackView removeView:self.fStatusBar.view];
|
|
|
|
self.fStatusBar = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([self.fDefaults boolForKey:@"FilterBar"])
|
|
|
|
{
|
|
|
|
if (self.fFilterBar == nil)
|
|
|
|
{
|
|
|
|
self.fFilterBar = [[FilterBarController alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.fStackView insertArrangedSubview:self.fFilterBar.view atIndex:idx];
|
|
|
|
|
|
|
|
NSDictionary* views = @{ @"fFilterBar" : self.fFilterBar.view };
|
2022-06-23 16:18:53 +00:00
|
|
|
[self.fStackView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[fFilterBar(==23)]" options:0
|
2022-06-16 19:59:54 +00:00
|
|
|
metrics:nil
|
|
|
|
views:views]];
|
2022-06-16 17:55:33 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
[self focusFilterField];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([subViews containsObject:self.fFilterBar.view])
|
|
|
|
{
|
|
|
|
[self.fStackView removeView:self.fFilterBar.view];
|
|
|
|
self.fFilterBar = nil;
|
2022-06-16 17:55:33 +00:00
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
[self.fWindow makeFirstResponder:self.fTableView];
|
|
|
|
}
|
2022-06-16 17:55:33 +00:00
|
|
|
}
|
2022-06-16 19:59:54 +00:00
|
|
|
|
|
|
|
[self fullUpdateUI];
|
|
|
|
[self updateForAutoSize];
|
2022-06-16 17:55:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
- (void)setWindowSizeToFit
|
2022-06-16 17:55:33 +00:00
|
|
|
{
|
2022-06-16 19:59:54 +00:00
|
|
|
if (!self.isFullScreen)
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
NSScrollView* scrollView = self.fTableView.enclosingScrollView;
|
|
|
|
|
|
|
|
scrollView.hasVerticalScroller = NO;
|
|
|
|
|
|
|
|
[self removeStackViewHeightConstraints];
|
|
|
|
|
|
|
|
NSDictionary* views = @{ @"scrollView" : scrollView };
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"AutoSize"])
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
//only set a minimum height constraint
|
|
|
|
CGFloat height = self.minScrollViewHeightAllowed;
|
|
|
|
NSString* constraintsString = [NSString stringWithFormat:@"V:[scrollView(>=%f)]", height];
|
|
|
|
self.fStackViewHeightConstraints = [NSLayoutConstraint constraintsWithVisualFormat:constraintsString options:0
|
|
|
|
metrics:nil
|
|
|
|
views:views];
|
2022-06-16 19:59:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
//set a fixed height constraint
|
2022-06-16 19:59:54 +00:00
|
|
|
CGFloat height = self.scrollViewHeight;
|
|
|
|
NSString* constraintsString = [NSString stringWithFormat:@"V:[scrollView(==%f)]", height];
|
|
|
|
self.fStackViewHeightConstraints = [NSLayoutConstraint constraintsWithVisualFormat:constraintsString options:0
|
|
|
|
metrics:nil
|
|
|
|
views:views];
|
2022-06-18 17:39:22 +00:00
|
|
|
}
|
2022-06-16 19:59:54 +00:00
|
|
|
|
2022-06-18 17:39:22 +00:00
|
|
|
//add height constraint to fStackView
|
|
|
|
[self.fStackView addConstraints:self.fStackViewHeightConstraints];
|
2022-06-16 19:59:54 +00:00
|
|
|
|
2022-06-18 17:39:22 +00:00
|
|
|
scrollView.hasVerticalScroller = YES;
|
2022-06-16 19:59:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self removeStackViewHeightConstraints];
|
|
|
|
}
|
2022-06-16 17:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateForAutoSize
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
if (!self.isFullScreen)
|
2022-06-16 17:55:33 +00:00
|
|
|
{
|
|
|
|
[self setWindowSizeToFit];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
[self removeStackViewHeightConstraints];
|
2022-06-16 17:55:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 05:26:36 +00:00
|
|
|
- (void)updateWindowAfterToolbarChange
|
|
|
|
{
|
|
|
|
//Hacky way of fixing an issue with showing the Toolbar
|
2022-07-17 23:04:32 +00:00
|
|
|
if (!self.isFullScreen)
|
2022-06-24 05:26:36 +00:00
|
|
|
{
|
|
|
|
//macOS Big Sur shows the unified toolbar by default
|
|
|
|
//and we only need to "fix" the layout when showing the toolbar
|
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
if (!self.fWindow.toolbar.isVisible)
|
|
|
|
{
|
|
|
|
[self removeStackViewHeightConstraints];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self removeStackViewHeightConstraints];
|
|
|
|
}
|
|
|
|
|
2022-06-28 21:14:10 +00:00
|
|
|
//this fixes a macOS bug where on toggling the toolbar item bezels will show
|
|
|
|
[self hideToolBarBezels:YES];
|
|
|
|
|
2022-06-24 05:26:36 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2022-07-17 23:04:32 +00:00
|
|
|
[self updateForAutoSize];
|
2022-06-28 21:14:10 +00:00
|
|
|
[self hideToolBarBezels:NO];
|
2022-06-24 05:26:36 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 21:14:10 +00:00
|
|
|
- (void)hideToolBarBezels:(BOOL)hide
|
|
|
|
{
|
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
for (NSToolbarItem* item in self.fWindow.toolbar.items)
|
|
|
|
{
|
|
|
|
item.view.hidden = hide;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
- (void)removeStackViewHeightConstraints
|
|
|
|
{
|
|
|
|
if (self.fStackViewHeightConstraints)
|
|
|
|
{
|
|
|
|
[self.fStackView removeConstraints:self.fStackViewHeightConstraints];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 17:39:22 +00:00
|
|
|
- (CGFloat)minScrollViewHeightAllowed
|
2022-06-16 17:55:33 +00:00
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
CGFloat contentMinHeight = self.fTableView.rowHeight + self.fTableView.intercellSpacing.height;
|
2022-06-16 17:55:33 +00:00
|
|
|
return contentMinHeight;
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:59:54 +00:00
|
|
|
- (CGFloat)toolbarHeight
|
|
|
|
{
|
|
|
|
return self.fWindow.frame.size.height - [self.fWindow contentRectForFrameRect:self.fWindow.frame].size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)mainWindowComponentHeight
|
|
|
|
{
|
|
|
|
CGFloat height = BOTTOM_BAR_HEIGHT;
|
|
|
|
if (self.fStatusBar)
|
|
|
|
{
|
|
|
|
height += STATUS_BAR_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.fFilterBar)
|
|
|
|
{
|
|
|
|
height += FILTER_BAR_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)scrollViewHeight
|
|
|
|
{
|
|
|
|
CGFloat height;
|
2022-06-18 17:39:22 +00:00
|
|
|
CGFloat minHeight = self.minScrollViewHeightAllowed;
|
2022-06-16 19:59:54 +00:00
|
|
|
|
|
|
|
if ([self.fDefaults boolForKey:@"AutoSize"])
|
|
|
|
{
|
|
|
|
NSUInteger groups = (self.fDisplayedTorrents.count > 0 && ![self.fDisplayedTorrents[0] isKindOfClass:[Torrent class]]) ?
|
|
|
|
self.fDisplayedTorrents.count :
|
|
|
|
0;
|
|
|
|
|
|
|
|
height = (GROUP_SEPARATOR_HEIGHT + self.fTableView.intercellSpacing.height) * groups +
|
|
|
|
(self.fTableView.rowHeight + self.fTableView.intercellSpacing.height) * (self.fTableView.numberOfRows - groups);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
height = NSHeight(self.fTableView.enclosingScrollView.frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
//make sure we dont go bigger that the screen height
|
|
|
|
NSScreen* screen = self.fWindow.screen;
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
NSSize maxSize = screen.frame.size;
|
|
|
|
maxSize.height -= self.toolbarHeight;
|
|
|
|
maxSize.height -= self.mainWindowComponentHeight;
|
|
|
|
|
|
|
|
//add a small buffer
|
|
|
|
maxSize.height -= 50;
|
|
|
|
|
|
|
|
if (height > maxSize.height)
|
|
|
|
{
|
|
|
|
height = maxSize.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//make sure we dont have zero height
|
|
|
|
if (height < minHeight)
|
|
|
|
{
|
|
|
|
height = minHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isFullScreen
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
return (self.fWindow.styleMask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;
|
2022-06-16 19:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillEnterFullScreen:(NSNotification*)notification
|
|
|
|
{
|
2022-06-18 17:39:22 +00:00
|
|
|
[self removeStackViewHeightConstraints];
|
2022-06-16 19:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidExitFullScreen:(NSNotification*)notification
|
|
|
|
{
|
|
|
|
[self updateForAutoSize];
|
|
|
|
}
|
|
|
|
|
2022-04-21 14:28:38 +00:00
|
|
|
- (void)updateForExpandCollapse
|
2009-12-13 21:42:45 +00:00
|
|
|
{
|
|
|
|
[self setWindowSizeToFit];
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setBottomCountText:YES];
|
2009-12-13 21:42:45 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)showMainWindow:(id)sender
|
2009-12-13 21:42:45 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fWindow makeKeyAndOrderFront:nil];
|
2009-12-13 21:42:45 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)windowDidBecomeMain:(NSNotification*)notification
|
2009-12-13 21:42:45 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fBadger clearCompleted];
|
2009-12-13 21:42:45 +00:00
|
|
|
[self updateUI];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applicationWillUnhide:(NSNotification*)notification
|
2007-09-26 04:12:57 +00:00
|
|
|
{
|
|
|
|
[self updateUI];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleQuickLook:(id)sender
|
2008-05-21 16:02:38 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([QLPreviewPanel sharedPreviewPanel].visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
|
|
|
|
}
|
2009-09-04 04:10:46 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
|
|
|
|
}
|
2008-05-21 16:02:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)linkHomepage:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:WEBSITE_URL]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)linkForums:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:FORUM_URL]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)linkGitHub:(id)sender
|
2008-09-07 14:51:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:GITHUB_URL]];
|
2008-09-07 14:51:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)linkDonate:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:DONATE_URL]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updaterWillRelaunchApplication:(SUUpdater*)updater
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fQuitRequested = YES;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcCallback:(tr_rpc_callback_type)type forTorrentStruct:(struct tr_torrent*)torrentStruct
|
2008-05-20 15:16:34 +00:00
|
|
|
{
|
2012-02-11 05:13:46 +00:00
|
|
|
@autoreleasepool
|
2008-05-20 15:16:34 +00:00
|
|
|
{
|
2012-02-11 05:13:46 +00:00
|
|
|
//get the torrent
|
2021-08-15 09:41:48 +00:00
|
|
|
__block Torrent* torrent = nil;
|
2012-02-11 05:13:46 +00:00
|
|
|
if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED && type != TR_RPC_SESSION_CLOSE))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents enumerateObjectsWithOptions:NSEnumerationConcurrent
|
2022-03-30 21:52:23 +00:00
|
|
|
usingBlock:^(Torrent* checkTorrent, NSUInteger idx, BOOL* stop) {
|
|
|
|
if (torrentStruct == checkTorrent.torrentStruct)
|
|
|
|
{
|
|
|
|
torrent = checkTorrent;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-03-04 04:12:54 +00:00
|
|
|
if (!torrent)
|
2008-11-08 22:13:00 +00:00
|
|
|
{
|
2012-02-11 05:13:46 +00:00
|
|
|
NSLog(@"No torrent found matching the given torrent struct from the RPC callback!");
|
|
|
|
return;
|
2008-11-08 22:13:00 +00:00
|
|
|
}
|
2012-02-11 05:13:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-03-04 04:01:38 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
switch (type)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_TORRENT_ADDED:
|
|
|
|
[self rpcAddTorrentStruct:torrentStruct];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_TORRENT_STARTED:
|
|
|
|
case TR_RPC_TORRENT_STOPPED:
|
|
|
|
[self rpcStartedStoppedTorrent:torrent];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_TORRENT_REMOVING:
|
|
|
|
[self rpcRemoveTorrent:torrent deleteData:NO];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_TORRENT_TRASHING:
|
|
|
|
[self rpcRemoveTorrent:torrent deleteData:YES];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_TORRENT_CHANGED:
|
|
|
|
[self rpcChangedTorrent:torrent];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_TORRENT_MOVED:
|
|
|
|
[self rpcMovedTorrent:torrent];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
|
|
|
|
[self rpcUpdateQueue];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_SESSION_CHANGED:
|
|
|
|
[_prefsController rpcUpdatePrefs];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_RPC_SESSION_CLOSE:
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fQuitRequested = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSApp terminate:self];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown RPC command received: %d", type);
|
2013-03-04 04:01:38 +00:00
|
|
|
}
|
|
|
|
});
|
2008-05-20 15:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcAddTorrentStruct:(struct tr_torrent*)torrentStruct
|
2008-05-27 00:52:18 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = nil;
|
2020-04-25 14:35:15 +00:00
|
|
|
if (tr_torrentGetDownloadDir(torrentStruct) != NULL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2020-04-25 14:35:15 +00:00
|
|
|
location = @(tr_torrentGetDownloadDir(torrentStruct));
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
Torrent* torrent = [[Torrent alloc] initWithTorrentStruct:torrentStruct location:location lib:self.fLib];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-09-27 01:37:41 +00:00
|
|
|
//change the location if the group calls for it (this has to wait until after the torrent is created)
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([GroupsController.groups usesCustomDownloadLocationForIndex:torrent.groupValue])
|
2011-09-27 01:37:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
location = [GroupsController.groups customDownloadLocationForIndex:torrent.groupValue];
|
|
|
|
[torrent changeDownloadFolderBeforeUsing:location determinationType:TorrentDeterminationAutomatic];
|
2011-09-27 01:37:41 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-27 00:52:18 +00:00
|
|
|
[torrent update];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fAddingTransfers)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAddingTransfers = [[NSMutableSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fAddingTransfers addObject:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
[self fullUpdateUI];
|
2008-05-27 00:52:18 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcRemoveTorrent:(Torrent*)torrent deleteData:(BOOL)deleteData
|
2008-05-27 19:05:48 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self confirmRemoveTorrents:@[ torrent ] deleteData:deleteData];
|
2011-02-06 17:32:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcStartedStoppedTorrent:(Torrent*)torrent
|
2008-06-03 16:20:21 +00:00
|
|
|
{
|
|
|
|
[torrent update];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 16:20:21 +00:00
|
|
|
[self updateUI];
|
2011-02-20 03:58:50 +00:00
|
|
|
[self applyFilter];
|
2008-06-03 16:20:21 +00:00
|
|
|
[self updateTorrentHistory];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcChangedTorrent:(Torrent*)torrent
|
2008-06-03 16:20:21 +00:00
|
|
|
{
|
|
|
|
[torrent update];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fTableView.selectedTorrents containsObject:torrent])
|
2008-06-03 16:28:09 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController updateInfoStats]; //this will reload the file table
|
|
|
|
[self.fInfoController updateOptions];
|
2008-06-03 16:28:09 +00:00
|
|
|
}
|
2008-06-03 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcMovedTorrent:(Torrent*)torrent
|
2009-10-21 22:20:43 +00:00
|
|
|
{
|
|
|
|
[torrent update];
|
2010-11-13 16:11:22 +00:00
|
|
|
[torrent updateTimeMachineExclude];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fTableView.selectedTorrents containsObject:torrent])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fInfoController updateInfoStats];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-21 22:20:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcUpdateQueue
|
2011-08-27 23:54:10 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-27 23:54:10 +00:00
|
|
|
[torrent update];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* descriptor = [NSSortDescriptor sortDescriptorWithKey:@"queuePosition" ascending:YES];
|
|
|
|
NSArray* descriptors = @[ descriptor ];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTorrents sortUsingDescriptors:descriptors];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 19:00:55 +00:00
|
|
|
[self sortTorrentsAndIncludeQueueOrder:YES];
|
2011-08-27 23:54:10 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|