VLCSettingsViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. @interface VLCSettingsViewController ()
  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] intValue];
  43. self.audioPlaybackInBackgroundSwitch.on = [[defaults objectForKey:kVLCSettingContinueAudioInBackgroundKey] intValue];
  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. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  58. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  59. CGRect frame = self.view.frame;
  60. frame.size.height -= 44.;
  61. appDelegate.playlistViewController.passcodeLockViewController.view.frame = frame;
  62. }
  63. [self.view addSubview:appDelegate.playlistViewController.passcodeLockViewController.view];
  64. [appDelegate.playlistViewController.passcodeLockViewController resetPasscode];
  65. } else {
  66. [defaults setObject:@0 forKey:kVLCSettingPasscodeOnKey];
  67. }
  68. } else if (sender == self.audioPlaybackInBackgroundSwitch) {
  69. [defaults setObject:@(self.audioPlaybackInBackgroundSwitch.on) forKey:kVLCSettingContinueAudioInBackgroundKey];
  70. } else if (sender == self.audioStretchingSwitch) {
  71. if (self.audioStretchingSwitch.on)
  72. [defaults setObject:@"--audio-time-stretch" forKey:kVLCSettingStretchAudio];
  73. else
  74. [defaults setObject:kVLCSettingStretchAudioDefaultValue forKey:kVLCSettingStretchAudio];
  75. } else if (sender == self.debugOutputSwitch) {
  76. if (self.debugOutputSwitch.on)
  77. [defaults setObject:kVLCSettingVerboseOutputDefaultValue forKey:kVLCSettingVerboseOutput];
  78. else
  79. [defaults setObject:@"--verbose=0" forKey:kVLCSettingVerboseOutput];
  80. }
  81. [defaults synchronize];
  82. }
  83. - (IBAction)dismiss:(id)sender
  84. {
  85. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  86. [appDelegate.playlistViewController.navigationController dismissModalViewControllerAnimated:YES];
  87. }
  88. #pragma mark - text encoding picker view delegate
  89. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  90. {
  91. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  92. [defaults setObject:_textEncodingNames[row] forKey:kVLCSettingTextEncoding];
  93. [defaults synchronize];
  94. }
  95. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  96. {
  97. return _userFacingTextEncodingNames[row];
  98. }
  99. #pragma mark - text encoding picker view data source
  100. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  101. {
  102. return 1;
  103. }
  104. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  105. {
  106. return _textEncodingNames.count;
  107. }
  108. @end