CCUploadFromOtherUpp.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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= [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  40. destinationTitle = NSLocalizedString(@"_home_", nil);
  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. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  49. }
  50. #pragma --------------------------------------------------------------------------------------------
  51. #pragma mark == tableView ==
  52. #pragma --------------------------------------------------------------------------------------------
  53. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  54. {
  55. if (section == 0) return NSLocalizedString(@"_file_to_upload_", nil);
  56. else if (section == 2) return NSLocalizedString(@"_destination_", nil);
  57. return @"";
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  62. cell.accessoryType = UITableViewCellAccessoryNone;
  63. UILabel *nameLabel;
  64. NSUInteger section = [indexPath section];
  65. NSUInteger row = [indexPath row];
  66. switch (section)
  67. {
  68. case 0:
  69. if (row == 0) {
  70. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] error:nil];
  71. NSString *fileSize = [CCUtility transformedSize:[[fileAttributes objectForKey:NSFileSize] longValue]];
  72. self.fileNameTextfield.text = appDelegate.fileNameUpload;
  73. self.fileSizeLabel.text = fileSize;
  74. }
  75. break;
  76. case 2:
  77. if (row == 0) {
  78. self.destinationLabel.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];
  87. 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 buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  115. {
  116. if (serverUrl) {
  117. serverUrlLocal = serverUrl;
  118. destinationTitle = metadata.fileNameView;
  119. self.destinationLabel.text = destinationTitle;
  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:self.fileNameTextfield.text serverUrl:serverUrlLocal account:appDelegate.activeAccount];
  140. tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrlLocal url:@"" contentType:@""];
  141. metadataForUpload.session = k_upload_session;
  142. metadataForUpload.sessionSelector = selectorUploadFile;
  143. metadataForUpload.status = k_metadataStatusWaitUpload;
  144. // Prepare file and directory
  145. [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageOcId:metadataForUpload.ocId fileNameView:fileName]];
  146. // Add Medtadata for upload
  147. [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  148. [appDelegate startLoadAutoUpload];
  149. [self dismissViewControllerAnimated:YES completion:nil];
  150. }
  151. - (IBAction)cancelUpload:(UIBarButtonItem *)sender
  152. {
  153. [self dismissViewControllerAnimated:YES completion:nil];
  154. }
  155. @end