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" |
| 41 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame^] | 42 | @interface PreferencesVC () |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 43 | |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 44 | @property NSButton* toggleAdvancedSettings; |
| 45 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 46 | @end |
| 47 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame^] | 48 | @implementation PreferencesVC |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 49 | @synthesize toggleAdvancedSettings; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 50 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 51 | static NSString* const kProfilePrefsIdentifier = @"ProfilesPrefsIdentifier"; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 52 | static NSString* const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 53 | static NSString* const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 54 | static NSString* const kAncragePrefsIdentifer = @"AncragePrefsIdentifer"; |
| 55 | static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
| 56 | static NSString* const kDonePrefsIdentifer = @"DonePrefsIdentifer"; |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 57 | static NSString* const kPowerSettingsIdentifer = @"PowerSettingsIdentifer"; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 58 | |
| 59 | -(void)loadView |
| 60 | { |
| 61 | [super loadView]; |
| 62 | |
| 63 | [self displayGeneral:nil]; |
| 64 | |
| 65 | [self.view setWantsLayer:YES]; |
| 66 | self.view.layer.backgroundColor = [NSColor windowBackgroundColor].CGColor; |
| 67 | |
| 68 | // Set the layer redraw policy. This would be better done in |
| 69 | // the initialization method of a NSView subclass instead of here. |
| 70 | self.view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize; |
| 71 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 72 | [self.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 73 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 74 | CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height); |
| 75 | |
| 76 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 77 | animation.fromValue = [NSValue valueWithPoint:frame.origin]; |
| 78 | animation.toValue = [NSValue valueWithPoint:self.view.frame.origin]; |
| 79 | animation.duration = 0.3f; |
| 80 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 81 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | - (void) close |
| 85 | { |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 86 | // first save codecs for each account |
| 87 | for (int i = 0 ; i < AccountModel::instance()->rowCount(); ++i) { |
| 88 | QModelIndex qIdx = AccountModel::instance()->index(i); |
| 89 | AccountModel::instance()->getAccountByModelIndex(qIdx)->codecModel()->save(); |
| 90 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 91 | |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 92 | // then save accounts |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 93 | AccountModel::instance()->save(); |
| 94 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 95 | CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height); |
| 96 | |
| 97 | [CATransaction begin]; |
| 98 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 99 | animation.fromValue = [NSValue valueWithPoint:self.view.frame.origin]; |
| 100 | animation.toValue = [NSValue valueWithPoint:frame.origin]; |
| 101 | animation.duration = 0.3f; |
| 102 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 103 | |
| 104 | [CATransaction setCompletionBlock:^{ |
| 105 | [self.view removeFromSuperview]; |
| 106 | }]; |
| 107 | |
| 108 | |
| 109 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 110 | [CATransaction commit]; |
| 111 | } |
| 112 | |
| 113 | - (void)displayGeneral:(NSToolbarItem *)sender { |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 114 | if (self.currentVC != nil) { |
| 115 | [self.currentVC.view removeFromSuperview]; |
| 116 | } |
| 117 | self.generalPrefsVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil]; |
| 118 | [self.view addSubview:self.generalPrefsVC.view]; |
| 119 | [self.generalPrefsVC.view setFrame:[self.view bounds]]; |
| 120 | self.currentVC = self.generalPrefsVC; |
| 121 | } |
| 122 | |
| 123 | - (void)displayAudio:(NSToolbarItem *)sender { |
| 124 | if (self.currentVC != nil) { |
| 125 | [self.currentVC.view removeFromSuperview]; |
| 126 | } |
| 127 | self.audioPrefsVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 128 | [self.view addSubview:self.audioPrefsVC.view]; |
| 129 | [self.audioPrefsVC.view setFrame:[self.view bounds]]; |
| 130 | self.currentVC = self.audioPrefsVC; |
| 131 | } |
| 132 | |
| 133 | - (void)displayAncrage:(NSToolbarItem *)sender { |
| 134 | |
| 135 | } |
| 136 | |
| 137 | - (void)displayVideo:(NSToolbarItem *)sender { |
| 138 | if (self.currentVC != nil) { |
| 139 | [self.currentVC.view removeFromSuperview]; |
| 140 | } |
| 141 | self.videoPrefsVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil]; |
| 142 | [self.view addSubview:self.videoPrefsVC.view]; |
| 143 | [self.videoPrefsVC.view setFrame:[self.view bounds]]; |
| 144 | self.currentVC = self.videoPrefsVC; |
| 145 | } |
| 146 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 147 | - (void) displayAccounts:(NSToolbarItem *) sender { |
| 148 | if (self.currentVC != nil) { |
| 149 | [self.currentVC.view removeFromSuperview]; |
| 150 | } |
| 151 | self.accountsPrefsVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil]; |
| 152 | [self.view addSubview:self.accountsPrefsVC.view]; |
| 153 | [self.accountsPrefsVC.view setFrame:[self.view bounds]]; |
| 154 | self.currentVC = self.accountsPrefsVC; |
| 155 | } |
| 156 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 157 | |
| 158 | #pragma NSToolbar Delegate |
| 159 | |
| 160 | -(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag |
| 161 | { |
| 162 | NSToolbarItem* item = nil; |
| 163 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 164 | if ([itemIdentifier isEqualToString: kProfilePrefsIdentifier]) { |
| 165 | |
| 166 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kProfilePrefsIdentifier]; |
| 167 | [item setImage: [NSImage imageNamed: @"NSUserAccounts"]]; |
| 168 | [item setLabel: @"Accounts"]; |
| 169 | [item setAction:@selector(displayAccounts:)]; |
| 170 | } |
| 171 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 172 | if ([itemIdentifier isEqualToString: kGeneralPrefsIdentifier]) { |
| 173 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kGeneralPrefsIdentifier]; |
| 174 | [item setImage: [NSImage imageNamed: @"general"]]; |
| 175 | [item setLabel: @"General"]; |
| 176 | [item setAction:@selector(displayGeneral:)]; |
| 177 | } |
| 178 | |
| 179 | if ([itemIdentifier isEqualToString: kAudioPrefsIdentifer]) { |
| 180 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kAudioPrefsIdentifer]; |
| 181 | [item setImage: [NSImage imageNamed: @"audio"]]; |
| 182 | [item setLabel: @"Audio"]; |
| 183 | [item setAction:@selector(displayAudio:)]; |
| 184 | } |
| 185 | |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 186 | if ([itemIdentifier isEqualToString: kPowerSettingsIdentifer]) { |
| 187 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kPowerSettingsIdentifer]; |
| 188 | toggleAdvancedSettings = [[NSButton alloc] initWithFrame:NSMakeRect(0,0,20,20)]; |
| 189 | [toggleAdvancedSettings setButtonType:NSSwitchButton]; |
| 190 | [toggleAdvancedSettings setTitle:@""]; |
| 191 | [toggleAdvancedSettings setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"show_advanced"]]; |
| 192 | [item setLabel:@"Show Advanced"]; |
| 193 | [item setView:toggleAdvancedSettings]; |
| 194 | [item setAction:@selector(togglePowerSettings:)]; |
| 195 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 196 | |
| 197 | if ([itemIdentifier isEqualToString: kDonePrefsIdentifer]) { |
| 198 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kDonePrefsIdentifer]; |
| 199 | [item setImage: [NSImage imageNamed: @"ic_action_cancel"]]; |
| 200 | [item setLabel: @"Done"]; |
| 201 | [item setAction:@selector(closePreferences:)]; |
| 202 | } |
| 203 | |
| 204 | if ([itemIdentifier isEqualToString: kVideoPrefsIdentifer]) { |
| 205 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kVideoPrefsIdentifer]; |
| 206 | [item setImage: [NSImage imageNamed: @"video"]]; |
| 207 | [item setLabel: @"Video"]; |
| 208 | [item setAction:@selector(displayVideo:)]; |
| 209 | } |
| 210 | |
| 211 | return item; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | -(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar |
| 215 | { |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 216 | |
| 217 | NSMutableArray* items = [NSMutableArray arrayWithObjects: |
| 218 | kPowerSettingsIdentifer, |
| 219 | NSToolbarFlexibleSpaceItemIdentifier, |
| 220 | kGeneralPrefsIdentifier, |
| 221 | kAudioPrefsIdentifer, |
| 222 | kVideoPrefsIdentifer, |
| 223 | // kAncragePrefsIdentifer, |
| 224 | NSToolbarFlexibleSpaceItemIdentifier, |
| 225 | kDonePrefsIdentifer, |
| 226 | nil]; |
| 227 | |
| 228 | if([[NSUserDefaults standardUserDefaults] boolForKey:@"show_advanced"]) { |
| 229 | [items insertObject:NSToolbarSpaceItemIdentifier atIndex:5]; |
| 230 | [items insertObject:kProfilePrefsIdentifier atIndex:2]; |
| 231 | } else |
| 232 | [items insertObject:NSToolbarSpaceItemIdentifier atIndex:5]; |
| 233 | |
| 234 | return items; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | -(NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar |
| 238 | { |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 239 | NSMutableArray* items = [NSMutableArray arrayWithObjects: |
| 240 | kPowerSettingsIdentifer, |
| 241 | kGeneralPrefsIdentifier, |
| 242 | kAudioPrefsIdentifer, |
| 243 | kVideoPrefsIdentifer, |
| 244 | nil]; |
| 245 | |
| 246 | if([[NSUserDefaults standardUserDefaults] boolForKey:@"show_advanced"]) |
| 247 | [items insertObject:kProfilePrefsIdentifier atIndex:1]; |
| 248 | |
| 249 | |
| 250 | return items; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | -(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar |
| 254 | { |
| 255 | return nil; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | @end |