CCSettings.m 46 KB

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