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