CCAdvanced.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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 "NCBridgeSwift.h"
  27. @interface CCAdvanced ()
  28. {
  29. AppDelegate *appDelegate;
  30. }
  31. @end
  32. @implementation CCAdvanced
  33. -(id)init
  34. {
  35. XLFormDescriptor *form ;
  36. XLFormSectionDescriptor *section;
  37. XLFormRowDescriptor *row;
  38. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  40. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_advanced_", nil)];
  41. // Section ACTIVITY -------------------------------------------------
  42. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_activity_", nil)];
  43. [form addFormSection:section];
  44. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"activityVerboseHigh" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_help_activity_verbose_", nil)];
  45. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  46. [row.cellConfig setObject:[UIImage imageNamed:@"settingsActivityHigh"] forKey:@"imageView.image"];
  47. if ([CCUtility getActivityVerboseHigh]) row.value = @"1";
  48. else row.value = @"0";
  49. [section addFormRow:row];
  50. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendMailActivity" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_mail_", nil)];
  51. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  52. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  53. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  54. [row.cellConfig setObject:[UIImage imageNamed:@"settingsSendActivity"] forKey:@"imageView.image"];
  55. row.action.formSelector = @selector(sendMail:);
  56. [section addFormRow:row];
  57. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearActivityLog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_clear_", nil)];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  60. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  61. [row.cellConfig setObject:[UIImage imageNamed:@"settingsClearActivity"] forKey:@"imageView.image"];
  62. row.action.formSelector = @selector(clearActivity:);
  63. [section addFormRow:row];
  64. // Section OTTIMIZATIONS -------------------------------------------------
  65. section = [XLFormSectionDescriptor formSection];
  66. [form addFormSection:section];
  67. section.footerTitle = NSLocalizedString(@"_optimized_photos_how_", nil);
  68. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizedphoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_optimized_photos_", nil)];
  69. if ([CCUtility getOptimizedPhoto]) row.value = @"1";
  70. else row.value = @"0";
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  72. [section addFormRow:row];
  73. section = [XLFormSectionDescriptor formSection];
  74. [form addFormSection:section];
  75. section.footerTitle = NSLocalizedString(@"_upload_del_photos_how_", nil);
  76. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"uploadremovephoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_upload_del_photos_", nil)];
  77. if ([CCUtility getUploadAndRemovePhoto]) row.value = @"1";
  78. else row.value = @"0";
  79. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  80. [section addFormRow:row];
  81. // Section HIDDEN FILES -------------------------------------------------
  82. section = [XLFormSectionDescriptor formSection];
  83. [form addFormSection:section];
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
  85. if ([CCUtility getShowHiddenFiles]) row.value = @"1";
  86. else row.value = @"0";
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  88. [section addFormRow:row];
  89. // Format Compatibility
  90. section = [XLFormSectionDescriptor formSection];
  91. [form addFormSection:section];
  92. section.footerTitle = NSLocalizedString(@"_format_compatibility_footer_", nil);
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
  94. if ([CCUtility getFormatCompatibility]) row.value = @"1";
  95. else row.value = @"0";
  96. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  97. [section addFormRow:row];
  98. // Section CLEAR CACHE -------------------------------------------------
  99. section = [XLFormSectionDescriptor formSection];
  100. [form addFormSection:section];
  101. // Clear cache
  102. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_no_size_", nil)];
  103. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  104. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  105. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  106. [row.cellConfig setObject:[UIImage imageNamed:@"settingsClearCache"] forKey:@"imageView.image"];
  107. row.action.formSelector = @selector(clearCache:);
  108. [section addFormRow:row];
  109. // Section EXIT --------------------------------------------------------
  110. section = [XLFormSectionDescriptor formSection];
  111. [form addFormSection:section];
  112. // Exit
  113. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  114. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  115. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  116. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  117. [row.cellConfig setObject:[UIImage imageNamed:@"settingsExit"] forKey:@"imageView.image"];
  118. row.action.formSelector = @selector(exitNextcloud:);
  119. [section addFormRow:row];
  120. return [super initWithForm:form];
  121. }
  122. - (void)viewDidLoad
  123. {
  124. [super viewDidLoad];
  125. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  126. }
  127. // Apparirà
  128. - (void)viewWillAppear:(BOOL)animated
  129. {
  130. [super viewWillAppear:animated];
  131. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  132. self.tableView.showsVerticalScrollIndicator = NO;
  133. // Color
  134. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  135. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  136. [self recalculateSize];
  137. }
  138. - (void)changeTheming
  139. {
  140. if (self.isViewLoaded && self.view.window)
  141. [appDelegate changeTheming:self];
  142. }
  143. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  144. {
  145. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  146. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  147. [CCUtility setActivityVerboseHigh:[[rowDescriptor.value valueData] boolValue]];
  148. // Clear Date read Activity for force reload datasource
  149. appDelegate.activeActivity.storeDateFirstActivity = nil;
  150. }
  151. if ([rowDescriptor.tag isEqualToString:@"optimizedphoto"]) {
  152. [CCUtility setOptimizedPhoto:[[rowDescriptor.value valueData] boolValue]];
  153. }
  154. if ([rowDescriptor.tag isEqualToString:@"uploadremovephoto"]) {
  155. [CCUtility setUploadAndRemovePhoto:[[rowDescriptor.value valueData] boolValue]];
  156. }
  157. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  158. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  159. // force reload
  160. [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
  161. }
  162. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  163. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  164. }
  165. }
  166. #pragma --------------------------------------------------------------------------------------------
  167. #pragma mark === Mail ===
  168. #pragma --------------------------------------------------------------------------------------------
  169. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  170. {
  171. switch (result)
  172. {
  173. case MFMailComposeResultCancelled:
  174. [appDelegate messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  175. break;
  176. case MFMailComposeResultSaved:
  177. [appDelegate messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  178. break;
  179. case MFMailComposeResultSent:
  180. [appDelegate messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  181. break;
  182. case MFMailComposeResultFailed: {
  183. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  184. [appDelegate messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode: error.code];
  185. }
  186. break;
  187. default:
  188. break;
  189. }
  190. // Close the Mail Interface
  191. [self dismissViewControllerAnimated:YES completion:NULL];
  192. }
  193. - (void)sendMail:(XLFormRowDescriptor *)sender
  194. {
  195. [self deselectFormRow:sender];
  196. // Email Subject
  197. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  198. // Email Content
  199. NSString *messageBody;
  200. // File Attachment
  201. NSString *fileAttachment = @"";
  202. // Email Recipents
  203. NSArray *toRecipents;
  204. NSArray *activities = [[NCManageDatabase sharedInstance] getActivityWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", appDelegate.activeAccount]];
  205. if ([activities count] == 0) {
  206. [appDelegate messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  207. return;
  208. }
  209. for (tableActivity *activity in activities) {
  210. NSString *date, *type, *actionFile, *note;
  211. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  212. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  213. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  214. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  215. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  216. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  217. else note = activity.note;
  218. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  219. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  220. }
  221. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  222. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  223. NSString *documentsDirectory = [paths objectAtIndex:0];
  224. NSError *error;
  225. // fix CCAdvanced.m line 276 2.17.2 (00005)
  226. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error] && [MFMailComposeViewController canSendMail]) {
  227. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  228. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  229. mc.mailComposeDelegate = self;
  230. [mc setSubject:emailTitle];
  231. [mc setMessageBody:messageBody isHTML:NO];
  232. [mc setToRecipients:toRecipents];
  233. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  234. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  235. // Present mail view controller on screen
  236. [self presentViewController:mc animated:YES completion:NULL];
  237. } else {
  238. [appDelegate messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  239. }
  240. }
  241. #pragma --------------------------------------------------------------------------------------------
  242. #pragma mark === Clear Activity ===
  243. #pragma --------------------------------------------------------------------------------------------
  244. - (void)clearActivity:(XLFormRowDescriptor *)sender
  245. {
  246. [self deselectFormRow:sender];
  247. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  248. [appDelegate.activeActivity reloadDatasource];
  249. }
  250. #pragma --------------------------------------------------------------------------------------------
  251. #pragma mark === Clear Cache ===
  252. #pragma --------------------------------------------------------------------------------------------
  253. - (void)removeAllFiles:(BOOL)removeIco
  254. {
  255. [appDelegate maintenanceMode:YES];
  256. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  257. [[NCManageDatabase sharedInstance] clearTable:[tableQueueDownload class] account:appDelegate.activeAccount];
  258. [[NCManageDatabase sharedInstance] clearTable:[tableQueueUpload class] account:appDelegate.activeAccount];
  259. [appDelegate.netQueue cancelAllOperations];
  260. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:appDelegate.activeAccount activeUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl];
  261. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  262. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  263. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  264. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  265. [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:appDelegate.activeAccount];
  266. [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:appDelegate.activeAccount];
  267. [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:appDelegate.activeAccount];
  268. [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:appDelegate.activeAccount];
  269. [[NCManageDatabase sharedInstance] clearTable:[tableGPS class] account:nil];
  270. [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:appDelegate.activeAccount];
  271. [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:appDelegate.activeAccount];
  272. [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:appDelegate.activeAccount];
  273. [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:appDelegate.activeAccount];
  274. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  275. [self emptyUserDirectoryUser:appDelegate.activeUser url:appDelegate.activeUrl removeIco:removeIco];
  276. [self emptyLocalDirectory];
  277. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  278. for (NSString *file in tmpDirectory)
  279. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  280. [self recalculateSize];
  281. [appDelegate maintenanceMode:NO];
  282. dispatch_async(dispatch_get_main_queue(), ^{
  283. // Close HUD
  284. [self.hud hideHud];
  285. // Inizialized home
  286. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  287. });
  288. });
  289. }
  290. - (void)clearCache:(XLFormRowDescriptor *)sender
  291. {
  292. [self deselectFormRow:sender];
  293. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  294. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  295. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_thumbnails_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  296. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil)
  297. style:UIAlertActionStyleDefault
  298. handler:^(UIAlertAction *action) {
  299. [self removeAllFiles:YES];
  300. }]];
  301. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_no_", nil)
  302. style:UIAlertActionStyleDefault
  303. handler:^(UIAlertAction *action) {
  304. [self removeAllFiles:NO];
  305. }]];
  306. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  307. }]];
  308. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  309. // iPhone
  310. [self presentViewController:alertController animated:YES completion:nil];
  311. } else {
  312. // iPad
  313. // Change Rect to position Popover
  314. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  315. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  316. }
  317. }]];
  318. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  319. }]];
  320. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  321. // iPhone
  322. [self presentViewController:alertController animated:YES completion:nil];
  323. } else {
  324. // iPad
  325. // Change Rect to position Popover
  326. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  327. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  328. }
  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.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  352. [appDelegate.netQueue cancelAllOperations];
  353. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:appDelegate.activeAccount activeUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl];
  354. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  355. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  356. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  357. [[NCManageDatabase sharedInstance] removeDB];
  358. [CCUtility deleteAllChainStore];
  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. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  372. // iPhone
  373. [self presentViewController:alertController animated:YES completion:nil];
  374. } else {
  375. // iPad
  376. // Change Rect to position Popover
  377. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  378. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  379. }
  380. }
  381. #pragma --------------------------------------------------------------------------------------------
  382. #pragma mark == Utility ==
  383. #pragma --------------------------------------------------------------------------------------------
  384. - (void)emptyGroupApplicationSupport
  385. {
  386. NSString *file;
  387. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:[NCBrandOptions sharedInstance].capabilitiesGroups];
  388. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  389. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  390. while (file = [enumerator nextObject])
  391. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  392. }
  393. - (void)emptyLibraryDirectory
  394. {
  395. NSString *file;
  396. NSString *dirIniziale;
  397. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  398. dirIniziale = [paths objectAtIndex:0];
  399. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  400. while (file = [enumerator nextObject])
  401. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  402. }
  403. - (void)emptyDocumentsDirectory
  404. {
  405. NSString *file;
  406. NSString *dirIniziale;
  407. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  408. dirIniziale = [paths objectAtIndex:0];
  409. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  410. while (file = [enumerator nextObject])
  411. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  412. }
  413. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url removeIco:(BOOL)removeIco
  414. {
  415. NSString *file;
  416. NSString *dirIniziale;
  417. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  418. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  419. while (file = [enumerator nextObject]) {
  420. NSString *ext = [[file pathExtension] lowercaseString];
  421. // Do not remove ICO
  422. if ([ext isEqualToString:@"ico"] && !removeIco)
  423. continue;
  424. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  425. }
  426. }
  427. - (void)emptyLocalDirectory
  428. {
  429. NSString *file;
  430. NSString *dirIniziale;
  431. dirIniziale = [CCUtility getDirectoryLocal];
  432. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  433. while (file = [enumerator nextObject])
  434. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  435. }
  436. - (NSNumber *)getUserDirectorySize
  437. {
  438. NSString *directoryUser = [CCUtility getDirectoryActiveUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl];
  439. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  440. unsigned long long count = 0;
  441. NSNumber *value = nil;
  442. if (! directoryURL) return 0;
  443. // Get dimension Document
  444. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  445. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  446. count += [value longLongValue];
  447. } else {
  448. return nil;
  449. }
  450. }
  451. return @(count);
  452. }
  453. @end