2019-07-27 13:15:37 +02:00
|
|
|
/* 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"
|
2019-07-27 16:39:06 +02:00
|
|
|
#import "HBQueue.h"
|
2019-07-27 13:15:37 +02:00
|
|
|
|
|
|
|
@interface HBQueueInfoViewController ()
|
|
|
|
|
2019-08-12 10:19:00 +02:00
|
|
|
@property (nonatomic, weak) IBOutlet NSView *statisticsHeader;
|
|
|
|
@property (nonatomic, weak) IBOutlet NSTextField *statisticsLabel;
|
|
|
|
@property (nonatomic, weak) IBOutlet NSTextField *summaryLabel;
|
|
|
|
@property (nonatomic, weak) IBOutlet NSScrollView *scrollView;
|
2020-01-28 18:55:04 +01:00
|
|
|
@property (nonatomic, weak) IBOutlet NSBox *divider;
|
2019-07-27 13:15:37 +02:00
|
|
|
|
2019-08-12 10:19:00 +02:00
|
|
|
@property (nonatomic, weak) id<HBQueueDetailsViewControllerDelegate> delegate;
|
2019-07-27 13:15:37 +02:00
|
|
|
|
2019-07-29 07:34:38 +02:00
|
|
|
@property (nonatomic) BOOL canReset;
|
|
|
|
|
2019-07-27 13:15:37 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation HBQueueInfoViewController
|
|
|
|
|
|
|
|
- (instancetype)initWithDelegate:(id<HBQueueDetailsViewControllerDelegate>)delegate
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
_delegate = delegate;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
[self updateLabels];
|
2019-07-27 16:39:06 +02:00
|
|
|
[self setUpObservers];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setUpObservers
|
|
|
|
{
|
2019-07-30 10:29:01 +02:00
|
|
|
// It would be easier to just KVO the item state property,
|
|
|
|
// But we can't because the item is a NSProxy.
|
2019-07-27 16:39:06 +02:00
|
|
|
NSNotificationCenter * __weak center = NSNotificationCenter.defaultCenter;
|
|
|
|
|
2019-07-29 07:34:38 +02:00
|
|
|
[center addObserverForName:HBQueueDidStartItemNotification
|
2019-07-27 16:39:06 +02:00
|
|
|
object:nil
|
|
|
|
queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
|
|
|
|
{
|
2019-07-29 07:34:38 +02:00
|
|
|
HBQueueItem *startedItem = note.userInfo[HBQueueItemNotificationItemKey];
|
2019-07-27 16:39:06 +02:00
|
|
|
|
2019-07-29 07:34:38 +02:00
|
|
|
if (startedItem == self.item)
|
2019-07-27 16:39:06 +02:00
|
|
|
{
|
|
|
|
[self updateLabels];
|
2019-07-29 07:34:38 +02:00
|
|
|
[self updateReset];
|
2019-07-27 16:39:06 +02:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
[center addObserverForName:HBQueueDidCompleteItemNotification
|
|
|
|
object:nil
|
|
|
|
queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
|
|
|
|
{
|
|
|
|
HBQueueItem *completedItem = note.userInfo[HBQueueItemNotificationItemKey];
|
|
|
|
|
|
|
|
if (completedItem == self.item)
|
|
|
|
{
|
|
|
|
[self updateLabels];
|
2019-07-29 07:34:38 +02:00
|
|
|
[self updateReset];
|
2019-07-27 16:39:06 +02:00
|
|
|
}
|
|
|
|
}];
|
2019-07-30 10:29:01 +02:00
|
|
|
|
|
|
|
[center addObserverForName:HBQueueDidChangeItemNotification
|
|
|
|
object:nil
|
|
|
|
queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
|
|
|
|
{
|
|
|
|
[self updateLabels];
|
|
|
|
[self updateReset];
|
|
|
|
}];
|
|
|
|
|
2019-07-29 07:34:38 +02:00
|
|
|
}
|
2019-07-27 16:39:06 +02:00
|
|
|
|
2019-07-29 07:34:38 +02:00
|
|
|
- (void)updateReset
|
|
|
|
{
|
|
|
|
self.canReset = self.item && (self.item.state != HBQueueItemStateWorking && self.item.state != HBQueueItemStateReady);
|
2019-07-27 13:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateLabels
|
|
|
|
{
|
|
|
|
if (self.item)
|
|
|
|
{
|
2019-07-29 07:34:38 +02:00
|
|
|
self.statisticsLabel.hidden = self.item.startedDate == nil;
|
|
|
|
self.statisticsHeader.hidden = self.item.startedDate == nil;
|
2019-07-27 13:15:37 +02:00
|
|
|
self.summaryLabel.hidden = NO;
|
|
|
|
|
|
|
|
self.statisticsLabel.attributedStringValue = self.item.attributedStatistics;
|
|
|
|
self.summaryLabel.attributedStringValue = self.item.attributedDescription;
|
|
|
|
|
|
|
|
[self.scrollView flashScrollers];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-27 16:39:06 +02:00
|
|
|
self.statisticsHeader.hidden = YES;
|
2019-07-27 13:15:37 +02:00
|
|
|
self.statisticsLabel.hidden = YES;
|
|
|
|
self.summaryLabel.hidden = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 18:55:04 +01:00
|
|
|
- (void)viewDidLayout
|
|
|
|
{
|
|
|
|
[super viewDidLayout];
|
|
|
|
self.divider.hidden = self.scrollView.frame.size.height > self.scrollView.contentView.documentView.frame.size.height;
|
|
|
|
}
|
|
|
|
|
2019-07-27 13:15:37 +02:00
|
|
|
- (void)setItem:(HBQueueItem *)item
|
|
|
|
{
|
|
|
|
_item = item;
|
|
|
|
[self updateLabels];
|
2019-07-29 07:34:38 +02:00
|
|
|
[self updateReset];
|
2019-07-27 13:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)editItem:(id)sender
|
|
|
|
{
|
|
|
|
[self.delegate detailsViewEditItem:self.item];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)resetItem:(id)sender
|
|
|
|
{
|
|
|
|
[self.delegate detailsViewResetItem:self.item];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|