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