CCTemplates.m 5.7 KB

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