CCTemplates.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 = COLOR_NAVIGATIONBAR_TEXT;
  34. label.backgroundColor = COLOR_NAVIGATIONBAR;
  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. NSMutableDictionary * result = [NSMutableDictionary dictionary];
  46. for (XLFormSectionDescriptor * section in form.formSections) {
  47. if (!section.isMultivaluedSection){
  48. for (XLFormRowDescriptor * row in section.formRows) {
  49. if (row.tag && ![row.tag isEqualToString:@""]){
  50. [result setObject:(row.value ?: [NSNull null]) forKey:row.tag];
  51. }
  52. }
  53. }
  54. else{
  55. NSMutableArray * multiValuedValuesArray = [NSMutableArray new];
  56. for (XLFormRowDescriptor * row in section.formRows) {
  57. if (row.value){
  58. [multiValuedValuesArray addObject:row.value];
  59. }
  60. }
  61. [result setObject:multiValuedValuesArray forKey:section.multivaluedTag];
  62. }
  63. }
  64. // save the result
  65. NSString *title = [AESCrypt encrypt:[result objectForKey:@"titolo"] password:[[CCCrypto sharedManager] getKeyPasscode:uuid]];
  66. if (fileName) {
  67. fileNameModel = fileName;
  68. // copy in memory for failure write
  69. data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", uuid, fileName]];
  70. } else {
  71. fileNameModel = [NSString stringWithFormat:@"%@.plist", [[CCCrypto sharedManager] createFilenameEncryptor:[result objectForKey:@"titolo"] uuid:uuid]];
  72. }
  73. if ([[CCCrypto sharedManager] createTemplatesPlist:fileNameModel title:title uuid:uuid icon:icona model:modello dictionary:result] == NO) {
  74. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_read_file_error_", nil) message:NSLocalizedString(@"_reload_folder_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  75. [alertView show];
  76. fileNameModel = nil;
  77. }
  78. return fileNameModel;
  79. }
  80. #pragma --------------------------------------------------------------------------------------------
  81. #pragma mark ===== Note =====
  82. #pragma --------------------------------------------------------------------------------------------
  83. - (NSString *)salvaNote:(NSString *)html titolo:(NSString *)titolo fileName:(NSString *)fileName uuid:(NSString *)uuid
  84. {
  85. NSString *fileNameModel = nil;
  86. NSData *data;
  87. NSMutableDictionary * result = [NSMutableDictionary dictionary];
  88. [result setObject:(titolo ?: [NSNull null]) forKey:@"titolo"];
  89. [result setObject:(html ?: [NSNull null]) forKey:@"note"];
  90. // save the result
  91. NSString *title = [AESCrypt encrypt:[result objectForKey:@"titolo"] password:[[CCCrypto sharedManager] getKeyPasscode:uuid]];
  92. if (fileName) {
  93. fileNameModel = fileName;
  94. // copy in memory for failure write
  95. data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", uuid, fileName]];
  96. } else {
  97. fileNameModel = [NSString stringWithFormat:@"%@.plist",[[CCCrypto sharedManager] createFilenameEncryptor:[result objectForKey:@"titolo"] uuid:uuid]];
  98. }
  99. if ([[CCCrypto sharedManager] createTemplatesPlist:fileNameModel title:title uuid:uuid icon:@"note" model:@"note" dictionary:result] == NO) {
  100. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_read_file_error_", nil) message:NSLocalizedString(@"_reload_folder_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  101. [alertView show];
  102. fileNameModel = nil;
  103. }
  104. return fileNameModel;
  105. }
  106. @end