aka RedditBar, Mac OS X menu bar reddit client
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PrefController.m 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // PrefController.m
  3. // RedditBar
  4. //
  5. // Created by Thomas Buck on 30.11.13.
  6. // Copyright (c) 2013 xythobuz. All rights reserved.
  7. //
  8. #import "PrefController.h"
  9. #import "AppDelegate.h"
  10. @implementation PrefController
  11. @synthesize username, password, subscriptions, subreddits, win, parent, state, lengthFormat, lengthField, lengthStepper, length;
  12. -(Boolean)isValidList:(NSString *)input {
  13. NSCharacterSet *invalidChars = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_\n"] invertedSet];
  14. if ([input rangeOfCharacterFromSet:invalidChars].location != NSNotFound) {
  15. return FALSE;
  16. } else {
  17. return TRUE;
  18. }
  19. }
  20. -(void)showWindow:(id)sender {
  21. [super showWindow:sender];
  22. [username setStringValue:state.username];
  23. // TODO what to do with modhash and password field??
  24. [subscriptions setState:[NSNumber numberWithBool:state.useSubsciptions].integerValue];
  25. [self toggleSubs:nil]; // Maybe the subreddits field needs to be editable
  26. NSMutableString *reddits = [[NSMutableString alloc] init];
  27. for(int i = 0; i < [state.subreddits count]; i++) {
  28. [reddits appendFormat:@"%@\n", [state.subreddits objectAtIndex:i]];
  29. }
  30. [subreddits setString:reddits];
  31. length = state.length;
  32. [lengthStepper setIntegerValue:length];
  33. [lengthField setIntegerValue:length];
  34. }
  35. -(IBAction)buttonSave:(id)sender {
  36. Boolean subs;
  37. if (subscriptions.state != 0) {
  38. subs = TRUE;
  39. } else {
  40. subs = FALSE;
  41. if (![self isValidList:subreddits.textStorage.string]) {
  42. NSAlert *alert = [[NSAlert alloc] init];
  43. [alert addButtonWithTitle:@"OK"];
  44. [alert setMessageText:@"Preferences Error"];
  45. [alert setInformativeText:@"Subreddit List Invalid!"];
  46. [alert setAlertStyle:NSCriticalAlertStyle];
  47. [alert beginSheetModalForWindow:win modalDelegate:nil didEndSelector:nil contextInfo:nil];
  48. return;
  49. }
  50. }
  51. // TODO if username / password changed, get modhash! Else, use the one we got from init
  52. NSString *modhash;
  53. AppDelegate *app = (AppDelegate *)parent;
  54. [app prefReturnName:username.stringValue Modhash:modhash subscriptions:subs subreddits:subreddits.textStorage.string length:length];
  55. [win performClose:self];
  56. }
  57. -(IBAction)toggleSubs:(id)sender {
  58. if (subscriptions.state != 0) {
  59. [subreddits setEditable:FALSE];
  60. } else {
  61. [subreddits setEditable:TRUE];
  62. }
  63. }
  64. -(IBAction)lengthDidChange:(id)sender {
  65. length = [sender integerValue];
  66. [lengthStepper setIntegerValue:length];
  67. [lengthField setIntegerValue:length];
  68. }
  69. @end