CCSettings.m 49 KB

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