CCShareInfoCMOC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // CCShareInfoCMOC.m
  3. // Crypto Cloud Technology Nextcloud
  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 "NCBridgeSwift.h"
  28. @interface CCShareInfoCMOC ()
  29. @end
  30. /*
  31. #define k_permission_shared @"S"
  32. #define k_permission_can_share @"R"
  33. #define k_permission_mounted @"M"
  34. #define k_permission_file_can_write @"W"
  35. #define k_permission_can_create_file @"C"
  36. #define k_permission_can_create_folder @"K"
  37. #define k_permission_can_delete @"D"
  38. #define k_permission_can_rename @"N"
  39. #define k_permission_can_move @"V"
  40. */
  41. @implementation CCShareInfoCMOC
  42. - (instancetype)initWithCoder:(NSCoder *)coder
  43. {
  44. self = [super initWithCoder:coder];
  45. if (self) {
  46. }
  47. return self;
  48. }
  49. - (void)initializeForm
  50. {
  51. XLFormDescriptor *form ;
  52. XLFormSectionDescriptor *section;
  53. XLFormRowDescriptor *row;
  54. form = [XLFormDescriptor formDescriptor];
  55. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  56. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)];
  57. [form addFormSection:section];
  58. if (self.metadata.directory == NO) {
  59. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"edit" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_file_can_write_", nil)];
  60. if ([self.metadata.permissions rangeOfString:k_permission_file_can_write].location != NSNotFound) row.value = @1;
  61. else row.value = @0;
  62. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  63. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  64. [section addFormRow:row];
  65. }
  66. if (self.metadata.directory == YES) {
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"createfile" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_file_", nil)];
  68. if ([self.metadata.permissions rangeOfString:k_permission_can_create_file].location != NSNotFound) row.value = @1;
  69. else row.value = @0;
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  71. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  72. [section addFormRow:row];
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"createfolder" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_folder_", nil)];
  74. if ([self.metadata.permissions rangeOfString:k_permission_can_create_folder].location != NSNotFound) row.value = @1;
  75. else row.value = @0;
  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. }
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)];
  81. if ([self.metadata.permissions rangeOfString:k_permission_can_delete].location != NSNotFound) row.value = @1;
  82. else row.value = @0;
  83. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  84. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  85. [section addFormRow:row];
  86. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"rename" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_rename_", nil)];
  87. if ([self.metadata.permissions rangeOfString:k_permission_can_rename].location != NSNotFound) row.value = @1;
  88. else row.value = @0;
  89. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  90. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  91. [section addFormRow:row];
  92. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"move" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_move_", nil)];
  93. if ([self.metadata.permissions rangeOfString:k_permission_can_move].location != NSNotFound) row.value = @1;
  94. else row.value = @0;
  95. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  96. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  97. [section addFormRow:row];
  98. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)];
  99. if ([self.metadata.permissions rangeOfString:k_permission_can_share].location != NSNotFound) row.value = @1;
  100. else row.value = @0;
  101. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  102. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  103. [section addFormRow:row];
  104. section = [XLFormSectionDescriptor formSection];
  105. [form addFormSection:section];
  106. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)];
  107. [form addFormSection:section];
  108. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)];
  109. if ([self.metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_connect_you_", nil);
  110. if ([self.metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_external_", nil);
  111. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  112. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  113. [section addFormRow:row];
  114. self.form = form;
  115. form.disabled = YES;
  116. }
  117. - (void)viewDidLoad
  118. {
  119. [super viewDidLoad];
  120. self.view.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  121. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  122. self.endButton.tintColor = [NCBrandColor sharedInstance].brand;
  123. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  124. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  125. metadataNet.action = actionGetSharePermissionsFile;
  126. metadataNet.fileName = _metadata.fileNameData;
  127. metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  128. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  129. [self initializeForm];
  130. }
  131. #pragma --------------------------------------------------------------------------------------------
  132. #pragma mark ===== Delegate getSharePermissions =====
  133. #pragma --------------------------------------------------------------------------------------------
  134. - (void)getSharePermissionsFileSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions
  135. {
  136. // ----------------------
  137. XLFormRowDescriptor *rowEdit = [self.form formRowWithTag:@"edit"];
  138. XLFormRowDescriptor *rowCreateFile = [self.form formRowWithTag:@"createfile"];
  139. XLFormRowDescriptor *rowCreateFolder = [self.form formRowWithTag:@"createfolder"];
  140. XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"];
  141. XLFormRowDescriptor *rowRename = [self.form formRowWithTag:@"rename"];
  142. XLFormRowDescriptor *rowMove = [self.form formRowWithTag:@"move"];
  143. XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"];
  144. // ------------------------------------------------------------------
  145. if (self.metadata.directory == NO) {
  146. } else {
  147. }
  148. /*
  149. if ([[CCUtility getBlockCode] length]) {
  150. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  151. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeYES"] forKey:@"imageView.image"];
  152. } else {
  153. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  154. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  155. }
  156. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  157. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  158. if ([CCUtility getFavoriteOffline]) [rowFavoriteOffline setValue:@1]; else [rowFavoriteOffline setValue:@0];
  159. */
  160. // -----------------------------------------------------------------
  161. [self.tableView reloadData];
  162. }
  163. - (void)getSharePermissionsFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
  164. {
  165. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  166. [self dismissViewControllerAnimated:YES completion:nil];
  167. }
  168. #pragma --------------------------------------------------------------------------------------------
  169. #pragma mark ===== Button =====
  170. #pragma --------------------------------------------------------------------------------------------
  171. - (IBAction)endButtonAction:(id)sender
  172. {
  173. [self dismissViewControllerAnimated:YES completion:nil];
  174. }
  175. @end