VLCSettingsController.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "VLCLibraryViewController.h"
  16. #import "IASKSettingsReader.h"
  17. #import "IASKAppSettingsViewController.h"
  18. #import "PAPasscodeViewController.h"
  19. #import "VLCKeychainCoordinator.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. } else {
  43. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
  44. [self didChangePasscodeStatus:NO];
  45. }
  46. }
  47. if ([notification.object isEqual:kVLCSettingPlaybackGestures]) {
  48. BOOL enabled = (BOOL)[[notification.userInfo objectForKey:@"EnableGesturesToControlPlayback"] intValue];
  49. [self.viewController setHiddenKeys:enabled ? nil : [NSSet setWithObjects:@"EnableVariableJumpDuration", nil] animated:YES];
  50. }
  51. }
  52. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  53. {
  54. [[VLCSidebarController sharedInstance] toggleSidebar];
  55. }
  56. - (void)didChangePasscodeStatus:(BOOL)passcodeEnabled {
  57. BOOL spotlightEnabled = !passcodeEnabled;
  58. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  59. if (!spotlightEnabled) {
  60. // delete whole index for VLC
  61. [[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:nil];
  62. } else {
  63. [[MLMediaLibrary sharedMediaLibrary] ]
  64. }
  65. }
  66. #pragma mark - PAPasscode delegate
  67. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  68. {
  69. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
  70. [self didChangePasscodeStatus:NO];
  71. [controller dismissViewControllerAnimated:YES completion:nil];
  72. }
  73. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  74. {
  75. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:controller.passcode];
  76. [self didChangePasscodeStatus:YES];
  77. [controller dismissViewControllerAnimated:YES completion:nil];
  78. }
  79. @end