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 | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 74 | currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 75 | |
| 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)]; |
| 84 | currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 85 | [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 Kostiuk | c3fc76c | 2019-01-06 22:12:34 -0500 | [diff] [blame] | 93 | currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil avModel: self.avModel]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 94 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 95 | [prefsContainer addSubview:currentVC.view]; |
| 96 | } |
| 97 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 98 | - (void) resizeWindowWithFrame:(NSRect)fr |
| 99 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 100 | auto frame = [self.window frame]; |
| 101 | frame.origin.y += frame.size.height; |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 102 | frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight]; |
| 103 | frame.size.height = NSHeight(fr) + [self toolBarHeight]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 104 | frame.size.width = NSWidth(fr); |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 105 | frame = [NSWindow frameRectForContentRect:frame |
| 106 | styleMask:[self.window styleMask]]; |
| 107 | |
| 108 | [self.window setFrame:frame display:YES animate:YES]; |
| 109 | } |
| 110 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 111 | - (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 Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 135 | @end |