CCSettings.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // CCSettings.m
  3. // Nextcloud iOS
  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 "CCSettings.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "OCCapabilities.h"
  27. #import "CCSynchronize.h"
  28. #import "CCAdvanced.h"
  29. #import "CCManageAccount.h"
  30. #import "NCManageEndToEndEncryption.h"
  31. #import "NCBridgeSwift.h"
  32. #define alertViewEsci 1
  33. #define alertViewAzzeraCache 2
  34. @implementation CCSettings
  35. - (id)initWithCoder:(NSCoder *)aDecoder
  36. {
  37. self = [super initWithCoder:aDecoder];
  38. if (self) {
  39. [self initializeForm];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  41. app.activeSettings = self;
  42. }
  43. return self;
  44. }
  45. - (void)initializeForm
  46. {
  47. XLFormDescriptor *form;
  48. XLFormSectionDescriptor *section;
  49. XLFormRowDescriptor *row;
  50. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  51. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  52. // Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
  53. section = [XLFormSectionDescriptor formSection];
  54. [form addFormSection:section];
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)];
  56. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  57. [row.cellConfig setObject:[UIImage imageNamed:@"settingsCameraUpload"] forKey:@"imageView.image"];
  58. row.action.formSegueIdentifier = @"CCManageAutoUploadSegue";
  59. [section addFormRow:row];
  60. // Section FOLDERS FAVORITES OFFLINE ------------------------------------
  61. section = [XLFormSectionDescriptor formSection];
  62. [form addFormSection:section];
  63. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"favoriteoffline" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_favorite_offline_", nil)];
  64. [row.cellConfig setObject:[UIImage imageNamed:@"settingsFavoriteOffline"] forKey:@"imageView.image"];
  65. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  66. [section addFormRow:row];
  67. // Section : LOCK --------------------------------------------------------------
  68. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_lock_", nil)];
  69. [form addFormSection:section];
  70. // Lock active YES/NO
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  72. [row.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  73. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  74. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  75. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  76. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  77. row.action.formSelector = @selector(bloccoPassword);
  78. [section addFormRow:row];
  79. // Passcode simply
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  82. [section addFormRow:row];
  83. // Lock no screen
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
  85. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  86. [section addFormRow:row];
  87. // Section : E2EEncryption --------------------------------------------------------------
  88. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
  89. [form addFormSection:section];
  90. // EndToEnd Encryption
  91. NSString *title = [NSString stringWithFormat:@"%@ (%@)",NSLocalizedString(@"_e2e_settings_", nil), NSLocalizedString(@"_experimental_", nil)];
  92. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title];
  93. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  94. [row.cellConfig setObject:[UIImage imageNamed:@"settingsE2EEncryption"] forKey:@"imageView.image"];
  95. row.action.viewControllerClass = [NCManageEndToEndEncryption class];
  96. [section addFormRow:row];
  97. // Section Advanced -------------------------------------------------
  98. section = [XLFormSectionDescriptor formSection];
  99. [form addFormSection:section];
  100. // Advanced
  101. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  102. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  103. [row.cellConfig setObject:[UIImage imageNamed:@"settingsAdvanced"] forKey:@"imageView.image"];
  104. row.action.viewControllerClass = [CCAdvanced class];
  105. [section addFormRow:row];
  106. // Section : INFORMATION ------------------------------------------------
  107. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  108. [form addFormSection:section];
  109. // Acknowledgements
  110. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  111. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  112. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  113. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  114. [row.cellConfig setObject:[UIImage imageNamed:@"settingsAcknowledgements"] forKey:@"imageView.image"];
  115. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  116. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  117. [self deselectFormRow:sender];
  118. };
  119. [section addFormRow:row];
  120. // Contact us mail
  121. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  122. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  123. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  124. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  125. [row.cellConfig setObject:[UIImage imageNamed:@"settingsMail"] forKey:@"imageView.image"];
  126. row.action.formSelector = @selector(sendMail:);
  127. [section addFormRow:row];
  128. self.form = form;
  129. }
  130. // Apparirà
  131. - (void)viewWillAppear:(BOOL)animated
  132. {
  133. [super viewWillAppear:animated];
  134. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  135. self.tableView.showsVerticalScrollIndicator = NO;
  136. // Color
  137. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  138. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  139. [self reloadForm];
  140. }
  141. - (void)changeTheming
  142. {
  143. if (self.isViewLoaded && self.view.window)
  144. [app changeTheming:self];
  145. }
  146. #pragma --------------------------------------------------------------------------------------------
  147. #pragma mark === Chiamate dal Form ===
  148. #pragma --------------------------------------------------------------------------------------------
  149. - (void)reloadForm
  150. {
  151. self.form.delegate = nil;
  152. // ----------------------
  153. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  154. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  155. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  156. XLFormRowDescriptor *rowFavoriteOffline = [self.form formRowWithTag:@"favoriteoffline"];
  157. // ------------------------------------------------------------------
  158. if ([[CCUtility getBlockCode] length]) {
  159. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  160. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeYES"] forKey:@"imageView.image"];
  161. } else {
  162. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  163. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  164. }
  165. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  166. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  167. if ([CCUtility getFavoriteOffline]) [rowFavoriteOffline setValue:@1]; else [rowFavoriteOffline setValue:@0];
  168. // -----------------------------------------------------------------
  169. [self.tableView reloadData];
  170. self.form.delegate = self;
  171. }
  172. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  173. {
  174. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  175. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  176. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  177. [CCUtility setOnlyLockDir:true];
  178. } else {
  179. [CCUtility setOnlyLockDir:false];
  180. }
  181. }
  182. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  183. if ([[CCUtility getBlockCode] length] == 0)
  184. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  185. else
  186. [self changeSimplyPassword];
  187. }
  188. if ([rowDescriptor.tag isEqualToString:@"favoriteoffline"]) {
  189. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  190. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_continue_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  191. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  192. [CCUtility setFavoriteOffline:true];
  193. [self synchronizeFavorites];
  194. }]];
  195. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  196. [self reloadForm];
  197. }]];
  198. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  199. // iPhone
  200. [self presentViewController:alertController animated:YES completion:nil];
  201. }else {
  202. // iPad
  203. // Change Rect to position Popover
  204. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  205. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:rowDescriptor]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  206. }
  207. } else {
  208. [CCUtility setFavoriteOffline:false];
  209. }
  210. }
  211. }
  212. - (void)changeSimplyPassword
  213. {
  214. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  215. viewController.delegate = self;
  216. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  217. viewController.fromType = CCBKPasscodeFromSimply;
  218. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  219. viewController.inputViewTitlePassword = YES;
  220. if ([CCUtility getSimplyBlockCode]) {
  221. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  222. viewController.passcodeInputView.maximumLength = 6;
  223. } else {
  224. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  225. viewController.passcodeInputView.maximumLength = 64;
  226. }
  227. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  228. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  229. viewController.touchIDManager = touchIDManager;
  230. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  231. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  232. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  233. [self presentViewController:navigationController animated:YES completion:nil];
  234. }
  235. - (void)bloccoPassword
  236. {
  237. // ATTIVAZIONE LOCK PASSWORD
  238. if ([[CCUtility getBlockCode] length] == 0) {
  239. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  240. viewController.delegate = self;
  241. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  242. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  243. viewController.inputViewTitlePassword = YES;
  244. if ([CCUtility getSimplyBlockCode]) {
  245. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  246. viewController.passcodeInputView.maximumLength = 6;
  247. } else {
  248. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  249. viewController.passcodeInputView.maximumLength = 64;
  250. }
  251. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  252. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  253. viewController.touchIDManager = touchIDManager;
  254. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  255. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  256. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  257. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  258. [self presentViewController:navigationController animated:YES completion:nil];
  259. } else {
  260. // OFF LOCK PASSWORD
  261. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  262. viewController.delegate = self;
  263. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  264. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  265. viewController.inputViewTitlePassword = YES;
  266. if ([CCUtility getSimplyBlockCode]) {
  267. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  268. viewController.passcodeInputView.maximumLength = 6;
  269. } else {
  270. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  271. viewController.passcodeInputView.maximumLength = 64;
  272. }
  273. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  274. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  275. viewController.touchIDManager = touchIDManager;
  276. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  277. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  278. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  279. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  280. [self presentViewController:navigationController animated:YES completion:nil];
  281. }
  282. }
  283. - (void)synchronizeFavorites
  284. {
  285. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND favorite = true", app.activeAccount] sorted:nil ascending:NO];
  286. for (tableMetadata *metadata in metadatas) {
  287. if (metadata.directory) {
  288. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  289. if (!serverUrl) continue;
  290. serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
  291. NSString *serverUrlBeginWith = serverUrl;
  292. if (![serverUrl hasSuffix:@"/"])
  293. serverUrlBeginWith = [serverUrl stringByAppendingString:@"/"];
  294. NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND (serverUrl = %@ OR serverUrl BEGINSWITH %@)", app.activeAccount, serverUrl, serverUrlBeginWith] sorted:@"serverUrl" ascending:true];
  295. for (tableDirectory *directory in directories)
  296. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:nil directoryID:directory.directoryID];
  297. }
  298. }
  299. [app.activeFavorites readListingFavorites];
  300. }
  301. #pragma --------------------------------------------------------------------------------------------
  302. #pragma mark === Table View ===
  303. #pragma --------------------------------------------------------------------------------------------
  304. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  305. {
  306. NSString *sectionName;
  307. switch (section)
  308. {
  309. case 1: {
  310. sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
  311. }
  312. break;
  313. case 2: {
  314. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  315. }
  316. break;
  317. case 4: {
  318. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilites];
  319. NSString *versionServer = capabilities.versionString;
  320. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  321. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudServer, versionServer];
  322. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  323. sectionName = [NSString stringWithFormat:@"%@\n%@", versionNextcloudiOS, versionNextcloud];
  324. }
  325. break;
  326. }
  327. return sectionName;
  328. }
  329. #pragma --------------------------------------------------------------------------------------------
  330. #pragma mark === Mail ===
  331. #pragma --------------------------------------------------------------------------------------------
  332. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  333. {
  334. switch (result)
  335. {
  336. case MFMailComposeResultCancelled:
  337. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  338. break;
  339. case MFMailComposeResultSaved:
  340. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  341. break;
  342. case MFMailComposeResultSent:
  343. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  344. break;
  345. case MFMailComposeResultFailed: {
  346. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  347. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  348. }
  349. break;
  350. default:
  351. break;
  352. }
  353. // Close the Mail Interface
  354. [self dismissViewControllerAnimated:YES completion:NULL];
  355. }
  356. - (void)sendMail:(XLFormRowDescriptor *)sender
  357. {
  358. if ([MFMailComposeViewController canSendMail]) {
  359. // Email Subject
  360. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  361. // Email Content
  362. NSString *messageBody;
  363. // Email Recipents
  364. NSArray *toRecipents;
  365. messageBody = [NSString stringWithFormat:@"%@\n\n\n\n%@ Version %@ (%@) - iOS %@", NSLocalizedString(@"_write_in_english_", nil), [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], [[UIDevice currentDevice] systemVersion]];
  366. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  367. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  368. mc.mailComposeDelegate = self;
  369. [mc setSubject:emailTitle];
  370. [mc setMessageBody:messageBody isHTML:NO];
  371. [mc setToRecipients:toRecipents];
  372. // Present mail view controller on screen
  373. [self presentViewController:mc animated:YES completion:NULL];
  374. }
  375. }
  376. #pragma --------------------------------------------------------------------------------------------
  377. #pragma mark === BKPasscodeViewController ===
  378. #pragma --------------------------------------------------------------------------------------------
  379. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  380. {
  381. [aViewController dismissViewControllerAnimated:YES completion:nil];
  382. switch (aViewController.type) {
  383. case BKPasscodeViewControllerNewPasscodeType: {
  384. // enable passcode
  385. [CCUtility setBlockCode:aPasscode];
  386. }
  387. break;
  388. case BKPasscodeViewControllerCheckPasscodeType: {
  389. // disable passcode
  390. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  391. [CCUtility setBlockCode:@""];
  392. [[NCManageDatabase sharedInstance] setAllDirectoryUnLock];
  393. [app.activeMain.tableView reloadData];
  394. }
  395. // change simply
  396. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  397. // disable passcode
  398. [CCUtility setBlockCode:@""];
  399. [[NCManageDatabase sharedInstance] setAllDirectoryUnLock];
  400. [app.activeMain.tableView reloadData];
  401. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  402. // Call new passcode
  403. [self bloccoPassword];
  404. }
  405. }
  406. break;
  407. default:
  408. break;
  409. }
  410. [self reloadForm];
  411. }
  412. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  413. {
  414. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  415. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  416. self.lockUntilDate = nil;
  417. self.failedAttempts = 0;
  418. aResultHandler(YES);
  419. } else aResultHandler(NO);
  420. }
  421. }
  422. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  423. {
  424. self.failedAttempts++;
  425. if (self.failedAttempts > 5) {
  426. NSTimeInterval timeInterval = 60;
  427. if (self.failedAttempts > 6) {
  428. NSUInteger multiplier = self.failedAttempts - 6;
  429. timeInterval = (5 * 60) * multiplier;
  430. if (timeInterval > 3600 * 24) {
  431. timeInterval = 3600 * 24;
  432. }
  433. }
  434. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  435. }
  436. }
  437. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  438. {
  439. return self.failedAttempts;
  440. }
  441. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  442. {
  443. return self.lockUntilDate;
  444. }
  445. - (void)passcodeViewCloseButtonPressed:(id)sender
  446. {
  447. [self dismissViewControllerAnimated:YES completion:nil];
  448. }
  449. @end