#1395 - patch from Waldorf: Bonjour support for Web Interface

This commit is contained in:
Mitchell Livingston
2008-12-06 01:18:25 +00:00
parent 9e98dcd248
commit 28414a9ed3
7 changed files with 160 additions and 10 deletions

1
NEWS
View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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];

View 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")];

View File

@@ -40,6 +40,8 @@ EXTRA_DIST = \
BlocklistDownloaderViewController.m \
BlocklistScheduler.h \
BlocklistScheduler.m \
BonjourController.h \
BonjourController.m \
ButtonToolbarItem.h \
ButtonToolbarItem.m \
ColorTextField.h \

View 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