]> granicus.if.org Git - transmission/commitdiff
#1395 - patch from Waldorf: Bonjour support for Web Interface
authorMitchell Livingston <livings124@transmissionbt.com>
Sat, 6 Dec 2008 01:18:25 +0000 (01:18 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sat, 6 Dec 2008 01:18:25 +0000 (01:18 +0000)
NEWS
macosx/BonjourController.h [new file with mode: 0644]
macosx/BonjourController.m [new file with mode: 0644]
macosx/Controller.m
macosx/InfoWindowController.m
macosx/Makefile.am
macosx/PrefsController.m

diff --git a/NEWS b/NEWS
index 5f20371b0442f2f0ad353dd20c41127d11145690..44241ea62b0e050bd93ba7a3e37d6fda4d0e9b91 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ NEWS file for Transmission <http://www.transmissionbt.com/>
    + Support BitTorrent Enhancement Proposal #21 "Extension for Partial Seeds"
 - Mac
    + Groups (moved to preferences) can have a default location when adding transfers
+   + Bonjour support for web interface
 - GTK+
    + Minor display improvements and HIG compliance
 
diff --git a/macosx/BonjourController.h b/macosx/BonjourController.h
new file mode 100644 (file)
index 0000000..7473f2a
--- /dev/null
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Copyright (c) 2008 Transmission authors and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+@interface BonjourController : NSObject
+{
+    NSNetService * fService;
+}
+
++ (BonjourController *) defaultController;
+
+- (void) startWithPort: (NSInteger) port;
+- (void) stop;
+
+@end
diff --git a/macosx/BonjourController.m b/macosx/BonjourController.m
new file mode 100644 (file)
index 0000000..2876485
--- /dev/null
@@ -0,0 +1,94 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Copyright (c) 2008 Transmission authors and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *****************************************************************************/
+
+#import "BonjourController.h"
+
+@implementation BonjourController
+
+BonjourController * fDefaultController = nil;
++ (BonjourController *) defaultController
+{
+    if (!fDefaultController)
+        fDefaultController = [[BonjourController alloc] init];
+    return fDefaultController;
+}
+
+- (void) dealloc
+{
+    [fService release];
+    [super dealloc];
+}
+
+- (void) startWithPort: (NSInteger) port
+{
+    [self stop];
+    
+    CFStringRef machineName = CSCopyMachineName();
+    NSString * serviceName = [NSString stringWithFormat: @"%@: Transmission Web Interface", (NSString *)machineName];
+    CFRelease(machineName);
+    
+    fService = [[NSNetService alloc] initWithDomain: @"local." type: @"_http._tcp." name: serviceName port: port];
+    [fService setDelegate: self];
+    
+    [fService publish];
+}
+
+- (void) stop;
+{
+    [fService stop];
+    [fService release];
+    fService = nil;
+}
+
+- (void) netServiceWillPublish: (NSNetService *) sender
+{
+    NSLog(@"Will publish the Web UI service on port: %d", [sender port]);
+}
+
+- (void) netService: (NSNetService *) sender didNotPublish: (NSDictionary *) errorDict
+{
+    NSLog(@"Failed to publish the Web UI service on port: %d, with error: %@", [sender port], errorDict);
+}
+
+- (void) netServiceDidPublish: (NSNetService *) sender
+{
+    NSLog(@"Did publish the Web UI service on port: %d", [sender port]);
+}
+
+- (void) netServiceWillResolve: (NSNetService *) sender
+{
+    NSLog(@"Will resolve the Web UI service on port: %d", [sender port]);
+}
+
+- (void) netService: (NSNetService *) sender didNotResolve: (NSDictionary *) errorDict
+{
+    NSLog(@"Failed to resolve the Web UI service on port: %d, with error: %@", [sender port], errorDict);
+}
+
+- (void) netServiceDidResolveAddress: (NSNetService *) sender
+{
+    NSLog(@"Did resolve the Web UI service on port: %d", [sender port]);
+}
+
+@end
index 2386741d67346a8a2388233dfe212afecf7806e2..961638afdd7cb20b1fc519097a4d996e1f63b4dd 100644 (file)
@@ -41,6 +41,7 @@
 #import "BlocklistDownloader.h"
 #import "StatusBarView.h"
 #import "FilterButton.h"
+#import "BonjourController.h"
 #import "NSApplicationAdditions.h"
 #import "NSStringAdditions.h"
 #import "NSMenuAdditions.h"
@@ -521,6 +522,10 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
     
     //auto importing
     [self checkAutoImportDirectory];
+    
+    //registering the Web UI to Bonjour
+    if ([fDefaults boolForKey: @"RPC"])
+        [[BonjourController defaultController] startWithPort: [fDefaults integerForKey: @"RPCPort"]];
 }
 
 - (BOOL) applicationShouldHandleReopen: (NSApplication *) app hasVisibleWindows: (BOOL) visibleWindows
@@ -571,6 +576,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
 
 - (void) applicationWillTerminate: (NSNotification *) notification
 {
+    //stop the Bonjour service
+    [[BonjourController defaultController] stop];
+
     //stop blocklist download
     if ([BlocklistDownloader isRunning])
         [[BlocklistDownloader downloader] cancelDownload];
index dd370cc9680dc4d9a1098518ebae2ac63768704b..c26ce121cc80fb2edd7796783721429299f70bc4 100644 (file)
@@ -981,16 +981,12 @@ typedef enum
         NSMutableArray * components = [NSMutableArray arrayWithCapacity: 5];
         
         CGFloat progress = [[peer objectForKey: @"Progress"] floatValue];
-        
-        NSString * seedStatus;
+        NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%",
+                                        "Inspector -> Peers tab -> table row tooltip"), progress * 100.0];
         if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue])
-            seedStatus = [NSString stringWithFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
-                            "Inspector -> Peers tab -> table row tooltip")];
-        else
-            seedStatus = @"";
-        
-        [components addObject: [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%%@",
-            "Inspector -> Peers tab -> table row tooltip"), progress * 100.0, seedStatus]];
+            progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
+                                "Inspector -> Peers tab -> table row tooltip")];
+        [components addObject: progressString];
         
         if ([[peer objectForKey: @"Encryption"] boolValue])
             [components addObject: NSLocalizedString(@"Encrypted Connection", "Inspector -> Peers tab -> table row tooltip")];
index 3d06b0c8293032d9701e6fcc96bf2ded617ada03..126961cbd541181dfe4e46a76fa30346851c6de2 100644 (file)
@@ -40,6 +40,8 @@ EXTRA_DIST = \
     BlocklistDownloaderViewController.m \
     BlocklistScheduler.h \
     BlocklistScheduler.m \
+    BonjourController.h \
+    BonjourController.m \
     ButtonToolbarItem.h \
     ButtonToolbarItem.m \
     ColorTextField.h \
index 84008bc84179924fed491794fd4aa471b467fc26..247389cec3c07e805500dd9d25b0b53d1c10b8ec 100644 (file)
@@ -26,6 +26,7 @@
 #import "BlocklistDownloaderViewController.h"
 #import "BlocklistScheduler.h"
 #import "PortChecker.h"
+#import "BonjourController.h"
 #import "NSApplicationAdditions.h"
 #import "NSStringAdditions.h"
 #import "UKKQueue.h"
@@ -819,7 +820,14 @@ tr_handle * fHandle;
 
 - (void) setRPCEnabled: (id) sender
 {
-    tr_sessionSetRPCEnabled(fHandle, [fDefaults boolForKey: @"RPC"]);
+    BOOL enable = [fDefaults boolForKey: @"RPC"];
+    tr_sessionSetRPCEnabled(fHandle, enable);
+    
+    //Registering the Web UI to Bonjour
+    if (enable)
+        [[BonjourController defaultController] startWithPort: [fDefaults integerForKey: @"RPCPort"]];
+    else
+        [[BonjourController defaultController] stop];
 }
 
 - (void) linkWebUI: (id) sender
@@ -870,6 +878,10 @@ tr_handle * fHandle;
     int port = [sender intValue];
     [fDefaults setInteger: port forKey: @"RPCPort"];
     tr_sessionSetRPCPort(fHandle, port);
+    
+    //Registering the Web UI to Bonjour
+    if ([fDefaults boolForKey:@"RPC"])
+        [[BonjourController defaultController] startWithPort: port];
 }
 
 - (void) setRPCUseWhitelist: (id) sender