[vlc-commits] macosx: Implement upgrade path for RTL for old setting files
David Fuhrmann
git at videolan.org
Sun Jul 30 17:59:50 CEST 2017
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sun Jul 30 17:52:15 2017 +0200| [09738d597cd8a31dbbbdba920fa63ccc13ab642f] | committer: David Fuhrmann
macosx: Implement upgrade path for RTL for old setting files
Auto-upgrade old setting (i.e. if a user selected a RTL language
before, the settings will be autoupdated and VLC will be
restarted). Restart will not happen for the most common case
(auto language).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=09738d597cd8a31dbbbdba920fa63ccc13ab642f
---
modules/gui/macosx/VLCMain+OldPrefs.m | 14 +++++++++++-
modules/gui/macosx/VLCSimplePrefsController.h | 6 ++++++
modules/gui/macosx/VLCSimplePrefsController.m | 31 ++++++++++++++++++++-------
3 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/modules/gui/macosx/VLCMain+OldPrefs.m b/modules/gui/macosx/VLCMain+OldPrefs.m
index 48da488a24..fb041485f4 100644
--- a/modules/gui/macosx/VLCMain+OldPrefs.m
+++ b/modules/gui/macosx/VLCMain+OldPrefs.m
@@ -25,13 +25,14 @@
#import "VLCMain+OldPrefs.h"
#import "VLCCoreInteraction.h"
+#import "VLCSimplePrefsController.h"
#include <unistd.h> /* execl() */
@implementation VLCMain(OldPrefs)
static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
-static const int kCurrentPreferencesVersion = 3;
+static const int kCurrentPreferencesVersion = 4;
+ (void)initialize
{
@@ -80,6 +81,17 @@ static const int kCurrentPreferencesVersion = 3;
* so we reset the OS X specific prefs here - in practice, no user will notice */
[self resetAndReinitializeUserDefaults];
+ } else if (version == 3) {
+ /* version 4 (introduced in 3.0.0) adds RTL settings depending on stored language */
+
+ [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
+ BOOL hasUpdated = [VLCSimplePrefsController updateRightToLeftSettings];
+ [defaults synchronize];
+
+ // This migration only has effect rarely, therefore only restart then
+ if (!hasUpdated)
+ return;
+
} else {
NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
diff --git a/modules/gui/macosx/VLCSimplePrefsController.h b/modules/gui/macosx/VLCSimplePrefsController.h
index 6d7d55ed58..7c0e66e1cb 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.h
+++ b/modules/gui/macosx/VLCSimplePrefsController.h
@@ -239,4 +239,10 @@
- (IBAction)hotkeySettingChanged:(id)sender;
- (BOOL)changeHotkeyTo: (NSString *)theKey;
+/**
+ * Updates right to left UI setting according to currently set language code
+ * \return true if specific language was selected and RTL UI settings were updated
+ */
++ (BOOL)updateRightToLeftSettings;
+
@end
diff --git a/modules/gui/macosx/VLCSimplePrefsController.m b/modules/gui/macosx/VLCSimplePrefsController.m
index b97d3ff1f7..d9d2e2f383 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/VLCSimplePrefsController.m
@@ -836,6 +836,28 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
}
}
++ (BOOL)updateRightToLeftSettings
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSString *isoCode = [defaults stringForKey:@"language"];
+
+ if (!isoCode || [isoCode isEqualToString:@"auto"]) {
+ // Automatic handling of right to left
+ [defaults removeObjectForKey:@"NSForceRightToLeftWritingDirection"];
+ [defaults removeObjectForKey:@"AppleTextDirection"];
+ } else {
+ for(int i = 0; i < ARRAY_SIZE(language_map); i++) {
+ if (!strcmp(language_map[i].iso, [isoCode UTF8String])) {
+ [defaults setBool:language_map[i].isRightToLeft forKey:@"NSForceRightToLeftWritingDirection"];
+ [defaults setBool:language_map[i].isRightToLeft forKey:@"AppleTextDirection"];
+ return YES;
+ }
+ }
+ }
+
+ return NO;
+}
+
- (void)saveChangedSettings
{
NSString *tmpString;
@@ -855,14 +877,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
NSUInteger index = [_intf_languagePopup indexOfSelectedItem];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:toNSStr(language_map[index].iso) forKey:@"language"];
-
- if (index == 0) { // Automatic handling of right to left
- [defaults removeObjectForKey:@"NSForceRightToLeftWritingDirection"];
- [defaults removeObjectForKey:@"AppleTextDirection"];
- } else {
- [defaults setBool:language_map[index].isRightToLeft forKey:@"NSForceRightToLeftWritingDirection"];
- [defaults setBool:language_map[index].isRightToLeft forKey:@"AppleTextDirection"];
- }
+ [VLCSimplePrefsController updateRightToLeftSettings];
[defaults synchronize];
config_PutInt(p_intf, "metadata-network-access", [_intf_artCheckbox state]);
More information about the vlc-commits
mailing list