Commit 09738d59 authored by David Fuhrmann's avatar 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).
parent c2a1ef59
...@@ -25,13 +25,14 @@ ...@@ -25,13 +25,14 @@
#import "VLCMain+OldPrefs.h" #import "VLCMain+OldPrefs.h"
#import "VLCCoreInteraction.h" #import "VLCCoreInteraction.h"
#import "VLCSimplePrefsController.h"
#include <unistd.h> /* execl() */ #include <unistd.h> /* execl() */
@implementation VLCMain(OldPrefs) @implementation VLCMain(OldPrefs)
static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion"; static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
static const int kCurrentPreferencesVersion = 3; static const int kCurrentPreferencesVersion = 4;
+ (void)initialize + (void)initialize
{ {
...@@ -80,6 +81,17 @@ static const int kCurrentPreferencesVersion = 3; ...@@ -80,6 +81,17 @@ static const int kCurrentPreferencesVersion = 3;
* so we reset the OS X specific prefs here - in practice, no user will notice */ * so we reset the OS X specific prefs here - in practice, no user will notice */
[self resetAndReinitializeUserDefaults]; [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 { } else {
NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES); NSUserDomainMask, YES);
......
...@@ -239,4 +239,10 @@ ...@@ -239,4 +239,10 @@
- (IBAction)hotkeySettingChanged:(id)sender; - (IBAction)hotkeySettingChanged:(id)sender;
- (BOOL)changeHotkeyTo: (NSString *)theKey; - (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 @end
...@@ -836,6 +836,28 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha ...@@ -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 - (void)saveChangedSettings
{ {
NSString *tmpString; NSString *tmpString;
...@@ -855,14 +877,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha ...@@ -855,14 +877,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
NSUInteger index = [_intf_languagePopup indexOfSelectedItem]; NSUInteger index = [_intf_languagePopup indexOfSelectedItem];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:toNSStr(language_map[index].iso) forKey:@"language"]; [defaults setObject:toNSStr(language_map[index].iso) forKey:@"language"];
[VLCSimplePrefsController updateRightToLeftSettings];
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"];
}
[defaults synchronize]; [defaults synchronize];
config_PutInt(p_intf, "metadata-network-access", [_intf_artCheckbox state]); config_PutInt(p_intf, "metadata-network-access", [_intf_artCheckbox state]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment