// // AddPerforceController.swift // DocHub // // Created by Tristan Juricek on 6/17/14. // Copyright (c) 2014 Perforce. All rights reserved. // import AppKit import Foundation // Controller to manage a sheet on top of the window to collect connection // settings to a Perforce instance. This will basically collect the username // and password, then get a token from the Perforce server for storage. class AddPerforceController : NSWindowController { @IBOutlet var cancelButton:NSButton @IBOutlet var addButton:NSButton @IBOutlet var hostname:NSTextField @IBOutlet var login:NSTextField @IBOutlet var password:NSSecureTextField @IBAction override func cancelOperation(sender: AnyObject!) { NSApp.endSheet(window!) } @IBAction func tryAdd(sender: AnyObject!) { var pwd = password.stringValue var host:String var port:Int let scRange = hostname.stringValue.rangeOfString(":") if scRange { let pre = Range<String.Index>(start: hostname.stringValue.startIndex, end: scRange.startIndex) host = hostname.stringValue[pre] let post = Range<String.Index>(start: scRange.endIndex, end: hostname.stringValue.endIndex) port = hostname.stringValue[post].toInt()! } else { host = hostname.stringValue port = 1666 } let settings = P4ConnectionSettings( hostname: host, port: port, login: login.stringValue, token: pwd, charset: nil // TODO we may need to provide a charset ... ugh, along with SSL bah! ) let p4Library = P4Library(settings: settings) let p4Client = p4Library.createConnection() var (err, p4Info) = p4Client.info() if err { NSException(name: "InfoFailed", reason: err!.localizedDescription, userInfo: nil).raise() } let localHost = p4Info!.clientAddress var (loginErr, token) = p4Client.loginToken(pwd, localHost: localHost) if loginErr { NSException(name: "LoginFailed", reason: err!.localizedDescription, userInfo: nil).raise() } // This is actually what we want to store. We're now done. let newSettings = P4ConnectionSettings( hostname: settings.hostname, port: settings.port, login: settings.login, token: token, charset: settings.charset) P4ConnectionSettings.save(newSettings) // TODO trigger a "hey we got a new setting" message... to a delegate? NSApp.endSheet(window!) } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 9547 | tjuricek |
Use p4 info to grab the clientAddress which is then used to restrict the hostname token correctly from p4d. (Idea via dscheirer) |
||
#4 | 9545 | tjuricek |
Use the left column to navigate p4 servers as "libraries" with their depots as "areas". I've had to stop using the output of login -p at the moment, since it doesn't quite work with the Objective-C API in lieu of a password. |
||
#3 | 9483 | tjuricek | Basic connection settings serialization in the sandboxed Application Settings directory. | ||
#2 | 9475 | tjuricek |
Set up the positive workflow for AddPerforceController to get a login token. This required adding another couple of methods to provide input to the p4api (which were surprisingly absent from the earlier system). |
||
#1 | 9469 | tjuricek | Add sheet view for collecting Perforce connection information. |