blob: 6a9b3400ea7298b528918bdeb0112b2dd8388c3b [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>
Kateryna Kostiuk67735232018-05-10 15:05:32 -040028#import <api/datatransfermodel.h>
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040029
Alexandre Lision261f1b92016-04-04 12:35:34 -040030//Ring
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040031#import "AccountsVC.h"
32#import "GeneralPrefsVC.h"
33#import "AudioPrefsVC.h"
34#import "VideoPrefsVC.h"
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040035
36@implementation PreferencesWC {
37
38 __unsafe_unretained IBOutlet NSView *prefsContainer;
39 NSViewController *currentVC;
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040040}
41
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040042@synthesize dataTransferModel, accountModel, behaviorController;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040043
Alexandre Lision261f1b92016-04-04 12:35:34 -040044// Identifiers used in PreferencesWindow.xib for tabs
45static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
46static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
47static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
48static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040049
50- (void)windowDidLoad
51{
52 [super windowDidLoad];
53 [self.window setMovableByWindowBackground:YES];
54 [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier];
55 [self displayGeneral:nil];
56}
57
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040058-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController
Kateryna Kostiuk67735232018-05-10 15:05:32 -040059{
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040060 if (self = [self initWithWindowNibName:nibNameOrNil])
Kateryna Kostiuk67735232018-05-10 15:05:32 -040061 {
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040062 self.accountModel = accountModel;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040063 self.dataTransferModel = dataTransferModel;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040064 self.behaviorController = behaviorController;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040065 }
66 return self;
67}
68
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040069- (void)windowWillClose:(NSNotification *)notification
70{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040071 AccountModel::instance().save();
Alexandre Lision261f1b92016-04-04 12:35:34 -040072 ProfileModel::instance().selectedProfile()->save();
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040073}
74
75- (IBAction)displayGeneral:(NSToolbarItem *)sender
76{
77 [[prefsContainer subviews]
78 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040079 currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040080
81 [self resizeWindowWithFrame:currentVC.view.frame];
82 [prefsContainer addSubview:currentVC.view];
83}
84
85- (IBAction)displayAudio:(NSToolbarItem *)sender
86{
87 [[prefsContainer subviews]
88 makeObjectsPerformSelector:@selector(removeFromSuperview)];
89 currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil];
90 [self resizeWindowWithFrame:currentVC.view.frame];
91 [prefsContainer addSubview:currentVC.view];
92}
93
94- (IBAction)displayVideo:(NSToolbarItem *)sender
95{
96 [[prefsContainer subviews]
97 makeObjectsPerformSelector:@selector(removeFromSuperview)];
98 currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil];
99 [self resizeWindowWithFrame:currentVC.view.frame];
100 [prefsContainer addSubview:currentVC.view];
101}
102
103- (IBAction)displayAccounts:(NSToolbarItem *)sender
104{
105 [[prefsContainer subviews]
Kateryna Kostiuk67735232018-05-10 15:05:32 -0400106 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400107 currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil accountmodel:self.accountModel];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400108 [self resizeWindowWithFrame:currentVC.view.frame];
109 [prefsContainer addSubview:currentVC.view];
110}
111
112- (void) resizeWindowWithFrame:(NSRect)fr
113{
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400114 auto frame = [self.window frame];
115 frame.origin.y += frame.size.height;
Alexandre Lision261f1b92016-04-04 12:35:34 -0400116 frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight];
117 frame.size.height = NSHeight(fr) + [self toolBarHeight];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400118 frame.size.width = NSWidth(fr);
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400119 frame = [NSWindow frameRectForContentRect:frame
120 styleMask:[self.window styleMask]];
121
122 [self.window setFrame:frame display:YES animate:YES];
123}
124
Alexandre Lision261f1b92016-04-04 12:35:34 -0400125- (CGFloat) toolBarHeight
126{
127 NSRect windowFrame;
128 NSToolbar *toolbar = [self.window toolbar];
129 CGFloat tHeight = 0.0;
130 if (toolbar && [toolbar isVisible]) {
131
132 windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
133 styleMask:[self.window styleMask]];
134 tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
135 }
136 return tHeight;
137}
138
139- (float) titleBarHeight
140{
141 NSRect frame = NSMakeRect (0, 0, 100, 100);
142 NSRect contentRect;
143 contentRect = [NSWindow contentRectForFrameRect: frame
144 styleMask: NSTitledWindowMask];
145
146 return (frame.size.height - contentRect.size.height);
147}
148
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400149@end