2013-03-11 22:59:50 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* MacFreeRDP
|
|
|
|
*
|
|
|
|
* Copyright 2013 Christian Hofstaedtler
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2013-03-11 05:25:14 +04:00
|
|
|
|
|
|
|
#import "PasswordDialog.h"
|
2016-10-15 01:24:14 +03:00
|
|
|
#import <freerdp/client/cmdline.h>
|
2013-03-11 05:25:14 +04:00
|
|
|
|
2018-11-29 17:46:37 +03:00
|
|
|
#import <CoreGraphics/CoreGraphics.h>
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
@interface PasswordDialog ()
|
2013-03-11 05:25:14 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
@property BOOL modalCode;
|
2016-10-15 01:24:14 +03:00
|
|
|
|
2013-03-11 05:25:14 +04:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PasswordDialog
|
|
|
|
|
2013-03-11 22:59:50 +04:00
|
|
|
@synthesize usernameText;
|
2013-03-11 05:25:14 +04:00
|
|
|
@synthesize passwordText;
|
|
|
|
@synthesize messageLabel;
|
2013-03-11 22:59:50 +04:00
|
|
|
@synthesize serverHostname;
|
|
|
|
@synthesize username;
|
2013-03-11 05:25:14 +04:00
|
|
|
@synthesize password;
|
2016-10-15 01:24:14 +03:00
|
|
|
@synthesize domain;
|
2016-10-08 08:39:07 +03:00
|
|
|
@synthesize modalCode;
|
2013-03-11 05:25:14 +04:00
|
|
|
|
2013-03-11 22:59:50 +04:00
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
return [self initWithWindowNibName:@"PasswordDialog"];
|
2013-03-11 05:25:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidLoad
|
|
|
|
{
|
2013-03-11 22:59:50 +04:00
|
|
|
[super windowDidLoad];
|
2019-11-06 17:24:51 +03:00
|
|
|
// Implement this method to handle any initialization after your window controller's window has
|
|
|
|
// been loaded from its nib file.
|
2013-03-11 22:59:50 +04:00
|
|
|
[self.window setTitle:self.serverHostname];
|
2019-11-06 17:24:51 +03:00
|
|
|
[self.messageLabel
|
|
|
|
setStringValue:[NSString stringWithFormat:@"Authenticate to %@", self.serverHostname]];
|
|
|
|
NSMutableString *domainUser = [[NSMutableString alloc] initWithString:@""];
|
2016-10-15 01:24:14 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (self.domain != nil &&
|
|
|
|
[[self.domain stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
|
|
|
|
length] > 0)
|
2016-10-15 01:24:14 +03:00
|
|
|
{
|
|
|
|
[domainUser appendFormat:@"%@\\", self.domain];
|
|
|
|
}
|
|
|
|
|
2013-03-11 22:59:50 +04:00
|
|
|
if (self.username != nil)
|
|
|
|
{
|
2016-10-15 01:24:14 +03:00
|
|
|
[domainUser appendString:self.username];
|
2018-11-29 19:23:09 +03:00
|
|
|
[self.window makeFirstResponder:self.passwordText];
|
2013-03-11 22:59:50 +04:00
|
|
|
}
|
2016-10-20 18:22:08 +03:00
|
|
|
|
2018-11-29 19:23:09 +03:00
|
|
|
[self.usernameText setStringValue:domainUser];
|
2013-03-11 05:25:14 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
- (IBAction)onOK:(NSObject *)sender
|
2013-03-11 22:59:50 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
char *submittedUser = NULL;
|
|
|
|
char *submittedDomain = NULL;
|
2016-10-15 01:24:14 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (freerdp_parse_username(
|
|
|
|
[self.usernameText.stringValue cStringUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
&submittedUser, &submittedDomain))
|
2016-10-20 18:22:08 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
self.username = [NSString stringWithCString:submittedUser encoding:NSUTF8StringEncoding];
|
|
|
|
self.domain = [NSString stringWithCString:submittedDomain encoding:NSUTF8StringEncoding];
|
2016-10-20 18:22:08 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-15 01:24:14 +03:00
|
|
|
self.username = self.usernameText.stringValue;
|
|
|
|
}
|
|
|
|
|
2013-03-11 22:59:50 +04:00
|
|
|
self.password = self.passwordText.stringValue;
|
|
|
|
[NSApp stopModalWithCode:TRUE];
|
2013-03-11 05:25:14 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
- (IBAction)onCancel:(NSObject *)sender
|
2013-03-11 22:59:50 +04:00
|
|
|
{
|
|
|
|
[NSApp stopModalWithCode:FALSE];
|
2013-03-11 05:25:14 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
- (BOOL)runModal:(NSWindow *)mainWindow
|
2013-03-11 22:59:50 +04:00
|
|
|
{
|
2016-10-20 18:22:08 +03:00
|
|
|
if ([mainWindow respondsToSelector:@selector(beginSheet:completionHandler:)])
|
|
|
|
{
|
2016-10-15 01:24:14 +03:00
|
|
|
[mainWindow beginSheet:self.window completionHandler:nil];
|
2019-11-06 17:24:51 +03:00
|
|
|
self.modalCode = [NSApp runModalForWindow:self.window];
|
|
|
|
[mainWindow endSheet:self.window];
|
2016-10-20 18:22:08 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
[NSApp beginSheet:self.window
|
|
|
|
modalForWindow:mainWindow
|
|
|
|
modalDelegate:nil
|
|
|
|
didEndSelector:nil
|
|
|
|
contextInfo:nil];
|
|
|
|
self.modalCode = [NSApp runModalForWindow:self.window];
|
|
|
|
[NSApp endSheet:self.window];
|
2016-10-15 01:24:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[self.window orderOut:nil];
|
|
|
|
return self.modalCode;
|
2013-03-11 05:25:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 23:35:43 +04:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[usernameText release];
|
|
|
|
[passwordText release];
|
|
|
|
[messageLabel release];
|
|
|
|
[serverHostname release];
|
|
|
|
[username release];
|
|
|
|
[password release];
|
2016-10-15 01:24:14 +03:00
|
|
|
[domain release];
|
2013-03-11 23:35:43 +04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2013-03-11 05:25:14 +04:00
|
|
|
@end
|