1 /*****************************************************************************
2 * VLCLoginPanel.m: A Generic Login Panel created for VLC
3 *****************************************************************************
4 * Copyright (C) 2009-2010 the VideoLAN team
7 * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
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.
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.
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 *****************************************************************************/
24 #import "VLCLoginPanel.h"
27 @implementation VLCLoginPanel
32 windowRect.size.height = 278;
33 windowRect.size.width = 505;
34 windowRect.origin.x = windowRect.origin.y = 0;
36 return [super initWithContentRect:windowRect
37 styleMask:NSTitledWindowMask
38 backing:NSBackingStoreBuffered
42 #define addButton( theButton, ox, oy, title, action ) \
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]
55 - (void)createContentView
57 NSRect s_rc = [self frame];
58 id ourContentView = [self contentView];
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];
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];
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];
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];
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];
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];
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];
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];
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];
166 - (IBAction)buttonAction:(id)sender
168 if (sender == _okayButton)
169 [NSApp stopModalWithCode: 1];
171 [NSApp stopModalWithCode: 0];
174 - (void)setDialogTitle:(NSString *)title
176 [_titleField setStringValue:title];
177 [self setTitle:title];
179 - (void)setDialogMessage:(NSString *)message
181 [_informativeTextField setStringValue:message];
184 - (NSString *)userName
186 return [_userNameField stringValue];
189 - (NSString *)password
191 return [_passwordField stringValue];