CCShareUserOC.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // CCShareUserOC.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 30/11/15.
  6. // Copyright (c) 2014 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 "CCShareUserOC.h"
  24. #import "AppDelegate.h"
  25. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCShareUserOC ()
  31. @end
  32. @implementation CCShareUserOC
  33. - (instancetype)initWithCoder:(NSCoder *)coder
  34. {
  35. self = [super initWithCoder:coder];
  36. if (self) {
  37. self.directUser = @"";
  38. [self initializeForm];
  39. }
  40. return self;
  41. }
  42. - (void)initializeForm
  43. {
  44. XLFormDescriptor *form ;
  45. XLFormSectionDescriptor *section;
  46. XLFormRowDescriptor *row;
  47. form = [XLFormDescriptor formDescriptor];
  48. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  49. form.assignFirstResponderOnShow = NO;
  50. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_find_sharee_title_", nil)];
  51. [form addFormSection:section];
  52. section.footerTitle = NSLocalizedString(@"_find_sharee_footer_", nil);
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeAccount];
  54. [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_find_sharee_", nil) forKey:@"textField.placeholder"];
  55. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  56. [section addFormRow:row];
  57. section = [XLFormSectionDescriptor formSection];
  58. [form addFormSection:section];
  59. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_direct_sharee_title_", nil)];
  60. [form addFormSection:section];
  61. section.footerTitle = NSLocalizedString(@"_direct_sharee_footer_", nil);
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"directUser" rowType:XLFormRowDescriptorTypeAccount];
  63. [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_direct_sharee_", nil) forKey:@"textField.placeholder"];
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  65. [section addFormRow:row];
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_type_title_", nil)];
  67. [form addFormSection:section];
  68. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareType" rowType:XLFormRowDescriptorTypePicker];
  69. row.selectorOptions = @[NSLocalizedString(@"_share_type_user_", nil), NSLocalizedString(@"_share_type_group_", nil), NSLocalizedString(@"_share_type_remote_", nil)];
  70. row.value = NSLocalizedString(@"_share_type_user_", nil);
  71. self.shareType = shareTypeUser;
  72. row.height = 100;
  73. [section addFormRow:row];
  74. section = [XLFormSectionDescriptor formSection];
  75. [form addFormSection:section];
  76. self.form = form;
  77. }
  78. - (void)viewDidLoad
  79. {
  80. [super viewDidLoad];
  81. self.selectedItems = [[NSMutableArray alloc] init];
  82. self.view.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  83. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  84. self.endButton.tintColor = [NCBrandColor sharedInstance].brand;
  85. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  86. }
  87. #pragma --------------------------------------------------------------------------------------------
  88. #pragma mark ===== Button =====
  89. #pragma --------------------------------------------------------------------------------------------
  90. - (IBAction)endButtonAction:(id)sender
  91. {
  92. NSInteger permission;
  93. if (self.isDirectory) permission = k_max_folder_share_permission;
  94. else permission = k_max_file_share_permission;
  95. // start share of select users
  96. for (NSString *num in self.selectedItems) {
  97. OCShareUser *item = [self.users objectAtIndex:[num integerValue]];
  98. [self.delegate shareUserAndGroup:item.name shareeType:item.shareeType permission:permission];
  99. }
  100. // start share with a user if not be i
  101. if ([self.directUser isEqual:[NSNull null]] == NO) {
  102. if ([self.directUser length] > 0 && [self.directUser isEqualToString:app.activeUser] == NO) {
  103. // User/Group/Federate
  104. [self.delegate shareUserAndGroup:self.directUser shareeType:self.shareType permission:permission];
  105. }
  106. }
  107. [self dismissViewControllerAnimated:YES completion:nil];
  108. }
  109. #pragma --------------------------------------------------------------------------------------------
  110. #pragma mark ===== Change Value =====
  111. #pragma --------------------------------------------------------------------------------------------
  112. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  113. {
  114. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  115. if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeBooleanCheck]) {
  116. if ([newValue boolValue] == YES)
  117. [self.selectedItems addObject:rowDescriptor.tag];
  118. if ([newValue boolValue] == NO)
  119. [self.selectedItems removeObject:rowDescriptor.tag];
  120. }
  121. if ([rowDescriptor.tag isEqualToString:@"directUser"]) {
  122. self.directUser = newValue;
  123. }
  124. if ([rowDescriptor.tag isEqualToString:@"shareType"]){
  125. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_user_", nil)])
  126. self.shareType = shareTypeUser;
  127. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_group_", nil)])
  128. self.shareType = shareTypeGroup;
  129. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_remote_", nil)])
  130. self.shareType = shareTypeRemote;
  131. }
  132. }
  133. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  134. {
  135. [super endEditing:rowDescriptor];
  136. if ([rowDescriptor.tag isEqualToString:@"findUser"]) {
  137. rowDescriptor.value = [rowDescriptor.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  138. if ([rowDescriptor.value length] > 1)
  139. [self.delegate getUserAndGroup:rowDescriptor.value];
  140. }
  141. }
  142. #pragma --------------------------------------------------------------------------------------------
  143. #pragma mark ===== Delegate =====
  144. #pragma --------------------------------------------------------------------------------------------
  145. - (void)reloadUserAndGroup:(NSArray *)items
  146. {
  147. self.users = [[NSMutableArray alloc] initWithArray:items];
  148. self.form.delegate = nil;
  149. // remove the select users and i
  150. for (OCShareUser *user in items) {
  151. for (OCSharedDto *item in self.itemsShareWith)
  152. if ([item.shareWith isEqualToString:user.name] && ((item.shareType == shareTypeGroup && user.shareeType == 1) || (item.shareType != shareTypeGroup && user.shareeType == 0)))
  153. [self.users removeObject:user];
  154. if ([self.itemsShareWith containsObject:user.name] || [user.name isEqualToString:app.activeUser])
  155. [self.users removeObject:user];
  156. }
  157. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:1];
  158. [section.formRows removeAllObjects];
  159. for (OCShareUser *item in self.users) {
  160. NSInteger num = [self.users indexOfObject:item];
  161. NSString *title;
  162. if (item.shareeType == 1) title = [item.name stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  163. else title = item.name;
  164. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:[@(num) stringValue] rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
  165. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  166. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"self.tintColor"];
  167. [section addFormRow:row];
  168. }
  169. [self.tableView reloadData];
  170. self.form.delegate = self;
  171. }
  172. @end