VLCLoginPanel.m 6.08 KB
Newer Older
1 2 3
/*****************************************************************************
 * VLCLoginPanel.m: A Generic Login Panel created for VLC
 *****************************************************************************
4
 * Copyright (C) 2009-2010 VLC authors and VideoLAN
5 6 7 8
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
 *
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
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
 *****************************************************************************/

#import "VLCLoginPanel.h"


@implementation VLCLoginPanel

- (id)init
{
    NSRect windowRect;
    windowRect.size.height = 278;
    windowRect.size.width = 505;
    windowRect.origin.x = windowRect.origin.y = 0;

    return [super initWithContentRect:windowRect
                            styleMask:NSTitledWindowMask
                              backing:NSBackingStoreBuffered
                                defer:YES];
}

- (void)createContentView
{
    NSRect s_rc = [self frame];
    id ourContentView = [self contentView];

    s_rc.origin.x = 275;
    s_rc.origin.y = 44;
    s_rc.size.height = 32;
    s_rc.size.width = 108;
    _cancelButton = [[NSButton alloc] initWithFrame:s_rc];
    [_cancelButton setButtonType:NSMomentaryLightButton];
    [_cancelButton setTitle:@"Cancel"];
    [_cancelButton setBezelStyle:NSRoundedBezelStyle];
    [_cancelButton setBordered:YES];
    [_cancelButton setTarget:self];
    [_cancelButton setAction:@selector(buttonAction:)];
58
    [_cancelButton setKeyEquivalent:@"\e"] ; // escape key
59 60 61 62 63 64 65 66 67 68 69 70 71
    [ourContentView addSubview:_cancelButton];

    s_rc.origin.x = 383;
    s_rc.origin.y = 44;
    s_rc.size.height = 32;
    s_rc.size.width = 108;
    _okayButton = [[NSButton alloc] initWithFrame:s_rc];
    [_okayButton setButtonType:NSMomentaryLightButton];
    [_okayButton setTitle:@"OK"];
    [_okayButton setBezelStyle:NSRoundedBezelStyle];
    [_okayButton setBordered:YES];
    [_okayButton setTarget:self];
    [_okayButton setAction:@selector(buttonAction:)];
72
    [_okayButton setKeyEquivalent:@"\r"] ; // enter key
73
    [ourContentView addSubview:_okayButton];
74

75 76 77 78 79 80
    s_rc.origin.x = 94;
    s_rc.origin.y = 170;
    s_rc.size.height = 14;
    s_rc.size.width = 129;
    _userNameLabel = [[NSTextField alloc] initWithFrame:s_rc];
    [_userNameLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
81
    [_userNameLabel setStringValue:@"Username"];
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
    [_userNameLabel setBezeled:NO];
    [_userNameLabel setEditable:NO];
    [_userNameLabel setSelectable:NO];
    [_userNameLabel setDrawsBackground:NO];
    [ourContentView addSubview:_userNameLabel];

    s_rc.origin.x = 97;
    s_rc.origin.y = 148;
    s_rc.size.height = 22;
    s_rc.size.width = 310;
    _userNameField = [[NSTextField alloc] initWithFrame:s_rc];
    [_userNameField setBezeled:YES];
    [_userNameField setEditable:YES];
    [_userNameField setImportsGraphics:NO];
    [ourContentView addSubview:_userNameField];

    s_rc.origin.x = 94;
    s_rc.origin.y = 116;
    s_rc.size.height = 14;
    s_rc.size.width = 129;
    _passwordLabel = [[NSTextField alloc] initWithFrame:s_rc];
    [_passwordLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
    [_passwordLabel setStringValue:@"Password"];
    [_passwordLabel setBezeled:NO];
    [_passwordLabel setEditable:NO];
    [_passwordLabel setSelectable:NO];
    [_passwordLabel setDrawsBackground:NO];
    [ourContentView addSubview:_passwordLabel];

    s_rc.origin.x = 97;
    s_rc.origin.y = 94;
    s_rc.size.height = 22;
    s_rc.size.width = 310;
    _passwordField = [[NSSecureTextField alloc] initWithFrame:s_rc];
    [_passwordField setBezeled:YES];
    [_passwordField setEditable:YES];
    [_passwordField setImportsGraphics:NO];
    [ourContentView addSubview:_passwordField];
120

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    s_rc.origin.x = 94;
    s_rc.origin.y = 238;
    s_rc.size.height = 17;
    s_rc.size.width = 316;
    _titleField = [[NSTextField alloc] initWithFrame:s_rc];
    [_titleField setFont:[NSFont boldSystemFontOfSize:0]];
    [_titleField setBezeled:NO];
    [_titleField setEditable:NO];
    [_titleField setSelectable:YES];
    [_titleField setDrawsBackground:NO];
    [ourContentView addSubview:_titleField];

    s_rc.origin.x = 94;
    s_rc.origin.y = 183;
    s_rc.size.height = 44;
    s_rc.size.width = 394;
    _informativeTextField = [[NSTextField alloc] initWithFrame:s_rc];
    [_informativeTextField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
    [_informativeTextField setBezeled:NO];
    [_informativeTextField setEditable:NO];
    [_informativeTextField setSelectable:YES];
    [_informativeTextField setDrawsBackground:NO];
    [ourContentView addSubview:_informativeTextField];

    s_rc.origin.x = 20;
    s_rc.origin.y = 188;
    s_rc.size.height = s_rc.size.width = 64;
    _iconView = [[NSImageView alloc] initWithFrame:s_rc];
    [_iconView setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
    [_iconView setEditable:NO];
    [_iconView setAllowsCutCopyPaste:NO];
    [ourContentView addSubview:_iconView];
}

- (IBAction)buttonAction:(id)sender
{
    if (sender == _okayButton)
        [NSApp stopModalWithCode: 1];
    else
        [NSApp stopModalWithCode: 0];
}

- (void)setDialogTitle:(NSString *)title
{
    [_titleField setStringValue:title];
    [self setTitle:title];
}
- (void)setDialogMessage:(NSString *)message
{
    [_informativeTextField setStringValue:message];
}

- (NSString *)userName
{
    return [_userNameField stringValue];
}

- (NSString *)password
{
    return [_passwordField stringValue];
}

@end