CCSettings.m 46 KB

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