1
0
Fork 0

FIXED - Protocol setting is now fully functional

MODIF - Init/deinit procedure, automatic preferences shown when no defaults exists
master
Matthieu Lalonde 14 years ago
parent 7aebb49d7e
commit 3f1e25babb

@ -86,6 +86,9 @@
BOOL _wrtReachable;
}
- (void) initialize;
- (void) deinitialize;
- (void) initDefaults;
- (void) readDefaults;
- (void) writeDefaults;
@ -121,6 +124,7 @@
- (void) throughputCallback:(NSData *)data;
- (void) doUpdateStatus:(NSData *)data;
- (NSMenu*) createCopyMenuItem;
- (IBAction) copyParentMenuTitle:(id)sender;
- (NSString *) stringFromSize:(uint64_t)theBytes;
- (NSString *) stringFromSpeed:(uint64_t)theBytes;

@ -27,11 +27,17 @@
if (![defaults boolForKey:@"configured"])
{
[self initDefaults];
[self showConfigPanel:nil];
} else {
[self initialize];
}
}
- (void) initialize
{
NSLog(@"Reading defaults...");
[self readDefaults];
// initialize the client
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
@ -42,8 +48,20 @@
[_readTimer fire];
}
- (void) deinitialize
{
[_readTimer invalidate];
_readTimer = nil;
[wrt_client release];
wrt_client = nil;
}
- (void) dealloc {
//[_readTimer invalidate];
if (_readTimer != nil) {
[_readTimer invalidate];
}
[AppMenu release];
[_appMenu release];
[ConfigPanel release];
@ -70,7 +88,6 @@
[defaults setBool:YES forKey:@"configured"];
// sync the defaults to disk
//[defaults registerDefaults:appDefaults];
[defaults synchronize];
// TODO: Add modal alert "First launch" here...
@ -104,7 +121,6 @@
[defaults setInteger:refreshTime forKey:@"refreshTime"];
// sync the defaults to disk
//[defaults registerDefaults:appDefaults];
[defaults synchronize];
}
@ -192,6 +208,15 @@
[configLabelRefresh setStringValue:[NSString stringWithFormat:@"%d s", ([defaults integerForKey:@"refreshTime"] + 1)]];
if ([protocol isEqualToString:@"http"] == true) {
[configFieldProtocolHTTP setState:1];
[configFieldProtocolHTTPS setState:0];
} else if ([protocol isEqualToString:@"https"] == true) {
[configFieldProtocolHTTP setState:0];
[configFieldProtocolHTTPS setState:1];
}
[ConfigPanel makeKeyAndOrderFront:nil];
}
@ -236,18 +261,15 @@
- (void) setConfigHostname:(id)sender
{
NSLog(@"%@", [sender title]);
}
- (IBAction) setConfigProtocol:(id)sender
{
NSLog(@"%@", [sender title]);
if ([sender state] == NSOnState) {
NSLog(@"Yes");
//NSLog(@"%s", [sender title]);
} else {
NSLog(@"No");
//NSLog(@"%s", [sender title]);
if ([configFieldProtocolHTTP state] == 1 && [[configFieldPort stringValue] isEqualToString:@"443"] == true) {
[configFieldPort setStringValue:@"80"];
} else if ([configFieldProtocolHTTPS state] == 1 && [[configFieldPort stringValue] isEqualToString:@"80"] == true) {
[configFieldPort setStringValue:@"443"];
}
}
@ -278,6 +300,8 @@
- (void) saveConfig:(id)sender
{
[self deinitialize];
[configStateStatus startAnimation:nil];
[configStateStatus setHidden:false];
@ -292,18 +316,17 @@
[defaults setInteger:port forKey:@"port"];
//NSLog(@"%d", [configFieldProtocol state]);
//NSLog(@"%d", [configFieldProtocolHTTP state]);
//NSLog(@"%d", [configFieldProtocolHTTPS state]);
if ([configFieldProtocolHTTP state] == 1) {
protocol = @"http";
} else if ([configFieldProtocolHTTPS state] == 1) {
protocol = @"https";
}
[defaults setValue:protocol forKey:@"protocol"];
refreshTime = [configFieldRefresh integerValue];
[defaults setInteger:refreshTime forKey:@"refreshTime"];
[_readTimer invalidate];
_readTimer = nil;
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
useBytes = ([configFieldUseBytes state] == 1 ? true: false);
[defaults setBool:useBytes forKey:@"useBytes"];
@ -321,6 +344,8 @@
[defaults synchronize];
[self initialize];
[self hideConfigPanel:nil];
}
@ -566,17 +591,15 @@
NSArray *clientsData = [clientsStringData componentsSeparatedByString:@","];
NSMenu *clientMenu;
NSMenu *copyMenu;
NSMenuItem *copyMenuItem;
NSMenuItem *clientMenuItem;
NSMenuItem *clientItem;
uint32_t clientsCount = [clientsData count] / 4;
uint16_t clientsCount = [clientsData count] / 4;
[menuClientsCount setTitle:[NSString stringWithFormat:@"%lu Active Client%@", clientsCount, (clientsCount > 1 ? @"s" : @"")]];
// Clear the old client data
uint32_t clientIndex;
uint32_t firstItem = [menuClients indexOfItem:menuClientsSeparator];
uint16_t clientIndex;
uint16_t firstItem = [menuClients indexOfItem:menuClientsSeparator];
if ([menuClients numberOfItems] > firstItem) {
for (clientIndex = ([menuClients numberOfItems] - 1); clientIndex > (firstItem + 1); clientIndex--) {
[menuClients removeItemAtIndex:clientIndex];
@ -584,49 +607,26 @@
}
for (clientIndex = 0; clientIndex < [clientsData count]; clientIndex+=4) {
/*NSLog(@"Client: %@ IP: %@ MAC: %@ Connections: %@",
[clientsData objectAtIndex:clientIndex],
[clientsData objectAtIndex:clientIndex+1],
[clientsData objectAtIndex:clientIndex+2],
[clientsData objectAtIndex:clientIndex+3]);
*/
// Allocate a new menu for the client data
clientMenu = [[NSMenu alloc] init];
// Hostname
copyMenu = [[NSMenu alloc] init];
copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:clientIndex] action:nil keyEquivalent:@""];
[clientMenuItem setSubmenu:copyMenu];
[clientMenuItem setSubmenu:[self createCopyMenuItem]];
[clientMenu addItem:clientMenuItem];
// IP
copyMenu = [[NSMenu alloc] init];
copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:(clientIndex+1)] action:nil keyEquivalent:@""];
[clientMenuItem setSubmenu:copyMenu];
[clientMenuItem setSubmenu:[self createCopyMenuItem]];
[clientMenu addItem:clientMenuItem];
// MAC
copyMenu = [[NSMenu alloc] init];
copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:(clientIndex+2)] action:nil keyEquivalent:@""];
[clientMenuItem setSubmenu:copyMenu];
[clientMenuItem setSubmenu:[self createCopyMenuItem]];
[clientMenu addItem:clientMenuItem];
// Connections
uint32_t conn = strtoull([[clientsData objectAtIndex:(clientIndex+3)] UTF8String], NULL, 0);
uint16_t conn = strtoull([[clientsData objectAtIndex:(clientIndex+3)] UTF8String], NULL, 0);
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%lu Connection%@", conn, (conn > 1 ? @"s" : @"")] action:nil keyEquivalent:@""];
[clientMenu addItem:clientMenuItem];
@ -642,6 +642,17 @@
[_readTimer fire];
}
- (NSMenu*) createCopyMenuItem
{
NSMenu *copyMenu = [[NSMenu alloc] init];
NSMenuItem *copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
return [copyMenu retain];
}
- (IBAction) copyParentMenuTitle:(id)sender
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];

@ -539,7 +539,7 @@
<string key="NSWindowClass">NSPanel</string>
<nil key="NSViewClass"/>
<object class="NSView" key="NSWindowView" id="284387334">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -558,6 +558,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{129, 55}, {125, 17}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="635692332"/>
<bool key="NSEnabled">YES</bool>
<object class="NSSliderCell" key="NSCell" id="272108650">
@ -585,6 +586,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 56}, {62, 14}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="166127716"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="341827300">
@ -618,6 +620,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{79, 56}, {45, 14}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="307276419"/>
<int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
@ -637,6 +640,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{82, 125}, {171, 16}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="163286529"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="795612448">
@ -673,6 +677,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 125}, {62, 14}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="808975838"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="826089764">
@ -690,6 +695,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 105}, {62, 14}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="348326688"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="667385484">
@ -707,6 +713,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{82, 103}, {126, 18}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="925158413"/>
<bool key="NSEnabled">YES</bool>
<int key="NSNumRows">1</int>
@ -820,6 +827,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{82, 82}, {39, 16}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1066090534"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="794333226">
@ -839,6 +847,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 82}, {62, 14}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1065807232"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="1037922107">
@ -856,6 +865,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 32}, {74, 18}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="170030078"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="809457279">
@ -884,6 +894,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 12}, {76, 18}}</string>
<reference key="NSSuperview" ref="812058280"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="371817589"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="1072996452">
@ -905,11 +916,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
<string key="NSFrame">{{1, 1}, {272, 152}}</string>
<reference key="NSSuperview" ref="306918856"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="588704663"/>
</object>
</object>
<string key="NSFrame">{{17, 41}, {274, 168}}</string>
<reference key="NSSuperview" ref="284387334"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="812058280"/>
<string key="NSOffsets">{0, 0}</string>
<object class="NSTextFieldCell" key="NSTitleCell">
@ -934,6 +947,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{156, 195}, {135, 17}}</string>
<reference key="NSSuperview" ref="284387334"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="7094024"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="190007600">
@ -954,6 +968,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{213, 20}, {75, 17}}</string>
<reference key="NSSuperview" ref="284387334"/>
<reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="373752751">
<int key="NSCellFlags">-2080244224</int>
@ -974,6 +989,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{130, 20}, {75, 17}}</string>
<reference key="NSSuperview" ref="284387334"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="179819426"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="367012609">
@ -996,6 +1012,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<object class="NSPSMatrix" key="NSDrawMatrix"/>
<string key="NSFrame">{{20, 20}, {16, 16}}</string>
<reference key="NSSuperview" ref="284387334"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="184594776"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<int key="NSpiFlags">20746</int>
@ -1003,6 +1020,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
</object>
<string key="NSFrame">{{7, 11}, {308, 232}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="306918856"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2048, 1130}}</string>
@ -1579,6 +1598,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
<int key="connectionID">823</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">setConfigProtocol:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="348326688"/>
</object>
<int key="connectionID">826</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -2631,7 +2658,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">824</int>
<int key="maxID">826</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">

Loading…
Cancel
Save