VLCSettingsController.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. @end
  22. @implementation VLCSettingsController
  23. - (id)init
  24. {
  25. self = [super init];
  26. if (self)
  27. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  28. return self;
  29. }
  30. - (void)dealloc
  31. {
  32. [[NSNotificationCenter defaultCenter] removeObserver:self];
  33. }
  34. - (void)settingDidChange:(NSNotification*)notification
  35. {
  36. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  37. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  38. if (passcodeOn) {
  39. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  40. passcodeLockController.delegate = self;
  41. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  42. }
  43. }
  44. if ([notification.object isEqual:kVLCSettingPlaybackGestures]) {
  45. BOOL enabled = (BOOL)[[notification.userInfo objectForKey:@"EnableGesturesToControlPlayback"] intValue];
  46. [self.viewController setHiddenKeys:enabled ? nil : [NSSet setWithObjects:@"EnableVariableJumpDuration", nil] animated:YES];
  47. }
  48. }
  49. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  50. {
  51. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  52. }
  53. #pragma mark - PAPasscode delegate
  54. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  55. {
  56. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  57. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  58. [defaults synchronize];
  59. [controller dismissViewControllerAnimated:YES completion:nil];
  60. }
  61. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  62. {
  63. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  64. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  65. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  66. [defaults synchronize];
  67. [controller dismissViewControllerAnimated:YES completion:nil];
  68. }
  69. @end