blob: f2bdde3d8528708f68ab67c0bd948aada59c9bdf [file] [log] [blame]
Alexandre Lision8521baa2015-03-13 11:08:00 -04001/*
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 Lision4a7b95e2015-02-20 10:06:43 -050030#import "PreferencesViewController.h"
Alexandre Lision8521baa2015-03-13 11:08:00 -040031
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050032#import <QuartzCore/QuartzCore.h>
33
Alexandre Lision91d11e52015-03-20 17:42:05 -040034#import <accountmodel.h>
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040035
36#import "AccountsVC.h"
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050037#import "GeneralPrefsVC.h"
38#import "AudioPrefsVC.h"
39#import "VideoPrefsVC.h"
40
41@interface PreferencesViewController ()
42
43@end
44
45@implementation PreferencesViewController
46
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040047static NSString* const kProfilePrefsIdentifier = @"ProfilesPrefsIdentifier";
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050048static NSString* const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
49static NSString* const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
50static NSString* const kAncragePrefsIdentifer = @"AncragePrefsIdentifer";
51static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
52static 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 Lisionf5fc4792015-03-17 09:15:43 -040067 [self.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
68
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050069 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 Lision4a7b95e2015-02-20 10:06:43 -050076 [self.view.layer addAnimation:animation forKey:animation.keyPath];
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050077}
78
79- (void) close
80{
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040081
82 AccountModel::instance()->save();
83
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050084 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 Lision4a7b95e2015-02-20 10:06:43 -0500103 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 Lisionf5fc4792015-03-17 09:15:43 -0400136- (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 Lision4a7b95e2015-02-20 10:06:43 -0500146
147#pragma NSToolbar Delegate
148
149-(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
150{
151 NSToolbarItem* item = nil;
152
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400153 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 Lision4a7b95e2015-02-20 10:06:43 -0500161 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 Lisionf5fc4792015-03-17 09:15:43 -0400175// 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 Lision4a7b95e2015-02-20 10:06:43 -0500181
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 Lisionf5fc4792015-03-17 09:15:43 -0400205 kProfilePrefsIdentifier,
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500206 kGeneralPrefsIdentifier,
207 kAudioPrefsIdentifer,
208 kVideoPrefsIdentifer,
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400209 // kAncragePrefsIdentifer,
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500210 NSToolbarFlexibleSpaceItemIdentifier,
211 kDonePrefsIdentifer,
212 nil];
213}
214
215-(NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
216{
217 return [NSArray arrayWithObjects:
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400218 kProfilePrefsIdentifier,
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500219 kGeneralPrefsIdentifier,
220 kAudioPrefsIdentifer,
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400221 // kAncragePrefsIdentifer,
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500222 kVideoPrefsIdentifer,
223 nil];
224}
225
226-(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
227{
228 return nil;
229}
230
231
232
233
234
235@end