1//
2//  KBPrefGeneralView.m
3//  Keybase
4//
5//  Created by Gabriel on 4/3/15.
6//  Copyright (c) 2015 Gabriel Handford. All rights reserved.
7//
8
9#import "KBPrefGeneralView.h"
10
11#import "KBPrefCheckbox.h"
12#import "KBPrefPopUpView.h"
13#import "KBPrefOption.h"
14
15#import "KBApp.h"
16//#import <Sparkle/Sparkle.h>
17#import <CocoaLumberjack/CocoaLumberjack.h>
18
19@implementation KBPrefGeneralView
20
21- (instancetype)initWithPreferences:(KBPreferences *)preferences {
22  if ((self = [super init])) {
23    [self setOptions:@{@"spacing": @"10", @"insets": @"40,0,40,0"}];
24
25    KBPrefCheckbox *launchAtLogin = [[KBPrefCheckbox alloc] init];
26    [launchAtLogin setCategory:@"System"];
27    [launchAtLogin setLabelText:@"Launch Keybase at login" identifier:@"Preferences.LaunchAtLogin" preferences:self];
28    [self addSubview:launchAtLogin];
29
30    KBPrefCheckbox *autoUpdate = [[KBPrefCheckbox alloc] init];
31    [autoUpdate setCategory:@"Updater"];
32    [autoUpdate setLabelText:@"Automatically check for updates" identifier:@"Preferences.Sparkle.AutoUpdate" preferences:self];
33    [self addSubview:autoUpdate];
34
35    KBPrefPopUpView *updateCheckInterval = [[KBPrefPopUpView alloc] init];
36    updateCheckInterval.inset = 170;
37    updateCheckInterval.fieldWidth = 150;
38    NSArray *udpateCheckOptions = @[[KBPrefOption prefOptionWithLabel:@"Hour" value:@(3600)],
39                                    [KBPrefOption prefOptionWithLabel:@"Day" value:@(86400)],
40                                    [KBPrefOption prefOptionWithLabel:@"Week" value:@(604800)],
41                                    [KBPrefOption prefOptionWithLabel:@"Month" value:@(2629800)],
42                                    ];
43    [updateCheckInterval setLabelText:@"Check Every" options:udpateCheckOptions identifier:@"Preferences.Sparkle.CheckInterval" preferences:self];
44    [self addSubview:updateCheckInterval];
45
46    KBPrefCheckbox *autoDownload = [[KBPrefCheckbox alloc] init];
47    [autoDownload setLabelText:@"Automatically download updates" identifier:@"Preferences.Sparkle.AutoDownload" preferences:self];
48    [self addSubview:autoDownload];
49
50    KBPrefCheckbox *sendsProfile = [[KBPrefCheckbox alloc] init];
51    [sendsProfile setLabelText:@"Sends system profile" identifier:@"Preferences.Sparkle.SendsProfile" preferences:self];
52    [self addSubview:sendsProfile];
53
54    KBPrefPopUpView *logLevel = [[KBPrefPopUpView alloc] init];
55    logLevel.inset = 0;
56    logLevel.labelWidth = 140;
57    logLevel.fieldWidth = 150;
58    NSArray *logLevelOptions = @[[KBPrefOption prefOptionWithLabel:@"Verbose" value:@(DDLogLevelVerbose)],
59                                 [KBPrefOption prefOptionWithLabel:@"Debug" value:@(DDLogLevelDebug)],
60                                 [KBPrefOption prefOptionWithLabel:@"Info" value:@(DDLogLevelInfo)],
61                                 [KBPrefOption prefOptionWithLabel:@"Warn" value:@(DDLogLevelWarning)],
62                                 [KBPrefOption prefOptionWithLabel:@"Error" value:@(DDLogLevelError)],
63                                 [KBPrefOption prefOptionWithLabel:@"Off" value:@(DDLogLevelOff)],
64                                 ];
65    [logLevel setLabelText:@"Logging" options:logLevelOptions identifier:@"Preferences.Log.Level" preferences:preferences];
66    [self addSubview:logLevel];
67  }
68  return self;
69}
70
71- (id)valueForIdentifier:(NSString *)identifier {
72  id value = [((id)[NSApp delegate]) preferencesValueForIdentifier:identifier];
73  NSAssert(value, @"Unknown preference: %@", identifier);
74  return value;
75}
76
77- (void)setValue:(id)value forIdentifier:(NSString *)identifier synchronize:(BOOL)synchronize {
78  [((id)[NSApp delegate]) setPrefencesValue:value forIdentifier:identifier synchronize:synchronize];
79}
80
81@end
82