Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 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 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 30 | #import "PreferencesVC.h" |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 31 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 32 | #import <QuartzCore/QuartzCore.h> |
| 33 | |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 34 | #import <accountmodel.h> |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 35 | #import <audio/codecmodel.h> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 36 | |
| 37 | #import "AccountsVC.h" |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 38 | #import "GeneralPrefsVC.h" |
| 39 | #import "AudioPrefsVC.h" |
| 40 | #import "VideoPrefsVC.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 41 | #import "Constants.h" |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 42 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 43 | @interface PreferencesVC () |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 44 | |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 45 | @property NSButton* toggleAdvancedSettings; |
| 46 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 47 | @end |
| 48 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 49 | @implementation PreferencesVC |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 50 | @synthesize toggleAdvancedSettings; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 51 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 52 | static NSString* const kProfilePrefsIdentifier = @"ProfilesPrefsIdentifier"; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 53 | static NSString* const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 54 | static NSString* const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 55 | static NSString* const kAncragePrefsIdentifer = @"AncragePrefsIdentifer"; |
| 56 | static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
| 57 | static NSString* const kDonePrefsIdentifer = @"DonePrefsIdentifer"; |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 58 | static NSString* const kPowerSettingsIdentifer = @"PowerSettingsIdentifer"; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 59 | |
| 60 | -(void)loadView |
| 61 | { |
| 62 | [super loadView]; |
| 63 | |
| 64 | [self displayGeneral:nil]; |
| 65 | |
| 66 | [self.view setWantsLayer:YES]; |
| 67 | self.view.layer.backgroundColor = [NSColor windowBackgroundColor].CGColor; |
| 68 | |
| 69 | // Set the layer redraw policy. This would be better done in |
| 70 | // the initialization method of a NSView subclass instead of here. |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 71 | self.view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 72 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 73 | [self.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 74 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 75 | CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height); |
| 76 | |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 77 | [CATransaction begin]; |
| 78 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"]; |
| 79 | animation.fromValue = @(frame.origin.y); |
| 80 | animation.toValue = @(self.view.frame.origin.y); |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 81 | animation.duration = 0.3f; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 82 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 83 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 84 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 85 | [CATransaction commit]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | - (void) close |
| 89 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 90 | AccountModel::instance()->save(); |
| 91 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 92 | CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height); |
| 93 | |
| 94 | [CATransaction begin]; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 95 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"]; |
| 96 | animation.fromValue = @(self.view.frame.origin.y); |
| 97 | animation.toValue = @(frame.origin.y); |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 98 | animation.duration = 0.3f; |
| 99 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 100 | |
| 101 | [CATransaction setCompletionBlock:^{ |
| 102 | [self.view removeFromSuperview]; |
| 103 | }]; |
| 104 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 105 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 106 | |
| 107 | // set final layer position to prevent glitching back to original one |
| 108 | [self.view.layer setPosition:frame.origin];; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 109 | [CATransaction commit]; |
| 110 | } |
| 111 | |
| 112 | - (void)displayGeneral:(NSToolbarItem *)sender { |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 113 | if (self.currentVC != nil) { |
| 114 | [self.currentVC.view removeFromSuperview]; |
| 115 | } |
| 116 | self.generalPrefsVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil]; |
| 117 | [self.view addSubview:self.generalPrefsVC.view]; |
| 118 | [self.generalPrefsVC.view setFrame:[self.view bounds]]; |
| 119 | self.currentVC = self.generalPrefsVC; |
| 120 | } |
| 121 | |
| 122 | - (void)displayAudio:(NSToolbarItem *)sender { |
| 123 | if (self.currentVC != nil) { |
| 124 | [self.currentVC.view removeFromSuperview]; |
| 125 | } |
| 126 | self.audioPrefsVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 127 | [self.view addSubview:self.audioPrefsVC.view]; |
| 128 | [self.audioPrefsVC.view setFrame:[self.view bounds]]; |
| 129 | self.currentVC = self.audioPrefsVC; |
| 130 | } |
| 131 | |
| 132 | - (void)displayAncrage:(NSToolbarItem *)sender { |
| 133 | |
| 134 | } |
| 135 | |
| 136 | - (void)displayVideo:(NSToolbarItem *)sender { |
| 137 | if (self.currentVC != nil) { |
| 138 | [self.currentVC.view removeFromSuperview]; |
| 139 | } |
| 140 | self.videoPrefsVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil]; |
| 141 | [self.view addSubview:self.videoPrefsVC.view]; |
| 142 | [self.videoPrefsVC.view setFrame:[self.view bounds]]; |
| 143 | self.currentVC = self.videoPrefsVC; |
| 144 | } |
| 145 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 146 | - (void) displayAccounts:(NSToolbarItem *) sender { |
| 147 | if (self.currentVC != nil) { |
| 148 | [self.currentVC.view removeFromSuperview]; |
| 149 | } |
| 150 | self.accountsPrefsVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil]; |
| 151 | [self.view addSubview:self.accountsPrefsVC.view]; |
| 152 | [self.accountsPrefsVC.view setFrame:[self.view bounds]]; |
| 153 | self.currentVC = self.accountsPrefsVC; |
| 154 | } |
| 155 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 156 | |
| 157 | #pragma NSToolbar Delegate |
| 158 | |
| 159 | -(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag |
| 160 | { |
| 161 | NSToolbarItem* item = nil; |
| 162 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 163 | if ([itemIdentifier isEqualToString: kProfilePrefsIdentifier]) { |
| 164 | |
| 165 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kProfilePrefsIdentifier]; |
| 166 | [item setImage: [NSImage imageNamed: @"NSUserAccounts"]]; |
| 167 | [item setLabel: @"Accounts"]; |
| 168 | [item setAction:@selector(displayAccounts:)]; |
| 169 | } |
| 170 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 171 | if ([itemIdentifier isEqualToString: kGeneralPrefsIdentifier]) { |
| 172 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kGeneralPrefsIdentifier]; |
| 173 | [item setImage: [NSImage imageNamed: @"general"]]; |
| 174 | [item setLabel: @"General"]; |
| 175 | [item setAction:@selector(displayGeneral:)]; |
| 176 | } |
| 177 | |
| 178 | if ([itemIdentifier isEqualToString: kAudioPrefsIdentifer]) { |
| 179 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kAudioPrefsIdentifer]; |
| 180 | [item setImage: [NSImage imageNamed: @"audio"]]; |
| 181 | [item setLabel: @"Audio"]; |
| 182 | [item setAction:@selector(displayAudio:)]; |
| 183 | } |
| 184 | |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 185 | if ([itemIdentifier isEqualToString: kPowerSettingsIdentifer]) { |
| 186 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kPowerSettingsIdentifer]; |
| 187 | toggleAdvancedSettings = [[NSButton alloc] initWithFrame:NSMakeRect(0,0,20,20)]; |
| 188 | [toggleAdvancedSettings setButtonType:NSSwitchButton]; |
| 189 | [toggleAdvancedSettings setTitle:@""]; |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 190 | [toggleAdvancedSettings setState:[[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]]; |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 191 | [item setLabel:@"Show Advanced"]; |
| 192 | [item setView:toggleAdvancedSettings]; |
| 193 | [item setAction:@selector(togglePowerSettings:)]; |
| 194 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 195 | |
| 196 | if ([itemIdentifier isEqualToString: kDonePrefsIdentifer]) { |
| 197 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kDonePrefsIdentifer]; |
| 198 | [item setImage: [NSImage imageNamed: @"ic_action_cancel"]]; |
| 199 | [item setLabel: @"Done"]; |
| 200 | [item setAction:@selector(closePreferences:)]; |
| 201 | } |
| 202 | |
| 203 | if ([itemIdentifier isEqualToString: kVideoPrefsIdentifer]) { |
| 204 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kVideoPrefsIdentifer]; |
| 205 | [item setImage: [NSImage imageNamed: @"video"]]; |
| 206 | [item setLabel: @"Video"]; |
| 207 | [item setAction:@selector(displayVideo:)]; |
| 208 | } |
| 209 | |
| 210 | return item; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | -(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar |
| 214 | { |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 215 | |
| 216 | NSMutableArray* items = [NSMutableArray arrayWithObjects: |
| 217 | kPowerSettingsIdentifer, |
| 218 | NSToolbarFlexibleSpaceItemIdentifier, |
| 219 | kGeneralPrefsIdentifier, |
| 220 | kAudioPrefsIdentifer, |
| 221 | kVideoPrefsIdentifer, |
| 222 | // kAncragePrefsIdentifer, |
| 223 | NSToolbarFlexibleSpaceItemIdentifier, |
| 224 | kDonePrefsIdentifer, |
| 225 | nil]; |
| 226 | |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 227 | if([[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]) { |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 228 | [items insertObject:NSToolbarSpaceItemIdentifier atIndex:5]; |
| 229 | [items insertObject:kProfilePrefsIdentifier atIndex:2]; |
| 230 | } else |
| 231 | [items insertObject:NSToolbarSpaceItemIdentifier atIndex:5]; |
| 232 | |
| 233 | return items; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | -(NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar |
| 237 | { |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 238 | NSMutableArray* items = [NSMutableArray arrayWithObjects: |
| 239 | kPowerSettingsIdentifer, |
| 240 | kGeneralPrefsIdentifier, |
| 241 | kAudioPrefsIdentifer, |
| 242 | kVideoPrefsIdentifer, |
| 243 | nil]; |
| 244 | |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 245 | if([[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]) |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 246 | [items insertObject:kProfilePrefsIdentifier atIndex:1]; |
| 247 | |
| 248 | |
| 249 | return items; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | -(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar |
| 253 | { |
| 254 | return nil; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | @end |