CCManageAutoUpload.m 24 KB

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