Merge pull request #3572 from rjcorrig/maclogin

client/mac: Run password dialog as a modal sheet and set window title to server:port
This commit is contained in:
akallabeth 2016-11-10 08:56:34 +01:00 committed by GitHub
commit f910bbe7b4
5 changed files with 282 additions and 1118 deletions

View File

@ -194,7 +194,7 @@ DWORD mac_client_thread(void* param)
if (settings->AsyncInput)
{
if (!(inputThread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL)))
(LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL)))
{
WLog_ERR(TAG, "failed to create async input thread");
goto disconnect;
@ -203,7 +203,7 @@ DWORD mac_client_thread(void* param)
else
{
if (!(inputEvent = freerdp_get_message_queue_event_handle(instance,
FREERDP_INPUT_MESSAGE_QUEUE)))
FREERDP_INPUT_MESSAGE_QUEUE)))
{
WLog_ERR(TAG, "failed to get input event handle");
goto disconnect;
@ -221,7 +221,7 @@ DWORD mac_client_thread(void* param)
if (!settings->AsyncTransport)
{
if (!(nCountTmp = freerdp_get_event_handles(context, &events[nCount],
16 - nCount)))
16 - nCount)))
{
WLog_ERR(TAG, "freerdp_get_event_handles failed");
break;
@ -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,11 +981,15 @@ 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;
if (ok)
if (ok)
{
const char* submittedUsername = [dialog.username cStringUsingEncoding:
NSUTF8StringEncoding];
@ -991,6 +999,10 @@ BOOL mac_authenticate(freerdp* instance, char** username, char** password,
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

@ -22,26 +22,28 @@
@interface PasswordDialog : NSWindowController
{
@public
NSTextField* usernameText;
NSTextField* passwordText;
NSTextField* messageLabel;
NSString* serverHostname;
NSString* username;
NSString* password;
BOOL modalCode;
NSTextField* usernameText;
NSTextField* passwordText;
NSTextField* messageLabel;
NSString* serverHostname;
NSString* username;
NSString* password;
NSString* domain;
BOOL modalCode;
}
@property (retain) IBOutlet NSTextField* usernameText;
@property (retain) IBOutlet NSTextField* passwordText;
@property (retain) IBOutlet NSTextField* messageLabel;
@property(retain) IBOutlet NSTextField* usernameText;
@property(retain) IBOutlet NSTextField* passwordText;
@property(retain) IBOutlet NSTextField* messageLabel;
- (IBAction)onOK:(NSObject*)sender;
- (IBAction)onCancel:(NSObject*)sender;
@property (retain) NSString* serverHostname;
@property (retain) NSString* username;
@property (retain) NSString* password;
@property BOOL modalCode;
@property(retain) NSString* serverHostname;
@property(retain) NSString* username;
@property(retain) NSString* password;
@property(retain) NSString* domain;
@property(readonly) BOOL modalCode;
- (BOOL) runModal;
- (BOOL) runModal:(NSWindow*)mainWindow;
@end

View File

@ -18,8 +18,11 @@
*/
#import "PasswordDialog.h"
#import <freerdp/client/cmdline.h>
@interface PasswordDialog ()
@interface PasswordDialog()
@property BOOL modalCode;
@end
@ -31,6 +34,7 @@
@synthesize serverHostname;
@synthesize username;
@synthesize password;
@synthesize domain;
@synthesize modalCode;
- (id)init
@ -43,31 +47,74 @@
[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];
[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)
{
[usernameText setStringValue:self.username];
[domainUser appendString:self.username];
[self.window makeFirstResponder:passwordText];
}
[usernameText setStringValue:domainUser];
}
- (IBAction)onOK:(NSObject *)sender
- (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
- (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,7 +125,7 @@
[serverHostname release];
[username release];
[password release];
[domain release];
[super dealloc];
}

File diff suppressed because it is too large Load Diff

View File

@ -13,10 +13,13 @@
#import <freerdp/client/cmdline.h>
static AppDelegate* _singleDelegate = nil;
void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEventArgs* e);
void AppDelegate_ConnectionResultEventHandler(void* context,
ConnectionResultEventArgs* e);
void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e);
void AppDelegate_EmbedWindowEventHandler(void* context, EmbedWindowEventArgs* e);
void AppDelegate_ResizeWindowEventHandler(void* context, ResizeWindowEventArgs* e);
void AppDelegate_EmbedWindowEventHandler(void* context,
EmbedWindowEventArgs* e);
void AppDelegate_ResizeWindowEventHandler(void* context,
ResizeWindowEventArgs* e);
void mac_set_view_size(rdpContext* context, MRDPView* view);
@implementation AppDelegate
@ -35,22 +38,17 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
{
int status;
mfContext* mfc;
_singleDelegate = self;
[self CreateContext];
status = [self ParseCommandLineArguments];
mfc = (mfContext*) context;
mfc->view = (void*) mrdpView;
if (status < 0)
{
NSString *winTitle;
NSString* winTitle;
winTitle = [[NSString alloc] initWithCString:"ERROR"];
[window setTitle:winTitle];
}
else
{
@ -63,21 +61,27 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
context->instance->settings->DesktopHeight = screenFrame.size.height;
}
PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler);
PubSub_SubscribeConnectionResult(context->pubSub,
AppDelegate_ConnectionResultEventHandler);
PubSub_SubscribeErrorInfo(context->pubSub, AppDelegate_ErrorInfoEventHandler);
PubSub_SubscribeEmbedWindow(context->pubSub, AppDelegate_EmbedWindowEventHandler);
PubSub_SubscribeResizeWindow(context->pubSub, AppDelegate_ResizeWindowEventHandler);
PubSub_SubscribeEmbedWindow(context->pubSub,
AppDelegate_EmbedWindowEventHandler);
PubSub_SubscribeResizeWindow(context->pubSub,
AppDelegate_ResizeWindowEventHandler);
freerdp_client_start(context);
NSString* winTitle;
NSString *winTitle;
if ( mfc->context.settings->WindowTitle && mfc->context.settings->WindowTitle[0])
if (mfc->context.settings->WindowTitle && mfc->context.settings->WindowTitle[0])
{
winTitle = [[NSString alloc] initWithCString:mfc->context.settings->WindowTitle];
winTitle = [[NSString alloc] initWithCString:
mfc->context.settings->WindowTitle];
}
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];
@ -88,14 +92,12 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
{
NSLog(@"Stopping...\n");
freerdp_client_stop(context);
[mrdpView releaseResources];
_singleDelegate = nil;
NSLog(@"Stopped.\n");
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender
{
return YES;
}
@ -106,49 +108,41 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
int length;
int status;
char* cptr;
NSArray* args = [[NSProcessInfo processInfo] arguments];
context->argc = (int) [args count];
context->argv = malloc(sizeof(char*) * context->argc);
i = 0;
for (NSString* str in args)
for (NSString * str in args)
{
/* filter out some arguments added by XCode */
if ([str isEqualToString:@"YES"])
continue;
if ([str isEqualToString:@"-NSDocumentRevisionsDebugMode"])
continue;
length = (int) ([str length] + 1);
length = (int)([str length] + 1);
cptr = (char*) malloc(length);
strcpy(cptr, [str UTF8String]);
context->argv[i++] = cptr;
}
context->argc = i;
status = freerdp_client_settings_parse_command_line(context->settings, context->argc, context->argv, FALSE);
status = freerdp_client_settings_command_line_status_print(context->settings, status, context->argc, context->argv);
context->argc = i;
status = freerdp_client_settings_parse_command_line(context->settings,
context->argc, context->argv, FALSE);
status = freerdp_client_settings_command_line_status_print(context->settings,
status, context->argc, context->argv);
return status;
}
- (void) CreateContext
{
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
ZeroMemory(&clientEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
clientEntryPoints.Size = sizeof(RDP_CLIENT_ENTRY_POINTS);
clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION;
RdpClientEntry(&clientEntryPoints);
context = freerdp_client_context_new(&clientEntryPoints);
}
@ -156,15 +150,12 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
{
mfContext* mfc;
MRDPView* view;
mfc = (mfContext*) context;
view = (MRDPView*) mfc->view;
[view exitFullScreenModeWithOptions:nil];
[view releaseResources];
[view release];
mfc->view = nil;
mfc->view = nil;
freerdp_client_context_free(context);
context = nil;
}
@ -178,20 +169,16 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
{
mfContext* mfc;
MRDPView* view;
mfc = (mfContext*) context;
view = (MRDPView*) mfc->view;
[view exitFullScreenModeWithOptions:nil];
NSString* message = withMessage ? withMessage : @"Error connecting to server";
NSAlert *alert = [[NSAlert alloc] init];
NSAlert* alert = [[NSAlert alloc] init];
[alert setMessageText:message];
[alert beginSheetModalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
@ -199,7 +186,7 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
* just a terminate selector for above call
***********************************************************************/
- (void) alertDidEnd:(NSAlert *)a returnCode:(NSInteger)rc contextInfo:(void *)ci
- (void) alertDidEnd:(NSAlert*)a returnCode:(NSInteger)rc contextInfo:(void*)ci
{
[NSApp terminate:nil];
}
@ -211,22 +198,26 @@ void mac_set_view_size(rdpContext* context, MRDPView* view);
* On connection error, display message and quit application
***********************************************************************/
void AppDelegate_ConnectionResultEventHandler(void* ctx, ConnectionResultEventArgs* e)
void AppDelegate_ConnectionResultEventHandler(void* ctx,
ConnectionResultEventArgs* e)
{
NSLog(@"ConnectionResult event result:%d\n", e->result);
if (_singleDelegate)
{
if (e->result != 0)
{
NSString* message = nil;
if (connectErrorCode == AUTHENTICATIONERROR)
{
message = [NSString stringWithFormat:@"%@", @"Authentication failure, check credentials."];
message = [NSString stringWithFormat:@"%@",
@"Authentication failure, check credentials."];
}
// Making sure this should be invoked on the main UI thread.
[_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:) withObject:message waitUntilDone:FALSE];
[_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:)
withObject:message waitUntilDone:FALSE];
}
}
}
@ -234,18 +225,21 @@ void AppDelegate_ConnectionResultEventHandler(void* ctx, ConnectionResultEventAr
void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e)
{
NSLog(@"ErrorInfo event code:%d\n", e->code);
if (_singleDelegate)
{
// Retrieve error message associated with error code
NSString* message = nil;
if (e->code != ERRINFO_NONE)
{
const char* errorMessage = freerdp_get_error_info_string(e->code);
message = [[NSString alloc] initWithUTF8String:errorMessage];
}
// Making sure this should be invoked on the main UI thread.
[_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:) withObject:message waitUntilDone:TRUE];
[_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:)
withObject:message waitUntilDone:TRUE];
[message release];
}
}
@ -253,17 +247,17 @@ void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e)
void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e)
{
rdpContext* context = (rdpContext*) ctx;
if (_singleDelegate)
{
mfContext* mfc = (mfContext*) context;
_singleDelegate->mrdpView = mfc->view;
if (_singleDelegate->window)
{
[[_singleDelegate->window contentView] addSubview:mfc->view];
}
mac_set_view_size(context, mfc->view);
}
}
@ -271,9 +265,8 @@ void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e)
void AppDelegate_ResizeWindowEventHandler(void* ctx, ResizeWindowEventArgs* e)
{
rdpContext* context = (rdpContext*) ctx;
fprintf(stderr, "ResizeWindowEventHandler: %d %d\n", e->width, e->height);
if (_singleDelegate)
{
mfContext* mfc = (mfContext*) context;
@ -290,17 +283,14 @@ void mac_set_view_size(rdpContext* context, MRDPView* view)
innerRect.size.width = context->settings->DesktopWidth;
innerRect.size.height = context->settings->DesktopHeight;
[view setFrame:innerRect];
// calculate window of same size, but keep position
NSRect outerRect = [[view window] frame];
outerRect.size = [[view window] frameRectForContentRect:innerRect].size;
// we are not in RemoteApp mode, disable larger than resolution
[[view window] setContentMaxSize:innerRect.size];
// set window to given area
[[view window] setFrame:outerRect display:YES];
if (context->settings->Fullscreen)
[[view window] toggleFullScreen:nil];
}