1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 19:46:56 +00:00
transmission/macosx/ShareTorrentFileHelper.mm
Mike Gelfand b7ba261359
Port macOS client to C++ (#1830)
* Rename all .m (Obj-C) files to .mm (Obj-C++)

* Fix build in Obj-C++ mode

* Fix Xcode build
2021-09-24 07:56:57 -05:00

65 lines
1.9 KiB
Text

//
// 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
{
NSArray* torrents = ((Controller*)NSApp.delegate).selectedTorrents;
NSMutableArray* fileURLs = [NSMutableArray arrayWithCapacity:torrents.count];
for (Torrent* torrent in torrents)
{
NSString* location = torrent.torrentLocation;
if (location.length > 0)
{
[fileURLs addObject:[NSURL fileURLWithPath:location]];
}
}
return fileURLs;
}
- (NSArray*)menuItems
{
NSArray* services = [NSSharingService sharingServicesForItems:self.shareTorrentURLs];
NSMutableArray* items = [NSMutableArray arrayWithCapacity:services.count];
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;
service.delegate = (Controller*)NSApp.delegate;
item.target = self;
[items addObject:item];
}
return items;
}
- (void)performShareAction:(NSMenuItem*)item
{
NSSharingService* service = item.representedObject;
[service performWithItems:self.shareTorrentURLs]; // on 10.9, use attachmentFileURLs?
}
@end