CCShareInfoCMOC.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // CCShareInfoCMOC.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 07/03/16.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCShareInfoCMOC.h"
  24. #import "XLFormViewController.h"
  25. #import "XLForm.h"
  26. #import "AppDelegate.h"
  27. #import "CCHud.h"
  28. #import "NCBridgeSwift.h"
  29. @interface CCShareInfoCMOC ()
  30. {
  31. AppDelegate *appDelegate;
  32. CCHud *_hud;
  33. }
  34. @end
  35. /*
  36. const PERMISSION_CREATE = 4;
  37. const PERMISSION_READ = 1;
  38. const PERMISSION_UPDATE = 2;
  39. const PERMISSION_DELETE = 8;
  40. const PERMISSION_SHARE = 16;
  41. const PERMISSION_ALL = 31;
  42. */
  43. @implementation CCShareInfoCMOC
  44. - (instancetype)initWithCoder:(NSCoder *)coder
  45. {
  46. self = [super initWithCoder:coder];
  47. if (self) {
  48. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  49. }
  50. return self;
  51. }
  52. - (void)initializeForm
  53. {
  54. XLFormDescriptor *form ;
  55. XLFormSectionDescriptor *section;
  56. XLFormRowDescriptor *row;
  57. form = [XLFormDescriptor formDescriptor];
  58. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  59. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)];
  60. [form addFormSection:section];
  61. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"create" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_", nil)];
  62. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  63. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  64. [section addFormRow:row];
  65. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"read" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_read_", nil)];
  66. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  67. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  68. [section addFormRow:row];
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"change" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_change_", nil)];
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  71. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  72. [section addFormRow:row];
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)];
  74. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  75. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  76. [section addFormRow:row];
  77. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)];
  78. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  79. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  80. [section addFormRow:row];
  81. section = [XLFormSectionDescriptor formSection];
  82. [form addFormSection:section];
  83. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)];
  84. [form addFormSection:section];
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)];
  86. if ([self.metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_connect_you_", nil);
  87. if ([self.metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_external_", nil);
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  89. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  90. [section addFormRow:row];
  91. self.form = form;
  92. form.disabled = YES;
  93. }
  94. - (void)viewDidLoad
  95. {
  96. [super viewDidLoad];
  97. self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  98. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  99. self.endButton.tintColor = [UIColor blackColor];
  100. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  101. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  102. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  103. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  104. metadataNet.action = actionGetSharePermissionsFile;
  105. metadataNet.fileName = _metadata.fileName;
  106. metadataNet.serverUrl = _metadata.serverUrl;
  107. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  108. [self initializeForm];
  109. }
  110. #pragma --------------------------------------------------------------------------------------------
  111. #pragma mark ===== Delegate getSharePermissions =====
  112. #pragma --------------------------------------------------------------------------------------------
  113. - (void)getSharePermissionsFileSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions
  114. {
  115. [_hud hideHud];
  116. if (permissions == nil)
  117. return;
  118. NSInteger iPermissions = [permissions integerValue];
  119. // ------------------------------------------------------------------
  120. XLFormRowDescriptor *rowCreate = [self.form formRowWithTag:@"create"];
  121. XLFormRowDescriptor *rowRead = [self.form formRowWithTag:@"read"];
  122. XLFormRowDescriptor *rowChange = [self.form formRowWithTag:@"change"];
  123. XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"];
  124. XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"];
  125. // ------------------------------------------------------------------
  126. if ([UtilsFramework isPermissionToCanCreate:iPermissions]) rowCreate.value = @1;
  127. else rowCreate.value = @0;
  128. if ([UtilsFramework isPermissionToRead:iPermissions]) rowRead.value = @1;
  129. else rowRead.value = @0;
  130. if ([UtilsFramework isPermissionToCanChange:iPermissions]) rowChange.value = @1;
  131. else rowChange.value = @0;
  132. if ([UtilsFramework isPermissionToCanDelete:iPermissions]) rowDelete.value = @1;
  133. else rowDelete.value = @0;
  134. if ([UtilsFramework isPermissionToCanShare:iPermissions]) rowShare.value = @1;
  135. else rowShare.value = @0;
  136. // -----------------------------------------------------------------
  137. [self.tableView reloadData];
  138. }
  139. - (void)getSharePermissionsFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
  140. {
  141. [_hud hideHud];
  142. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  143. [self dismissViewControllerAnimated:YES completion:nil];
  144. }
  145. #pragma --------------------------------------------------------------------------------------------
  146. #pragma mark ===== Button =====
  147. #pragma --------------------------------------------------------------------------------------------
  148. - (IBAction)endButtonAction:(id)sender
  149. {
  150. [self dismissViewControllerAnimated:YES completion:nil];
  151. }
  152. @end