VLCSettingsController.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #import <DropboxSDK/DropboxSDK.h>
  21. #import "VLCGoogleDriveController.h"
  22. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  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. - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier {
  52. if ([specifier.key isEqualToString:@"UnlinkDropbox"]) {
  53. [[DBSession sharedSession] unlinkAll];
  54. } else if ([specifier.key isEqualToString:@"UnlinkGoogleDrive"]) {
  55. [[VLCGoogleDriveController sharedInstance] logout];
  56. }
  57. }
  58. #pragma mark - PAPasscode delegate
  59. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  60. {
  61. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  62. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  63. [defaults synchronize];
  64. [controller dismissViewControllerAnimated:YES completion:nil];
  65. }
  66. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  67. {
  68. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  69. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  70. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  71. [defaults synchronize];
  72. [controller dismissViewControllerAnimated:YES completion:nil];
  73. }
  74. @end