CCAdvanced.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. //
  2. // CCManageHelp.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  6. // Copyright (c) 2015 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. CCHud *_hud;
  32. }
  33. @end
  34. @implementation CCAdvanced
  35. - (void)initializeForm
  36. {
  37. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  38. XLFormSectionDescriptor *section;
  39. XLFormRowDescriptor *row;
  40. // Section HIDDEN FILES -------------------------------------------------
  41. section = [XLFormSectionDescriptor formSection];
  42. [form addFormSection:section];
  43. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
  44. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  45. if ([CCUtility getShowHiddenFiles]) row.value = @"1";
  46. else row.value = @"0";
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  48. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  49. [section addFormRow:row];
  50. // Format Compatibility + Live Photo
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. section.footerTitle = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"_format_compatibility_footer_", nil), NSLocalizedString(@"_upload_mov_livephoto_footer_", nil)];
  54. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
  55. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  56. if ([CCUtility getFormatCompatibility]) row.value = @"1";
  57. else row.value = @"0";
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  60. [section addFormRow:row];
  61. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"livePhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_upload_mov_livephoto_", nil)];
  62. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  63. if ([CCUtility getLivePhoto]) row.value = @"1";
  64. else row.value = @"0";
  65. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  66. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  67. [section addFormRow:row];
  68. // Disable Local Cache After Upload
  69. section = [XLFormSectionDescriptor formSection];
  70. [form addFormSection:section];
  71. section.footerTitle = NSLocalizedString(@"_disableLocalCacheAfterUpload_footer_", nil);
  72. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disableLocalCacheAfterUpload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disableLocalCacheAfterUpload_", nil)];
  73. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  74. if ([CCUtility getDisableLocalCacheAfterUpload]) row.value = @"1";
  75. else row.value = @"0";
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  77. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  78. [section addFormRow:row];
  79. // Section : Files App --------------------------------------------------------------
  80. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  81. section = [XLFormSectionDescriptor formSection];
  82. [form addFormSection:section];
  83. section.footerTitle = NSLocalizedString(@"_disable_files_app_footer_", nil);
  84. // Disable Files App
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disable_files_app_", nil)];
  86. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  87. if ([CCUtility getDisableFilesApp]) row.value = @"1";
  88. else row.value = @"0";
  89. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  90. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  91. [section addFormRow:row];
  92. }
  93. // Section : Privacy --------------------------------------------------------------
  94. if (!NCBrandOptions.sharedInstance.disable_crash_service) {
  95. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_privacy_", nil)];
  96. [form addFormSection:section];
  97. section.footerTitle = NSLocalizedString(@"_privacy_footer_", nil);
  98. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"crashservice" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_crashservice_title_", nil)];
  99. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  100. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  101. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  102. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"crashservice"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  103. if ([CCUtility getDisableCrashservice]) row.value = @"1";
  104. else row.value = @"0";
  105. [section addFormRow:row];
  106. }
  107. // Section DIAGNOSTICS -------------------------------------------------
  108. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_diagnostics_", nil)];
  109. [form addFormSection:section];
  110. NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  111. NSString *logFile = [documentPath stringByAppendingPathComponent:@"communication.log"];
  112. if ([[NSFileManager defaultManager] fileExistsAtPath:logFile]) {
  113. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"log" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Log", nil)];
  114. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  115. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  116. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  117. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  118. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"capabilities"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  119. row.action.formBlock = ^(XLFormRowDescriptor * sender) {
  120. [self deselectFormRow:sender];
  121. NCViewerQuickLook *viewerQuickLook = [NCViewerQuickLook new];
  122. [viewerQuickLook quickLookWithUrl:[NSURL fileURLWithPath:logFile] viewController:self];
  123. };
  124. [section addFormRow:row];
  125. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearlog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Clear Log", nil)];
  126. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  127. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  128. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  129. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  130. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"capabilities"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  131. row.action.formBlock = ^(XLFormRowDescriptor * sender) {
  132. [self deselectFormRow:sender];
  133. [[NCCommunicationCommon shared] clearFileLog];
  134. [[NCCommunicationCommon shared] writeLog:@"[LOG] Start session"];
  135. };
  136. [section addFormRow:row];
  137. }
  138. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"capabilities" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_capabilities_", nil)];
  139. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  140. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  141. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  143. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"capabilities"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  144. row.action.formBlock = ^(XLFormRowDescriptor * sender) {
  145. [self deselectFormRow:sender];
  146. NCCapabilitiesViewController *capabilities = [[UIStoryboard storyboardWithName:@"NCCapabilitiesViewController" bundle:nil] instantiateInitialViewController];
  147. [self presentViewController:capabilities animated:YES completion:nil];
  148. };
  149. [section addFormRow:row];
  150. // Section CLEAR CACHE -------------------------------------------------
  151. section = [XLFormSectionDescriptor formSection];
  152. [form addFormSection:section];
  153. section.footerTitle = NSLocalizedString(@"_clear_cache_footer_", nil);
  154. // Clear cache
  155. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_", nil)];
  156. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  157. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  158. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  159. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  160. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  161. row.action.formSelector = @selector(clearCacheRequest:);
  162. [section addFormRow:row];
  163. // Section EXIT --------------------------------------------------------
  164. section = [XLFormSectionDescriptor formSection];
  165. [form addFormSection:section];
  166. section.footerTitle = NSLocalizedString(@"_exit_footer_", nil);
  167. // Exit
  168. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  169. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  170. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  171. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  172. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  173. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"exit"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
  174. row.action.formSelector = @selector(exitNextcloud:);
  175. [section addFormRow:row];
  176. self.tableView.showsVerticalScrollIndicator = NO;
  177. self.form = form;
  178. }
  179. - (void)viewDidLoad
  180. {
  181. [super viewDidLoad];
  182. self.title = NSLocalizedString(@"_advanced_", nil);
  183. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  184. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  185. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  186. [self changeTheming];
  187. }
  188. - (void)changeTheming
  189. {
  190. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  191. [self initializeForm];
  192. }
  193. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  194. {
  195. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  196. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  197. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  198. }
  199. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  200. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  201. }
  202. if ([rowDescriptor.tag isEqualToString:@"livePhoto"]) {
  203. [CCUtility setLivePhoto:[[rowDescriptor.value valueData] boolValue]];
  204. }
  205. if ([rowDescriptor.tag isEqualToString:@"disableLocalCacheAfterUpload"]) {
  206. [CCUtility setDisableLocalCacheAfterUpload:[[rowDescriptor.value valueData] boolValue]];
  207. }
  208. if ([rowDescriptor.tag isEqualToString:@"disablefilesapp"]) {
  209. [CCUtility setDisableFilesApp:[[rowDescriptor.value valueData] boolValue]];
  210. }
  211. if ([rowDescriptor.tag isEqualToString:@"crashservice"]) {
  212. [CCUtility setDisableCrashservice:[[rowDescriptor.value valueData] boolValue]];
  213. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_crashservice_title_", nil) message:NSLocalizedString(@"_crashservice_alert_", nil) preferredStyle:UIAlertControllerStyleAlert];
  214. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  215. exit(0);
  216. }];
  217. [alertController addAction:okAction];
  218. [self presentViewController:alertController animated:YES completion:nil];
  219. }
  220. }
  221. #pragma --------------------------------------------------------------------------------------------
  222. #pragma mark === Clear Cache ===
  223. #pragma --------------------------------------------------------------------------------------------
  224. - (void)clearCache
  225. {
  226. [appDelegate maintenanceMode:YES];
  227. [[NCMainCommon sharedInstance] cancelAllTransfer];
  228. [[NCOperationQueue shared] cancelAllQueue];
  229. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  230. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  231. [KTVHTTPCache cacheDeleteAllCaches];
  232. [[NCManageDatabase sharedInstance] clearDatabaseWithAccount:appDelegate.account removeAccount:false];
  233. [CCUtility removeGroupDirectoryProviderStorage];
  234. [CCUtility removeGroupLibraryDirectory];
  235. [CCUtility removeDocumentsDirectory];
  236. [CCUtility removeTemporaryDirectory];
  237. [CCUtility createDirectoryStandard];
  238. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  239. [appDelegate maintenanceMode:NO];
  240. // Inizialized home
  241. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
  242. // Clear Media
  243. [appDelegate.activeMedia reloadDataSource];
  244. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  245. [_hud hideHud];
  246. });
  247. }
  248. - (void)clearCacheRequest:(XLFormRowDescriptor *)sender
  249. {
  250. [self deselectFormRow:sender];
  251. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  252. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  253. [_hud visibleHudTitle:NSLocalizedString(@"_wait_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  254. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  255. [self clearCache];
  256. });
  257. }]];
  258. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  259. }]];
  260. alertController.popoverPresentationController.sourceView = self.view;
  261. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  262. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  263. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  264. [self presentViewController:alertController animated:YES completion:nil];
  265. }
  266. #pragma --------------------------------------------------------------------------------------------
  267. #pragma mark == Exit Nextcloud ==
  268. #pragma --------------------------------------------------------------------------------------------
  269. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  270. {
  271. [self deselectFormRow:sender];
  272. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  273. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  274. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  275. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  276. [KTVHTTPCache cacheDeleteAllCaches];
  277. [CCUtility removeGroupDirectoryProviderStorage];
  278. [CCUtility removeGroupApplicationSupport];
  279. [CCUtility removeDocumentsDirectory];
  280. [CCUtility removeTemporaryDirectory];
  281. [CCUtility deleteAllChainStore];
  282. [[NCManageDatabase sharedInstance] removeDB];
  283. exit(0);
  284. }]];
  285. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  286. }]];
  287. alertController.popoverPresentationController.sourceView = self.view;
  288. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  289. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  290. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  291. [self presentViewController:alertController animated:YES completion:nil];
  292. }
  293. @end