]> granicus.if.org Git - handbrake/commitdiff
[merge] MacGui: add a better check for regenerating the built-in presets after a...
authorritsuka <damiog@gmail.com>
Mon, 24 Nov 2014 20:09:33 +0000 (20:09 +0000)
committerritsuka <damiog@gmail.com>
Mon, 24 Nov 2014 20:09:33 +0000 (20:09 +0000)
added a missing retain, it caused a crash when selecting a new default preset if the old default was a default preset that had been deleted by they built-in presets upgrade.

git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/0.10.x@6553 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/Controller.m
macosx/HBPresetsManager.h
macosx/HBPresetsManager.m

index b44b582650b01308322bad2d90aa20e7f302d22f..bf0e079bb3e907b8a54872f8764bc7194590ada3 100644 (file)
@@ -80,7 +80,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         // we init the HBPresetsManager class
         NSURL *presetsURL = [NSURL fileURLWithPath:[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"UserPresets.plist"]];
         presetManager = [[HBPresetsManager alloc] initWithURL:presetsURL];
-        _selectedPreset = presetManager.defaultPreset;
+        _selectedPreset = [presetManager.defaultPreset retain];
 
         // Workaround to avoid a bug in Snow Leopard
         // we can switch back to [[NSApplication sharedApplication] applicationIconImage]
@@ -4978,7 +4978,7 @@ the user is using "Custom" settings by determining the sender*/
     else
     {
         /* Here we create a custom user preset */
-        [presetManager addPreset:[self createPreset]];
+        [presetManager addPresetFromDictionary:[self createPreset]];
 
         [self closeAddPresetPanel:nil];
     }
@@ -5133,7 +5133,7 @@ the user is using "Custom" settings by determining the sender*/
             [tempObject setObject:prependedName forKey:@"PresetName"];
             
             /* actually add the new preset to our presets array */
-            [presetManager addPreset:tempObject];
+            [presetManager addPresetFromDictionary:tempObject];
         }
         [presetsToImport autorelease];
     }];
index 74427f550de32b84c0faa297839f59420ee2aada..4eddec36570df969925d46c1ebdb29b2c41ecb85 100644 (file)
@@ -55,7 +55,14 @@ extern NSString *HBPresetsChangedNotification;
  *
  *  @param preset the preset dict.
  */
-- (void)addPreset:(NSDictionary *)preset;
+- (void)addPresetFromDictionary:(NSDictionary *)preset;
+
+/**
+ *  Adds a given preset to the manager.
+ *
+ *  @param preset the preset dict.
+ */
+- (void)addPreset:(HBPreset *)preset;
 
 /**
  *  Deletes the presets at the specified index path.
index 86bd7f4fa113dde174997c60d733b3707fa919f7..195c1ea8f6e239d879b67ca513bb8e87c316e873 100644 (file)
@@ -105,9 +105,18 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
 
     [presetsArray release];
 
-    // If the preset list is empty,
-    // readd the built in presets.
-    if (self.root.children.count == 0)
+    // If the preset list contains no leaf,
+    // add back the built in presets.
+    __block BOOL leafFound = NO;
+    [self.root enumerateObjectsUsingBlock:^(id obj, NSIndexPath *idx, BOOL *stop) {
+        if ([obj isLeaf])
+        {
+            leafFound = YES;
+            *stop = YES;
+        }
+    }];
+
+    if (!leafFound)
     {
         [self generateBuiltInPresets];
     }
@@ -170,10 +179,7 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
         }
     }
 
-    if (!node.isBuiltIn)
-    {
-        node.delegate = self;
-    }
+    node.delegate = self;
 
     return node;
 }
@@ -229,7 +235,7 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
     return retValue;
 }
 
-- (void)addPreset:(NSDictionary *)preset
+- (void)addPresetFromDictionary:(NSDictionary *)preset
 {
     HBPreset *presetNode = [[HBPreset alloc] initWithName:preset[@"PresetName"]
                                                    content:preset
@@ -241,6 +247,13 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
     [self savePresets];
 }
 
+- (void)addPreset:(HBPreset *)preset
+{
+    [self.root insertObject:preset inChildrenAtIndex:[self.root countOfChildren]];
+
+    [self savePresets];
+}
+
 - (void)deletePresetAtIndexPath:(NSIndexPath *)idx
 {
     HBPreset *parentNode = self.root;
@@ -277,13 +290,15 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
 }
 
 /**
- *  Private method to select a new default
- *  when the default preset is deleted.
+ *  Private method to select a new default after the default preset is deleted
+ *  or when the built-in presets are regenerated.
  */
 - (void)selectNewDefault
 {
     __block HBPreset *normalPreset = nil;
     __block HBPreset *firstUserPreset = nil;
+    __block HBPreset *firstBuiltInPreset = nil;
+    __block BOOL defaultAlreadySetted = NO;
 
     // Search for a possibile new default preset
     // Try to use "Normal" or the first user preset.
@@ -294,15 +309,27 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
             {
                 normalPreset = obj;
             }
+            if (firstBuiltInPreset == nil)
+            {
+                firstBuiltInPreset = obj;
+            }
         }
-        else if ([obj isLeaf])
+        else if ([obj isLeaf] && firstUserPreset == nil)
         {
             firstUserPreset = obj;
             *stop = YES;
         }
+
+        if ([obj isDefault]) {
+            defaultAlreadySetted = YES;
+        }
     }];
 
-    if (normalPreset)
+    if (defaultAlreadySetted)
+    {
+        return;
+    }
+    else if (normalPreset)
     {
         self.defaultPreset = normalPreset;
         normalPreset.isDefault = YES;
@@ -312,6 +339,10 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
         self.defaultPreset = firstUserPreset;
         firstUserPreset.isDefault = YES;
     }
+    else if (firstBuiltInPreset) {
+        self.defaultPreset = firstBuiltInPreset;
+        firstBuiltInPreset.isDefault = YES;
+    }
 }
 
 - (void)setDefaultPreset:(HBPreset *)defaultPreset
@@ -372,20 +403,17 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
         @selector(createAndroidTabletPreset),
         @selector(createW8PhonePreset)
     };
-    
+
     SEL regularPresets[] = { @selector(createNormalPreset),
         @selector(createHighProfilePreset)};
-    
+
     [self deleteBuiltInPresets];
 
     [self loadPresetsForType:@"Regular" fromSel:regularPresets length:2];
     [self loadPresetsForType:@"Devices" fromSel:devicesPresets length:10];
 
-    if (self.defaultPreset == nil)
-    {
-        [self selectNewDefault];
-    }
-
+    // set a new Default preset
+    [self selectNewDefault];
 
     [HBUtilities writeToActivityLog: "built in presets updated to build number: %d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]];
 }