1
0
Fork 0

More small fixes

master
Matthieu Lalonde 13 years ago
parent d3f915740d
commit 140c7a6bdd

@ -24,8 +24,7 @@
defaults = [NSUserDefaults standardUserDefaults];
// check if the app is configured yet
if (![defaults boolForKey:@"configured"])
{
if (![defaults boolForKey:@"configured"]) {
[self initDefaults];
} else {
[self initialize];
@ -41,10 +40,7 @@
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
[wrt_client getConnectionStatus];
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
[self updateThroughput:nil];
}
- (void) deinitialize
@ -335,7 +331,7 @@
- (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) {
_wrtReachable = true;
if (showMenuIcon == true) {
@ -351,6 +347,12 @@
if (_wrtReachable == true) {
[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
@ -375,7 +377,9 @@
double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]);
_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 speedOut = diffOut / timeDiff;
@ -384,8 +388,8 @@
[ 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,
_lastOutThroughput, diffIn, diffOut, speedIn, speedOut, timeDiff);
//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);
}
_lastInThroughput = ifIn;
@ -399,6 +403,7 @@
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"];
[menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"];
@ -666,8 +671,6 @@
- (NSString *) stringFromSpeed:(uint64_t)theBytes
{
unsigned int minSize = /*(useBytes ? */1023/* : 999)*/;
unsigned int divSize = /*(useBytes ? */1024/* : 1000)*/;
NSString *suffix;
if (useBytes == false) {
@ -677,21 +680,21 @@
double floatSize = theBytes;
suffix = (useBytes ? @"B" : @"b");
if (theBytes<minSize)
if (theBytes<1023)
return([NSString stringWithFormat:@"%llu%@", theBytes, suffix]);
floatSize = floatSize / divSize;
floatSize = floatSize / 1024;
suffix = (useBytes ? @"KiB" : @"Kb");
if (floatSize<minSize)
if (floatSize<1023)
return([NSString stringWithFormat:@"%1.1f%@", floatSize, suffix]);
floatSize = floatSize / divSize;
floatSize = floatSize / 1024;
suffix = (useBytes ? @"MiB" : @"Mb");
if (floatSize<minSize)
if (floatSize<1023)
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
floatSize = floatSize / divSize;
floatSize = floatSize / 1024;
suffix = (useBytes ? @"GiB" : @"Gb");
if (floatSize<minSize)
if (floatSize<1023)
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
floatSize = floatSize / divSize;
floatSize = floatSize / 1024;
suffix = (useBytes ? @"TiB" : @"Tb");
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);

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

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

Loading…
Cancel
Save