Ignore:
Timestamp:
Nov 26, 2009, 4:38:21 PM (13 years ago)
Author:
livings124
Message:

register to automatically accept when a user clicks a magnet link

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r9577 r9587  
    346346        tr_sessionSetRPCCallback(fLib, rpcCallback, self);
    347347       
     348        //register for dock icon drags
     349        [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
     350            forEventClass: kCoreEventClass andEventID: kAEOpenContents];
     351       
     352        //register for magnet URLs
     353        [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
     354        forEventClass: kInternetEventClass andEventID: kAEGetURL];
     355       
    348356        [GrowlApplicationBridge setGrowlDelegate: self];
    349357       
     
    566574{
    567575    [NSApp setServicesProvider: self];
    568    
    569     //register for dock icon drags
    570     [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
    571         forEventClass: kCoreEventClass andEventID: kAEOpenContents];
    572576   
    573577    //auto importing
     
    758762   
    759763    if (urlString)
    760         [self openURL: [NSURL URLWithString: urlString]];
     764        [self openURL: urlString];
    761765}
    762766
     
    10811085}
    10821086
    1083 - (void) openURL: (NSURL *) url
    1084 {
    1085     [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
    1086 }
    1087 
    1088 - (void) openURLShowSheet: (id) sender
    1089 {
    1090     [NSApp beginSheet: fURLSheetWindow modalForWindow: fWindow modalDelegate: self
    1091             didEndSelector: @selector(urlSheetDidEnd:returnCode:contextInfo:) contextInfo: nil];
    1092 }
    1093 
    1094 - (void) openURLEndSheet: (id) sender
    1095 {
    1096     [fURLSheetWindow orderOut: sender];
    1097     [NSApp endSheet: fURLSheetWindow returnCode: 1];
    1098 }
    1099 
    1100 - (void) openURLCancelEndSheet: (id) sender
    1101 {
    1102     [fURLSheetWindow orderOut: sender];
    1103     [NSApp endSheet: fURLSheetWindow returnCode: 0];
    1104 }
    1105 
    1106 - (void) controlTextDidChange: (NSNotification *) notification
    1107 {
    1108     if ([notification object] != fURLSheetTextField)
    1109         return;
    1110    
    1111     NSString * string = [fURLSheetTextField stringValue];
    1112     BOOL enable = YES;
    1113     if ([string isEqualToString: @""])
    1114         enable = NO;
    1115     else
    1116     {
    1117         NSRange prefixRange = [string rangeOfString: @"://"];
    1118         if (prefixRange.location != NSNotFound && [string length] == NSMaxRange(prefixRange))
    1119             enable = NO;
    1120     }
    1121    
    1122     [fURLSheetOpenButton setEnabled: enable];
    1123 }
    1124 
    1125 - (void) urlSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
    1126 {
    1127     [fURLSheetTextField selectText: self];
    1128     if (returnCode != 1)
    1129         return;
    1130    
    1131     NSString * urlString = [fURLSheetTextField stringValue];
    1132    
     1087- (void) openURL: (NSString *) urlString
     1088{
    11331089    if ([urlString rangeOfString: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
    11341090        [self openMagnet: urlString];
     
    11521108       
    11531109        NSURL * url = [NSURL URLWithString: urlString];
    1154         [self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO];
    1155     }
     1110        [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
     1111    }
     1112}
     1113
     1114- (void) openURLShowSheet: (id) sender
     1115{
     1116    [NSApp beginSheet: fURLSheetWindow modalForWindow: fWindow modalDelegate: self
     1117            didEndSelector: @selector(urlSheetDidEnd:returnCode:contextInfo:) contextInfo: nil];
     1118}
     1119
     1120- (void) openURLEndSheet: (id) sender
     1121{
     1122    [fURLSheetWindow orderOut: sender];
     1123    [NSApp endSheet: fURLSheetWindow returnCode: 1];
     1124}
     1125
     1126- (void) openURLCancelEndSheet: (id) sender
     1127{
     1128    [fURLSheetWindow orderOut: sender];
     1129    [NSApp endSheet: fURLSheetWindow returnCode: 0];
     1130}
     1131
     1132- (void) controlTextDidChange: (NSNotification *) notification
     1133{
     1134    if ([notification object] != fURLSheetTextField)
     1135        return;
     1136   
     1137    NSString * string = [fURLSheetTextField stringValue];
     1138    BOOL enable = YES;
     1139    if ([string isEqualToString: @""])
     1140        enable = NO;
     1141    else
     1142    {
     1143        NSRange prefixRange = [string rangeOfString: @"://"];
     1144        if (prefixRange.location != NSNotFound && [string length] == NSMaxRange(prefixRange))
     1145            enable = NO;
     1146    }
     1147   
     1148    [fURLSheetOpenButton setEnabled: enable];
     1149}
     1150
     1151- (void) urlSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
     1152{
     1153    [fURLSheetTextField selectText: self];
     1154    if (returnCode != 1)
     1155        return;
     1156   
     1157    NSString * urlString = [fURLSheetTextField stringValue];
     1158    [self performSelectorOnMainThread: @selector(openURL:) withObject: urlString waitUntilDone: NO];
    11561159}
    11571160
     
    28762879        if ((url = [NSURL URLFromPasteboard: pasteboard]))
    28772880        {
    2878             [self openURL: url];
     2881            [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
    28792882            return YES;
    28802883        }
Note: See TracChangeset for help on using the changeset viewer.