VLCSettingsController.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*****************************************************************************
  2. * VLCSettingsController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Carola Nitz <nitz.carola # googlemail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCSettingsController.h"
  15. #import "VLCAppDelegate.h"
  16. #import "VLCPlaylistViewController.h"
  17. #import "IASKSettingsReader.h"
  18. #import "IASKAppSettingsViewController.h"
  19. #import "PAPasscodeViewController.h"
  20. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  21. {
  22. }
  23. @end
  24. @implementation VLCSettingsController
  25. - (id)init
  26. {
  27. self = [super init];
  28. if (self)
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  30. return self;
  31. }
  32. - (void)dealloc
  33. {
  34. [[NSNotificationCenter defaultCenter] removeObserver:self];
  35. }
  36. - (void)settingDidChange:(NSNotification*)notification
  37. {
  38. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  39. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  40. if (passcodeOn) {
  41. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  42. passcodeLockController.delegate = self;
  43. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  44. }
  45. }
  46. }
  47. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  48. {
  49. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  50. }
  51. #pragma mark - PAPasscode delegate
  52. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  53. {
  54. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  55. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  56. [defaults synchronize];
  57. [controller dismissViewControllerAnimated:YES completion:nil];
  58. }
  59. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  60. {
  61. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  62. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  63. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  64. [defaults synchronize];
  65. [controller dismissViewControllerAnimated:YES completion:nil];
  66. }
  67. @end