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 "GeneralPrefsVC.h" |
| 32 | #import "AudioPrefsVC.h" |
| 33 | #import "VideoPrefsVC.h" |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 34 | #import "views/NSColor+RingTheme.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 |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 45 | static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 46 | static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 47 | static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 48 | |
| 49 | - (void)windowDidLoad |
| 50 | { |
| 51 | [super windowDidLoad]; |
| 52 | [self.window setMovableByWindowBackground:YES]; |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 53 | NSArray *items = [self.window.toolbar items]; |
| 54 | for(NSToolbarItem *toolbarItem in items) { |
| 55 | NSImage * image = [NSColor image: [toolbarItem image] tintedWithColor: [NSColor secondaryLabelColor]]; |
| 56 | toolbarItem.image = image; |
| 57 | } |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 58 | [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier]; |
| 59 | [self displayGeneral:nil]; |
| 60 | } |
| 61 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 62 | -(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] | 63 | { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 64 | if (self = [self initWithWindowNibName:nibNameOrNil]) |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 65 | { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 66 | self.accountModel = accountModel; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 67 | self.dataTransferModel = dataTransferModel; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 68 | self.behaviorController = behaviorController; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 69 | } |
| 70 | return self; |
| 71 | } |
| 72 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 73 | - (IBAction)displayGeneral:(NSToolbarItem *)sender |
| 74 | { |
| 75 | [[prefsContainer subviews] |
| 76 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 77 | currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 78 | |
| 79 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 80 | [prefsContainer addSubview:currentVC.view]; |
| 81 | } |
| 82 | |
| 83 | - (IBAction)displayAudio:(NSToolbarItem *)sender |
| 84 | { |
| 85 | [[prefsContainer subviews] |
| 86 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 87 | currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 88 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 89 | [prefsContainer addSubview:currentVC.view]; |
| 90 | } |
| 91 | |
| 92 | - (IBAction)displayVideo:(NSToolbarItem *)sender |
| 93 | { |
| 94 | [[prefsContainer subviews] |
| 95 | makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
| 96 | currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil]; |
| 97 | [self resizeWindowWithFrame:currentVC.view.frame]; |
| 98 | [prefsContainer addSubview:currentVC.view]; |
| 99 | } |
| 100 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 101 | - (void) resizeWindowWithFrame:(NSRect)fr |
| 102 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 103 | auto frame = [self.window frame]; |
| 104 | frame.origin.y += frame.size.height; |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 105 | frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight]; |
| 106 | frame.size.height = NSHeight(fr) + [self toolBarHeight]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 107 | frame.size.width = NSWidth(fr); |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 108 | frame = [NSWindow frameRectForContentRect:frame |
| 109 | styleMask:[self.window styleMask]]; |
| 110 | |
| 111 | [self.window setFrame:frame display:YES animate:YES]; |
| 112 | } |
| 113 | |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 114 | - (CGFloat) toolBarHeight |
| 115 | { |
| 116 | NSRect windowFrame; |
| 117 | NSToolbar *toolbar = [self.window toolbar]; |
| 118 | CGFloat tHeight = 0.0; |
| 119 | if (toolbar && [toolbar isVisible]) { |
| 120 | |
| 121 | windowFrame = [NSWindow contentRectForFrameRect:[self.window frame] |
| 122 | styleMask:[self.window styleMask]]; |
| 123 | tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]); |
| 124 | } |
| 125 | return tHeight; |
| 126 | } |
| 127 | |
| 128 | - (float) titleBarHeight |
| 129 | { |
| 130 | NSRect frame = NSMakeRect (0, 0, 100, 100); |
| 131 | NSRect contentRect; |
| 132 | contentRect = [NSWindow contentRectForFrameRect: frame |
| 133 | styleMask: NSTitledWindowMask]; |
| 134 | |
| 135 | return (frame.size.height - contentRect.size.height); |
| 136 | } |
| 137 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 138 | @end |