diff --git a/macosx/Controller.h b/macosx/Controller.h index 45d3000f6..ee9485efa 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -116,11 +116,13 @@ typedef enum BOOL fSoundPlaying; } -- (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path; -- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add; -- (void) openCreatedFile: (NSNotification *) notification; -- (void) openFilesWithDict: (NSDictionary *) dictionary; -- (void) openShowSheet: (id) sender; +- (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path; +- (void) openMagnet: (NSString *) address; + +- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add; +- (void) openCreatedFile: (NSNotification *) notification; +- (void) openFilesWithDict: (NSDictionary *) dictionary; +- (void) openShowSheet: (id) sender; - (void) invalidOpenAlert: (NSString *) filename; - (void) duplicateOpenAlert: (NSString *) name; diff --git a/macosx/Controller.m b/macosx/Controller.m index 6ed4fcba8..0ce6742ba 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -933,6 +933,25 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [self updateTorrentsInQueue]; } +- (void) openMagnet: (NSString *) address +{ + Torrent * torrent; + if (!(torrent = [[Torrent alloc] initWithMagnetAddress: address location: nil lib: fLib])) + { + #warning should we do something here? + return; + } + + #warning should we do this? + [torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]]; + + [torrent update]; + [fTorrents addObject: torrent]; + [torrent release]; + + [self updateTorrentsInQueue]; +} + - (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add { Torrent * torrent = [addController torrent]; @@ -1110,24 +1129,34 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy return; NSString * urlString = [fURLSheetTextField stringValue]; - if ([urlString rangeOfString: @"://"].location == NSNotFound) - { - if ([urlString rangeOfString: @"."].location == NSNotFound) - { - NSInteger beforeCom; - if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound) - urlString = [NSString stringWithFormat: @"http://www.%@.com/%@", - [urlString substringToIndex: beforeCom], - [urlString substringFromIndex: beforeCom + 1]]; - else - urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString]; - } - else - urlString = [@"http://" stringByAppendingString: urlString]; - } - NSURL * url = [NSURL URLWithString: urlString]; - [self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO]; + if ([urlString compare: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)]) + [self openMagnet: urlString]; + else + { + if ([urlString rangeOfString: @"://"].location == NSNotFound) + { + if ([urlString rangeOfString: @"."].location == NSNotFound) + { + NSInteger beforeCom; + if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound) + urlString = [NSString stringWithFormat: @"http://www.%@.com/%@", + [urlString substringToIndex: beforeCom], + [urlString substringFromIndex: beforeCom + 1]]; + else + urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString]; + } + else + urlString = [@"http://" stringByAppendingString: urlString]; + } + + + else + { + NSURL * url = [NSURL URLWithString: urlString]; + [self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO]; + } + } } - (void) createFile: (id) sender diff --git a/macosx/FileOutlineController.m b/macosx/FileOutlineController.m index 838f4ae3c..797a08339 100644 --- a/macosx/FileOutlineController.m +++ b/macosx/FileOutlineController.m @@ -358,7 +358,7 @@ typedef enum if (action == @selector(setCheck:)) { - if ([fOutline numberOfSelectedRows] <= 0) + if ([fOutline numberOfSelectedRows] == 0) return NO; NSIndexSet * indexSet = [fOutline selectedRowIndexes]; @@ -372,7 +372,7 @@ typedef enum if (action == @selector(setOnlySelectedCheck:)) { - if ([fOutline numberOfSelectedRows] <= 0) + if ([fOutline numberOfSelectedRows] == 0) return NO; NSIndexSet * indexSet = [fOutline selectedRowIndexes]; @@ -385,7 +385,7 @@ typedef enum if (action == @selector(setPriority:)) { - if ([fOutline numberOfSelectedRows] <= 0) + if ([fOutline numberOfSelectedRows] == 0) { [menuItem setState: NSOffState]; return NO; @@ -404,13 +404,13 @@ typedef enum break; case FILE_PRIORITY_LOW_TAG: priority = TR_PRI_LOW; + break; } BOOL current = NO, canChange = NO; - NSIndexSet * fileIndexSet; for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) { - fileIndexSet = [[fOutline itemAtRow: i] indexes]; + NSIndexSet * fileIndexSet = [[fOutline itemAtRow: i] indexes]; if (![fTorrent canChangeDownloadCheckForFiles: fileIndexSet]) continue; diff --git a/macosx/ProgressGradients.m b/macosx/ProgressGradients.m index 9be63444a..aaa1937d9 100644 --- a/macosx/ProgressGradients.m +++ b/macosx/ProgressGradients.m @@ -45,7 +45,7 @@ NSGradient * fProgressWhiteGradient = nil; + (NSGradient *) progressWhiteGradient { if (!fProgressWhiteGradient) - fProgressWhiteGradient = [[[self class] progressGradientForRed: 0.95 green: 0.95 blue: 0.95] retain]; + fProgressWhiteGradient = [[[self class] progressGradientForRed: 0.95 green: 0.95 blue: 0.95] retain]; return fProgressWhiteGradient; } @@ -53,7 +53,7 @@ NSGradient * fProgressGrayGradient = nil; + (NSGradient *) progressGrayGradient { if (!fProgressGrayGradient) - fProgressGrayGradient = [[[self class] progressGradientForRed: 0.7 green: 0.7 blue: 0.7] retain]; + fProgressGrayGradient = [[[self class] progressGradientForRed: 0.7 green: 0.7 blue: 0.7] retain]; return fProgressGrayGradient; } @@ -61,7 +61,7 @@ NSGradient * fProgressLightGrayGradient = nil; + (NSGradient *) progressLightGrayGradient { if (!fProgressLightGrayGradient) - fProgressLightGrayGradient = [[[self class] progressGradientForRed: 0.87 green: 0.87 blue: 0.87] retain]; + fProgressLightGrayGradient = [[[self class] progressGradientForRed: 0.87 green: 0.87 blue: 0.87] retain]; return fProgressLightGrayGradient; } @@ -69,7 +69,7 @@ NSGradient * fProgressBlueGradient = nil; + (NSGradient *) progressBlueGradient { if (!fProgressBlueGradient) - fProgressBlueGradient = [[[self class] progressGradientForRed: 0.35 green: 0.67 blue: 0.98] retain]; + fProgressBlueGradient = [[[self class] progressGradientForRed: 0.35 green: 0.67 blue: 0.98] retain]; return fProgressBlueGradient; } @@ -77,7 +77,7 @@ NSGradient * fProgressDarkBlueGradient = nil; + (NSGradient *) progressDarkBlueGradient { if (!fProgressDarkBlueGradient) - fProgressDarkBlueGradient = [[[self class] progressGradientForRed: 0.616 green: 0.722 blue: 0.776] retain]; + fProgressDarkBlueGradient = [[[self class] progressGradientForRed: 0.616 green: 0.722 blue: 0.776] retain]; return fProgressDarkBlueGradient; } @@ -85,7 +85,7 @@ NSGradient * fProgressGreenGradient = nil; + (NSGradient *) progressGreenGradient { if (!fProgressGreenGradient) - fProgressGreenGradient = [[[self class] progressGradientForRed: 0.44 green: 0.89 blue: 0.40] retain]; + fProgressGreenGradient = [[[self class] progressGradientForRed: 0.44 green: 0.89 blue: 0.40] retain]; return fProgressGreenGradient; } @@ -93,7 +93,7 @@ NSGradient * fProgressLightGreenGradient = nil; + (NSGradient *) progressLightGreenGradient { if (!fProgressLightGreenGradient) - fProgressLightGreenGradient = [[[self class] progressGradientForRed: 0.62 green: 0.99 blue: 0.58] retain]; + fProgressLightGreenGradient = [[[self class] progressGradientForRed: 0.62 green: 0.99 blue: 0.58] retain]; return fProgressLightGreenGradient; } @@ -101,7 +101,7 @@ NSGradient * fProgressDarkGreenGradient = nil; + (NSGradient *) progressDarkGreenGradient { if (!fProgressDarkGreenGradient) - fProgressDarkGreenGradient = [[[self class] progressGradientForRed: 0.627 green: 0.714 blue: 0.639] retain]; + fProgressDarkGreenGradient = [[[self class] progressGradientForRed: 0.627 green: 0.714 blue: 0.639] retain]; return fProgressDarkGreenGradient; } @@ -109,7 +109,7 @@ NSGradient * fProgressRedGradient = nil; + (NSGradient *) progressRedGradient { if (!fProgressRedGradient) - fProgressRedGradient = [[[self class] progressGradientForRed: 0.902 green: 0.439 blue: 0.451] retain]; + fProgressRedGradient = [[[self class] progressGradientForRed: 0.902 green: 0.439 blue: 0.451] retain]; return fProgressRedGradient; } @@ -117,7 +117,7 @@ NSGradient * fProgressYellowGradient = nil; + (NSGradient *) progressYellowGradient { if (!fProgressYellowGradient) - fProgressYellowGradient = [[[self class] progressGradientForRed: 0.933 green: 0.890 blue: 0.243] retain]; + fProgressYellowGradient = [[[self class] progressGradientForRed: 0.933 green: 0.890 blue: 0.243] retain]; return fProgressYellowGradient; } diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 9a54a1cd3..74de08257 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -59,6 +59,7 @@ - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete lib: (tr_session *) lib; - (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib; +- (id) initWithMagnetAddress: (NSString *) address location: (NSString *) location lib: (tr_session *) lib; - (id) initWithHistory: (NSDictionary *) history lib: (tr_session *) lib forcePause: (BOOL) pause; - (NSDictionary *) history; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 89484ac4d..a7442751e 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -34,6 +34,7 @@ - (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib waitToStart: (NSNumber *) waitToStart groupValue: (NSNumber *) groupValue + #warning legacy download folder isn't necessarily legacy legacyDownloadFolder: (NSString *) downloadFolder legacyIncompleteFolder: (NSString *) incompleteFolder; - (void) createFileList; @@ -94,6 +95,30 @@ int trashDataFile(const char * filename) return self; } +#warning need location (and use it)? +- (id) initWithMagnetAddress: (NSString *) address location: (NSString *) location lib: (tr_session *) lib +{ + #warning move into real constructor? + //set libtransmission settings for initialization + tr_ctor * ctor = tr_ctorNew(lib); + tr_ctorSetPaused(ctor, TR_FORCE, YES); + + const tr_parse_result result = tr_ctorSetMagnet(ctor, [address UTF8String]); + + tr_torrent * handle = NULL; + if (result == TR_PARSE_OK) + handle = tr_torrentNew(ctor, NULL); + + tr_ctorFree(ctor); + + if (handle) + self = [self initWithPath: nil hash: nil torrentStruct: handle lib: lib + waitToStart: nil groupValue: nil + legacyDownloadFolder: location legacyIncompleteFolder: nil]; + + return self; +} + - (id) initWithHistory: (NSDictionary *) history lib: (tr_session *) lib forcePause: (BOOL) pause { self = [self initWithPath: [history objectForKey: @"InternalTorrentPath"] @@ -1486,17 +1511,14 @@ int trashDataFile(const char * filename) fDefaults = [NSUserDefaults standardUserDefaults]; if (torrentStruct) - { fHandle = torrentStruct; - fInfo = tr_torrentInfo(fHandle); - } else { //set libtransmission settings for initialization tr_ctor * ctor = tr_ctorNew(lib); tr_ctorSetPaused(ctor, TR_FORCE, YES); - int result = TR_PARSE_ERR; + tr_parse_result result = TR_PARSE_ERR; if (path) result = tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]); @@ -1506,20 +1528,12 @@ int trashDataFile(const char * filename) if (result == TR_PARSE_OK) { - tr_info info; - result = tr_torrentParse(ctor, &info); + if (downloadFolder) + tr_ctorSetDownloadDir(ctor, TR_FORCE, [downloadFolder UTF8String]); + if (incompleteFolder) + tr_ctorSetIncompleteDir(ctor, [incompleteFolder UTF8String]); - if (result == TR_PARSE_OK) - { - if (downloadFolder) - tr_ctorSetDownloadDir(ctor, TR_FORCE, [downloadFolder UTF8String]); - if (incompleteFolder) - tr_ctorSetIncompleteDir(ctor, [incompleteFolder UTF8String]); - - fHandle = tr_torrentNew(ctor, NULL); - } - if (result != TR_PARSE_ERR) - tr_metainfoFree(&info); + fHandle = tr_torrentNew(ctor, NULL); } tr_ctorFree(ctor); @@ -1529,9 +1543,9 @@ int trashDataFile(const char * filename) [self release]; return nil; } - - fInfo = tr_torrentInfo(fHandle); } + + fInfo = tr_torrentInfo(fHandle); tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self); tr_torrentSetRatioLimitHitCallback(fHandle, ratioLimitHitCallback, self); diff --git a/macosx/TorrentGroup.m b/macosx/TorrentGroup.m index 16279d136..7427cbee6 100644 --- a/macosx/TorrentGroup.m +++ b/macosx/TorrentGroup.m @@ -68,7 +68,7 @@ - (CGFloat) uploadRate { - CGFloat rate = 0.0f; + CGFloat rate = 0.0; for (Torrent * torrent in fTorrents) rate += [torrent uploadRate]; @@ -77,7 +77,7 @@ - (CGFloat) downloadRate { - CGFloat rate = 0.0f; + CGFloat rate = 0.0; for (Torrent * torrent in fTorrents) rate += [torrent downloadRate];