CCAdvanced.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // CCManageHelp.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "CCAdvanced.h"
  24. #import "CCUtility.h"
  25. #import "AppDelegate.h"
  26. #import <KTVHTTPCache/KTVHTTPCache.h>
  27. #import "NCBridgeSwift.h"
  28. @interface CCAdvanced ()
  29. {
  30. AppDelegate *appDelegate;
  31. }
  32. @end
  33. @implementation CCAdvanced
  34. - (id)init
  35. {
  36. XLFormDescriptor *form ;
  37. XLFormSectionDescriptor *section;
  38. XLFormRowDescriptor *row;
  39. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  41. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_advanced_", nil)];
  42. // Section HIDDEN FILES -------------------------------------------------
  43. section = [XLFormSectionDescriptor formSection];
  44. [form addFormSection:section];
  45. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
  46. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  47. if ([CCUtility getShowHiddenFiles]) row.value = @"1";
  48. else row.value = @"0";
  49. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  50. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  51. [section addFormRow:row];
  52. // Format Compatibility
  53. section = [XLFormSectionDescriptor formSection];
  54. [form addFormSection:section];
  55. section.footerTitle = NSLocalizedString(@"_format_compatibility_footer_", nil);
  56. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
  57. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  58. if ([CCUtility getFormatCompatibility]) row.value = @"1";
  59. else row.value = @"0";
  60. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  61. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  62. [section addFormRow:row];
  63. // Disable Local Cache After Upload
  64. section = [XLFormSectionDescriptor formSection];
  65. [form addFormSection:section];
  66. section.footerTitle = NSLocalizedString(@"_disableLocalCacheAfterUpload_footer_", nil);
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disableLocalCacheAfterUpload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disableLocalCacheAfterUpload_", nil)];
  68. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  69. if ([CCUtility getDisableLocalCacheAfterUpload]) row.value = @"1";
  70. else row.value = @"0";
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  72. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  73. [section addFormRow:row];
  74. // Section : Files App --------------------------------------------------------------
  75. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  76. section = [XLFormSectionDescriptor formSection];
  77. [form addFormSection:section];
  78. section.footerTitle = NSLocalizedString(@"_disable_files_app_footer_", nil);
  79. // Disable Files App
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disable_files_app_", nil)];
  81. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  82. if ([CCUtility getDisableFilesApp]) row.value = @"1";
  83. else row.value = @"0";
  84. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  85. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  86. [section addFormRow:row];
  87. }
  88. // Section : Privacy --------------------------------------------------------------
  89. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_privacy_", nil)];
  90. [form addFormSection:section];
  91. section.footerTitle = NSLocalizedString(@"_privacy_footer_", nil);
  92. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"crashservice" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_crashservice_title_", nil)];
  93. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  95. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  96. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"crashservice"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  97. if ([CCUtility getDisableCrashservice]) row.value = @"1";
  98. else row.value = @"0";
  99. [section addFormRow:row];
  100. // Section CLEAR CACHE -------------------------------------------------
  101. section = [XLFormSectionDescriptor formSection];
  102. [form addFormSection:section];
  103. section.footerTitle = NSLocalizedString(@"_clear_cache_footer_", nil);
  104. // Clear cache
  105. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_", nil)];
  106. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  107. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  108. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  109. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  110. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  111. row.action.formSelector = @selector(clearCacheRequest:);
  112. [section addFormRow:row];
  113. // Section EXIT --------------------------------------------------------
  114. section = [XLFormSectionDescriptor formSection];
  115. [form addFormSection:section];
  116. section.footerTitle = NSLocalizedString(@"_exit_footer_", nil);
  117. // Exit
  118. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  119. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  120. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  121. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  122. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  123. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"exit"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
  124. row.action.formSelector = @selector(exitNextcloud:);
  125. [section addFormRow:row];
  126. return [super initWithForm:form];
  127. }
  128. - (void)viewDidLoad
  129. {
  130. [super viewDidLoad];
  131. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  132. }
  133. // Apparirà
  134. - (void)viewWillAppear:(BOOL)animated
  135. {
  136. [super viewWillAppear:animated];
  137. self.tableView.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
  138. self.tableView.showsVerticalScrollIndicator = NO;
  139. self.tableView.separatorColor = NCBrandColor.sharedInstance.separator;
  140. // Color
  141. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  142. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  143. }
  144. - (void)changeTheming
  145. {
  146. if (self.isViewLoaded && self.view.window)
  147. [appDelegate changeTheming:self];
  148. }
  149. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  150. {
  151. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  152. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  153. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  154. // force reload
  155. [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
  156. }
  157. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  158. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  159. }
  160. if ([rowDescriptor.tag isEqualToString:@"disableLocalCacheAfterUpload"]) {
  161. [CCUtility setDisableLocalCacheAfterUpload:[[rowDescriptor.value valueData] boolValue]];
  162. }
  163. if ([rowDescriptor.tag isEqualToString:@"disablefilesapp"]) {
  164. [CCUtility setDisableFilesApp:[[rowDescriptor.value valueData] boolValue]];
  165. }
  166. if ([rowDescriptor.tag isEqualToString:@"crashservice"]) {
  167. [CCUtility setDisableCrashservice:[[rowDescriptor.value valueData] boolValue]];
  168. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_crashservice_title_", nil) message:NSLocalizedString(@"_crashservice_alert_", nil) preferredStyle:UIAlertControllerStyleAlert];
  169. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  170. exit(0);
  171. }];
  172. [alertController addAction:okAction];
  173. [self presentViewController:alertController animated:YES completion:nil];
  174. }
  175. }
  176. #pragma --------------------------------------------------------------------------------------------
  177. #pragma mark === Clear Cache ===
  178. #pragma --------------------------------------------------------------------------------------------
  179. - (void)clearCache
  180. {
  181. [appDelegate maintenanceMode:YES];
  182. [[NCMainCommon sharedInstance] cancelAllTransfer];
  183. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  184. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  185. [KTVHTTPCache cacheDeleteAllCaches];
  186. [[NCManageDatabase sharedInstance] clearDatabaseWithAccount:appDelegate.activeAccount removeAccount:false];
  187. [CCUtility emptyGroupDirectoryProviderStorage];
  188. [CCUtility emptyGroupLibraryDirectory];
  189. [CCUtility emptyDocumentsDirectory];
  190. [CCUtility emptyTemporaryDirectory];
  191. [CCUtility createDirectoryStandard];
  192. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  193. [appDelegate.filterocId removeAllObjects];
  194. [appDelegate maintenanceMode:NO];
  195. // Inizialized home
  196. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  197. }
  198. - (void)clearCacheRequest:(XLFormRowDescriptor *)sender
  199. {
  200. [self deselectFormRow:sender];
  201. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  202. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil)
  203. style:UIAlertActionStyleDefault
  204. handler:^(UIAlertAction *action) {
  205. [self clearCache];
  206. }]];
  207. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  208. }]];
  209. alertController.popoverPresentationController.sourceView = self.view;
  210. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  211. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  212. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  213. [self presentViewController:alertController animated:YES completion:nil];
  214. }
  215. #pragma --------------------------------------------------------------------------------------------
  216. #pragma mark == Exit Nextcloud ==
  217. #pragma --------------------------------------------------------------------------------------------
  218. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  219. {
  220. [self deselectFormRow:sender];
  221. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  222. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  223. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  224. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  225. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  226. [KTVHTTPCache cacheDeleteAllCaches];
  227. [CCUtility emptyGroupDirectoryProviderStorage];
  228. [CCUtility emptyGroupApplicationSupport];
  229. [CCUtility emptyDocumentsDirectory];
  230. [CCUtility emptyTemporaryDirectory];
  231. [CCUtility deleteAllChainStore];
  232. [[NCManageDatabase sharedInstance] removeDB];
  233. exit(0);
  234. }]];
  235. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  236. }]];
  237. alertController.popoverPresentationController.sourceView = self.view;
  238. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  239. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  240. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  241. [self presentViewController:alertController animated:YES completion:nil];
  242. }
  243. @end