CCManageAutoUpload.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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 "CCManageAutoUpload.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCManageAutoUpload () <NCSelectDelegate>
  27. {
  28. AppDelegate *appDelegate;
  29. }
  30. @end
  31. @implementation CCManageAutoUpload
  32. - (void)initializeForm
  33. {
  34. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  35. XLFormSectionDescriptor *section;
  36. XLFormRowDescriptor *row;
  37. tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
  38. // Auto Upload
  39. section = [XLFormSectionDescriptor formSection];
  40. [form addFormSection:section];
  41. section.footerTitle = NSLocalizedString(@"_autoupload_description_", nil);
  42. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_", nil)];
  43. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  44. if (tableAccount.autoUpload) row.value = @1;
  45. else row.value = @0;
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  48. [section addFormRow:row];
  49. // Auto Upload Directory
  50. section = [XLFormSectionDescriptor formSection];
  51. [form addFormSection:section];
  52. // Lock active YES/NO
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadDirectory" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_select_folder_", nil)];
  54. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  55. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  56. [row.cellConfig setObject:[[UIImage imageNamed:@"folderAutomaticUpload"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
  57. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  58. [row.cellConfig setObject:NCBrandColor.shared.textView 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"] = NCBrandColor.shared.backgroundCell;
  68. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  69. if (tableAccount.autoUploadImage) row.value = @1;
  70. else row.value = @0;
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  72. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  73. [section addFormRow:row];
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  75. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  76. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  77. if (tableAccount.autoUploadWWAnPhoto) row.value = @1;
  78. else row.value = @0;
  79. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  80. [row.cellConfig setObject:NCBrandColor.shared.textView 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"] = NCBrandColor.shared.backgroundCell;
  87. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  88. if (tableAccount.autoUploadVideo) row.value = @1;
  89. else row.value = @0;
  90. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  91. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  92. [section addFormRow:row];
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  94. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  95. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  96. if (tableAccount.autoUploadWWAnVideo) row.value = @1;
  97. else row.value = @0;
  98. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  99. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  100. [section addFormRow:row];
  101. // Delete asset
  102. section = [XLFormSectionDescriptor formSection];
  103. [form addFormSection:section];
  104. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"removePhotoCameraRoll" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_remove_photo_CameraRoll_", nil)];
  105. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  106. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  107. if (tableAccount.autoUploadDeleteAssetLocalIdentifier) row.value = @1;
  108. else row.value = @0;
  109. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  110. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  111. [section addFormRow:row];
  112. // Auto Upload Background
  113. section = [XLFormSectionDescriptor formSection];
  114. [form addFormSection:section];
  115. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadBackground" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_background_", nil)];
  116. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  117. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  118. if (tableAccount.autoUploadBackground) row.value = @1;
  119. else row.value = @0;
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  121. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  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.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  129. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  130. row.value = 0;
  131. if (tableAccount.autoUploadFull) row.value = @1;
  132. else row.value = @0;
  133. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  134. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  135. [section addFormRow:row];
  136. // Auto Upload create subfolder
  137. section = [XLFormSectionDescriptor formSection];
  138. [form addFormSection:section];
  139. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadCreateSubfolder" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_create_subfolder_", nil)];
  140. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  141. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  142. if (tableAccount.autoUploadCreateSubfolder) row.value = @1;
  143. else row.value = @0;
  144. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  145. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  146. [section addFormRow:row];
  147. // Auto Upload file name
  148. section = [XLFormSectionDescriptor formSection];
  149. [form addFormSection:section];
  150. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFileName" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_filenamemask_", nil)];
  151. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
  152. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  153. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  154. row.action.viewControllerClass = [NCManageAutoUploadFileName class];
  155. [section addFormRow:row];
  156. // end
  157. section = [XLFormSectionDescriptor formSection];
  158. [form addFormSection:section];
  159. self.tableView.showsVerticalScrollIndicator = NO;
  160. self.form = form;
  161. }
  162. - (void)viewDidLoad
  163. {
  164. [super viewDidLoad];
  165. self.title = NSLocalizedString(@"_settings_autoupload_", nil);
  166. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  167. // changeTheming
  168. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:NCBrandGlobal.shared.notificationCenterChangeTheming object:nil];
  169. [self changeTheming];
  170. }
  171. - (void)viewWillAppear:(BOOL)animated
  172. {
  173. [super viewWillAppear:animated];
  174. // Request permission for camera roll access
  175. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  176. switch (status) {
  177. case PHAuthorizationStatusRestricted:
  178. NSLog(@"[LOG] user can't grant access to camera roll");
  179. break;
  180. case PHAuthorizationStatusDenied:
  181. NSLog(@"[LOG] user denied access to camera roll");
  182. break;
  183. default:
  184. break;
  185. }
  186. }];
  187. }
  188. - (void)changeTheming
  189. {
  190. self.view.backgroundColor = NCBrandColor.shared.backgroundForm;
  191. self.tableView.backgroundColor = NCBrandColor.shared.backgroundForm;
  192. [self.tableView reloadData];
  193. [self initializeForm];
  194. [self reloadForm];
  195. }
  196. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  197. {
  198. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  199. tableAccount *account = [[NCManageDatabase shared] getAccountActive];
  200. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  201. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  202. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  203. // Default
  204. [[NCManageDatabase shared] setAccountAutoUploadFileName:nil];
  205. [[NCManageDatabase shared] setAccountAutoUploadDirectory:nil urlBase:appDelegate.urlBase account:appDelegate.account];
  206. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  207. if (account.autoUploadImage == NO && account.autoUploadVideo == NO) {
  208. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  209. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  210. }
  211. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  212. } else {
  213. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  214. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  215. // remove
  216. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  217. }
  218. [self reloadForm];
  219. }
  220. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  221. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadDeleteAssetLocalIdentifier" state:[[rowDescriptor.value valueData] boolValue]];
  222. }
  223. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  224. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  225. [[NCAskAuthorization shared] askAuthorizationLocationManagerWithCompletion: ^(BOOL hasFullPermissions) {
  226. if (hasFullPermissions == YES) {
  227. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  228. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  229. [alertController addAction:okAction];
  230. [self presentViewController:alertController animated:YES completion:nil];
  231. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  232. [[NCAutoUpload shared] startSignificantChangeUpdates];
  233. } else {
  234. [self reloadForm];
  235. }
  236. }];
  237. } else {
  238. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  239. [[NCAutoUpload shared] stopSignificantChangeUpdates];
  240. }
  241. }
  242. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  243. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  244. [[NCAutoUpload shared] autoUploadFullPhotosWithViewController:self log:@"Auto upload full"];
  245. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  246. } else {
  247. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  248. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  249. }
  250. }
  251. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  252. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  253. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  254. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  255. }
  256. }
  257. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  258. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  259. }
  260. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  261. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  262. if ([[rowDescriptor.value valueData] boolValue] == YES){
  263. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  264. }
  265. }
  266. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  267. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  268. }
  269. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  270. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  271. }
  272. }
  273. - (void)done:(XLFormRowDescriptor *)sender
  274. {
  275. [self dismissViewControllerAnimated:YES completion:nil];
  276. }
  277. - (void)reloadForm
  278. {
  279. self.form.delegate = nil;
  280. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  281. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  282. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  283. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  284. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  285. XLFormRowDescriptor *rowRemovePhotoCameraRoll = [self.form formRowWithTag:@"removePhotoCameraRoll"];
  286. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  287. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  288. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  289. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  290. // - STATUS ---------------------
  291. tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
  292. if (tableAccount.autoUpload)
  293. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  294. if (tableAccount.autoUploadImage)
  295. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  296. if (tableAccount.autoUploadWWAnPhoto)
  297. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  298. if (tableAccount.autoUploadVideo)
  299. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  300. if (tableAccount.autoUploadWWAnVideo)
  301. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  302. if (tableAccount.autoUploadDeleteAssetLocalIdentifier)
  303. [rowRemovePhotoCameraRoll setValue:@1]; else [rowRemovePhotoCameraRoll setValue:@0];
  304. if (tableAccount.autoUploadBackground)
  305. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  306. if (tableAccount.autoUploadFull)
  307. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  308. if (tableAccount.autoUploadCreateSubfolder)
  309. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  310. // - HIDDEN --------------------------------------------------------------------------
  311. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  312. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  313. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  314. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  315. rowRemovePhotoCameraRoll.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  316. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  317. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  318. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  319. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  320. // -----------------------------------------------------------------------------------
  321. [self.tableView reloadData];
  322. self.form.delegate = self;
  323. }
  324. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  325. {
  326. tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
  327. NSString *sectionName;
  328. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase shared] getAccountAutoUploadDirectoryWithUrlBase:appDelegate.urlBase account:appDelegate.account], [[NCManageDatabase shared] getAccountAutoUploadFileName]];
  329. switch (section)
  330. {
  331. case 0:
  332. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  333. break;
  334. case 1:
  335. if (tableAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath urlBase:appDelegate.urlBase account:appDelegate.account]];
  336. else sectionName = @"";
  337. break;
  338. case 4:
  339. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil);
  340. else sectionName = @"";
  341. break;
  342. case 5:
  343. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  344. else sectionName = @"";
  345. break;
  346. case 6:
  347. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  348. else sectionName = @"";
  349. break;
  350. case 7:
  351. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  352. else sectionName = @"";
  353. break;
  354. case 8:
  355. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  356. else sectionName = @"";
  357. break;
  358. }
  359. return sectionName;
  360. }
  361. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  362. {
  363. if (serverUrl != nil) {
  364. if ([serverUrl isEqualToString:[[NCUtilityFileSystem shared] getHomeServerWithUrlBase:appDelegate.urlBase account:appDelegate.account]]) {
  365. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" delay:[[NCBrandGlobal shared] dismissAfterSecond] type:messageTypeError errorCode:NCBrandGlobal.shared.ErrorInternalError forced:true];
  366. return;
  367. }
  368. // Settings new folder Automatatic upload
  369. [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
  370. [[NCManageDatabase shared] setAccountAutoUploadDirectory:[[NCUtilityFileSystem shared] deletingLastPathComponentWithServerUrl:serverUrl urlBase:appDelegate.urlBase account:appDelegate.account] urlBase:appDelegate.urlBase account:appDelegate.account];
  371. }
  372. }
  373. - (void)selectAutomaticUploadFolder
  374. {
  375. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  376. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  377. viewController.delegate = self;
  378. viewController.hideButtonCreateFolder = false;
  379. viewController.selectFile = false;
  380. viewController.includeDirectoryE2EEncryption = false;
  381. viewController.includeImages = false;
  382. viewController.type = @"";
  383. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  384. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  385. [self presentViewController:navigationController animated:YES completion:^{
  386. [self.tableView reloadData];
  387. }];
  388. }
  389. @end