CCAdvanced.m 15 KB

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