CCAdvanced.m 15 KB

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