Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 1 | /* |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015-2018 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; |
| 36 | |
| 37 | @end |
Alexandre Lision | 08abfac | 2015-09-22 12:20:51 -0400 | [diff] [blame] | 38 | @implementation RingWizardWC { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 39 | IBOutlet RingWizardNewAccountVC* newAccountWC; |
| 40 | IBOutlet RingWizardLinkAccountVC* linkAccountWC; |
| 41 | IBOutlet RingWizardChooseVC* chooseActiontWC; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 42 | IBOutlet AddSIPAccountVC* addSIPAccountVC; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 43 | BOOL isCancelable; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 44 | BOOL withAdvanced; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 47 | @synthesize accountModel; |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 48 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 49 | -(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 Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 55 | return self; |
| 56 | } |
| 57 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 58 | - (void)windowDidLoad |
| 59 | { |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 60 | [super windowDidLoad]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 61 | 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 Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 67 | [chooseActiontWC setDelegate:self]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 68 | [linkAccountWC setDelegate:self]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 69 | [newAccountWC setDelegate:self]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 70 | [self showChooseWithCancelButton:isCancelable andAdvanced: withAdvanced]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 71 | } |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 72 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 73 | - (void)removeSubviews |
| 74 | { |
| 75 | while ([self.container.subviews count] > 0) |
| 76 | { |
| 77 | [[self.container.subviews firstObject] removeFromSuperview]; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 78 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 81 | #define headerHeight 60 |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 82 | #define minHeight 150 |
| 83 | #define defaultMargin 5 |
| 84 | #define heightWithSIP 160 |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 85 | - (void)showView:(NSView*)view |
Alexandre Lision | 54187a2 | 2016-04-04 09:45:52 -0400 | [diff] [blame] | 86 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 87 | [self removeSubviews]; |
| 88 | NSRect frame = [self.container frame]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 89 | CGFloat height = withAdvanced ? minHeight : minHeight - 10; |
| 90 | float sizeFrame = MAX(height, view.frame.size.height); |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 91 | frame.size.height = sizeFrame; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 92 | [view setFrame:frame]; |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 93 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 94 | [self.container setFrame:frame]; |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 95 | 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 Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 100 | [self.container addSubview:view]; |
| 101 | } |
| 102 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 103 | - (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 Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 125 | - (void)showChooseWithCancelButton:(BOOL)showCancel |
| 126 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 127 | [chooseActiontWC showCancelButton:showCancel]; |
| 128 | isCancelable = showCancel; |
Loïc Siret | 3652cfb | 2016-10-27 10:12:07 -0400 | [diff] [blame] | 129 | [self showView:chooseActiontWC.view]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 130 | } |
| 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 Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 144 | - (void)showSIPAccountVC |
| 145 | { |
| 146 | [self showView: addSIPAccountVC.view]; |
| 147 | [addSIPAccountVC show]; |
| 148 | } |
| 149 | |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 150 | # pragma NSWindowDelegate methods |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 151 | |
| 152 | - (void)windowWillClose:(NSNotification *)notification |
| 153 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 154 | 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 Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 166 | if (action == WIZARD_ACTION_LINK) { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 167 | [self showLinkAccountVC]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 168 | } else if (action == WIZARD_ACTION_NEW) { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 169 | [self showNewAccountVC]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 170 | } else if (action == WIZARD_ACTION_ADVANCED) { |
| 171 | [self updateWindowHeight: heightWithSIP]; |
| 172 | } else if (action == WIZARD_ACTION_SIP_ACCOUNT) { |
| 173 | [self showSIPAccountVC]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 174 | } else { |
| 175 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 176 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | 465cfbe | 2018-06-05 16:13:05 -0400 | [diff] [blame] | 177 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 178 | } |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | #pragma - WizardCreateAccountDelegate methods |
| 182 | |
| 183 | - (void)didCreateAccountWithSuccess:(BOOL)success |
| 184 | { |
| 185 | if (success) { |
| 186 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 187 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | 465cfbe | 2018-06-05 16:13:05 -0400 | [diff] [blame] | 188 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 189 | if (!isCancelable){ |
| 190 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 191 | [appDelegate showMainWindow]; |
| 192 | } |
| 193 | } else { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 194 | [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | #pragma - WizardLinkAccountDelegate methods |
| 199 | |
| 200 | - (void)didLinkAccountWithSuccess:(BOOL)success |
| 201 | { |
| 202 | if (success) { |
| 203 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 204 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | 465cfbe | 2018-06-05 16:13:05 -0400 | [diff] [blame] | 205 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 206 | if (!isCancelable){ |
| 207 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 208 | [appDelegate showMainWindow]; |
| 209 | } |
| 210 | } else { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 211 | [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced]; |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 212 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 215 | #pragma - AddSIPAccountDelegate methods |
| 216 | |
| 217 | - (void)close { |
| 218 | [self.window close]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 219 | [NSApp endSheet:self.window]; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 220 | [[NSApplication sharedApplication] removeWindowsItem:self.window]; |
| 221 | } |
| 222 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 223 | @end |