1
0
Fork 0

More small fixes

master
Matthieu Lalonde 13 years ago
parent d3f915740d
commit 140c7a6bdd

@ -117,14 +117,14 @@
- (IBAction) refreshWanMenu:(id)sender; - (IBAction) refreshWanMenu:(id)sender;
- (void) wanRequestCallback:(NSData *)data; - (void) wanRequestCallback:(NSData *)data;
- (IBAction) refreshClientsMenu:(id)sender; - (IBAction) refreshClientsMenu:(id)sender;
- (void) cbClientsRequest:(NSData*)data; - (void) cbClientsRequest:(NSData *)data;
- (void) saveConfig:(id)sender; - (void) saveConfig:(id)sender;
- (void) updateThroughput:(NSTimer*)timer; - (void) updateThroughput:(NSTimer *)timer;
- (void) throughputCallback:(NSData *)data; - (void) throughputCallback:(NSData *)data;
- (void) doUpdateStatus:(NSData *)data; - (void) doUpdateStatus:(NSData *)data;
- (NSMenu*) createCopyMenuItem; - (NSMenu *) createCopyMenuItem;
- (IBAction) copyParentMenuTitle:(id)sender; - (IBAction) copyParentMenuTitle:(id)sender;
- (NSString *) stringFromSize:(uint64_t)theBytes; - (NSString *) stringFromSize:(uint64_t)theBytes;
- (NSString *) stringFromSpeed:(uint64_t)theBytes; - (NSString *) stringFromSpeed:(uint64_t)theBytes;

@ -24,8 +24,7 @@
defaults = [NSUserDefaults standardUserDefaults]; defaults = [NSUserDefaults standardUserDefaults];
// check if the app is configured yet // check if the app is configured yet
if (![defaults boolForKey:@"configured"]) if (![defaults boolForKey:@"configured"]) {
{
[self initDefaults]; [self initDefaults];
} else { } else {
[self initialize]; [self initialize];
@ -41,10 +40,7 @@
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password]; wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
[wrt_client getConnectionStatus]; [wrt_client getConnectionStatus];
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); [self updateThroughput:nil];
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
} }
- (void) deinitialize - (void) deinitialize
@ -333,9 +329,9 @@
[self hideConfigPanel:nil]; [self hideConfigPanel:nil];
} }
- (void) updateThroughput:(NSTimer*)timer - (void) updateThroughput:(NSTimer *)timer
{ {
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); //NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
if ([wrt_client wrtReachable] == true && _wrtReachable == false) { if ([wrt_client wrtReachable] == true && _wrtReachable == false) {
_wrtReachable = true; _wrtReachable = true;
if (showMenuIcon == true) { if (showMenuIcon == true) {
@ -351,6 +347,12 @@
if (_wrtReachable == true) { if (_wrtReachable == true) {
[wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)]; [wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)];
} }
if (_readTimer == nil) {
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
}
} }
- (void) throughputCallback:(NSData *)data - (void) throughputCallback:(NSData *)data
@ -375,7 +377,9 @@
double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]); double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]);
_lastDateThroughput = [[NSDate date] retain]; _lastDateThroughput = [[NSDate date] retain];
if (timeDiff <= 0) timeDiff = 1; // avoid division by zero
if (timeDiff <= 0)
timeDiff = 1; // avoid division by zero
double speedIn = diffIn / timeDiff; double speedIn = diffIn / timeDiff;
double speedOut = diffOut / timeDiff; double speedOut = diffOut / timeDiff;
@ -384,8 +388,8 @@
[ self setMenubarText:[NSString stringWithFormat:@"%@s\n%@s", [self stringFromSpeed:speedOut], [self stringFromSpeed:speedIn]] ]; [ self setMenubarText:[NSString stringWithFormat:@"%@s\n%@s", [self stringFromSpeed:speedOut], [self stringFromSpeed:speedIn]] ];
NSLog(@"In %llu Out %llu Last In %llu Last Out %llu diffIn %llu diffOut %llu In %f Out %f Interval %f", ifIn, ifOut, _lastInThroughput, //NSLog(@"In %llu Out %llu Last In %llu Last Out %llu diffIn %llu diffOut %llu In %f Out %f Interval %f", ifIn, ifOut, _lastInThroughput,
_lastOutThroughput, diffIn, diffOut, speedIn, speedOut, timeDiff); // _lastOutThroughput, diffIn, diffOut, speedIn, speedOut, timeDiff);
} }
_lastInThroughput = ifIn; _lastInThroughput = ifIn;
@ -399,6 +403,7 @@
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"]; NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"];
[menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]]; [menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"]; NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"];
@ -550,7 +555,7 @@
} }
- (void) cbClientsRequest:(NSData*)data - (void) cbClientsRequest:(NSData *)data
{ {
NSString * clientsStringData; NSString * clientsStringData;
@ -626,7 +631,7 @@
[_readTimer fire]; [_readTimer fire];
} }
- (NSMenu*) createCopyMenuItem - (NSMenu *) createCopyMenuItem
{ {
NSMenu *copyMenu = [[NSMenu alloc] init]; NSMenu *copyMenu = [[NSMenu alloc] init];
NSMenuItem *copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""]; NSMenuItem *copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
@ -666,8 +671,6 @@
- (NSString *) stringFromSpeed:(uint64_t)theBytes - (NSString *) stringFromSpeed:(uint64_t)theBytes
{ {
unsigned int minSize = /*(useBytes ? */1023/* : 999)*/;
unsigned int divSize = /*(useBytes ? */1024/* : 1000)*/;
NSString *suffix; NSString *suffix;
if (useBytes == false) { if (useBytes == false) {
@ -677,21 +680,21 @@
double floatSize = theBytes; double floatSize = theBytes;
suffix = (useBytes ? @"B" : @"b"); suffix = (useBytes ? @"B" : @"b");
if (theBytes<minSize) if (theBytes<1023)
return([NSString stringWithFormat:@"%llu%@", theBytes, suffix]); return([NSString stringWithFormat:@"%llu%@", theBytes, suffix]);
floatSize = floatSize / divSize; floatSize = floatSize / 1024;
suffix = (useBytes ? @"KiB" : @"Kb"); suffix = (useBytes ? @"KiB" : @"Kb");
if (floatSize<minSize) if (floatSize<1023)
return([NSString stringWithFormat:@"%1.1f%@", floatSize, suffix]); return([NSString stringWithFormat:@"%1.1f%@", floatSize, suffix]);
floatSize = floatSize / divSize; floatSize = floatSize / 1024;
suffix = (useBytes ? @"MiB" : @"Mb"); suffix = (useBytes ? @"MiB" : @"Mb");
if (floatSize<minSize) if (floatSize<1023)
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]); return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
floatSize = floatSize / divSize; floatSize = floatSize / 1024;
suffix = (useBytes ? @"GiB" : @"Gb"); suffix = (useBytes ? @"GiB" : @"Gb");
if (floatSize<minSize) if (floatSize<1023)
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]); return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
floatSize = floatSize / divSize; floatSize = floatSize / 1024;
suffix = (useBytes ? @"TiB" : @"Tb"); suffix = (useBytes ? @"TiB" : @"Tb");
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]); return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);

@ -944,7 +944,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<object class="NSTextField" id="371817589"> <object class="NSTextField" id="371817589">
<reference key="NSNextResponder" ref="284387334"/> <reference key="NSNextResponder" ref="284387334"/>
<int key="NSvFlags">268</int> <int key="NSvFlags">-2147483380</int>
<string key="NSFrame">{{156, 195}, {135, 17}}</string> <string key="NSFrame">{{156, 195}, {135, 17}}</string>
<reference key="NSSuperview" ref="284387334"/> <reference key="NSSuperview" ref="284387334"/>
<reference key="NSWindow"/> <reference key="NSWindow"/>

@ -44,7 +44,7 @@
port, port,
uri]; uri];
NSLog(@"Building request form %@", urlAddress); //NSLog(@"Building request form %@", urlAddress);
NSURL *url = [NSURL URLWithString:urlAddress]; NSURL *url = [NSURL URLWithString:urlAddress];
@ -240,7 +240,7 @@
{ {
return YES; return YES;
} }
/*
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{ {
NSLog(@"1"); NSLog(@"1");
@ -259,7 +259,7 @@
NSLog(@"Invalid Username or Password"); NSLog(@"Invalid Username or Password");
} }
} }
*/
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{ {
//NSLog(@"2"); //NSLog(@"2");
@ -273,7 +273,7 @@
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{ {
NSLog(@"4"); //NSLog(@"4");
//[connection release]; //[connection release];
//[receivedData release]; //[receivedData release];
//[theRequest release]; //[theRequest release];

Loading…
Cancel
Save