summaryrefslogtreecommitdiffstats
path: root/macosx/QueueController.mm
blob: e775bb33d1a610f9dcd6a7de5317aee844c19e2d (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
#include "QueueController.h"

@implementation QueueController

- (void) SetHandle: (hb_handle_t *) handle
{
    fHandle = handle;
}

- (void) AddTextField: (NSString *) string rect: (NSRect *) rect
{
    NSTextField * textField;

    rect->origin.x     = 10;
    rect->origin.y    -= 17;
    rect->size.height  = 17;
    textField = [[NSTextField alloc] initWithFrame: *rect];

    [textField setEditable: NO];
    [textField setSelectable: NO];
    [textField setDrawsBackground: NO];
    [textField setBordered: NO];
    [textField setStringValue: string];

    [fTaskView addSubview: textField];
}

- (void) removeTask: (id) sender
{
    hb_rem( fHandle, hb_job( fHandle, [sender tag] ) );
    [self performSelectorOnMainThread: @selector( Update: )
        withObject: sender waitUntilDone: NO];
}

- (void) AddButton: (NSRect *) rect tag: (int) tag
{
    NSButton * button;

    rect->origin.x     = rect->size.width - 90;
    rect->origin.y    -= 20;
    rect->size.width   = 100;
    rect->size.height  = 20;
    button = [[NSButton alloc] initWithFrame: *rect];
    rect->size.width   = rect->origin.x + 90;

    [button setTitle: @"Remove"];
    [button setBezelStyle: NSRoundedBezelStyle];
    [button setFont: [NSFont systemFontOfSize:
        [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
    [[button cell] setControlSize: NSSmallControlSize];

    [button setTag: tag];
    [button setTarget: self];
    [button setAction: @selector( removeTask: )];

    [fTaskView addSubview: button];

    NSBox * box;

    rect->origin.x     = 15;
    rect->origin.y    -= 10;
    rect->size.width  -= 10;
    rect->size.height  = 1;
    box = [[NSBox alloc] initWithFrame: *rect];
    [box setBoxType: NSBoxSeparator];
    rect->origin.y    -= 10;
    rect->size.width  += 10;

    [fTaskView addSubview: box];
}

- (IBAction) Update: (id) sender
{
    int i;
    hb_job_t * j;
    hb_title_t * title;

    NSSize size = [fScrollView contentSize];
    int height = MAX( 20 + 125 * hb_count( fHandle ), size.height );
    [fTaskView setFrame: NSMakeRect(0,0,size.width,height)];

    NSRect rect = NSMakeRect(10,height-10,size.width-20,10);

    NSArray * subviews = [fTaskView subviews];
    while( [subviews count] > 0 )
    {
        [[subviews objectAtIndex: 0]
            removeFromSuperviewWithoutNeedingDisplay];
    }

    for( i = 0; i < hb_count( fHandle ); i++ )
    {
        j = hb_job( fHandle, i );
        title = j->title;
        
        [self AddTextField: [NSString stringWithFormat:
            @"DVD: %s", title->dvd] rect: &rect];
        [self AddTextField: [NSString stringWithFormat:
            @"Title: %d", title->index] rect: &rect];
        [self AddTextField: [NSString stringWithFormat:
            @"Chapters: %d to %d", j->chapter_start, j->chapter_end]
            rect: &rect];
        [self AddTextField: [NSString stringWithFormat:
            @"Pass: %d of %d", MAX( 1, j->pass ), MIN( 2, j->pass + 1 )]
            rect: &rect];
        [self AddTextField: [NSString stringWithFormat:
            @"Destination: %s", j->file] rect: &rect];
        [self AddButton: &rect tag: i];
    }

    [fTaskView scrollPoint: NSMakePoint(0,height)];
    [fTaskView setNeedsDisplay: YES];
}

- (IBAction) ClosePanel: (id) sender
{
    [NSApp stopModal];
}

@end