macosx: Implement upgrade path for RTL for old setting files
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Sun, 30 Jul 2017 15:52:15 +0000 (17:52 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Sun, 30 Jul 2017 15:59:33 +0000 (17:59 +0200)
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).

modules/gui/macosx/VLCMain+OldPrefs.m
modules/gui/macosx/VLCSimplePrefsController.h
modules/gui/macosx/VLCSimplePrefsController.m

index 48da488..fb04148 100644 (file)
 
 #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);
index 6d7d55e..7c0e66e 100644 (file)
 - (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
index b97d3ff..d9d2e2f 100644 (file)
@@ -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]);