Run password dialog as a modal sheet and set window title to server:port

This commit is contained in:
Robert Corrigan 2016-10-14 18:24:14 -04:00
parent f5a6645832
commit 91e6255015
5 changed files with 202 additions and 1030 deletions

View File

@ -965,9 +965,13 @@ BOOL mac_post_connect(freerdp* instance)
BOOL mac_authenticate(freerdp* instance, char** username, char** password,
char** domain)
{
mfContext* mfc = (mfContext*) instance->context;
MRDPView* view = (MRDPView*) mfc->view;
PasswordDialog* dialog = [PasswordDialog new];
dialog.serverHostname = [NSString stringWithCString:
instance->settings->ServerHostname encoding:NSUTF8StringEncoding];
dialog.serverHostname = [NSString stringWithFormat:@"%@:%u",
[NSString stringWithCString:instance->settings->ServerHostname encoding:NSUTF8StringEncoding],
instance->settings->ServerPort];
if (*username)
dialog.username = [NSString stringWithCString:*username encoding:
@ -977,7 +981,11 @@ BOOL mac_authenticate(freerdp* instance, char** username, char** password,
dialog.password = [NSString stringWithCString:*password encoding:
NSUTF8StringEncoding];
[dialog performSelectorOnMainThread:@selector(runModal) withObject:nil waitUntilDone:TRUE];
if (*domain)
dialog.domain = [NSString stringWithCString:*domain encoding:
NSUTF8StringEncoding];
[dialog performSelectorOnMainThread:@selector(runModal:) withObject:[view window] waitUntilDone:TRUE];
BOOL ok = dialog.modalCode;
@ -987,10 +995,16 @@ BOOL mac_authenticate(freerdp* instance, char** username, char** password,
NSUTF8StringEncoding];
*username = malloc((strlen(submittedUsername) + 1) * sizeof(char));
strcpy(*username, submittedUsername);
const char* submittedPassword = [dialog.password cStringUsingEncoding:
NSUTF8StringEncoding];
*password = malloc((strlen(submittedPassword) + 1) * sizeof(char));
strcpy(*password, submittedPassword);
const char* submittedDomain = [dialog.domain cStringUsingEncoding:
NSUTF8StringEncoding];
*domain = malloc((strlen(submittedDomain) + 1) * sizeof(char));
strcpy(*domain, submittedDomain);
}
return ok;

View File

@ -28,6 +28,7 @@
NSString* serverHostname;
NSString* username;
NSString* password;
NSString* domain;
BOOL modalCode;
}
@property (retain) IBOutlet NSTextField* usernameText;
@ -40,8 +41,9 @@
@property (retain) NSString* serverHostname;
@property (retain) NSString* username;
@property (retain) NSString* password;
@property BOOL modalCode;
@property (retain) NSString* domain;
@property (readonly) BOOL modalCode;
- (BOOL) runModal;
- (BOOL) runModal:(NSWindow*)mainWindow;
@end

View File

@ -18,9 +18,12 @@
*/
#import "PasswordDialog.h"
#import <freerdp/client/cmdline.h>
@interface PasswordDialog ()
@property BOOL modalCode;
@end
@implementation PasswordDialog
@ -31,6 +34,7 @@
@synthesize serverHostname;
@synthesize username;
@synthesize password;
@synthesize domain;
@synthesize modalCode;
- (id)init
@ -44,30 +48,66 @@
// 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];
[messageLabel setStringValue:[NSString stringWithFormat:@"Authenticate to %@", self.serverHostname]];
NSMutableString* domainUser = [[NSMutableString alloc] initWithString:@""];
if (self.domain != nil && [[self.domain stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] > 0)
{
[domainUser appendFormat:@"%@\\", self.domain];
}
if (self.username != nil)
{
[usernameText setStringValue:self.username];
[domainUser appendString:self.username];
[self.window makeFirstResponder:passwordText];
}
[usernameText setStringValue:domainUser];
}
- (IBAction)onOK:(NSObject *)sender
{
self.username = self.usernameText.stringValue;
char *submittedUser = NULL;
char *submittedDomain = NULL;
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 {
self.username = self.usernameText.stringValue;
}
self.password = self.passwordText.stringValue;
[self.window orderOut:nil];
[NSApp stopModalWithCode:TRUE];
}
- (IBAction)onCancel:(NSObject *)sender
{
[self.window orderOut:nil];
[NSApp stopModalWithCode:FALSE];
}
- (BOOL)runModal
- (BOOL)runModal:(NSWindow*)mainWindow
{
return (self.modalCode = [NSApp runModalForWindow:self.window]);
if ([mainWindow respondsToSelector:@selector(beginSheet:completionHandler:)]) {
[mainWindow beginSheet:self.window completionHandler:nil];
self.modalCode = [NSApp runModalForWindow: self.window];
[mainWindow endSheet: self.window];
} else {
[NSApp beginSheet: self.window
modalForWindow: mainWindow
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
self.modalCode = [NSApp runModalForWindow: self.window];
[NSApp endSheet: self.window];
}
[self.window orderOut:nil];
return self.modalCode;
}
- (void)dealloc
@ -78,6 +118,7 @@
[serverHostname release];
[username release];
[password release];
[domain release];
[super dealloc];
}

File diff suppressed because it is too large Load Diff

View File

@ -77,7 +77,9 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
}
else
{
winTitle = [[NSString alloc] initWithCString:"FreeRDP"];
winTitle = [[NSString alloc] initWithFormat:@"%@:%u",
[NSString stringWithCString:mfc->context.settings->ServerHostname encoding:NSUTF8StringEncoding],
mfc->context.settings->ServerPort];
}
[window setTitle:winTitle];