blob: a65cdfd6216ce97fe8bd990851d525f320894824 [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
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040021
Kateryna Kostiuk67735232018-05-10 15:05:32 -040022#import <api/datatransfermodel.h>
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040023
Alexandre Lision261f1b92016-04-04 12:35:34 -040024//Ring
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040025#import "GeneralPrefsVC.h"
26#import "AudioPrefsVC.h"
27#import "VideoPrefsVC.h"
Kateryna Kostiuk394f74c2018-10-05 15:45:26 -040028#import "views/NSColor+RingTheme.h"
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040029
30@implementation PreferencesWC {
31
32 __unsafe_unretained IBOutlet NSView *prefsContainer;
33 NSViewController *currentVC;
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040034}
35
Kateryna Kostiukc3fc76c2019-01-06 22:12:34 -050036@synthesize dataTransferModel, accountModel, behaviorController, avModel;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040037
Alexandre Lision261f1b92016-04-04 12:35:34 -040038// Identifiers used in PreferencesWindow.xib for tabs
Alexandre Lision261f1b92016-04-04 12:35:34 -040039static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
40static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
41static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040042
43- (void)windowDidLoad
44{
45 [super windowDidLoad];
46 [self.window setMovableByWindowBackground:YES];
Kateryna Kostiuk394f74c2018-10-05 15:45:26 -040047 NSArray *items = [self.window.toolbar items];
48 for(NSToolbarItem *toolbarItem in items) {
49 NSImage * image = [NSColor image: [toolbarItem image] tintedWithColor: [NSColor secondaryLabelColor]];
50 toolbarItem.image = image;
51 }
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040052 [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier];
53 [self displayGeneral:nil];
Kateryna Kostiukef66f972018-11-02 17:10:37 -040054 NSToolbar *tb = [[self window] toolbar];
55 [tb setAllowsUserCustomization:NO];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040056}
57
Kateryna Kostiukc3fc76c2019-01-06 22:12:34 -050058-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(lrc::api::NewAccountModel*)accountModel dataTransferModel:(lrc::api::DataTransferModel*)dataTransferModel behaviourController:(lrc::api::BehaviorController*) behaviorController avModel: (lrc::api::AVModel*)avModel
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 Kostiukc3fc76c2019-01-06 22:12:34 -050065 self.avModel = avModel;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040066 }
67 return self;
68}
69
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040070- (IBAction)displayGeneral:(NSToolbarItem *)sender
71{
72 [[prefsContainer subviews]
73 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiuk6db52802019-08-12 17:56:38 -040074 currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel avModel: self.avModel];
Kateryna Kostiuk99eff4f2020-12-04 09:59:10 -050075 [self addCurrentVC];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040076}
77
78- (IBAction)displayAudio:(NSToolbarItem *)sender
79{
80 [[prefsContainer subviews]
81 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040082 currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil avModel: self.avModel];
Kateryna Kostiuk99eff4f2020-12-04 09:59:10 -050083 [self addCurrentVC];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040084}
85
86- (IBAction)displayVideo:(NSToolbarItem *)sender
87{
88 [[prefsContainer subviews]
89 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiukc3fc76c2019-01-06 22:12:34 -050090 currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil avModel: self.avModel];
Kateryna Kostiuk99eff4f2020-12-04 09:59:10 -050091 [self addCurrentVC];
92}
93
94-(void) addCurrentVC {
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040095 [self resizeWindowWithFrame:currentVC.view.frame];
96 [prefsContainer addSubview:currentVC.view];
Kateryna Kostiuk99eff4f2020-12-04 09:59:10 -050097 currentVC.view.translatesAutoresizingMaskIntoConstraints = false;
98 [NSLayoutConstraint constraintWithItem:currentVC.view
99 attribute:NSLayoutAttributeCenterX
100 relatedBy:NSLayoutRelationEqual toItem: prefsContainer
101 attribute:NSLayoutAttributeCenterX
102 multiplier:1 constant:0].active = YES;
103 [NSLayoutConstraint constraintWithItem:currentVC.view
104 attribute:NSLayoutAttributeTop
105 relatedBy:NSLayoutRelationEqual
106 toItem:prefsContainer
107 attribute:NSLayoutAttributeTop
108 multiplier:1
109 constant:0].active = YES;
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400110}
111
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400112- (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];
Kateryna Kostiuk99eff4f2020-12-04 09:59:10 -0500118 if (frame.size.width < NSWidth(fr)) {
119 frame.size.width = NSWidth(fr);
120 }
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400121 frame = [NSWindow frameRectForContentRect:frame
122 styleMask:[self.window styleMask]];
123
124 [self.window setFrame:frame display:YES animate:YES];
125}
126
Alexandre Lision261f1b92016-04-04 12:35:34 -0400127- (CGFloat) toolBarHeight
128{
129 NSRect windowFrame;
130 NSToolbar *toolbar = [self.window toolbar];
131 CGFloat tHeight = 0.0;
132 if (toolbar && [toolbar isVisible]) {
133
134 windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
135 styleMask:[self.window styleMask]];
136 tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
137 }
138 return tHeight;
139}
140
141- (float) titleBarHeight
142{
143 NSRect frame = NSMakeRect (0, 0, 100, 100);
144 NSRect contentRect;
145 contentRect = [NSWindow contentRectForFrameRect: frame
146 styleMask: NSTitledWindowMask];
147
148 return (frame.size.height - contentRect.size.height);
149}
150
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400151@end