CCManagePhotos.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // CCManagePhotos.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 22/05/16.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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 "CCManagePhotos.h"
  24. #import "AppDelegate.h"
  25. @implementation CCManagePhotos
  26. // From Settings
  27. - (id)initWithCoder:(NSCoder *)aDecoder
  28. {
  29. if (self = [super initWithCoder:aDecoder]) {
  30. [self initializeForm];
  31. }
  32. return self;
  33. }
  34. - (void)initializeForm
  35. {
  36. XLFormDescriptor *form ;
  37. XLFormSectionDescriptor *section;
  38. XLFormRowDescriptor *row;
  39. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_photo_camera_", nil)];
  40. // Camera Upload change location
  41. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_change_folder_photos_", nil)];
  42. section.footerTitle = NSLocalizedString(@"_upload_camera_change_location_footer_", nil);
  43. [form addFormSection:section];
  44. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"camerauploadlocationnow" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_upload_camera_location_now_", nil)];
  45. row.value = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  48. [section addFormRow:row];
  49. NSString *title = [NSString stringWithFormat:@"%@ : %@", NSLocalizedString(@"_upload_camera_location_default_", nil), folderDefaultCameraUpload];
  50. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"camerauploadlocationdefault" rowType:XLFormRowDescriptorTypeButton title:title];
  51. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  52. [row.cellConfig setObject:[UIImage imageNamed:image_settingsManagePhotos] forKey:@"imageView.image"];
  53. row.action.formSelector = @selector(locationDefault:);
  54. [section addFormRow:row];
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"camerauploadchangelocation" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_upload_camera_change_location_", nil)];
  56. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  57. [row.cellConfig setObject:[UIImage imageNamed:image_settingsManagePhotosChange] forKey:@"imageView.image"];
  58. row.action.formSelector = @selector(changeLocation:);
  59. [section addFormRow:row];
  60. // end
  61. section = [XLFormSectionDescriptor formSection];
  62. [form addFormSection:section];
  63. self.form = form;
  64. }
  65. // Apparirà
  66. - (void)viewWillAppear:(BOOL)animated
  67. {
  68. [super viewWillAppear:animated];
  69. // Color
  70. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  71. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  72. //
  73. [self reloadForm];
  74. }
  75. - (void)move:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  76. {
  77. NSString *fileName, *newPath;
  78. if (serverUrlTo) {
  79. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  80. NSURL *url = [NSURL URLWithString:[serverUrlTo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  81. fileName = [serverUrlTo lastPathComponent];
  82. newPath = [[url URLByDeletingLastPathComponent] absoluteString];
  83. newPath = [newPath substringToIndex:[newPath length] -1];
  84. }
  85. if ([serverUrlTo isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud]]) {
  86. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_camera_upload_not_select_home_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  87. [alertView show];
  88. } else {
  89. NSString *oldPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  90. [CCCoreData setCameraUploadFolderName:fileName activeAccount:app.activeAccount];
  91. [CCCoreData setCameraUploadFolderPath:newPath activeUrl:app.activeUrl typeCloud:app.typeCloud activeAccount:app.activeAccount];
  92. [CCCoreData clearDateReadDirectory:oldPath activeAccount:app.activeAccount];
  93. [CCCoreData clearDateReadDirectory:newPath activeAccount:app.activeAccount];
  94. if (app.activeAccount && app.activeUrl && app.activePhotosCameraUpload)
  95. [app.activePhotosCameraUpload reloadDatasourceForced];
  96. [self reloadForm];
  97. }
  98. }
  99. }
  100. - (void)done:(XLFormRowDescriptor *)sender
  101. {
  102. [self dismissViewControllerAnimated:YES completion:nil];
  103. }
  104. - (void)changeLocation:(XLFormRowDescriptor *)sender
  105. {
  106. [self deselectFormRow:sender];
  107. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  108. CCMove *viewController = (CCMove *)navigationController.topViewController;
  109. viewController.delegate = self;
  110. viewController.move.title = NSLocalizedString(@"_select_", nil);
  111. viewController.onlyClearDirectory = YES;
  112. viewController.tintColor = COLOR_BRAND;
  113. viewController.barTintColor = COLOR_BAR;
  114. viewController.tintColorTitle = COLOR_GRAY;
  115. viewController.networkingOperationQueue = app.netQueue;
  116. [self presentViewController:navigationController animated:YES completion:nil];
  117. }
  118. - (void)locationDefault:(XLFormRowDescriptor *)sender
  119. {
  120. [self deselectFormRow:sender];
  121. NSString *oldPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  122. NSString *newPath = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud];
  123. [CCCoreData setCameraUploadFolderName:folderDefaultCameraUpload activeAccount:app.activeAccount];
  124. [CCCoreData setCameraUploadFolderPath:newPath activeUrl:app.activeUrl typeCloud:app.typeCloud activeAccount:app.activeAccount];
  125. [CCCoreData clearDateReadDirectory:oldPath activeAccount:app.activeAccount];
  126. [CCCoreData clearDateReadDirectory:newPath activeAccount:app.activeAccount];
  127. // rebuild
  128. if (app.activeAccount && app.activeUrl && app.activePhotosCameraUpload)
  129. [app.activePhotosCameraUpload reloadDatasourceForced];
  130. // Create Folder cameraUpload
  131. if (([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) && app.activeMain)
  132. [app.activeMain createFolderCameraUpload];
  133. [self reloadForm];
  134. }
  135. - (void)reloadForm
  136. {
  137. self.form.delegate = nil;
  138. XLFormRowDescriptor *rowCameraUploadLocationNow = [self.form formRowWithTag:@"camerauploadlocationnow"];
  139. [rowCameraUploadLocationNow setValue:[CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount]];
  140. [self.tableView reloadData];
  141. self.form.delegate = self;
  142. }
  143. @end