CCUploadFromOtherUpp.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // CCUploadFromOtherUpp.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/12/14.
  6. // Copyright (c) 2014 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 "CCUploadFromOtherUpp.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCUploadFromOtherUpp() <NCSelectDelegate>
  27. {
  28. AppDelegate *appDelegate;
  29. NSString *serverUrlLocal;
  30. NSString *destinationTitle;
  31. }
  32. @end
  33. @implementation CCUploadFromOtherUpp
  34. - (void)viewDidLoad
  35. {
  36. [super viewDidLoad];
  37. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  38. self.title = NSLocalizedString(@"_upload_", nil);
  39. serverUrlLocal= [[NCUtility shared] getHomeServerWithUrlBase:appDelegate.urlBase account:appDelegate.account];
  40. destinationTitle = @"/";
  41. // changeTheming
  42. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  43. [self changeTheming];
  44. [self.tableView reloadData];
  45. }
  46. - (void)changeTheming
  47. {
  48. self.view.backgroundColor = NCBrandColor.shared.backgroundForm;
  49. self.tableView.backgroundColor = NCBrandColor.shared.backgroundForm;
  50. [self.tableView reloadData];
  51. }
  52. #pragma --------------------------------------------------------------------------------------------
  53. #pragma mark == tableView ==
  54. #pragma --------------------------------------------------------------------------------------------
  55. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  56. {
  57. if (section == 0) return NSLocalizedString(@"_file_to_upload_", nil);
  58. else if (section == 2) return NSLocalizedString(@"_destination_", nil);
  59. return @"";
  60. }
  61. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  62. {
  63. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  64. cell.accessoryType = UITableViewCellAccessoryNone;
  65. UILabel *nameLabel;
  66. NSUInteger section = [indexPath section];
  67. NSUInteger row = [indexPath row];
  68. switch (section)
  69. {
  70. case 0:
  71. if (row == 0) {
  72. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] error:nil];
  73. NSString *fileSize = [CCUtility transformedSize:[[fileAttributes objectForKey:NSFileSize] longValue]];
  74. self.fileNameTextfield.text = appDelegate.fileNameUpload;
  75. self.fileSizeLabel.text = fileSize;
  76. }
  77. break;
  78. case 2:
  79. if (row == 0) {
  80. self.destinationLabel.text = destinationTitle;
  81. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  82. UIImageView *img = (UIImageView *)[cell viewWithTag:201];
  83. img.image = [UIImage imageNamed:@"folder"];
  84. }
  85. break;
  86. case 4:
  87. if (row == 0) {
  88. nameLabel = (UILabel *)[cell viewWithTag:102];
  89. nameLabel.text = NSLocalizedString(@"_upload_file_", nil);
  90. }
  91. break;
  92. }
  93. return cell;
  94. }
  95. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  96. {
  97. NSUInteger section = [indexPath section];
  98. NSUInteger row = [indexPath row];
  99. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  100. switch (section) {
  101. case 2:
  102. if (row == 0) {
  103. [self changeFolder];
  104. }
  105. break;
  106. case 4:
  107. if (row == 0) {
  108. [self upload];
  109. }
  110. break;
  111. }
  112. }
  113. #pragma --------------------------------------------------------------------------------------------
  114. #pragma mark == IBAction ==
  115. #pragma --------------------------------------------------------------------------------------------
  116. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  117. {
  118. if (serverUrl) {
  119. serverUrlLocal = serverUrl;
  120. if ([serverUrl isEqualToString:appDelegate.urlBase]) {
  121. destinationTitle = @"/";
  122. } else {
  123. destinationTitle = [CCUtility returnPathfromServerUrl:serverUrl urlBase:appDelegate.urlBase account:appDelegate.account];
  124. }
  125. self.destinationLabel.text = destinationTitle;
  126. }
  127. }
  128. - (void)changeFolder
  129. {
  130. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  131. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  132. viewController.delegate = self;
  133. viewController.hideButtonCreateFolder = false;
  134. viewController.selectFile = false;
  135. viewController.includeDirectoryE2EEncryption = false;
  136. viewController.includeImages = false;
  137. viewController.type = @"";
  138. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  139. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  140. [self presentViewController:navigationController animated:YES completion:nil];
  141. }
  142. -(void)upload
  143. {
  144. NSString *fileName = [[NCUtility shared] createFileName:self.fileNameTextfield.text serverUrl:serverUrlLocal account:appDelegate.account];
  145. tableMetadata *metadataForUpload = [[NCManageDatabase shared] createMetadataWithAccount:appDelegate.account fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrlLocal urlBase:appDelegate.urlBase url:@"" contentType:@"" livePhoto:false];
  146. metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground;
  147. metadataForUpload.sessionSelector = selectorUploadFile;
  148. metadataForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload;
  149. // Prepare file and directory
  150. [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageOcId:metadataForUpload.ocId fileNameView:fileName]];
  151. // Add Medtadata for upload
  152. [[NCManageDatabase shared] addMetadata:metadataForUpload];
  153. [[appDelegate networkingAutoUpload] startProcess];
  154. [self dismissViewControllerAnimated:YES completion:nil];
  155. }
  156. - (IBAction)cancelUpload:(UIBarButtonItem *)sender
  157. {
  158. [self dismissViewControllerAnimated:YES completion:nil];
  159. }
  160. @end