ZeroTierOne/ZeroTier One/NetworkInfoCell.swift
Grant Limberg 1756e8b0f2 Wire up checkboxes for allowGlobal, allowDefault, allowManaged to set the proper state in zerotier daemon
checkboxes are disabled if the network is not currently connected.
2016-06-26 17:33:46 -07:00

73 lines
2.1 KiB
Swift

//
// NetworkInfoCell.swift
// ZeroTier One
//
// Created by Grant Limberg on 5/24/16.
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
//
import Cocoa
class NetworkInfoCell: NSTableCellView {
weak var parent: ShowNetworksViewController!
@IBOutlet var networkIdField: NSTextField!
@IBOutlet var networkNameField: NSTextField!
@IBOutlet var statusField: NSTextField!
@IBOutlet var typeField: NSTextField!
@IBOutlet var macField: NSTextField!
@IBOutlet var mtuField: NSTextField!
@IBOutlet var broadcastField: NSTextField!
@IBOutlet var bridgingField: NSTextField!
@IBOutlet var deviceField: NSTextField!
@IBOutlet var addressesField: NSTextField!
@IBOutlet var allowManaged: NSButton!
@IBOutlet var allowGlobal: NSButton!
@IBOutlet var allowDefault: NSButton!
@IBOutlet var connectedCheckbox: NSButton!
@IBOutlet var deleteButton: NSButton!
override func awakeFromNib() {
super.awakeFromNib()
}
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
// Drawing code here.
}
@IBAction func onConnectCheckStateChanged(sender: NSButton) {
if(sender.state == NSOnState) {
joinNetwork(networkIdField.stringValue)
}
else {
leaveNetwork(networkIdField.stringValue)
}
}
@IBAction func deleteNetwork(sender: NSButton) {
leaveNetwork(networkIdField.stringValue)
parent.deleteNetworkFromList(networkIdField.stringValue)
}
func joinNetwork(nwid: String) {
ServiceCom.joinNetwork(nwid,
allowManaged: allowManaged.state == NSOnState,
allowGlobal: allowGlobal.state == NSOnState,
allowDefault: !defaultRouteExists(parent.networkList) && (allowDefault.state == NSOnState))
}
func leaveNetwork(nwid: String) {
ServiceCom.leaveNetwork(nwid)
}
@IBAction func onAllowStatusChanged(sender: NSButton) {
joinNetwork(networkIdField.stringValue)
}
}