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 | |
| 21 | #import <QuartzCore/QuartzCore.h> |
| 22 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 23 | //LRC |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 24 | #import <accountmodel.h> |
Edric Milaret | ea245cd | 2016-03-21 12:19:39 -0400 | [diff] [blame] | 25 | #import <codecmodel.h> |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 26 | #import <profilemodel.h> |
| 27 | #import <profile.h> |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 28 | #import <api/datatransfermodel.h> |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 29 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 30 | //Ring |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 31 | #import "AccountsVC.h" |
| 32 | #import "GeneralPrefsVC.h" |
| 33 | #import "AudioPrefsVC.h" |
| 34 | #import "VideoPrefsVC.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 35 | |
| 36 | @implementation PreferencesWC { |
| 37 | |
| 38 | __unsafe_unretained IBOutlet NSView *prefsContainer; |
| 39 | NSViewController *currentVC; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame^] | 42 | @synthesize dataTransferModel, accountModel, behaviorController; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 43 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 44 | // Identifiers used in PreferencesWindow.xib for tabs |
| 45 | static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier"; |
| 46 | static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 47 | static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 48 | static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 49 | |
| 50 | - (void)windowDidLoad |
| 51 | { |
| 52 | [super windowDidLoad]; |
| 53 | [self.window setMovableByWindowBackground:YES]; |
| 54 | [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier]; |
| 55 | [self displayGeneral:nil]; |
| 56 | } |
| 57 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [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 |
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 | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 65 | } |
| 66 | return self; |
| 67 | } |
| 68 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 69 | - (void)windowWillClose:(NSNotification *)notification |
| 70 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 71 | AccountModel::instance().save(); |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 72 | ProfileModel::instance().selectedProfile()->save(); |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | - (IBAction)displayGeneral:(NSToolbarItem *)sender |
| 76 | { |
| 77 | [[prefsContainer subviews] |
| 78 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame^] | 79 | currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 80 | |
| 81 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 82 | [prefsContainer addSubview:currentVC.view]; |
| 83 | } |
| 84 | |
| 85 | - (IBAction)displayAudio:(NSToolbarItem *)sender |
| 86 | { |
| 87 | [[prefsContainer subviews] |
| 88 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 89 | currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 90 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 91 | [prefsContainer addSubview:currentVC.view]; |
| 92 | } |
| 93 | |
| 94 | - (IBAction)displayVideo:(NSToolbarItem *)sender |
| 95 | { |
| 96 | [[prefsContainer subviews] |
| 97 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 98 | currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil]; |
| 99 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 100 | [prefsContainer addSubview:currentVC.view]; |
| 101 | } |
| 102 | |
| 103 | - (IBAction)displayAccounts:(NSToolbarItem *)sender |
| 104 | { |
| 105 | [[prefsContainer subviews] |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 106 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame^] | 107 | currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil accountmodel:self.accountModel]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 108 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 109 | [prefsContainer addSubview:currentVC.view]; |
| 110 | } |
| 111 | |
| 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]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 118 | frame.size.width = NSWidth(fr); |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 119 | frame = [NSWindow frameRectForContentRect:frame |
| 120 | styleMask:[self.window styleMask]]; |
| 121 | |
| 122 | [self.window setFrame:frame display:YES animate:YES]; |
| 123 | } |
| 124 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 125 | - (CGFloat) toolBarHeight |
| 126 | { |
| 127 | NSRect windowFrame; |
| 128 | NSToolbar *toolbar = [self.window toolbar]; |
| 129 | CGFloat tHeight = 0.0; |
| 130 | if (toolbar && [toolbar isVisible]) { |
| 131 | |
| 132 | windowFrame = [NSWindow contentRectForFrameRect:[self.window frame] |
| 133 | styleMask:[self.window styleMask]]; |
| 134 | tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]); |
| 135 | } |
| 136 | return tHeight; |
| 137 | } |
| 138 | |
| 139 | - (float) titleBarHeight |
| 140 | { |
| 141 | NSRect frame = NSMakeRect (0, 0, 100, 100); |
| 142 | NSRect contentRect; |
| 143 | contentRect = [NSWindow contentRectForFrameRect: frame |
| 144 | styleMask: NSTitledWindowMask]; |
| 145 | |
| 146 | return (frame.size.height - contentRect.size.height); |
| 147 | } |
| 148 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 149 | @end |