CCManageAutoUpload.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. //
  2. // CCManageAutoUpload.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/09/15.
  6. // Copyright (c) 2015 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 <Photos/Photos.h>
  24. #import "CCManageAutoUpload.h"
  25. #import "CCUtility.h"
  26. #import "NCBridgeSwift.h"
  27. @interface CCManageAutoUpload () <NCSelectDelegate>
  28. {
  29. AppDelegate *appDelegate;
  30. }
  31. @end
  32. @implementation CCManageAutoUpload
  33. - (void)initializeForm
  34. {
  35. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  36. XLFormSectionDescriptor *section;
  37. XLFormRowDescriptor *row;
  38. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  39. // Auto Upload
  40. section = [XLFormSectionDescriptor formSection];
  41. [form addFormSection:section];
  42. section.footerTitle = NSLocalizedString(@"_autoupload_description_", nil);
  43. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_", nil)];
  44. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  45. if (activeAccount.autoUpload) row.value = @1;
  46. else row.value = @0;
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  48. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  49. [section addFormRow:row];
  50. // Auto Upload Directory
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadDirectory" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_select_folder_", nil)];
  54. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  55. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  56. [row.cellConfig setObject:[[UIImage imageNamed:@"foldersOnTop"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  57. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  58. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  59. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  60. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  61. row.action.formSelector = @selector(selectAutomaticUploadFolder);
  62. [section addFormRow:row];
  63. // Auto Upload Photo
  64. section = [XLFormSectionDescriptor formSection];
  65. [form addFormSection:section];
  66. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadImage" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_photos_", nil)];
  67. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  68. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  69. if (activeAccount.autoUploadImage) row.value = @1;
  70. else row.value = @0;
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  72. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  73. [section addFormRow:row];
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  75. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  76. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  77. if (activeAccount.autoUploadWWAnPhoto) row.value = @1;
  78. else row.value = @0;
  79. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  80. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  81. [section addFormRow:row];
  82. // Auto Upload Video
  83. section = [XLFormSectionDescriptor formSection];
  84. [form addFormSection:section];
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_videos_", nil)];
  86. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  87. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  88. if (activeAccount.autoUploadVideo) row.value = @1;
  89. else row.value = @0;
  90. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  91. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  92. [section addFormRow:row];
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  94. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  95. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  96. if (activeAccount.autoUploadWWAnVideo) row.value = @1;
  97. else row.value = @0;
  98. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  99. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  100. [section addFormRow:row];
  101. // Auto Upload Full
  102. section = [XLFormSectionDescriptor formSection];
  103. [form addFormSection:section];
  104. NSString *title = NSLocalizedString(@"_autoupload_fullphotos_", nil);
  105. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFull" rowType:XLFormRowDescriptorTypeBooleanSwitch title:title];
  106. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  107. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  108. row.value = 0;
  109. if (activeAccount.autoUploadFull) row.value = @1;
  110. else row.value = @0;
  111. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  112. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  113. [section addFormRow:row];
  114. // Auto Upload create subfolder
  115. section = [XLFormSectionDescriptor formSection];
  116. [form addFormSection:section];
  117. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadCreateSubfolder" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_create_subfolder_", nil)];
  118. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  119. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  120. if (activeAccount.autoUploadCreateSubfolder) row.value = @1;
  121. else row.value = @0;
  122. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  123. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  124. [section addFormRow:row];
  125. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadSubfolderGranularity" rowType:XLFormRowDescriptorTypeSelectorPush title:NSLocalizedString(@"_autoupload_subfolder_granularity_", nil)];
  126. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  127. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  128. row.selectorOptions = @[
  129. [XLFormOptionsObject formOptionsObjectWithValue:@(NCGlobal.shared.subfolderGranularityYearly) displayText:NSLocalizedString(@"_yearly_", nil)],
  130. [XLFormOptionsObject formOptionsObjectWithValue:@(NCGlobal.shared.subfolderGranularityMonthly) displayText:NSLocalizedString(@"_monthly_", nil)],
  131. [XLFormOptionsObject formOptionsObjectWithValue:@(NCGlobal.shared.subfolderGranularityDaily) displayText:NSLocalizedString(@"_daily_", nil)]
  132. ];
  133. row.value = row.selectorOptions[activeAccount.autoUploadSubfolderGranularity];
  134. row.required = true;
  135. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  136. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  137. [section addFormRow:row];
  138. // Auto Upload file name
  139. section = [XLFormSectionDescriptor formSection];
  140. [form addFormSection:section];
  141. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFileName" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_filenamemask_", nil)];
  142. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  143. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  144. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  145. row.action.viewControllerClass = [NCManageAutoUploadFileName class];
  146. [section addFormRow:row];
  147. // end
  148. section = [XLFormSectionDescriptor formSection];
  149. [form addFormSection:section];
  150. self.tableView.showsVerticalScrollIndicator = NO;
  151. self.form = form;
  152. }
  153. // MARK: - View Life Cycle
  154. - (void)viewDidLoad
  155. {
  156. [super viewDidLoad];
  157. self.title = NSLocalizedString(@"_settings_autoupload_", nil);
  158. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  159. self.view.backgroundColor = UIColor.systemGroupedBackgroundColor;
  160. self.tableView.backgroundColor = UIColor.systemGroupedBackgroundColor;
  161. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeUser) name:NCGlobal.shared.notificationCenterChangeUser object:nil];
  162. [self initializeForm];
  163. [self reloadForm];
  164. }
  165. - (void)viewWillAppear:(BOOL)animated
  166. {
  167. [super viewWillAppear:animated];
  168. appDelegate.activeViewController = self;
  169. [[NCAskAuthorization shared] askAuthorizationPhotoLibraryWithViewController:self completion:^(BOOL status) { }];
  170. }
  171. - (void)changeUser
  172. {
  173. // [[self navigationController] popViewControllerAnimated:YES];
  174. [self initializeForm];
  175. [self reloadForm];
  176. }
  177. #pragma mark - NotificationCenter
  178. #pragma mark -
  179. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  180. {
  181. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  182. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  183. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  184. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  185. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  186. // Default
  187. [[NCManageDatabase shared] setAccountAutoUploadFileName:nil];
  188. [[NCManageDatabase shared] setAccountAutoUploadDirectory:nil urlBase:appDelegate.urlBase userId:appDelegate.userId account:appDelegate.account];
  189. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  190. if (activeAccount.autoUploadImage == NO && activeAccount.autoUploadVideo == NO) {
  191. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  192. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  193. }
  194. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  195. } else {
  196. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  197. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  198. // remove
  199. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  200. }
  201. [self reloadForm];
  202. }
  203. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  204. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  205. [[NCAutoUpload shared] autoUploadFullPhotosWithViewController:self log:@"Auto upload full"];
  206. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  207. } else {
  208. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  209. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  210. }
  211. }
  212. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  213. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  214. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  215. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  216. }
  217. }
  218. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  219. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  220. }
  221. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  222. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  223. if ([[rowDescriptor.value valueData] boolValue] == YES){
  224. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  225. }
  226. }
  227. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  228. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  229. }
  230. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  231. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  232. }
  233. if ([rowDescriptor.tag isEqualToString:@"autoUploadSubfolderGranularity"]) {
  234. [[NCManageDatabase shared] setAccountAutoUploadGranularity:@"autoUploadSubfolderGranularity" state:[[rowDescriptor.value valueData] integerValue]];
  235. }
  236. }
  237. - (void)done:(XLFormRowDescriptor *)sender
  238. {
  239. [self dismissViewControllerAnimated:YES completion:nil];
  240. }
  241. - (void)reloadForm
  242. {
  243. self.form.delegate = nil;
  244. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  245. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  246. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  247. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  248. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  249. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  250. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  251. XLFormRowDescriptor *rowAutoUploadSubfolderGranularity = [self.form formRowWithTag:@"autoUploadSubfolderGranularity"];
  252. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  253. // - STATUS ---------------------
  254. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  255. if (activeAccount.autoUpload)
  256. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  257. if (activeAccount.autoUploadImage)
  258. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  259. if (activeAccount.autoUploadWWAnPhoto)
  260. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  261. if (activeAccount.autoUploadVideo)
  262. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  263. if (activeAccount.autoUploadWWAnVideo)
  264. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  265. if (activeAccount.autoUploadFull)
  266. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  267. if (activeAccount.autoUploadCreateSubfolder)
  268. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  269. [rowAutoUploadSubfolderGranularity setValue:rowAutoUploadSubfolderGranularity.selectorOptions[activeAccount.autoUploadSubfolderGranularity]];
  270. // - HIDDEN --------------------------------------------------------------------------
  271. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  272. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  273. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  274. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  275. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  276. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  277. rowAutoUploadSubfolderGranularity.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  278. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  279. // -----------------------------------------------------------------------------------
  280. [self.tableView reloadData];
  281. self.form.delegate = self;
  282. }
  283. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  284. return NCGlobal.shared.heightCellSettings;
  285. }
  286. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  287. {
  288. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  289. NSString *sectionName;
  290. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase shared] getAccountAutoUploadDirectoryWithUrlBase:appDelegate.urlBase userId:appDelegate.userId account:appDelegate.account], [[NCManageDatabase shared] getAccountAutoUploadFileName]];
  291. switch (section)
  292. {
  293. case 0:
  294. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  295. break;
  296. case 1:
  297. if (activeAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath urlBase:appDelegate.urlBase userId:appDelegate.userId account:appDelegate.account]];
  298. else sectionName = @"";
  299. break;
  300. case 4:
  301. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  302. else sectionName = @"";
  303. break;
  304. case 5:
  305. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  306. else sectionName = @"";
  307. break;
  308. case 6:
  309. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  310. else sectionName = @"";
  311. break;
  312. }
  313. return sectionName;
  314. }
  315. - (void)dismissSelectWithServerUrl:(NSString * _Nullable)serverUrl metadata:(tableMetadata * _Nullable)metadata type:(NSString * _Nonnull)type items:(NSArray * _Nonnull)items indexPath:(NSArray<NSIndexPath *> * _Nonnull)indexPath overwrite:(BOOL)overwrite copy:(BOOL)copy move:(BOOL)move
  316. {
  317. if (serverUrl != nil) {
  318. NSString* home = [[NCUtilityFileSystem shared] getHomeServerWithUrlBase:appDelegate.urlBase userId:appDelegate.userId];
  319. if ([serverUrl isEqualToString:home]) {
  320. NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"_autoupload_error_select_folder_" responseData:nil];
  321. [[NCContentPresenter shared] messageNotification:@"_error_" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
  322. return;
  323. }
  324. // Settings new folder Automatatic upload
  325. [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
  326. NSString *path = [[NCUtilityFileSystem shared] deleteLastPathWithServerUrlPath:serverUrl home:home];
  327. if (path != nil) {
  328. [[NCManageDatabase shared] setAccountAutoUploadDirectory:path urlBase:appDelegate.urlBase userId:appDelegate.userId account:appDelegate.account];
  329. }
  330. // Reload
  331. [self.tableView reloadData];
  332. }
  333. }
  334. - (void)selectAutomaticUploadFolder
  335. {
  336. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  337. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  338. viewController.delegate = self;
  339. viewController.typeOfCommandView = 1;
  340. [self presentViewController:navigationController animated:YES completion:^{
  341. [self.tableView reloadData];
  342. }];
  343. }
  344. @end