CCUploadFromOtherUpp.m 6.9 KB

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