blob: ca6426c0da95d0d2f73472c4a1acf3de364e90de [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];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040075
76 [self resizeWindowWithFrame:currentVC.view.frame];
77 [prefsContainer addSubview:currentVC.view];
78}
79
80- (IBAction)displayAudio:(NSToolbarItem *)sender
81{
82 [[prefsContainer subviews]
83 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040084 currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil avModel: self.avModel];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040085 [self resizeWindowWithFrame:currentVC.view.frame];
86 [prefsContainer addSubview:currentVC.view];
87}
88
89- (IBAction)displayVideo:(NSToolbarItem *)sender
90{
91 [[prefsContainer subviews]
92 makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiukc3fc76c2019-01-06 22:12:34 -050093 currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil avModel: self.avModel];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040094 [self resizeWindowWithFrame:currentVC.view.frame];
95 [prefsContainer addSubview:currentVC.view];
96}
97
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040098- (void) resizeWindowWithFrame:(NSRect)fr
99{
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400100 auto frame = [self.window frame];
101 frame.origin.y += frame.size.height;
Alexandre Lision261f1b92016-04-04 12:35:34 -0400102 frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight];
103 frame.size.height = NSHeight(fr) + [self toolBarHeight];
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400104 frame.size.width = NSWidth(fr);
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400105 frame = [NSWindow frameRectForContentRect:frame
106 styleMask:[self.window styleMask]];
107
108 [self.window setFrame:frame display:YES animate:YES];
109}
110
Alexandre Lision261f1b92016-04-04 12:35:34 -0400111- (CGFloat) toolBarHeight
112{
113 NSRect windowFrame;
114 NSToolbar *toolbar = [self.window toolbar];
115 CGFloat tHeight = 0.0;
116 if (toolbar && [toolbar isVisible]) {
117
118 windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
119 styleMask:[self.window styleMask]];
120 tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
121 }
122 return tHeight;
123}
124
125- (float) titleBarHeight
126{
127 NSRect frame = NSMakeRect (0, 0, 100, 100);
128 NSRect contentRect;
129 contentRect = [NSWindow contentRectForFrameRect: frame
130 styleMask: NSTitledWindowMask];
131
132 return (frame.size.height - contentRect.size.height);
133}
134
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400135@end