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, BOOL mac_authenticate(freerdp* instance, char** username, char** password,
char** domain) char** domain)
{ {
mfContext* mfc = (mfContext*) instance->context;
MRDPView* view = (MRDPView*) mfc->view;
PasswordDialog* dialog = [PasswordDialog new]; PasswordDialog* dialog = [PasswordDialog new];
dialog.serverHostname = [NSString stringWithCString: dialog.serverHostname = [NSString stringWithFormat:@"%@:%u",
instance->settings->ServerHostname encoding:NSUTF8StringEncoding]; [NSString stringWithCString:instance->settings->ServerHostname encoding:NSUTF8StringEncoding],
instance->settings->ServerPort];
if (*username) if (*username)
dialog.username = [NSString stringWithCString:*username encoding: 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: dialog.password = [NSString stringWithCString:*password encoding:
NSUTF8StringEncoding]; 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; BOOL ok = dialog.modalCode;
@ -987,10 +995,16 @@ BOOL mac_authenticate(freerdp* instance, char** username, char** password,
NSUTF8StringEncoding]; NSUTF8StringEncoding];
*username = malloc((strlen(submittedUsername) + 1) * sizeof(char)); *username = malloc((strlen(submittedUsername) + 1) * sizeof(char));
strcpy(*username, submittedUsername); strcpy(*username, submittedUsername);
const char* submittedPassword = [dialog.password cStringUsingEncoding: const char* submittedPassword = [dialog.password cStringUsingEncoding:
NSUTF8StringEncoding]; NSUTF8StringEncoding];
*password = malloc((strlen(submittedPassword) + 1) * sizeof(char)); *password = malloc((strlen(submittedPassword) + 1) * sizeof(char));
strcpy(*password, submittedPassword); strcpy(*password, submittedPassword);
const char* submittedDomain = [dialog.domain cStringUsingEncoding:
NSUTF8StringEncoding];
*domain = malloc((strlen(submittedDomain) + 1) * sizeof(char));
strcpy(*domain, submittedDomain);
} }
return ok; return ok;

View File

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

View File

@ -18,9 +18,12 @@
*/ */
#import "PasswordDialog.h" #import "PasswordDialog.h"
#import <freerdp/client/cmdline.h>
@interface PasswordDialog () @interface PasswordDialog ()
@property BOOL modalCode;
@end @end
@implementation PasswordDialog @implementation PasswordDialog
@ -31,6 +34,7 @@
@synthesize serverHostname; @synthesize serverHostname;
@synthesize username; @synthesize username;
@synthesize password; @synthesize password;
@synthesize domain;
@synthesize modalCode; @synthesize modalCode;
- (id)init - (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. // 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]; [self.window setTitle:self.serverHostname];
[messageLabel setStringValue:[NSString stringWithFormat:@"Authenticate to %@", 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) if (self.username != nil)
{ {
[usernameText setStringValue:self.username]; [domainUser appendString:self.username];
[self.window makeFirstResponder:passwordText]; [self.window makeFirstResponder:passwordText];
} }
[usernameText setStringValue:domainUser];
} }
- (IBAction)onOK:(NSObject *)sender - (IBAction)onOK:(NSObject *)sender
{ {
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.username = self.usernameText.stringValue;
}
self.password = self.passwordText.stringValue; self.password = self.passwordText.stringValue;
[self.window orderOut:nil];
[NSApp stopModalWithCode:TRUE]; [NSApp stopModalWithCode:TRUE];
} }
- (IBAction)onCancel:(NSObject *)sender - (IBAction)onCancel:(NSObject *)sender
{ {
[self.window orderOut:nil];
[NSApp stopModalWithCode:FALSE]; [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 - (void)dealloc
@ -78,6 +118,7 @@
[serverHostname release]; [serverHostname release];
[username release]; [username release];
[password release]; [password release];
[domain release];
[super dealloc]; [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 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]; [window setTitle:winTitle];