VLCSettingsViewController.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // VLCSettingsViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 19.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCSettingsViewController.h"
  9. #import "VLCPlaylistViewController.h"
  10. #import "VLCPasscodeLockViewController.h"
  11. #import "VLCAppDelegate.h"
  12. @implementation VLCSettingsViewController
  13. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  14. {
  15. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  16. return self;
  17. }
  18. - (void)viewDidLoad
  19. {
  20. [super viewDidLoad];
  21. self.dismissButton.title = NSLocalizedString(@"BUTTON_DONE", @"");
  22. self.passcodeLockLabel.text = NSLocalizedString(@"PREF_PASSCODE", @"");
  23. self.audioPlaybackInBackgroundLabel.text = NSLocalizedString(@"PREF_AUDIOBACKGROUND", @"");
  24. self.audioStretchingLabel.text = NSLocalizedString(@"PREF_AUDIOSTRETCH", @"");
  25. self.debugOutputLabel.text = NSLocalizedString(@"PREF_VERBOSEDEBUG", @"");
  26. }
  27. - (void)viewWillAppear:(BOOL)animated
  28. {
  29. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  30. self.passcodeLockSwitch.on = [[defaults objectForKey:kVLCSettingPasscodeOnKey] intValue];
  31. self.audioPlaybackInBackgroundSwitch.on = [[defaults objectForKey:kVLCSettingContinueAudioInBackgroundKey] intValue];
  32. self.audioStretchingSwitch.on = ![[defaults objectForKey:kVLCSettingStretchAudio] isEqualToString:kVLCSettingStretchAudioDefaultValue];
  33. self.debugOutputSwitch.on = [[defaults objectForKey:kVLCSettingVerboseOutput] isEqualToString:kVLCSettingVerboseOutputDefaultValue];
  34. [super viewWillAppear:animated];
  35. }
  36. - (IBAction)toggleSetting:(id)sender
  37. {
  38. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  39. if (sender == self.passcodeLockSwitch) {
  40. if (self.passcodeLockSwitch.on) {
  41. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  42. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  43. CGRect frame = self.view.frame;
  44. frame.size.height -= 44.;
  45. appDelegate.playlistViewController.passcodeLockViewController.view.frame = frame;
  46. }
  47. [self.view addSubview:appDelegate.playlistViewController.passcodeLockViewController.view];
  48. [appDelegate.playlistViewController.passcodeLockViewController resetPasscode];
  49. } else {
  50. [defaults setObject:@0 forKey:kVLCSettingPasscodeOnKey];
  51. }
  52. } else if (sender == self.audioPlaybackInBackgroundSwitch) {
  53. [defaults setObject:@(self.audioPlaybackInBackgroundSwitch.on) forKey:kVLCSettingContinueAudioInBackgroundKey];
  54. } else if (sender == self.audioStretchingSwitch) {
  55. if (self.audioStretchingSwitch.on)
  56. [defaults setObject:@"--audio-time-stretch" forKey:kVLCSettingStretchAudio];
  57. else
  58. [defaults setObject:kVLCSettingStretchAudioDefaultValue forKey:kVLCSettingStretchAudio];
  59. } else if (sender == self.debugOutputSwitch) {
  60. if (self.debugOutputSwitch.on)
  61. [defaults setObject:kVLCSettingVerboseOutputDefaultValue forKey:kVLCSettingVerboseOutput];
  62. else
  63. [defaults setObject:@"--verbose=0" forKey:kVLCSettingVerboseOutput];
  64. }
  65. [defaults synchronize];
  66. }
  67. - (IBAction)dismiss:(id)sender
  68. {
  69. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  70. [appDelegate.playlistViewController.navigationController dismissModalViewControllerAnimated:YES];
  71. }
  72. @end