From 3394209f360699c4854145a386dffc0a5e600e56 Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Date: Wed, 3 Feb 2016 12:19:09 -0500
Subject: [PATCH] wizard: prepopulate field name

Use username's login provided by the system

Tuleap: #334
Change-Id: I61f18fa4e3265763d16aa6c1b4ae715c024bfe96
---
 src/RingWizardWC.mm          | 56 +++++++++++++++++++-----------------
 ui/Base.lproj/RingWizard.xib | 10 +++----
 2 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/src/RingWizardWC.mm b/src/RingWizardWC.mm
index 0043a7f0..c562aa65 100644
--- a/src/RingWizardWC.mm
+++ b/src/RingWizardWC.mm
@@ -31,19 +31,19 @@
 #import "AppDelegate.h"
 
 @implementation RingWizardWC {
-    __unsafe_unretained IBOutlet NSButton *goToAppButton;
-    __unsafe_unretained IBOutlet NSTextField *nickname;
-    __unsafe_unretained IBOutlet NSProgressIndicator *progressBar;
-    __unsafe_unretained IBOutlet NSTextField *indicationLabel;
-    __unsafe_unretained IBOutlet NSButton *createButton;
-    __unsafe_unretained IBOutlet NSButton *showCustomCertsButton;
+    __unsafe_unretained IBOutlet NSButton* goToAppButton;
+    __unsafe_unretained IBOutlet NSTextField* nicknameField;
+    __unsafe_unretained IBOutlet NSProgressIndicator* progressBar;
+    __unsafe_unretained IBOutlet NSTextField* indicationLabel;
+    __unsafe_unretained IBOutlet NSButton* createButton;
+    __unsafe_unretained IBOutlet NSButton* showCustomCertsButton;
     IBOutlet NSView *securityContainer;
 
-    __unsafe_unretained IBOutlet NSSecureTextField *passwordField;
-    __unsafe_unretained IBOutlet NSView *pvkContainer;
-    __unsafe_unretained IBOutlet NSPathControl *certificatePathControl;
-    __unsafe_unretained IBOutlet NSPathControl *caListPathControl;
-    __unsafe_unretained IBOutlet NSPathControl *pvkPathControl;
+    __unsafe_unretained IBOutlet NSSecureTextField* passwordField;
+    __unsafe_unretained IBOutlet NSView* pvkContainer;
+    __unsafe_unretained IBOutlet NSPathControl* certificatePathControl;
+    __unsafe_unretained IBOutlet NSPathControl* caListPathControl;
+    __unsafe_unretained IBOutlet NSPathControl* pvkPathControl;
     BOOL isExpanded;
     Account* accountToCreate;
 }
@@ -55,7 +55,7 @@ NSInteger const NICKNAME_TAG        = 1;
     [super windowDidLoad];
 
     [passwordField setTag:PVK_PASSWORD_TAG];
-    [nickname setTag:NICKNAME_TAG];
+    [nicknameField setTag:NICKNAME_TAG];
 
     isExpanded = false;
     [self.window makeKeyAndOrderFront:nil];
@@ -65,6 +65,8 @@ NSInteger const NICKNAME_TAG        = 1;
 
     if(![appDelegate checkForRingAccount]) {
         accountToCreate = AccountModel::instance().add("", Account::Protocol::RING);
+        [nicknameField setStringValue:NSFullUserName()];
+        [self toggleCreateButton:NSFullUserName()];
     } else {
         [indicationLabel setStringValue:NSLocalizedString(@"Ring is already ready to work",
                                                           @"Display message to user")];
@@ -79,10 +81,10 @@ NSInteger const NICKNAME_TAG        = 1;
 
 - (void) displayHash:(NSString* ) hash
 {
-    [nickname setFrameSize:NSMakeSize(400, nickname.frame.size.height)];
-    [nickname setStringValue:hash];
-    [nickname setEditable:NO];
-    [nickname setHidden:NO];
+    [nicknameField setFrameSize:NSMakeSize(400, nicknameField.frame.size.height)];
+    [nicknameField setStringValue:hash];
+    [nicknameField setEditable:NO];
+    [nicknameField setHidden:NO];
 
     [showCustomCertsButton setHidden:YES];
 
@@ -100,7 +102,7 @@ NSInteger const NICKNAME_TAG        = 1;
 
 - (IBAction)createRingAccount:(id)sender
 {
-    [nickname setHidden:YES];
+    [nicknameField setHidden:YES];
     [progressBar setHidden:NO];
     [createButton setEnabled:NO];
     [indicationLabel setStringValue:NSLocalizedString(@"Just a moment...",
@@ -173,6 +175,13 @@ NSInteger const NICKNAME_TAG        = 1;
     }
 }
 
+- (void) toggleCreateButton:(NSString*) alias
+{
+    [createButton setEnabled:![alias isEqualToString:@""]];
+    accountToCreate->setAlias([alias UTF8String]);
+    accountToCreate->setDisplayName([alias UTF8String]);
+}
+
 - (IBAction)goToApp:(id)sender
 {
     [self.window close];
@@ -182,7 +191,7 @@ NSInteger const NICKNAME_TAG        = 1;
 
 - (void) shareByEmail
 {
-    NSMutableArray *shareItems = [[NSMutableArray alloc] initWithObjects:[nickname stringValue], nil];
+    NSMutableArray *shareItems = [[NSMutableArray alloc] initWithObjects:[nicknameField stringValue], nil];
     NSSharingService* emailSharingService = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
     [emailSharingService performWithItems:shareItems];
 }
@@ -291,21 +300,14 @@ NSInteger const NICKNAME_TAG        = 1;
 
 -(void)controlTextDidChange:(NSNotification *)notif
 {
-    NSTextField *textField = [notif object];
+    NSTextField* textField = [notif object];
     if (textField.tag == PVK_PASSWORD_TAG) {
         accountToCreate->setTlsPassword([textField.stringValue UTF8String]);
         return;
     }
 
     // else it is NICKNAME_TAG field
-    if ([textField.stringValue isEqualToString:@""]) {
-        [createButton setEnabled:NO];
-    } else {
-        [createButton setEnabled:YES];
-    }
-
-    accountToCreate->setAlias([textField.stringValue UTF8String]);
-    accountToCreate->setDisplayName([textField.stringValue UTF8String]);
+    [self toggleCreateButton:textField.stringValue];
 }
 
 # pragma NSWindowDelegate methods
diff --git a/ui/Base.lproj/RingWizard.xib b/ui/Base.lproj/RingWizard.xib
index e893f931..cd9853df 100644
--- a/ui/Base.lproj/RingWizard.xib
+++ b/ui/Base.lproj/RingWizard.xib
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="RingWizardWC">
@@ -11,7 +11,7 @@
                 <outlet property="createButton" destination="rC1-mU-Scu" id="JrT-qi-fF5"/>
                 <outlet property="goToAppButton" destination="hKA-b6-heE" id="voO-WW-sdE"/>
                 <outlet property="indicationLabel" destination="PZB-UI-B3R" id="t79-DV-rKR"/>
-                <outlet property="nickname" destination="Phj-na-SP1" id="HYj-kV-lyE"/>
+                <outlet property="nicknameField" destination="Phj-na-SP1" id="e9d-3N-z9N"/>
                 <outlet property="passwordField" destination="1nU-BV-LdG" id="1fI-Xa-L9w"/>
                 <outlet property="progressBar" destination="nRx-qJ-VIe" id="qJ2-ra-GkK"/>
                 <outlet property="pvkContainer" destination="he3-z9-OHD" id="rmf-aA-Lv6"/>
@@ -31,7 +31,7 @@
                 <rect key="frame" x="0.0" y="5" width="480" height="173"/>
                 <autoresizingMask key="autoresizingMask"/>
                 <subviews>
-                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rAn-Kv-PgL">
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rAn-Kv-PgL">
                         <rect key="frame" x="18" y="117" width="231" height="36"/>
                         <textFieldCell key="cell" controlSize="mini" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Welcome to Ring" id="uqu-uh-Wao">
                             <font key="font" metaFont="system" size="30"/>
@@ -61,7 +61,7 @@ DQ
                             <constraint firstAttribute="width" constant="96" id="EN6-qO-gH1"/>
                         </constraints>
                     </progressIndicator>
-                    <button hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hKA-b6-heE">
+                    <button hidden="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hKA-b6-heE">
                         <rect key="frame" x="306" y="17" width="80" height="29"/>
                         <buttonCell key="cell" type="bevel" title="Continue" bezelStyle="regularSquare" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Kwr-LJ-K8C">
                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
-- 
GitLab