ZeroTierOne/ZeroTier One/ShowNetworksViewController.swift

83 lines
2.4 KiB
Swift
Raw Normal View History

//
// ShowNetworksViewController.swift
// ZeroTier One
//
// Created by Grant Limberg on 5/14/16.
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
//
import Cocoa
class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
2016-05-17 02:08:00 +00:00
@IBOutlet var tableView: NSTableView!
var networkList: [Network] = [Network]()
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
tableView.setDelegate(self)
tableView.setDataSource(self)
tableView.backgroundColor = NSColor.clearColor()
}
override func viewWillAppear() {
super.viewWillAppear()
ServiceCom.getNetworkList() { (networkList) -> Void in
NSOperationQueue.mainQueue().addOperationWithBlock() { () -> Void in
self.networkList = networkList
self.tableView.reloadData()
}
}
}
func deleteNetworkFromList(nwid: String) {
}
// NSTableViewDataSource
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
return networkList.count
}
// end NSTableViewDataSource
2016-05-27 20:28:32 +00:00
// NSTableViewDelegate
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
2016-05-27 20:28:32 +00:00
cell.networkIdField.stringValue = String(network.nwid, radix: 16)
cell.networkNameField.stringValue = network.name
2016-05-27 20:48:22 +00:00
cell.statusField.stringValue = network.status.description
cell.typeField.stringValue = network.type.description
cell.macField.stringValue = network.mac
cell.mtuField.stringValue = String(network.mtu)
cell.broadcastField.stringValue = network.broadcastEnabled ? "ENABLED" : "DISABLED"
cell.bridgingField.stringValue = network.bridge ? "ENABLED" : "DISABLED"
cell.deviceField.stringValue = network.portDeviceName
cell.addressesField.stringValue = ""
for nw in network.assignedAddresses {
cell.addressesField.stringValue += nw
cell.addressesField.stringValue += "\n"
}
2016-05-27 20:28:32 +00:00
return cell
}
return nil
}
// end NSTableViewDelegate
}