From 720112a9cb9927e9fa654ec7048b82641a25ef70 Mon Sep 17 00:00:00 2001 From: Spike Grobstein Date: Tue, 31 May 2011 19:48:11 -0400 Subject: [PATCH] beginnings of rewrite of defaults reading/writing --- .../UserInterfaceState.xcuserstate | 393 ++++++++++++------ DDWRT_MonitorAppDelegate.h | 6 +- DDWRT_MonitorAppDelegate.m | 79 ++-- 3 files changed, 311 insertions(+), 167 deletions(-) diff --git a/DDWRT-Monitor.xcodeproj/project.xcworkspace/xcuserdata/spike.xcuserdatad/UserInterfaceState.xcuserstate b/DDWRT-Monitor.xcodeproj/project.xcworkspace/xcuserdata/spike.xcuserdatad/UserInterfaceState.xcuserstate index ba0439c..3e7eab5 100644 --- a/DDWRT-Monitor.xcodeproj/project.xcworkspace/xcuserdata/spike.xcuserdatad/UserInterfaceState.xcuserstate +++ b/DDWRT-Monitor.xcodeproj/project.xcworkspace/xcuserdata/spike.xcuserdatad/UserInterfaceState.xcuserstate @@ -2801,9 +2801,9 @@ - 328577815.697043 - {930, 959} - {1434, 0} + 328578404.99264902 + {733, 885} + {1321, 0} $class @@ -2897,9 +2897,9 @@ - 328577902.92416799 - {0, 1089} - {2472, 0} + 328578489.274598 + {1044, 1134} + {2148, 0} $class @@ -3586,7 +3586,7 @@ 323 NS.time - 328577829.65523702 + 328578485.318919 $classes @@ -3597,7 +3597,7 @@ $classname NSDate - Today at 7:37 PM + Today at 7:48 PM 106 $class @@ -3893,7 +3893,7 @@ CF$UID - 464 + 473 CF$UID @@ -3905,7 +3905,7 @@ CF$UID - 465 + 474 @@ -3975,7 +3975,7 @@ CF$UID - 407 + 409 CF$UID @@ -3983,7 +3983,7 @@ CF$UID - 415 + 417 @@ -4124,19 +4124,19 @@ CF$UID - 372 + 374 CF$UID - 376 + 378 CF$UID - 42 + 362 CF$UID - 389 + 391 @@ -4208,7 +4208,7 @@ CF$UID - 366 + 369 @@ -4220,13 +4220,18 @@ 13 NS.objects - + + + CF$UID + 366 + + $class CF$UID - 53 + 38 NS.objects @@ -4236,8 +4241,24 @@ CF$UID - 369 + 65 + + CF$UID + 368 + + + + DDWRT-Monitor + DDWRT_MonitorAppDelegate.m + + $class + + CF$UID + 53 + + NS.objects + CF$UID 370 @@ -4246,6 +4267,14 @@ CF$UID 371 + + CF$UID + 372 + + + CF$UID + 373 + @@ -4258,11 +4287,10 @@ CF$UID - 368 + 367 - DDWRT-Monitor $class @@ -4273,7 +4301,7 @@ CF$UID - 368 + 367 CF$UID @@ -4291,7 +4319,7 @@ CF$UID - 368 + 367 CF$UID @@ -4309,7 +4337,7 @@ CF$UID - 368 + 367 CF$UID @@ -4327,15 +4355,15 @@ CF$UID - 373 + 375 CF$UID - 374 + 376 CF$UID - 375 + 377 NS.objects @@ -4367,31 +4395,31 @@ CF$UID - 377 + 379 CF$UID - 378 + 380 CF$UID - 379 + 381 CF$UID - 380 + 382 CF$UID - 381 + 383 CF$UID - 382 + 384 CF$UID - 383 + 385 NS.objects @@ -4410,11 +4438,11 @@ CF$UID - 384 + 386 CF$UID - 385 + 387 CF$UID @@ -4422,7 +4450,7 @@ CF$UID - 387 + 389 @@ -4438,7 +4466,7 @@ $class CF$UID - 386 + 388 NSRangeCount 0 @@ -4456,7 +4484,7 @@ $class CF$UID - 388 + 390 NSRangeCount 0 @@ -4479,14 +4507,6 @@ NS.keys - - CF$UID - 390 - - - CF$UID - 391 - CF$UID 392 @@ -4519,6 +4539,14 @@ CF$UID 399 + + CF$UID + 400 + + + CF$UID + 401 + NS.objects @@ -4528,19 +4556,19 @@ CF$UID - 400 + 402 CF$UID - 401 + 403 CF$UID - 403 + 405 CF$UID - 404 + 406 CF$UID @@ -4552,7 +4580,7 @@ CF$UID - 405 + 407 CF$UID @@ -4560,7 +4588,7 @@ CF$UID - 406 + 408 @@ -4579,7 +4607,7 @@ $class CF$UID - 402 + 404 NS.objects @@ -4598,7 +4626,7 @@ $class CF$UID - 402 + 404 NS.objects @@ -4616,7 +4644,7 @@ $class CF$UID - 402 + 404 NS.objects @@ -4625,7 +4653,7 @@ $class CF$UID - 402 + 404 NS.objects @@ -4647,7 +4675,7 @@ CF$UID - 408 + 410 @@ -4661,15 +4689,15 @@ CF$UID - 409 + 411 CF$UID - 411 + 413 CF$UID - 413 + 415 @@ -4698,7 +4726,7 @@ CF$UID - 410 + 412 @@ -4728,7 +4756,7 @@ CF$UID - 412 + 414 @@ -4758,7 +4786,7 @@ CF$UID - 414 + 416 @@ -4808,15 +4836,15 @@ CF$UID - 416 + 418 CF$UID - 424 + 430 CF$UID - 442 + 451 CF$UID @@ -4828,11 +4856,11 @@ CF$UID - 457 + 466 CF$UID - 463 + 472 CF$UID @@ -4854,12 +4882,12 @@ primaryEditorContextNode CF$UID - 417 + 419 rootLayoutTreeNode CF$UID - 422 + 428 @@ -4878,14 +4906,14 @@ documentArchivableRepresentation CF$UID - 418 + 420 orientation 0 parent CF$UID - 422 + 428 @@ -4897,22 +4925,22 @@ DocumentLocation CF$UID - 421 + 426 DomainIdentifier CF$UID - 0 + 87 IdentifierPath CF$UID - 419 + 421 IndexOfDocumentIdentifier CF$UID - 420 + 26 @@ -4922,9 +4950,58 @@ 13 NS.objects - + + + CF$UID + 422 + + + CF$UID + 423 + + + CF$UID + 424 + + - 9223372036854775807 + + $class + + CF$UID + 90 + + Identifier + + CF$UID + 368 + + + + $class + + CF$UID + 90 + + Identifier + + CF$UID + 65 + + + + $class + + CF$UID + 90 + + Identifier + + CF$UID + 425 + + + DDWRT-Monitor $class @@ -4934,7 +5011,7 @@ documentURL CF$UID - 336 + 427 timestamp @@ -4942,6 +5019,15 @@ 0 + + $class + + CF$UID + 97 + + NS.string + file://localhost/Users/spike/Downloads/DDWRT-Monitor/DDWRT_MonitorAppDelegate.m + $class @@ -4951,7 +5037,7 @@ children CF$UID - 423 + 429 contentType 0 @@ -4978,7 +5064,7 @@ CF$UID - 417 + 419 @@ -4999,7 +5085,7 @@ CF$UID - 425 + 431 @@ -5020,7 +5106,7 @@ CF$UID - 426 + 432 @@ -5049,7 +5135,7 @@ CF$UID - 427 + 433 CF$UID @@ -5057,7 +5143,7 @@ CF$UID - 440 + 449 @@ -5071,7 +5157,7 @@ CF$UID - 428 + 434 @@ -5116,23 +5202,23 @@ CF$UID - 429 + 435 CF$UID - 430 + 436 CF$UID - 433 + 442 CF$UID - 437 + 446 CF$UID - 438 + 368 CF$UID @@ -5140,7 +5226,7 @@ CF$UID - 439 + 447 @@ -5154,22 +5240,22 @@ DocumentLocation CF$UID - 421 + 426 DomainIdentifier CF$UID - 0 + 87 IdentifierPath CF$UID - 431 + 437 IndexOfDocumentIdentifier CF$UID - 432 + 26 @@ -5179,9 +5265,58 @@ 13 NS.objects - + + + CF$UID + 438 + + + CF$UID + 439 + + + CF$UID + 440 + + + + + $class + + CF$UID + 90 + + Identifier + + CF$UID + 368 + - 9223372036854775807 + + $class + + CF$UID + 90 + + Identifier + + CF$UID + 65 + + + + $class + + CF$UID + 90 + + Identifier + + CF$UID + 441 + + + DDWRT-Monitor $class @@ -5211,11 +5346,11 @@ CF$UID - 434 + 443 CF$UID - 435 + 444 CF$UID @@ -5223,15 +5358,14 @@ CF$UID - 436 + 445 - 328577902.926952 - {0, 1089} - {2472, 0} - @implementation DDWRT_MonitorAppDelegate - DDWRT_MonitorAppDelegate.m + 328578489.277578 + {1044, 1134} + {2148, 0} + -initDefaults $class @@ -5246,9 +5380,10 @@ NS.relative CF$UID - 336 + 448 + file://localhost/Users/spike/Downloads/DDWRT-Monitor/DDWRT_MonitorAppDelegate.m $class @@ -5259,7 +5394,7 @@ CF$UID - 441 + 450 @@ -5305,11 +5440,11 @@ CF$UID - 443 + 452 CF$UID - 444 + 453 CF$UID @@ -5317,11 +5452,11 @@ CF$UID - 445 + 454 CF$UID - 451 + 460 @@ -5384,7 +5519,7 @@ CF$UID - 446 + 455 @@ -5398,11 +5533,11 @@ CF$UID - 447 + 456 CF$UID - 449 + 458 @@ -5431,7 +5566,7 @@ CF$UID - 448 + 457 @@ -5461,7 +5596,7 @@ CF$UID - 450 + 459 @@ -5483,7 +5618,7 @@ CF$UID - 452 + 461 @@ -5497,11 +5632,11 @@ CF$UID - 453 + 462 CF$UID - 455 + 464 @@ -5530,7 +5665,7 @@ CF$UID - 454 + 463 @@ -5560,7 +5695,7 @@ CF$UID - 456 + 465 @@ -5582,7 +5717,7 @@ CF$UID - 458 + 467 @@ -5596,11 +5731,11 @@ CF$UID - 459 + 468 CF$UID - 461 + 470 @@ -5629,7 +5764,7 @@ CF$UID - 460 + 469 @@ -5659,7 +5794,7 @@ CF$UID - 462 + 471 diff --git a/DDWRT_MonitorAppDelegate.h b/DDWRT_MonitorAppDelegate.h index cc677c0..f69c56a 100644 --- a/DDWRT_MonitorAppDelegate.h +++ b/DDWRT_MonitorAppDelegate.h @@ -50,7 +50,8 @@ IBOutlet id menuWanDNSItem2; IBOutlet id menuWanBandwidthGraph; - + NSUserDefaults *defaults; + NSStatusItem *_appMenu; NSAlert *modalWindow; @@ -65,6 +66,9 @@ BOOL _wrtReachable; } +- (void) initDefaults; +- (void) readDefaults; + - (void) terminate:(id)sender; - (void) showConfigPanel:(id)sender; - (void) hideConfigPanel:(id)sender; diff --git a/DDWRT_MonitorAppDelegate.m b/DDWRT_MonitorAppDelegate.m index b2d6c3d..00ed349 100644 --- a/DDWRT_MonitorAppDelegate.m +++ b/DDWRT_MonitorAppDelegate.m @@ -14,44 +14,23 @@ //- (void)applicationDidFinishLaunching:(NSNotification *)aNotification - (void) awakeFromNib -{ - NSLog(@"Spike debug start."); - +{ wrt_client = [[WRTStatusClient alloc] initWithHostname:@"router" port:80 username:@"spike" password:@"aaaassss"]; - - [wrt_client getStatusUpdate:@"graph_if.svg?vlan2" delegate: self]; - - NSLog(@"Spike debug end."); - + // Insert code here to initialize your application [self showMenubar]; _wrtReachable = false; - // initialize defaults - NSString *hostname = [[NSUserDefaults standardUserDefaults] stringForKey:@"hostname"]; - - if (hostname == nil) // App first run: set up user defaults. + defaults = [NSUserDefaults standardUserDefaults]; + + // check if the app is configured yet + if (![defaults boolForKey:@"configured"]) { - NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:nil]; - - NSLog(@"Creating new user defaults"); - - // do any other initialization you want to do here - e.g. the starting default values. - //[[NSUserDefaults standardUserDefaults] setObject:@"192.168.1.1" foKey:@"hostname"]; - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showMenuIcon"]; - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"useBytes"]; - [[NSUserDefaults standardUserDefaults] setInteger:80 forKey:@"port"]; - [[NSUserDefaults standardUserDefaults] setInteger:4 forKey:@"refreshTime"]; - - // sync the defaults to disk - [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; - [[NSUserDefaults standardUserDefaults] synchronize]; - - // TODO: Add modal alert "First launch" here... - [self showConfigPanel:nil]; + [self initDefaults]; } else { + [self readDefaults]; NSLog(@"Using existing user defaults"); //_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; @@ -59,9 +38,9 @@ [self updateThroughput]; - WRTRequest *wrtr = [[WRTRequest alloc] init]; + //WRTRequest *wrtr = [[WRTRequest alloc] init]; - [wrtr doRequest:self requestSelector:@selector(doUpdateStatus:) uri:@"Status_Router.live.asp"]; + //[wrtr doRequest:self requestSelector:@selector(doUpdateStatus:) uri:@"Status_Router.live.asp"]; } } @@ -75,6 +54,32 @@ [super dealloc]; } +- (void) initDefaults +{ + NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:nil]; + + NSLog(@"Creating new user defaults"); + + // do any other initialization you want to do here - e.g. the starting default values. + //[[NSUserDefaults standardUserDefaults] setObject:@"192.168.1.1" foKey:@"hostname"]; + [defaults setBool:YES forKey:@"showMenuIcon"]; + [defaults setBool:YES forKey:@"useBytes"]; + [defaults setInteger:80 forKey:@"port"]; + [defaults setInteger:4 forKey:@"refreshTime"]; + + // sync the defaults to disk + [defaults registerDefaults:appDefaults]; + [defaults synchronize]; + + // TODO: Add modal alert "First launch" here... + [self showConfigPanel:self]; +} + +- (void) readDefaults +{ + +} + - (void) terminate:(id)sender { [[NSUserDefaults standardUserDefaults] synchronize]; [self dealloc]; @@ -241,9 +246,9 @@ [configStateStatus startAnimation:nil]; [configStateStatus setHidden:false]; - WRTRequest *wrtr = [[WRTRequest alloc] init]; + //WRTRequest *wrtr = [[WRTRequest alloc] init]; - [wrtr doRequest:self requestSelector:@selector(configSaveRequestCallback:) uri:@"Status_Router.live.asp"]; + //[wrtr doRequest:self requestSelector:@selector(configSaveRequestCallback:) uri:@"Status_Router.live.asp"]; } -(NSString *)getKey:(NSString *)stringData key:(NSString *)key @@ -308,9 +313,9 @@ - (void) updateThroughput { - WRTRequest *wrtr = [[WRTRequest alloc] init]; + //WRTRequest *wrtr = [[WRTRequest alloc] init]; - [wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"]; + //[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"]; } - (void) throughputCallback:(NSData *)data @@ -367,9 +372,9 @@ - (void) refreshWanMenu:(id)sender { NSLog(@"Refreshing Wan Menu"); - WRTRequest *wrtr = [[WRTRequest alloc] init]; + //WRTRequest *wrtr = [[WRTRequest alloc] init]; - [wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"]; + //[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"]; } - (void) wanRequestCallback:(NSData *)data