summaryrefslogtreecommitdiffstats
path: root/macosx/HBQueueItemView.m
blob: d736fe59f71766b1dba6ea8ea4ad09bd0433101f (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*  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;
@property (nonatomic, weak) IBOutlet NSButton *expandButton;

@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;
    self.expandButton.target = self;
    self.expandButton.action = @selector(toggleHeight:);
}

- (void)HB_updateLabel
{
    if (_item.expanded)
    {
        self.textField.attributedStringValue = _item.attributedDescription;
        self.expandButton.state = NSOnState;
    }
    else
    {
        self.textField.attributedStringValue = _item.attributedTitleDescription;
        self.expandButton.state = NSOffState;
    }
}

- (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];
}

- (void)expand
{
    self.expandButton.state = NSOnState;
    self.textField.attributedStringValue = _item.attributedDescription;
}

- (void)collapse
{
    self.expandButton.state = NSOffState;
    self.textField.attributedStringValue = _item.attributedTitleDescription;
}

- (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];
}

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

@end