source: trunk/macosx/ShareTorrentFileHelper.m @ 14221

Last change on this file since 14221 was 14221, checked in by livings124, 8 years ago

#5584 Share option in File menu and context menu

File size: 1.9 KB
Line 
1//
2//  ShareTorrentFileHelper.m
3//  Transmission
4//
5//  Created by Mitchell Livingston on 1/10/14.
6//  Copyright (c) 2014 The Transmission Project. All rights reserved.
7//
8
9#import "ShareTorrentFileHelper.h"
10#import "Controller.h"
11#import "Torrent.h"
12
13@implementation ShareTorrentFileHelper
14
15+ (ShareTorrentFileHelper *) sharedHelper
16{
17    static ShareTorrentFileHelper *helper;
18    static dispatch_once_t onceToken;
19    dispatch_once(&onceToken, ^{
20        helper = [[ShareTorrentFileHelper alloc] init];
21    });
22    return helper;
23}
24
25- (NSArray *) shareTorrentURLs
26{
27    NSArray * torrents = [(Controller *)[NSApp delegate] selectedTorrents];
28    NSMutableArray * fileURLs = [NSMutableArray arrayWithCapacity: [torrents count]];
29    for (Torrent * torrent in torrents)
30    {
31        NSString * location = [torrent torrentLocation];
32        if ([location length] > 0) {
33            [fileURLs addObject: [NSURL fileURLWithPath: location]];
34        }
35    }
36    return fileURLs;
37}
38
39- (NSArray *)menuItems
40{
41    NSArray * services = [NSSharingService sharingServicesForItems: [self shareTorrentURLs]];
42    NSMutableArray * items = [NSMutableArray arrayWithCapacity: [services count]];
43    for (NSSharingService * service in services)
44    {
45        NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: service.title // 10.9: change to menuItemTitle
46                                                      action: @selector(performShareAction:)
47                                               keyEquivalent: @""];
48        item.image = service.image;
49        item.representedObject = service;
50        service.delegate = (Controller *)[NSApp delegate];
51        item.target = self;
52        [items addObject: item];
53        [item release];
54    }
55   
56    return items;
57}
58
59
60- (void)performShareAction:(NSMenuItem *)item
61{
62    NSSharingService * service = item.representedObject;
63    [service performWithItems: [self shareTorrentURLs]]; // on 10.9, use attachmentFileURLs?
64}
65
66@end
Note: See TracBrowser for help on using the repository browser.