Skip to content

Commit

Permalink
now we store a dictionary instead of just the netservice
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Lebel committed Sep 26, 2010
1 parent e9d78be commit 2a59999
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 6 additions & 4 deletions iProxyMacSetup/Classes/PMUIController.m
Expand Up @@ -77,11 +77,13 @@ - (void)updateStartButton
- (void)updateProxyPopUpButton - (void)updateProxyPopUpButton
{ {
[proxyPopUpButton removeAllItems]; [proxyPopUpButton removeAllItems];
for (NSNetService *service in appDelegate.proxyServiceList) { for (NSDictionary *proxy in appDelegate.proxyServiceList) {
NSString *title; NSString *title;
NSNetService *proxyService;


title = [[NSString alloc] initWithFormat:@"%@.%@", [service name], [service domain]]; proxyService = [proxy objectForKey:PROXY_SERVICE_KEY];
if ([service port] != -1) { title = [[NSString alloc] initWithFormat:@"%@.%@", [proxyService name], [proxyService domain]];
if ([proxyService port] != -1 || [proxyService port] != 0) {
[proxyPopUpButton addItemWithTitle:title]; [proxyPopUpButton addItemWithTitle:title];
} else { } else {
[proxyPopUpButton addItemWithTitle:[NSString stringWithFormat:@"%@ (disabled)", title]]; [proxyPopUpButton addItemWithTitle:[NSString stringWithFormat:@"%@ (disabled)", title]];
Expand Down Expand Up @@ -114,7 +116,7 @@ - (void)updateInterfacePopUpButton
- (IBAction)startButtonAction:(id)sender - (IBAction)startButtonAction:(id)sender
{ {
NSDictionary *interfaceInfo; NSDictionary *interfaceInfo;
NSNetService *proxy; NSDictionary *proxy;


[self updateProxyPopUpButton]; [self updateProxyPopUpButton];
[self updateInterfacePopUpButton]; [self updateInterfacePopUpButton];
Expand Down
4 changes: 3 additions & 1 deletion iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.h
Expand Up @@ -11,6 +11,8 @@
#define INTERFACE_NAME @"name" #define INTERFACE_NAME @"name"
#define INTERFACE_ENABLED @"enabled" #define INTERFACE_ENABLED @"enabled"


#define PROXY_SERVICE_KEY @"service"

@interface iProxyMacSetupAppDelegate : NSObject <NSApplicationDelegate, NSNetServiceBrowserDelegate, NSNetServiceDelegate> @interface iProxyMacSetupAppDelegate : NSObject <NSApplicationDelegate, NSNetServiceBrowserDelegate, NSNetServiceDelegate>
{ {
NSMutableArray *proxyServiceList; NSMutableArray *proxyServiceList;
Expand All @@ -34,7 +36,7 @@
@property(retain, nonatomic) NSString *defaultInterface; @property(retain, nonatomic) NSString *defaultInterface;


- (void)startBrowsingServices; - (void)startBrowsingServices;
- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSNetService *)proxy; - (void)enableForInterface:(NSString *)interfaceName withProxy:(NSDictionary *)proxy;
- (void)disableProxyForInterface:(NSString *)interface; - (void)disableProxyForInterface:(NSString *)interface;


@end @end
21 changes: 15 additions & 6 deletions iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.m
Expand Up @@ -45,12 +45,15 @@ - (void)applicationWillTerminate:(NSNotification *)notification
- (void)_updateAutomatic - (void)_updateAutomatic
{ {
if (automatic) { if (automatic) {
NSNetService *proxy = nil; NSDictionary *proxy = nil;
NSDictionary *currentInterface = nil; NSDictionary *currentInterface = nil;
NSUInteger ii, count = [proxyServiceList count]; NSUInteger ii, count = [proxyServiceList count];


for (ii = 0; ii < count; ii++) { for (ii = 0; ii < count; ii++) {
if ([(NSNetService *)[proxyServiceList objectAtIndex:ii] port] != -1 && [(NSNetService *)[proxyServiceList objectAtIndex:ii] port] != 0) { NSNetService *proxyService;

proxyService = [[proxyServiceList objectAtIndex:ii] objectForKey:PROXY_SERVICE_KEY];
if ([proxyService port] != -1 && [proxyService port] != 0) {
proxy = [proxyServiceList objectAtIndex:ii]; proxy = [proxyServiceList objectAtIndex:ii];
break; break;
} }
Expand Down Expand Up @@ -222,7 +225,10 @@ - (NSInteger)indexForDomain:(NSString *)domain name:(NSString *)name type:(NSStr
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
{ {
[self willChangeValueForKey:@"proxyServiceList"]; [self willChangeValueForKey:@"proxyServiceList"];
[proxyServiceList addObject:aNetService]; NSMutableDictionary *proxy = [[NSMutableDictionary alloc] init];
[proxy setObject:aNetService forKey:PROXY_SERVICE_KEY];
[proxyServiceList addObject:proxy];
[proxy release];
[self didChangeValueForKey:@"proxyServiceList"]; [self didChangeValueForKey:@"proxyServiceList"];
[aNetService setDelegate:self]; [aNetService setDelegate:self];
[aNetService resolveWithTimeout:20.0]; [aNetService resolveWithTimeout:20.0];
Expand Down Expand Up @@ -286,12 +292,15 @@ - (void)_enableProxyForInterface:(NSString *)interface server:(NSString *)server
[task waitUntilExit]; [task waitUntilExit];
} }


- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSNetService *)proxy - (void)enableForInterface:(NSString *)interfaceName withProxy:(NSDictionary *)proxy
{ {
if (!proxyEnabled) { if (!proxyEnabled) {
NSNetService *proxyService;

[self willChangeValueForKey:@"proxyEnabled"]; [self willChangeValueForKey:@"proxyEnabled"];
if ([proxy port] != -1) { proxyService = [proxy objectForKey:PROXY_SERVICE_KEY];
[self _enableProxyForInterface:interfaceName server:[NSString stringWithFormat:@"%@.%@", [proxy name], [proxy domain]] port:[proxy port]]; if ([proxyService port] != -1) {
[self _enableProxyForInterface:interfaceName server:[NSString stringWithFormat:@"%@.%@", [proxyService name], [proxyService domain]] port:[proxyService port]];
proxyEnabled = YES; proxyEnabled = YES;
proxyEnabledInterfaceName = [interfaceName retain]; proxyEnabledInterfaceName = [interfaceName retain];
} }
Expand Down

0 comments on commit 2a59999

Please sign in to comment.