FreeRDP
PasswordDialog.m
1 
20 #import "PasswordDialog.h"
21 #import <freerdp/client/cmdline.h>
22 
23 #import <CoreGraphics/CoreGraphics.h>
24 
25 @interface PasswordDialog ()
26 
27 @property BOOL modalCode;
28 
29 @end
30 
31 @implementation PasswordDialog
32 
33 @synthesize usernameText;
34 @synthesize passwordText;
35 @synthesize messageLabel;
36 @synthesize serverHostname;
37 @synthesize username;
38 @synthesize password;
39 @synthesize domain;
40 @synthesize modalCode;
41 
42 - (id)init
43 {
44  return [self initWithWindowNibName:@"PasswordDialog"];
45 }
46 
47 - (void)windowDidLoad
48 {
49  [super windowDidLoad];
50  // Implement this method to handle any initialization after your window controller's window has
51  // been loaded from its nib file.
52  [self.window setTitle:self.serverHostname];
53  [self.messageLabel
54  setStringValue:[NSString stringWithFormat:@"Authenticate to %@", self.serverHostname]];
55  NSMutableString *domainUser = [[NSMutableString alloc] initWithString:@""];
56 
57  if (self.domain != nil &&
58  [[self.domain stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
59  length] > 0)
60  {
61  [domainUser appendFormat:@"%@\\", self.domain];
62  }
63 
64  if (self.username != nil)
65  {
66  [domainUser appendString:self.username];
67  [self.window makeFirstResponder:self.passwordText];
68  }
69 
70  [self.usernameText setStringValue:domainUser];
71 }
72 
73 - (IBAction)onOK:(NSObject *)sender
74 {
75  char *submittedUser = NULL;
76  char *submittedDomain = NULL;
77 
78  if (freerdp_parse_username(
79  [self.usernameText.stringValue cStringUsingEncoding:NSUTF8StringEncoding],
80  &submittedUser, &submittedDomain))
81  {
82  if (submittedUser)
83  self.username = [NSString stringWithCString:submittedUser
84  encoding:NSUTF8StringEncoding];
85  if (submittedDomain)
86  self.domain = [NSString stringWithCString:submittedDomain
87  encoding:NSUTF8StringEncoding];
88  }
89  else
90  {
91  self.username = self.usernameText.stringValue;
92  }
93 
94  self.password = self.passwordText.stringValue;
95  free(submittedUser);
96  free(submittedDomain);
97  [NSApp stopModalWithCode:TRUE];
98 }
99 
100 - (IBAction)onCancel:(NSObject *)sender
101 {
102  [NSApp stopModalWithCode:FALSE];
103 }
104 
105 - (BOOL)runModal:(NSWindow *)mainWindow
106 {
107  if ([mainWindow respondsToSelector:@selector(beginSheet:completionHandler:)])
108  {
109  [mainWindow beginSheet:self.window completionHandler:nil];
110  self.modalCode = [NSApp runModalForWindow:self.window];
111  [mainWindow endSheet:self.window];
112  }
113  else
114  {
115  [NSApp beginSheet:self.window
116  modalForWindow:mainWindow
117  modalDelegate:nil
118  didEndSelector:nil
119  contextInfo:nil];
120  self.modalCode = [NSApp runModalForWindow:self.window];
121  [NSApp endSheet:self.window];
122  }
123 
124  [self.window orderOut:nil];
125  return self.modalCode;
126 }
127 
128 - (void)dealloc
129 {
130  [usernameText release];
131  [passwordText release];
132  [messageLabel release];
133  [serverHostname release];
134  [username release];
135  [password release];
136  [domain release];
137  [super dealloc];
138 }
139 
140 @end