CCManageSynchronizations.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // CCManageSynchronizations.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/11/15.
  6. // Copyright (c) 2014 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 "CCManageSynchronizations.h"
  24. #import "AppDelegate.h"
  25. @implementation CCManageSynchronizations
  26. - (id)initWithCoder:(NSCoder *)aDecoder
  27. {
  28. self = [super initWithCoder:aDecoder];
  29. if (self) {
  30. [self initializeForm];
  31. }
  32. return self;
  33. }
  34. - (void)initializeForm
  35. {
  36. XLFormDescriptor *form ;
  37. XLFormSectionDescriptor *section;
  38. XLFormRowDescriptor *row;
  39. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_synchronizations_", nil)];
  40. section = [XLFormSectionDescriptor formSection];
  41. [form addFormSection:section];
  42. section.footerTitle = NSLocalizedString(@"_sync_wifi_how_", nil);
  43. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"synchronizationswifi" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  44. if ([CCUtility getSynchronizationsOnlyWiFi]) row.value = @1;
  45. else row.value = @0;
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  47. [section addFormRow:row];
  48. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_sync_active_", nil) sectionOptions:XLFormSectionOptionCanDelete];
  49. [form addFormSection:section];
  50. [self synchronizationsActive:section];
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. self.form = form;
  54. }
  55. - (void)viewDidLoad
  56. {
  57. [super viewDidLoad];
  58. // Color
  59. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  60. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  61. [self.tableView setEditing:!self.tableView.editing animated:YES];
  62. }
  63. // Apparirà
  64. - (void)viewWillAppear:(BOOL)animated
  65. {
  66. [super viewWillAppear:animated];
  67. // Color
  68. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  69. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  70. }
  71. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  72. {
  73. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  74. if ([rowDescriptor.tag isEqualToString:@"synchronizationswifi"]) {
  75. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  76. [CCUtility setSynchronizationsOnlyWiFi:YES];
  77. } else {
  78. [CCUtility setSynchronizationsOnlyWiFi:NO];
  79. }
  80. }
  81. }
  82. -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. NSLog(@"[LOG] Should delete %i",(int)indexPath.row);
  85. XLFormRowDescriptor *rowDescriptor = [self.form formRowAtIndex:indexPath];
  86. [CCCoreData removeSynchronizedDirectoryID:rowDescriptor.tag activeAccount:app.activeAccount];
  87. [super tableView:tableView commitEditingStyle:editingStyle forRowAtIndexPath:indexPath];
  88. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:indexPath.section];
  89. [self synchronizationsActive:section];
  90. }
  91. - (void)synchronizationsActive:(XLFormSectionDescriptor *)section
  92. {
  93. XLFormRowDescriptor *row;
  94. NSArray *tableSynchronized = [CCCoreData getSynchronizedDirectoryActiveAccount:app.activeAccount];
  95. NSString *home = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud];
  96. NSString *title;
  97. [section.formRows removeAllObjects];
  98. [self.tableView reloadData];
  99. if ([tableSynchronized count] > 0) {
  100. for (TableDirectory *directory in tableSynchronized) {
  101. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])
  102. title = [directory.serverUrl stringByReplacingOccurrencesOfString:home withString:@""];
  103. title = [title lastPathComponent];
  104. if ([CCUtility isCryptoString:title]) {
  105. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileNameData == %@) AND (directory == 1) AND (account == %@)", title, app.activeAccount] context:nil];
  106. title = metadata.fileNamePrint;
  107. row = [XLFormRowDescriptor formRowDescriptorWithTag:directory.directoryID rowType:XLFormRowDescriptorTypeInfo title:title];
  108. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  109. } else {
  110. row = [XLFormRowDescriptor formRowDescriptorWithTag:directory.directoryID rowType:XLFormRowDescriptorTypeInfo title:title];
  111. }
  112. [section addFormRow:row];
  113. }
  114. section.title = NSLocalizedString(@"_sync_active_", nil);
  115. section.footerTitle = NSLocalizedString(@"_sync_active_footer_", nil);
  116. } else {
  117. section.title = @"";
  118. section.footerTitle = @"";
  119. }
  120. }
  121. @end