Changeset 9561


Ignore:
Timestamp:
Nov 25, 2009, 4:11:52 AM (12 years ago)
Author:
livings124
Message:

start laying a little magnet link groundwork, and remove redundant torrent parse when creating torrent objects

Location:
trunk/macosx
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r9348 r9561  
    117117}
    118118
    119 - (void) openFiles:             (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path;
    120 - (void) askOpenConfirmed:      (AddWindowController *) addController add: (BOOL) add;
    121 - (void) openCreatedFile:       (NSNotification *) notification;
    122 - (void) openFilesWithDict:     (NSDictionary *) dictionary;
    123 - (void) openShowSheet:         (id) sender;
     119- (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path;
     120- (void) openMagnet: (NSString *) address;
     121
     122- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add;
     123- (void) openCreatedFile: (NSNotification *) notification;
     124- (void) openFilesWithDict: (NSDictionary *) dictionary;
     125- (void) openShowSheet: (id) sender;
    124126
    125127- (void) invalidOpenAlert: (NSString *) filename;
  • trunk/macosx/Controller.m

    r9453 r9561  
    934934}
    935935
     936- (void) openMagnet: (NSString *) address
     937{
     938    Torrent * torrent;
     939    if (!(torrent = [[Torrent alloc] initWithMagnetAddress: address location: nil lib: fLib]))
     940    {
     941        #warning should we do something here?
     942        return;
     943    }
     944   
     945    #warning should we do this?
     946    [torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];
     947   
     948    [torrent update];
     949    [fTorrents addObject: torrent];
     950    [torrent release];
     951
     952    [self updateTorrentsInQueue];
     953}
     954
    936955- (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add
    937956{
     
    11111130   
    11121131    NSString * urlString = [fURLSheetTextField stringValue];
    1113     if ([urlString rangeOfString: @"://"].location == NSNotFound)
    1114     {
    1115         if ([urlString rangeOfString: @"."].location == NSNotFound)
    1116         {
    1117             NSInteger beforeCom;
    1118             if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound)
    1119                 urlString = [NSString stringWithFormat: @"http://www.%@.com/%@",
    1120                                 [urlString substringToIndex: beforeCom],
    1121                                 [urlString substringFromIndex: beforeCom + 1]];
     1132   
     1133    if ([urlString compare: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)])
     1134        [self openMagnet: urlString];
     1135    else
     1136    {
     1137        if ([urlString rangeOfString: @"://"].location == NSNotFound)
     1138        {
     1139            if ([urlString rangeOfString: @"."].location == NSNotFound)
     1140            {
     1141                NSInteger beforeCom;
     1142                if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound)
     1143                    urlString = [NSString stringWithFormat: @"http://www.%@.com/%@",
     1144                                    [urlString substringToIndex: beforeCom],
     1145                                    [urlString substringFromIndex: beforeCom + 1]];
     1146                else
     1147                    urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString];
     1148            }
    11221149            else
    1123                 urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString];
    1124         }
     1150                urlString = [@"http://" stringByAppendingString: urlString];
     1151        }
     1152       
     1153       
    11251154        else
    1126             urlString = [@"http://" stringByAppendingString: urlString];
    1127     }
    1128    
    1129     NSURL * url = [NSURL URLWithString: urlString];
    1130     [self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO];
     1155        {
     1156            NSURL * url = [NSURL URLWithString: urlString];
     1157            [self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO];
     1158        }
     1159    }
    11311160}
    11321161
  • trunk/macosx/FileOutlineController.m

    r9347 r9561  
    359359    if (action == @selector(setCheck:))
    360360    {
    361         if ([fOutline numberOfSelectedRows] <= 0)
     361        if ([fOutline numberOfSelectedRows] == 0)
    362362            return NO;
    363363       
     
    373373    if (action == @selector(setOnlySelectedCheck:))
    374374    {
    375         if ([fOutline numberOfSelectedRows] <= 0)
     375        if ([fOutline numberOfSelectedRows] == 0)
    376376            return NO;
    377377       
     
    386386    if (action == @selector(setPriority:))
    387387    {
    388         if ([fOutline numberOfSelectedRows] <= 0)
     388        if ([fOutline numberOfSelectedRows] == 0)
    389389        {
    390390            [menuItem setState: NSOffState];
     
    405405            case FILE_PRIORITY_LOW_TAG:
    406406                priority = TR_PRI_LOW;
     407                break;
    407408        }
    408409       
    409410        BOOL current = NO, canChange = NO;
    410         NSIndexSet * fileIndexSet;
    411411        for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    412412        {
    413             fileIndexSet = [[fOutline itemAtRow: i] indexes];
     413            NSIndexSet * fileIndexSet = [[fOutline itemAtRow: i] indexes];
    414414            if (![fTorrent canChangeDownloadCheckForFiles: fileIndexSet])
    415415                continue;
  • trunk/macosx/ProgressGradients.m

    r9491 r9561  
    4646{
    4747    if (!fProgressWhiteGradient)
    48         fProgressWhiteGradient = [[[self class] progressGradientForRed: 0.95 green: 0.95  blue: 0.95] retain];
     48        fProgressWhiteGradient = [[[self class] progressGradientForRed: 0.95 green: 0.95 blue: 0.95] retain];
    4949    return fProgressWhiteGradient;
    5050}
     
    5454{
    5555    if (!fProgressGrayGradient)
    56         fProgressGrayGradient = [[[self class] progressGradientForRed: 0.7 green: 0.7  blue: 0.7] retain];
     56        fProgressGrayGradient = [[[self class] progressGradientForRed: 0.7 green: 0.7 blue: 0.7] retain];
    5757    return fProgressGrayGradient;
    5858}
     
    6262{
    6363    if (!fProgressLightGrayGradient)
    64         fProgressLightGrayGradient = [[[self class] progressGradientForRed: 0.87 green: 0.87  blue: 0.87] retain];
     64        fProgressLightGrayGradient = [[[self class] progressGradientForRed: 0.87 green: 0.87 blue: 0.87] retain];
    6565    return fProgressLightGrayGradient;
    6666}
     
    7070{
    7171    if (!fProgressBlueGradient)
    72         fProgressBlueGradient = [[[self class] progressGradientForRed: 0.35 green: 0.67  blue: 0.98] retain];
     72        fProgressBlueGradient = [[[self class] progressGradientForRed: 0.35 green: 0.67 blue: 0.98] retain];
    7373    return fProgressBlueGradient;
    7474}
     
    7878{
    7979    if (!fProgressDarkBlueGradient)
    80         fProgressDarkBlueGradient = [[[self class] progressGradientForRed: 0.616 green: 0.722  blue: 0.776] retain];
     80        fProgressDarkBlueGradient = [[[self class] progressGradientForRed: 0.616 green: 0.722 blue: 0.776] retain];
    8181    return fProgressDarkBlueGradient;
    8282}
     
    8686{
    8787    if (!fProgressGreenGradient)
    88         fProgressGreenGradient = [[[self class] progressGradientForRed: 0.44 green: 0.89  blue: 0.40] retain];
     88        fProgressGreenGradient = [[[self class] progressGradientForRed: 0.44 green: 0.89 blue: 0.40] retain];
    8989    return fProgressGreenGradient;
    9090}
     
    9494{
    9595    if (!fProgressLightGreenGradient)
    96         fProgressLightGreenGradient = [[[self class] progressGradientForRed: 0.62 green: 0.99  blue: 0.58] retain];
     96        fProgressLightGreenGradient = [[[self class] progressGradientForRed: 0.62 green: 0.99 blue: 0.58] retain];
    9797    return fProgressLightGreenGradient;
    9898}
     
    102102{
    103103    if (!fProgressDarkGreenGradient)
    104         fProgressDarkGreenGradient = [[[self class] progressGradientForRed: 0.627 green: 0.714  blue: 0.639] retain];
     104        fProgressDarkGreenGradient = [[[self class] progressGradientForRed: 0.627 green: 0.714 blue: 0.639] retain];
    105105    return fProgressDarkGreenGradient;
    106106}
     
    110110{
    111111    if (!fProgressRedGradient)
    112         fProgressRedGradient = [[[self class] progressGradientForRed: 0.902 green: 0.439  blue: 0.451] retain];
     112        fProgressRedGradient = [[[self class] progressGradientForRed: 0.902 green: 0.439 blue: 0.451] retain];
    113113    return fProgressRedGradient;
    114114}
     
    118118{
    119119    if (!fProgressYellowGradient)
    120         fProgressYellowGradient = [[[self class] progressGradientForRed: 0.933 green: 0.890  blue: 0.243] retain];
     120        fProgressYellowGradient = [[[self class] progressGradientForRed: 0.933 green: 0.890 blue: 0.243] retain];
    121121    return fProgressYellowGradient;
    122122}
  • trunk/macosx/Torrent.h

    r9539 r9561  
    6060        lib: (tr_session *) lib;
    6161- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib;
     62- (id) initWithMagnetAddress: (NSString *) address location: (NSString *) location lib: (tr_session *) lib;
    6263- (id) initWithHistory: (NSDictionary *) history lib: (tr_session *) lib forcePause: (BOOL) pause;
    6364
  • trunk/macosx/Torrent.m

    r9539 r9561  
    3535        waitToStart: (NSNumber *) waitToStart
    3636        groupValue: (NSNumber *) groupValue
     37        #warning legacy download folder isn't necessarily legacy
    3738        legacyDownloadFolder: (NSString *) downloadFolder legacyIncompleteFolder: (NSString *) incompleteFolder;
    3839
     
    9192            waitToStart: nil groupValue: nil
    9293            legacyDownloadFolder: location legacyIncompleteFolder: nil];
     94   
     95    return self;
     96}
     97
     98#warning need location (and use it)?
     99- (id) initWithMagnetAddress: (NSString *) address location: (NSString *) location lib: (tr_session *) lib
     100{
     101    #warning move into real constructor?
     102    //set libtransmission settings for initialization
     103    tr_ctor * ctor = tr_ctorNew(lib);
     104    tr_ctorSetPaused(ctor, TR_FORCE, YES);
     105   
     106    const tr_parse_result result = tr_ctorSetMagnet(ctor, [address UTF8String]);
     107   
     108    tr_torrent * handle = NULL;
     109    if (result == TR_PARSE_OK)
     110        handle = tr_torrentNew(ctor, NULL);
     111   
     112    tr_ctorFree(ctor);
     113   
     114    if (handle)
     115        self = [self initWithPath: nil hash: nil torrentStruct: handle lib: lib
     116                waitToStart: nil groupValue: nil
     117                legacyDownloadFolder: location legacyIncompleteFolder: nil];
    93118   
    94119    return self;
     
    14871512   
    14881513    if (torrentStruct)
    1489     {
    14901514        fHandle = torrentStruct;
    1491         fInfo = tr_torrentInfo(fHandle);
    1492     }
    14931515    else
    14941516    {
     
    14971519        tr_ctorSetPaused(ctor, TR_FORCE, YES);
    14981520       
    1499         int result = TR_PARSE_ERR;
     1521        tr_parse_result result = TR_PARSE_ERR;
    15001522        if (path)
    15011523            result = tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
     
    15071529        if (result == TR_PARSE_OK)
    15081530        {
    1509             tr_info info;
    1510             result = tr_torrentParse(ctor, &info);
     1531            if (downloadFolder)
     1532                tr_ctorSetDownloadDir(ctor, TR_FORCE, [downloadFolder UTF8String]);
     1533            if (incompleteFolder)
     1534                tr_ctorSetIncompleteDir(ctor, [incompleteFolder UTF8String]);
    15111535           
    1512             if (result == TR_PARSE_OK)
    1513             {
    1514                 if (downloadFolder)
    1515                     tr_ctorSetDownloadDir(ctor, TR_FORCE, [downloadFolder UTF8String]);
    1516                 if (incompleteFolder)
    1517                     tr_ctorSetIncompleteDir(ctor, [incompleteFolder UTF8String]);
    1518                
    1519                 fHandle = tr_torrentNew(ctor, NULL);
    1520             }
    1521             if (result != TR_PARSE_ERR)
    1522                 tr_metainfoFree(&info);
     1536            fHandle = tr_torrentNew(ctor, NULL);
    15231537        }
    15241538       
     
    15301544            return nil;
    15311545        }
    1532        
    1533         fInfo = tr_torrentInfo(fHandle);
    1534     }
     1546    }
     1547
     1548    fInfo = tr_torrentInfo(fHandle);
    15351549   
    15361550    tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self);
  • trunk/macosx/TorrentGroup.m

    r7659 r9561  
    6969- (CGFloat) uploadRate
    7070{
    71     CGFloat rate = 0.0f;
     71    CGFloat rate = 0.0;
    7272    for (Torrent * torrent in fTorrents)
    7373        rate += [torrent uploadRate];
     
    7878- (CGFloat) downloadRate
    7979{
    80     CGFloat rate = 0.0f;
     80    CGFloat rate = 0.0;
    8181    for (Torrent * torrent in fTorrents)
    8282        rate += [torrent downloadRate];
Note: See TracChangeset for help on using the changeset viewer.