CCAdvanced.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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 : START DIRECTOY PHOTOS TAB -----------------------------------
  99. section = [XLFormSectionDescriptor formSection];
  100. [form addFormSection:section];
  101. section.footerTitle = NSLocalizedString(@"_start_directory_photos_tab_footer_", nil);
  102. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"startDirectoryPhotosTab" rowType:XLFormRowDescriptorTypeButton];
  103. NSString *directory = [CCUtility getStartDirectoryPhotosTab:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
  104. NSString *folder = [directory stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl] withString:@""];
  105. if ([folder isEqualToString:@""])
  106. folder = @"/";
  107. row.title = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_start_directory_photos_tab_", nil), folder];
  108. //[row.cellConfig setObject:[UIImage imageNamed:@"tabBarPhotos"] forKey:@"imageView.image"];
  109. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  110. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  111. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  112. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  113. row.action.formSelector = @selector(selectStartDirectoryPhotosTab:);
  114. [section addFormRow:row];
  115. // Section CLEAR CACHE -------------------------------------------------
  116. section = [XLFormSectionDescriptor formSection];
  117. [form addFormSection:section];
  118. // Clear cache
  119. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_no_size_", nil)];
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  121. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  122. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  123. [row.cellConfig setObject:[UIImage imageNamed:@"settingsClearCache"] forKey:@"imageView.image"];
  124. row.action.formSelector = @selector(clearCache:);
  125. [section addFormRow:row];
  126. // Section EXIT --------------------------------------------------------
  127. section = [XLFormSectionDescriptor formSection];
  128. [form addFormSection:section];
  129. // Exit
  130. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  131. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  132. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  133. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  134. [row.cellConfig setObject:[UIImage imageNamed:@"settingsExit"] forKey:@"imageView.image"];
  135. row.action.formSelector = @selector(exitNextcloud:);
  136. [section addFormRow:row];
  137. return [super initWithForm:form];
  138. }
  139. - (void)viewDidLoad
  140. {
  141. [super viewDidLoad];
  142. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  143. }
  144. // Apparirà
  145. - (void)viewWillAppear:(BOOL)animated
  146. {
  147. [super viewWillAppear:animated];
  148. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  149. self.tableView.showsVerticalScrollIndicator = NO;
  150. // Color
  151. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  152. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  153. [self recalculateSize];
  154. }
  155. - (void)changeTheming
  156. {
  157. if (self.isViewLoaded && self.view.window)
  158. [appDelegate changeTheming:self];
  159. }
  160. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  161. {
  162. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  163. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  164. [CCUtility setActivityVerboseHigh:[[rowDescriptor.value valueData] boolValue]];
  165. // Clear Date read Activity for force reload datasource
  166. appDelegate.activeActivity.storeDateFirstActivity = nil;
  167. }
  168. if ([rowDescriptor.tag isEqualToString:@"optimizedphoto"]) {
  169. [CCUtility setOptimizedPhoto:[[rowDescriptor.value valueData] boolValue]];
  170. }
  171. if ([rowDescriptor.tag isEqualToString:@"uploadremovephoto"]) {
  172. [CCUtility setUploadAndRemovePhoto:[[rowDescriptor.value valueData] boolValue]];
  173. }
  174. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  175. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  176. // force reload
  177. [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
  178. }
  179. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  180. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  181. }
  182. }
  183. #pragma --------------------------------------------------------------------------------------------
  184. #pragma mark == Action ==
  185. #pragma --------------------------------------------------------------------------------------------
  186. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  187. {
  188. switch (result)
  189. {
  190. case MFMailComposeResultCancelled:
  191. [appDelegate messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  192. break;
  193. case MFMailComposeResultSaved:
  194. [appDelegate messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  195. break;
  196. case MFMailComposeResultSent:
  197. [appDelegate messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  198. break;
  199. case MFMailComposeResultFailed: {
  200. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  201. [appDelegate messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode: error.code];
  202. }
  203. break;
  204. default:
  205. break;
  206. }
  207. // Close the Mail Interface
  208. [self dismissViewControllerAnimated:YES completion:NULL];
  209. }
  210. - (void)sendMail:(XLFormRowDescriptor *)sender
  211. {
  212. [self deselectFormRow:sender];
  213. // Email Subject
  214. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  215. // Email Content
  216. NSString *messageBody;
  217. // File Attachment
  218. NSString *fileAttachment = @"";
  219. // Email Recipents
  220. NSArray *toRecipents;
  221. NSArray *activities = [[NCManageDatabase sharedInstance] getActivityWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", appDelegate.activeAccount]];
  222. if ([activities count] == 0) {
  223. [appDelegate messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  224. return;
  225. }
  226. for (tableActivity *activity in activities) {
  227. NSString *date, *type, *actionFile, *note;
  228. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  229. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  230. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  231. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  232. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  233. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  234. else note = activity.note;
  235. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  236. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  237. }
  238. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  239. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  240. NSString *documentsDirectory = [paths objectAtIndex:0];
  241. NSError *error;
  242. // fix CCAdvanced.m line 276 2.17.2 (00005)
  243. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error] && [MFMailComposeViewController canSendMail]) {
  244. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  245. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  246. mc.mailComposeDelegate = self;
  247. [mc setSubject:emailTitle];
  248. [mc setMessageBody:messageBody isHTML:NO];
  249. [mc setToRecipients:toRecipents];
  250. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  251. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  252. // Present mail view controller on screen
  253. [self presentViewController:mc animated:YES completion:NULL];
  254. } else {
  255. [appDelegate messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  256. }
  257. }
  258. - (void)selectStartDirectoryPhotosTab:(XLFormRowDescriptor *)sender
  259. {
  260. [self deselectFormRow:sender];
  261. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  262. CCMove *viewController = (CCMove *)navigationController.topViewController;
  263. viewController.delegate = self;
  264. viewController.move.title = NSLocalizedString(@"_select_", nil);
  265. viewController.tintColor = [NCBrandColor sharedInstance].brandText;
  266. viewController.barTintColor = [NCBrandColor sharedInstance].brand;
  267. viewController.tintColorTitle = [NCBrandColor sharedInstance].brandText;
  268. viewController.networkingOperationQueue = appDelegate.netQueue;
  269. // E2EE
  270. viewController.includeDirectoryE2EEncryption = YES;
  271. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  272. [self presentViewController:navigationController animated:YES completion:nil];
  273. }
  274. - (void)clearActivity:(XLFormRowDescriptor *)sender
  275. {
  276. [self deselectFormRow:sender];
  277. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  278. [appDelegate.activeActivity reloadDatasource];
  279. }
  280. - (void)removeAllFiles:(BOOL)removeIco
  281. {
  282. [appDelegate maintenanceMode:YES];
  283. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  284. [[NCManageDatabase sharedInstance] clearTable:[tableQueueDownload class] account:appDelegate.activeAccount];
  285. [[NCManageDatabase sharedInstance] clearTable:[tableQueueUpload class] account:appDelegate.activeAccount];
  286. [appDelegate.netQueue cancelAllOperations];
  287. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:appDelegate.activeAccount activeUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl];
  288. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  289. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  290. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  291. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  292. [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:appDelegate.activeAccount];
  293. [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:appDelegate.activeAccount];
  294. [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:appDelegate.activeAccount];
  295. [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:appDelegate.activeAccount];
  296. [[NCManageDatabase sharedInstance] clearTable:[tableGPS class] account:nil];
  297. [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:appDelegate.activeAccount];
  298. [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:appDelegate.activeAccount];
  299. [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:appDelegate.activeAccount];
  300. [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:appDelegate.activeAccount];
  301. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  302. [self emptyUserDirectoryUser:appDelegate.activeUser url:appDelegate.activeUrl removeIco:removeIco];
  303. [self emptyDocumentsDirectory];
  304. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  305. for (NSString *file in tmpDirectory)
  306. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  307. [self recalculateSize];
  308. [appDelegate maintenanceMode:NO];
  309. dispatch_async(dispatch_get_main_queue(), ^{
  310. // Close HUD
  311. [self.hud hideHud];
  312. // Inizialized home
  313. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  314. });
  315. });
  316. }
  317. - (void)clearCache:(XLFormRowDescriptor *)sender
  318. {
  319. [self deselectFormRow:sender];
  320. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  321. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  322. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_thumbnails_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  323. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil)
  324. style:UIAlertActionStyleDefault
  325. handler:^(UIAlertAction *action) {
  326. [self removeAllFiles:YES];
  327. }]];
  328. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_no_", nil)
  329. style:UIAlertActionStyleDefault
  330. handler:^(UIAlertAction *action) {
  331. [self removeAllFiles:NO];
  332. }]];
  333. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  334. }]];
  335. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  336. // iPhone
  337. [self presentViewController:alertController animated:YES completion:nil];
  338. } else {
  339. // iPad
  340. // Change Rect to position Popover
  341. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  342. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  343. }
  344. }]];
  345. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  346. }]];
  347. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  348. // iPhone
  349. [self presentViewController:alertController animated:YES completion:nil];
  350. } else {
  351. // iPad
  352. // Change Rect to position Popover
  353. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  354. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  355. }
  356. }
  357. - (void)recalculateSize
  358. {
  359. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  360. self.form.delegate = nil;
  361. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  362. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  363. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  364. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  365. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  366. self.form.delegate = self;
  367. });
  368. }
  369. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  370. {
  371. [self deselectFormRow:sender];
  372. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  373. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  374. [self.hud visibleIndeterminateHud];
  375. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  376. [appDelegate.netQueue cancelAllOperations];
  377. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:appDelegate.activeAccount activeUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl];
  378. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  379. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  380. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  381. [[NCManageDatabase sharedInstance] removeDB];
  382. [CCUtility deleteAllChainStore];
  383. [self emptyDocumentsDirectory];
  384. [self emptyLibraryDirectory];
  385. [self emptyGroupApplicationSupport];
  386. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  387. for (NSString *file in tmpDirectory)
  388. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  389. [self.hud hideHud];
  390. exit(0);
  391. });
  392. }]];
  393. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  394. }]];
  395. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  396. // iPhone
  397. [self presentViewController:alertController animated:YES completion:nil];
  398. } else {
  399. // iPad
  400. // Change Rect to position Popover
  401. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  402. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  403. }
  404. }
  405. #pragma --------------------------------------------------------------------------------------------
  406. #pragma mark == Delegate Move ==
  407. #pragma --------------------------------------------------------------------------------------------
  408. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title
  409. {
  410. NSString *oldStartDirectoryPhotosTab = [CCUtility getStartDirectoryPhotosTab:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
  411. [CCUtility setStartDirectoryPhotosTab:serverUrlTo];
  412. if (![serverUrlTo isEqualToString:oldStartDirectoryPhotosTab]) {
  413. // Save
  414. [CCUtility setStartDirectoryPhotosTab:serverUrlTo];
  415. // Reload row
  416. XLFormRowDescriptor *rowStartDirectoryPhotosTab = [self.form formRowWithTag:@"startDirectoryPhotosTab"];
  417. NSString *folder = [serverUrlTo stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl] withString:@""];
  418. if ([folder isEqualToString:@""])
  419. folder = @"/";
  420. rowStartDirectoryPhotosTab.title = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_start_directory_photos_tab_", nil), folder];
  421. [self.tableView reloadData];
  422. // search PhotoVideo with new start directory
  423. [appDelegate.activePhotos searchPhotoVideo];
  424. }
  425. }
  426. #pragma --------------------------------------------------------------------------------------------
  427. #pragma mark == Utility ==
  428. #pragma --------------------------------------------------------------------------------------------
  429. - (void)emptyGroupApplicationSupport
  430. {
  431. NSString *file;
  432. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:[NCBrandOptions sharedInstance].capabilitiesGroups];
  433. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  434. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  435. while (file = [enumerator nextObject])
  436. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  437. }
  438. - (void)emptyLibraryDirectory
  439. {
  440. NSString *file;
  441. NSString *dirIniziale;
  442. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  443. dirIniziale = [paths objectAtIndex:0];
  444. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  445. while (file = [enumerator nextObject])
  446. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  447. }
  448. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url removeIco:(BOOL)removeIco
  449. {
  450. NSString *file;
  451. NSString *dirIniziale;
  452. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  453. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  454. while (file = [enumerator nextObject]) {
  455. NSString *ext = [[file pathExtension] lowercaseString];
  456. // Do not remove ICO
  457. if ([ext isEqualToString:@"ico"] && !removeIco)
  458. continue;
  459. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  460. }
  461. }
  462. - (void)emptyDocumentsDirectory
  463. {
  464. NSString *file;
  465. NSString *dirIniziale;
  466. dirIniziale = [CCUtility getDirectoryDocuments];
  467. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  468. while (file = [enumerator nextObject])
  469. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  470. }
  471. - (NSNumber *)getUserDirectorySize
  472. {
  473. NSString *directoryUser = [CCUtility getDirectoryActiveUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl];
  474. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  475. unsigned long long count = 0;
  476. NSNumber *value = nil;
  477. if (! directoryURL) return 0;
  478. // Get dimension Document
  479. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  480. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  481. count += [value longLongValue];
  482. } else {
  483. return nil;
  484. }
  485. }
  486. return @(count);
  487. }
  488. @end