mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
Make Copy Torrent dialog a sheet.
This commit is contained in:
parent
86edc01368
commit
2ef0725b59
2 changed files with 56 additions and 30 deletions
|
@ -105,6 +105,9 @@
|
|||
deleteData: (BOOL) deleteData;
|
||||
|
||||
- (void) copyTorrentFile: (id) sender;
|
||||
- (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents;
|
||||
- (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (int) code
|
||||
contextInfo: (NSMutableArray *) torrents;
|
||||
|
||||
- (void) revealFile: (id) sender;
|
||||
|
||||
|
|
|
@ -632,38 +632,61 @@ static void sleepCallBack( void * controller, io_service_t y,
|
|||
|
||||
- (void) copyTorrentFile: (id) sender
|
||||
{
|
||||
Torrent * torrent;
|
||||
NSEnumerator * enumerator = [[self torrentsAtIndexes:
|
||||
[fTableView selectedRowIndexes]] objectEnumerator];
|
||||
|
||||
while ((torrent = [enumerator nextObject]))
|
||||
[self copyTorrentFileForTorrents: [[NSMutableArray alloc] initWithArray:
|
||||
[self torrentsAtIndexes: [fTableView selectedRowIndexes]]]];
|
||||
}
|
||||
|
||||
- (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents
|
||||
{
|
||||
if ([torrents count] == 0)
|
||||
{
|
||||
//warn user if torrent file can't be found
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent torrentLocation]])
|
||||
{
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert addButtonWithTitle: @"OK"];
|
||||
[alert setMessageText: [NSString stringWithFormat:
|
||||
@"Copy of \"%@\" Cannot Be Created", [torrent name]]];
|
||||
[alert setInformativeText: [NSString stringWithFormat:
|
||||
@"The torrent file (%@) cannot be found.", [torrent torrentLocation]]];
|
||||
[alert setAlertStyle: NSWarningAlertStyle];
|
||||
|
||||
[alert runModal];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//save with extension
|
||||
NSSavePanel * savePanel = [NSSavePanel savePanel];
|
||||
[savePanel setRequiredFileType: @"torrent"];
|
||||
[savePanel setCanSelectHiddenExtension: YES];
|
||||
|
||||
//if save successful, copy torrent to new location with name of data file
|
||||
if ([savePanel runModalForDirectory: nil file: [torrent name]] == NSOKButton)
|
||||
[[NSFileManager defaultManager] copyPath: [torrent torrentLocation]
|
||||
toPath: [savePanel filename] handler: nil];
|
||||
[torrents release];
|
||||
return;
|
||||
}
|
||||
|
||||
Torrent * torrent = [torrents objectAtIndex: 0];
|
||||
|
||||
//warn user if torrent file can't be found
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent torrentLocation]])
|
||||
{
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert addButtonWithTitle: @"OK"];
|
||||
[alert setMessageText: [NSString stringWithFormat:
|
||||
@"Copy of \"%@\" Cannot Be Created", [torrent name]]];
|
||||
[alert setInformativeText: [NSString stringWithFormat:
|
||||
@"The torrent file (%@) cannot be found.", [torrent torrentLocation]]];
|
||||
[alert setAlertStyle: NSWarningAlertStyle];
|
||||
|
||||
[alert runModal];
|
||||
|
||||
[torrents removeObjectAtIndex: 0];
|
||||
[self copyTorrentFileForTorrents: torrents];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSSavePanel * panel = [NSSavePanel savePanel];
|
||||
[panel setRequiredFileType: @"torrent"];
|
||||
[panel setExtensionHidden: NO];
|
||||
[panel setCanSelectHiddenExtension: NO];
|
||||
|
||||
[panel beginSheetForDirectory: nil file: [torrent name]
|
||||
modalForWindow: fWindow modalDelegate: self didEndSelector:
|
||||
@selector( saveTorrentCopySheetClosed:returnCode:contextInfo: )
|
||||
contextInfo: torrents];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (int) code
|
||||
contextInfo: (NSMutableArray *) torrents
|
||||
{
|
||||
//if save successful, copy torrent to new location with name of data file
|
||||
if (code == NSOKButton)
|
||||
[[NSFileManager defaultManager] copyPath: [[torrents objectAtIndex: 0] torrentLocation]
|
||||
toPath: [panel filename] handler: nil];
|
||||
|
||||
[torrents removeObjectAtIndex: 0];
|
||||
[self performSelectorOnMainThread: @selector(copyTorrentFileForTorrents:)
|
||||
withObject: torrents waitUntilDone: NO];
|
||||
}
|
||||
|
||||
- (void) revealFile: (id) sender
|
||||
|
|
Loading…
Reference in a new issue