blob: 8556ffe5c8a094b942ae5c15cbeace6dd49302e4 [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 "GeneralPrefsVC.h"
32#import "AudioPrefsVC.h"
33#import "VideoPrefsVC.h"
Kateryna Kostiuk394f74c2018-10-05 15:45:26 -040034#import "views/NSColor+RingTheme.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
Alexandre Lision261f1b92016-04-04 12:35:34 -040045static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
46static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
47static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040048
49- (void)windowDidLoad
50{
51 [super windowDidLoad];
52 [self.window setMovableByWindowBackground:YES];
Kateryna Kostiuk394f74c2018-10-05 15:45:26 -040053 NSArray *items = [self.window.toolbar items];
54 for(NSToolbarItem *toolbarItem in items) {
55 NSImage * image = [NSColor image: [toolbarItem image] tintedWithColor: [NSColor secondaryLabelColor]];
56 toolbarItem.image = image;
57 }
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040058 [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier];
59 [self displayGeneral:nil];
60}
61
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040062-(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 -040063{
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040064 if (self = [self initWithWindowNibName:nibNameOrNil])
Kateryna Kostiuk67735232018-05-10 15:05:32 -040065 {
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040066 self.accountModel = accountModel;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040067 self.dataTransferModel = dataTransferModel;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040068 self.behaviorController = behaviorController;
Kateryna Kostiuk67735232018-05-10 15:05:32 -040069 }
70 return self;
71}
72
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040073- (IBAction)displayGeneral:(NSToolbarItem *)sender
74{
75 [[prefsContainer subviews]
76 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040077 currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040078
79 [self resizeWindowWithFrame:currentVC.view.frame];
80 [prefsContainer addSubview:currentVC.view];
81}
82
83- (IBAction)displayAudio:(NSToolbarItem *)sender
84{
85 [[prefsContainer subviews]
86 makeObjectsPerformSelector:@selector(removeFromSuperview)];
87 currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil];
88 [self resizeWindowWithFrame:currentVC.view.frame];
89 [prefsContainer addSubview:currentVC.view];
90}
91
92- (IBAction)displayVideo:(NSToolbarItem *)sender
93{
94 [[prefsContainer subviews]
95 makeObjectsPerformSelector:@selector(removeFromSuperview)];
96 currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil];
97 [self resizeWindowWithFrame:currentVC.view.frame];
98 [prefsContainer addSubview:currentVC.view];
99}
100
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400101- (void) resizeWindowWithFrame:(NSRect)fr
102{
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400103 auto frame = [self.window frame];
104 frame.origin.y += frame.size.height;
Alexandre Lision261f1b92016-04-04 12:35:34 -0400105 frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight];
106 frame.size.height = NSHeight(fr) + [self toolBarHeight];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400107 frame.size.width = NSWidth(fr);
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400108 frame = [NSWindow frameRectForContentRect:frame
109 styleMask:[self.window styleMask]];
110
111 [self.window setFrame:frame display:YES animate:YES];
112}
113
Alexandre Lision261f1b92016-04-04 12:35:34 -0400114- (CGFloat) toolBarHeight
115{
116 NSRect windowFrame;
117 NSToolbar *toolbar = [self.window toolbar];
118 CGFloat tHeight = 0.0;
119 if (toolbar && [toolbar isVisible]) {
120
121 windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
122 styleMask:[self.window styleMask]];
123 tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
124 }
125 return tHeight;
126}
127
128- (float) titleBarHeight
129{
130 NSRect frame = NSMakeRect (0, 0, 100, 100);
131 NSRect contentRect;
132 contentRect = [NSWindow contentRectForFrameRect: frame
133 styleMask: NSTitledWindowMask];
134
135 return (frame.size.height - contentRect.size.height);
136}
137
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400138@end