blob: 6bb635a4a11be0e02416d6a30f34a20c5af28ed5 [file] [log] [blame]
Alexandre Lisionbfa68f62015-09-10 08:38:42 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lisionbfa68f62015-09-10 08:38:42 -04003 * 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
Alexandre Lision261f1b92016-04-04 12:35:34 -040023//LRC
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040024#import <accountmodel.h>
Edric Milaretea245cd2016-03-21 12:19:39 -040025#import <codecmodel.h>
Alexandre Lision261f1b92016-04-04 12:35:34 -040026#import <profilemodel.h>
27#import <profile.h>
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040028
Alexandre Lision261f1b92016-04-04 12:35:34 -040029//Ring
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040030#import "AccountsVC.h"
31#import "GeneralPrefsVC.h"
32#import "AudioPrefsVC.h"
33#import "VideoPrefsVC.h"
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040034
35@implementation PreferencesWC {
36
37 __unsafe_unretained IBOutlet NSView *prefsContainer;
38 NSViewController *currentVC;
39
40}
41
Alexandre Lision261f1b92016-04-04 12:35:34 -040042// Identifiers used in PreferencesWindow.xib for tabs
43static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
44static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
45static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
46static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040047
48- (void)windowDidLoad
49{
50 [super windowDidLoad];
51 [self.window setMovableByWindowBackground:YES];
52 [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier];
53 [self displayGeneral:nil];
54}
55
56- (void)windowWillClose:(NSNotification *)notification
57{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040058 AccountModel::instance().save();
Alexandre Lision261f1b92016-04-04 12:35:34 -040059 ProfileModel::instance().selectedProfile()->save();
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040060}
61
62- (IBAction)displayGeneral:(NSToolbarItem *)sender
63{
64 [[prefsContainer subviews]
65 makeObjectsPerformSelector:@selector(removeFromSuperview)];
66 currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil];
67
68 [self resizeWindowWithFrame:currentVC.view.frame];
69 [prefsContainer addSubview:currentVC.view];
70}
71
72- (IBAction)displayAudio:(NSToolbarItem *)sender
73{
74 [[prefsContainer subviews]
75 makeObjectsPerformSelector:@selector(removeFromSuperview)];
76 currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil];
77 [self resizeWindowWithFrame:currentVC.view.frame];
78 [prefsContainer addSubview:currentVC.view];
79}
80
81- (IBAction)displayVideo:(NSToolbarItem *)sender
82{
83 [[prefsContainer subviews]
84 makeObjectsPerformSelector:@selector(removeFromSuperview)];
85 currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil];
86 [self resizeWindowWithFrame:currentVC.view.frame];
87 [prefsContainer addSubview:currentVC.view];
88}
89
90- (IBAction)displayAccounts:(NSToolbarItem *)sender
91{
92 [[prefsContainer subviews]
93 makeObjectsPerformSelector:@selector(removeFromSuperview)];
94 currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil];
95 [self resizeWindowWithFrame:currentVC.view.frame];
96 [prefsContainer addSubview:currentVC.view];
97}
98
99- (void) resizeWindowWithFrame:(NSRect)fr
100{
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400101 auto frame = [self.window frame];
102 frame.origin.y += frame.size.height;
Alexandre Lision261f1b92016-04-04 12:35:34 -0400103 frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight];
104 frame.size.height = NSHeight(fr) + [self toolBarHeight];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400105 frame.size.width = NSWidth(fr);
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400106 frame = [NSWindow frameRectForContentRect:frame
107 styleMask:[self.window styleMask]];
108
109 [self.window setFrame:frame display:YES animate:YES];
110}
111
Alexandre Lision261f1b92016-04-04 12:35:34 -0400112- (CGFloat) toolBarHeight
113{
114 NSRect windowFrame;
115 NSToolbar *toolbar = [self.window toolbar];
116 CGFloat tHeight = 0.0;
117 if (toolbar && [toolbar isVisible]) {
118
119 windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
120 styleMask:[self.window styleMask]];
121 tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
122 }
123 return tHeight;
124}
125
126- (float) titleBarHeight
127{
128 NSRect frame = NSMakeRect (0, 0, 100, 100);
129 NSRect contentRect;
130 contentRect = [NSWindow contentRectForFrameRect: frame
131 styleMask: NSTitledWindowMask];
132
133 return (frame.size.height - contentRect.size.height);
134}
135
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400136@end