CCManageAutoUpload.m 22 KB

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