CCUploadFromOtherUpp.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 typeCloud:app.typeCloud];
  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 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) { nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = NSLocalizedString(@"_upload_file_", nil); }
  90. if (row == 1) { nameLabel = (UILabel *)[cell viewWithTag:103]; nameLabel.text = NSLocalizedString(@"_upload_encrypted_file_", nil); }
  91. break;
  92. }
  93. return cell;
  94. }
  95. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  96. {
  97. NSUInteger section = [indexPath section];
  98. NSUInteger row = [indexPath row];
  99. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  100. switch (section) {
  101. case 2:
  102. if (row == 0) {
  103. [self changeFolder];
  104. }
  105. break;
  106. case 4:
  107. if (row == 0) {
  108. [self uploadPlain];
  109. }
  110. if (row == 1) {
  111. [self uploadEncrypted];
  112. }
  113. break;
  114. }
  115. }
  116. #pragma --------------------------------------------------------------------------------------------
  117. #pragma mark == IBAction ==
  118. #pragma --------------------------------------------------------------------------------------------
  119. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  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 = COLOR_BRAND;
  134. viewController.barTintColor = COLOR_BAR;
  135. viewController.tintColorTitle = COLOR_GRAY;
  136. viewController.networkingOperationQueue = app.netQueue;
  137. [self presentViewController:navigationController animated:YES completion:nil];
  138. }
  139. - (void)uploadEncrypted
  140. {
  141. [[CCNetworking sharedNetworking] uploadFile:app.fileNameUpload serverUrl:serverUrlLocal cryptated:YES onlyPlist:NO session:upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil parentRev:nil errorCode:0 delegate:nil];
  142. [self dismissViewControllerAnimated:YES completion:nil];
  143. }
  144. -(void)uploadPlain
  145. {
  146. [[CCNetworking sharedNetworking] uploadFile:app.fileNameUpload serverUrl:serverUrlLocal cryptated:NO onlyPlist:NO session:upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil parentRev:nil errorCode:0 delegate:nil];
  147. [self dismissViewControllerAnimated:YES completion:nil];
  148. }
  149. - (IBAction)Annula:(UIBarButtonItem *)sender
  150. {
  151. [self dismissViewControllerAnimated:YES completion:nil];
  152. }
  153. @end