From 188f8021f806ff922924949054b94e53dc0fed30 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 9 Jun 2016 19:59:05 -0700 Subject: [PATCH] Joining/Deleting networks now implemented. Still need to implement known networks cache so we can join/leave networks without deleting them from the UI --- ZeroTier One/JoinNetworkViewController.swift | 2 +- ZeroTier One/NetworkInfoCell.swift | 32 +++++++- ZeroTier One/ShowNetworksViewController.swift | 5 ++ ZeroTier One/ShowNetworksViewController.xib | 75 +++++++++++++------ 4 files changed, 88 insertions(+), 26 deletions(-) diff --git a/ZeroTier One/JoinNetworkViewController.swift b/ZeroTier One/JoinNetworkViewController.swift index 1ac3c7ea6..cc768254e 100644 --- a/ZeroTier One/JoinNetworkViewController.swift +++ b/ZeroTier One/JoinNetworkViewController.swift @@ -62,7 +62,7 @@ class JoinNetworkViewController: NSViewController, NSComboBoxDelegate, NSComboBo let networkString = network.stringValue let networkId = UInt64(networkString, radix: 16) - // TODO: Execute join network call + ServiceCom.joinNetwork(networkString) network.stringValue = "" diff --git a/ZeroTier One/NetworkInfoCell.swift b/ZeroTier One/NetworkInfoCell.swift index 73305f838..c31fcb912 100644 --- a/ZeroTier One/NetworkInfoCell.swift +++ b/ZeroTier One/NetworkInfoCell.swift @@ -10,6 +10,8 @@ import Cocoa class NetworkInfoCell: NSTableCellView { + weak var parent: ShowNetworksViewController! + @IBOutlet var networkIdField: NSTextField! @IBOutlet var networkNameField: NSTextField! @@ -22,6 +24,9 @@ class NetworkInfoCell: NSTableCellView { @IBOutlet var deviceField: NSTextField! @IBOutlet var addressesField: NSTextField! + @IBOutlet var connectedCheckbox: NSButton! + @IBOutlet var deleteButton: NSButton! + override func awakeFromNib() { super.awakeFromNib() @@ -31,5 +36,30 @@ class NetworkInfoCell: NSTableCellView { // Drawing code here. } - + + @IBAction func onConnectCheckStateChanged(sender: NSButton) { + NSLog("Checked State Changed") + + if(sender.state == NSOnState) { + NSLog("Checked") + joinNetwork(networkIdField.stringValue) + } + else { + NSLog("Unchecked") + leaveNetwork(networkIdField.stringValue) + } + } + + @IBAction func deleteNetwork(sender: NSButton) { + leaveNetwork(networkIdField.stringValue) + parent.deleteNetworkFromList(networkIdField.stringValue) + } + + func joinNetwork(nwid: String) { + ServiceCom.joinNetwork(nwid) + } + + func leaveNetwork(nwid: String) { + ServiceCom.leaveNetwork(nwid) + } } diff --git a/ZeroTier One/ShowNetworksViewController.swift b/ZeroTier One/ShowNetworksViewController.swift index 857e2147b..33148f839 100644 --- a/ZeroTier One/ShowNetworksViewController.swift +++ b/ZeroTier One/ShowNetworksViewController.swift @@ -34,6 +34,10 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable } } + func deleteNetworkFromList(nwid: String) { + + } + // NSTableViewDataSource func numberOfRowsInTableView(tableView: NSTableView) -> Int { @@ -47,6 +51,7 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? { if let cell = tableView.makeViewWithIdentifier("NetworkInfoCell", owner: nil) as? NetworkInfoCell { let network = networkList[row] + cell.parent = self cell.networkIdField.stringValue = String(network.nwid, radix: 16) cell.networkNameField.stringValue = network.name diff --git a/ZeroTier One/ShowNetworksViewController.xib b/ZeroTier One/ShowNetworksViewController.xib index 6b12ea3fa..12f1ea3ce 100644 --- a/ZeroTier One/ShowNetworksViewController.xib +++ b/ZeroTier One/ShowNetworksViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -17,14 +17,14 @@ - + - - + + @@ -44,11 +44,11 @@ - + - + @@ -56,7 +56,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -80,7 +80,7 @@ - + @@ -88,7 +88,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -112,7 +112,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -136,7 +136,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -160,7 +160,7 @@ - + @@ -168,7 +168,7 @@ - + @@ -176,7 +176,7 @@ - + @@ -184,13 +184,33 @@ - + + + @@ -210,6 +230,7 @@ + @@ -222,14 +243,18 @@ + + + + @@ -242,6 +267,8 @@ + +