CCSettings.m 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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 "TableAccount+CoreDataClass.h"
  27. #define alertViewEsci 1
  28. #define alertViewAzzeraCache 2
  29. @implementation CCSettings
  30. - (id)initWithCoder:(NSCoder *)aDecoder
  31. {
  32. self = [super initWithCoder:aDecoder];
  33. if (self) {
  34. [self initializeForm];
  35. app.activeSettings = self;
  36. }
  37. return self;
  38. }
  39. - (void)initializeForm
  40. {
  41. XLFormDescriptor *form;
  42. XLFormSectionDescriptor *section;
  43. XLFormRowDescriptor *row;
  44. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. // Section : PASSWORD --------------------------------------------------------------
  47. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_passcode_", nil)];
  48. [form addFormSection:section];
  49. // Passcode
  50. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  51. [row.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  52. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  53. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  54. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  55. row.action.formSelector = @selector(bloccoPassword);
  56. [section addFormRow:row];
  57. // Passcode simply
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [section addFormRow:row];
  61. // Passcode only directory
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_folder_", nil)];
  63. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  64. [section addFormRow:row];
  65. // Section : CLOUD ACCOUNT --------------------------------------------------------------
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_cloud_account_", nil)];
  67. [form addFormSection:section];
  68. // version
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versionserver" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_version_server_", nil)];
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  72. [section addFormRow:row];
  73. // Url
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"urlcloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_url_", nil)];
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  77. [section addFormRow:row];
  78. // username
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usernamecloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_username_", nil)];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  82. [section addFormRow:row];
  83. // information
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userinformation" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_information_", nil)];
  85. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  87. row.cellConfig[@"textLabel.numberOfLines"] = @0;
  88. [section addFormRow:row];
  89. // email
  90. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useremail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_email_", nil)];
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  93. [section addFormRow:row];
  94. // quota
  95. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quota" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_quota_", nil)];
  96. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  97. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  98. [section addFormRow:row];
  99. // Change Account
  100. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"changecredentials" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_change_credentials_", nil)];
  101. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  102. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCredentials] forKey:@"imageView.image"];
  103. row.action.formSegueIdentifier = @"CCManageAccountSegue";
  104. [section addFormRow:row];
  105. // Section --------------------------------------------------------------
  106. section = [XLFormSectionDescriptor formSection];
  107. [form addFormSection:section];
  108. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cameraupload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_uploading_from_camera_", nil)];
  109. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  110. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCameraUpload] forKey:@"imageView.image"];
  111. row.action.formSegueIdentifier = @"CCManageCameraUploadSegue";
  112. [section addFormRow:row];
  113. // Section --------------------------------------------------------------
  114. section = [XLFormSectionDescriptor formSection];
  115. [form addFormSection:section];
  116. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizations" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_optimizations_", nil)];
  117. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  118. [row.cellConfig setObject:[UIImage imageNamed:image_settingsOptimizations] forKey:@"imageView.image"];
  119. row.action.formSegueIdentifier = @"CCManageOptimizationsSegue";
  120. [section addFormRow:row];
  121. // Section --------------------------------------------------------------
  122. section = [XLFormSectionDescriptor formSection];
  123. [form addFormSection:section];
  124. // Crypto Cloud
  125. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cryptocloud" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_crypto_cloud_system_", nil)];
  126. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  127. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCryptoCloud] forKey:@"imageView.image"];
  128. row.action.formSegueIdentifier = @"CCManageCryptoCloudSegue";
  129. [section addFormRow:row];
  130. // Section : INFORMATION --------------------------------------------------------------
  131. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  132. [form addFormSection:section];
  133. section.footerTitle = @"Nextcloud © 2017 T.W.S. Inc.";
  134. // Acknowledgements
  135. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  136. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  137. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  138. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAcknowledgements] forKey:@"imageView.image"];
  139. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  140. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  141. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  142. [self deselectFormRow:sender];
  143. };
  144. [section addFormRow:row];
  145. // Help
  146. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"help" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_", nil)];
  147. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  148. [row.cellConfig setObject:[UIImage imageNamed:image_settingsHelp] forKey:@"imageView.image"];
  149. row.action.formSegueIdentifier = @"CCManageHelpSegue";
  150. [section addFormRow:row];
  151. // Contact us mail
  152. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  153. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  154. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  155. [row.cellConfig setObject:[UIImage imageNamed:image_settingsMail] forKey:@"imageView.image"];
  156. row.action.formSelector = @selector(sendMail:);
  157. [section addFormRow:row];
  158. // Version
  159. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versioneapplicazione" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_app_version_", nil)];
  160. row.value = [NSString stringWithFormat:@"%@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  161. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  162. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  163. [section addFormRow:row];
  164. // Section --------------------------------------------------------------
  165. section = [XLFormSectionDescriptor formSection];
  166. [form addFormSection:section];
  167. // Clear cache
  168. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:@""];
  169. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  170. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearCache] forKey:@"imageView.image"];
  171. row.action.formSelector = @selector(azzeraCache:);
  172. [section addFormRow:row];
  173. // Section --------------------------------------------------------------
  174. section = [XLFormSectionDescriptor formSection];
  175. [form addFormSection:section];
  176. // Exit
  177. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:[CCUtility localizableBrand:@"_exit_" table:nil]];
  178. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  179. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  180. [row.cellConfig setObject:[UIImage imageNamed:image_settingsExit] forKey:@"imageView.image"];
  181. row.action.formSelector = @selector(esci:);
  182. [section addFormRow:row];
  183. #ifdef DEBUG
  184. /*
  185. // Section : debug
  186. section = [XLFormSectionDescriptor formSectionWithTitle:@"Debug"];
  187. [form addFormSection:section];
  188. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"adminRemoveVersion" rowType:XLFormRowDescriptorTypeButton title:@"Remove Version"];
  189. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  190. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  191. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  192. row.action.formSelector = @selector(adminRemoveVersion:);
  193. [section addFormRow:row];
  194. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quickActionPhotos" rowType:XLFormRowDescriptorTypeButton title:@"Quick Action Photos"];
  195. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  196. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  197. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  198. row.action.formSelector = @selector(quickActionPhotos:);
  199. [section addFormRow:row];
  200. */
  201. #endif
  202. self.form = form;
  203. }
  204. - (void)viewDidLoad
  205. {
  206. [super viewDidLoad];
  207. self.hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  208. self.title = NSLocalizedString(@"_settings_", nil);
  209. // Color
  210. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  211. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  212. }
  213. // Apparirà
  214. - (void)viewWillAppear:(BOOL)animated
  215. {
  216. [super viewWillAppear:animated];
  217. // Color
  218. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  219. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  220. [self reloadForm];
  221. [self recalculateSize];
  222. }
  223. // E' apparsa
  224. - (void)viewDidAppear:(BOOL)animated
  225. {
  226. [super viewDidAppear:animated];
  227. }
  228. #pragma --------------------------------------------------------------------------------------------
  229. #pragma mark === Admin ===
  230. #pragma --------------------------------------------------------------------------------------------
  231. /*
  232. - (void)adminRemoveVersion:(XLFormRowDescriptor *)sender
  233. {
  234. [self deselectFormRow:sender];
  235. [CCUtility adminRemoveVersion];
  236. exit(0);
  237. }
  238. - (void)quickActionPhotos:(XLFormRowDescriptor *)sender
  239. {
  240. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  241. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:@"" localizedSubtitle:nil icon:nil userInfo:nil];
  242. [app handleShortCutItem:shortcutPhotos];
  243. }
  244. */
  245. #pragma --------------------------------------------------------------------------------------------
  246. #pragma mark === Chiamate dal Form ===
  247. #pragma --------------------------------------------------------------------------------------------
  248. - (void)reloadForm
  249. {
  250. self.form.delegate = nil;
  251. // ----------------------
  252. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  253. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  254. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  255. XLFormRowDescriptor *rowVersionServer = [self.form formRowWithTag:@"versionserver"];
  256. XLFormRowDescriptor *rowUrlCloud = [self.form formRowWithTag:@"urlcloud"];
  257. XLFormRowDescriptor *rowUserNameCloud = [self.form formRowWithTag:@"usernamecloud"];
  258. XLFormRowDescriptor *rowUserInformation = [self.form formRowWithTag:@"userinformation"];
  259. XLFormRowDescriptor *rowUserEmail = [self.form formRowWithTag:@"useremail"];
  260. XLFormRowDescriptor *rowQuota = [self.form formRowWithTag:@"quota"];
  261. // ------------------------------------------------------------------
  262. if ([[CCUtility getBlockCode] length]) {
  263. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  264. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeYES] forKey:@"imageView.image"];
  265. } else {
  266. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  267. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  268. }
  269. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  270. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  271. TableAccount *tableAccount = [CCCoreData getActiveAccount];
  272. rowVersionServer.value = [CCNetworking sharedNetworking].sharedOCCommunication.getCurrentServerVersion;
  273. rowUrlCloud.value = app.activeUrl;
  274. rowUserNameCloud.value = app.activeUser;
  275. if (tableAccount.displayName.length > 0 || tableAccount.address.length > 0 || tableAccount.phone.length > 0) {
  276. rowUserInformation.title = [NSString stringWithFormat:@"%@ %@ %@", tableAccount.displayName, tableAccount.address, tableAccount.phone];
  277. rowUserInformation.disabled = @YES;
  278. } else {
  279. rowUserInformation.title = NSLocalizedString(@"_information_", nil);
  280. rowUserInformation.disabled = @NO;
  281. }
  282. rowUserEmail.value = tableAccount.email;
  283. NSString *quota = [CCUtility transformedSize:[tableAccount.quotaTotal doubleValue]];
  284. NSString *quotaAvailable = [CCUtility transformedSize:[tableAccount.quotaFree doubleValue]];
  285. rowQuota.value = [NSString stringWithFormat:@"%@ / %@ %@", quota, quotaAvailable, NSLocalizedString(@"_available_", nil)];
  286. // -----------------------------------------------------------------
  287. [self.tableView reloadData];
  288. self.form.delegate = self;
  289. }
  290. - (void)recalculateSize
  291. {
  292. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  293. self.form.delegate = nil;
  294. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  295. //NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  296. //rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  297. rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  298. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  299. self.form.delegate = self;
  300. });
  301. }
  302. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  303. {
  304. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  305. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  306. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  307. [CCUtility setOnlyLockDir:true];
  308. } else {
  309. [CCUtility setOnlyLockDir:false];
  310. }
  311. }
  312. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  313. if ([[CCUtility getBlockCode] length] == 0)
  314. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  315. else
  316. [self changeSimplyPassword];
  317. }
  318. }
  319. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  320. {
  321. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  322. viewController.delegate = self;
  323. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  324. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  325. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  326. viewController.passcodeInputView.maximumLength = 64;
  327. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  328. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  329. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  330. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  331. [self presentViewController:navigationController animated:YES completion:nil];
  332. }
  333. - (void)changeSimplyPassword
  334. {
  335. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  336. viewController.delegate = self;
  337. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  338. viewController.fromType = CCBKPasscodeFromSimply;
  339. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  340. viewController.inputViewTitlePassword = YES;
  341. if ([CCUtility getSimplyBlockCode]) {
  342. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  343. viewController.passcodeInputView.maximumLength = 6;
  344. } else {
  345. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  346. viewController.passcodeInputView.maximumLength = 64;
  347. }
  348. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  349. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  350. viewController.touchIDManager = touchIDManager;
  351. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  352. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  353. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  354. [self presentViewController:navigationController animated:YES completion:nil];
  355. }
  356. - (void)bloccoPassword
  357. {
  358. // ATTIVAZIONE LOCK PASSWORD
  359. if ([[CCUtility getBlockCode] length] == 0) {
  360. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  361. viewController.delegate = self;
  362. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  363. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  364. viewController.inputViewTitlePassword = YES;
  365. if ([CCUtility getSimplyBlockCode]) {
  366. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  367. viewController.passcodeInputView.maximumLength = 6;
  368. } else {
  369. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  370. viewController.passcodeInputView.maximumLength = 64;
  371. }
  372. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  373. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  374. viewController.touchIDManager = touchIDManager;
  375. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  376. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  377. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  378. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  379. [self presentViewController:navigationController animated:YES completion:nil];
  380. } else {
  381. // OFF LOCK PASSWORD
  382. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  383. viewController.delegate = self;
  384. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  385. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  386. viewController.inputViewTitlePassword = YES;
  387. if ([CCUtility getSimplyBlockCode]) {
  388. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  389. viewController.passcodeInputView.maximumLength = 6;
  390. } else {
  391. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  392. viewController.passcodeInputView.maximumLength = 64;
  393. }
  394. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  395. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  396. viewController.touchIDManager = touchIDManager;
  397. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  398. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  399. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  400. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  401. [self presentViewController:navigationController animated:YES completion:nil];
  402. }
  403. }
  404. - (void)esci:(XLFormRowDescriptor *)sender
  405. {
  406. [self deselectFormRow:sender];
  407. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:[CCUtility localizableBrand:@"_exit_" table:nil]
  408. message:[CCUtility localizableBrand:@"_want_exit_" table:nil]
  409. delegate:self
  410. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  411. otherButtonTitles: nil];
  412. alertView.tag = alertViewEsci;
  413. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  414. [alertView show];
  415. }
  416. - (void)azzeraCache:(XLFormRowDescriptor *)sender
  417. {
  418. [self deselectFormRow:sender];
  419. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"_delete_cache_",nil)
  420. message:NSLocalizedString(@"_want_delete_cache_", nil)
  421. delegate:self
  422. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  423. otherButtonTitles: nil];
  424. alertView.tag = alertViewAzzeraCache;
  425. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  426. [alertView show];
  427. }
  428. #pragma --------------------------------------------------------------------------------------------
  429. #pragma mark === Mail ===
  430. #pragma --------------------------------------------------------------------------------------------
  431. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  432. {
  433. switch (result)
  434. {
  435. case MFMailComposeResultCancelled:
  436. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  437. break;
  438. case MFMailComposeResultSaved:
  439. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  440. break;
  441. case MFMailComposeResultSent:
  442. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  443. break;
  444. case MFMailComposeResultFailed: {
  445. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  446. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  447. }
  448. break;
  449. default:
  450. break;
  451. }
  452. // Close the Mail Interface
  453. [self dismissViewControllerAnimated:YES completion:NULL];
  454. }
  455. - (void)sendMail:(XLFormRowDescriptor *)sender
  456. {
  457. // Email Subject
  458. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  459. // Email Content
  460. NSString *messageBody;
  461. // Email Recipents
  462. NSArray *toRecipents;
  463. messageBody = [NSString stringWithFormat:@"\n\n\nNextcloud Version %@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  464. toRecipents = [NSArray arrayWithObject:_mail_me_];
  465. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  466. mc.mailComposeDelegate = self;
  467. [mc setSubject:emailTitle];
  468. [mc setMessageBody:messageBody isHTML:NO];
  469. [mc setToRecipients:toRecipents];
  470. // Present mail view controller on screen
  471. [self presentViewController:mc animated:YES completion:NULL];
  472. }
  473. - (void)sendMailEncryptPass
  474. {
  475. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self];
  476. }
  477. #pragma --------------------------------------------------------------------------------------------
  478. #pragma mark === AlertView ===
  479. #pragma --------------------------------------------------------------------------------------------
  480. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  481. {
  482. // Remove ALL
  483. if (buttonIndex == 1 && alertView.tag == alertViewEsci)
  484. {
  485. [self.hud visibleIndeterminateHud];
  486. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  487. [app cancelAllOperations];
  488. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  489. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  490. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  491. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  492. [CCCoreData flushAllDatabase];
  493. [CCUtility deleteAllChainStore];
  494. [self emptyDocumentsDirectory];
  495. [self emptyLibraryDirectory];
  496. [self emptyGroupApplicationSupport];
  497. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  498. for (NSString *file in tmpDirectory)
  499. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  500. [self.hud hideHud];
  501. exit(0);
  502. });
  503. }
  504. // Clear Cache
  505. if (buttonIndex == 1 && alertView.tag == alertViewAzzeraCache)
  506. {
  507. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  508. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  509. [app cancelAllOperations];
  510. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  511. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  512. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  513. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  514. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  515. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  516. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  517. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  518. [self emptyLocalDirectory];
  519. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  520. for (NSString *file in tmpDirectory)
  521. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  522. [self recalculateSize];
  523. // Inizialized home
  524. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  525. [self.hud hideHud];
  526. });
  527. }
  528. }
  529. #pragma --------------------------------------------------------------------------------------------
  530. #pragma mark === BKPasscodeViewController ===
  531. #pragma --------------------------------------------------------------------------------------------
  532. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  533. {
  534. [aViewController dismissViewControllerAnimated:YES completion:nil];
  535. switch (aViewController.type) {
  536. case BKPasscodeViewControllerNewPasscodeType: {
  537. // enable passcode
  538. [CCUtility setBlockCode:aPasscode];
  539. }
  540. break;
  541. case BKPasscodeViewControllerCheckPasscodeType: {
  542. // disable passcode
  543. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  544. [CCUtility setBlockCode:@""];
  545. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  546. [app.activeMain.tableView reloadData];
  547. }
  548. // email Key EAS-256
  549. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  550. [self sendMailEncryptPass];
  551. // change simply
  552. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  553. // disable passcode
  554. [CCUtility setBlockCode:@""];
  555. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  556. [app.activeMain.tableView reloadData];
  557. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  558. // Call new passcode
  559. [self bloccoPassword];
  560. }
  561. }
  562. break;
  563. default:
  564. break;
  565. }
  566. [self reloadForm];
  567. }
  568. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  569. {
  570. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  571. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  572. if ([aPasscode isEqualToString:key]) {
  573. self.lockUntilDate = nil;
  574. self.failedAttempts = 0;
  575. aResultHandler(YES);
  576. } else aResultHandler(NO);
  577. }
  578. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  579. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  580. self.lockUntilDate = nil;
  581. self.failedAttempts = 0;
  582. aResultHandler(YES);
  583. } else aResultHandler(NO);
  584. }
  585. }
  586. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  587. {
  588. self.failedAttempts++;
  589. if (self.failedAttempts > 5) {
  590. NSTimeInterval timeInterval = 60;
  591. if (self.failedAttempts > 6) {
  592. NSUInteger multiplier = self.failedAttempts - 6;
  593. timeInterval = (5 * 60) * multiplier;
  594. if (timeInterval > 3600 * 24) {
  595. timeInterval = 3600 * 24;
  596. }
  597. }
  598. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  599. }
  600. }
  601. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  602. {
  603. return self.failedAttempts;
  604. }
  605. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  606. {
  607. return self.lockUntilDate;
  608. }
  609. - (void)passcodeViewCloseButtonPressed:(id)sender
  610. {
  611. [self dismissViewControllerAnimated:YES completion:nil];
  612. }
  613. #pragma --------------------------------------------------------------------------------------------
  614. #pragma mark == Utility ==
  615. #pragma --------------------------------------------------------------------------------------------
  616. - (void)emptyGroupApplicationSupport
  617. {
  618. NSString *file;
  619. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  620. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  621. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  622. while (file = [enumerator nextObject])
  623. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  624. }
  625. - (void)emptyLibraryDirectory
  626. {
  627. NSString *file;
  628. NSString *dirIniziale;
  629. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  630. dirIniziale = [paths objectAtIndex:0];
  631. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  632. while (file = [enumerator nextObject])
  633. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  634. }
  635. - (void)emptyDocumentsDirectory
  636. {
  637. NSString *file;
  638. NSString *dirIniziale;
  639. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  640. dirIniziale = [paths objectAtIndex:0];
  641. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  642. while (file = [enumerator nextObject])
  643. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  644. }
  645. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  646. {
  647. NSString *file;
  648. NSString *dirIniziale;
  649. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  650. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  651. while (file = [enumerator nextObject]) {
  652. NSString *ext = [[file pathExtension] lowercaseString];
  653. // Do not remove ICO
  654. if ([ext isEqualToString:@"ico"])
  655. continue;
  656. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  657. }
  658. }
  659. - (void)emptyLocalDirectory
  660. {
  661. NSString *file;
  662. NSString *dirIniziale;
  663. dirIniziale = [CCUtility getDirectoryLocal];
  664. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  665. while (file = [enumerator nextObject])
  666. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  667. }
  668. - (NSNumber *)getUserDirectorySize
  669. {
  670. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  671. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  672. unsigned long long count = 0;
  673. NSNumber *value = nil;
  674. if (! directoryURL) return 0;
  675. // Get dimension Document
  676. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  677. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  678. count += [value longLongValue];
  679. } else {
  680. return nil;
  681. }
  682. }
  683. return @(count);
  684. }
  685. @end