1
0
Fork 0

Added some modal alerts for first run and cancel prefs save on first run.

master
Matthieu Lalonde 14 years ago
parent 9b30a400f2
commit 7b495f22a9

@ -90,6 +90,7 @@
- (void) terminate:(id)sender; - (void) terminate:(id)sender;
- (void) initialize; - (void) initialize;
- (void) deinitialize; - (void) deinitialize;
- (void) showInitAlert;
- (IBAction) showBandwidthViewer:(id)sender; - (IBAction) showBandwidthViewer:(id)sender;
# pragma mark Menu Methods: # pragma mark Menu Methods:

@ -10,23 +10,23 @@
@implementation DDWRT_MonitorAppDelegate @implementation DDWRT_MonitorAppDelegate
# pragma mark - # pragma mark -
# pragma mark Application Delegates: # pragma mark Application Delegates:
- (void) awakeFromNib - (void) awakeFromNib
{ {
// Insert code here to initialize your application // Insert code here to initialize your application
[self showMenubar];
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"] || [[defaults stringForKey:@"hostname"] length] == 0) {
[self showInitAlert];
[self initDefaults]; [self initDefaults];
} else { } else {
[self initialize]; [self initialize];
} }
[self showMenubar];
} }
- (void) dealloc { - (void) dealloc {
@ -34,10 +34,13 @@
[_appMenu release]; [_appMenu release];
[ConfigPanel release]; [ConfigPanel release];
[BandwidthViewer release]; [BandwidthViewer release];
[super dealloc]; [super dealloc];
} }
- (void) terminate:(id)sender { - (void) terminate:(id)sender {
[self deinitialize];
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
[self dealloc]; [self dealloc];
[[NSApplication sharedApplication] terminate:self]; [[NSApplication sharedApplication] terminate:self];
@ -64,6 +67,7 @@
if (_updateTimer != nil) { if (_updateTimer != nil) {
[_updateTimer invalidate]; [_updateTimer invalidate];
_updateTimer = nil; _updateTimer = nil;
[_updateTimer release];
} }
[wrt_update_client release]; [wrt_update_client release];
@ -73,6 +77,16 @@
wrt_request_client = nil; wrt_request_client = nil;
} }
- (void) showInitAlert
{
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:@"First Launch!"];
[alert setInformativeText:@"In order to conitnue, you must first provide your router settings."];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert runModal];
}
- (IBAction) showBandwidthViewer:(id)sender - (IBAction) showBandwidthViewer:(id)sender
{ {
[ [BandwidthViewerWebView mainFrame] loadRequest: [wrt_update_client requestForBandwidthViewerForInterface:[wrt_update_client getWanPort]] ]; [ [BandwidthViewerWebView mainFrame] loadRequest: [wrt_update_client requestForBandwidthViewerForInterface:[wrt_update_client getWanPort]] ];
@ -150,7 +164,7 @@
// do any other initialization you want to do here - e.g. the starting default values. // do any other initialization you want to do here - e.g. the starting default values.
[defaults setValue:@"http" forKey:@"protocol"]; [defaults setValue:@"http" forKey:@"protocol"];
[defaults setValue:@"192.168.1.1" forKey:@"hostname"]; [defaults setValue:@"" forKey:@"hostname"];
[defaults setInteger:80 forKey:@"port"]; [defaults setInteger:80 forKey:@"port"];
[defaults setValue:@"" forKey:@"username"]; [defaults setValue:@"" forKey:@"username"];
[defaults setValue:@"" forKey:@"password"]; [defaults setValue:@"" forKey:@"password"];
@ -161,7 +175,6 @@
[defaults setBool:YES forKey:@"configured"]; [defaults setBool:YES forKey:@"configured"];
// TODO: Add modal alert "First launch" here...
[self showConfigPanel:self]; [self showConfigPanel:self];
} }
@ -205,8 +218,6 @@
[configFieldHostname setStringValue:hostname]; [configFieldHostname setStringValue:hostname];
} }
// TODO
[configFieldPort setIntValue:[defaults integerForKey:@"port"]]; [configFieldPort setIntValue:[defaults integerForKey:@"port"]];
[configFieldRefresh setIntegerValue:[defaults integerForKey:@"refreshTime"]]; [configFieldRefresh setIntegerValue:[defaults integerForKey:@"refreshTime"]];
@ -226,12 +237,23 @@
- (IBAction) hideConfigPanel:(id)sender - (IBAction) hideConfigPanel:(id)sender
{ {
if (hostname == nil && [[sender title] isEqualToString:@"Cancel"]) { if ([hostname length] == 0 && [[sender title] isEqualToString:@"Cancel"]) {
// TODO: Add modal alert "will quit if not configured" NSAlert *alert = [NSAlert alertWithMessageText:@"Application Not Configured!"
[self terminate:nil]; defaultButton:@"Cancel" alternateButton:@"Ok" otherButton:nil
} informativeTextWithFormat:@"The application will quit now."
];
[alert setAlertStyle:NSCriticalAlertStyle];
NSInteger button = [alert runModal];
[ConfigPanel orderOut:nil]; if (button != NSAlertDefaultReturn) {
[self terminate:nil];
[ConfigPanel orderOut:nil];
}
} else {
[ConfigPanel orderOut:nil];
}
} }
- (IBAction) setConfigProtocol:(id)sender - (IBAction) setConfigProtocol:(id)sender
@ -362,7 +384,6 @@
- (void) getRouterData:(NSData *)data - (void) getRouterData:(NSData *)data
{ {
NSLog(@"Gathering status data");
if (data != nil) { if (data != nil) {
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
@ -370,20 +391,18 @@
_statusStringData = [newStringData retain]; _statusStringData = [newStringData retain];
} else { } else {
NSLog(@"No data received yet"); _statusStringData = @"";
_statusDataRequestNumber = 0;
} }
switch (_statusDataRequestNumber++) { switch (_statusDataRequestNumber++) {
case 0: case 0:
NSLog(@"Status 0");
[wrt_request_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(getRouterData:)]; [wrt_request_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(getRouterData:)];
break; break;
case 1: case 1:
NSLog(@"Status 1");
[wrt_request_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(getRouterData:)]; [wrt_request_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(getRouterData:)];
break; break;
case 2: case 2:
NSLog(@"Status 2");
[wrt_request_client getStatusUpdate:@"Status_Lan.live.asp" delegate:self callback:@selector(getRouterData:)]; [wrt_request_client getStatusUpdate:@"Status_Lan.live.asp" delegate:self callback:@selector(getRouterData:)];
break; break;
case 3: case 3:
@ -395,9 +414,6 @@
// Show the menu // Show the menu
[_appMenu popUpStatusItemMenu:AppMenu]; [_appMenu popUpStatusItemMenu:AppMenu];
_statusStringData = @"";
_statusDataRequestNumber = 0;
break; break;
} }
} }

@ -1260,22 +1260,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<int key="connectionID">754</int> <int key="connectionID">754</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menu</string>
<reference key="source" ref="284387334"/>
<reference key="destination" ref="1033903501"/>
</object>
<int key="connectionID">755</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menu</string>
<reference key="source" ref="40768770"/>
<reference key="destination" ref="1033903501"/>
</object>
<int key="connectionID">756</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection"> <object class="IBOutletConnection" key="connection">
<string key="label">configFieldHostname</string> <string key="label">configFieldHostname</string>
@ -1468,14 +1452,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<int key="connectionID">811</int> <int key="connectionID">811</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="492386921"/>
<reference key="destination" ref="976324537"/>
</object>
<int key="connectionID">812</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection"> <object class="IBOutletConnection" key="connection">
<string key="label">delegate</string> <string key="label">delegate</string>
@ -1484,14 +1460,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<int key="connectionID">813</int> <int key="connectionID">813</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="206781734"/>
<reference key="destination" ref="976324537"/>
</object>
<int key="connectionID">814</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection"> <object class="IBOutletConnection" key="connection">
<string key="label">menuClientsCount</string> <string key="label">menuClientsCount</string>
@ -1564,6 +1532,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<int key="connectionID">826</int> <int key="connectionID">826</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="1050"/>
<reference key="destination" ref="976324537"/>
</object>
<int key="connectionID">841</int>
</object>
</object> </object>
<object class="IBMutableOrderedSet" key="objectRecords"> <object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects"> <object class="NSArray" key="orderedObjects">
@ -2616,7 +2592,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<reference key="dict.values" ref="0"/> <reference key="dict.values" ref="0"/>
</object> </object>
<nil key="sourceID"/> <nil key="sourceID"/>
<int key="maxID">840</int> <int key="maxID">841</int>
</object> </object>
<object class="IBClassDescriber" key="IBDocument.Classes"> <object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions"> <object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -2634,6 +2610,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>saveConfig:</string> <string>saveConfig:</string>
<string>setConfigProtocol:</string> <string>setConfigProtocol:</string>
<string>setConfigRefresh:</string> <string>setConfigRefresh:</string>
<string>showBandwidthViewer:</string>
<string>showConfigPanel:</string> <string>showConfigPanel:</string>
</object> </object>
<object class="NSMutableArray" key="dict.values"> <object class="NSMutableArray" key="dict.values">
@ -2645,6 +2622,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>id</string> <string>id</string>
<string>id</string> <string>id</string>
<string>id</string> <string>id</string>
<string>id</string>
</object> </object>
</object> </object>
<object class="NSMutableDictionary" key="actionInfosByName"> <object class="NSMutableDictionary" key="actionInfosByName">
@ -2657,6 +2635,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>saveConfig:</string> <string>saveConfig:</string>
<string>setConfigProtocol:</string> <string>setConfigProtocol:</string>
<string>setConfigRefresh:</string> <string>setConfigRefresh:</string>
<string>showBandwidthViewer:</string>
<string>showConfigPanel:</string> <string>showConfigPanel:</string>
</object> </object>
<object class="NSMutableArray" key="dict.values"> <object class="NSMutableArray" key="dict.values">
@ -2685,6 +2664,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string key="name">setConfigRefresh:</string> <string key="name">setConfigRefresh:</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>
</object> </object>
<object class="IBActionInfo">
<string key="name">showBandwidthViewer:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo"> <object class="IBActionInfo">
<string key="name">showConfigPanel:</string> <string key="name">showConfigPanel:</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>

Loading…
Cancel
Save