blob: ff65c107e9bd9f2b03f1fa455af5dd506b52f8a7 [file] [log] [blame]
Alexandre Lision745e4d62015-03-22 20:03:10 -04001/*
Sébastien Blin029ffa82019-01-02 17:43:48 -05002 * Copyright (C) 2015-2019 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;
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -050036@property (retain, nonatomic)IBOutlet NSTextField* windowHeader;
37@property (retain, nonatomic)IBOutlet NSImageView* ringImage;
38@property (retain, nonatomic)IBOutlet NSLayoutConstraint* titleConstraint;
Loïc Siretfcb4ca62016-09-21 17:12:09 -040039
40@end
Alexandre Lision08abfac2015-09-22 12:20:51 -040041@implementation RingWizardWC {
Loïc Siretfcb4ca62016-09-21 17:12:09 -040042 IBOutlet RingWizardNewAccountVC* newAccountWC;
43 IBOutlet RingWizardLinkAccountVC* linkAccountWC;
44 IBOutlet RingWizardChooseVC* chooseActiontWC;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040045 IBOutlet AddSIPAccountVC* addSIPAccountVC;
Loïc Siretfcb4ca62016-09-21 17:12:09 -040046 BOOL isCancelable;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040047 BOOL withAdvanced;
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -040048}
49
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -050050@synthesize accountModel, ringImage, titleConstraint;
Loïc Siret3652cfb2016-10-27 10:12:07 -040051
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040052-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel;
53{
54 if (self = [self initWithWindowNibName:nibNameOrNil])
55 {
56 self.accountModel = accountModel;
57 }
Loïc Siret3652cfb2016-10-27 10:12:07 -040058 return self;
59}
60
Loïc Siretfcb4ca62016-09-21 17:12:09 -040061- (void)windowDidLoad
62{
Alexandre Lision745e4d62015-03-22 20:03:10 -040063 [super windowDidLoad];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040064 newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardNewAccount" bundle:nil accountmodel:self.accountModel];
65
66 chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
67 linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil accountmodel:self.accountModel];
68 addSIPAccountVC = [[AddSIPAccountVC alloc] initWithNibName:@"AddSIPAccountVC" bundle:nil accountmodel:self.accountModel];
69 [addSIPAccountVC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040070 [chooseActiontWC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040071 [linkAccountWC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040072 [newAccountWC setDelegate:self];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040073 [self showChooseWithCancelButton:isCancelable andAdvanced: withAdvanced];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040074}
Alexandre Lision34607032016-02-08 16:16:49 -050075
Loïc Siretfcb4ca62016-09-21 17:12:09 -040076- (void)removeSubviews
77{
78 while ([self.container.subviews count] > 0)
79 {
80 [[self.container.subviews firstObject] removeFromSuperview];
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -040081 }
Alexandre Lision745e4d62015-03-22 20:03:10 -040082}
83
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -050084#define headerHeight 70
85#define minHeight 140
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040086#define defaultMargin 5
Loïc Siret3652cfb2016-10-27 10:12:07 -040087- (void)showView:(NSView*)view
Alexandre Lision54187a22016-04-04 09:45:52 -040088{
Loïc Siretfcb4ca62016-09-21 17:12:09 -040089 [self removeSubviews];
90 NSRect frame = [self.container frame];
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -050091 CGFloat height = minHeight;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -040092 float sizeFrame = MAX(height, view.frame.size.height);
Loïc Siret3652cfb2016-10-27 10:12:07 -040093 frame.size.height = sizeFrame;
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -050094 [view setFrame: frame];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040095 [self.container setFrame:frame];
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -050096 float titleBarHeight = self.window.frame.size.height -
97 [NSWindow contentRectForFrameRect: self.window.frame styleMask:self.window.styleMask].size.height;
98 titleBarHeight = self.window.isSheet ? 0 : titleBarHeight;
99 float size = headerHeight + sizeFrame + titleBarHeight;
Loïc Siret3652cfb2016-10-27 10:12:07 -0400100 NSRect frameWindows = self.window.frame;
101 frameWindows.size.height = size;
102 [self.window setFrame:frameWindows display:YES animate:YES];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400103 [self.container addSubview:view];
104}
105
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500106- (void) updateFrame:(float) height {
107 float titleBarHeight = self.window.frame.size.height -
108 [NSWindow contentRectForFrameRect: self.window.frame styleMask:self.window.styleMask].size.height;
109 titleBarHeight = self.window.isSheet ? 0 : titleBarHeight;
110 float size = headerHeight + height + titleBarHeight;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400111 NSRect frameWindows = self.window.frame;
112 frameWindows.size.height = size;
113 [self.window setFrame:frameWindows display:YES animate:YES];
114}
115
116- (void)showChooseWithCancelButton:(BOOL)showCancel andAdvanced:(BOOL)showAdvanced {
Kateryna Kostiuk85a334e2018-12-03 15:54:19 -0500117 [self.windowHeader setStringValue: NSLocalizedString(@"Welcome to Jami",
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500118 @"Welcome title")];
119 [ringImage setHidden: NO];
120 titleConstraint.constant = -26.5;
121 [self showView:chooseActiontWC.view];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400122 [chooseActiontWC showCancelButton:showCancel];
123 [chooseActiontWC showAdvancedButton:showAdvanced];
124 isCancelable = showCancel;
125 withAdvanced = showAdvanced;
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500126 [chooseActiontWC updateFrame];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400127 [self showView:chooseActiontWC.view];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400128}
129
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400130- (void)showChooseWithCancelButton:(BOOL)showCancel
131{
Kateryna Kostiuk85a334e2018-12-03 15:54:19 -0500132 [self.windowHeader setStringValue: NSLocalizedString(@"Welcome to Jami",
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500133 @"Welcome title")];
134 [ringImage setHidden: NO];
135 titleConstraint.constant = -26.5;
136 [self showView:chooseActiontWC.view];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400137 [chooseActiontWC showCancelButton:showCancel];
138 isCancelable = showCancel;
139}
140
141- (void)showNewAccountVC
142{
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500143 [self.windowHeader setStringValue: NSLocalizedString(@"Create a new account",
144 @"Welcome title")];
145 [chooseActiontWC showCancelButton: isCancelable];
146 [ringImage setHidden: YES];
147 titleConstraint.constant = 0;
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400148 [self showView: newAccountWC.view];
149 [newAccountWC show];
150}
151
152- (void)showLinkAccountVC
153{
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500154 [self.windowHeader setStringValue: NSLocalizedString(@"Link to an account",
155 @"link account title")];
156 [ringImage setHidden: YES];
157 titleConstraint.constant = 0;
158 [chooseActiontWC showCancelButton: isCancelable];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400159 [self showView: linkAccountWC.view];
160 [linkAccountWC show];
Alexandre Lision745e4d62015-03-22 20:03:10 -0400161}
162
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400163- (void)showSIPAccountVC
164{
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500165 [self.windowHeader setStringValue: NSLocalizedString(@"Add a SIP account",
166 @"Welcome title")];
167 [ringImage setHidden: YES];
168 titleConstraint.constant = 0;
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400169 [self showView: addSIPAccountVC.view];
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500170 [chooseActiontWC showAdvancedButton: NO];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400171 [addSIPAccountVC show];
172}
173
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -0400174# pragma NSWindowDelegate methods
Alexandre Lision745e4d62015-03-22 20:03:10 -0400175
176- (void)windowWillClose:(NSNotification *)notification
177{
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400178 if (!isCancelable){
179 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
180 if ([appDelegate checkForRingAccount]) {
181 [appDelegate showMainWindow];
182 }
183 }
184}
185
186#pragma - WizardChooseDelegate methods
187
188- (void)didCompleteWithAction:(WizardAction)action
189{
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400190 if (action == WIZARD_ACTION_LINK) {
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400191 [self showLinkAccountVC];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400192 } else if (action == WIZARD_ACTION_NEW) {
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400193 [self showNewAccountVC];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400194 } else if (action == WIZARD_ACTION_ADVANCED) {
Kateryna Kostiuk23222fe2018-11-16 14:28:02 -0500195 [self showView:chooseActiontWC.view];
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400196 } else if (action == WIZARD_ACTION_SIP_ACCOUNT) {
197 [self showSIPAccountVC];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400198 } else {
199 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400200 [NSApp endSheet:self.window];
Kateryna Kostiuk465cfbe2018-06-05 16:13:05 -0400201 [[NSApplication sharedApplication] removeWindowsItem:self.window];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400202 }
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400203}
204
205#pragma - WizardCreateAccountDelegate methods
206
207- (void)didCreateAccountWithSuccess:(BOOL)success
208{
209 if (success) {
210 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400211 [NSApp endSheet:self.window];
Kateryna Kostiuk465cfbe2018-06-05 16:13:05 -0400212 [[NSApplication sharedApplication] removeWindowsItem:self.window];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400213 if (!isCancelable){
214 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
215 [appDelegate showMainWindow];
216 }
217 } else {
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400218 [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400219 }
220}
221
222#pragma - WizardLinkAccountDelegate methods
223
224- (void)didLinkAccountWithSuccess:(BOOL)success
225{
226 if (success) {
227 [self.window close];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400228 [NSApp endSheet:self.window];
Kateryna Kostiuk465cfbe2018-06-05 16:13:05 -0400229 [[NSApplication sharedApplication] removeWindowsItem:self.window];
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400230 if (!isCancelable){
231 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
232 [appDelegate showMainWindow];
233 }
234 } else {
Kateryna Kostiukecaa3952018-07-13 16:00:34 -0400235 [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced];
Alexandre Lision76d59692016-01-20 18:06:05 -0500236 }
Alexandre Lision745e4d62015-03-22 20:03:10 -0400237}
238
Alexandre Lision745e4d62015-03-22 20:03:10 -0400239@end