CCShareInfoCMOC.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // CCShareInfoCMOC.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 07/03/16.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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. CCHud *_hud;
  32. }
  33. @end
  34. /*
  35. const PERMISSION_CREATE = 4;
  36. const PERMISSION_READ = 1;
  37. const PERMISSION_UPDATE = 2;
  38. const PERMISSION_DELETE = 8;
  39. const PERMISSION_SHARE = 16;
  40. const PERMISSION_ALL = 31;
  41. */
  42. @implementation CCShareInfoCMOC
  43. - (instancetype)initWithCoder:(NSCoder *)coder
  44. {
  45. self = [super initWithCoder:coder];
  46. if (self) {
  47. }
  48. return self;
  49. }
  50. - (void)initializeForm
  51. {
  52. XLFormDescriptor *form ;
  53. XLFormSectionDescriptor *section;
  54. XLFormRowDescriptor *row;
  55. form = [XLFormDescriptor formDescriptor];
  56. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  57. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)];
  58. [form addFormSection:section];
  59. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"create" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_", nil)];
  60. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  61. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  62. [section addFormRow:row];
  63. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"read" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_read_", nil)];
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  65. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  66. [section addFormRow:row];
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"change" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_change_", nil)];
  68. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  69. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  70. [section addFormRow:row];
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)];
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  73. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  74. [section addFormRow:row];
  75. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)];
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  77. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  78. [section addFormRow:row];
  79. section = [XLFormSectionDescriptor formSection];
  80. [form addFormSection:section];
  81. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)];
  82. [form addFormSection:section];
  83. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)];
  84. if ([self.metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_connect_you_", nil);
  85. if ([self.metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_external_", nil);
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  88. [section addFormRow:row];
  89. self.form = form;
  90. form.disabled = YES;
  91. }
  92. - (void)viewDidLoad
  93. {
  94. [super viewDidLoad];
  95. self.view.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  96. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  97. self.endButton.tintColor = [NCBrandColor sharedInstance].brand;
  98. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  99. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  100. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  101. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  102. metadataNet.action = actionGetSharePermissionsFile;
  103. metadataNet.fileName = _metadata.fileName;
  104. metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  105. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  106. [self initializeForm];
  107. }
  108. #pragma --------------------------------------------------------------------------------------------
  109. #pragma mark ===== Delegate getSharePermissions =====
  110. #pragma --------------------------------------------------------------------------------------------
  111. - (void)getSharePermissionsFileSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions
  112. {
  113. [_hud hideHud];
  114. if (permissions == nil)
  115. return;
  116. NSInteger iPermissions = [permissions integerValue];
  117. // ------------------------------------------------------------------
  118. XLFormRowDescriptor *rowCreate = [self.form formRowWithTag:@"create"];
  119. XLFormRowDescriptor *rowRead = [self.form formRowWithTag:@"read"];
  120. XLFormRowDescriptor *rowChange = [self.form formRowWithTag:@"change"];
  121. XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"];
  122. XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"];
  123. // ------------------------------------------------------------------
  124. if ([UtilsFramework isPermissionToCanCreate:iPermissions]) rowCreate.value = @1;
  125. else rowCreate.value = @0;
  126. if ([UtilsFramework isPermissionToRead:iPermissions]) rowRead.value = @1;
  127. else rowRead.value = @0;
  128. if ([UtilsFramework isPermissionToCanChange:iPermissions]) rowChange.value = @1;
  129. else rowChange.value = @0;
  130. if ([UtilsFramework isPermissionToCanDelete:iPermissions]) rowDelete.value = @1;
  131. else rowDelete.value = @0;
  132. if ([UtilsFramework isPermissionToCanShare:iPermissions]) rowShare.value = @1;
  133. else rowShare.value = @0;
  134. // -----------------------------------------------------------------
  135. [self.tableView reloadData];
  136. }
  137. - (void)getSharePermissionsFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
  138. {
  139. [_hud hideHud];
  140. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  141. [self dismissViewControllerAnimated:YES completion:nil];
  142. }
  143. #pragma --------------------------------------------------------------------------------------------
  144. #pragma mark ===== Button =====
  145. #pragma --------------------------------------------------------------------------------------------
  146. - (IBAction)endButtonAction:(id)sender
  147. {
  148. [self dismissViewControllerAnimated:YES completion:nil];
  149. }
  150. @end