summaryrefslogtreecommitdiffstats
path: root/macosx/HBQueueItemView.m
blob: 243c52938381585539e107b4fc3980080eb2ed73 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*  HBQueueItemView.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 "HBQueueItemView.h"
#import "HBQueueItem.h"

@interface HBQueueItemView ()

@property (nonatomic, weak) IBOutlet NSButton *removeButton;

@end

@implementation HBQueueItemView

- (void)setItem:(HBQueueItem *)item
{
    _item = item;
    [self reload];
}

- (void)reload
{
    [self HB_updateLabel];
    [self HB_updateState];
    [self HB_updateRightButton];

    self.removeButton.target = self;
}

- (void)HB_updateLabel
{
    self.textField.stringValue = _item.outputFileName;
}

- (void)HB_updateState
{
    NSImage *state = nil;
    switch (_item.state) {
        case HBQueueItemStateCompleted:
            state = [NSImage imageNamed:@"EncodeComplete"];
            break;
        case HBQueueItemStateWorking:
            state = [NSImage imageNamed:@"EncodeWorking0"];
            break;
        case HBQueueItemStateCanceled:
            state = [NSImage imageNamed:@"EncodeCanceled"];
            break;
        case HBQueueItemStateFailed:
            state = [NSImage imageNamed:@"EncodeFailed"];
            break;
        default:
            state = [NSImage imageNamed:@"JobSmall"];
            break;
    }

    self.imageView.image = state;
}

- (void)HB_updateRightButton
{
    BOOL darkAqua = NO;

    if (@available(macOS 10.14, *))
    {
        darkAqua = [self.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameDarkAqua]] == NSAppearanceNameDarkAqua ? YES : NO;
    }

    if (_item.state == HBQueueItemStateCompleted)
    {
        [_removeButton setAction: @selector(revealQueueItem:)];
        if (self.backgroundStyle == NSBackgroundStyleEmphasized)
        {
            [_removeButton setImage:[NSImage imageNamed:@"RevealHighlight"]];
            [_removeButton setAlternateImage:[NSImage imageNamed:@"RevealHighlightPressed"]];
        }
        else
        {
            [_removeButton setImage:[NSImage imageNamed:darkAqua ? @"RevealHighlight" : @"Reveal"]];
        }
    }
    else
    {
        [_removeButton setAction: @selector(removeQueueItem:)];
        if (self.backgroundStyle == NSBackgroundStyleEmphasized)
        {
            [_removeButton setImage:[NSImage imageNamed:@"DeleteHighlight"]];
            [_removeButton setAlternateImage:[NSImage imageNamed:@"DeleteHighlightPressed"]];
        }
        else
        {
            [_removeButton setImage:[NSImage imageNamed:darkAqua ? @"DeleteHighlight" : @"Delete"]];
        }
    }
}

- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle
{
    [super setBackgroundStyle:backgroundStyle];
    [self HB_updateRightButton];
}

- (BOOL)isFlipped
{
    return YES;
}

- (void)viewDidChangeEffectiveAppearance
{
    [self HB_updateRightButton];
}

- (IBAction)revealQueueItem:(id)sender
{
    [self.delegate revealQueueItem:_item];
}

- (IBAction)removeQueueItem:(id)sender
{
    [self.delegate removeQueueItem:_item];
}

@end