diff options
author | Damiano Galassi <[email protected]> | 2015-10-13 10:22:02 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2015-10-13 10:22:02 +0200 |
commit | 14839ed2b8a7e4615b2c30fe8a46bb63819d0b40 (patch) | |
tree | f8684e1d7eb41fa1df0c420da50cd4f53f692e64 /macosx/HBPreset.m | |
parent | b8bcf81a60e505135cab3f6deeb090989012ba5e (diff) |
MacGui: remove some HBPreset -> NSDictionary conversions and add a mutable version of HBPreset.
Diffstat (limited to 'macosx/HBPreset.m')
-rw-r--r-- | macosx/HBPreset.m | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/macosx/HBPreset.m b/macosx/HBPreset.m index 58fe6a36d..971d2c0d6 100644 --- a/macosx/HBPreset.m +++ b/macosx/HBPreset.m @@ -5,10 +5,21 @@ It may be used under the terms of the GNU General Public License. */ #import "HBPreset.h" +#import "HBMutablePreset.h" + #include "preset.h" #import "NSJSONSerialization+HBAdditions.h" +@interface HBPreset () + +/** + * The actual content of the preset. + */ +@property (nonatomic, strong, nullable) NSMutableDictionary *content; + +@end + @implementation HBPreset - (instancetype)init @@ -30,7 +41,7 @@ { _name = [title copy]; _isBuiltIn = builtIn; - _content = [content copy]; + _content = [content mutableCopy]; if ([content[@"PresetDescription"] isKindOfClass:[NSString class]]) { _presetDescription = [content[@"PresetDescription"] copy]; @@ -188,6 +199,9 @@ } +/** + * A dictionary representation of the preset. + */ - (NSDictionary *)dictionary { NSMutableDictionary *output = [[NSMutableDictionary alloc] init]; @@ -248,39 +262,30 @@ return success; } +#pragma mark - NSCopying + - (id)copyWithZone:(NSZone *)zone { HBPreset *node = [super copyWithZone:zone]; node->_name = [self.name copy]; - node->_content = [self.content copy]; + node->_content = [self.content mutableCopy]; node->_presetDescription = [self.presetDescription copy]; return node; } -- (NSUInteger)hash +- (id)mutableCopyWithZone:(NSZone *)zone { - return self.name.hash + self.isBuiltIn + self.isLeaf; + return [[HBMutablePreset allocWithZone:zone] initWithDictionary:_content]; } -- (void)cleanUp +- (NSUInteger)hash { - // 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; - } - } + return self.name.hash + self.isBuiltIn + self.isLeaf; } +#pragma mark - Properties + - (void)setName:(NSString *)name { _name = [name copy]; @@ -293,6 +298,18 @@ [self.delegate nodeDidChange:self]; } +#pragma mark - Keys + +- (id)objectForKey:(NSString *)key +{ + return [_content objectForKey:key]; +} + +- (nullable id)objectForKeyedSubscript:(NSString *)key +{ + return _content[key]; +} + #pragma mark - KVC - (BOOL)validateName:(id *)ioValue error:(NSError * __autoreleasing *)outError |