NetworkInfoCell.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. error:&error];
  53. if (error) {
  54. NSAlert *alert = [NSAlert alertWithError:error];
  55. alert.alertStyle = NSCriticalAlertStyle;
  56. [alert addButtonWithTitle:@"Ok"];
  57. [alert runModal];
  58. }
  59. }
  60. - (void)leaveNetwork:(NSString*)nwid
  61. {
  62. NSError *error = nil;
  63. [[ServiceCom sharedInstance] leaveNetwork:nwid error:&error];
  64. if (error) {
  65. NSAlert *alert = [NSAlert alertWithError:error];
  66. alert.alertStyle = NSCriticalAlertStyle;
  67. [alert addButtonWithTitle:@"Ok"];
  68. [alert runModal];
  69. }
  70. }
  71. @end