CCAdvanced.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. //
  2. // CCManageHelp.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  6. // Copyright (c) 2017 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 "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 ACTIVITY -------------------------------------------------
  43. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_activity_", nil)];
  44. [form addFormSection:section];
  45. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"activityVerboseHigh" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_help_activity_verbose_", nil)];
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"activityHigh"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  48. if ([CCUtility getActivityVerboseHigh]) row.value = @"1";
  49. else row.value = @"0";
  50. [section addFormRow:row];
  51. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendMailActivity" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_mail_", nil)];
  52. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  53. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  54. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  55. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"mail"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  56. row.action.formSelector = @selector(sendMail:);
  57. [section addFormRow:row];
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearActivityLog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_clear_", nil)];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  61. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  62. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  63. row.action.formSelector = @selector(clearActivity:);
  64. [section addFormRow:row];
  65. // Section OTTIMIZATIONS -------------------------------------------------
  66. section = [XLFormSectionDescriptor formSection];
  67. [form addFormSection:section];
  68. section.footerTitle = NSLocalizedString(@"_optimized_photos_how_", nil);
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizedphoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_optimized_photos_", nil)];
  70. if ([CCUtility getOptimizedPhoto]) row.value = @"1";
  71. else row.value = @"0";
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  73. [section addFormRow:row];
  74. section = [XLFormSectionDescriptor formSection];
  75. [form addFormSection:section];
  76. section.footerTitle = NSLocalizedString(@"_upload_del_photos_how_", nil);
  77. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"uploadremovephoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_upload_del_photos_", nil)];
  78. if ([CCUtility getUploadAndRemovePhoto]) row.value = @"1";
  79. else row.value = @"0";
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [section addFormRow:row];
  82. // Section HIDDEN FILES -------------------------------------------------
  83. section = [XLFormSectionDescriptor formSection];
  84. [form addFormSection:section];
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
  86. if ([CCUtility getShowHiddenFiles]) row.value = @"1";
  87. else row.value = @"0";
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  89. [section addFormRow:row];
  90. // Format Compatibility
  91. section = [XLFormSectionDescriptor formSection];
  92. [form addFormSection:section];
  93. section.footerTitle = NSLocalizedString(@"_format_compatibility_footer_", nil);
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
  95. if ([CCUtility getFormatCompatibility]) row.value = @"1";
  96. else row.value = @"0";
  97. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  98. [section addFormRow:row];
  99. // Section : Files App --------------------------------------------------------------
  100. section = [XLFormSectionDescriptor formSection];
  101. [form addFormSection:section];
  102. section.footerTitle = NSLocalizedString(@"_disable_files_app_footer_", nil);
  103. // Disable Files App
  104. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disable_files_app_", nil)];
  105. if ([CCUtility getDisableFilesApp]) row.value = @"1";
  106. else row.value = @"0";
  107. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  108. [section addFormRow:row];
  109. // Section CLEAR CACHE -------------------------------------------------
  110. section = [XLFormSectionDescriptor formSection];
  111. [form addFormSection:section];
  112. // Clear cache
  113. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_no_size_", nil)];
  114. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  115. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  116. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  117. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  118. row.action.formSelector = @selector(clearCache:);
  119. [section addFormRow:row];
  120. // Section EXIT --------------------------------------------------------
  121. section = [XLFormSectionDescriptor formSection];
  122. [form addFormSection:section];
  123. // Exit
  124. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  125. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  126. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  127. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  128. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"exit"] multiplier:2 color:[UIColor redColor]] forKey:@"imageView.image"];
  129. row.action.formSelector = @selector(exitNextcloud:);
  130. [section addFormRow:row];
  131. return [super initWithForm:form];
  132. }
  133. - (void)viewDidLoad
  134. {
  135. [super viewDidLoad];
  136. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  137. }
  138. // Apparirà
  139. - (void)viewWillAppear:(BOOL)animated
  140. {
  141. [super viewWillAppear:animated];
  142. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  143. self.tableView.showsVerticalScrollIndicator = NO;
  144. // Color
  145. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  146. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  147. [self recalculateSize];
  148. }
  149. - (void)changeTheming
  150. {
  151. if (self.isViewLoaded && self.view.window)
  152. [appDelegate changeTheming:self];
  153. }
  154. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  155. {
  156. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  157. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  158. [CCUtility setActivityVerboseHigh:[[rowDescriptor.value valueData] boolValue]];
  159. // Clear Date read Activity for force reload datasource
  160. appDelegate.activeActivity.storeDateFirstActivity = nil;
  161. }
  162. if ([rowDescriptor.tag isEqualToString:@"optimizedphoto"]) {
  163. [CCUtility setOptimizedPhoto:[[rowDescriptor.value valueData] boolValue]];
  164. }
  165. if ([rowDescriptor.tag isEqualToString:@"uploadremovephoto"]) {
  166. [CCUtility setUploadAndRemovePhoto:[[rowDescriptor.value valueData] boolValue]];
  167. }
  168. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  169. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  170. // force reload
  171. [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
  172. }
  173. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  174. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  175. }
  176. if ([rowDescriptor.tag isEqualToString:@"disablefilesapp"]) {
  177. [CCUtility setDisableFilesApp:[[rowDescriptor.value valueData] boolValue]];
  178. }
  179. }
  180. #pragma --------------------------------------------------------------------------------------------
  181. #pragma mark === Mail ===
  182. #pragma --------------------------------------------------------------------------------------------
  183. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  184. {
  185. switch (result)
  186. {
  187. case MFMailComposeResultCancelled:
  188. [appDelegate messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  189. break;
  190. case MFMailComposeResultSaved:
  191. [appDelegate messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  192. break;
  193. case MFMailComposeResultSent:
  194. [appDelegate messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  195. break;
  196. case MFMailComposeResultFailed: {
  197. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  198. [appDelegate messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode: error.code];
  199. }
  200. break;
  201. default:
  202. break;
  203. }
  204. // Close the Mail Interface
  205. [self dismissViewControllerAnimated:YES completion:NULL];
  206. }
  207. - (void)sendMail:(XLFormRowDescriptor *)sender
  208. {
  209. [self deselectFormRow:sender];
  210. // Email Subject
  211. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  212. // Email Content
  213. NSString *messageBody;
  214. // File Attachment
  215. NSString *fileAttachment = @"";
  216. // Email Recipents
  217. NSArray *toRecipents;
  218. NSArray *activities = [[NCManageDatabase sharedInstance] getActivityWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
  219. if ([activities count] == 0) {
  220. [appDelegate messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  221. return;
  222. }
  223. for (tableActivity *activity in activities) {
  224. NSString *date, *type, *actionFile, *note;
  225. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  226. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  227. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  228. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  229. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  230. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  231. else note = activity.note;
  232. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  233. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  234. }
  235. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  236. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  237. NSString *documentsDirectory = [paths objectAtIndex:0];
  238. NSError *error;
  239. // fix CCAdvanced.m line 276 2.17.2 (00005)
  240. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error] && [MFMailComposeViewController canSendMail]) {
  241. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  242. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  243. mc.mailComposeDelegate = self;
  244. [mc setSubject:emailTitle];
  245. [mc setMessageBody:messageBody isHTML:NO];
  246. [mc setToRecipients:toRecipents];
  247. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  248. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  249. // Present mail view controller on screen
  250. [self presentViewController:mc animated:YES completion:NULL];
  251. } else {
  252. [appDelegate messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  253. }
  254. }
  255. #pragma --------------------------------------------------------------------------------------------
  256. #pragma mark === Clear Activity ===
  257. #pragma --------------------------------------------------------------------------------------------
  258. - (void)clearActivity:(XLFormRowDescriptor *)sender
  259. {
  260. [self deselectFormRow:sender];
  261. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  262. [appDelegate.activeActivity reloadDatasource];
  263. }
  264. #pragma --------------------------------------------------------------------------------------------
  265. #pragma mark === Clear Cache ===
  266. #pragma --------------------------------------------------------------------------------------------
  267. - (void)removeAllFilesWithDB:(BOOL)withDB
  268. {
  269. [appDelegate maintenanceMode:YES];
  270. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  271. if (withDB) {
  272. [appDelegate.netQueue cancelAllOperations];
  273. }
  274. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  275. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorage] error:nil];
  276. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryUserData] error:nil];
  277. [self emptyDocumentsDirectory];
  278. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  279. for (NSString *file in tmpDirectory)
  280. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  281. [KTVHTTPCache cacheDeleteAllCaches];
  282. [self recalculateSize];
  283. // Clear Database
  284. [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:appDelegate.activeAccount];
  285. if (withDB) {
  286. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  287. [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:appDelegate.activeAccount];
  288. [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:appDelegate.activeAccount];
  289. [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:appDelegate.activeAccount];
  290. [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:appDelegate.activeAccount];
  291. [[NCManageDatabase sharedInstance] clearTable:[tableGPS class] account:nil];
  292. [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:appDelegate.activeAccount];
  293. [[NCManageDatabase sharedInstance] clearTable:[tablePhotos class] account:appDelegate.activeAccount];
  294. [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:appDelegate.activeAccount];
  295. [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:appDelegate.activeAccount];
  296. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  297. [appDelegate.filterFileID removeAllObjects];
  298. }
  299. [appDelegate maintenanceMode:NO];
  300. dispatch_async(dispatch_get_main_queue(), ^{
  301. // Close HUD
  302. [self.hud hideHud];
  303. // Inizialized home
  304. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  305. });
  306. });
  307. }
  308. - (void)clearCache:(XLFormRowDescriptor *)sender
  309. {
  310. [self deselectFormRow:sender];
  311. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  312. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil)
  313. style:UIAlertActionStyleDefault
  314. handler:^(UIAlertAction *action) {
  315. [self removeAllFilesWithDB:NO];
  316. }]];
  317. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_cache_and_db_", nil)
  318. style:UIAlertActionStyleDefault
  319. handler:^(UIAlertAction *action) {
  320. [self removeAllFilesWithDB:YES];
  321. }]];
  322. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  323. }]];
  324. alertController.popoverPresentationController.sourceView = self.view;
  325. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  326. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  327. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  328. [self presentViewController:alertController animated:YES completion:nil];
  329. }
  330. - (void)recalculateSize
  331. {
  332. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  333. self.form.delegate = nil;
  334. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  335. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  336. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  337. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  338. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  339. self.form.delegate = self;
  340. });
  341. }
  342. #pragma --------------------------------------------------------------------------------------------
  343. #pragma mark == Exit Nextcloud ==
  344. #pragma --------------------------------------------------------------------------------------------
  345. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  346. {
  347. [self deselectFormRow:sender];
  348. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  349. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  350. [self.hud visibleIndeterminateHud];
  351. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  352. [appDelegate.netQueue cancelAllOperations];
  353. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  354. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  355. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  356. [[NCManageDatabase sharedInstance] removeDB];
  357. [CCUtility deleteAllChainStore];
  358. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorage] error:nil];
  359. [self emptyDocumentsDirectory];
  360. [self emptyLibraryDirectory];
  361. [self emptyGroupApplicationSupport];
  362. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  363. for (NSString *file in tmpDirectory)
  364. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  365. [self.hud hideHud];
  366. exit(0);
  367. });
  368. }]];
  369. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  370. }]];
  371. alertController.popoverPresentationController.sourceView = self.view;
  372. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  373. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  374. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  375. [self presentViewController:alertController animated:YES completion:nil];
  376. }
  377. #pragma --------------------------------------------------------------------------------------------
  378. #pragma mark == Utility ==
  379. #pragma --------------------------------------------------------------------------------------------
  380. - (void)emptyGroupApplicationSupport
  381. {
  382. NSString *file;
  383. NSURL *dirGroup = [CCUtility getDirectoryGroup];
  384. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:k_appApplicationSupport] path];
  385. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  386. while (file = [enumerator nextObject])
  387. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  388. }
  389. - (void)emptyLibraryDirectory
  390. {
  391. NSString *file;
  392. NSString *dirIniziale;
  393. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  394. dirIniziale = [paths objectAtIndex:0];
  395. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  396. while (file = [enumerator nextObject])
  397. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  398. }
  399. - (void)emptyDocumentsDirectory
  400. {
  401. NSString *file;
  402. NSString *dirIniziale;
  403. dirIniziale = [CCUtility getDirectoryDocuments];
  404. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  405. while (file = [enumerator nextObject])
  406. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  407. }
  408. - (NSNumber *)getUserDirectorySize
  409. {
  410. NSURL *directoryURL = [CCUtility getDirectoryGroup];
  411. unsigned long long count = 0;
  412. NSNumber *value = nil;
  413. if (! directoryURL) return 0;
  414. // Get dimension Document
  415. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  416. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  417. count += [value longLongValue];
  418. } else {
  419. return nil;
  420. }
  421. }
  422. return @(count);
  423. }
  424. @end