OSDN Git Service

MacGui: Fix Presets mangling the x264 option strings for the umpteenth time.
[handbrake-jp/handbrake-jp-git.git] / macosx / QueueController.mm
1 #include "QueueController.h"
2
3 @implementation QueueController
4
5 - (void) SetHandle: (hb_handle_t *) handle
6 {
7     fHandle = handle;
8 }
9
10 - (void) AddTextField: (NSString *) string rect: (NSRect *) rect
11 {
12     NSTextField * textField;
13
14     rect->origin.x     = 10;
15     rect->origin.y    -= 17;
16     rect->size.height  = 17;
17     textField = [[NSTextField alloc] initWithFrame: *rect];
18
19     [textField setEditable: NO];
20     [textField setSelectable: NO];
21     [textField setDrawsBackground: NO];
22     [textField setBordered: NO];
23     [textField setStringValue: string];
24
25     [fTaskView addSubview: textField];
26 }
27
28 - (void) removeTask: (id) sender
29 {
30     hb_rem( fHandle, hb_job( fHandle, [sender tag] ) );
31     [self performSelectorOnMainThread: @selector( Update: )
32         withObject: sender waitUntilDone: NO];
33 }
34
35 - (void) AddButton: (NSRect *) rect tag: (int) tag
36 {
37     NSButton * button;
38
39     rect->origin.x     = rect->size.width - 90;
40     rect->origin.y    -= 20;
41     rect->size.width   = 100;
42     rect->size.height  = 20;
43     button = [[NSButton alloc] initWithFrame: *rect];
44     rect->size.width   = rect->origin.x + 90;
45
46     [button setTitle: @"Remove"];
47     [button setBezelStyle: NSRoundedBezelStyle];
48     [button setFont: [NSFont systemFontOfSize:
49         [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
50     [[button cell] setControlSize: NSSmallControlSize];
51
52     [button setTag: tag];
53     [button setTarget: self];
54     [button setAction: @selector( removeTask: )];
55
56     [fTaskView addSubview: button];
57
58     NSBox * box;
59
60     rect->origin.x     = 15;
61     rect->origin.y    -= 10;
62     rect->size.width  -= 10;
63     rect->size.height  = 1;
64     box = [[NSBox alloc] initWithFrame: *rect];
65     [box setBoxType: NSBoxSeparator];
66     rect->origin.y    -= 10;
67     rect->size.width  += 10;
68
69     [fTaskView addSubview: box];
70 }
71
72 - (IBAction) Update: (id) sender
73 {
74     int i;
75     hb_job_t * j;
76     hb_title_t * title;
77
78     NSSize size = [fScrollView contentSize];
79     int height = MAX( 20 + 125 * hb_count( fHandle ), size.height );
80     [fTaskView setFrame: NSMakeRect(0,0,size.width,height)];
81
82     NSRect rect = NSMakeRect(10,height-10,size.width-20,10);
83
84     NSArray * subviews = [fTaskView subviews];
85     while( [subviews count] > 0 )
86     {
87         [[subviews objectAtIndex: 0]
88             removeFromSuperviewWithoutNeedingDisplay];
89     }
90
91     for( i = 0; i < hb_count( fHandle ); i++ )
92     {
93         j = hb_job( fHandle, i );
94         title = j->title;
95         
96         [self AddTextField: [NSString stringWithFormat:
97             @"DVD: %s", title->dvd] rect: &rect];
98         [self AddTextField: [NSString stringWithFormat:
99             @"Title: %d", title->index] rect: &rect];
100         [self AddTextField: [NSString stringWithFormat:
101             @"Chapters: %d to %d", j->chapter_start, j->chapter_end]
102             rect: &rect];
103         [self AddTextField: [NSString stringWithFormat:
104             @"Pass: %d of %d", MAX( 1, j->pass ), MIN( 2, j->pass + 1 )]
105             rect: &rect];
106         [self AddTextField: [NSString stringWithFormat:
107             @"Destination: %s", j->file] rect: &rect];
108         [self AddButton: &rect tag: i];
109     }
110
111     [fTaskView scrollPoint: NSMakePoint(0,height)];
112     [fTaskView setNeedsDisplay: YES];
113 }
114
115 - (IBAction) ClosePanel: (id) sender
116 {
117     [NSApp stopModal];
118 }
119
120 @end