CCUploadFromOtherUpp.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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:false];
  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)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  115. {
  116. if (serverUrl) {
  117. serverUrlLocal = serverUrl;
  118. destinationTitle = metadata.fileNameView;
  119. //destinationTitle = NSLocalizedString(@"_home_", nil);
  120. }
  121. }
  122. - (void)changeFolder
  123. {
  124. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  125. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  126. viewController.delegate = self;
  127. viewController.hideButtonCreateFolder = false;
  128. viewController.selectFile = false;
  129. viewController.includeDirectoryE2EEncryption = false;
  130. viewController.includeImages = false;
  131. viewController.type = @"";
  132. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  133. viewController.layoutViewSelect = k_layout_view_move;
  134. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  135. [self presentViewController:navigationController animated:YES completion:nil];
  136. }
  137. -(void)upload
  138. {
  139. NSString *fileName = [[NCUtility sharedInstance] createFileName:appDelegate.fileNameUpload serverUrl:serverUrlLocal account:appDelegate.activeAccount];
  140. tableMetadata *metadataForUpload = [tableMetadata new];
  141. metadataForUpload.account = appDelegate.activeAccount;
  142. metadataForUpload.date = [NSDate new];
  143. metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrlLocal fileNameView:fileName directory:false];
  144. metadataForUpload.fileName = fileName;
  145. metadataForUpload.fileNameView = fileName;
  146. metadataForUpload.serverUrl = serverUrlLocal;
  147. metadataForUpload.session = k_upload_session;
  148. metadataForUpload.sessionSelector = selectorUploadFile;
  149. metadataForUpload.status = k_metadataStatusWaitUpload;
  150. // Prepare file and directory
  151. [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageOcId:metadataForUpload.ocId fileNameView:fileName]];
  152. // Add Medtadata for upload
  153. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  154. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrlLocal ocId:metadataForUpload.ocId action:k_action_NULL];
  155. [appDelegate startLoadAutoDownloadUpload];
  156. [self dismissViewControllerAnimated:YES completion:nil];
  157. }
  158. - (IBAction)Annula:(UIBarButtonItem *)sender
  159. {
  160. [self dismissViewControllerAnimated:YES completion:nil];
  161. }
  162. @end