Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 3 | * 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 Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 21 | |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 22 | #import <api/datatransfermodel.h> |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 23 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 24 | //Ring |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 25 | #import "GeneralPrefsVC.h" |
| 26 | #import "AudioPrefsVC.h" |
| 27 | #import "VideoPrefsVC.h" |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 28 | #import "views/NSColor+RingTheme.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 29 | |
| 30 | @implementation PreferencesWC { |
| 31 | |
| 32 | __unsafe_unretained IBOutlet NSView *prefsContainer; |
| 33 | NSViewController *currentVC; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Kateryna Kostiuk | c3fc76c | 2019-01-06 22:12:34 -0500 | [diff] [blame] | 36 | @synthesize dataTransferModel, accountModel, behaviorController, avModel; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 37 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 38 | // Identifiers used in PreferencesWindow.xib for tabs |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 39 | static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 40 | static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 41 | static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 42 | |
| 43 | - (void)windowDidLoad |
| 44 | { |
| 45 | [super windowDidLoad]; |
| 46 | [self.window setMovableByWindowBackground:YES]; |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 47 | 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 Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 52 | [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier]; |
| 53 | [self displayGeneral:nil]; |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 54 | NSToolbar *tb = [[self window] toolbar]; |
| 55 | [tb setAllowsUserCustomization:NO]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Kateryna Kostiuk | c3fc76c | 2019-01-06 22:12:34 -0500 | [diff] [blame] | 58 | -(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 Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 59 | { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 60 | if (self = [self initWithWindowNibName:nibNameOrNil]) |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 61 | { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 62 | self.accountModel = accountModel; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 63 | self.dataTransferModel = dataTransferModel; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 64 | self.behaviorController = behaviorController; |
Kateryna Kostiuk | c3fc76c | 2019-01-06 22:12:34 -0500 | [diff] [blame] | 65 | self.avModel = avModel; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 66 | } |
| 67 | return self; |
| 68 | } |
| 69 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 70 | - (IBAction)displayGeneral:(NSToolbarItem *)sender |
| 71 | { |
| 72 | [[prefsContainer subviews] |
| 73 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
Kateryna Kostiuk | 6db5280 | 2019-08-12 17:56:38 -0400 | [diff] [blame] | 74 | currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel avModel: self.avModel]; |
Kateryna Kostiuk | 99eff4f | 2020-12-04 09:59:10 -0500 | [diff] [blame^] | 75 | [self addCurrentVC]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | - (IBAction)displayAudio:(NSToolbarItem *)sender |
| 79 | { |
| 80 | [[prefsContainer subviews] |
| 81 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 82 | currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil avModel: self.avModel]; |
Kateryna Kostiuk | 99eff4f | 2020-12-04 09:59:10 -0500 | [diff] [blame^] | 83 | [self addCurrentVC]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | - (IBAction)displayVideo:(NSToolbarItem *)sender |
| 87 | { |
| 88 | [[prefsContainer subviews] |
| 89 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
Kateryna Kostiuk | c3fc76c | 2019-01-06 22:12:34 -0500 | [diff] [blame] | 90 | currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil avModel: self.avModel]; |
Kateryna Kostiuk | 99eff4f | 2020-12-04 09:59:10 -0500 | [diff] [blame^] | 91 | [self addCurrentVC]; |
| 92 | } |
| 93 | |
| 94 | -(void) addCurrentVC { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 95 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 96 | [prefsContainer addSubview:currentVC.view]; |
Kateryna Kostiuk | 99eff4f | 2020-12-04 09:59:10 -0500 | [diff] [blame^] | 97 | 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 Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 112 | - (void) resizeWindowWithFrame:(NSRect)fr |
| 113 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 114 | auto frame = [self.window frame]; |
| 115 | frame.origin.y += frame.size.height; |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 116 | frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight]; |
| 117 | frame.size.height = NSHeight(fr) + [self toolBarHeight]; |
Kateryna Kostiuk | 99eff4f | 2020-12-04 09:59:10 -0500 | [diff] [blame^] | 118 | if (frame.size.width < NSWidth(fr)) { |
| 119 | frame.size.width = NSWidth(fr); |
| 120 | } |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 121 | frame = [NSWindow frameRectForContentRect:frame |
| 122 | styleMask:[self.window styleMask]]; |
| 123 | |
| 124 | [self.window setFrame:frame display:YES animate:YES]; |
| 125 | } |
| 126 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 127 | - (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 Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 151 | @end |