aka RedditBar, Mac OS X menu bar reddit client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppDelegate.m 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // AppDelegate.m
  3. // RedditBar
  4. //
  5. // Created by Thomas Buck on 30.11.13.
  6. // Copyright (c) 2013 xythobuz. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. @implementation AppDelegate
  10. @synthesize statusMenu, statusItem, statusImage, statusHighlightImage, prefWindow, currentState, application;
  11. -(void)defaultPreferences {
  12. NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
  13. NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"" forKey:@"username"];
  14. [appDefaults setValue:@"" forKey:@"modhash"];
  15. [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:@"subscriptions"];
  16. [appDefaults setValue:[NSNumber numberWithInt:10] forKey:@"length"];
  17. [store registerDefaults:appDefaults];
  18. }
  19. -(void)savePreferences {
  20. NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
  21. [store setObject:currentState.username forKey:@"username"];
  22. [store setObject:currentState.modhash forKey:@"modhash"];
  23. [store setBool:currentState.useSubsciptions forKey:@"subscriptions"];
  24. [store setObject:currentState.subreddits forKey:@"subreddits"];
  25. [store setInteger:currentState.length forKey:@"length"];
  26. [store synchronize];
  27. }
  28. -(void)loadPreferences {
  29. NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
  30. [store synchronize];
  31. [currentState setUsername:[store stringForKey:@"username"]];
  32. [currentState setModhash:[store stringForKey:@"modhash"]];
  33. [currentState setUseSubsciptions:[store boolForKey:@"subscriptions"]];
  34. [currentState setSubreddits:[store arrayForKey:@"subreddits"]];
  35. [currentState setLength:[store integerForKey:@"length"]];
  36. }
  37. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  38. statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
  39. NSBundle *bundle = [NSBundle mainBundle];
  40. statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
  41. statusHighlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon-alt" ofType:@"png"]];
  42. [statusItem setImage:statusImage];
  43. [statusItem setAlternateImage:statusHighlightImage];
  44. [statusItem setMenu:statusMenu];
  45. [statusItem setToolTip:@"Reddit Bar"];
  46. [statusItem setHighlightMode:YES];
  47. [self defaultPreferences];
  48. currentState = [[StateModel alloc] init];
  49. [self loadPreferences]; // Fill currentState
  50. // TODO apply currentState
  51. // TODO reload menu list
  52. }
  53. -(IBAction)showPreferences:(id)sender {
  54. [NSApp activateIgnoringOtherApps:YES];
  55. prefWindow = [[PrefController alloc] initWithWindowNibName:@"Prefs"];
  56. [prefWindow setParent:self];
  57. [prefWindow setState:currentState];
  58. [prefWindow showWindow:self];
  59. }
  60. -(IBAction)showAbout:(id)sender {
  61. [NSApp activateIgnoringOtherApps:YES];
  62. [application orderFrontStandardAboutPanel:self];
  63. }
  64. -(void)prefReturnName:(NSString *)name Modhash:(NSString *)modhash subscriptions:(Boolean)subscriptions subreddits:(NSString *)subreddits length:(NSInteger)length {
  65. currentState.username = name;
  66. currentState.modhash = modhash;
  67. currentState.useSubsciptions = subscriptions;
  68. currentState.subreddits = [subreddits componentsSeparatedByString: @"\n"];
  69. currentState.length = length;
  70. [self savePreferences]; // write currentState
  71. // TODO apply currentState
  72. // TODO reload menu list
  73. }
  74. @end