CCSettings.m 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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_folders_offline_footer_", nil);
  152. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"favoritefoldersoffline" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_favorite_folders_offline_", nil)];
  153. [row.cellConfig setObject:[UIImage imageNamed:image_settingsFavoriteFoldersOffline] 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 *rowFavoriteFoldersOffline = [self.form formRowWithTag:@"favoritefoldersoffline"];
  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 getFavoriteFoldersOffline]) [rowFavoriteFoldersOffline setValue:@1]; else [rowFavoriteFoldersOffline 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. rowUserPhone.value = _tableAccount.phone;
  371. rowUserEmail.value = _tableAccount.email;
  372. rowUserWeb.value = _tableAccount.webpage;
  373. rowUserTwitter.value = _tableAccount.twitter;
  374. // -----------------------------------------------------------------
  375. [self.tableView reloadData];
  376. self.form.delegate = self;
  377. }
  378. - (void)recalculateSize
  379. {
  380. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  381. self.form.delegate = nil;
  382. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  383. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  384. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  385. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  386. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  387. self.form.delegate = self;
  388. });
  389. }
  390. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  391. {
  392. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  393. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  394. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  395. [CCUtility setOnlyLockDir:true];
  396. } else {
  397. [CCUtility setOnlyLockDir:false];
  398. }
  399. }
  400. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  401. if ([[CCUtility getBlockCode] length] == 0)
  402. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  403. else
  404. [self changeSimplyPassword];
  405. }
  406. if ([rowDescriptor.tag isEqualToString:@"favoritefoldersoffline"]) {
  407. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  408. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_confirm_", nil) message:NSLocalizedString(@"_continue_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  409. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  410. [CCUtility setFavoriteFoldersOffline:true];
  411. [self synchronizeFavorites];
  412. }]];
  413. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  414. [self reloadForm];
  415. }]];
  416. [self presentViewController:alertController animated:YES completion:nil];
  417. } else {
  418. [CCUtility setFavoriteFoldersOffline:false];
  419. }
  420. }
  421. }
  422. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  423. {
  424. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  425. viewController.delegate = self;
  426. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  427. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  428. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  429. viewController.passcodeInputView.maximumLength = 64;
  430. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  431. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  432. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  433. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  434. [self presentViewController:navigationController animated:YES completion:nil];
  435. }
  436. - (void)changeSimplyPassword
  437. {
  438. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  439. viewController.delegate = self;
  440. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  441. viewController.fromType = CCBKPasscodeFromSimply;
  442. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  443. viewController.inputViewTitlePassword = YES;
  444. if ([CCUtility getSimplyBlockCode]) {
  445. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  446. viewController.passcodeInputView.maximumLength = 6;
  447. } else {
  448. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  449. viewController.passcodeInputView.maximumLength = 64;
  450. }
  451. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  452. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  453. viewController.touchIDManager = touchIDManager;
  454. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  455. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  456. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  457. [self presentViewController:navigationController animated:YES completion:nil];
  458. }
  459. - (void)bloccoPassword
  460. {
  461. // ATTIVAZIONE LOCK PASSWORD
  462. if ([[CCUtility getBlockCode] length] == 0) {
  463. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  464. viewController.delegate = self;
  465. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  466. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  467. viewController.inputViewTitlePassword = YES;
  468. if ([CCUtility getSimplyBlockCode]) {
  469. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  470. viewController.passcodeInputView.maximumLength = 6;
  471. } else {
  472. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  473. viewController.passcodeInputView.maximumLength = 64;
  474. }
  475. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  476. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  477. viewController.touchIDManager = touchIDManager;
  478. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  479. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  480. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  481. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  482. [self presentViewController:navigationController animated:YES completion:nil];
  483. } else {
  484. // OFF LOCK PASSWORD
  485. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  486. viewController.delegate = self;
  487. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  488. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  489. viewController.inputViewTitlePassword = YES;
  490. if ([CCUtility getSimplyBlockCode]) {
  491. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  492. viewController.passcodeInputView.maximumLength = 6;
  493. } else {
  494. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  495. viewController.passcodeInputView.maximumLength = 64;
  496. }
  497. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  498. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  499. viewController.touchIDManager = touchIDManager;
  500. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  501. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  502. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  503. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  504. [self presentViewController:navigationController animated:YES completion:nil];
  505. }
  506. }
  507. - (void)esci:(XLFormRowDescriptor *)sender
  508. {
  509. [self deselectFormRow:sender];
  510. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:[CCUtility localizableBrand:@"_exit_" table:nil]
  511. message:[CCUtility localizableBrand:@"_want_exit_" table:nil]
  512. delegate:self
  513. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  514. otherButtonTitles: nil];
  515. alertView.tag = alertViewEsci;
  516. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  517. [alertView show];
  518. }
  519. - (void)azzeraCache:(XLFormRowDescriptor *)sender
  520. {
  521. [self deselectFormRow:sender];
  522. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"_delete_cache_",nil)
  523. message:NSLocalizedString(@"_want_delete_cache_", nil)
  524. delegate:self
  525. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  526. otherButtonTitles: nil];
  527. alertView.tag = alertViewAzzeraCache;
  528. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  529. [alertView show];
  530. }
  531. - (void)quota:(XLFormRowDescriptor *)sender
  532. {
  533. [self deselectFormRow:sender];
  534. }
  535. - (void)synchronizeFavorites
  536. {
  537. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (favorite == 1)", app.activeAccount] context:nil];
  538. for (TableMetadata *record in recordsTableMetadata) {
  539. if (!record.directoryID)
  540. continue;
  541. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:record.directoryID activeAccount:app.activeAccount];
  542. serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:record.fileNamePrint];
  543. NSArray *TableDirectories = [CCCoreData getDirectoryIDsFromBeginsWithServerUrl:serverUrl activeAccount:app.activeAccount];
  544. for (TableDirectory *tableDirecory in TableDirectories) {
  545. NSLog(@"%@", tableDirecory.serverUrl);
  546. [CCCoreData clearDateReadAccount:app.activeAccount serverUrl:nil directoryID:tableDirecory.directoryID];
  547. }
  548. }
  549. [[CCSynchronize sharedSynchronize] readListingFavorites];
  550. }
  551. #pragma --------------------------------------------------------------------------------------------
  552. #pragma mark === Mail ===
  553. #pragma --------------------------------------------------------------------------------------------
  554. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  555. {
  556. switch (result)
  557. {
  558. case MFMailComposeResultCancelled:
  559. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  560. break;
  561. case MFMailComposeResultSaved:
  562. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  563. break;
  564. case MFMailComposeResultSent:
  565. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  566. break;
  567. case MFMailComposeResultFailed: {
  568. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  569. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  570. }
  571. break;
  572. default:
  573. break;
  574. }
  575. // Close the Mail Interface
  576. [self dismissViewControllerAnimated:YES completion:NULL];
  577. }
  578. - (void)sendMail:(XLFormRowDescriptor *)sender
  579. {
  580. // Email Subject
  581. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  582. // Email Content
  583. NSString *messageBody;
  584. // Email Recipents
  585. NSArray *toRecipents;
  586. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", k_brand,[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  587. toRecipents = [NSArray arrayWithObject:k_mailMe];
  588. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  589. mc.mailComposeDelegate = self;
  590. [mc setSubject:emailTitle];
  591. [mc setMessageBody:messageBody isHTML:NO];
  592. [mc setToRecipients:toRecipents];
  593. // Present mail view controller on screen
  594. [self presentViewController:mc animated:YES completion:NULL];
  595. }
  596. - (void)sendMailEncryptPass
  597. {
  598. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self];
  599. }
  600. #pragma --------------------------------------------------------------------------------------------
  601. #pragma mark === AlertView ===
  602. #pragma --------------------------------------------------------------------------------------------
  603. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  604. {
  605. // Remove ALL
  606. if (buttonIndex == 1 && alertView.tag == alertViewEsci)
  607. {
  608. [self.hud visibleIndeterminateHud];
  609. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  610. [app cancelAllOperations];
  611. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  612. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  613. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  614. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  615. [CCCoreData flushAllDatabase];
  616. [CCUtility deleteAllChainStore];
  617. [self emptyDocumentsDirectory];
  618. [self emptyLibraryDirectory];
  619. [self emptyGroupApplicationSupport];
  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.hud hideHud];
  624. exit(0);
  625. });
  626. }
  627. // Clear Cache
  628. if (buttonIndex == 1 && alertView.tag == alertViewAzzeraCache)
  629. {
  630. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  631. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  632. [app cancelAllOperations];
  633. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  634. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  635. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  636. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  637. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  638. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  639. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  640. [CCCoreData flushTableActivityAccount:app.activeAccount];
  641. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  642. [self emptyLocalDirectory];
  643. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  644. for (NSString *file in tmpDirectory)
  645. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  646. [self recalculateSize];
  647. // Inizialized home
  648. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  649. [self.hud hideHud];
  650. });
  651. }
  652. }
  653. #pragma --------------------------------------------------------------------------------------------
  654. #pragma mark === BKPasscodeViewController ===
  655. #pragma --------------------------------------------------------------------------------------------
  656. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  657. {
  658. [aViewController dismissViewControllerAnimated:YES completion:nil];
  659. switch (aViewController.type) {
  660. case BKPasscodeViewControllerNewPasscodeType: {
  661. // enable passcode
  662. [CCUtility setBlockCode:aPasscode];
  663. }
  664. break;
  665. case BKPasscodeViewControllerCheckPasscodeType: {
  666. // disable passcode
  667. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  668. [CCUtility setBlockCode:@""];
  669. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  670. [app.activeMain.tableView reloadData];
  671. }
  672. // email Key EAS-256
  673. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  674. [self sendMailEncryptPass];
  675. // change simply
  676. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  677. // disable passcode
  678. [CCUtility setBlockCode:@""];
  679. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  680. [app.activeMain.tableView reloadData];
  681. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  682. // Call new passcode
  683. [self bloccoPassword];
  684. }
  685. }
  686. break;
  687. default:
  688. break;
  689. }
  690. [self reloadForm];
  691. }
  692. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  693. {
  694. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  695. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  696. if ([aPasscode isEqualToString:key]) {
  697. self.lockUntilDate = nil;
  698. self.failedAttempts = 0;
  699. aResultHandler(YES);
  700. } else aResultHandler(NO);
  701. }
  702. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  703. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  704. self.lockUntilDate = nil;
  705. self.failedAttempts = 0;
  706. aResultHandler(YES);
  707. } else aResultHandler(NO);
  708. }
  709. }
  710. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  711. {
  712. self.failedAttempts++;
  713. if (self.failedAttempts > 5) {
  714. NSTimeInterval timeInterval = 60;
  715. if (self.failedAttempts > 6) {
  716. NSUInteger multiplier = self.failedAttempts - 6;
  717. timeInterval = (5 * 60) * multiplier;
  718. if (timeInterval > 3600 * 24) {
  719. timeInterval = 3600 * 24;
  720. }
  721. }
  722. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  723. }
  724. }
  725. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  726. {
  727. return self.failedAttempts;
  728. }
  729. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  730. {
  731. return self.lockUntilDate;
  732. }
  733. - (void)passcodeViewCloseButtonPressed:(id)sender
  734. {
  735. [self dismissViewControllerAnimated:YES completion:nil];
  736. }
  737. #pragma --------------------------------------------------------------------------------------------
  738. #pragma mark == Utility ==
  739. #pragma --------------------------------------------------------------------------------------------
  740. - (void)emptyGroupApplicationSupport
  741. {
  742. NSString *file;
  743. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  744. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  745. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  746. while (file = [enumerator nextObject])
  747. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  748. }
  749. - (void)emptyLibraryDirectory
  750. {
  751. NSString *file;
  752. NSString *dirIniziale;
  753. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  754. dirIniziale = [paths objectAtIndex:0];
  755. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  756. while (file = [enumerator nextObject])
  757. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  758. }
  759. - (void)emptyDocumentsDirectory
  760. {
  761. NSString *file;
  762. NSString *dirIniziale;
  763. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  764. dirIniziale = [paths objectAtIndex:0];
  765. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  766. while (file = [enumerator nextObject])
  767. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  768. }
  769. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  770. {
  771. NSString *file;
  772. NSString *dirIniziale;
  773. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  774. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  775. while (file = [enumerator nextObject]) {
  776. NSString *ext = [[file pathExtension] lowercaseString];
  777. // Do not remove ICO
  778. if ([ext isEqualToString:@"ico"])
  779. continue;
  780. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  781. }
  782. }
  783. - (void)emptyLocalDirectory
  784. {
  785. NSString *file;
  786. NSString *dirIniziale;
  787. dirIniziale = [CCUtility getDirectoryLocal];
  788. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  789. while (file = [enumerator nextObject])
  790. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  791. }
  792. - (NSNumber *)getUserDirectorySize
  793. {
  794. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  795. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  796. unsigned long long count = 0;
  797. NSNumber *value = nil;
  798. if (! directoryURL) return 0;
  799. // Get dimension Document
  800. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  801. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  802. count += [value longLongValue];
  803. } else {
  804. return nil;
  805. }
  806. }
  807. return @(count);
  808. }
  809. @end