1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 19:03:04 +00:00
transmission/macosx/ShareTorrentFileHelper.m
Dmitry Serov af3a4d4557
Modern Objective-C syntax (#509)
* Update enabled complier warnings

* Convert to Modern Objective-C syntax using Xcode's tool

* Convert to modern objc syntax manually, fix some PR issues

* Remove unnecessary parentheses

* Use property syntax for all custom properties

* Use property syntax for all system properties

* Fix erroneously autoreleased values

* Revert VDKQueue to old objc syntax

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
Co-authored-by: Mitch Livingston <livings124@mac.com>
2021-08-07 10:27:56 +03:00

64 lines
1.9 KiB
Objective-C

//
// 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