VLCSettingsController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. {
  24. NSString *_currentUnlinkSpecifier;
  25. NSString *_currentUnlinkDialogTitle;
  26. NSString *_currentCloudName;
  27. }
  28. @end
  29. @implementation VLCSettingsController
  30. - (id)init
  31. {
  32. self = [super init];
  33. if (self)
  34. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  35. return self;
  36. }
  37. - (void)dealloc
  38. {
  39. [[NSNotificationCenter defaultCenter] removeObserver:self];
  40. }
  41. - (void)settingDidChange:(NSNotification*)notification
  42. {
  43. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  44. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  45. if (passcodeOn) {
  46. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  47. passcodeLockController.delegate = self;
  48. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  49. }
  50. }
  51. }
  52. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  53. {
  54. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  55. }
  56. - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier
  57. {
  58. _currentUnlinkSpecifier = specifier.key;
  59. if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkDropbox"]) {
  60. _currentCloudName = @"Dropbox";
  61. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_DROPBOX", @"");
  62. } else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkGoogleDrive"]) {
  63. _currentCloudName = @"Google Drive";
  64. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_GOOGLEDRIVE", @"");
  65. }
  66. UIAlertView *alert = [[UIAlertView alloc]
  67. initWithTitle:_currentUnlinkDialogTitle
  68. message:[NSString stringWithFormat:NSLocalizedString(@"CLOUDUNLINKING", @""), _currentCloudName]
  69. delegate:self
  70. cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"")
  71. otherButtonTitles:NSLocalizedString(@"BUTTON_CLOUDUNLINKING", @""), nil];
  72. [alert show];
  73. }
  74. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  75. {
  76. if (buttonIndex == 1) {
  77. if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkDropbox"])
  78. [[DBSession sharedSession] unlinkAll];
  79. else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkGoogleDrive"])
  80. [[VLCGoogleDriveController sharedInstance] logout];
  81. _currentUnlinkSpecifier = nil;
  82. UIAlertView *alert = [[UIAlertView alloc]
  83. initWithTitle:_currentUnlinkDialogTitle
  84. message:[NSString stringWithFormat:NSLocalizedString(@"CLOUDUNLINKING_DONE", @""), _currentCloudName]
  85. delegate:self
  86. cancelButtonTitle:NSLocalizedString(@"BUTTON_DONE", @"")
  87. otherButtonTitles:nil];
  88. [alert show];
  89. _currentUnlinkDialogTitle = nil;
  90. _currentCloudName = nil;
  91. }
  92. }
  93. #pragma mark - PAPasscode delegate
  94. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  95. {
  96. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  97. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  98. [defaults synchronize];
  99. [controller dismissViewControllerAnimated:YES completion:nil];
  100. }
  101. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  102. {
  103. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  104. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  105. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  106. [defaults synchronize];
  107. [controller dismissViewControllerAnimated:YES completion:nil];
  108. }
  109. @end