CCSettings.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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 "TableAccount+CoreDataClass.h"
  27. #define alertViewEsci 1
  28. #define alertViewAzzeraCache 2
  29. @implementation CCSettings
  30. - (id)initWithCoder:(NSCoder *)aDecoder
  31. {
  32. self = [super initWithCoder:aDecoder];
  33. if (self) {
  34. [self initializeForm];
  35. app.activeSettings = self;
  36. }
  37. return self;
  38. }
  39. - (void)initializeForm
  40. {
  41. XLFormDescriptor *form;
  42. XLFormSectionDescriptor *section;
  43. XLFormRowDescriptor *row;
  44. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. // Section : PASSWORD --------------------------------------------------------------
  47. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_passcode_", nil)];
  48. [form addFormSection:section];
  49. // Passcode
  50. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  51. [row.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  52. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  53. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  54. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  55. row.action.formSelector = @selector(bloccoPassword);
  56. [section addFormRow:row];
  57. // Passcode simply
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [section addFormRow:row];
  61. // Passcode only directory
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_folder_", nil)];
  63. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  64. [section addFormRow:row];
  65. // Section : CLOUD ACCOUNT --------------------------------------------------------------
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_cloud_account_", nil)];
  67. [form addFormSection:section];
  68. // version
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versionserver" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_version_server_", nil)];
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  72. [section addFormRow:row];
  73. // Url
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"urlcloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_url_", nil)];
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  77. [section addFormRow:row];
  78. // username
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usernamecloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_username_", nil)];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  82. [section addFormRow:row];
  83. // information
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userinformation" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_information_", nil)];
  85. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  87. row.cellConfig[@"textLabel.numberOfLines"] = @0;
  88. [section addFormRow:row];
  89. // email
  90. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useremail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_email_", nil)];
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  93. [section addFormRow:row];
  94. // quota
  95. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quota" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_quota_", nil)];
  96. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  97. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  98. [section addFormRow:row];
  99. // Change Account
  100. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"changecredentials" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_change_credentials_", nil)];
  101. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  102. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCredentials] forKey:@"imageView.image"];
  103. row.action.formSegueIdentifier = @"CCManageAccountSegue";
  104. [section addFormRow:row];
  105. // Section --------------------------------------------------------------
  106. section = [XLFormSectionDescriptor formSection];
  107. [form addFormSection:section];
  108. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cameraupload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_uploading_from_camera_", nil)];
  109. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  110. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCameraUpload] forKey:@"imageView.image"];
  111. row.action.formSegueIdentifier = @"CCManageCameraUploadSegue";
  112. [section addFormRow:row];
  113. // Section --------------------------------------------------------------
  114. section = [XLFormSectionDescriptor formSection];
  115. [form addFormSection:section];
  116. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizations" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_optimizations_", nil)];
  117. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  118. [row.cellConfig setObject:[UIImage imageNamed:image_settingsOptimizations] forKey:@"imageView.image"];
  119. row.action.formSegueIdentifier = @"CCManageOptimizationsSegue";
  120. [section addFormRow:row];
  121. // Section --------------------------------------------------------------
  122. section = [XLFormSectionDescriptor formSection];
  123. [form addFormSection:section];
  124. // Crypto Cloud
  125. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cryptocloud" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_crypto_cloud_system_", nil)];
  126. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  127. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCryptoCloud] forKey:@"imageView.image"];
  128. row.action.formSegueIdentifier = @"CCManageCryptoCloudSegue";
  129. [section addFormRow:row];
  130. // Section : INFORMATION --------------------------------------------------------------
  131. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  132. [form addFormSection:section];
  133. section.footerTitle = @"Nextcloud © 2017 T.W.S. Inc.";
  134. // Acknowledgements
  135. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  136. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  137. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  138. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAcknowledgements] forKey:@"imageView.image"];
  139. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  140. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  141. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  142. [self deselectFormRow:sender];
  143. };
  144. [section addFormRow:row];
  145. // Help
  146. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"help" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_", nil)];
  147. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  148. [row.cellConfig setObject:[UIImage imageNamed:image_settingsHelp] forKey:@"imageView.image"];
  149. row.action.formSegueIdentifier = @"CCManageHelpSegue";
  150. [section addFormRow:row];
  151. // Contact us mail
  152. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  153. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  154. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  155. [row.cellConfig setObject:[UIImage imageNamed:image_settingsMail] forKey:@"imageView.image"];
  156. row.action.formSelector = @selector(sendMail:);
  157. [section addFormRow:row];
  158. // Version
  159. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versioneapplicazione" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_app_version_", nil)];
  160. row.value = [NSString stringWithFormat:@"%@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  161. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  162. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  163. [section addFormRow:row];
  164. // Section --------------------------------------------------------------
  165. section = [XLFormSectionDescriptor formSection];
  166. [form addFormSection:section];
  167. // Clear cache
  168. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_no_size_", nil)];
  169. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  170. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearCache] forKey:@"imageView.image"];
  171. row.action.formSelector = @selector(azzeraCache:);
  172. [section addFormRow:row];
  173. // Section --------------------------------------------------------------
  174. section = [XLFormSectionDescriptor formSection];
  175. [form addFormSection:section];
  176. // Exit
  177. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:[CCUtility localizableBrand:@"_exit_" table:nil]];
  178. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  179. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  180. [row.cellConfig setObject:[UIImage imageNamed:image_settingsExit] forKey:@"imageView.image"];
  181. row.action.formSelector = @selector(esci:);
  182. [section addFormRow:row];
  183. #ifdef DEBUG
  184. /*
  185. // Section : debug
  186. section = [XLFormSectionDescriptor formSectionWithTitle:@"Debug"];
  187. [form addFormSection:section];
  188. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"adminRemoveVersion" rowType:XLFormRowDescriptorTypeButton title:@"Remove Version"];
  189. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  190. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  191. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  192. row.action.formSelector = @selector(adminRemoveVersion:);
  193. [section addFormRow:row];
  194. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quickActionPhotos" rowType:XLFormRowDescriptorTypeButton title:@"Quick Action Photos"];
  195. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  196. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  197. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  198. row.action.formSelector = @selector(quickActionPhotos:);
  199. [section addFormRow:row];
  200. */
  201. #endif
  202. self.form = form;
  203. }
  204. - (void)viewDidLoad
  205. {
  206. [super viewDidLoad];
  207. self.hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  208. self.title = NSLocalizedString(@"_settings_", nil);
  209. // Color
  210. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  211. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  212. }
  213. // Apparirà
  214. - (void)viewWillAppear:(BOOL)animated
  215. {
  216. [super viewWillAppear:animated];
  217. // Color
  218. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  219. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  220. [self reloadForm];
  221. }
  222. // E' apparsa
  223. - (void)viewDidAppear:(BOOL)animated
  224. {
  225. [super viewDidAppear:animated];
  226. }
  227. #pragma --------------------------------------------------------------------------------------------
  228. #pragma mark === Admin ===
  229. #pragma --------------------------------------------------------------------------------------------
  230. /*
  231. - (void)adminRemoveVersion:(XLFormRowDescriptor *)sender
  232. {
  233. [self deselectFormRow:sender];
  234. [CCUtility adminRemoveVersion];
  235. exit(0);
  236. }
  237. - (void)quickActionPhotos:(XLFormRowDescriptor *)sender
  238. {
  239. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  240. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:@"" localizedSubtitle:nil icon:nil userInfo:nil];
  241. [app handleShortCutItem:shortcutPhotos];
  242. }
  243. */
  244. #pragma --------------------------------------------------------------------------------------------
  245. #pragma mark === Chiamate dal Form ===
  246. #pragma --------------------------------------------------------------------------------------------
  247. - (void)reloadForm
  248. {
  249. self.form.delegate = nil;
  250. // ----------------------
  251. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  252. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  253. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  254. XLFormRowDescriptor *rowVersionServer = [self.form formRowWithTag:@"versionserver"];
  255. XLFormRowDescriptor *rowUrlCloud = [self.form formRowWithTag:@"urlcloud"];
  256. XLFormRowDescriptor *rowUserNameCloud = [self.form formRowWithTag:@"usernamecloud"];
  257. XLFormRowDescriptor *rowUserInformation = [self.form formRowWithTag:@"userinformation"];
  258. XLFormRowDescriptor *rowUserEmail = [self.form formRowWithTag:@"useremail"];
  259. XLFormRowDescriptor *rowQuota = [self.form formRowWithTag:@"quota"];
  260. //XLFormRowDescriptor *rowChangeCredentials = [self.form formRowWithTag:@"changecredentials"];
  261. // ------------------------------------------------------------------
  262. if ([[CCUtility getBlockCode] length]) {
  263. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  264. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeYES] forKey:@"imageView.image"];
  265. } else {
  266. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  267. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  268. }
  269. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  270. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  271. // Avatar
  272. UIImage *avatar = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser]];
  273. if (avatar) {
  274. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(50, 50)];
  275. APAvatarImageView *avatarImageView = [[APAvatarImageView alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  276. CGSize imageSize = avatarImageView.bounds.size;
  277. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  278. CGContextRef context = UIGraphicsGetCurrentContext();
  279. [avatarImageView.layer renderInContext:context];
  280. avatar = UIGraphicsGetImageFromCurrentImageContext();
  281. UIGraphicsEndImageContext();
  282. }
  283. TableAccount *tableAccount = [CCCoreData getActiveAccount];
  284. rowVersionServer.value = [CCNetworking sharedNetworking].sharedOCCommunication.getCurrentServerVersion;
  285. rowUrlCloud.value = app.activeUrl;
  286. rowUserNameCloud.value = app.activeUser;
  287. if (avatar || tableAccount.displayName.length > 0 || tableAccount.address.length > 0 || tableAccount.phone.length > 0) {
  288. rowUserInformation.title = [NSString stringWithFormat:@"%@ %@ %@", tableAccount.displayName, tableAccount.address, tableAccount.phone];
  289. rowUserInformation.disabled = @YES;
  290. if (avatar)
  291. [rowUserInformation.cellConfig setObject:avatar forKey:@"imageView.image"];
  292. else
  293. [rowUserInformation.cellConfig setObject:[UIImage imageNamed:image_avatar] forKey:@"imageView.image"];
  294. } else {
  295. rowUserInformation.title = NSLocalizedString(@"_information_", nil);
  296. rowUserInformation.disabled = @NO;
  297. [rowUserInformation.cellConfig setObject:[UIImage imageNamed:image_avatar] forKey:@"imageView.image"];
  298. }
  299. rowUserEmail.value = tableAccount.email;
  300. NSString *quota = [CCUtility transformedSize:[tableAccount.quotaTotal doubleValue]];
  301. NSString *quotaAvailable = [CCUtility transformedSize:[tableAccount.quotaFree doubleValue]];
  302. rowQuota.value = [NSString stringWithFormat:@"%@ / %@ %@", quota, quotaAvailable, NSLocalizedString(@"_available_", nil)];
  303. // -----------------------------------------------------------------
  304. [self.tableView reloadData];
  305. self.form.delegate = self;
  306. }
  307. - (void)recalculateSize
  308. {
  309. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  310. self.form.delegate = nil;
  311. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  312. //NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  313. //rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  314. rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  315. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  316. self.form.delegate = self;
  317. });
  318. }
  319. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  320. {
  321. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  322. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  323. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  324. [CCUtility setOnlyLockDir:true];
  325. } else {
  326. [CCUtility setOnlyLockDir:false];
  327. }
  328. }
  329. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  330. if ([[CCUtility getBlockCode] length] == 0)
  331. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  332. else
  333. [self changeSimplyPassword];
  334. }
  335. }
  336. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  337. {
  338. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  339. viewController.delegate = self;
  340. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  341. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  342. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  343. viewController.passcodeInputView.maximumLength = 64;
  344. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  345. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  346. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  347. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  348. [self presentViewController:navigationController animated:YES completion:nil];
  349. }
  350. - (void)changeSimplyPassword
  351. {
  352. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  353. viewController.delegate = self;
  354. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  355. viewController.fromType = CCBKPasscodeFromSimply;
  356. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  357. viewController.inputViewTitlePassword = YES;
  358. if ([CCUtility getSimplyBlockCode]) {
  359. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  360. viewController.passcodeInputView.maximumLength = 6;
  361. } else {
  362. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  363. viewController.passcodeInputView.maximumLength = 64;
  364. }
  365. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  366. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  367. viewController.touchIDManager = touchIDManager;
  368. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  369. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  370. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  371. [self presentViewController:navigationController animated:YES completion:nil];
  372. }
  373. - (void)bloccoPassword
  374. {
  375. // ATTIVAZIONE LOCK PASSWORD
  376. if ([[CCUtility getBlockCode] length] == 0) {
  377. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  378. viewController.delegate = self;
  379. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  380. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  381. viewController.inputViewTitlePassword = YES;
  382. if ([CCUtility getSimplyBlockCode]) {
  383. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  384. viewController.passcodeInputView.maximumLength = 6;
  385. } else {
  386. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  387. viewController.passcodeInputView.maximumLength = 64;
  388. }
  389. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  390. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  391. viewController.touchIDManager = touchIDManager;
  392. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  393. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  394. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  395. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  396. [self presentViewController:navigationController animated:YES completion:nil];
  397. } else {
  398. // OFF LOCK PASSWORD
  399. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  400. viewController.delegate = self;
  401. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  402. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  403. viewController.inputViewTitlePassword = YES;
  404. if ([CCUtility getSimplyBlockCode]) {
  405. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  406. viewController.passcodeInputView.maximumLength = 6;
  407. } else {
  408. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  409. viewController.passcodeInputView.maximumLength = 64;
  410. }
  411. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  412. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  413. viewController.touchIDManager = touchIDManager;
  414. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  415. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  416. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  417. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  418. [self presentViewController:navigationController animated:YES completion:nil];
  419. }
  420. }
  421. - (void)esci:(XLFormRowDescriptor *)sender
  422. {
  423. [self deselectFormRow:sender];
  424. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:[CCUtility localizableBrand:@"_exit_" table:nil]
  425. message:[CCUtility localizableBrand:@"_want_exit_" table:nil]
  426. delegate:self
  427. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  428. otherButtonTitles: nil];
  429. alertView.tag = alertViewEsci;
  430. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  431. [alertView show];
  432. }
  433. - (void)azzeraCache:(XLFormRowDescriptor *)sender
  434. {
  435. [self deselectFormRow:sender];
  436. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"_delete_cache_",nil)
  437. message:NSLocalizedString(@"_want_delete_cache_", nil)
  438. delegate:self
  439. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  440. otherButtonTitles: nil];
  441. alertView.tag = alertViewAzzeraCache;
  442. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  443. [alertView show];
  444. }
  445. #pragma --------------------------------------------------------------------------------------------
  446. #pragma mark === Mail ===
  447. #pragma --------------------------------------------------------------------------------------------
  448. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  449. {
  450. switch (result)
  451. {
  452. case MFMailComposeResultCancelled:
  453. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  454. break;
  455. case MFMailComposeResultSaved:
  456. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  457. break;
  458. case MFMailComposeResultSent:
  459. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  460. break;
  461. case MFMailComposeResultFailed: {
  462. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  463. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  464. }
  465. break;
  466. default:
  467. break;
  468. }
  469. // Close the Mail Interface
  470. [self dismissViewControllerAnimated:YES completion:NULL];
  471. }
  472. - (void)sendMail:(XLFormRowDescriptor *)sender
  473. {
  474. // Email Subject
  475. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  476. // Email Content
  477. NSString *messageBody;
  478. // Email Recipents
  479. NSArray *toRecipents;
  480. messageBody = [NSString stringWithFormat:@"\n\n\nNextcloud Version %@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  481. toRecipents = [NSArray arrayWithObject:_mail_me_];
  482. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  483. mc.mailComposeDelegate = self;
  484. [mc setSubject:emailTitle];
  485. [mc setMessageBody:messageBody isHTML:NO];
  486. [mc setToRecipients:toRecipents];
  487. // Present mail view controller on screen
  488. [self presentViewController:mc animated:YES completion:NULL];
  489. }
  490. - (void)sendMailEncryptPass
  491. {
  492. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self];
  493. }
  494. #pragma --------------------------------------------------------------------------------------------
  495. #pragma mark === AlertView ===
  496. #pragma --------------------------------------------------------------------------------------------
  497. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  498. {
  499. // Remove ALL
  500. if (buttonIndex == 1 && alertView.tag == alertViewEsci)
  501. {
  502. [self.hud visibleIndeterminateHud];
  503. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  504. [app cancelAllOperations];
  505. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  506. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  507. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  508. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  509. [CCCoreData flushAllDatabase];
  510. [CCUtility deleteAllChainStore];
  511. [self emptyDocumentsDirectory];
  512. [self emptyLibraryDirectory];
  513. [self emptyGroupApplicationSupport];
  514. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  515. for (NSString *file in tmpDirectory)
  516. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  517. [self.hud hideHud];
  518. exit(0);
  519. });
  520. }
  521. // Clear Cache
  522. if (buttonIndex == 1 && alertView.tag == alertViewAzzeraCache)
  523. {
  524. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  525. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  526. [app cancelAllOperations];
  527. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  528. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  529. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  530. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  531. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  532. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  533. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  534. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  535. [self emptyLocalDirectory];
  536. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  537. for (NSString *file in tmpDirectory)
  538. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  539. [self recalculateSize];
  540. // Inizialized home
  541. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  542. [self.hud hideHud];
  543. });
  544. }
  545. }
  546. #pragma --------------------------------------------------------------------------------------------
  547. #pragma mark === BKPasscodeViewController ===
  548. #pragma --------------------------------------------------------------------------------------------
  549. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  550. {
  551. [aViewController dismissViewControllerAnimated:YES completion:nil];
  552. switch (aViewController.type) {
  553. case BKPasscodeViewControllerNewPasscodeType: {
  554. // enable passcode
  555. [CCUtility setBlockCode:aPasscode];
  556. }
  557. break;
  558. case BKPasscodeViewControllerCheckPasscodeType: {
  559. // disable passcode
  560. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  561. [CCUtility setBlockCode:@""];
  562. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  563. [app.activeMain.tableView reloadData];
  564. }
  565. // email Key EAS-256
  566. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  567. [self sendMailEncryptPass];
  568. // change simply
  569. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  570. // disable passcode
  571. [CCUtility setBlockCode:@""];
  572. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  573. [app.activeMain.tableView reloadData];
  574. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  575. // Call new passcode
  576. [self bloccoPassword];
  577. }
  578. }
  579. break;
  580. default:
  581. break;
  582. }
  583. [self reloadForm];
  584. }
  585. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  586. {
  587. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  588. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  589. if ([aPasscode isEqualToString:key]) {
  590. self.lockUntilDate = nil;
  591. self.failedAttempts = 0;
  592. aResultHandler(YES);
  593. } else aResultHandler(NO);
  594. }
  595. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  596. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  597. self.lockUntilDate = nil;
  598. self.failedAttempts = 0;
  599. aResultHandler(YES);
  600. } else aResultHandler(NO);
  601. }
  602. }
  603. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  604. {
  605. self.failedAttempts++;
  606. if (self.failedAttempts > 5) {
  607. NSTimeInterval timeInterval = 60;
  608. if (self.failedAttempts > 6) {
  609. NSUInteger multiplier = self.failedAttempts - 6;
  610. timeInterval = (5 * 60) * multiplier;
  611. if (timeInterval > 3600 * 24) {
  612. timeInterval = 3600 * 24;
  613. }
  614. }
  615. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  616. }
  617. }
  618. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  619. {
  620. return self.failedAttempts;
  621. }
  622. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  623. {
  624. return self.lockUntilDate;
  625. }
  626. - (void)passcodeViewCloseButtonPressed:(id)sender
  627. {
  628. [self dismissViewControllerAnimated:YES completion:nil];
  629. }
  630. #pragma --------------------------------------------------------------------------------------------
  631. #pragma mark == Utility ==
  632. #pragma --------------------------------------------------------------------------------------------
  633. - (void)emptyGroupApplicationSupport
  634. {
  635. NSString *file;
  636. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  637. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  638. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  639. while (file = [enumerator nextObject])
  640. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  641. }
  642. - (void)emptyLibraryDirectory
  643. {
  644. NSString *file;
  645. NSString *dirIniziale;
  646. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  647. dirIniziale = [paths objectAtIndex:0];
  648. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  649. while (file = [enumerator nextObject])
  650. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  651. }
  652. - (void)emptyDocumentsDirectory
  653. {
  654. NSString *file;
  655. NSString *dirIniziale;
  656. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  657. dirIniziale = [paths objectAtIndex:0];
  658. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  659. while (file = [enumerator nextObject])
  660. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  661. }
  662. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  663. {
  664. NSString *file;
  665. NSString *dirIniziale;
  666. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  667. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  668. while (file = [enumerator nextObject]) {
  669. NSString *ext = [[file pathExtension] lowercaseString];
  670. // Do not remove ICO
  671. if ([ext isEqualToString:@"ico"])
  672. continue;
  673. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  674. }
  675. }
  676. - (void)emptyLocalDirectory
  677. {
  678. NSString *file;
  679. NSString *dirIniziale;
  680. dirIniziale = [CCUtility getDirectoryLocal];
  681. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  682. while (file = [enumerator nextObject])
  683. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  684. }
  685. - (NSNumber *)getUserDirectorySize
  686. {
  687. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  688. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  689. unsigned long long count = 0;
  690. NSNumber *value = nil;
  691. if (! directoryURL) return 0;
  692. // Get dimension Document
  693. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  694. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  695. count += [value longLongValue];
  696. } else {
  697. return nil;
  698. }
  699. }
  700. return @(count);
  701. }
  702. @end