CCManageAutoUpload.m 24 KB

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