CCSettings.m 48 KB

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