summaryrefslogtreecommitdiffstats
path: root/macosx/HBQueueActionItem.m
blob: 41401f2715b07c668ece708ecf3a876e111e6154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*  HBQueueActionItem.m $

 This file is part of the HandBrake source code.
 Homepage: <http://handbrake.fr/>.
 It may be used under the terms of the GNU General Public License. */

#import "HBQueueActionItem.h"
#import "HBCodingUtilities.h"

@implementation HBQueueActionStopItem

#pragma mark - NSSecureCoding

- (instancetype)init
{
    self = [super init];
    if (self) {
        _state = HBQueueItemStateReady;
    }
    return self;
}

- (NSString *)title
{
    return NSLocalizedString(@"Stop", @"Queue -> Stop action");
}

- (BOOL)hasFileRepresentation
{
    return NO;
}

- (NSAttributedString *)attributedDescription
{
    return [[NSAttributedString alloc] initWithString:NSLocalizedString(@"Stop action.", @"Queue -> Stop action")
                                           attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:NSFont.smallSystemFontSize]}];
}

- (NSImage *)image
{
    return [NSImage imageNamed:@"EncodeCanceled"];
}

+ (BOOL)supportsSecureCoding
{
    return YES;
}

static NSString *versionKey = @"HBQueueActionItemVersion";

- (void)encodeWithCoder:(nonnull NSCoder *)coder {
    [coder encodeInt:1 forKey:versionKey];
    encodeInteger(_state);
}

- (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder {
    int version = [decoder decodeIntForKey:versionKey];

    if (version == 1 && (self = [super init]))
    {
        decodeInteger(_state); if (_state < HBQueueItemStateReady || _state > HBQueueItemStateRescanning) { goto fail; }
        return self;
    }
fail:
    return nil;
}

@end