RingWizardWC.mm 4.65 KB
Newer Older
1
/*
Alexandre Lision's avatar
Alexandre Lision committed
2
 *  Copyright (C) 2015-2016 Savoir-faire Linux Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */
#import "RingWizardWC.h"

Alexandre Lision's avatar
Alexandre Lision committed
21 22 23 24
//Cocoa
#import <AddressBook/AddressBook.h>
#import <Quartz/Quartz.h>

25 26

#import "AppDelegate.h"
Alexandre Lision's avatar
Alexandre Lision committed
27
#import "Constants.h"
28
#import "views/NSImage+Extensions.h"
Alexandre Lision's avatar
Alexandre Lision committed
29
#import "views/NSColor+RingTheme.h"
30 31 32
#import "RingWizardNewAccountVC.h"
#import "RingWizardLinkAccountVC.h"
#import "RingWizardChooseVC.h"
33

Alexandre Lision's avatar
Alexandre Lision committed
34

35
@interface RingWizardWC ()
36

37
@property (retain, nonatomic)IBOutlet NSView* container;
38

39 40 41 42 43 44 45
@end
@implementation RingWizardWC {
    IBOutlet RingWizardNewAccountVC* newAccountWC;
    IBOutlet RingWizardLinkAccountVC* linkAccountWC;
    IBOutlet RingWizardChooseVC* chooseActiontWC;
    BOOL isCancelable;
}
46

47 48 49 50 51 52 53 54 55
- (instancetype)initWithWindowNibName:(NSString *)windowNibName{
    self = [super initWithWindowNibName:windowNibName];

    chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
    linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil];
    newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
    return self;
}

56 57
- (void)windowDidLoad
{
58
    [super windowDidLoad];
59 60 61
    [chooseActiontWC setDelegate:self];
    [linkAccountWC setDelegate:self];
    [newAccountWC setDelegate:self];
62 63
    [self.window setBackgroundColor:[NSColor ringGreyHighlight]];
    [self showChooseWithCancelButton:isCancelable];
64 65
}

66
- (void)removeSubviews
Alexandre Lision's avatar
Alexandre Lision committed
67
{
68 69 70 71
    while ([self.container.subviews count] > 0)
    {
        [[self.container.subviews firstObject] removeFromSuperview];
    }
72 73
}

74 75 76 77
#define headerHeight 60
#define minHeight 141
#define defaultMargin 20
- (void)showView:(NSView*)view
78
{
79 80
    [self removeSubviews];
    NSRect frame = [self.container frame];
81 82
    float sizeFrame = MAX(minHeight, view.bounds.size.height);
    frame.size.height = sizeFrame;
83
    [view setFrame:frame];
84

85
    [self.container setFrame:frame];
86 87 88 89 90
    float size = headerHeight + sizeFrame + defaultMargin;
    NSRect frameWindows = self.window.frame;
    frameWindows.size.height = size;
    [self.window setFrame:frameWindows display:YES animate:YES];

91
    [self.container addSubview:view];
92 93
}

94
- (void)showChooseWithCancelButton:(BOOL)showCancel
95
{
96 97
    [chooseActiontWC showCancelButton:showCancel];
    isCancelable = showCancel;
98
    [self showView:chooseActiontWC.view];
99 100
}

101
- (void)showNewAccountVC
102
{
103 104
    [self showView: newAccountWC.view];
    [newAccountWC show];
105 106
}

107
- (void)showLinkAccountVC
108
{
109 110
    [self showView: linkAccountWC.view];
    [linkAccountWC show];
111 112
}

113 114 115
# pragma NSWindowDelegate methods

- (void)windowWillClose:(NSNotification *)notification
116
{
117 118 119 120 121 122
    if (!isCancelable){
        AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
        if ([appDelegate checkForRingAccount]) {
            [appDelegate showMainWindow];
        }
    }
123 124
}

125
#pragma - WizardChooseDelegate methods
126

127
- (void)didCompleteWithAction:(WizardAction)action
128
{
129 130 131 132 133 134 135 136
    if (action == WIZARD_ACTION_LINK){
        [self showLinkAccountVC];
    } else if (action == WIZARD_ACTION_NEW){
        [self showNewAccountVC];
    } else {
        [self.window close];
    }

137 138
}

139
#pragma - WizardCreateAccountDelegate methods
140

141
- (void)didCreateAccountWithSuccess:(BOOL)success
142
{
143 144 145 146 147 148 149 150
    if (success) {
        [self.window close];
        if (!isCancelable){
            AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
            [appDelegate showMainWindow];
        }
    } else {
        [self showChooseWithCancelButton:isCancelable];
Alexandre Lision's avatar
Alexandre Lision committed
151
    }
152 153
}

154
#pragma - WizardLinkAccountDelegate methods
155

156
- (void)didLinkAccountWithSuccess:(BOOL)success
157
{
158 159 160 161 162 163 164 165
    if (success) {
        [self.window close];
        if (!isCancelable){
            AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
            [appDelegate showMainWindow];
        }
    } else {
        [self showChooseWithCancelButton:isCancelable];
166
    }
167 168 169
}

@end