aka RedditBar, Mac OS X menu bar reddit client
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

StateModel.m 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * StateModel.m
  3. *
  4. * Copyright (c) 2013, Thomas Buck <xythobuz@xythobuz.de>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. *
  13. * - Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #import "StateModel.h"
  30. #import <ServiceManagement/ServiceManagement.h>
  31. @implementation StateModel
  32. @synthesize username, modhash, useSubscriptions, subreddits, length, showSubreddit, titleLength, refreshInterval, filter, removeVisited, reloadAfterVisit, lastNotifiedPM, startOnLogin;
  33. NSString *s_username = @"username";
  34. NSString *s_modhash = @"modhash";
  35. NSString *s_useSubs = @"subscriptions";
  36. NSString *s_subreddits = @"subreddits";
  37. NSString *s_length = @"length";
  38. NSString *s_subs = @"showSubs";
  39. NSString *s_title = @"titleLength";
  40. NSString *s_refresh = @"refreshInterval";
  41. NSString *s_filter = @"filter";
  42. NSString *s_remove = @"remove";
  43. NSString *s_reload = @"reload";
  44. NSString *s_lastPM = @"lastNotifiedPM";
  45. NSString *s_startLogin = @"startOnLogin";
  46. -(void)registerDefaultPreferences {
  47. NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
  48. NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"" forKey:s_username];
  49. [appDefaults setValue:@"" forKey:s_modhash];
  50. [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_useSubs];
  51. [appDefaults setValue:[NSNumber numberWithInt:10] forKey:s_length];
  52. [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_subs];
  53. [appDefaults setValue:[NSNumber numberWithInt:66] forKey:s_title];
  54. [appDefaults setValue:[NSNumber numberWithInt:5] forKey:s_refresh];
  55. [appDefaults setValue:@"hot" forKey:s_filter];
  56. [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_remove];
  57. [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_reload];
  58. [appDefaults setValue:@"" forKey:s_lastPM];
  59. [appDefaults setValue:[NSNumber numberWithBool:NO] forKey:s_startLogin];
  60. [store registerDefaults:appDefaults];
  61. }
  62. -(void)savePreferences {
  63. NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
  64. [store setObject:username forKey:s_username];
  65. [store setObject:modhash forKey:s_modhash];
  66. [store setBool:useSubscriptions forKey:s_useSubs];
  67. [store setObject:subreddits forKey:s_subreddits];
  68. [store setInteger:length forKey:s_length];
  69. [store setBool:showSubreddit forKey:s_subs];
  70. [store setInteger:titleLength forKey:s_title];
  71. [store setInteger:refreshInterval forKey:s_refresh];
  72. [store setObject:filter forKey:s_filter];
  73. [store setBool:removeVisited forKey:s_remove];
  74. [store setBool:reloadAfterVisit forKey:s_reload];
  75. [store setObject:lastNotifiedPM forKey:s_lastPM];
  76. [store synchronize];
  77. // TODO start on login on or off
  78. if (startOnLogin != [store boolForKey:s_startLogin]) {
  79. NSString *appName = [NSString stringWithFormat:@"%@Helper", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]];
  80. if (SMLoginItemSetEnabled((__bridge CFStringRef)appName, startOnLogin)) {
  81. [store setBool:startOnLogin forKey:s_startLogin];
  82. } else {
  83. startOnLogin = !startOnLogin; // Propagate revert of users change to the UI
  84. }
  85. }
  86. }
  87. -(void)loadPreferences {
  88. NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
  89. [store synchronize];
  90. username = [store stringForKey:s_username];
  91. modhash = [store stringForKey:s_modhash];
  92. useSubscriptions = [store boolForKey:s_useSubs];
  93. subreddits = [store arrayForKey:s_subreddits];
  94. length = [store integerForKey:s_length];
  95. showSubreddit = [store boolForKey:s_subs];
  96. titleLength = [store integerForKey:s_title];
  97. refreshInterval = [store integerForKey:s_refresh];
  98. filter = [store stringForKey:s_filter];
  99. removeVisited = [store boolForKey:s_remove];
  100. reloadAfterVisit = [store boolForKey:s_reload];
  101. lastNotifiedPM = [store stringForKey:s_lastPM];
  102. startOnLogin = [store boolForKey:s_startLogin];
  103. }
  104. @end