Commit 42115489 authored by David Fuhrmann's avatar David Fuhrmann

macosx: video effects: improve compatibility with old settings

This implements the following migration behaviour with older
VLC version:
- Index 0 in settings used to be the Default profile, and is now
  ignored (not read from and not written to anymore)
- The default settings still include the default profile in index
  0, to maintain backwards compatibility if older VLC are started.
- In profile selector, index 0 is still the Default profile,
  if the "apply at next startup" is selected, a new Custom profile
  is created at exit.
- By default after updating, no profile will be deployed at launch,
  so the "Default profile is selected.

refs #19260
parent 14d1b6be
...@@ -34,11 +34,6 @@ ...@@ -34,11 +34,6 @@
#define getWidgetFloatValue(w) ((vlc_value_t){ .f_float = [w floatValue] }) #define getWidgetFloatValue(w) ((vlc_value_t){ .f_float = [w floatValue] })
#define getWidgetStringValue(w) ((vlc_value_t){ .psz_string = (char *)[[w stringValue] UTF8String] }) #define getWidgetStringValue(w) ((vlc_value_t){ .psz_string = (char *)[[w stringValue] UTF8String] })
@interface VLCVideoEffectsWindowController()
{
NSInteger i_old_profile_index;
}
@end
#pragma mark - #pragma mark -
#pragma mark Initialization #pragma mark Initialization
...@@ -47,6 +42,13 @@ ...@@ -47,6 +42,13 @@
+ (void)initialize + (void)initialize
{ {
/*
* Video effects profiles starting with 3.0:
* - Index 0 is assumed to be the default profile from previous versions
* - Index 0 from settings is never read or written anymore starting with 3.0, as the Default profile
* is not persisted anymore.
*/
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObject:[VLCVideoEffectsWindowController defaultProfileString]], @"VideoEffectProfiles", [NSArray arrayWithObject:[VLCVideoEffectsWindowController defaultProfileString]], @"VideoEffectProfiles",
[NSArray arrayWithObject:_NS("Default")], @"VideoEffectProfileNames", [NSArray arrayWithObject:_NS("Default")], @"VideoEffectProfileNames",
...@@ -63,35 +65,40 @@ ...@@ -63,35 +65,40 @@
{ {
self = [super initWithWindowNibName:@"VideoEffects"]; self = [super initWithWindowNibName:@"VideoEffects"];
if (self) { if (self) {
i_old_profile_index = -1;
self.popupPanel = [[VLCPopupPanelController alloc] init]; self.popupPanel = [[VLCPopupPanelController alloc] init];
self.textfieldPanel = [[VLCTextfieldPanelController alloc] init]; self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:@"VideoEffectApplyProfileOnStartup"]) { if ([defaults boolForKey:@"VideoEffectApplyProfileOnStartup"]) {
// This does not reset the UI (which does not exist yet), but it initalizes needed playlist vars // This does not reset the UI (which does not exist yet), but it initalizes needed playlist vars
[self resetValues]; [self resetValues];
[self loadProfile];
} else {
[self saveCurrentProfileIndex:0];
}
[self loadProfile];
} }
else
[defaults setInteger:0 forKey:@"VideoEffectSelectedProfile"];
return self; return self;
} }
/// Loads values from profile into variables
- (void)loadProfile - (void)loadProfile
{ {
intf_thread_t *p_intf = getIntf(); intf_thread_t *p_intf = getIntf();
playlist_t *p_playlist = pl_Get(p_intf); playlist_t *p_playlist = pl_Get(p_intf);
VLCCoreInteraction *vci_si = [VLCCoreInteraction sharedInstance]; VLCCoreInteraction *vci_si = [VLCCoreInteraction sharedInstance];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSUInteger profile = [defaults integerForKey:@"VideoEffectSelectedProfile"]; NSInteger profileIndex = [self currentProfileIndex];
/* fetch preset */ NSString *profileString;
NSArray *items = [[[defaults objectForKey:@"VideoEffectProfiles"] objectAtIndex:profile] componentsSeparatedByString:@";"]; if (profileIndex == 0)
profileString = [VLCVideoEffectsWindowController defaultProfileString];
else
profileString = [[defaults objectForKey:@"VideoEffectProfiles"] objectAtIndex:profileIndex];
NSArray *items = [profileString componentsSeparatedByString:@";"];
// version 1 of profile string has 32 entries // version 1 of profile string has 32 entries
if ([items count] < 32) { if ([items count] < 32) {
...@@ -174,9 +181,6 @@ ...@@ -174,9 +181,6 @@
hueValue.f_float -= 180; hueValue.f_float -= 180;
} }
[vci_si setVideoFilterProperty: "hue" forFilter: "adjust" withValue: hueValue]; [vci_si setVideoFilterProperty: "hue" forFilter: "adjust" withValue: hueValue];
[defaults setInteger:profile forKey:@"VideoEffectSelectedProfile"];
[defaults synchronize];
} }
- (void)windowDidLoad - (void)windowDidLoad
...@@ -347,6 +351,16 @@ ...@@ -347,6 +351,16 @@
#pragma mark - #pragma mark -
#pragma mark internal functions #pragma mark internal functions
- (void)saveCurrentProfileIndex:(NSInteger)index
{
[[NSUserDefaults standardUserDefaults] setInteger:index forKey:@"VideoEffectSelectedProfile"];
}
- (NSInteger)currentProfileIndex
{
return [[NSUserDefaults standardUserDefaults] integerForKey:@"VideoEffectSelectedProfile"];
}
-(void)inputChangedEvent:(NSNotification *)o_notification -(void)inputChangedEvent:(NSNotification *)o_notification
{ {
// reset crop values when input changed // reset crop values when input changed
...@@ -361,7 +375,11 @@ ...@@ -361,7 +375,11 @@
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[_profilePopup removeAllItems]; [_profilePopup removeAllItems];
NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"]; // Ignore "Default" index 0 from settings
[_profilePopup addItemWithTitle:_NS("Default")];
NSMutableArray *profileNames = [[defaults stringArrayForKey:@"VideoEffectProfileNames"] mutableCopy];
[profileNames removeObjectAtIndex:0];
[_profilePopup addItemsWithTitles:profileNames]; [_profilePopup addItemsWithTitles:profileNames];
[[_profilePopup menu] addItem:[NSMenuItem separatorItem]]; [[_profilePopup menu] addItem:[NSMenuItem separatorItem]];
...@@ -375,8 +393,9 @@ ...@@ -375,8 +393,9 @@
[[_profilePopup lastItem] setAction: @selector(removeProfile:)]; [[_profilePopup lastItem] setAction: @selector(removeProfile:)];
} }
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; [_profilePopup selectItemAtIndex: [self currentProfileIndex]];
if (i_old_profile_index || [defaults integerForKey:@"VideoEffectSelectedProfile"]) // Loading only non-default profiles ensures that vlcrc or command line settings are not overwritten
if ([self currentProfileIndex] > 0)
[self profileSelectorAction:self]; [self profileSelectorAction:self];
} }
...@@ -398,9 +417,11 @@ ...@@ -398,9 +417,11 @@
msg_Err(p_intf, "%s variable is of an unsupported type (%d)", psz_option, i_type); msg_Err(p_intf, "%s variable is of an unsupported type (%d)", psz_option, i_type);
return; return;
} }
if (var_Create(p_playlist, psz_option, i_type | VLC_VAR_DOINHERIT) || if (var_Create(p_playlist, psz_option, i_type | VLC_VAR_DOINHERIT) ||
var_GetChecked(p_playlist, psz_option, i_type, &val)) var_GetChecked(p_playlist, psz_option, i_type, &val)) {
return; return;
}
if (i_type == VLC_VAR_BOOL || i_type == VLC_VAR_INTEGER) if (i_type == VLC_VAR_BOOL || i_type == VLC_VAR_INTEGER)
{ {
...@@ -446,6 +467,7 @@ ...@@ -446,6 +467,7 @@
[widget setEnabled: b_state]; [widget setEnabled: b_state];
} }
/// Sets widget values based on variables
- (void)resetValues - (void)resetValues
{ {
intf_thread_t *p_intf = getIntf(); intf_thread_t *p_intf = getIntf();
...@@ -668,37 +690,43 @@ ...@@ -668,37 +690,43 @@
- (void)saveCurrentProfile - (void)saveCurrentProfile
{ {
if (!i_old_profile_index || i_old_profile_index == -1) NSInteger currentProfileIndex = [self currentProfileIndex];
// Do not save default profile
if (currentProfileIndex == 0) {
return; return;
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
/* fetch all the current settings in a uniform string */ /* fetch all the current settings in a uniform string */
NSString *newProfile = [self generateProfileString]; NSString *newProfile = [self generateProfileString];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
if (i_old_profile_index >= [workArray count]) if (currentProfileIndex >= [workArray count])
return; return;
[workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile]; [workArray replaceObjectAtIndex:currentProfileIndex withObject:newProfile];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
[defaults synchronize]; [defaults synchronize];
} }
- (void)saveCurrentProfileAtTerminate - (void)saveCurrentProfileAtTerminate
{ {
if (i_old_profile_index) if ([self currentProfileIndex] > 0) {
return [self saveCurrentProfile]; [self saveCurrentProfile];
return;
}
// A new "Custom profile" is only created if the user wants to load this as new profile at startup ... // A new "Custom profile" is only created if the user wants to load this as new profile at startup ...
if (_applyProfileCheckbox.state == NSOffState) if (_applyProfileCheckbox.state == NSOffState)
return; return;
// ... and some settings are changed // ... and some settings are changed
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *newProfile = [self generateProfileString]; NSString *newProfile = [self generateProfileString];
if ([newProfile compare:[[defaults objectForKey:@"VideoEffectProfiles"] firstObject]] == NSOrderedSame) if ([newProfile compare:[VLCVideoEffectsWindowController defaultProfileString]] == NSOrderedSame)
return; return;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
[workArray addObject:newProfile]; [workArray addObject:newProfile];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
...@@ -715,7 +743,7 @@ ...@@ -715,7 +743,7 @@
[workArray addObject:newProfileName]; [workArray addObject:newProfileName];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];
[defaults setInteger:([workArray count] - 1) forKey:@"VideoEffectSelectedProfile"]; [self saveCurrentProfileIndex:([workArray count] - 1)];
[defaults synchronize]; [defaults synchronize];
} }
...@@ -733,8 +761,9 @@ ...@@ -733,8 +761,9 @@
- (IBAction)profileSelectorAction:(id)sender - (IBAction)profileSelectorAction:(id)sender
{ {
[self saveCurrentProfile]; [self saveCurrentProfile];
i_old_profile_index = [_profilePopup indexOfSelectedItem];
[[NSUserDefaults standardUserDefaults] setInteger:i_old_profile_index forKey:@"VideoEffectSelectedProfile"]; [self saveCurrentProfileIndex:[_profilePopup indexOfSelectedItem]];
[self loadProfile]; [self loadProfile];
[self resetValues]; [self resetValues];
} }
...@@ -759,18 +788,17 @@ ...@@ -759,18 +788,17 @@
__unsafe_unretained typeof(self) _self = self; __unsafe_unretained typeof(self) _self = self;
[_textfieldPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSString *resultingText) { [_textfieldPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSString *resultingText) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (returnCode != NSOKButton) { if (returnCode != NSOKButton) {
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; [_profilePopup selectItemAtIndex:[self currentProfileIndex]];
return; return;
} }
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"]; NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"];
// duplicate names are not allowed in the popup control // duplicate names are not allowed in the popup control
if ([resultingText length] == 0 || [profileNames containsObject:resultingText]) { if ([resultingText length] == 0 || [profileNames containsObject:resultingText]) {
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; [_profilePopup selectItemAtIndex:[self currentProfileIndex]];
NSAlert *alert = [[NSAlert alloc] init]; NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSCriticalAlertStyle]; [alert setAlertStyle:NSCriticalAlertStyle];
...@@ -792,7 +820,8 @@ ...@@ -792,7 +820,8 @@
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
[workArray addObject:newProfile]; [workArray addObject:newProfile];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
[defaults setInteger:[workArray count] - 1 forKey:@"VideoEffectSelectedProfile"];
[self saveCurrentProfileIndex:([workArray count] - 1)];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfileNames"]]; workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfileNames"]];
[workArray addObject:resultingText]; [workArray addObject:resultingText];
...@@ -827,18 +856,20 @@ ...@@ -827,18 +856,20 @@
__unsafe_unretained typeof(self) _self = self; __unsafe_unretained typeof(self) _self = self;
[_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) { [_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger activeProfileIndex = [_self currentProfileIndex];
if (returnCode != NSOKButton) { if (returnCode != NSOKButton) {
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; [_profilePopup selectItemAtIndex:activeProfileIndex];
return; return;
} }
if (!selectedIndex) { // TODO: add popup to notify user if (!selectedIndex) { // TODO: add popup to notify user
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; [_profilePopup selectItemAtIndex:activeProfileIndex];
return; return;
} }
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
/* remove selected profile from settings */ /* remove selected profile from settings */
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]];
[workArray removeObjectAtIndex:selectedIndex]; [workArray removeObjectAtIndex:selectedIndex];
...@@ -848,14 +879,12 @@ ...@@ -848,14 +879,12 @@
[workArray removeObjectAtIndex:selectedIndex]; [workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];
if (i_old_profile_index >= selectedIndex) if (activeProfileIndex >= selectedIndex)
[defaults setInteger:i_old_profile_index - 1 forKey:@"VideoEffectSelectedProfile"]; [self saveCurrentProfileIndex:(activeProfileIndex - 1)];
/* save defaults */ /* save defaults */
[defaults synchronize]; [defaults synchronize];
/* do not save deleted profile */
i_old_profile_index = -1;
/* refresh UI */ /* refresh UI */
[_self resetProfileSelector]; [_self resetProfileSelector];
}]; }];
......
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