Skip to content

Commit

Permalink
Fixed to allow adding ports other than the one's specified in code. A…
Browse files Browse the repository at this point in the history
…dded a new speed called T1.
  • Loading branch information
mledford committed Dec 1, 2009
1 parent c708155 commit 42bf3d5
Show file tree
Hide file tree
Showing 3 changed files with 1,593 additions and 2,117 deletions.
14 changes: 10 additions & 4 deletions SpeedLimit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
8D202CF10486D31800D8A456 /* SpeedLimitPref.m in Sources */ = {isa = PBXBuildFile; fileRef = F506C03D013D9D7901CA16C8 /* SpeedLimitPref.m */; };
8D202CF30486D31800D8A456 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
8D202CF40486D31800D8A456 /* PreferencePanes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F506C035013D953901CA16C8 /* PreferencePanes.framework */; };
EC5DAEEE10C4928900E728BA /* SLPort.h in Headers */ = {isa = PBXBuildFile; fileRef = EC5DAEEC10C4928900E728BA /* SLPort.h */; };
EC5DAEEF10C4928900E728BA /* SLPort.m in Sources */ = {isa = PBXBuildFile; fileRef = EC5DAEED10C4928900E728BA /* SLPort.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -38,6 +40,8 @@
88F7EB77106C07D700745902 /* SecurityInterface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityInterface.framework; path = /System/Library/Frameworks/SecurityInterface.framework; sourceTree = "<absolute>"; };
8D202CF70486D31800D8A456 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D202CF80486D31800D8A456 /* SpeedLimit.prefPane */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SpeedLimit.prefPane; sourceTree = BUILT_PRODUCTS_DIR; };
EC5DAEEC10C4928900E728BA /* SLPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SLPort.h; sourceTree = "<group>"; };
EC5DAEED10C4928900E728BA /* SLPort.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SLPort.m; sourceTree = "<group>"; };
F506C035013D953901CA16C8 /* PreferencePanes.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PreferencePanes.framework; path = /System/Library/Frameworks/PreferencePanes.framework; sourceTree = "<absolute>"; };
F506C03C013D9D7901CA16C8 /* SpeedLimitPref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeedLimitPref.h; sourceTree = "<group>"; };
F506C03D013D9D7901CA16C8 /* SpeedLimitPref.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpeedLimitPref.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -100,6 +104,8 @@
F506C03D013D9D7901CA16C8 /* SpeedLimitPref.m */,
550EDEAD0E651B3B00A4C8A1 /* Speed.h */,
550EDEAE0E651B3B00A4C8A1 /* Speed.m */,
EC5DAEEC10C4928900E728BA /* SLPort.h */,
EC5DAEED10C4928900E728BA /* SLPort.m */,
);
name = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -150,6 +156,7 @@
8D202CEA0486D31800D8A456 /* SpeedLimit_Prefix.pch in Headers */,
8D202CEB0486D31800D8A456 /* SpeedLimitPref.h in Headers */,
550EDEAF0E651B3B00A4C8A1 /* Speed.h in Headers */,
EC5DAEEE10C4928900E728BA /* SLPort.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -181,7 +188,7 @@
/* Begin PBXProject section */
089C1669FE841209C02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DBD214C08BA80EA00186707 /* Build configuration list for PBXProject "SpeedLimit" */;
buildConfigurationList = 1DBD214C08BA80EA00186707 /* Build configuration list for PBXProject "speedlimit" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = en;
hasScannedForEncodings = 1;
Expand Down Expand Up @@ -233,6 +240,7 @@
files = (
8D202CF10486D31800D8A456 /* SpeedLimitPref.m in Sources */,
550EDEB00E651B3B00A4C8A1 /* Speed.m in Sources */,
EC5DAEEF10C4928900E728BA /* SLPort.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -301,7 +309,6 @@
MACOSX_DEPLOYMENT_TARGET = 10.5;
ONLY_ACTIVE_ARCH = NO;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Debug;
};
Expand All @@ -316,7 +323,6 @@
MACOSX_DEPLOYMENT_TARGET = 10.5;
ONLY_ACTIVE_ARCH = NO;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Release;
};
Expand All @@ -332,7 +338,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1DBD214C08BA80EA00186707 /* Build configuration list for PBXProject "SpeedLimit" */ = {
1DBD214C08BA80EA00186707 /* Build configuration list for PBXProject "speedlimit" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DBD214D08BA80EA00186707 /* Debug */,
Expand Down
31 changes: 22 additions & 9 deletions SpeedLimitPref.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "SpeedLimitPref.h"
#import "SLPort.h"
#import <Security/Authorization.h>
#import <Security/AuthorizationTags.h>

Expand Down Expand Up @@ -45,6 +46,7 @@ - (NSString *)speedLimiterPath {

- (void) mainViewDidLoad {

[speedsController addObject:[Speed speedWithName:@"T1" speed:1572]];
[speedsController addObject:[Speed speedWithName:@"DSL" speed:768]];
[speedsController addObject:[Speed speedWithName:@"3G" speed:384]];
[speedsController addObject:[Speed speedWithName:@"Edge" speed:64]];
Expand Down Expand Up @@ -79,7 +81,11 @@ - (NSString *)execute:(NSString *)command withArguments:(NSArray *)arguments {
- (void)saveSettings {
NSMutableDictionary *prefs = [NSMutableDictionary dictionary];

[prefs setObject:[portsController arrangedObjects] forKey:PORTS_KEY];
NSMutableArray *ports = [NSMutableArray array];
for (SLPort *thePort in [portsController arrangedObjects]) {
[ports addObject:[[thePort port] stringValue]];
}
[prefs setObject:ports forKey:PORTS_KEY];
if (self.delay) {
[prefs setObject:self.delay forKey:DELAY_KEY];
}
Expand Down Expand Up @@ -152,15 +158,18 @@ - (void)releaseAuthorization {

- (void)willSelect {
NSDictionary *prefs = [[NSUserDefaults standardUserDefaults] persistentDomainForName:[[NSBundle bundleForClass:[self class]] bundleIdentifier]];

NSArray *previousPorts = [prefs objectForKey:PORTS_KEY];
[portsController removeObjects:[portsController arrangedObjects]];
if ([previousPorts count]) {
[portsController addObjects:previousPorts];
for (NSString *object in [previousPorts objectEnumerator]) {
SLPort *newPort = [[SLPort alloc] initWithPort:[object intValue]];
[portsController addObject:newPort];
[newPort release];
}
}
else {
[portsController addObject:@"80"];
[portsController addObject:@"443"];
[portsController addObject:[[[SLPort alloc] initWithPort:80] autorelease]];
[portsController addObject:[[[SLPort alloc] initWithPort:443] autorelease]];
}
[portsController setSelectedObjects:nil];

Expand Down Expand Up @@ -201,7 +210,6 @@ - (void)willSelect {
}

- (void)didSelect {

if (authorizationView) {

const char *path = [[self speedLimiterPath] fileSystemRepresentation];
Expand Down Expand Up @@ -255,8 +263,9 @@ - (void)enableInterfaces:(BOOL)enable {
}

-(IBAction)addPort:(id)sender {
NSString *newPort = @"1000";
SLPort *newPort = [[SLPort alloc] initWithPort:1000];
[portsController addObject:newPort];
[newPort release];
}

-(IBAction)removePort:(id)sender {
Expand All @@ -267,7 +276,11 @@ -(IBAction)toggle:(id)sender {
[self refreshRules];
if (!self.slow) {
NSArray *ports = [self.portsController arrangedObjects];
if (self.speed && [ports count]) {
NSMutableArray *portStrings = [NSMutableArray array];
for (SLPort *thePort in ports) {
[portStrings addObject:[[thePort port] stringValue]];
}
if (self.speed && [portStrings count]) {
NSString *finalSpeed = [NSString stringWithFormat:@"%ld", speed.speed];
NSString *finalDelay = (self.delay == nil || [self.delay length] == 0) ? 0 : self.delay;
NSString *finalHosts = (self.hosts == nil) ? @"" : self.hosts;
Expand All @@ -279,7 +292,7 @@ -(IBAction)toggle:(id)sender {
[arguments addObject:finalPacketLossRatio];
[arguments addObject:finalPacketLossErrorSuppress];
[arguments addObject:finalHosts];
[arguments addObjectsFromArray:ports];
[arguments addObjectsFromArray:portStrings];
self.rules = [self rulesForCommand:@"start" withArguments:arguments];
[self saveSettings];
[self updateStatus];
Expand Down
Loading

0 comments on commit 42bf3d5

Please sign in to comment.