Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 1 | /* |
Sébastien Blin | 029ffa8 | 2019-01-02 17:43:48 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2019 Savoir-faire Linux Inc. |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 4 | * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 5 | * |
| 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 Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 19 | */ |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 20 | |
Alexandre Lision | 54187a2 | 2016-04-04 09:45:52 -0400 | [diff] [blame] | 21 | //Cocoa |
Alexandre Lision | 54187a2 | 2016-04-04 09:45:52 -0400 | [diff] [blame] | 22 | #import <Quartz/Quartz.h> |
| 23 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 24 | #import "RingWizardWC.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 25 | #import "AppDelegate.h" |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 26 | #import "Constants.h" |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 27 | #import "views/NSImage+Extensions.h" |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 28 | #import "views/NSColor+RingTheme.h" |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 29 | #import "RingWizardNewAccountVC.h" |
| 30 | #import "RingWizardLinkAccountVC.h" |
| 31 | #import "RingWizardChooseVC.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 32 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 33 | @interface RingWizardWC () |
| 34 | |
| 35 | @property (retain, nonatomic)IBOutlet NSView* container; |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 36 | @property (retain, nonatomic)IBOutlet NSTextField* windowHeader; |
| 37 | @property (retain, nonatomic)IBOutlet NSImageView* ringImage; |
| 38 | @property (retain, nonatomic)IBOutlet NSLayoutConstraint* titleConstraint; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 39 | |
| 40 | @end |
Alexandre Lision | 08abfac | 2015-09-22 12:20:51 -0400 | [diff] [blame] | 41 | @implementation RingWizardWC { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 42 | IBOutlet RingWizardNewAccountVC* newAccountWC; |
| 43 | IBOutlet RingWizardLinkAccountVC* linkAccountWC; |
| 44 | IBOutlet RingWizardChooseVC* chooseActiontWC; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 45 | IBOutlet AddSIPAccountVC* addSIPAccountVC; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 46 | BOOL isCancelable; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 47 | BOOL withAdvanced; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 50 | @synthesize accountModel, ringImage, titleConstraint; |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 51 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 52 | -(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 Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 58 | return self; |
| 59 | } |
| 60 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 61 | - (void)windowDidLoad |
| 62 | { |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 63 | [super windowDidLoad]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 64 | 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 Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 70 | [chooseActiontWC setDelegate:self]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 71 | [linkAccountWC setDelegate:self]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 72 | [newAccountWC setDelegate:self]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 73 | [self showChooseWithCancelButton:isCancelable andAdvanced: withAdvanced]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 74 | } |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 75 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 76 | - (void)removeSubviews |
| 77 | { |
| 78 | while ([self.container.subviews count] > 0) |
| 79 | { |
| 80 | [[self.container.subviews firstObject] removeFromSuperview]; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 81 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 84 | #define headerHeight 70 |
| 85 | #define minHeight 140 |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 86 | #define defaultMargin 5 |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 87 | - (void)showView:(NSView*)view |
Alexandre Lision | 54187a2 | 2016-04-04 09:45:52 -0400 | [diff] [blame] | 88 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 89 | [self removeSubviews]; |
| 90 | NSRect frame = [self.container frame]; |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 91 | CGFloat height = minHeight; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 92 | float sizeFrame = MAX(height, view.frame.size.height); |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 93 | frame.size.height = sizeFrame; |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 94 | [view setFrame: frame]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 95 | [self.container setFrame:frame]; |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 96 | 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 Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 100 | NSRect frameWindows = self.window.frame; |
| 101 | frameWindows.size.height = size; |
| 102 | [self.window setFrame:frameWindows display:YES animate:YES]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 103 | [self.container addSubview:view]; |
| 104 | } |
| 105 | |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 106 | - (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 Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 111 | 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 Kostiuk | 85a334e | 2018-12-03 15:54:19 -0500 | [diff] [blame] | 117 | [self.windowHeader setStringValue: NSLocalizedString(@"Welcome to Jami", |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 118 | @"Welcome title")]; |
| 119 | [ringImage setHidden: NO]; |
| 120 | titleConstraint.constant = -26.5; |
| 121 | [self showView:chooseActiontWC.view]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 122 | [chooseActiontWC showCancelButton:showCancel]; |
| 123 | [chooseActiontWC showAdvancedButton:showAdvanced]; |
| 124 | isCancelable = showCancel; |
| 125 | withAdvanced = showAdvanced; |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 126 | [chooseActiontWC updateFrame]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 127 | [self showView:chooseActiontWC.view]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 128 | } |
| 129 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 130 | - (void)showChooseWithCancelButton:(BOOL)showCancel |
| 131 | { |
Kateryna Kostiuk | 85a334e | 2018-12-03 15:54:19 -0500 | [diff] [blame] | 132 | [self.windowHeader setStringValue: NSLocalizedString(@"Welcome to Jami", |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 133 | @"Welcome title")]; |
| 134 | [ringImage setHidden: NO]; |
| 135 | titleConstraint.constant = -26.5; |
| 136 | [self showView:chooseActiontWC.view]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 137 | [chooseActiontWC showCancelButton:showCancel]; |
| 138 | isCancelable = showCancel; |
| 139 | } |
| 140 | |
| 141 | - (void)showNewAccountVC |
| 142 | { |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 143 | [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 Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 148 | [self showView: newAccountWC.view]; |
| 149 | [newAccountWC show]; |
| 150 | } |
| 151 | |
| 152 | - (void)showLinkAccountVC |
| 153 | { |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 154 | [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 Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 159 | [self showView: linkAccountWC.view]; |
| 160 | [linkAccountWC show]; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 163 | - (void)showSIPAccountVC |
| 164 | { |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 165 | [self.windowHeader setStringValue: NSLocalizedString(@"Add a SIP account", |
| 166 | @"Welcome title")]; |
| 167 | [ringImage setHidden: YES]; |
| 168 | titleConstraint.constant = 0; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 169 | [self showView: addSIPAccountVC.view]; |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 170 | [chooseActiontWC showAdvancedButton: NO]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 171 | [addSIPAccountVC show]; |
| 172 | } |
| 173 | |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 174 | # pragma NSWindowDelegate methods |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 175 | |
| 176 | - (void)windowWillClose:(NSNotification *)notification |
| 177 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 178 | 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 Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 190 | if (action == WIZARD_ACTION_LINK) { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 191 | [self showLinkAccountVC]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 192 | } else if (action == WIZARD_ACTION_NEW) { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 193 | [self showNewAccountVC]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 194 | } else if (action == WIZARD_ACTION_ADVANCED) { |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 195 | [self showView:chooseActiontWC.view]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 196 | } else if (action == WIZARD_ACTION_SIP_ACCOUNT) { |
| 197 | [self showSIPAccountVC]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 198 | } else { |
| 199 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 200 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | 465cfbe | 2018-06-05 16:13:05 -0400 | [diff] [blame] | 201 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 202 | } |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | #pragma - WizardCreateAccountDelegate methods |
| 206 | |
| 207 | - (void)didCreateAccountWithSuccess:(BOOL)success |
| 208 | { |
| 209 | if (success) { |
| 210 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 211 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | 465cfbe | 2018-06-05 16:13:05 -0400 | [diff] [blame] | 212 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 213 | if (!isCancelable){ |
| 214 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 215 | [appDelegate showMainWindow]; |
| 216 | } |
| 217 | } else { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 218 | [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | #pragma - WizardLinkAccountDelegate methods |
| 223 | |
| 224 | - (void)didLinkAccountWithSuccess:(BOOL)success |
| 225 | { |
| 226 | if (success) { |
| 227 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 228 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | 465cfbe | 2018-06-05 16:13:05 -0400 | [diff] [blame] | 229 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 230 | if (!isCancelable){ |
| 231 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 232 | [appDelegate showMainWindow]; |
| 233 | } |
| 234 | } else { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 235 | [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced]; |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 236 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 239 | @end |