CCManageHelp.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // CCManageHelp.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  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 "CCManageHelp.h"
  24. #import "CCUtility.h"
  25. #import "AppDelegate.h"
  26. @interface CCManageHelp ()
  27. @end
  28. @implementation CCManageHelp
  29. - (id)initWithCoder:(NSCoder *)aDecoder
  30. {
  31. self = [super initWithCoder:aDecoder];
  32. if (self) {
  33. [self initializeForm];
  34. }
  35. return self;
  36. }
  37. - (void)initializeForm
  38. {
  39. XLFormDescriptor *form ;
  40. XLFormSectionDescriptor *section;
  41. XLFormRowDescriptor *row;
  42. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_help_", nil)];
  43. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_help_tutorial_", nil)];
  44. [form addFormSection:section];
  45. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"intro" rowType:XLFormRowDescriptorTypeButton title:[CCUtility localizableBrand:@"_help_intro_" table:nil]];
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  48. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  49. [row.cellConfig setObject:[UIImage imageNamed:image_settingsIntroduction] forKey:@"imageView.image"];
  50. row.action.formSelector = @selector(intro:);
  51. [section addFormRow:row];
  52. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_help_activity_section_", nil)];
  53. [form addFormSection:section];
  54. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"activityVerboseHigh" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_help_activity_verbose_", nil)];
  55. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  56. [row.cellConfig setObject:[UIImage imageNamed:image_settingsActivityHigh] forKey:@"imageView.image"];
  57. if ([CCUtility getActivityVerboseHigh]) row.value = @"1";
  58. else row.value = @"0";
  59. [section addFormRow:row];
  60. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendMailActivity" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_mail_", nil)];
  61. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  62. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  63. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  64. [row.cellConfig setObject:[UIImage imageNamed:image_settingsSendActivity] forKey:@"imageView.image"];
  65. row.action.formSelector = @selector(sendMail:);
  66. [section addFormRow:row];
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearActivityLog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_clear_", nil)];
  68. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  69. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  70. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  71. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearActivity] forKey:@"imageView.image"];
  72. row.action.formSelector = @selector(clearActivity:);
  73. [section addFormRow:row];
  74. section = [XLFormSectionDescriptor formSection];
  75. [form addFormSection:section];
  76. self.form = form;
  77. }
  78. - (void)viewDidLoad
  79. {
  80. [super viewDidLoad];
  81. // Color
  82. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  83. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  84. // Intro
  85. self.intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.splitViewController.view];
  86. }
  87. // Apparirà
  88. - (void)viewWillAppear:(BOOL)animated
  89. {
  90. [super viewWillAppear:animated];
  91. // Color
  92. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  93. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  94. }
  95. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  96. {
  97. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  98. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  99. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  100. [CCUtility setActivityVerboseHigh:true];
  101. } else {
  102. [CCUtility setActivityVerboseHigh:false];
  103. }
  104. // Clear Date read Activity for force reload datasource
  105. app.controlCenterActivity.storeDateFirstActivity = nil;
  106. }
  107. }
  108. #pragma --------------------------------------------------------------------------------------------
  109. #pragma mark === Intro ===
  110. #pragma --------------------------------------------------------------------------------------------
  111. - (void)intro:(XLFormRowDescriptor *)sender
  112. {
  113. [self deselectFormRow:sender];
  114. [self.intro showIntroCryptoCloud:0.1];
  115. }
  116. #pragma --------------------------------------------------------------------------------------------
  117. #pragma mark === Mail ===
  118. #pragma --------------------------------------------------------------------------------------------
  119. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  120. {
  121. switch (result)
  122. {
  123. case MFMailComposeResultCancelled:
  124. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  125. break;
  126. case MFMailComposeResultSaved:
  127. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  128. break;
  129. case MFMailComposeResultSent:
  130. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  131. break;
  132. case MFMailComposeResultFailed: {
  133. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  134. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  135. }
  136. break;
  137. default:
  138. break;
  139. }
  140. // Close the Mail Interface
  141. [self dismissViewControllerAnimated:YES completion:NULL];
  142. }
  143. - (void)sendMail:(XLFormRowDescriptor *)sender
  144. {
  145. [self deselectFormRow:sender];
  146. // Email Subject
  147. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  148. // Email Content
  149. NSString *messageBody;
  150. // File Attachment
  151. NSString *fileAttachment = @"";
  152. // Email Recipents
  153. NSArray *toRecipents;
  154. NSArray *activities = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"((account == %@) || (account == ''))", app.activeAccount]];
  155. if ([activities count] == 0) {
  156. [app messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  157. return;
  158. }
  159. for (TableActivity *activity in activities) {
  160. NSString *date, *type, *actionFile, *note;
  161. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  162. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  163. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  164. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  165. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  166. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  167. else note = activity.note;
  168. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  169. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  170. }
  171. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", k_brand,[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  172. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  173. NSString *documentsDirectory = [paths objectAtIndex:0];
  174. NSError *error;
  175. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
  176. toRecipents = [NSArray arrayWithObject:k_mailMe];
  177. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  178. mc.mailComposeDelegate = self;
  179. [mc setSubject:emailTitle];
  180. [mc setMessageBody:messageBody isHTML:NO];
  181. [mc setToRecipients:toRecipents];
  182. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  183. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  184. // Present mail view controller on screen
  185. [self presentViewController:mc animated:YES completion:NULL];
  186. } else {
  187. [app messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  188. }
  189. }
  190. #pragma --------------------------------------------------------------------------------------------
  191. #pragma mark === Clear ===
  192. #pragma --------------------------------------------------------------------------------------------
  193. - (void)clearActivity:(XLFormRowDescriptor *)sender
  194. {
  195. [self deselectFormRow:sender];
  196. [CCCoreData flushTableActivityAccount:app.activeAccount];
  197. [app.controlCenterActivity reloadDatasource];
  198. }
  199. @end