CCSettings.m 48 KB

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