CCAccountWeb.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // CCAccountWeb.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/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 "CCAccountWeb.h"
  24. #import "AppDelegate.h"
  25. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCAccountWeb()
  31. {
  32. XLFormDescriptor *form ;
  33. NSTimer* myTimer;
  34. NSMutableDictionary *field;
  35. CCTemplates *templates;
  36. NSString *_saveFileID;
  37. }
  38. @end
  39. @implementation CCAccountWeb
  40. - (id)initWithDelegate:(id <CCAccountWebDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid fileID:(NSString *)fileID isLocal:(BOOL)isLocal serverUrl:(NSString *)serverUrl
  41. {
  42. self = [super init];
  43. if (self) {
  44. self.delegate = delegate;
  45. self.fileName = fileName;
  46. self.isLocal = isLocal;
  47. self.fileID = fileID;
  48. self.uuid = uuid;
  49. self.serverUrl = serverUrl;
  50. // if fileName read Crypto File
  51. if (fileName)
  52. field = [[CCCrypto sharedManager] getDictionaryEncrypted:fileName uuid:uuid isLocal:isLocal directoryUser:app.directoryUser];
  53. XLFormSectionDescriptor *section;
  54. XLFormRowDescriptor *row;
  55. // Information - Section
  56. form = [XLFormDescriptor formDescriptor];
  57. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  58. [form addFormSection:section];
  59. if (!fileName) form.assignFirstResponderOnShow = YES;
  60. // Title
  61. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  62. [row.cellConfig setObject:[NCBrandColor sharedInstance].cryptocloud forKey:@"textField.textColor"];
  63. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  65. row.value = [field objectForKey:@"titolo"];
  66. row.required = YES;
  67. [section addFormRow:row];
  68. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_web_account_data_", nil)];
  69. [form addFormSection:section];
  70. // url
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"url" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_url:_", nil)];
  72. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  73. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  74. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  75. row.value = [field objectForKey:@"url"];
  76. [section addFormRow:row];
  77. // Login
  78. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"login" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_login:_", nil)];
  79. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  82. row.value = [field objectForKey:@"login"];
  83. [section addFormRow:row];
  84. // Password
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_password:_", nil)];
  86. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  89. row.value = [field objectForKey:@"password"];
  90. [section addFormRow:row];
  91. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  92. [form addFormSection:section];
  93. // Note
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  95. row.value = [field objectForKey:@"note"];
  96. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textView.textColor"];
  97. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  98. [section addFormRow:row];
  99. self.form = form;
  100. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  101. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  102. }
  103. return self;
  104. }
  105. - (void)viewDidLoad
  106. {
  107. [super viewDidLoad];
  108. templates = [[CCTemplates alloc] init];
  109. [templates setImageTitle:NSLocalizedString(@"_web_account_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  110. // Color
  111. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  112. }
  113. - (void)viewDidAppear:(BOOL)animated
  114. {
  115. [super viewDidAppear:animated];
  116. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  117. }
  118. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  119. {
  120. [super didSelectFormRow:formRow];
  121. if ([formRow.tag isEqual:@"mytag"]) {
  122. // do your thing for your row.
  123. }
  124. }
  125. #pragma --------------------------------------------------------------------------------------------
  126. #pragma mark - ==== IBAction ====
  127. #pragma --------------------------------------------------------------------------------------------
  128. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  129. {
  130. [self dismissViewControllerAnimated:YES completion:nil];
  131. }
  132. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  133. {
  134. NSString *fileNameModel;
  135. NSArray *validationErrors = [self formValidationErrors];
  136. if (validationErrors.count > 0){
  137. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  138. [alertView show];
  139. return;
  140. }
  141. [self.tableView endEditing:YES];
  142. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"accountweb" icona:@"accountweb"];
  143. if (fileNameModel) {
  144. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  145. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  146. metadataNet.action = actionUploadTemplate;
  147. metadataNet.serverUrl = self.serverUrl;
  148. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  149. metadataNet.fileNamePrint = titolo.value;
  150. metadataNet.pathFolder = NSTemporaryDirectory();
  151. metadataNet.session = k_upload_session_foreground;
  152. metadataNet.taskStatus = k_taskStatusResume;
  153. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  154. }
  155. }
  156. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  157. {
  158. if (![_saveFileID isEqualToString:fileID]) {
  159. _saveFileID = fileID;
  160. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  161. // remove the file
  162. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount]];
  163. [self.delegate readFolderWithForced:YES serverUrl:self.serverUrl];
  164. }
  165. }
  166. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  167. {
  168. [self dismissViewControllerAnimated:YES completion:nil];
  169. }
  170. @end