CCTemplates.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // CCTemplates.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 "CCTemplates.h"
  24. @implementation CCTemplates
  25. #pragma --------------------------------------------------------------------------------------------
  26. #pragma mark ===== Effetti Grafici =====
  27. #pragma --------------------------------------------------------------------------------------------
  28. - (void)setImageTitle:(NSString*)titolo conNavigationItem:(UINavigationItem *)navItem reachability:(BOOL)reachability
  29. {
  30. UILabel* label=[[UILabel alloc] initWithFrame:CGRectMake(0,0, navItem.titleView.frame.size.width, 40)];
  31. label.text=titolo;
  32. if (!reachability) label.textColor = COLOR_TEXT_NO_CONNECTION;
  33. else label.textColor = [UIColor blackColor];
  34. label.backgroundColor =[UIColor clearColor];
  35. label.textAlignment = NSTextAlignmentCenter;
  36. navItem.titleView=label;
  37. }
  38. #pragma --------------------------------------------------------------------------------------------
  39. #pragma mark ===== Form =====
  40. #pragma --------------------------------------------------------------------------------------------
  41. - (NSString *)salvaForm:(XLFormDescriptor *)form fileName:(NSString *)fileName uuid:(NSString *)uuid modello:(NSString *)modello icona:(NSString *)icona
  42. {
  43. NSString *fileNameModel = nil;
  44. NSData *data;
  45. CCCrypto *crypto = [[CCCrypto alloc] init];
  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:[crypto 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", [crypto createFilenameEncryptor:[result objectForKey:@"titolo"] uuid:uuid]];
  73. }
  74. if ([crypto 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. CCCrypto *crypto = [[CCCrypto alloc] init];
  90. [result setObject:(titolo ?: [NSNull null]) forKey:@"titolo"];
  91. [result setObject:(html ?: [NSNull null]) forKey:@"note"];
  92. // save the result
  93. NSString *title = [AESCrypt encrypt:[result objectForKey:@"titolo"] password:[crypto getKeyPasscode:uuid]];
  94. if (fileName) {
  95. fileNameModel = fileName;
  96. // copy in memory for failure write
  97. data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", uuid, fileName]];
  98. } else {
  99. fileNameModel = [NSString stringWithFormat:@"%@.plist",[crypto createFilenameEncryptor:[result objectForKey:@"titolo"] uuid:uuid]];
  100. }
  101. if ([crypto createTemplatesPlist:fileNameModel title:title uuid:uuid icon:@"note" model:@"note" dictionary:result] == NO) {
  102. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_read_file_error_", nil) message:NSLocalizedString(@"_reload_folder_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  103. [alertView show];
  104. fileNameModel = nil;
  105. }
  106. return fileNameModel;
  107. }
  108. @end