Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 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. |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 18 | */ |
| 19 | #import "RingWizardWC.h" |
| 20 | |
Alexandre Lision | 54187a2 | 2016-04-04 09:45:52 -0400 | [diff] [blame] | 21 | //Cocoa |
| 22 | #import <AddressBook/AddressBook.h> |
| 23 | #import <Quartz/Quartz.h> |
| 24 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 25 | |
| 26 | #import "AppDelegate.h" |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 27 | #import "Constants.h" |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 28 | #import "views/NSImage+Extensions.h" |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 29 | #import "views/NSColor+RingTheme.h" |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 30 | #import "RingWizardNewAccountVC.h" |
| 31 | #import "RingWizardLinkAccountVC.h" |
| 32 | #import "RingWizardChooseVC.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 33 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 34 | |
| 35 | @interface RingWizardWC () |
| 36 | |
| 37 | @property (retain, nonatomic)IBOutlet NSView* container; |
| 38 | |
| 39 | @end |
Alexandre Lision | 08abfac | 2015-09-22 12:20:51 -0400 | [diff] [blame] | 40 | @implementation RingWizardWC { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 41 | IBOutlet RingWizardNewAccountVC* newAccountWC; |
| 42 | IBOutlet RingWizardLinkAccountVC* linkAccountWC; |
| 43 | IBOutlet RingWizardChooseVC* chooseActiontWC; |
| 44 | float initialHeight; |
| 45 | float currentHeight; |
| 46 | BOOL isCancelable; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 49 | - (void)windowDidLoad |
| 50 | { |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 51 | [super windowDidLoad]; |
| 52 | |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 53 | [self.window setBackgroundColor:[NSColor ringGreyHighlight]]; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 54 | chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil]; |
| 55 | [chooseActiontWC setDelegate:self]; |
| 56 | linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil]; |
| 57 | [linkAccountWC setDelegate:self]; |
| 58 | newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardNewAccount" bundle:nil]; |
| 59 | [newAccountWC setDelegate:self]; |
| 60 | initialHeight = self.window.frame.size.height; |
| 61 | currentHeight = self.window.frame.size.height; |
| 62 | isCancelable = NO; |
| 63 | [self showView:chooseActiontWC.view]; |
| 64 | } |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 65 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 66 | - (void)removeSubviews |
| 67 | { |
| 68 | while ([self.container.subviews count] > 0) |
| 69 | { |
| 70 | [[self.container.subviews firstObject] removeFromSuperview]; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 71 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 74 | #define minHeight 135 |
| 75 | - (void)showView: (NSView*) view |
Alexandre Lision | 54187a2 | 2016-04-04 09:45:52 -0400 | [diff] [blame] | 76 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 77 | [self removeSubviews]; |
| 78 | NSRect frame = [self.container frame]; |
| 79 | frame.size.height = MAX(minHeight, view.bounds.size.height); |
| 80 | [view setFrame:frame]; |
| 81 | [self.container setFrame:frame]; |
| 82 | float size = 0; |
| 83 | NSView *container = self.window.contentView; |
| 84 | for (NSView *child in container.subviews){ |
| 85 | size += child.frame.size.height; |
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 | if (currentHeight != size){ |
| 88 | currentHeight = size; |
| 89 | NSRect frameWindows = self.window.frame; |
| 90 | frameWindows.size.height = currentHeight; |
| 91 | [self.window setFrame:frameWindows display:YES animate:YES]; |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 92 | } |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 93 | [self.container addSubview:view]; |
| 94 | } |
| 95 | |
| 96 | - (void)showChooseWithCancelButton:(BOOL)showCancel |
| 97 | { |
| 98 | [self showView: chooseActiontWC.view]; |
| 99 | [chooseActiontWC showCancelButton:showCancel]; |
| 100 | isCancelable = showCancel; |
| 101 | } |
| 102 | |
| 103 | - (void)showNewAccountVC |
| 104 | { |
| 105 | [self showView: newAccountWC.view]; |
| 106 | [newAccountWC show]; |
| 107 | } |
| 108 | |
| 109 | - (void)showLinkAccountVC |
| 110 | { |
| 111 | [self showView: linkAccountWC.view]; |
| 112 | [linkAccountWC show]; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 115 | # pragma NSWindowDelegate methods |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 116 | |
| 117 | - (void)windowWillClose:(NSNotification *)notification |
| 118 | { |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame^] | 119 | if (!isCancelable){ |
| 120 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 121 | if ([appDelegate checkForRingAccount]) { |
| 122 | [appDelegate showMainWindow]; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | #pragma - WizardChooseDelegate methods |
| 128 | |
| 129 | - (void)didCompleteWithAction:(WizardAction)action |
| 130 | { |
| 131 | if (action == WIZARD_ACTION_LINK){ |
| 132 | [self showLinkAccountVC]; |
| 133 | } else if (action == WIZARD_ACTION_NEW){ |
| 134 | [self showNewAccountVC]; |
| 135 | } else { |
| 136 | [self.window close]; |
| 137 | } |
| 138 | |
| 139 | } |
| 140 | |
| 141 | #pragma - WizardCreateAccountDelegate methods |
| 142 | |
| 143 | - (void)didCreateAccountWithSuccess:(BOOL)success |
| 144 | { |
| 145 | if (success) { |
| 146 | [self.window close]; |
| 147 | if (!isCancelable){ |
| 148 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 149 | [appDelegate showMainWindow]; |
| 150 | } |
| 151 | } else { |
| 152 | [self showChooseWithCancelButton:isCancelable]; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | #pragma - WizardLinkAccountDelegate methods |
| 157 | |
| 158 | - (void)didLinkAccountWithSuccess:(BOOL)success |
| 159 | { |
| 160 | if (success) { |
| 161 | [self.window close]; |
| 162 | if (!isCancelable){ |
| 163 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 164 | [appDelegate showMainWindow]; |
| 165 | } |
| 166 | } else { |
| 167 | [self showChooseWithCancelButton:isCancelable]; |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 168 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | @end |