CCSettings.m 27 KB

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