CCUploadFromOtherUpp.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // CCUploadFromOtherUpp.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/12/14.
  6. // Copyright (c) 2017 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()
  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.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"_cancel_", nil);
  39. self.title = NSLocalizedString(@"_upload_", nil);
  40. serverUrlLocal= [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  41. destinationTitle = NSLocalizedString(@"_home_", nil);
  42. // changeTheming
  43. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  44. [self changeTheming];
  45. [self.tableView reloadData];
  46. }
  47. - (void)changeTheming
  48. {
  49. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil];
  50. }
  51. #pragma --------------------------------------------------------------------------------------------
  52. #pragma mark == tableView ==
  53. #pragma --------------------------------------------------------------------------------------------
  54. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  55. {
  56. if (section == 0) return NSLocalizedString(@"_file_to_upload_", nil);
  57. else if (section == 2) return NSLocalizedString(@"_destination_", nil);
  58. else if (section == 4) return NSLocalizedString(@"_upload_file_", 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. nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = [NSString stringWithFormat:@"%@ - %@", appDelegate.fileNameUpload, fileSize];
  75. }
  76. break;
  77. case 2:
  78. if (row == 0) {
  79. nameLabel = (UILabel *)[cell viewWithTag:101]; nameLabel.text = destinationTitle;
  80. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  81. UIImageView *img = (UIImageView *)[cell viewWithTag:201];
  82. img.image = [UIImage imageNamed:@"folder"];
  83. }
  84. break;
  85. case 4:
  86. if (row == 0) {
  87. nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = NSLocalizedString(@"_upload_file_", nil);
  88. }
  89. break;
  90. }
  91. return cell;
  92. }
  93. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. NSUInteger section = [indexPath section];
  96. NSUInteger row = [indexPath row];
  97. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  98. switch (section) {
  99. case 2:
  100. if (row == 0) {
  101. [self changeFolder];
  102. }
  103. break;
  104. case 4:
  105. if (row == 0) {
  106. [self upload];
  107. }
  108. break;
  109. }
  110. }
  111. #pragma --------------------------------------------------------------------------------------------
  112. #pragma mark == IBAction ==
  113. #pragma --------------------------------------------------------------------------------------------
  114. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title type:(NSString *)type
  115. {
  116. if (serverUrlTo) {
  117. serverUrlLocal = serverUrlTo;
  118. if (title) destinationTitle = title;
  119. else destinationTitle = NSLocalizedString(@"_home_", nil);
  120. }
  121. }
  122. - (void)changeFolder
  123. {
  124. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  125. CCMove *viewController = (CCMove *)navigationController.topViewController;
  126. viewController.delegate = self;
  127. viewController.move.title = NSLocalizedString(@"_select_", nil);
  128. viewController.tintColor = NCBrandColor.sharedInstance.brandText;
  129. viewController.barTintColor = NCBrandColor.sharedInstance.brand;
  130. viewController.tintColorTitle = NCBrandColor.sharedInstance.brandText;
  131. // E2EE
  132. viewController.includeDirectoryE2EEncryption = NO;
  133. [self presentViewController:navigationController animated:YES completion:nil];
  134. }
  135. -(void)upload
  136. {
  137. NSString *fileName = [[NCUtility sharedInstance] createFileName:appDelegate.fileNameUpload serverUrl:serverUrlLocal account:appDelegate.activeAccount];
  138. tableMetadata *metadataForUpload = [tableMetadata new];
  139. metadataForUpload.account = appDelegate.activeAccount;
  140. metadataForUpload.date = [NSDate new];
  141. metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrlLocal fileNameView:fileName directory:false];
  142. metadataForUpload.fileName = fileName;
  143. metadataForUpload.fileNameView = fileName;
  144. metadataForUpload.serverUrl = serverUrlLocal;
  145. metadataForUpload.session = k_upload_session;
  146. metadataForUpload.sessionSelector = selectorUploadFile;
  147. metadataForUpload.status = k_metadataStatusWaitUpload;
  148. // Prepare file and directory
  149. [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageOcId:metadataForUpload.ocId fileNameView:fileName]];
  150. // Add Medtadata for upload
  151. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  152. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrlLocal ocId:metadataForUpload.ocId action:k_action_NULL];
  153. [appDelegate startLoadAutoDownloadUpload];
  154. [self dismissViewControllerAnimated:YES completion:nil];
  155. }
  156. - (IBAction)Annula:(UIBarButtonItem *)sender
  157. {
  158. [self dismissViewControllerAnimated:YES completion:nil];
  159. }
  160. @end