summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/HBPreset.h2
-rw-r--r--macosx/HBPreset.m43
2 files changed, 40 insertions, 5 deletions
diff --git a/macosx/HBPreset.h b/macosx/HBPreset.h
index 32f20c177..100972784 100644
--- a/macosx/HBPreset.h
+++ b/macosx/HBPreset.h
@@ -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.
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