/
OTRSettingsManager.m
195 lines (158 loc) · 8.02 KB
/
OTRSettingsManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// OTRSettingsManager.m
// Off the Record
//
// Created by Chris Ballinger on 4/10/12.
// Copyright (c) 2012 Chris Ballinger. All rights reserved.
//
// This file is part of ChatSecure.
//
// ChatSecure is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ChatSecure is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ChatSecure. If not, see <http://www.gnu.org/licenses/>.
#import "OTRSettingsManager.h"
#import "OTRViewSetting.h"
@import OTRAssets;
#import "OTRSettingsGroup.h"
#import "OTRSetting.h"
#import "OTRBoolSetting.h"
#import "OTRViewSetting.h"
#import "OTRDoubleSetting.h"
#import "OTRFeedbackSetting.h"
#import "OTRConstants.h"
#import "OTRShareSetting.h"
#import "OTRLanguageSetting.h"
#import "OTRDonateSetting.h"
#import "OTRIntSetting.h"
#import "OTRCertificateSetting.h"
#import "OTRUtilities.h"
#import "OTRFingerprintSetting.h"
#import <ChatSecureCore/ChatSecureCore-Swift.h>
#import "OTRUtilities.h"
@interface OTRSettingsManager ()
@property (nonatomic, strong) NSMutableArray *settingsGroups;
@property (nonatomic, strong) NSDictionary *settingsDictionary;
- (void) populateSettings;
@end
@implementation OTRSettingsManager
- (id) init
{
if (self = [super init])
{
[self populateSettings];
}
return self;
}
- (void) populateSettings
{
self.settingsGroups = [NSMutableArray array];
NSMutableDictionary *newSettingsDictionary = [NSMutableDictionary dictionary];
// Leave this in for now
OTRViewSetting *accountsViewSetting = [[OTRViewSetting alloc] initWithTitle:ACCOUNTS_STRING description:nil viewControllerClass:nil];
OTRSettingsGroup *accountsGroup = [[OTRSettingsGroup alloc] initWithTitle:ACCOUNTS_STRING settings:[NSArray arrayWithObject:accountsViewSetting]];
[self.settingsGroups addObject:accountsGroup];
OTRBoolSetting *deletedDisconnectedConversations = [[OTRBoolSetting alloc] initWithTitle:DELETE_CONVERSATIONS_ON_DISCONNECT_TITLE_STRING
description:DELETE_CONVERSATIONS_ON_DISCONNECT_DESCRIPTION_STRING
settingsKey:kOTRSettingKeyDeleteOnDisconnect];
[newSettingsDictionary setObject:deletedDisconnectedConversations forKey:kOTRSettingKeyDeleteOnDisconnect];
OTRBoolSetting *opportunisticOtrSetting = [[OTRBoolSetting alloc] initWithTitle:OPPORTUNISTIC_OTR_SETTING_TITLE
description:OPPORTUNISTIC_OTR_SETTING_DESCRIPTION
settingsKey:kOTRSettingKeyOpportunisticOtr];
opportunisticOtrSetting.defaultValue = @(YES);
[newSettingsDictionary setObject:opportunisticOtrSetting forKey:kOTRSettingKeyOpportunisticOtr];
OTRCertificateSetting * certSetting = [[OTRCertificateSetting alloc] initWithTitle:PINNED_CERTIFICATES_STRING
description:PINNED_CERTIFICATES_DESCRIPTION_STRING];
certSetting.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
OTRFingerprintSetting * fingerprintSetting = [[OTRFingerprintSetting alloc] initWithTitle:OTR_FINGERPRINTS_STRING
description:OTR_FINGERPRINTS_SUBTITLE_STRING];
fingerprintSetting.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (![OTRNotificationPermissions canSendNotifications] ||
[PushController getPushPreference] != PushPreferenceEnabled) {
OTRViewSetting *pushViewSetting = [[OTRViewSetting alloc] initWithTitle:CHATSECURE_PUSH_STRING description:nil viewControllerClass:[EnablePushViewController class]];
pushViewSetting.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
OTRSettingsGroup *pushGroup = [[OTRSettingsGroup alloc] initWithTitle:PUSH_TITLE_STRING settings:@[pushViewSetting]];
[self.settingsGroups addObject:pushGroup];
}
NSArray *chatSettings;
NSArray * securitySettings;
chatSettings = [NSArray arrayWithObjects:deletedDisconnectedConversations, nil];
OTRSettingsGroup *chatSettingsGroup = [[OTRSettingsGroup alloc] initWithTitle:CHAT_STRING settings:chatSettings];
[self.settingsGroups addObject:chatSettingsGroup];
securitySettings = @[opportunisticOtrSetting,certSetting,fingerprintSetting];
OTRSettingsGroup *securitySettingsGroup = [[OTRSettingsGroup alloc] initWithTitle:SECURITY_STRING settings:securitySettings];
[self.settingsGroups addObject:securitySettingsGroup];
OTRFeedbackSetting * feedbackViewSetting = [[OTRFeedbackSetting alloc] initWithTitle:SEND_FEEDBACK_STRING description:nil];
feedbackViewSetting.imageName = @"18-envelope.png";
OTRShareSetting * shareViewSetting = [[OTRShareSetting alloc] initWithTitle:SHARE_STRING description:nil];
shareViewSetting.imageName = @"275-broadcast.png";
OTRLanguageSetting * languageSetting = [[OTRLanguageSetting alloc]initWithTitle:LANGUAGE_STRING description:nil settingsKey:kOTRSettingKeyLanguage];
languageSetting.imageName = @"globe.png";
[newSettingsDictionary setObject:languageSetting forKey:kOTRSettingKeyLanguage];
OTRDonateSetting *donateSetting = [[OTRDonateSetting alloc] initWithTitle:DONATE_STRING description:nil];
donateSetting.imageName = @"29-heart.png";
NSMutableArray *otherSettings = [NSMutableArray arrayWithCapacity:5];
[otherSettings addObjectsFromArray:@[languageSetting,donateSetting, shareViewSetting,feedbackViewSetting]];
OTRSettingsGroup *otherGroup = [[OTRSettingsGroup alloc] initWithTitle:OTHER_STRING settings:otherSettings];
[self.settingsGroups addObject:otherGroup];
self.settingsDictionary = newSettingsDictionary;
}
- (OTRSetting*) settingAtIndexPath:(NSIndexPath*)indexPath
{
OTRSettingsGroup *settingsGroup = [self.settingsGroups objectAtIndex:indexPath.section];
return [settingsGroup.settings objectAtIndex:indexPath.row];
}
- (NSString*) stringForGroupInSection:(NSUInteger)section
{
OTRSettingsGroup *settingsGroup = [self.settingsGroups objectAtIndex:section];
return settingsGroup.title;
}
- (NSUInteger) numberOfSettingsInSection:(NSUInteger)section
{
OTRSettingsGroup *settingsGroup = [self.settingsGroups objectAtIndex:section];
return [settingsGroup.settings count];
}
- (NSIndexPath *)indexPathForSetting:(OTRSetting *)setting
{
__block NSIndexPath *indexPath = nil;
[self.settingsGroups enumerateObjectsUsingBlock:^(OTRSettingsGroup *group, NSUInteger idx, BOOL *stop) {
NSUInteger row = [group.settings indexOfObject:setting];
if (row != NSNotFound) {
indexPath = [NSIndexPath indexPathForItem:row inSection:idx];
*stop = YES;
}
}];
return indexPath;
}
+ (BOOL) boolForOTRSettingKey:(NSString*)key
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults boolForKey:key];
}
+ (double) doubleForOTRSettingKey:(NSString*)key
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults doubleForKey:key];
}
+ (NSInteger) intForOTRSettingKey:(NSString *)key
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults integerForKey:key];
}
+ (float) floatForOTRSettingKey:(NSString *)key
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults floatForKey:key];
}
- (OTRSetting*) settingForOTRSettingKey:(NSString*)key {
return [self.settingsDictionary objectForKey:key];
}
@end