NetworkInfoCell.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #import "NetworkInfoCell.h"
  19. #import "ServiceCom.h"
  20. #import "ShowNetworksViewController.h"
  21. #import "Network.h"
  22. @implementation NetworkInfoCell
  23. - (void)drawRect:(NSRect)dirtyRect {
  24. [super drawRect:dirtyRect];
  25. // Drawing code here.
  26. }
  27. - (IBAction)onConnectCheckStateChanged:(NSButton*)sender
  28. {
  29. if(sender.state == NSOnState) {
  30. [self joinNetwork:self.networkIdField.stringValue];
  31. }
  32. else {
  33. [self leaveNetwork:self.networkIdField.stringValue];
  34. }
  35. }
  36. - (IBAction)deleteNetwork:(NSButton*)sender;
  37. {
  38. [self leaveNetwork:self.networkIdField.stringValue];
  39. [self.parent deleteNetworkFromList:self.networkIdField.stringValue];
  40. }
  41. - (IBAction)onAllowStatusChanged:(NSButton*)sender
  42. {
  43. [self joinNetwork:self.networkIdField.stringValue];
  44. }
  45. - (void)joinNetwork:(NSString*)nwid
  46. {
  47. NSError *error = nil;
  48. [[ServiceCom sharedInstance] joinNetwork:nwid
  49. allowManaged:(self.allowManaged.state == NSOnState)
  50. allowGlobal:(self.allowGlobal.state == NSOnState)
  51. allowDefault:![Network defaultRouteExists:_parent.networkList] && (self.allowDefault.state == NSOnState)
  52. allowDNS:(self.allowDNS.state == NSOnState)
  53. error:&error];
  54. if (error) {
  55. NSAlert *alert = [NSAlert alertWithError:error];
  56. alert.alertStyle = NSCriticalAlertStyle;
  57. [alert addButtonWithTitle:@"Ok"];
  58. [alert runModal];
  59. }
  60. }
  61. - (void)leaveNetwork:(NSString*)nwid
  62. {
  63. NSError *error = nil;
  64. [[ServiceCom sharedInstance] leaveNetwork:nwid error:&error];
  65. if (error) {
  66. NSAlert *alert = [NSAlert alertWithError:error];
  67. alert.alertStyle = NSCriticalAlertStyle;
  68. [alert addButtonWithTitle:@"Ok"];
  69. [alert runModal];
  70. }
  71. }
  72. @end