CCManageAutoUpload.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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 *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  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.secondarySystemGroupedBackground;
  45. if (activeAccount.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.label forKey:@"textLabel.textColor"];
  49. [section addFormRow:row];
  50. // Auto Upload Directory
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadDirectory" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_select_folder_", nil)];
  54. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  55. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  56. [row.cellConfig setObject:[[UIImage imageNamed:@"foldersOnTop"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  57. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  58. [row.cellConfig setObject:NCBrandColor.shared.label 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.secondarySystemGroupedBackground;
  68. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  69. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  76. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  77. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  87. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  88. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  95. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  96. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  106. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  107. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  117. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  118. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  129. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  130. row.value = 0;
  131. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  141. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  142. if (activeAccount.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.label 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.secondarySystemGroupedBackground;
  152. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  153. [row.cellConfig setObject:NCBrandColor.shared.label 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. // MARK: - View Life Cycle
  163. - (void)viewDidLoad
  164. {
  165. [super viewDidLoad];
  166. self.title = NSLocalizedString(@"_settings_autoupload_", nil);
  167. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  168. self.view.backgroundColor = NCBrandColor.shared.systemGroupedBackground;
  169. self.tableView.backgroundColor = NCBrandColor.shared.systemGroupedBackground;
  170. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initialize) name:NCGlobal.shared.notificationCenterInitialize object:nil];
  171. [self initializeForm];
  172. [self reloadForm];
  173. }
  174. - (void)viewWillAppear:(BOOL)animated
  175. {
  176. [super viewWillAppear:animated];
  177. appDelegate.activeViewController = self;
  178. // Request permission for camera roll access
  179. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  180. switch (status) {
  181. case PHAuthorizationStatusRestricted:
  182. NSLog(@"[LOG] user can't grant access to camera roll");
  183. break;
  184. case PHAuthorizationStatusDenied:
  185. NSLog(@"[LOG] user denied access to camera roll");
  186. break;
  187. default:
  188. break;
  189. }
  190. }];
  191. }
  192. - (void)initialize
  193. {
  194. [[self navigationController] popViewControllerAnimated:YES];
  195. }
  196. #pragma mark - NotificationCenter
  197. #pragma mark -
  198. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  199. {
  200. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  201. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  202. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  203. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  204. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  205. // Default
  206. [[NCManageDatabase shared] setAccountAutoUploadFileName:nil];
  207. [[NCManageDatabase shared] setAccountAutoUploadDirectory:nil urlBase:appDelegate.urlBase account:appDelegate.account];
  208. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  209. if (activeAccount.autoUploadImage == NO && activeAccount.autoUploadVideo == NO) {
  210. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  211. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  212. }
  213. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  214. } else {
  215. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  216. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  217. // remove
  218. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  219. }
  220. [self reloadForm];
  221. }
  222. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  223. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadDeleteAssetLocalIdentifier" state:[[rowDescriptor.value valueData] boolValue]];
  224. }
  225. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  226. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  227. [[NCAskAuthorization shared] askAuthorizationLocationManagerWithCompletion: ^(BOOL hasFullPermissions) {
  228. if (hasFullPermissions == YES) {
  229. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  230. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  231. [alertController addAction:okAction];
  232. [self presentViewController:alertController animated:YES completion:nil];
  233. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  234. [[NCAutoUpload shared] startSignificantChangeUpdates];
  235. } else {
  236. [self reloadForm];
  237. }
  238. }];
  239. } else {
  240. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  241. [[NCAutoUpload shared] stopSignificantChangeUpdates];
  242. }
  243. }
  244. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  245. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  246. [[NCAutoUpload shared] autoUploadFullPhotosWithViewController:self log:@"Auto upload full"];
  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. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  257. }
  258. }
  259. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  260. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  261. }
  262. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  263. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  264. if ([[rowDescriptor.value valueData] boolValue] == YES){
  265. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  266. }
  267. }
  268. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  269. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  270. }
  271. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  272. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  273. }
  274. }
  275. - (void)done:(XLFormRowDescriptor *)sender
  276. {
  277. [self dismissViewControllerAnimated:YES completion:nil];
  278. }
  279. - (void)reloadForm
  280. {
  281. self.form.delegate = nil;
  282. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  283. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  284. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  285. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  286. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  287. XLFormRowDescriptor *rowRemovePhotoCameraRoll = [self.form formRowWithTag:@"removePhotoCameraRoll"];
  288. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  289. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  290. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  291. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  292. // - STATUS ---------------------
  293. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  294. if (activeAccount.autoUpload)
  295. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  296. if (activeAccount.autoUploadImage)
  297. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  298. if (activeAccount.autoUploadWWAnPhoto)
  299. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  300. if (activeAccount.autoUploadVideo)
  301. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  302. if (activeAccount.autoUploadWWAnVideo)
  303. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  304. if (activeAccount.autoUploadDeleteAssetLocalIdentifier)
  305. [rowRemovePhotoCameraRoll setValue:@1]; else [rowRemovePhotoCameraRoll setValue:@0];
  306. if (activeAccount.autoUploadBackground)
  307. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  308. if (activeAccount.autoUploadFull)
  309. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  310. if (activeAccount.autoUploadCreateSubfolder)
  311. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  312. // - HIDDEN --------------------------------------------------------------------------
  313. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  314. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  315. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  316. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  317. rowRemovePhotoCameraRoll.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  318. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  319. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  320. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  321. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  322. // -----------------------------------------------------------------------------------
  323. [self.tableView reloadData];
  324. self.form.delegate = self;
  325. }
  326. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  327. return NCGlobal.shared.heightCellSettings;
  328. }
  329. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  330. {
  331. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  332. NSString *sectionName;
  333. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase shared] getAccountAutoUploadDirectoryWithUrlBase:appDelegate.urlBase account:appDelegate.account], [[NCManageDatabase shared] getAccountAutoUploadFileName]];
  334. switch (section)
  335. {
  336. case 0:
  337. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  338. break;
  339. case 1:
  340. if (activeAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath urlBase:appDelegate.urlBase account:appDelegate.account]];
  341. else sectionName = @"";
  342. break;
  343. case 4:
  344. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil);
  345. else sectionName = @"";
  346. break;
  347. case 5:
  348. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  349. else sectionName = @"";
  350. break;
  351. case 6:
  352. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  353. else sectionName = @"";
  354. break;
  355. case 7:
  356. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  357. else sectionName = @"";
  358. break;
  359. case 8:
  360. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  361. else sectionName = @"";
  362. break;
  363. }
  364. return sectionName;
  365. }
  366. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items overwrite:(BOOL)overwrite copy:(BOOL)copy move:(BOOL)move
  367. {
  368. if (serverUrl != nil) {
  369. if ([serverUrl isEqualToString:[[NCUtilityFileSystem shared] getHomeServerWithAccount:appDelegate.account]]) {
  370. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError errorCode:NCGlobal.shared.errorInternalError forced:true];
  371. return;
  372. }
  373. // Settings new folder Automatatic upload
  374. [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
  375. [[NCManageDatabase shared] setAccountAutoUploadDirectory:[[NCUtilityFileSystem shared] deletingLastPathComponentWithAccount:appDelegate.account serverUrl:serverUrl] urlBase:appDelegate.urlBase account:appDelegate.account];
  376. // Reload
  377. [self.tableView reloadData];
  378. }
  379. }
  380. - (void)selectAutomaticUploadFolder
  381. {
  382. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  383. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  384. viewController.delegate = self;
  385. viewController.typeOfCommandView = 1;
  386. [self presentViewController:navigationController animated:YES completion:^{
  387. [self.tableView reloadData];
  388. }];
  389. }
  390. @end