vlc | branch: master | David Fuhrmann <[email protected]> | Sun Dec 10 22:50:46 2017 +0100| [42115489853231f77f1221791294616c716e80fb] | committer: 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 > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=42115489853231f77f1221791294616c716e80fb --- .../gui/macosx/VLCVideoEffectsWindowController.m | 125 +++++++++++++-------- 1 file changed, 77 insertions(+), 48 deletions(-) diff --git a/modules/gui/macosx/VLCVideoEffectsWindowController.m b/modules/gui/macosx/VLCVideoEffectsWindowController.m index 98ded961f1..a007069f75 100644 --- a/modules/gui/macosx/VLCVideoEffectsWindowController.m +++ b/modules/gui/macosx/VLCVideoEffectsWindowController.m @@ -34,11 +34,6 @@ #define getWidgetFloatValue(w) ((vlc_value_t){ .f_float = [w floatValue] }) #define getWidgetStringValue(w) ((vlc_value_t){ .psz_string = (char *)[[w stringValue] UTF8String] }) -@interface VLCVideoEffectsWindowController() -{ - NSInteger i_old_profile_index; -} -@end #pragma mark - #pragma mark Initialization @@ -47,6 +42,13 @@ + (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: [NSArray arrayWithObject:[VLCVideoEffectsWindowController defaultProfileString]], @"VideoEffectProfiles", [NSArray arrayWithObject:_NS("Default")], @"VideoEffectProfileNames", @@ -63,35 +65,40 @@ { self = [super initWithWindowNibName:@"VideoEffects"]; if (self) { - i_old_profile_index = -1; - self.popupPanel = [[VLCPopupPanelController alloc] init]; self.textfieldPanel = [[VLCTextfieldPanelController alloc] init]; - } - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - if ([defaults boolForKey:@"VideoEffectApplyProfileOnStartup"]) { - // This does not reset the UI (which does not exist yet), but it initalizes needed playlist vars - [self resetValues]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + if ([defaults boolForKey:@"VideoEffectApplyProfileOnStartup"]) { + // This does not reset the UI (which does not exist yet), but it initalizes needed playlist vars + [self resetValues]; + + [self loadProfile]; + } else { + [self saveCurrentProfileIndex:0]; + } - [self loadProfile]; } - else - [defaults setInteger:0 forKey:@"VideoEffectSelectedProfile"]; return self; } +/// Loads values from profile into variables - (void)loadProfile { intf_thread_t *p_intf = getIntf(); playlist_t *p_playlist = pl_Get(p_intf); VLCCoreInteraction *vci_si = [VLCCoreInteraction sharedInstance]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSUInteger profile = [defaults integerForKey:@"VideoEffectSelectedProfile"]; + NSInteger profileIndex = [self currentProfileIndex]; - /* fetch preset */ - NSArray *items = [[[defaults objectForKey:@"VideoEffectProfiles"] objectAtIndex:profile] componentsSeparatedByString:@";"]; + NSString *profileString; + 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 if ([items count] < 32) { @@ -174,9 +181,6 @@ hueValue.f_float -= 180; } [vci_si setVideoFilterProperty: "hue" forFilter: "adjust" withValue: hueValue]; - - [defaults setInteger:profile forKey:@"VideoEffectSelectedProfile"]; - [defaults synchronize]; } - (void)windowDidLoad @@ -347,6 +351,16 @@ #pragma mark - #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 { // reset crop values when input changed @@ -361,7 +375,11 @@ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [_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 menu] addItem:[NSMenuItem separatorItem]]; @@ -375,8 +393,9 @@ [[_profilePopup lastItem] setAction: @selector(removeProfile:)]; } - [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; - if (i_old_profile_index || [defaults integerForKey:@"VideoEffectSelectedProfile"]) + [_profilePopup selectItemAtIndex: [self currentProfileIndex]]; + // Loading only non-default profiles ensures that vlcrc or command line settings are not overwritten + if ([self currentProfileIndex] > 0) [self profileSelectorAction:self]; } @@ -398,9 +417,11 @@ msg_Err(p_intf, "%s variable is of an unsupported type (%d)", psz_option, i_type); return; } + 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; + } if (i_type == VLC_VAR_BOOL || i_type == VLC_VAR_INTEGER) { @@ -446,6 +467,7 @@ [widget setEnabled: b_state]; } +/// Sets widget values based on variables - (void)resetValues { intf_thread_t *p_intf = getIntf(); @@ -668,37 +690,43 @@ - (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; + } - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; /* fetch all the current settings in a uniform string */ NSString *newProfile = [self generateProfileString]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]]; - if (i_old_profile_index >= [workArray count]) + if (currentProfileIndex >= [workArray count]) return; - [workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile]; + [workArray replaceObjectAtIndex:currentProfileIndex withObject:newProfile]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"]; [defaults synchronize]; } - (void)saveCurrentProfileAtTerminate { - if (i_old_profile_index) - return [self saveCurrentProfile]; + if ([self currentProfileIndex] > 0) { + [self saveCurrentProfile]; + return; + } // A new "Custom profile" is only created if the user wants to load this as new profile at startup ... if (_applyProfileCheckbox.state == NSOffState) return; // ... and some settings are changed - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *newProfile = [self generateProfileString]; - if ([newProfile compare:[[defaults objectForKey:@"VideoEffectProfiles"] firstObject]] == NSOrderedSame) + if ([newProfile compare:[VLCVideoEffectsWindowController defaultProfileString]] == NSOrderedSame) return; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]]; [workArray addObject:newProfile]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"]; @@ -715,7 +743,7 @@ [workArray addObject:newProfileName]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"]; - [defaults setInteger:([workArray count] - 1) forKey:@"VideoEffectSelectedProfile"]; + [self saveCurrentProfileIndex:([workArray count] - 1)]; [defaults synchronize]; } @@ -733,8 +761,9 @@ - (IBAction)profileSelectorAction:(id)sender { [self saveCurrentProfile]; - i_old_profile_index = [_profilePopup indexOfSelectedItem]; - [[NSUserDefaults standardUserDefaults] setInteger:i_old_profile_index forKey:@"VideoEffectSelectedProfile"]; + + [self saveCurrentProfileIndex:[_profilePopup indexOfSelectedItem]]; + [self loadProfile]; [self resetValues]; } @@ -759,18 +788,17 @@ __unsafe_unretained typeof(self) _self = self; [_textfieldPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSString *resultingText) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - if (returnCode != NSOKButton) { - [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; + [_profilePopup selectItemAtIndex:[self currentProfileIndex]]; return; } + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"]; // duplicate names are not allowed in the popup control if ([resultingText length] == 0 || [profileNames containsObject:resultingText]) { - [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; + [_profilePopup selectItemAtIndex:[self currentProfileIndex]]; NSAlert *alert = [[NSAlert alloc] init]; [alert setAlertStyle:NSCriticalAlertStyle]; @@ -792,7 +820,8 @@ NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]]; [workArray addObject:newProfile]; [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 addObject:resultingText]; @@ -827,18 +856,20 @@ __unsafe_unretained typeof(self) _self = self; [_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + NSInteger activeProfileIndex = [_self currentProfileIndex]; if (returnCode != NSOKButton) { - [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; + [_profilePopup selectItemAtIndex:activeProfileIndex]; return; } if (!selectedIndex) { // TODO: add popup to notify user - [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; + [_profilePopup selectItemAtIndex:activeProfileIndex]; return; } + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; /* remove selected profile from settings */ NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]]; [workArray removeObjectAtIndex:selectedIndex]; @@ -848,14 +879,12 @@ [workArray removeObjectAtIndex:selectedIndex]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"]; - if (i_old_profile_index >= selectedIndex) - [defaults setInteger:i_old_profile_index - 1 forKey:@"VideoEffectSelectedProfile"]; + if (activeProfileIndex >= selectedIndex) + [self saveCurrentProfileIndex:(activeProfileIndex - 1)]; /* save defaults */ [defaults synchronize]; - /* do not save deleted profile */ - i_old_profile_index = -1; /* refresh UI */ [_self resetProfileSelector]; }]; _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
