blob: 29b0aeb36e08c79a59c81168b1b3212d952f8bfb (
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
|
/* HBQueueDetailsViewController.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 "HBQueueInfoViewController.h"
#import "HBQueueJobItem.h"
static void *HBQueueInfoViewControllerContext = &HBQueueInfoViewControllerContext;
@interface HBQueueInfoViewController ()
@property (nonatomic, weak) IBOutlet NSView *statisticsHeader;
@property (nonatomic, weak) IBOutlet NSTextField *statisticsLabel;
@property (nonatomic, weak) IBOutlet NSTextField *summaryLabel;
@property (nonatomic, weak) IBOutlet NSScrollView *scrollView;
@property (nonatomic, weak) IBOutlet NSBox *divider;
@property (nonatomic, weak) id<HBQueueDetailsViewControllerDelegate> delegate;
@property (nonatomic) BOOL canReset;
@property (nonatomic) BOOL canEdit;
@end
@implementation HBQueueInfoViewController
- (instancetype)initWithDelegate:(id<HBQueueDetailsViewControllerDelegate>)delegate
{
self = [super init];
if (self)
{
_delegate = delegate;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self updateUI];
[self addObserver:self forKeyPath:@"item.state" options:0 context:HBQueueInfoViewControllerContext];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == HBQueueInfoViewControllerContext)
{
[self updateUI];
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)updateUI
{
[self updateLabels];
[self updateReset];
dispatch_async(dispatch_get_main_queue(), ^{
[self updateDivider];
});
}
- (void)updateReset
{
self.canReset = self.item && (self.item.state != HBQueueItemStateWorking &&
self.item.state != HBQueueItemStateRescanning && self.item.state != HBQueueItemStateReady);
self.canEdit = self.item && self.item.hasFileRepresentation;
}
- (void)updateLabels
{
if (self.item)
{
if ([self.item isKindOfClass:[HBQueueJobItem class]])
{
HBQueueJobItem *jobItem = (HBQueueJobItem *)self.item;
self.statisticsLabel.hidden = jobItem.startedDate == nil;
self.statisticsHeader.hidden = jobItem.startedDate == nil;
self.statisticsLabel.attributedStringValue = jobItem.attributedStatistics;
}
else
{
self.statisticsLabel.hidden = YES;
self.statisticsHeader.hidden = YES;
}
self.summaryLabel.hidden = NO;
self.summaryLabel.attributedStringValue = self.item.attributedDescription;
dispatch_async(dispatch_get_main_queue(), ^{
[self.scrollView flashScrollers];
});
}
else
{
self.statisticsHeader.hidden = YES;
self.statisticsLabel.hidden = YES;
self.summaryLabel.hidden = YES;
}
}
- (void)updateDivider
{
self.divider.hidden = self.scrollView.frame.size.height > self.scrollView.contentView.documentView.frame.size.height;
}
- (void)viewDidLayout
{
[super viewDidLayout];
[self updateDivider];
}
- (void)setItem:(id<HBQueueItem>)item
{
_item = item;
}
- (IBAction)editItem:(id)sender
{
[self.delegate detailsViewEditItem:self.item];
}
- (IBAction)resetItem:(id)sender
{
[self.delegate detailsViewResetItem:self.item];
}
@end
|