CCManageAutoUpload.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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.cellSettings;
  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.textView 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.cellSettings;
  55. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  56. [row.cellConfig setObject:[[UIImage imageNamed:@"foldersOnTop"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
  57. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  58. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  59. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  60. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  61. row.action.formSelector = @selector(selectAutomaticUploadFolder);
  62. [section addFormRow:row];
  63. // Auto Upload Photo
  64. section = [XLFormSectionDescriptor formSection];
  65. [form addFormSection:section];
  66. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadImage" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_photos_", nil)];
  67. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  73. [section addFormRow:row];
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  75. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  81. [section addFormRow:row];
  82. // Auto Upload Video
  83. section = [XLFormSectionDescriptor formSection];
  84. [form addFormSection:section];
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_videos_", nil)];
  86. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  92. [section addFormRow:row];
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  94. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  100. [section addFormRow:row];
  101. // Delete asset
  102. section = [XLFormSectionDescriptor formSection];
  103. [form addFormSection:section];
  104. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"removePhotoCameraRoll" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_remove_photo_CameraRoll_", nil)];
  105. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  111. [section addFormRow:row];
  112. // Auto Upload Background
  113. section = [XLFormSectionDescriptor formSection];
  114. [form addFormSection:section];
  115. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadBackground" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_background_", nil)];
  116. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  122. [section addFormRow:row];
  123. // Auto Upload Full
  124. section = [XLFormSectionDescriptor formSection];
  125. [form addFormSection:section];
  126. NSString *title = NSLocalizedString(@"_autoupload_fullphotos_", nil);
  127. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFull" rowType:XLFormRowDescriptorTypeBooleanSwitch title:title];
  128. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  135. [section addFormRow:row];
  136. // Auto Upload create subfolder
  137. section = [XLFormSectionDescriptor formSection];
  138. [form addFormSection:section];
  139. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadCreateSubfolder" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_create_subfolder_", nil)];
  140. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  146. [section addFormRow:row];
  147. // Auto Upload file name
  148. section = [XLFormSectionDescriptor formSection];
  149. [form addFormSection:section];
  150. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFileName" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_filenamemask_", nil)];
  151. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
  152. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  153. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  154. row.action.viewControllerClass = [NCManageAutoUploadFileName class];
  155. [section addFormRow:row];
  156. // end
  157. section = [XLFormSectionDescriptor formSection];
  158. [form addFormSection:section];
  159. self.tableView.showsVerticalScrollIndicator = NO;
  160. self.form = form;
  161. }
  162. #pragma mark - Life Cycle
  163. - (void)viewDidLoad
  164. {
  165. [super viewDidLoad];
  166. self.title = NSLocalizedString(@"_settings_autoupload_", nil);
  167. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  168. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:NCGlobal.shared.notificationCenterChangeTheming object:nil];
  169. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain) name:NCGlobal.shared.notificationCenterInitializeMain object:nil];
  170. [self changeTheming];
  171. }
  172. - (void)viewWillAppear:(BOOL)animated
  173. {
  174. [super viewWillAppear:animated];
  175. appDelegate.activeViewController = self;
  176. [self initializeForm];
  177. [self reloadForm];
  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)initializeMain
  193. {
  194. [[self navigationController] popViewControllerAnimated:YES];
  195. }
  196. #pragma mark - NotificationCenter
  197. - (void)changeTheming
  198. {
  199. self.view.backgroundColor = NCBrandColor.shared.backgroundSettings;
  200. self.tableView.backgroundColor = NCBrandColor.shared.backgroundSettings;
  201. [self.tableView reloadData];
  202. [self initializeForm];
  203. [self reloadForm];
  204. }
  205. #pragma mark -
  206. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  207. {
  208. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  209. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  210. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  211. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  212. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  213. // Default
  214. [[NCManageDatabase shared] setAccountAutoUploadFileName:nil];
  215. [[NCManageDatabase shared] setAccountAutoUploadDirectory:nil urlBase:appDelegate.urlBase account:appDelegate.account];
  216. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  217. if (activeAccount.autoUploadImage == NO && activeAccount.autoUploadVideo == NO) {
  218. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  219. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  220. }
  221. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  222. } else {
  223. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  224. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  225. // remove
  226. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  227. }
  228. [self reloadForm];
  229. }
  230. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  231. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadDeleteAssetLocalIdentifier" state:[[rowDescriptor.value valueData] boolValue]];
  232. }
  233. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  234. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  235. [[NCAskAuthorization shared] askAuthorizationLocationManagerWithCompletion: ^(BOOL hasFullPermissions) {
  236. if (hasFullPermissions == YES) {
  237. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  238. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  239. [alertController addAction:okAction];
  240. [self presentViewController:alertController animated:YES completion:nil];
  241. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  242. [[NCAutoUpload shared] startSignificantChangeUpdates];
  243. } else {
  244. [self reloadForm];
  245. }
  246. }];
  247. } else {
  248. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  249. [[NCAutoUpload shared] stopSignificantChangeUpdates];
  250. }
  251. }
  252. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  253. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  254. [[NCAutoUpload shared] autoUploadFullPhotosWithViewController:self log:@"Auto upload full"];
  255. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  256. } else {
  257. [[NCManageDatabase shared] clearMetadatasUploadWithAccount:appDelegate.account];
  258. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  259. }
  260. }
  261. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  262. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  263. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  264. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  265. }
  266. }
  267. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  268. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  269. }
  270. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  271. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  272. if ([[rowDescriptor.value valueData] boolValue] == YES){
  273. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  274. }
  275. }
  276. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  277. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  278. }
  279. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  280. [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  281. }
  282. }
  283. - (void)done:(XLFormRowDescriptor *)sender
  284. {
  285. [self dismissViewControllerAnimated:YES completion:nil];
  286. }
  287. - (void)reloadForm
  288. {
  289. self.form.delegate = nil;
  290. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  291. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  292. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  293. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  294. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  295. XLFormRowDescriptor *rowRemovePhotoCameraRoll = [self.form formRowWithTag:@"removePhotoCameraRoll"];
  296. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  297. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  298. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  299. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  300. // - STATUS ---------------------
  301. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  302. if (activeAccount.autoUpload)
  303. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  304. if (activeAccount.autoUploadImage)
  305. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  306. if (activeAccount.autoUploadWWAnPhoto)
  307. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  308. if (activeAccount.autoUploadVideo)
  309. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  310. if (activeAccount.autoUploadWWAnVideo)
  311. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  312. if (activeAccount.autoUploadDeleteAssetLocalIdentifier)
  313. [rowRemovePhotoCameraRoll setValue:@1]; else [rowRemovePhotoCameraRoll setValue:@0];
  314. if (activeAccount.autoUploadBackground)
  315. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  316. if (activeAccount.autoUploadFull)
  317. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  318. if (activeAccount.autoUploadCreateSubfolder)
  319. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  320. // - HIDDEN --------------------------------------------------------------------------
  321. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  322. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  323. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  324. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  325. rowRemovePhotoCameraRoll.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  326. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  327. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  328. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  329. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  330. // -----------------------------------------------------------------------------------
  331. [self.tableView reloadData];
  332. self.form.delegate = self;
  333. }
  334. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  335. {
  336. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  337. NSString *sectionName;
  338. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase shared] getAccountAutoUploadDirectoryWithUrlBase:appDelegate.urlBase account:appDelegate.account], [[NCManageDatabase shared] getAccountAutoUploadFileName]];
  339. switch (section)
  340. {
  341. case 0:
  342. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  343. break;
  344. case 1:
  345. if (activeAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath urlBase:appDelegate.urlBase account:appDelegate.account]];
  346. else sectionName = @"";
  347. break;
  348. case 4:
  349. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil);
  350. else sectionName = @"";
  351. break;
  352. case 5:
  353. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  354. else sectionName = @"";
  355. break;
  356. case 6:
  357. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  358. else sectionName = @"";
  359. break;
  360. case 7:
  361. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  362. else sectionName = @"";
  363. break;
  364. case 8:
  365. if (activeAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  366. else sectionName = @"";
  367. break;
  368. }
  369. return sectionName;
  370. }
  371. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items overwrite:(BOOL)overwrite copy:(BOOL)copy move:(BOOL)move
  372. {
  373. if (serverUrl != nil) {
  374. if ([serverUrl isEqualToString:[[NCUtilityFileSystem shared] getHomeServerWithUrlBase:appDelegate.urlBase account:appDelegate.account]]) {
  375. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError errorCode:NCGlobal.shared.errorInternalError forced:true];
  376. return;
  377. }
  378. // Settings new folder Automatatic upload
  379. [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
  380. [[NCManageDatabase shared] setAccountAutoUploadDirectory:[[NCUtilityFileSystem shared] deletingLastPathComponentWithServerUrl:serverUrl urlBase:appDelegate.urlBase account:appDelegate.account] urlBase:appDelegate.urlBase account:appDelegate.account];
  381. // Reload
  382. [self.tableView reloadData];
  383. }
  384. }
  385. - (void)selectAutomaticUploadFolder
  386. {
  387. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  388. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  389. viewController.delegate = self;
  390. viewController.typeOfCommandView = 1;
  391. [self presentViewController:navigationController animated:YES completion:^{
  392. [self.tableView reloadData];
  393. }];
  394. }
  395. @end