VLCSettingsViewController.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "PAPasscodeViewController.h"
  11. #import "VLCAppDelegate.h"
  12. @interface VLCSettingsViewController () <PAPasscodeViewControllerDelegate>
  13. {
  14. NSArray *_userFacingTextEncodingNames;
  15. NSArray *_textEncodingNames;
  16. }
  17. @end
  18. @implementation VLCSettingsViewController
  19. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  20. {
  21. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  22. return self;
  23. }
  24. - (void)viewDidLoad
  25. {
  26. [super viewDidLoad];
  27. self.dismissButton.title = NSLocalizedString(@"BUTTON_DONE", @"");
  28. self.passcodeLockLabel.text = NSLocalizedString(@"PREF_PASSCODE", @"");
  29. self.audioPlaybackInBackgroundLabel.text = NSLocalizedString(@"PREF_AUDIOBACKGROUND", @"");
  30. self.audioStretchingLabel.text = NSLocalizedString(@"PREF_AUDIOSTRETCH", @"");
  31. self.debugOutputLabel.text = NSLocalizedString(@"PREF_VERBOSEDEBUG", @"");
  32. }
  33. - (void)viewWillDisappear:(BOOL)animated
  34. {
  35. /* save some memory */
  36. _userFacingTextEncodingNames = nil;
  37. _textEncodingNames = nil;
  38. }
  39. - (void)viewWillAppear:(BOOL)animated
  40. {
  41. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  42. self.passcodeLockSwitch.on = [[defaults objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  43. self.audioPlaybackInBackgroundSwitch.on = [[defaults objectForKey:kVLCSettingContinueAudioInBackgroundKey] boolValue];
  44. self.audioStretchingSwitch.on = ![[defaults objectForKey:kVLCSettingStretchAudio] isEqualToString:kVLCSettingStretchAudioDefaultValue];
  45. self.debugOutputSwitch.on = [[defaults objectForKey:kVLCSettingVerboseOutput] isEqualToString:kVLCSettingVerboseOutputDefaultValue];
  46. _userFacingTextEncodingNames = @[@"Default (Windows-1252)", @"Universal (UTF-8)", @"Universal (UTF-16)", @"Universal (big endian UTF-16)", @"Universal (little endian UTF-16)", @"Universal, Chinese (GB18030)", @"Western European (Latin-9)", @"Western European (Windows-1252)", @"Western European (IBM 00850)", @"Eastern European (Latin-2)", @"Eastern European (Windows-1250)", @"Esperanto (Latin-3)", @"Nordic (Latin-6)", @"Cyrillic (Windows-1251)", @"Russian (KOI8-R)", @"Ukrainian (KOI8-U)", @"Arabic (ISO 8859-6)", @"Arabic (Windows-1256)", @"Greek (ISO 8859-7)", @"Greek (Windows-1253)", @"Hebrew (ISO 8859-8)", @"Hebrew (Windows-1255)", @"Turkish (ISO 8859-9)", @"Turkish (Windows-1254)", @"Thai (TIS 620-2533/ISO 8859-11)", @"Thai (Windows-874)", @"Baltic (Latin-7)", @"Baltic (Windows-1257)", @"Celtic (Latin-8)", @"South-Eastern European (Latin-10)", @"Simplified Chinese (ISO-2022-CN-EXT)", @"Simplified Chinese Unix (EUC-CN)", @"Japanese (7-bits JIS/ISO-2022-JP-2)", @"Japanese Unix (EUC-JP)", @"Japanese (Shift JIS)", @"Korean (EUC-KR/CP949)", @"Korean (ISO-2022-KR)", @"Traditional Chinese (Big5)", @"Traditional Chinese Unix (EUC-TW)", @"Hong-Kong Supplementary (HKSCS)", @"Vietnamese (VISCII)", @"Vietnamese (Windows-1258)"];
  47. _textEncodingNames = @[@"", @"UTF-8", @"UTF-16", @"UTF-16BE", @"UTF-16LE", @"GB18030", @"ISO-8859-15", @"Windows-1252", @"IBM850", @"ISO-8859-2", @"Windows-1250", @"ISO-8859-3", @"ISO-8859-10", @"Windows-1251", @"KOI8-R", @"KOI8-U", @"ISO-8859-6", @"Windows-1256", @"ISO-8859-7", @"Windows-1253", @"ISO-8859-8", @"Windows-1255", @"ISO-8859-9", @"Windows-1254", @"ISO-8859-11", @"Windows-874", @"ISO-8859-13", @"Windows-1257", @"ISO-8859-14", @"ISO-8859-16", @"ISO-2022-CN-EXT", @"EUC-CN", @"ISO-2022-JP-2", @"EUC-JP", @"Shift_JIS", @"CP949", @"ISO-2022-KR", @"Big5", @"ISO-2022-TW", @"Big5-HKSCS", @"VISCII", @"Windows-1258"];
  48. [self.textEncodingPicker reloadAllComponents];
  49. [self.textEncodingPicker selectRow:[_textEncodingNames indexOfObject:[defaults objectForKey:kVLCSettingTextEncoding]] inComponent:0 animated:NO];
  50. [super viewWillAppear:animated];
  51. }
  52. - (IBAction)toggleSetting:(id)sender
  53. {
  54. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  55. if (sender == self.passcodeLockSwitch) {
  56. if (self.passcodeLockSwitch.on) {
  57. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  58. passcodeLockController.delegate = self;
  59. [self presentModalViewController:passcodeLockController animated:YES];
  60. } else {
  61. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  62. }
  63. } else if (sender == self.audioPlaybackInBackgroundSwitch) {
  64. [defaults setObject:@(self.audioPlaybackInBackgroundSwitch.on) forKey:kVLCSettingContinueAudioInBackgroundKey];
  65. } else if (sender == self.audioStretchingSwitch) {
  66. if (self.audioStretchingSwitch.on)
  67. [defaults setObject:@"--audio-time-stretch" forKey:kVLCSettingStretchAudio];
  68. else
  69. [defaults setObject:kVLCSettingStretchAudioDefaultValue forKey:kVLCSettingStretchAudio];
  70. } else if (sender == self.debugOutputSwitch) {
  71. if (self.debugOutputSwitch.on)
  72. [defaults setObject:kVLCSettingVerboseOutputDefaultValue forKey:kVLCSettingVerboseOutput];
  73. else
  74. [defaults setObject:@"--verbose=0" forKey:kVLCSettingVerboseOutput];
  75. }
  76. [defaults synchronize];
  77. }
  78. - (IBAction)dismiss:(id)sender
  79. {
  80. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  81. [appDelegate.playlistViewController.navigationController dismissModalViewControllerAnimated:YES];
  82. }
  83. #pragma mark - text encoding picker view delegate
  84. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  85. {
  86. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  87. [defaults setObject:_textEncodingNames[row] forKey:kVLCSettingTextEncoding];
  88. [defaults synchronize];
  89. }
  90. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  91. {
  92. return _userFacingTextEncodingNames[row];
  93. }
  94. #pragma mark - text encoding picker view data source
  95. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  96. {
  97. return 1;
  98. }
  99. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  100. {
  101. return _textEncodingNames.count;
  102. }
  103. #pragma mark - PAPasscode delegate
  104. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  105. {
  106. self.passcodeLockSwitch.on = NO;
  107. [controller dismissModalViewControllerAnimated:YES];
  108. }
  109. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  110. {
  111. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  112. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  113. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  114. [defaults synchronize];
  115. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  116. appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
  117. [controller dismissModalViewControllerAnimated:YES];
  118. }
  119. @end