CCManageAutoUpload.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. //
  2. // CCManageAutoUpload.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/09/15.
  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 "CCManageAutoUpload.h"
  24. #import "NCAutoUpload.h"
  25. #import "AppDelegate.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 formDescriptorWithTitle:NSLocalizedString(@"_settings_autoupload_", nil)];
  36. XLFormSectionDescriptor *section;
  37. XLFormRowDescriptor *row;
  38. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  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"] = NCBrandColor.sharedInstance.backgroundView;
  45. if (tableAccount.autoUpload) row.value = @1;
  46. else row.value = @0;
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  48. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  49. [section addFormRow:row];
  50. // Auto Upload Directory
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. // Lock active YES/NO
  54. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadDirectory" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_select_folder_", nil)];
  55. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  56. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  57. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folderAutomaticUpload"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  60. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  61. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  62. row.action.formSelector = @selector(selectAutomaticUploadFolder);
  63. [section addFormRow:row];
  64. // Auto Upload Photo
  65. section = [XLFormSectionDescriptor formSection];
  66. [form addFormSection:section];
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadImage" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_photos_", nil)];
  68. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  69. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  70. if (tableAccount.autoUploadImage) row.value = @1;
  71. else row.value = @0;
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  73. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  74. [section addFormRow:row];
  75. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  76. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  77. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  78. if (tableAccount.autoUploadWWAnPhoto) row.value = @1;
  79. else row.value = @0;
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  82. [section addFormRow:row];
  83. // Auto Upload Video
  84. section = [XLFormSectionDescriptor formSection];
  85. [form addFormSection:section];
  86. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_videos_", nil)];
  87. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  88. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  89. if (tableAccount.autoUploadVideo) row.value = @1;
  90. else row.value = @0;
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  93. [section addFormRow:row];
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  95. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  96. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  97. if (tableAccount.autoUploadWWAnVideo) row.value = @1;
  98. else row.value = @0;
  99. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  100. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  101. [section addFormRow:row];
  102. // Auto Upload Background
  103. section = [XLFormSectionDescriptor formSection];
  104. [form addFormSection:section];
  105. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadBackground" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_background_", nil)];
  106. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  107. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  108. if (tableAccount.autoUploadBackground) row.value = @1;
  109. else row.value = @0;
  110. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  111. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  112. [section addFormRow:row];
  113. // Auto Upload Full
  114. section = [XLFormSectionDescriptor formSection];
  115. [form addFormSection:section];
  116. NSString *title = NSLocalizedString(@"_autoupload_fullphotos_", nil);
  117. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFull" rowType:XLFormRowDescriptorTypeBooleanSwitch title:title];
  118. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  119. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  120. row.value = 0;
  121. if (tableAccount.autoUploadFull) row.value = @1;
  122. else row.value = @0;
  123. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  124. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  125. [section addFormRow:row];
  126. // Auto Upload create subfolder
  127. section = [XLFormSectionDescriptor formSection];
  128. [form addFormSection:section];
  129. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadCreateSubfolder" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_create_subfolder_", nil)];
  130. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  131. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  132. if (tableAccount.autoUploadCreateSubfolder) row.value = @1;
  133. else row.value = @0;
  134. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  135. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  136. [section addFormRow:row];
  137. // Auto Upload file name
  138. section = [XLFormSectionDescriptor formSection];
  139. [form addFormSection:section];
  140. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFileName" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_filenamemask_", nil)];
  141. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  143. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  144. row.action.viewControllerClass = [NCManageAutoUploadFileName class];
  145. [section addFormRow:row];
  146. // end
  147. section = [XLFormSectionDescriptor formSection];
  148. [form addFormSection:section];
  149. self.form = form;
  150. }
  151. - (void)viewDidLoad
  152. {
  153. [super viewDidLoad];
  154. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  155. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  156. [self initializeForm];
  157. }
  158. - (void)viewWillAppear:(BOOL)animated
  159. {
  160. [super viewWillAppear:animated];
  161. self.tableView.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
  162. self.tableView.showsVerticalScrollIndicator = NO;
  163. self.tableView.separatorColor = NCBrandColor.sharedInstance.separator;
  164. // Color
  165. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  166. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  167. // Request permission for camera roll access
  168. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  169. switch (status) {
  170. case PHAuthorizationStatusRestricted:
  171. NSLog(@"[LOG] user can't grant access to camera roll");
  172. break;
  173. case PHAuthorizationStatusDenied:
  174. NSLog(@"[LOG] user denied access to camera roll");
  175. break;
  176. default:
  177. break;
  178. }
  179. }];
  180. [self reloadForm];
  181. }
  182. - (void)changeTheming
  183. {
  184. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil];
  185. [self initializeForm];
  186. }
  187. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  188. {
  189. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  190. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  191. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  192. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  193. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  194. // Default
  195. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:nil];
  196. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:nil activeUrl:appDelegate.activeUrl];
  197. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  198. if (account.autoUploadImage == NO && account.autoUploadVideo == NO) {
  199. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  200. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  201. }
  202. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  203. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  204. });
  205. } else {
  206. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  207. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  208. // remove
  209. [[NCManageDatabase sharedInstance] clearMetadatasUploadWithAccount:appDelegate.activeAccount];
  210. }
  211. [self reloadForm];
  212. }
  213. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  214. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  215. BOOL isLocationIsEnabled = NO;
  216. [[NCAutoUpload sharedInstance] checkIfLocationIsEnabled];
  217. if(isLocationIsEnabled == YES) {
  218. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  219. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  220. [alertController addAction:okAction];
  221. [self presentViewController:alertController animated:YES completion:nil];
  222. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  223. } else {
  224. [self reloadForm];
  225. }
  226. } else {
  227. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  228. [[CCManageLocation sharedInstance] stopSignificantChangeUpdates];
  229. }
  230. }
  231. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  232. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  233. [[NCAutoUpload sharedInstance] setupAutoUploadFull];
  234. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  235. } else {
  236. [[NCManageDatabase sharedInstance] clearMetadatasUploadWithAccount:appDelegate.activeAccount];
  237. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  238. }
  239. }
  240. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  241. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  242. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  243. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  244. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  245. });
  246. }
  247. }
  248. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  249. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  250. }
  251. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  252. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  253. if ([[rowDescriptor.value valueData] boolValue] == YES){
  254. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  255. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  256. });
  257. }
  258. }
  259. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  260. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  261. }
  262. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  263. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  264. }
  265. }
  266. - (void)done:(XLFormRowDescriptor *)sender
  267. {
  268. [self dismissViewControllerAnimated:YES completion:nil];
  269. }
  270. - (void)reloadForm
  271. {
  272. self.form.delegate = nil;
  273. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  274. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  275. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  276. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  277. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  278. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  279. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  280. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  281. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  282. // - STATUS ---------------------
  283. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  284. if (tableAccount.autoUpload)
  285. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  286. if (tableAccount.autoUploadImage)
  287. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  288. if (tableAccount.autoUploadWWAnPhoto)
  289. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  290. if (tableAccount.autoUploadVideo)
  291. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  292. if (tableAccount.autoUploadWWAnVideo)
  293. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  294. if (tableAccount.autoUploadBackground)
  295. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  296. if (tableAccount.autoUploadFull)
  297. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  298. if (tableAccount.autoUploadCreateSubfolder)
  299. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  300. // - HIDDEN --------------------------------------------------------------------------
  301. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  302. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  303. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  304. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  305. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  306. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  307. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  308. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  309. // -----------------------------------------------------------------------------------
  310. [self.tableView reloadData];
  311. self.form.delegate = self;
  312. }
  313. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  314. {
  315. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  316. NSString *sectionName;
  317. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl], [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName]];
  318. switch (section)
  319. {
  320. case 0:
  321. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  322. break;
  323. case 1:
  324. if (tableAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath activeUrl:appDelegate.activeUrl]];
  325. else sectionName = @"";
  326. break;
  327. case 4:
  328. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  329. else sectionName = @"";
  330. break;
  331. case 5:
  332. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  333. else sectionName = @"";
  334. break;
  335. case 6:
  336. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  337. else sectionName = @"";
  338. break;
  339. case 7:
  340. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  341. else sectionName = @"";
  342. break;
  343. }
  344. return sectionName;
  345. }
  346. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  347. {
  348. if (serverUrl != nil) {
  349. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  350. [appDelegate messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  351. return;
  352. }
  353. // Clear data (old) Auto Upload
  354. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:[[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl] account:appDelegate.activeAccount];
  355. // Settings new folder Automatatic upload
  356. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:[CCUtility getLastPathFromServerUrl:serverUrl activeUrl:appDelegate.activeUrl]];
  357. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:[CCUtility deletingLastPathComponentFromServerUrl:serverUrl] activeUrl:appDelegate.activeUrl];
  358. // Clear data new Auto Upload
  359. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  360. }
  361. }
  362. - (void)selectAutomaticUploadFolder
  363. {
  364. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  365. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  366. viewController.delegate = self;
  367. viewController.hideButtonCreateFolder = false;
  368. viewController.selectFile = false;
  369. viewController.includeDirectoryE2EEncryption = false;
  370. viewController.includeImages = false;
  371. viewController.type = @"";
  372. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  373. viewController.layoutViewSelect = k_layout_view_move;
  374. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  375. [self presentViewController:navigationController animated:YES completion:nil];
  376. }
  377. @end