diff options
author | Damiano Galassi <[email protected]> | 2019-02-07 19:11:51 +0100 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2019-02-07 19:11:51 +0100 |
commit | 5c52e252def1d72d072adc4cfdb2137a35705186 (patch) | |
tree | 8c34d9d5ea5acdc012155c8c14abd15b87cfefc6 /macosx/HBQueueItem.m | |
parent | 618ee9eb98daba5d4f64cf26c04b6429d16faf97 (diff) |
MacGui: refactor some queue related properties out of HBJob to a new HBQueueItem class.
Diffstat (limited to 'macosx/HBQueueItem.m')
-rw-r--r-- | macosx/HBQueueItem.m | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/macosx/HBQueueItem.m b/macosx/HBQueueItem.m new file mode 100644 index 000000000..3e993281f --- /dev/null +++ b/macosx/HBQueueItem.m @@ -0,0 +1,99 @@ +// +// HBQueueItem.m +// HandBrake +// +// Created by Damiano Galassi on 07/02/2019. +// + +#import "HBQueueItem.h" + +#import "HBCodingUtilities.h" + +@implementation HBQueueItem + +@synthesize job = _job; +@synthesize attributedDescription = _attributedDescription; +@synthesize attributedTitleDescription = _attributedTitleDescription; + +@synthesize uuid = _uuid; + +- (instancetype)initWithJob:(HBJob *)job +{ + self = [super init]; + if (self) + { + _job = job; + _uuid = [NSUUID UUID].UUIDString; + } + return self; +} + +#pragma mark - Properties + +- (NSURL *)fileURL +{ + return _job.fileURL; +} + +- (NSString *)outputFileName +{ + return _job.outputFileName; +} + +- (NSURL *)outputURL +{ + return _job.outputURL; +} + +- (NSURL *)completeOutputURL +{ + return _job.completeOutputURL; +} + +- (NSAttributedString *)attributedDescription +{ + if (_attributedDescription == nil) { + _attributedDescription = _job.attributedDescription; + } + return _attributedDescription; +} + +- (NSAttributedString *)attributedTitleDescription +{ + if (_attributedTitleDescription == nil) { + _attributedTitleDescription = _job.attributedTitleDescription; + } + return _attributedTitleDescription; +} + +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +static NSString *versionKey = @"HBQueueItemVersion"; + +- (void)encodeWithCoder:(nonnull NSCoder *)coder +{ + [coder encodeInt:1 forKey:versionKey]; + encodeObject(_job); + encodeObject(_uuid); +} + +- (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder +{ + int version = [decoder decodeIntForKey:versionKey]; + + if (version == 1 && (self = [super init])) + { + decodeObjectOrFail(_job, HBJob); + decodeObjectOrFail(_uuid, NSString); + return self; + } +fail: + return nil; +} + +@end |