blob: 8c2b8fc19101dbe16d0e6a1e09e9ae0add8a6cbc [file] [log] [blame]
Alexandre Lision745e4d62015-03-22 20:03:10 -04001/*
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -04002 * Copyright (C) 2015-2018 Savoir-faire Linux Inc.
Alexandre Lision745e4d62015-03-22 20:03:10 -04003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Kateryna Kostiukecaa3952018-07-13 16:00:34 -04004 * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Alexandre Lision745e4d62015-03-22 20:03:10 -04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Alexandre Lision745e4d62015-03-22 20:03:10 -040019 */
Alexandre Lision745e4d62015-03-22 20:03:10 -040020
Alexandre Lision54187a22016-04-04 09:45:52 -040021//Cocoa
Alexandre Lision54187a22016-04-04 09:45:52 -040022#import <Quartz/Quartz.h>
23
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040024#import "RingWizardWC.h"
Alexandre Lision745e4d62015-03-22 20:03:10 -040025#import "AppDelegate.h"
Alexandre Lision34607032016-02-08 16:16:49 -050026#import "Constants.h"
Alexandre Lision261f1b92016-04-04 12:35:34 -040027#import "views/NSImage+Extensions.h"
Alexandre Lision34607032016-02-08 16:16:49 -050028#import "views/NSColor+RingTheme.h"
Loïc Siretfcb4ca62016-09-21 17:12:09 -040029#import "RingWizardNewAccountVC.h"
30#import "RingWizardLinkAccountVC.h"
31#import "RingWizardChooseVC.h"
Alexandre Lision745e4d62015-03-22 20:03:10 -040032
Loïc Siretfcb4ca62016-09-21 17:12:09 -040033@interface RingWizardWC ()
34
35@property (retain, nonatomic)IBOutlet NSView* container;
36
37@end
Alexandre Lision08abfac2015-09-22 12:20:51 -040038@implementation RingWizardWC {
Loïc Siretfcb4ca62016-09-21 17:12:09 -040039 IBOutlet RingWizardNewAccountVC* newAccountWC;
40 IBOutlet RingWizardLinkAccountVC* linkAccountWC;
41 IBOutlet RingWizardChooseVC* chooseActiontWC;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040042 IBOutlet AddSIPAccountVC* addSIPAccountVC;
Loïc Siretfcb4ca62016-09-21 17:12:09 -040043 BOOL isCancelable;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040044 BOOL withAdvanced;
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -040045}
46
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040047@synthesize accountModel;
Loïc Siret3652cfb2016-10-27 10:12:07 -040048
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040049-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel;
50{
51 if (self = [self initWithWindowNibName:nibNameOrNil])
52 {
53 self.accountModel = accountModel;
54 }
Loïc Siret3652cfb2016-10-27 10:12:07 -040055 return self;
56}
57
Loïc Siretfcb4ca62016-09-21 17:12:09 -040058- (void)windowDidLoad
59{
Alexandre Lision745e4d62015-03-22 20:03:10 -040060 [super windowDidLoad];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040061 newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardNewAccount" bundle:nil accountmodel:self.accountModel];
62
63 chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
64 linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil accountmodel:self.accountModel];
65 addSIPAccountVC = [[AddSIPAccountVC alloc] initWithNibName:@"AddSIPAccountVC" bundle:nil accountmodel:self.accountModel];
66 [addSIPAccountVC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040067 [chooseActiontWC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040068 [linkAccountWC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040069 [newAccountWC setDelegate:self];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040070 [self showChooseWithCancelButton:isCancelable andAdvanced: withAdvanced];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040071}
Alexandre Lision34607032016-02-08 16:16:49 -050072
Loïc Siretfcb4ca62016-09-21 17:12:09 -040073- (void)removeSubviews
74{
75 while ([self.container.subviews count] > 0)
76 {
77 [[self.container.subviews firstObject] removeFromSuperview];
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -040078 }
Alexandre Lision745e4d62015-03-22 20:03:10 -040079}
80
Loïc Siret3652cfb2016-10-27 10:12:07 -040081#define headerHeight 60
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040082#define minHeight 150
83#define defaultMargin 5
84#define heightWithSIP 160
Loïc Siret3652cfb2016-10-27 10:12:07 -040085- (void)showView:(NSView*)view
Alexandre Lision54187a22016-04-04 09:45:52 -040086{
Loïc Siretfcb4ca62016-09-21 17:12:09 -040087 [self removeSubviews];
88 NSRect frame = [self.container frame];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040089 CGFloat height = withAdvanced ? minHeight : minHeight - 10;
90 float sizeFrame = MAX(height, view.frame.size.height);
Loïc Siret3652cfb2016-10-27 10:12:07 -040091 frame.size.height = sizeFrame;
Loïc Siretfcb4ca62016-09-21 17:12:09 -040092 [view setFrame:frame];
Loïc Siret3652cfb2016-10-27 10:12:07 -040093
Loïc Siretfcb4ca62016-09-21 17:12:09 -040094 [self.container setFrame:frame];
Loïc Siret3652cfb2016-10-27 10:12:07 -040095 float size = headerHeight + sizeFrame + defaultMargin;
96 NSRect frameWindows = self.window.frame;
97 frameWindows.size.height = size;
98 [self.window setFrame:frameWindows display:YES animate:YES];
99
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400100 [self.container addSubview:view];
101}
102
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400103- (void) updateWindowHeight: (CGFloat) height {
104 NSRect frame = [self.container frame];
105 float sizeFrame = height;
106 frame.size.height = sizeFrame;
107 [self.container setFrame:frame];
108 float size = headerHeight + sizeFrame + defaultMargin;
109 NSRect frameWindows = self.window.frame;
110 frameWindows.size.height = size;
111 [self.window setFrame:frameWindows display:YES animate:YES];
112}
113
114- (void)showChooseWithCancelButton:(BOOL)showCancel andAdvanced:(BOOL)showAdvanced {
115 [chooseActiontWC showCancelButton:showCancel];
116 [chooseActiontWC showAdvancedButton:showAdvanced];
117 isCancelable = showCancel;
118 withAdvanced = showAdvanced;
119 NSRect frame = CGRectMake(0, 0, chooseActiontWC.view.frame.size.width, 0);
120 chooseActiontWC.view.frame = frame;
121 [self showView:chooseActiontWC.view];
122
123}
124
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400125- (void)showChooseWithCancelButton:(BOOL)showCancel
126{
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400127 [chooseActiontWC showCancelButton:showCancel];
128 isCancelable = showCancel;
Loïc Siret3652cfb2016-10-27 10:12:07 -0400129 [self showView:chooseActiontWC.view];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400130}
131
132- (void)showNewAccountVC
133{
134 [self showView: newAccountWC.view];
135 [newAccountWC show];
136}
137
138- (void)showLinkAccountVC
139{
140 [self showView: linkAccountWC.view];
141 [linkAccountWC show];
Alexandre Lision745e4d62015-03-22 20:03:10 -0400142}
143
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400144- (void)showSIPAccountVC
145{
146 [self showView: addSIPAccountVC.view];
147 [addSIPAccountVC show];
148}
149
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -0400150# pragma NSWindowDelegate methods
Alexandre Lision745e4d62015-03-22 20:03:10 -0400151
152- (void)windowWillClose:(NSNotification *)notification
153{
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400154 if (!isCancelable){
155 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
156 if ([appDelegate checkForRingAccount]) {
157 [appDelegate showMainWindow];
158 }
159 }
160}
161
162#pragma - WizardChooseDelegate methods
163
164- (void)didCompleteWithAction:(WizardAction)action
165{
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400166 if (action == WIZARD_ACTION_LINK) {
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400167 [self showLinkAccountVC];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400168 } else if (action == WIZARD_ACTION_NEW) {
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400169 [self showNewAccountVC];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400170 } else if (action == WIZARD_ACTION_ADVANCED) {
171 [self updateWindowHeight: heightWithSIP];
172 } else if (action == WIZARD_ACTION_SIP_ACCOUNT) {
173 [self showSIPAccountVC];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400174 } else {
175 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400176 [NSApp endSheet:self.window];
Kateryna Kostiuk465cfbe2018-06-05 16:13:05 -0400177 [[NSApplication sharedApplication] removeWindowsItem:self.window];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400178 }
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400179}
180
181#pragma - WizardCreateAccountDelegate methods
182
183- (void)didCreateAccountWithSuccess:(BOOL)success
184{
185 if (success) {
186 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400187 [NSApp endSheet:self.window];
Kateryna Kostiuk465cfbe2018-06-05 16:13:05 -0400188 [[NSApplication sharedApplication] removeWindowsItem:self.window];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400189 if (!isCancelable){
190 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
191 [appDelegate showMainWindow];
192 }
193 } else {
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400194 [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400195 }
196}
197
198#pragma - WizardLinkAccountDelegate methods
199
200- (void)didLinkAccountWithSuccess:(BOOL)success
201{
202 if (success) {
203 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400204 [NSApp endSheet:self.window];
Kateryna Kostiuk465cfbe2018-06-05 16:13:05 -0400205 [[NSApplication sharedApplication] removeWindowsItem:self.window];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400206 if (!isCancelable){
207 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
208 [appDelegate showMainWindow];
209 }
210 } else {
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400211 [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced];
Alexandre Lision76d59692016-01-20 18:06:05 -0500212 }
Alexandre Lision745e4d62015-03-22 20:03:10 -0400213}
214
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400215#pragma - AddSIPAccountDelegate methods
216
217- (void)close {
218 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400219 [NSApp endSheet:self.window];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400220 [[NSApplication sharedApplication] removeWindowsItem:self.window];
221}
222
Alexandre Lision745e4d62015-03-22 20:03:10 -0400223@end