CCUploadFromOtherUpp.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // CCUploadFromOtherUpp.m
  3. // Nextcloud iOS
  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. // Color
  43. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  44. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  45. }
  46. - (void)didReceiveMemoryWarning
  47. {
  48. [super didReceiveMemoryWarning];
  49. }
  50. // E' apparsa
  51. - (void)viewDidAppear:(BOOL)animated
  52. {
  53. [super viewDidAppear:animated];
  54. [self.tableView reloadData];
  55. }
  56. #pragma --------------------------------------------------------------------------------------------
  57. #pragma mark == tableView ==
  58. #pragma --------------------------------------------------------------------------------------------
  59. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  60. {
  61. if (section == 0) return NSLocalizedString(@"_file_to_upload_", nil);
  62. else if (section == 2) return NSLocalizedString(@"_destination_", nil);
  63. else if (section == 4) return NSLocalizedString(@"_upload_file_", nil);
  64. return @"";
  65. }
  66. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  67. {
  68. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  69. cell.accessoryType = UITableViewCellAccessoryNone;
  70. UILabel *nameLabel;
  71. NSUInteger section = [indexPath section];
  72. NSUInteger row = [indexPath row];
  73. switch (section)
  74. {
  75. case 0:
  76. if (row == 0) {
  77. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] error:nil];
  78. NSString *fileSize = [CCUtility transformedSize:[[fileAttributes objectForKey:NSFileSize] longValue]];
  79. nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = [NSString stringWithFormat:@"%@ - %@", appDelegate.fileNameUpload, fileSize];
  80. }
  81. break;
  82. case 2:
  83. if (row == 0) {
  84. nameLabel = (UILabel *)[cell viewWithTag:101]; nameLabel.text = destinationTitle;
  85. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  86. UIImageView *img = (UIImageView *)[cell viewWithTag:201];
  87. img.image = [UIImage imageNamed:@"folder"];
  88. }
  89. break;
  90. case 4:
  91. if (row == 0) {
  92. nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = NSLocalizedString(@"_upload_file_", nil);
  93. }
  94. break;
  95. }
  96. return cell;
  97. }
  98. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. NSUInteger section = [indexPath section];
  101. NSUInteger row = [indexPath row];
  102. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  103. switch (section) {
  104. case 2:
  105. if (row == 0) {
  106. [self changeFolder];
  107. }
  108. break;
  109. case 4:
  110. if (row == 0) {
  111. [self upload];
  112. }
  113. break;
  114. }
  115. }
  116. #pragma --------------------------------------------------------------------------------------------
  117. #pragma mark == IBAction ==
  118. #pragma --------------------------------------------------------------------------------------------
  119. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title type:(NSString *)type
  120. {
  121. if (serverUrlTo) {
  122. serverUrlLocal = serverUrlTo;
  123. if (title) destinationTitle = title;
  124. else destinationTitle = NSLocalizedString(@"_home_", nil);
  125. }
  126. }
  127. - (void)changeFolder
  128. {
  129. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  130. CCMove *viewController = (CCMove *)navigationController.topViewController;
  131. viewController.delegate = self;
  132. viewController.move.title = NSLocalizedString(@"_select_", nil);
  133. viewController.tintColor = [NCBrandColor sharedInstance].brandText;
  134. viewController.barTintColor = [NCBrandColor sharedInstance].brand;
  135. viewController.tintColorTitle = [NCBrandColor sharedInstance].brandText;
  136. viewController.networkingOperationQueue = appDelegate.netQueue;
  137. // E2EE
  138. viewController.includeDirectoryE2EEncryption = NO;
  139. [self presentViewController:navigationController animated:YES completion:nil];
  140. }
  141. -(void)upload
  142. {
  143. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlLocal account:appDelegate.activeAccount];
  144. NSString *fileName = [[NCUtility sharedInstance] createFileName:appDelegate.fileNameUpload serverUrl:serverUrlLocal account:appDelegate.activeAccount];
  145. NSString *fileID = [directoryID stringByAppendingString:appDelegate.fileNameUpload];
  146. tableMetadata *metadataForUpload = [tableMetadata new];
  147. metadataForUpload.account = appDelegate.activeAccount;
  148. metadataForUpload.date = [NSDate new];
  149. metadataForUpload.directoryID = directoryID;
  150. metadataForUpload.fileID = fileID;
  151. metadataForUpload.fileName = fileName;
  152. metadataForUpload.fileNameView = fileName;
  153. metadataForUpload.serverUrl = serverUrlLocal;
  154. metadataForUpload.session = k_upload_session;
  155. metadataForUpload.sessionSelector = selectorUploadFile;
  156. metadataForUpload.status = k_metadataStatusWaitUpload;
  157. // Prepare file and directory
  158. [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageFileID:metadataForUpload.fileID fileNameView:fileName]];
  159. // Add Medtadata for upload
  160. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  161. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  162. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrlLocal fileID:fileID action:k_action_NULL];
  163. [self dismissViewControllerAnimated:YES completion:nil];
  164. }
  165. - (IBAction)Annula:(UIBarButtonItem *)sender
  166. {
  167. [self dismissViewControllerAnimated:YES completion:nil];
  168. }
  169. @end