CCUploadFromOtherUpp.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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() <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.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 form:true];
  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. return @"";
  59. }
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  61. {
  62. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  63. cell.accessoryType = UITableViewCellAccessoryNone;
  64. UILabel *nameLabel;
  65. NSUInteger section = [indexPath section];
  66. NSUInteger row = [indexPath row];
  67. switch (section)
  68. {
  69. case 0:
  70. if (row == 0) {
  71. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] error:nil];
  72. NSString *fileSize = [CCUtility transformedSize:[[fileAttributes objectForKey:NSFileSize] longValue]];
  73. nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = [NSString stringWithFormat:@"%@ - %@", appDelegate.fileNameUpload, fileSize];
  74. }
  75. break;
  76. case 2:
  77. if (row == 0) {
  78. nameLabel = (UILabel *)[cell viewWithTag:101]; nameLabel.text = destinationTitle;
  79. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  80. UIImageView *img = (UIImageView *)[cell viewWithTag:201];
  81. img.image = [UIImage imageNamed:@"folder"];
  82. }
  83. break;
  84. case 4:
  85. if (row == 0) {
  86. nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = NSLocalizedString(@"_upload_file_", nil);
  87. }
  88. break;
  89. }
  90. return cell;
  91. }
  92. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  93. {
  94. NSUInteger section = [indexPath section];
  95. NSUInteger row = [indexPath row];
  96. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  97. switch (section) {
  98. case 2:
  99. if (row == 0) {
  100. [self changeFolder];
  101. }
  102. break;
  103. case 4:
  104. if (row == 0) {
  105. [self upload];
  106. }
  107. break;
  108. }
  109. }
  110. #pragma --------------------------------------------------------------------------------------------
  111. #pragma mark == IBAction ==
  112. #pragma --------------------------------------------------------------------------------------------
  113. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  114. {
  115. if (serverUrl) {
  116. serverUrlLocal = serverUrl;
  117. destinationTitle = metadata.fileNameView;
  118. //destinationTitle = NSLocalizedString(@"_home_", nil);
  119. }
  120. }
  121. - (void)changeFolder
  122. {
  123. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  124. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  125. viewController.delegate = self;
  126. viewController.hideButtonCreateFolder = false;
  127. viewController.selectFile = false;
  128. viewController.includeDirectoryE2EEncryption = false;
  129. viewController.includeImages = false;
  130. viewController.type = @"";
  131. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  132. viewController.layoutViewSelect = k_layout_view_move;
  133. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  134. [self presentViewController:navigationController animated:YES completion:nil];
  135. }
  136. -(void)upload
  137. {
  138. NSString *fileName = [[NCUtility sharedInstance] createFileName:appDelegate.fileNameUpload serverUrl:serverUrlLocal account:appDelegate.activeAccount];
  139. tableMetadata *metadataForUpload = [tableMetadata new];
  140. metadataForUpload.account = appDelegate.activeAccount;
  141. metadataForUpload.date = [NSDate new];
  142. metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrlLocal fileNameView:fileName directory:false];
  143. metadataForUpload.fileName = fileName;
  144. metadataForUpload.fileNameView = fileName;
  145. metadataForUpload.serverUrl = serverUrlLocal;
  146. metadataForUpload.session = k_upload_session;
  147. metadataForUpload.sessionSelector = selectorUploadFile;
  148. metadataForUpload.status = k_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. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  153. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrlLocal ocId:metadataForUpload.ocId action:k_action_NULL];
  154. [appDelegate startLoadAutoDownloadUpload];
  155. [self dismissViewControllerAnimated:YES completion:nil];
  156. }
  157. - (IBAction)Annula:(UIBarButtonItem *)sender
  158. {
  159. [self dismissViewControllerAnimated:YES completion:nil];
  160. }
  161. @end