CCSettings.m 45 KB

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