]> granicus.if.org Git - transmission/commitdiff
register to automatically accept when a user clicks a magnet link
authorMitchell Livingston <livings124@transmissionbt.com>
Thu, 26 Nov 2009 16:38:21 +0000 (16:38 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Thu, 26 Nov 2009 16:38:21 +0000 (16:38 +0000)
macosx/Controller.h
macosx/Controller.m
macosx/Info.plist
macosx/Torrent.m

index ee9485efa933eca621d38f633a7b18ce02aa6257..87ab19f91ea4b8bb3409fff1b4b620667b5a2449 100644 (file)
@@ -127,7 +127,7 @@ typedef enum
 - (void) invalidOpenAlert: (NSString *) filename;
 - (void) duplicateOpenAlert: (NSString *) name;
 
-- (void) openURL:               (NSURL *) torrentURL;
+- (void) openURL:               (NSString *) urlString;
 - (void) openURLEndSheet:       (id) sender;
 - (void) openURLCancelEndSheet: (id) sender;
 - (void) openURLShowSheet:      (id) sender;
index d90d9ff2bc344ac0cbc5875cef2f222315d1a7e8..1f2347e8c8e929631cfd26bc6c7c51ff383f9319 100644 (file)
@@ -345,6 +345,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
         
         tr_sessionSetRPCCallback(fLib, rpcCallback, self);
         
+        //register for dock icon drags
+        [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
+            forEventClass: kCoreEventClass andEventID: kAEOpenContents];
+        
+        //register for magnet URLs
+        [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
+        forEventClass: kInternetEventClass andEventID: kAEGetURL];
+        
         [GrowlApplicationBridge setGrowlDelegate: self];
         
         [[UKKQueue sharedFileWatcher] setDelegate: self];
@@ -566,10 +574,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
 {
     [NSApp setServicesProvider: self];
     
-    //register for dock icon drags
-    [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
-        forEventClass: kCoreEventClass andEventID: kAEOpenContents];
-    
     //auto importing
     [self checkAutoImportDirectory];
     
@@ -757,7 +761,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
         urlString = [directObject stringValue];
     
     if (urlString)
-        [self openURL: [NSURL URLWithString: urlString]];
+        [self openURL: urlString];
 }
 
 - (void) download: (NSURLDownload *) download decideDestinationWithSuggestedFilename: (NSString *) suggestedName
@@ -1080,9 +1084,31 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
     [alert release];
 }
 
-- (void) openURL: (NSURL *) url
+- (void) openURL: (NSString *) urlString
 {
-    [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
+    if ([urlString rangeOfString: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
+        [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];
+        }
+        
+        NSURL * url = [NSURL URLWithString: urlString];
+        [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
+    }
 }
 
 - (void) openURLShowSheet: (id) sender
@@ -1129,30 +1155,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
         return;
     
     NSString * urlString = [fURLSheetTextField stringValue];
-    
-    if ([urlString rangeOfString: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
-        [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];
-        }
-        
-        NSURL * url = [NSURL URLWithString: urlString];
-        [self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO];
-    }
+    [self performSelectorOnMainThread: @selector(openURL:) withObject: urlString waitUntilDone: NO];
 }
 
 - (void) createFile: (id) sender
@@ -2875,7 +2878,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
         NSURL * url;
         if ((url = [NSURL URLFromPasteboard: pasteboard]))
         {
-            [self openURL: url];
+            [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
             return YES;
         }
     }
index 96fe48ebd93d4c15515231fb6e2fa4ddb974528b..5824a4d33e7980eb2ce1055e0c0ea788d8018f02 100644 (file)
        <string>TR##</string>
        <key>CFBundleShortVersionString</key>
        <string>VERSION_STRING_INFOPLIST</string>
+       <key>CFBundleURLTypes</key>
+       <array>
+               <dict>
+                       <key>CFBundleURLSchemes</key>
+                       <array>
+                               <string>magnet</string>
+                               <string>dht</string>
+                       </array>
+                       <key>CFBundleURLName</key>
+                       <string>BitTorrent Magnet URL</string>
+               </dict>
+       </array>
        <key>CFBundleVersion</key>
        <string>SVN_REVISION_NUM</string>
        <key>CFBundleGetInfoString</key>
index 628e8fa2b35859b18eab12478547519db642c927..cf896e2400f105d712dc51e804ccbe78f0ef92d2 100644 (file)
@@ -909,7 +909,8 @@ int trashDataFile(const char * filename)
 - (NSString *) progressString
 {
     if ([self isMagnet])
-        return NSLocalizedString(@"Magnetized transfer - acquiring torrent information", "Torrent -> progress string");
+        return [NSString stringWithFormat: @"%@ - %@", NSLocalizedString(@"Magnetized transfer", "Torrent -> progress string"),
+                                            NSLocalizedString(@"torrent information needed", "Torrent -> progress string")];
     
     NSString * string;