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> |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 28 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 29 | //Ring |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 30 | #import "AccountsVC.h" |
| 31 | #import "GeneralPrefsVC.h" |
| 32 | #import "AudioPrefsVC.h" |
| 33 | #import "VideoPrefsVC.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 34 | |
| 35 | @implementation PreferencesWC { |
| 36 | |
| 37 | __unsafe_unretained IBOutlet NSView *prefsContainer; |
| 38 | NSViewController *currentVC; |
| 39 | |
| 40 | } |
| 41 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 42 | // Identifiers used in PreferencesWindow.xib for tabs |
| 43 | static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier"; |
| 44 | static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 45 | static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 46 | static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 47 | |
| 48 | - (void)windowDidLoad |
| 49 | { |
| 50 | [super windowDidLoad]; |
| 51 | [self.window setMovableByWindowBackground:YES]; |
| 52 | [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier]; |
| 53 | [self displayGeneral:nil]; |
| 54 | } |
| 55 | |
| 56 | - (void)windowWillClose:(NSNotification *)notification |
| 57 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 58 | AccountModel::instance().save(); |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 59 | ProfileModel::instance().selectedProfile()->save(); |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | - (IBAction)displayGeneral:(NSToolbarItem *)sender |
| 63 | { |
| 64 | [[prefsContainer subviews] |
| 65 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 66 | currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil]; |
| 67 | |
| 68 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 69 | [prefsContainer addSubview:currentVC.view]; |
| 70 | } |
| 71 | |
| 72 | - (IBAction)displayAudio:(NSToolbarItem *)sender |
| 73 | { |
| 74 | [[prefsContainer subviews] |
| 75 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 76 | currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 77 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 78 | [prefsContainer addSubview:currentVC.view]; |
| 79 | } |
| 80 | |
| 81 | - (IBAction)displayVideo:(NSToolbarItem *)sender |
| 82 | { |
| 83 | [[prefsContainer subviews] |
| 84 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 85 | currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil]; |
| 86 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 87 | [prefsContainer addSubview:currentVC.view]; |
| 88 | } |
| 89 | |
| 90 | - (IBAction)displayAccounts:(NSToolbarItem *)sender |
| 91 | { |
| 92 | [[prefsContainer subviews] |
| 93 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 94 | currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil]; |
| 95 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 96 | [prefsContainer addSubview:currentVC.view]; |
| 97 | } |
| 98 | |
| 99 | - (void) resizeWindowWithFrame:(NSRect)fr |
| 100 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 101 | auto frame = [self.window frame]; |
| 102 | frame.origin.y += frame.size.height; |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 103 | frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight]; |
| 104 | frame.size.height = NSHeight(fr) + [self toolBarHeight]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 105 | frame.size.width = NSWidth(fr); |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 106 | frame = [NSWindow frameRectForContentRect:frame |
| 107 | styleMask:[self.window styleMask]]; |
| 108 | |
| 109 | [self.window setFrame:frame display:YES animate:YES]; |
| 110 | } |
| 111 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 112 | - (CGFloat) toolBarHeight |
| 113 | { |
| 114 | NSRect windowFrame; |
| 115 | NSToolbar *toolbar = [self.window toolbar]; |
| 116 | CGFloat tHeight = 0.0; |
| 117 | if (toolbar && [toolbar isVisible]) { |
| 118 | |
| 119 | windowFrame = [NSWindow contentRectForFrameRect:[self.window frame] |
| 120 | styleMask:[self.window styleMask]]; |
| 121 | tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]); |
| 122 | } |
| 123 | return tHeight; |
| 124 | } |
| 125 | |
| 126 | - (float) titleBarHeight |
| 127 | { |
| 128 | NSRect frame = NSMakeRect (0, 0, 100, 100); |
| 129 | NSRect contentRect; |
| 130 | contentRect = [NSWindow contentRectForFrameRect: frame |
| 131 | styleMask: NSTitledWindowMask]; |
| 132 | |
| 133 | return (frame.size.height - contentRect.size.height); |
| 134 | } |
| 135 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 136 | @end |