2014-01-10 17:50:05 +00:00
|
|
|
//
|
|
|
|
// ShareTorrentFileHelper.m
|
|
|
|
// Transmission
|
|
|
|
//
|
|
|
|
// Created by Mitchell Livingston on 1/10/14.
|
|
|
|
// Copyright (c) 2014 The Transmission Project. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ShareTorrentFileHelper.h"
|
|
|
|
#import "Controller.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
|
|
|
|
@implementation ShareTorrentFileHelper
|
|
|
|
|
|
|
|
+ (ShareTorrentFileHelper *) sharedHelper
|
|
|
|
{
|
|
|
|
static ShareTorrentFileHelper *helper;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
helper = [[ShareTorrentFileHelper alloc] init];
|
|
|
|
});
|
|
|
|
return helper;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) shareTorrentURLs
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSArray * torrents = ((Controller *)NSApp.delegate).selectedTorrents;
|
|
|
|
NSMutableArray * fileURLs = [NSMutableArray arrayWithCapacity: torrents.count];
|
2014-01-10 17:50:05 +00:00
|
|
|
for (Torrent * torrent in torrents)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSString * location = torrent.torrentLocation;
|
|
|
|
if (location.length > 0) {
|
2014-01-10 17:50:05 +00:00
|
|
|
[fileURLs addObject: [NSURL fileURLWithPath: location]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fileURLs;
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:06:34 +00:00
|
|
|
- (NSArray *) menuItems
|
2014-01-10 17:50:05 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSArray * services = [NSSharingService sharingServicesForItems: self.shareTorrentURLs];
|
|
|
|
NSMutableArray * items = [NSMutableArray arrayWithCapacity: services.count];
|
2014-01-10 17:50:05 +00:00
|
|
|
for (NSSharingService * service in services)
|
|
|
|
{
|
|
|
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: service.title // 10.9: change to menuItemTitle
|
|
|
|
action: @selector(performShareAction:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
item.image = service.image;
|
|
|
|
item.representedObject = service;
|
2021-08-07 07:27:56 +00:00
|
|
|
service.delegate = (Controller *)NSApp.delegate;
|
2014-01-10 17:50:05 +00:00
|
|
|
item.target = self;
|
|
|
|
[items addObject: item];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2014-01-10 17:50:05 +00:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:06:34 +00:00
|
|
|
- (void) performShareAction: (NSMenuItem *) item
|
2014-01-10 17:50:05 +00:00
|
|
|
{
|
|
|
|
NSSharingService * service = item.representedObject;
|
2021-08-07 07:27:56 +00:00
|
|
|
[service performWithItems: self.shareTorrentURLs]; // on 10.9, use attachmentFileURLs?
|
2014-01-10 17:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|