CCSettings.m 44 KB

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