]> git.sesse.net Git - vlc/blob - modules/gui/macosx_dialog_provider/VLCProgressPanel.m
osx dialog provider: implemented the progress bar dialog
[vlc] / modules / gui / macosx_dialog_provider / VLCProgressPanel.m
1 /*****************************************************************************
2  * VLCProgressPanel.m: A Generic Progress Indicator Panel created for VLC
3  *****************************************************************************
4  * Copyright (C) 2009-2010 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "VLCProgressPanel.h"
25
26
27 @implementation VLCProgressPanel
28
29 - (id)init
30 {
31     NSRect windowRect;
32     windowRect.size.height = 182;
33     windowRect.size.width = 520;
34     windowRect.origin.x = windowRect.origin.y = 0;
35
36     return [super initWithContentRect:windowRect
37                             styleMask:NSTitledWindowMask
38                               backing:NSBackingStoreBuffered
39                                 defer:YES];
40 }
41
42 - (void)createContentView
43 {
44     NSRect s_rc = [self frame];
45     id ourContentView = [self contentView];
46
47     s_rc.origin.x = 398;
48     s_rc.origin.y = 28;
49     s_rc.size.height = 32;
50     s_rc.size.width = 108;
51     _cancelButton = [[NSButton alloc] initWithFrame:s_rc];
52     [_cancelButton setButtonType:NSMomentaryLightButton];
53     [_cancelButton setTitle:@"Cancel"];
54     [_cancelButton setBezelStyle:NSRoundedBezelStyle];
55     [_cancelButton setBordered:YES];
56     [_cancelButton setTarget:self];
57     [_cancelButton setAction:@selector(cancelDialog:)];
58     [ourContentView addSubview:_cancelButton];
59
60     s_rc.origin.x = 89;
61     s_rc.origin.y = 153;
62     s_rc.size.height = 17;
63     s_rc.size.width = 414;
64     _titleField = [[NSTextField alloc] initWithFrame:s_rc];
65     [_titleField setFont:[NSFont boldSystemFontOfSize:0]];
66     [_titleField setBezeled:NO];
67     [_titleField setEditable:NO];
68     [_titleField setSelectable:YES];
69     [_titleField setDrawsBackground:NO];
70     [ourContentView addSubview:_titleField];
71
72     s_rc.origin.x = 89;
73     s_rc.origin.y = 116;
74     s_rc.size.height = 42;
75     s_rc.size.width = 414;
76     _messageField = [[NSTextField alloc] initWithFrame:s_rc];
77     [_messageField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
78     [_messageField setBezeled:NO];
79     [_messageField setEditable:NO];
80     [_messageField setSelectable:YES];
81     [_messageField setDrawsBackground:NO];
82     [ourContentView addSubview:_messageField];
83
84     s_rc.origin.x = 90;
85     s_rc.origin.y = 66;
86     s_rc.size.height = 20;
87     s_rc.size.width = 412;
88     _progressBar = [[NSProgressIndicator alloc] initWithFrame:s_rc];
89     [_progressBar setMaxValue:1000.0];
90     [_progressBar setUsesThreadedAnimation:YES];
91     [_progressBar setStyle:NSProgressIndicatorBarStyle];
92     [_progressBar setDisplayedWhenStopped:YES];
93     [_progressBar setControlSize:NSRegularControlSize];
94     [_progressBar setIndeterminate:NO];
95     [ourContentView addSubview:_progressBar];
96     [_progressBar startAnimation:nil];
97
98     s_rc.origin.x = 20;
99     s_rc.origin.y = 110;
100     s_rc.size.height = s_rc.size.width = 64;
101     _iconView = [[NSImageView alloc] initWithFrame:s_rc];
102     [_iconView setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
103     [_iconView setEditable:NO];
104     [_iconView setAllowsCutCopyPaste:NO];
105     [ourContentView addSubview:_iconView];
106 }
107
108 - setDialogTitle:(NSString *)title
109 {
110     [_titleField setStringValue:title];
111     [self setTitle:title];
112 }
113
114 - setDialogMessage:(NSString *)message
115 {
116     [_messageField setStringValue:message];
117 }
118
119 - setCancelButtonLabel:(NSString *)cancelLabel
120 {
121     [_cancelButton setTitle:cancelLabel];
122 }
123
124 - setProgressAsDouble:(double)value
125 {
126     [_progressBar setDoubleValue:value];
127 }
128
129 - (BOOL)isCancelled
130 {
131     return _isCancelled;
132 }
133
134 - (IBAction)cancelDialog:(id)sender
135 {
136     _isCancelled = YES;
137 }
138
139 @end