CCManageAutoUpload.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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 <Photos/Photos.h>
  24. #import "CCManageAutoUpload.h"
  25. #import "CCUtility.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.backgroundView;
  45. if (tableAccount.autoUpload) row.value = @1;
  46. else row.value = @0;
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  48. [row.cellConfig setObject:NCBrandColor.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.backgroundView;
  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.backgroundView;
  69. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  70. if (tableAccount.autoUploadImage) row.value = @1;
  71. else row.value = @0;
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  73. [row.cellConfig setObject:NCBrandColor.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.backgroundView;
  77. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  78. if (tableAccount.autoUploadWWAnPhoto) row.value = @1;
  79. else row.value = @0;
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:NCBrandColor.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.backgroundView;
  88. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  89. if (tableAccount.autoUploadVideo) row.value = @1;
  90. else row.value = @0;
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:NCBrandColor.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.backgroundView;
  96. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  97. if (tableAccount.autoUploadWWAnVideo) row.value = @1;
  98. else row.value = @0;
  99. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  100. [row.cellConfig setObject:NCBrandColor.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.backgroundView;
  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.backgroundView;
  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.backgroundView;
  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.backgroundView;
  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.backgroundView;
  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. #pragma mark - Life Cycle
  164. - (void)viewDidLoad
  165. {
  166. [super viewDidLoad];
  167. self.title = NSLocalizedString(@"_settings_autoupload_", nil);
  168. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  169. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:NCGlobal.shared.notificationCenterChangeTheming object:nil];
  170. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain) name:NCGlobal.shared.notificationCenterInitializeMain object:nil];
  171. [self changeTheming];
  172. }
  173. - (void)viewWillAppear:(BOOL)animated
  174. {
  175. [super viewWillAppear:animated];
  176. appDelegate.activeViewController = self;
  177. [self initializeForm];
  178. [self reloadForm];
  179. // Request permission for camera roll access
  180. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  181. switch (status) {
  182. case PHAuthorizationStatusRestricted:
  183. NSLog(@"[LOG] user can't grant access to camera roll");
  184. break;
  185. case PHAuthorizationStatusDenied:
  186. NSLog(@"[LOG] user denied access to camera roll");
  187. break;
  188. default:
  189. break;
  190. }
  191. }];
  192. }
  193. - (void)initializeMain
  194. {
  195. [[self navigationController] popViewControllerAnimated:YES];
  196. }
  197. #pragma mark - NotificationCenter
  198. - (void)changeTheming
  199. {
  200. self.view.backgroundColor = NCBrandColor.shared.backgroundForm;
  201. self.tableView.backgroundColor = NCBrandColor.shared.backgroundForm;
  202. [self.tableView reloadData];
  203. [self initializeForm];
  204. [self reloadForm];
  205. }
  206. #pragma mark -
  207. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  208. {
  209. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  210. tableAccount *account = [[NCManageDatabase shared] getAccountActive];
  211. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  212. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  213. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  214. // Default
  215. [[NCManageDatabase shared] setAccountAutoUploadFileName:nil];
  216. [[NCManageDatabase shared] setAccountAutoUploadDirectory:nil urlBase:appDelegate.urlBase account:appDelegate.account];
  217. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  218. if (account.autoUploadImage == NO && account.autoUploadVideo == NO) {
  219. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  220. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  221. }
  222. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  223. } else {
  224. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  225. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  226. // remove
  227. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  228. }
  229. [self reloadForm];
  230. }
  231. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  232. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadDeleteAssetLocalIdentifier" state:[[rowDescriptor.value valueData] boolValue]];
  233. }
  234. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  235. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  236. [[NCAskAuthorization shared] askAuthorizationLocationManagerWithCompletion: ^(BOOL hasFullPermissions) {
  237. if (hasFullPermissions == YES) {
  238. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  239. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  240. [alertController addAction:okAction];
  241. [self presentViewController:alertController animated:YES completion:nil];
  242. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  243. [[NCAutoUpload shared] startSignificantChangeUpdates];
  244. } else {
  245. [self reloadForm];
  246. }
  247. }];
  248. } else {
  249. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  250. [[NCAutoUpload shared] stopSignificantChangeUpdates];
  251. }
  252. }
  253. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  254. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  255. [[NCAutoUpload shared] autoUploadFullPhotosWithViewController:self log:@"Auto upload full"];
  256. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  257. } else {
  258. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  259. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  260. }
  261. }
  262. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  263. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  264. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  265. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  266. }
  267. }
  268. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  269. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  270. }
  271. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  272. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  273. if ([[rowDescriptor.value valueData] boolValue] == YES){
  274. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  275. }
  276. }
  277. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  278. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  279. }
  280. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  281. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  282. }
  283. }
  284. - (void)done:(XLFormRowDescriptor *)sender
  285. {
  286. [self dismissViewControllerAnimated:YES completion:nil];
  287. }
  288. - (void)reloadForm
  289. {
  290. self.form.delegate = nil;
  291. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  292. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  293. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  294. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  295. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  296. XLFormRowDescriptor *rowRemovePhotoCameraRoll = [self.form formRowWithTag:@"removePhotoCameraRoll"];
  297. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  298. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  299. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  300. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  301. // - STATUS ---------------------
  302. tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
  303. if (tableAccount.autoUpload)
  304. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  305. if (tableAccount.autoUploadImage)
  306. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  307. if (tableAccount.autoUploadWWAnPhoto)
  308. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  309. if (tableAccount.autoUploadVideo)
  310. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  311. if (tableAccount.autoUploadWWAnVideo)
  312. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  313. if (tableAccount.autoUploadDeleteAssetLocalIdentifier)
  314. [rowRemovePhotoCameraRoll setValue:@1]; else [rowRemovePhotoCameraRoll setValue:@0];
  315. if (tableAccount.autoUploadBackground)
  316. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  317. if (tableAccount.autoUploadFull)
  318. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  319. if (tableAccount.autoUploadCreateSubfolder)
  320. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  321. // - HIDDEN --------------------------------------------------------------------------
  322. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  323. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  324. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  325. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  326. rowRemovePhotoCameraRoll.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  327. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  328. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  329. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  330. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  331. // -----------------------------------------------------------------------------------
  332. [self.tableView reloadData];
  333. self.form.delegate = self;
  334. }
  335. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  336. {
  337. tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
  338. NSString *sectionName;
  339. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase shared] getAccountAutoUploadDirectoryWithUrlBase:appDelegate.urlBase account:appDelegate.account], [[NCManageDatabase shared] getAccountAutoUploadFileName]];
  340. switch (section)
  341. {
  342. case 0:
  343. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  344. break;
  345. case 1:
  346. if (tableAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath urlBase:appDelegate.urlBase account:appDelegate.account]];
  347. else sectionName = @"";
  348. break;
  349. case 4:
  350. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil);
  351. else sectionName = @"";
  352. break;
  353. case 5:
  354. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  355. else sectionName = @"";
  356. break;
  357. case 6:
  358. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  359. else sectionName = @"";
  360. break;
  361. case 7:
  362. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  363. else sectionName = @"";
  364. break;
  365. case 8:
  366. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  367. else sectionName = @"";
  368. break;
  369. }
  370. return sectionName;
  371. }
  372. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  373. {
  374. if (serverUrl != nil) {
  375. if ([serverUrl isEqualToString:[[NCUtilityFileSystem shared] getHomeServerWithUrlBase:appDelegate.urlBase account:appDelegate.account]]) {
  376. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError errorCode:NCGlobal.shared.ErrorInternalError forced:true];
  377. return;
  378. }
  379. // Settings new folder Automatatic upload
  380. [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
  381. [[NCManageDatabase shared] setAccountAutoUploadDirectory:[[NCUtilityFileSystem shared] deletingLastPathComponentWithServerUrl:serverUrl urlBase:appDelegate.urlBase account:appDelegate.account] urlBase:appDelegate.urlBase account:appDelegate.account];
  382. }
  383. }
  384. - (void)selectAutomaticUploadFolder
  385. {
  386. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  387. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  388. viewController.delegate = self;
  389. viewController.hideButtonCreateFolder = false;
  390. viewController.selectFile = false;
  391. viewController.includeDirectoryE2EEncryption = false;
  392. viewController.includeImages = false;
  393. viewController.type = @"";
  394. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  395. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  396. [self presentViewController:navigationController animated:YES completion:^{
  397. [self.tableView reloadData];
  398. }];
  399. }
  400. @end