CCTemplates.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // CCTemplates.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/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 "CCTemplates.h"
  24. #import "NCBridgeSwift.h"
  25. @implementation CCTemplates
  26. #pragma --------------------------------------------------------------------------------------------
  27. #pragma mark ===== Effetti Grafici =====
  28. #pragma --------------------------------------------------------------------------------------------
  29. - (void)setImageTitle:(NSString*)titolo conNavigationItem:(UINavigationItem *)navItem reachability:(BOOL)reachability
  30. {
  31. UILabel* label=[[UILabel alloc] initWithFrame:CGRectMake(0,0, navItem.titleView.frame.size.width, 40)];
  32. label.text=titolo;
  33. if (!reachability) label.textColor = [NCBrandColor sharedInstance].connectionNo;
  34. else label.textColor = [NCBrandColor sharedInstance].navigationBarText;
  35. label.backgroundColor = [NCBrandColor sharedInstance].brand;
  36. label.textAlignment = NSTextAlignmentCenter;
  37. navItem.titleView=label;
  38. }
  39. #pragma --------------------------------------------------------------------------------------------
  40. #pragma mark ===== Form =====
  41. #pragma --------------------------------------------------------------------------------------------
  42. - (NSString *)salvaForm:(XLFormDescriptor *)form fileName:(NSString *)fileName uuid:(NSString *)uuid modello:(NSString *)modello icona:(NSString *)icona
  43. {
  44. NSString *fileNameModel = nil;
  45. NSData *data;
  46. NSMutableDictionary * result = [NSMutableDictionary dictionary];
  47. for (XLFormSectionDescriptor * section in form.formSections) {
  48. if (!section.isMultivaluedSection){
  49. for (XLFormRowDescriptor * row in section.formRows) {
  50. if (row.tag && ![row.tag isEqualToString:@""]){
  51. [result setObject:(row.value ?: [NSNull null]) forKey:row.tag];
  52. }
  53. }
  54. }
  55. else{
  56. NSMutableArray * multiValuedValuesArray = [NSMutableArray new];
  57. for (XLFormRowDescriptor * row in section.formRows) {
  58. if (row.value){
  59. [multiValuedValuesArray addObject:row.value];
  60. }
  61. }
  62. [result setObject:multiValuedValuesArray forKey:section.multivaluedTag];
  63. }
  64. }
  65. // save the result
  66. NSString *title = [AESCrypt encrypt:[result objectForKey:@"titolo"] password:[[CCCrypto sharedManager] getKeyPasscode:uuid]];
  67. if (fileName) {
  68. fileNameModel = fileName;
  69. // copy in memory for failure write
  70. data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", uuid, fileName]];
  71. } else {
  72. fileNameModel = [NSString stringWithFormat:@"%@.plist", [[CCCrypto sharedManager] createFilenameEncryptor:[result objectForKey:@"titolo"] uuid:uuid]];
  73. }
  74. if ([[CCCrypto sharedManager] createTemplatesPlist:fileNameModel title:title uuid:uuid icon:icona model:modello dictionary:result] == NO) {
  75. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_read_file_error_", nil) message:NSLocalizedString(@"_reload_folder_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  76. [alertView show];
  77. fileNameModel = nil;
  78. }
  79. return fileNameModel;
  80. }
  81. #pragma --------------------------------------------------------------------------------------------
  82. #pragma mark ===== Note =====
  83. #pragma --------------------------------------------------------------------------------------------
  84. - (NSString *)salvaNote:(NSString *)html titolo:(NSString *)titolo fileName:(NSString *)fileName uuid:(NSString *)uuid
  85. {
  86. NSString *fileNameModel = nil;
  87. NSData *data;
  88. NSMutableDictionary * result = [NSMutableDictionary dictionary];
  89. [result setObject:(titolo ?: [NSNull null]) forKey:@"titolo"];
  90. [result setObject:(html ?: [NSNull null]) forKey:@"note"];
  91. // save the result
  92. NSString *title = [AESCrypt encrypt:[result objectForKey:@"titolo"] password:[[CCCrypto sharedManager] getKeyPasscode:uuid]];
  93. if (fileName) {
  94. fileNameModel = fileName;
  95. // copy in memory for failure write
  96. data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", uuid, fileName]];
  97. } else {
  98. fileNameModel = [NSString stringWithFormat:@"%@.plist",[[CCCrypto sharedManager] createFilenameEncryptor:[result objectForKey:@"titolo"] uuid:uuid]];
  99. }
  100. if ([[CCCrypto sharedManager] createTemplatesPlist:fileNameModel title:title uuid:uuid icon:@"note" model:@"note" dictionary:result] == NO) {
  101. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_read_file_error_", nil) message:NSLocalizedString(@"_reload_folder_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  102. [alertView show];
  103. fileNameModel = nil;
  104. }
  105. return fileNameModel;
  106. }
  107. @end