]> granicus.if.org Git - handbrake/commitdiff
MacGui: add a new method to create a copy of a HBPreset instance, and added back...
authorDamiano Galassi <damiog@gmail.com>
Tue, 13 Oct 2015 17:17:10 +0000 (19:17 +0200)
committerDamiano Galassi <damiog@gmail.com>
Tue, 13 Oct 2015 17:17:10 +0000 (19:17 +0200)
macosx/HBPreset.h
macosx/HBPreset.m

index 32f20c177e3d333bf4ac28fc1bc81dac1a45f3f0..100972784b3fb043bf327dde56361678a30ce6b5 100644 (file)
@@ -22,10 +22,10 @@ typedef NS_ENUM(NSUInteger, HBPresetFormat) {
 @interface HBPreset : HBTreeNode <NSCopying, NSMutableCopying>
 
 - (instancetype)initWithFolderName:(NSString *)title builtIn:(BOOL)builtIn;
-
 - (instancetype)initWithName:(NSString *)title content:(NSDictionary *)content builtIn:(BOOL)builtIn;
 
 - (instancetype)initWithDictionary:(NSDictionary *)dict;
+- (instancetype)initWithPreset:(HBPreset *)preset;
 
 /**
  *  Initializes a newly allocated preset object initialized with the data found at a given URL.
index 971d2c0d68656c506b59aa80b435c39815baf447..147c0c555d67f8f7a2cef88c33fba03df784bead 100644 (file)
@@ -13,9 +13,7 @@
 
 @interface HBPreset ()
 
-/**
- *  The actual content of the preset.
- */
+///  The actual content of the preset.
 @property (nonatomic, strong, nullable) NSMutableDictionary *content;
 
 @end
     return self;
 }
 
+- (instancetype)initWithPreset:(HBPreset *)preset
+{
+    self = [super init];
+    if (self)
+    {
+        _name = preset.name;
+        _presetDescription = preset.presetDescription;
+        _content = [preset.content mutableCopy];
+        self.isLeaf = preset.isLeaf;
+
+        for (HBPreset *child in preset.children)
+        {
+            HBPreset *mutableChild = [[[self class] alloc] initWithPreset:child];
+            [self insertObject:mutableChild inChildrenAtIndex:0];
+        }
+    }
+    return self;
+}
+
 - (instancetype)initWithName:(NSString *)title content:(NSDictionary *)content builtIn:(BOOL)builtIn;
 {
     self = [self init];
     return success;
 }
 
+- (void)cleanUp
+{
+    // Run the libhb clean function
+    NSString *presetJson = [NSJSONSerialization HB_StringWithJSONObject:self.dictionary options:0 error:NULL];
+
+    if (presetJson.length)
+    {
+        char *cleanedJson = hb_presets_clean_json(presetJson.UTF8String);
+        NSDictionary *cleanedDict = [NSJSONSerialization HB_JSONObjectWithUTF8String:cleanedJson options:0 error:NULL];
+        free(cleanedJson);
+
+        if ([cleanedDict isKindOfClass:[NSDictionary class]])
+        {
+            self.content = [cleanedDict mutableCopy];
+        }
+    }
+}
+
 #pragma mark - NSCopying
 
 - (id)copyWithZone:(NSZone *)zone
 
 - (id)mutableCopyWithZone:(NSZone *)zone
 {
-    return [[HBMutablePreset allocWithZone:zone] initWithDictionary:_content];
+    return [[HBMutablePreset allocWithZone:zone] initWithPreset:self];
 }
 
 - (NSUInteger)hash