blob: 754ec1c5575ba518f3c48ace4965bb06b699f866 [file] [log] [blame]
Alexandre Lisionbfa68f62015-09-10 08:38:42 -04001/*
2 * Copyright (C) 2015 Savoir-faire Linux Inc.
3 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#import "PreferencesWC.h"
20
21#import <QuartzCore/QuartzCore.h>
22
23#import <accountmodel.h>
24#import <audio/codecmodel.h>
25
26#import "AccountsVC.h"
27#import "GeneralPrefsVC.h"
28#import "AudioPrefsVC.h"
29#import "VideoPrefsVC.h"
30#import "Constants.h"
31
32@implementation PreferencesWC {
33
34 __unsafe_unretained IBOutlet NSView *prefsContainer;
35 NSViewController *currentVC;
36
37}
38
39static NSString* const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
40static NSString* const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
41static NSString* const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
42static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
43
44- (void)windowDidLoad
45{
46 [super windowDidLoad];
47 [self.window setMovableByWindowBackground:YES];
48 [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier];
49 [self displayGeneral:nil];
50}
51
52- (void)windowWillClose:(NSNotification *)notification
53{
54 AccountModel::instance()->save();
55}
56
57- (IBAction)displayGeneral:(NSToolbarItem *)sender
58{
59 [[prefsContainer subviews]
60 makeObjectsPerformSelector:@selector(removeFromSuperview)];
61 currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil];
62
63 [self resizeWindowWithFrame:currentVC.view.frame];
64 [prefsContainer addSubview:currentVC.view];
65}
66
67- (IBAction)displayAudio:(NSToolbarItem *)sender
68{
69 [[prefsContainer subviews]
70 makeObjectsPerformSelector:@selector(removeFromSuperview)];
71 currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil];
72 [self resizeWindowWithFrame:currentVC.view.frame];
73 [prefsContainer addSubview:currentVC.view];
74}
75
76- (IBAction)displayVideo:(NSToolbarItem *)sender
77{
78 [[prefsContainer subviews]
79 makeObjectsPerformSelector:@selector(removeFromSuperview)];
80 currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil];
81 [self resizeWindowWithFrame:currentVC.view.frame];
82 [prefsContainer addSubview:currentVC.view];
83}
84
85- (IBAction)displayAccounts:(NSToolbarItem *)sender
86{
87 [[prefsContainer subviews]
88 makeObjectsPerformSelector:@selector(removeFromSuperview)];
89 currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil];
90 [self resizeWindowWithFrame:currentVC.view.frame];
91 [prefsContainer addSubview:currentVC.view];
92}
93
94- (void) resizeWindowWithFrame:(NSRect)fr
95{
96 NSToolbar *toolbar = [self.window toolbar];
97 CGFloat toolbarHeight = 0.0;
98 NSRect windowFrame;
99
100 if (toolbar && [toolbar isVisible]) {
101 windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
102 styleMask:[self.window styleMask]];
103 toolbarHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
104 }
105
106 auto frame = [self.window frame];
107 frame.origin.y += frame.size.height;
108 frame.origin.y -= NSHeight(fr) + toolbarHeight;
109 frame.size.height = NSHeight(fr) + toolbarHeight;
110 frame.size.width = NSWidth(fr);
111
112 frame = [NSWindow frameRectForContentRect:frame
113 styleMask:[self.window styleMask]];
114
115 [self.window setFrame:frame display:YES animate:YES];
116}
117
118@end