CCSettings.m 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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. }
  222. // E' apparsa
  223. - (void)viewDidAppear:(BOOL)animated
  224. {
  225. [super viewDidAppear:animated];
  226. }
  227. #pragma --------------------------------------------------------------------------------------------
  228. #pragma mark === Admin ===
  229. #pragma --------------------------------------------------------------------------------------------
  230. /*
  231. - (void)adminRemoveVersion:(XLFormRowDescriptor *)sender
  232. {
  233. [self deselectFormRow:sender];
  234. [CCUtility adminRemoveVersion];
  235. exit(0);
  236. }
  237. - (void)quickActionPhotos:(XLFormRowDescriptor *)sender
  238. {
  239. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  240. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:@"" localizedSubtitle:nil icon:nil userInfo:nil];
  241. [app handleShortCutItem:shortcutPhotos];
  242. }
  243. */
  244. #pragma --------------------------------------------------------------------------------------------
  245. #pragma mark === Chiamate dal Form ===
  246. #pragma --------------------------------------------------------------------------------------------
  247. - (void)reloadForm
  248. {
  249. self.form.delegate = nil;
  250. // ----------------------
  251. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  252. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  253. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  254. XLFormRowDescriptor *rowVersionServer = [self.form formRowWithTag:@"versionserver"];
  255. XLFormRowDescriptor *rowUrlCloud = [self.form formRowWithTag:@"urlcloud"];
  256. XLFormRowDescriptor *rowUserNameCloud = [self.form formRowWithTag:@"usernamecloud"];
  257. XLFormRowDescriptor *rowUserInformation = [self.form formRowWithTag:@"userinformation"];
  258. XLFormRowDescriptor *rowUserEmail = [self.form formRowWithTag:@"useremail"];
  259. XLFormRowDescriptor *rowQuota = [self.form formRowWithTag:@"quota"];
  260. //XLFormRowDescriptor *rowChangeCredentials = [self.form formRowWithTag:@"changecredentials"];
  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. // Avatar
  272. UIImage *avatar = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser]];
  273. if (avatar) {
  274. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(50, 50)];
  275. APAvatarImageView *avatarImageView = [[APAvatarImageView alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  276. CGSize imageSize = avatarImageView.bounds.size;
  277. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  278. CGContextRef context = UIGraphicsGetCurrentContext();
  279. [avatarImageView.layer renderInContext:context];
  280. avatar = UIGraphicsGetImageFromCurrentImageContext();
  281. UIGraphicsEndImageContext();
  282. }
  283. TableAccount *tableAccount = [CCCoreData getActiveAccount];
  284. rowVersionServer.value = [CCNetworking sharedNetworking].sharedOCCommunication.getCurrentServerVersion;
  285. rowUrlCloud.value = app.activeUrl;
  286. rowUserNameCloud.value = app.activeUser;
  287. if (avatar || tableAccount.displayName.length > 0 || tableAccount.address.length > 0 || tableAccount.phone.length > 0) {
  288. rowUserInformation.title = [NSString stringWithFormat:@"%@ %@ %@", tableAccount.displayName, tableAccount.address, tableAccount.phone];
  289. rowUserInformation.disabled = @YES;
  290. if (avatar)
  291. [rowUserInformation.cellConfig setObject:avatar forKey:@"imageView.image"];
  292. } else {
  293. rowUserInformation.title = NSLocalizedString(@"_information_", nil);
  294. rowUserInformation.disabled = @NO;
  295. }
  296. rowUserEmail.value = tableAccount.email;
  297. NSString *quota = [CCUtility transformedSize:[tableAccount.quotaTotal doubleValue]];
  298. NSString *quotaAvailable = [CCUtility transformedSize:[tableAccount.quotaFree doubleValue]];
  299. rowQuota.value = [NSString stringWithFormat:@"%@ / %@ %@", quota, quotaAvailable, NSLocalizedString(@"_available_", nil)];
  300. // -----------------------------------------------------------------
  301. [self.tableView reloadData];
  302. self.form.delegate = self;
  303. }
  304. - (void)recalculateSize
  305. {
  306. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  307. self.form.delegate = nil;
  308. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  309. //NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  310. //rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  311. rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  312. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  313. self.form.delegate = self;
  314. });
  315. }
  316. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  317. {
  318. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  319. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  320. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  321. [CCUtility setOnlyLockDir:true];
  322. } else {
  323. [CCUtility setOnlyLockDir:false];
  324. }
  325. }
  326. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  327. if ([[CCUtility getBlockCode] length] == 0)
  328. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  329. else
  330. [self changeSimplyPassword];
  331. }
  332. }
  333. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  334. {
  335. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  336. viewController.delegate = self;
  337. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  338. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  339. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  340. viewController.passcodeInputView.maximumLength = 64;
  341. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  342. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  343. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  344. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  345. [self presentViewController:navigationController animated:YES completion:nil];
  346. }
  347. - (void)changeSimplyPassword
  348. {
  349. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  350. viewController.delegate = self;
  351. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  352. viewController.fromType = CCBKPasscodeFromSimply;
  353. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  354. viewController.inputViewTitlePassword = YES;
  355. if ([CCUtility getSimplyBlockCode]) {
  356. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  357. viewController.passcodeInputView.maximumLength = 6;
  358. } else {
  359. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  360. viewController.passcodeInputView.maximumLength = 64;
  361. }
  362. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  363. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  364. viewController.touchIDManager = touchIDManager;
  365. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  366. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  367. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  368. [self presentViewController:navigationController animated:YES completion:nil];
  369. }
  370. - (void)bloccoPassword
  371. {
  372. // ATTIVAZIONE LOCK PASSWORD
  373. if ([[CCUtility getBlockCode] length] == 0) {
  374. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  375. viewController.delegate = self;
  376. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  377. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  378. viewController.inputViewTitlePassword = YES;
  379. if ([CCUtility getSimplyBlockCode]) {
  380. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  381. viewController.passcodeInputView.maximumLength = 6;
  382. } else {
  383. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  384. viewController.passcodeInputView.maximumLength = 64;
  385. }
  386. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  387. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  388. viewController.touchIDManager = touchIDManager;
  389. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  390. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  391. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  392. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  393. [self presentViewController:navigationController animated:YES completion:nil];
  394. } else {
  395. // OFF LOCK PASSWORD
  396. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  397. viewController.delegate = self;
  398. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  399. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  400. viewController.inputViewTitlePassword = YES;
  401. if ([CCUtility getSimplyBlockCode]) {
  402. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  403. viewController.passcodeInputView.maximumLength = 6;
  404. } else {
  405. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  406. viewController.passcodeInputView.maximumLength = 64;
  407. }
  408. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  409. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  410. viewController.touchIDManager = touchIDManager;
  411. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  412. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  413. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  414. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  415. [self presentViewController:navigationController animated:YES completion:nil];
  416. }
  417. }
  418. - (void)esci:(XLFormRowDescriptor *)sender
  419. {
  420. [self deselectFormRow:sender];
  421. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:[CCUtility localizableBrand:@"_exit_" table:nil]
  422. message:[CCUtility localizableBrand:@"_want_exit_" table:nil]
  423. delegate:self
  424. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  425. otherButtonTitles: nil];
  426. alertView.tag = alertViewEsci;
  427. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  428. [alertView show];
  429. }
  430. - (void)azzeraCache:(XLFormRowDescriptor *)sender
  431. {
  432. [self deselectFormRow:sender];
  433. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"_delete_cache_",nil)
  434. message:NSLocalizedString(@"_want_delete_cache_", nil)
  435. delegate:self
  436. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  437. otherButtonTitles: nil];
  438. alertView.tag = alertViewAzzeraCache;
  439. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  440. [alertView show];
  441. }
  442. #pragma --------------------------------------------------------------------------------------------
  443. #pragma mark === Mail ===
  444. #pragma --------------------------------------------------------------------------------------------
  445. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  446. {
  447. switch (result)
  448. {
  449. case MFMailComposeResultCancelled:
  450. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  451. break;
  452. case MFMailComposeResultSaved:
  453. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  454. break;
  455. case MFMailComposeResultSent:
  456. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  457. break;
  458. case MFMailComposeResultFailed: {
  459. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  460. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  461. }
  462. break;
  463. default:
  464. break;
  465. }
  466. // Close the Mail Interface
  467. [self dismissViewControllerAnimated:YES completion:NULL];
  468. }
  469. - (void)sendMail:(XLFormRowDescriptor *)sender
  470. {
  471. // Email Subject
  472. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  473. // Email Content
  474. NSString *messageBody;
  475. // Email Recipents
  476. NSArray *toRecipents;
  477. messageBody = [NSString stringWithFormat:@"\n\n\nNextcloud Version %@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  478. toRecipents = [NSArray arrayWithObject:_mail_me_];
  479. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  480. mc.mailComposeDelegate = self;
  481. [mc setSubject:emailTitle];
  482. [mc setMessageBody:messageBody isHTML:NO];
  483. [mc setToRecipients:toRecipents];
  484. // Present mail view controller on screen
  485. [self presentViewController:mc animated:YES completion:NULL];
  486. }
  487. - (void)sendMailEncryptPass
  488. {
  489. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self];
  490. }
  491. #pragma --------------------------------------------------------------------------------------------
  492. #pragma mark === AlertView ===
  493. #pragma --------------------------------------------------------------------------------------------
  494. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  495. {
  496. // Remove ALL
  497. if (buttonIndex == 1 && alertView.tag == alertViewEsci)
  498. {
  499. [self.hud visibleIndeterminateHud];
  500. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  501. [app cancelAllOperations];
  502. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  503. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  504. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  505. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  506. [CCCoreData flushAllDatabase];
  507. [CCUtility deleteAllChainStore];
  508. [self emptyDocumentsDirectory];
  509. [self emptyLibraryDirectory];
  510. [self emptyGroupApplicationSupport];
  511. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  512. for (NSString *file in tmpDirectory)
  513. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  514. [self.hud hideHud];
  515. exit(0);
  516. });
  517. }
  518. // Clear Cache
  519. if (buttonIndex == 1 && alertView.tag == alertViewAzzeraCache)
  520. {
  521. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  522. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  523. [app cancelAllOperations];
  524. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  525. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  526. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  527. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  528. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  529. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  530. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  531. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  532. [self emptyLocalDirectory];
  533. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  534. for (NSString *file in tmpDirectory)
  535. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  536. [self recalculateSize];
  537. // Inizialized home
  538. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  539. [self.hud hideHud];
  540. });
  541. }
  542. }
  543. #pragma --------------------------------------------------------------------------------------------
  544. #pragma mark === BKPasscodeViewController ===
  545. #pragma --------------------------------------------------------------------------------------------
  546. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  547. {
  548. [aViewController dismissViewControllerAnimated:YES completion:nil];
  549. switch (aViewController.type) {
  550. case BKPasscodeViewControllerNewPasscodeType: {
  551. // enable passcode
  552. [CCUtility setBlockCode:aPasscode];
  553. }
  554. break;
  555. case BKPasscodeViewControllerCheckPasscodeType: {
  556. // disable passcode
  557. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  558. [CCUtility setBlockCode:@""];
  559. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  560. [app.activeMain.tableView reloadData];
  561. }
  562. // email Key EAS-256
  563. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  564. [self sendMailEncryptPass];
  565. // change simply
  566. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  567. // disable passcode
  568. [CCUtility setBlockCode:@""];
  569. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  570. [app.activeMain.tableView reloadData];
  571. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  572. // Call new passcode
  573. [self bloccoPassword];
  574. }
  575. }
  576. break;
  577. default:
  578. break;
  579. }
  580. [self reloadForm];
  581. }
  582. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  583. {
  584. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  585. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  586. if ([aPasscode isEqualToString:key]) {
  587. self.lockUntilDate = nil;
  588. self.failedAttempts = 0;
  589. aResultHandler(YES);
  590. } else aResultHandler(NO);
  591. }
  592. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  593. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  594. self.lockUntilDate = nil;
  595. self.failedAttempts = 0;
  596. aResultHandler(YES);
  597. } else aResultHandler(NO);
  598. }
  599. }
  600. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  601. {
  602. self.failedAttempts++;
  603. if (self.failedAttempts > 5) {
  604. NSTimeInterval timeInterval = 60;
  605. if (self.failedAttempts > 6) {
  606. NSUInteger multiplier = self.failedAttempts - 6;
  607. timeInterval = (5 * 60) * multiplier;
  608. if (timeInterval > 3600 * 24) {
  609. timeInterval = 3600 * 24;
  610. }
  611. }
  612. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  613. }
  614. }
  615. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  616. {
  617. return self.failedAttempts;
  618. }
  619. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  620. {
  621. return self.lockUntilDate;
  622. }
  623. - (void)passcodeViewCloseButtonPressed:(id)sender
  624. {
  625. [self dismissViewControllerAnimated:YES completion:nil];
  626. }
  627. #pragma --------------------------------------------------------------------------------------------
  628. #pragma mark == Utility ==
  629. #pragma --------------------------------------------------------------------------------------------
  630. - (void)emptyGroupApplicationSupport
  631. {
  632. NSString *file;
  633. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  634. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  635. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  636. while (file = [enumerator nextObject])
  637. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  638. }
  639. - (void)emptyLibraryDirectory
  640. {
  641. NSString *file;
  642. NSString *dirIniziale;
  643. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  644. dirIniziale = [paths objectAtIndex:0];
  645. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  646. while (file = [enumerator nextObject])
  647. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  648. }
  649. - (void)emptyDocumentsDirectory
  650. {
  651. NSString *file;
  652. NSString *dirIniziale;
  653. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  654. dirIniziale = [paths objectAtIndex:0];
  655. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  656. while (file = [enumerator nextObject])
  657. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  658. }
  659. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  660. {
  661. NSString *file;
  662. NSString *dirIniziale;
  663. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  664. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  665. while (file = [enumerator nextObject]) {
  666. NSString *ext = [[file pathExtension] lowercaseString];
  667. // Do not remove ICO
  668. if ([ext isEqualToString:@"ico"])
  669. continue;
  670. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  671. }
  672. }
  673. - (void)emptyLocalDirectory
  674. {
  675. NSString *file;
  676. NSString *dirIniziale;
  677. dirIniziale = [CCUtility getDirectoryLocal];
  678. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  679. while (file = [enumerator nextObject])
  680. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  681. }
  682. - (NSNumber *)getUserDirectorySize
  683. {
  684. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  685. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  686. unsigned long long count = 0;
  687. NSNumber *value = nil;
  688. if (! directoryURL) return 0;
  689. // Get dimension Document
  690. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  691. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  692. count += [value longLongValue];
  693. } else {
  694. return nil;
  695. }
  696. }
  697. return @(count);
  698. }
  699. @end