CCUploadFromOtherUpp.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // CCUploadFromOtherUpp.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/12/14.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCUploadFromOtherUpp()
  31. {
  32. NSString *serverUrlLocal;
  33. NSString *destinationTitle;
  34. }
  35. @end
  36. @implementation CCUploadFromOtherUpp
  37. - (void)viewDidLoad
  38. {
  39. [super viewDidLoad];
  40. self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"_cancel_", nil);
  41. self.title = [CCUtility localizableBrand:@"_crypto_cloud_upload_" table:nil];
  42. serverUrlLocal= [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  43. destinationTitle = NSLocalizedString(@"_home_", nil);
  44. // Color
  45. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  46. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  47. }
  48. - (void)didReceiveMemoryWarning
  49. {
  50. [super didReceiveMemoryWarning];
  51. }
  52. // E' apparsa
  53. - (void)viewDidAppear:(BOOL)animated
  54. {
  55. [super viewDidAppear:animated];
  56. [self.tableView reloadData];
  57. }
  58. #pragma --------------------------------------------------------------------------------------------
  59. #pragma mark == tableView ==
  60. #pragma --------------------------------------------------------------------------------------------
  61. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  62. {
  63. if (section == 0) return NSLocalizedString(@"_file_to_upload_", nil);
  64. else if (section == 2) return NSLocalizedString(@"_destination_", nil);
  65. else if (section == 4) return NSLocalizedString(@"_upload_file_", nil);
  66. return @"";
  67. }
  68. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  71. cell.accessoryType = UITableViewCellAccessoryNone;
  72. UILabel *nameLabel;
  73. NSUInteger section = [indexPath section];
  74. NSUInteger row = [indexPath row];
  75. switch (section)
  76. {
  77. case 0:
  78. if (row == 0) {
  79. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, app.fileNameUpload] error:nil];
  80. NSString *fileSize = [CCUtility transformedSize:[[fileAttributes objectForKey:NSFileSize] longValue]];
  81. nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = [NSString stringWithFormat:@"%@ - %@", app.fileNameUpload, fileSize];
  82. }
  83. break;
  84. case 2:
  85. if (row == 0) {
  86. nameLabel = (UILabel *)[cell viewWithTag:101]; nameLabel.text = destinationTitle;
  87. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  88. UIImageView *img = (UIImageView *)[cell viewWithTag:201];
  89. if ([CCUtility isCryptoString:[serverUrlLocal lastPathComponent]]) img.image = [UIImage imageNamed:image_foldercrypto];
  90. else img.image = [UIImage imageNamed:image_folder];
  91. }
  92. break;
  93. case 4:
  94. if (row == 0) {
  95. nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = NSLocalizedString(@"_upload_file_", nil);
  96. }
  97. if (row == 1) {
  98. nameLabel = (UILabel *)[cell viewWithTag:103]; nameLabel.text = NSLocalizedString(@"_upload_encrypted_file_", nil);
  99. if (app.isCryptoCloudMode == NO)
  100. cell.hidden = YES;
  101. }
  102. break;
  103. }
  104. return cell;
  105. }
  106. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  107. {
  108. NSUInteger section = [indexPath section];
  109. NSUInteger row = [indexPath row];
  110. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  111. switch (section) {
  112. case 2:
  113. if (row == 0) {
  114. [self changeFolder];
  115. }
  116. break;
  117. case 4:
  118. if (row == 0) {
  119. [self uploadPlain];
  120. }
  121. if (row == 1) {
  122. [self uploadEncrypted];
  123. }
  124. break;
  125. }
  126. }
  127. #pragma --------------------------------------------------------------------------------------------
  128. #pragma mark == IBAction ==
  129. #pragma --------------------------------------------------------------------------------------------
  130. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  131. {
  132. if (serverUrlTo) {
  133. serverUrlLocal = serverUrlTo;
  134. if (title) destinationTitle = title;
  135. else destinationTitle = NSLocalizedString(@"_home_", nil);
  136. }
  137. }
  138. - (void)changeFolder
  139. {
  140. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  141. CCMove *viewController = (CCMove *)navigationController.topViewController;
  142. viewController.delegate = self;
  143. viewController.move.title = NSLocalizedString(@"_select_", nil);
  144. viewController.tintColor = [NCColorBrand sharedInstance].navigationBarText;
  145. viewController.barTintColor = [NCColorBrand sharedInstance].navigationBar;
  146. viewController.tintColorTitle = [NCColorBrand sharedInstance].navigationBarText;
  147. viewController.networkingOperationQueue = app.netQueue;
  148. [self presentViewController:navigationController animated:YES completion:nil];
  149. }
  150. - (void)uploadEncrypted
  151. {
  152. [[CCNetworking sharedNetworking] uploadFile:app.fileNameUpload serverUrl:serverUrlLocal cryptated:YES onlyPlist:NO session:k_upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  153. [self dismissViewControllerAnimated:YES completion:nil];
  154. }
  155. -(void)uploadPlain
  156. {
  157. [[CCNetworking sharedNetworking] uploadFile:app.fileNameUpload serverUrl:serverUrlLocal cryptated:NO onlyPlist:NO session:k_upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  158. [self dismissViewControllerAnimated:YES completion:nil];
  159. }
  160. - (IBAction)Annula:(UIBarButtonItem *)sender
  161. {
  162. [self dismissViewControllerAnimated:YES completion:nil];
  163. }
  164. @end