summaryrefslogtreecommitdiffstats
path: root/macosx/HBPreset.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2015-10-13 19:17:10 +0200
committerDamiano Galassi <[email protected]>2015-10-13 19:17:10 +0200
commit1b8ff2bb17489ebadca609d91af2bde286fa69a2 (patch)
tree8d30dca2d32e2354fda6188bd2df678e4ee72b1e /macosx/HBPreset.m
parent441754fd518abf26385035fa58a1c1fa048f4119 (diff)
MacGui: add a new method to create a copy of a HBPreset instance, and added back a method that had been inadvertently deleted.
Diffstat (limited to 'macosx/HBPreset.m')
-rw-r--r--macosx/HBPreset.m43
1 files changed, 39 insertions, 4 deletions
diff --git a/macosx/HBPreset.m b/macosx/HBPreset.m
index 971d2c0d6..147c0c555 100644
--- a/macosx/HBPreset.m
+++ b/macosx/HBPreset.m
@@ -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
@@ -34,6 +32,25 @@
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];
@@ -262,6 +279,24 @@
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
@@ -276,7 +311,7 @@
- (id)mutableCopyWithZone:(NSZone *)zone
{
- return [[HBMutablePreset allocWithZone:zone] initWithDictionary:_content];
+ return [[HBMutablePreset allocWithZone:zone] initWithPreset:self];
}
- (NSUInteger)hash