1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

Make Copy Torrent dialog a sheet.

This commit is contained in:
Mitchell Livingston 2006-06-11 00:16:31 +00:00
parent 86edc01368
commit 2ef0725b59
2 changed files with 56 additions and 30 deletions

View file

@ -105,6 +105,9 @@
deleteData: (BOOL) deleteData; deleteData: (BOOL) deleteData;
- (void) copyTorrentFile: (id) sender; - (void) copyTorrentFile: (id) sender;
- (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents;
- (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (int) code
contextInfo: (NSMutableArray *) torrents;
- (void) revealFile: (id) sender; - (void) revealFile: (id) sender;

View file

@ -632,38 +632,61 @@ static void sleepCallBack( void * controller, io_service_t y,
- (void) copyTorrentFile: (id) sender - (void) copyTorrentFile: (id) sender
{ {
Torrent * torrent; [self copyTorrentFileForTorrents: [[NSMutableArray alloc] initWithArray:
NSEnumerator * enumerator = [[self torrentsAtIndexes: [self torrentsAtIndexes: [fTableView selectedRowIndexes]]]];
[fTableView selectedRowIndexes]] objectEnumerator]; }
while ((torrent = [enumerator nextObject])) - (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents
{
if ([torrents count] == 0)
{ {
//warn user if torrent file can't be found [torrents release];
if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent torrentLocation]]) return;
{
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];
} }
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 - (void) revealFile: (id) sender