1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00

support for adding a transfer through rpc

This commit is contained in:
Mitchell Livingston 2008-05-27 00:52:18 +00:00
parent c939cc4b98
commit ff929b1f6a
3 changed files with 31 additions and 10 deletions

View file

@ -40,7 +40,7 @@
typedef enum typedef enum
{ {
ADD_NORMAL, ADD_MANUAL,
ADD_AUTO, ADD_AUTO,
ADD_SHOW_OPTIONS, ADD_SHOW_OPTIONS,
ADD_URL, ADD_URL,

View file

@ -693,7 +693,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
- (void) application: (NSApplication *) app openFiles: (NSArray *) filenames - (void) application: (NSApplication *) app openFiles: (NSArray *) filenames
{ {
[self openFiles: filenames addType: ADD_NORMAL forcePath: nil]; [self openFiles: filenames addType: ADD_MANUAL forcePath: nil];
} }
- (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path - (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path
@ -884,7 +884,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
- (void) open: (NSArray *) files - (void) open: (NSArray *) files
{ {
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: files, @"Filenames", NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: files, @"Filenames",
[NSNumber numberWithInt: ADD_NORMAL], @"AddType", nil]; [NSNumber numberWithInt: ADD_MANUAL], @"AddType", nil];
[self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dict waitUntilDone: NO]; [self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dict waitUntilDone: NO];
} }
@ -906,7 +906,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
if (code == NSOKButton) if (code == NSOKButton)
{ {
NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: [panel filenames], @"Filenames", NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: [panel filenames], @"Filenames",
[NSNumber numberWithInt: [useOptions boolValue] ? ADD_SHOW_OPTIONS : ADD_NORMAL], @"AddType", nil]; [NSNumber numberWithInt: [useOptions boolValue] ? ADD_SHOW_OPTIONS : ADD_MANUAL], @"AddType", nil];
[self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO]; [self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
} }
} }
@ -4151,7 +4151,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//get the torrent //get the torrent
if (torrentStruct != NULL && type != TR_RPC_TORRENT_ADDED) if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED))
{ {
NSEnumerator * enumerator = [fTorrents objectEnumerator]; NSEnumerator * enumerator = [fTorrents objectEnumerator];
Torrent * torrent; Torrent * torrent;
@ -4169,6 +4169,8 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
switch (type) switch (type)
{ {
case TR_RPC_TORRENT_ADDED: case TR_RPC_TORRENT_ADDED:
[self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
[[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
break; break;
case TR_RPC_TORRENT_STARTED: case TR_RPC_TORRENT_STARTED:
break; break;
@ -4185,6 +4187,26 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[pool release]; [pool release];
} }
- (void) rpcAddTorrentStruct: (NSValue *) torrentStructPtr
{
tr_torrent * torrentStruct = (tr_torrent *)[torrentStructPtr pointerValue];
[torrentStructPtr release];
NSString * location = nil;
if (tr_torrentGetDownloadDir(torrentStruct) != NULL)
location = [NSString stringWithUTF8String: tr_torrentGetDownloadDir(torrentStruct)];
Torrent * torrent = [[Torrent alloc] initWithTorrentStruct: torrentStruct location: location lib: fLib];
[torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];
[torrent update];
[fTorrents addObject: torrent];
[torrent release];
[self updateTorrentsInQueue];
}
/*- (void) ipcQuit /*- (void) ipcQuit
{ {
fRemoteQuit = YES; fRemoteQuit = YES;

View file

@ -1558,12 +1558,11 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
if (torrentStruct) if (torrentStruct)
{ {
fHandle = torrentStruct; fHandle = torrentStruct;
fInfo = tr_torrentInfo(fHandle);
const tr_info * info = tr_torrentInfo(fHandle); NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: fInfo->name]]
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info->name]]
? fIncompleteFolder : fDownloadFolder; ? fIncompleteFolder : fDownloadFolder;
tr_torrentSetDownloadDir(fHandle, [currentDownloadFolder UTF8String]); tr_torrentSetDownloadDir(fHandle, [currentDownloadFolder UTF8String]);
tr_metainfoFree(info);
} }
else else
{ {
@ -1607,12 +1606,12 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
[self release]; [self release];
return nil; return nil;
} }
fInfo = tr_torrentInfo(fHandle);
} }
tr_torrentSetStatusCallback(fHandle, completenessChangeCallback, self); tr_torrentSetStatusCallback(fHandle, completenessChangeCallback, self);
fInfo = tr_torrentInfo(fHandle);
fNameString = [[NSString alloc] initWithUTF8String: fInfo->name]; fNameString = [[NSString alloc] initWithUTF8String: fInfo->name];
fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString]; fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];