blob: bb4e101e762642748d54da90bff1923aa4bdd569 [file] [log] [blame]
Alexandre Lision745e4d62015-03-22 20:03:10 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision745e4d62015-03-22 20:03:10 -04003 * 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 Lision745e4d62015-03-22 20:03:10 -040018 */
19#import "RingWizardWC.h"
20
Alexandre Lision54187a22016-04-04 09:45:52 -040021//Cocoa
22#import <AddressBook/AddressBook.h>
23#import <Quartz/Quartz.h>
24
Alexandre Lision745e4d62015-03-22 20:03:10 -040025
26#import "AppDelegate.h"
Alexandre Lision34607032016-02-08 16:16:49 -050027#import "Constants.h"
Alexandre Lision261f1b92016-04-04 12:35:34 -040028#import "views/NSImage+Extensions.h"
Alexandre Lision34607032016-02-08 16:16:49 -050029#import "views/NSColor+RingTheme.h"
Loïc Siretfcb4ca62016-09-21 17:12:09 -040030#import "RingWizardNewAccountVC.h"
31#import "RingWizardLinkAccountVC.h"
32#import "RingWizardChooseVC.h"
Alexandre Lision745e4d62015-03-22 20:03:10 -040033
Loïc Siretfcb4ca62016-09-21 17:12:09 -040034
35@interface RingWizardWC ()
36
37@property (retain, nonatomic)IBOutlet NSView* container;
38
39@end
Alexandre Lision08abfac2015-09-22 12:20:51 -040040@implementation RingWizardWC {
Loïc Siretfcb4ca62016-09-21 17:12:09 -040041 IBOutlet RingWizardNewAccountVC* newAccountWC;
42 IBOutlet RingWizardLinkAccountVC* linkAccountWC;
43 IBOutlet RingWizardChooseVC* chooseActiontWC;
Loïc Siretfcb4ca62016-09-21 17:12:09 -040044 BOOL isCancelable;
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -040045}
46
Loïc Siret3652cfb2016-10-27 10:12:07 -040047- (instancetype)initWithWindowNibName:(NSString *)windowNibName{
48 self = [super initWithWindowNibName:windowNibName];
49
50 chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
51 linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil];
52 newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
53 return self;
54}
55
Loïc Siretfcb4ca62016-09-21 17:12:09 -040056- (void)windowDidLoad
57{
Alexandre Lision745e4d62015-03-22 20:03:10 -040058 [super windowDidLoad];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040059 [chooseActiontWC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040060 [linkAccountWC setDelegate:self];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040061 [newAccountWC setDelegate:self];
Loïc Siret3652cfb2016-10-27 10:12:07 -040062 [self.window setBackgroundColor:[NSColor ringGreyHighlight]];
63 [self showChooseWithCancelButton:isCancelable];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040064}
Alexandre Lision34607032016-02-08 16:16:49 -050065
Loïc Siretfcb4ca62016-09-21 17:12:09 -040066- (void)removeSubviews
67{
68 while ([self.container.subviews count] > 0)
69 {
70 [[self.container.subviews firstObject] removeFromSuperview];
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -040071 }
Alexandre Lision745e4d62015-03-22 20:03:10 -040072}
73
Loïc Siret3652cfb2016-10-27 10:12:07 -040074#define headerHeight 60
75#define minHeight 141
76#define defaultMargin 20
77- (void)showView:(NSView*)view
Alexandre Lision54187a22016-04-04 09:45:52 -040078{
Loïc Siretfcb4ca62016-09-21 17:12:09 -040079 [self removeSubviews];
80 NSRect frame = [self.container frame];
Loïc Siret3652cfb2016-10-27 10:12:07 -040081 float sizeFrame = MAX(minHeight, view.bounds.size.height);
82 frame.size.height = sizeFrame;
Loïc Siretfcb4ca62016-09-21 17:12:09 -040083 [view setFrame:frame];
Loïc Siret3652cfb2016-10-27 10:12:07 -040084
Loïc Siretfcb4ca62016-09-21 17:12:09 -040085 [self.container setFrame:frame];
Loïc Siret3652cfb2016-10-27 10:12:07 -040086 float size = headerHeight + sizeFrame + defaultMargin;
87 NSRect frameWindows = self.window.frame;
88 frameWindows.size.height = size;
89 [self.window setFrame:frameWindows display:YES animate:YES];
90
Loïc Siretfcb4ca62016-09-21 17:12:09 -040091 [self.container addSubview:view];
92}
93
94- (void)showChooseWithCancelButton:(BOOL)showCancel
95{
Loïc Siretfcb4ca62016-09-21 17:12:09 -040096 [chooseActiontWC showCancelButton:showCancel];
97 isCancelable = showCancel;
Loïc Siret3652cfb2016-10-27 10:12:07 -040098 [self showView:chooseActiontWC.view];
Loïc Siretfcb4ca62016-09-21 17:12:09 -040099}
100
101- (void)showNewAccountVC
102{
103 [self showView: newAccountWC.view];
104 [newAccountWC show];
105}
106
107- (void)showLinkAccountVC
108{
109 [self showView: linkAccountWC.view];
110 [linkAccountWC show];
Alexandre Lision745e4d62015-03-22 20:03:10 -0400111}
112
Alexandre Lisionb3f7ed62015-08-17 11:53:13 -0400113# pragma NSWindowDelegate methods
Alexandre Lision745e4d62015-03-22 20:03:10 -0400114
115- (void)windowWillClose:(NSNotification *)notification
116{
Loïc Siretfcb4ca62016-09-21 17:12:09 -0400117 if (!isCancelable){
118 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
119 if ([appDelegate checkForRingAccount]) {
120 [appDelegate showMainWindow];
121 }
122 }
123}
124
125#pragma - WizardChooseDelegate methods
126
127- (void)didCompleteWithAction:(WizardAction)action
128{
129 if (action == WIZARD_ACTION_LINK){
130 [self showLinkAccountVC];
131 } else if (action == WIZARD_ACTION_NEW){
132 [self showNewAccountVC];
133 } else {
134 [self.window close];
135 }
136
137}
138
139#pragma - WizardCreateAccountDelegate methods
140
141- (void)didCreateAccountWithSuccess:(BOOL)success
142{
143 if (success) {
144 [self.window close];
145 if (!isCancelable){
146 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
147 [appDelegate showMainWindow];
148 }
149 } else {
150 [self showChooseWithCancelButton:isCancelable];
151 }
152}
153
154#pragma - WizardLinkAccountDelegate methods
155
156- (void)didLinkAccountWithSuccess:(BOOL)success
157{
158 if (success) {
159 [self.window close];
160 if (!isCancelable){
161 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
162 [appDelegate showMainWindow];
163 }
164 } else {
165 [self showChooseWithCancelButton:isCancelable];
Alexandre Lision76d59692016-01-20 18:06:05 -0500166 }
Alexandre Lision745e4d62015-03-22 20:03:10 -0400167}
168
169@end