VLCSettingsController.m 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*****************************************************************************
 * VLCSettingsController.m
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2013 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Gleb Pinigin <gpinigin # gmail.com>
 *          Carola Nitz <nitz.carola # googlemail.com>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
Felix Paul Kühne's avatar
Felix Paul Kühne committed
14

15
#import "VLCSettingsController.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
16
#import "VLCAppDelegate.h"
17
#import "VLCPlaylistViewController.h"
18
#import "IASKSettingsReader.h"
19 20
#import "IASKAppSettingsViewController.h"
#import "PAPasscodeViewController.h"
21

22
@interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
23
{
24

25
}
26 27
@end

28
@implementation VLCSettingsController
Felix Paul Kühne's avatar
Felix Paul Kühne committed
29

30
- (id)init
Felix Paul Kühne's avatar
Felix Paul Kühne committed
31
{
32 33 34 35
    self = [super init];
    if (self)
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];

Felix Paul Kühne's avatar
Felix Paul Kühne committed
36 37 38
    return self;
}

39
- (void)dealloc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
40
{
41
    [[NSNotificationCenter defaultCenter] removeObserver:self];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
42 43
}

44
- (void)settingDidChange:(NSNotification*)notification
45
{
46
    if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
47
        BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
48

49 50 51
        if (passcodeOn) {
            PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
            passcodeLockController.delegate = self;
52
            [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
53 54
        }
    }
55 56
}

57 58
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
{
59
    [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
60 61
}

62 63 64 65
#pragma mark - PAPasscode delegate

- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
66 67 68
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
    [defaults synchronize];
69
    [controller dismissViewControllerAnimated:YES completion:nil];
70 71 72 73 74
}

- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
75
    [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
76 77
    [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
    [defaults synchronize];
78

79
    [controller dismissViewControllerAnimated:YES completion:nil];
80 81
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
82
@end