CCSettings.m 26 KB

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