]> git.sesse.net Git - vlc/blob - modules/gui/macosx_dialog_provider/VLCLoginPanel.m
81663f845285c487023231105c7420f9963af5e0
[vlc] / modules / gui / macosx_dialog_provider / VLCLoginPanel.m
1 /*****************************************************************************
2  * VLCLoginPanel.m: A Generic Login 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 "VLCLoginPanel.h"
25
26
27 @implementation VLCLoginPanel
28
29 - (id)init
30 {
31     NSRect windowRect;
32     windowRect.size.height = 278;
33     windowRect.size.width = 505;
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 #define addButton( theButton, ox, oy, title, action )           \
43 s_rc.origin.x = ox;                                             \
44 s_rc.origin.y = oy;                                             \
45 s_rc.size.height = 32;                                          \
46 s_rc.size.width = 108;                                          \
47 theButton = [[NSButton alloc] initWithFrame:s_rc];              \
48 [theButton setButtonType:NSMomentaryLightButton];               \
49 [theButton setTitle:title];                                     \
50 [theButton setBordered:NO];                                     \
51 [theButton setTarget:self];                                     \
52 [theButton setAction:@selector(action:)];                       \
53 [ourContentView addSubview:theButton]
54
55 - (void)createContentView
56 {
57     NSRect s_rc = [self frame];
58     id ourContentView = [self contentView];
59
60     s_rc.origin.x = 275;
61     s_rc.origin.y = 44;
62     s_rc.size.height = 32;
63     s_rc.size.width = 108;
64     _cancelButton = [[NSButton alloc] initWithFrame:s_rc];
65     [_cancelButton setButtonType:NSMomentaryLightButton];
66     [_cancelButton setTitle:@"Cancel"];
67     [_cancelButton setBezelStyle:NSRoundedBezelStyle];
68     [_cancelButton setBordered:YES];
69     [_cancelButton setTarget:self];
70     [_cancelButton setAction:@selector(buttonAction:)];
71     [ourContentView addSubview:_cancelButton];
72
73     s_rc.origin.x = 383;
74     s_rc.origin.y = 44;
75     s_rc.size.height = 32;
76     s_rc.size.width = 108;
77     _okayButton = [[NSButton alloc] initWithFrame:s_rc];
78     [_okayButton setButtonType:NSMomentaryLightButton];
79     [_okayButton setTitle:@"OK"];
80     [_okayButton setBezelStyle:NSRoundedBezelStyle];
81     [_okayButton setBordered:YES];
82     [_okayButton setTarget:self];
83     [_okayButton setAction:@selector(buttonAction:)];
84     [ourContentView addSubview:_okayButton];
85     
86     s_rc.origin.x = 94;
87     s_rc.origin.y = 170;
88     s_rc.size.height = 14;
89     s_rc.size.width = 129;
90     _userNameLabel = [[NSTextField alloc] initWithFrame:s_rc];
91     [_userNameLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
92     [_userNameLabel setStringValue:@"User Name"];
93     [_userNameLabel setBezeled:NO];
94     [_userNameLabel setEditable:NO];
95     [_userNameLabel setSelectable:NO];
96     [_userNameLabel setDrawsBackground:NO];
97     [ourContentView addSubview:_userNameLabel];
98
99     s_rc.origin.x = 97;
100     s_rc.origin.y = 148;
101     s_rc.size.height = 22;
102     s_rc.size.width = 310;
103     _userNameField = [[NSTextField alloc] initWithFrame:s_rc];
104     [_userNameField setBezeled:YES];
105     [_userNameField setEditable:YES];
106     [_userNameField setImportsGraphics:NO];
107     [ourContentView addSubview:_userNameField];
108
109     s_rc.origin.x = 94;
110     s_rc.origin.y = 116;
111     s_rc.size.height = 14;
112     s_rc.size.width = 129;
113     _passwordLabel = [[NSTextField alloc] initWithFrame:s_rc];
114     [_passwordLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
115     [_passwordLabel setStringValue:@"Password"];
116     [_passwordLabel setBezeled:NO];
117     [_passwordLabel setEditable:NO];
118     [_passwordLabel setSelectable:NO];
119     [_passwordLabel setDrawsBackground:NO];
120     [ourContentView addSubview:_passwordLabel];
121
122     s_rc.origin.x = 97;
123     s_rc.origin.y = 94;
124     s_rc.size.height = 22;
125     s_rc.size.width = 310;
126     _passwordField = [[NSSecureTextField alloc] initWithFrame:s_rc];
127     [_passwordField setBezeled:YES];
128     [_passwordField setEditable:YES];
129     [_passwordField setImportsGraphics:NO];
130     [ourContentView addSubview:_passwordField];
131     
132     s_rc.origin.x = 94;
133     s_rc.origin.y = 238;
134     s_rc.size.height = 17;
135     s_rc.size.width = 316;
136     _titleField = [[NSTextField alloc] initWithFrame:s_rc];
137     [_titleField setFont:[NSFont boldSystemFontOfSize:0]];
138     [_titleField setBezeled:NO];
139     [_titleField setEditable:NO];
140     [_titleField setSelectable:YES];
141     [_titleField setDrawsBackground:NO];
142     [ourContentView addSubview:_titleField];
143
144     s_rc.origin.x = 94;
145     s_rc.origin.y = 183;
146     s_rc.size.height = 44;
147     s_rc.size.width = 394;
148     _informativeTextField = [[NSTextField alloc] initWithFrame:s_rc];
149     [_informativeTextField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
150     [_informativeTextField setBezeled:NO];
151     [_informativeTextField setEditable:NO];
152     [_informativeTextField setSelectable:YES];
153     [_informativeTextField setDrawsBackground:NO];
154     [ourContentView addSubview:_informativeTextField];
155
156     s_rc.origin.x = 20;
157     s_rc.origin.y = 188;
158     s_rc.size.height = s_rc.size.width = 64;
159     _iconView = [[NSImageView alloc] initWithFrame:s_rc];
160     [_iconView setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
161     [_iconView setEditable:NO];
162     [_iconView setAllowsCutCopyPaste:NO];
163     [ourContentView addSubview:_iconView];
164 }
165
166 - (IBAction)buttonAction:(id)sender
167 {
168     if (sender == _okayButton)
169         [NSApp stopModalWithCode: 1];
170     else
171         [NSApp stopModalWithCode: 0];
172 }
173
174 - (void)setDialogTitle:(NSString *)title
175 {
176     [_titleField setStringValue:title];
177     [self setTitle:title];
178 }
179 - (void)setDialogMessage:(NSString *)message
180 {
181     [_informativeTextField setStringValue:message];
182 }
183
184 - (NSString *)userName
185 {
186     return [_userNameField stringValue];
187 }
188
189 - (NSString *)password
190 {
191     return [_passwordField stringValue];
192 }
193
194 @end