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
|
|
|
|
2016-10-20 18:22:08 +03:00
|
|
|
@interface PasswordDialog()
|
2013-03-11 05:25:14 +04:00
|
|
|
|
2016-10-20 18:22:08 +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];
|
|
|
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
|
|
|
[self.window setTitle:self.serverHostname];
|
2016-10-20 18:22:08 +03:00
|
|
|
[messageLabel setStringValue:[NSString stringWithFormat:@"Authenticate to %@",
|
|
|
|
self.serverHostname]];
|
2016-10-15 01:24:14 +03:00
|
|
|
NSMutableString* domainUser = [[NSMutableString alloc] initWithString:@""];
|
|
|
|
|
2016-10-20 18:22:08 +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];
|
2013-03-11 22:59:50 +04:00
|
|
|
[self.window makeFirstResponder:passwordText];
|
|
|
|
}
|
2016-10-20 18:22:08 +03:00
|
|
|
|
2016-10-15 01:24:14 +03:00
|
|
|
[usernameText setStringValue:domainUser];
|
2013-03-11 05:25:14 +04:00
|
|
|
}
|
|
|
|
|
2016-10-20 18:22:08 +03:00
|
|
|
- (IBAction)onOK:(NSObject*)sender
|
2013-03-11 22:59:50 +04:00
|
|
|
{
|
2016-10-20 18:22:08 +03:00
|
|
|
char* submittedUser = NULL;
|
|
|
|
char* submittedDomain = NULL;
|
2016-10-15 01:24:14 +03:00
|
|
|
|
2016-10-20 18:22:08 +03:00
|
|
|
if (freerdp_parse_username([self.usernameText.stringValue cStringUsingEncoding:
|
|
|
|
NSUTF8StringEncoding], &submittedUser, &submittedDomain))
|
|
|
|
{
|
|
|
|
self.username = [NSString stringWithCString: submittedUser encoding:
|
|
|
|
NSUTF8StringEncoding];
|
|
|
|
self.domain = [NSString stringWithCString: submittedDomain encoding:
|
|
|
|
NSUTF8StringEncoding];
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-20 18:22:08 +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
|
|
|
}
|
|
|
|
|
2016-10-15 01:24:14 +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];
|
|
|
|
self.modalCode = [NSApp runModalForWindow: self.window];
|
|
|
|
[mainWindow endSheet: self.window];
|
2016-10-20 18:22:08 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-15 01:24:14 +03:00
|
|
|
[NSApp beginSheet: self.window
|
2016-10-20 18:22:08 +03:00
|
|
|
modalForWindow: mainWindow
|
|
|
|
modalDelegate: nil
|
|
|
|
didEndSelector: nil
|
|
|
|
contextInfo: nil];
|
2016-10-15 01:24:14 +03:00
|
|
|
self.modalCode = [NSApp runModalForWindow: self.window];
|
|
|
|
[NSApp endSheet: self.window];
|
|
|
|
}
|
|
|
|
|
|
|
|
[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
|