Loïc Siret | 31d5cc0 | 2016-09-08 14:38:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
| 3 | * Author: Loïc Siret <loic.siret@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. |
| 18 | */ |
| 19 | |
| 20 | #import "AbstractLoadingWC.h" |
| 21 | |
| 22 | @interface AbstractLoadingWC() <NSTextFieldDelegate> |
| 23 | { |
| 24 | |
| 25 | } |
| 26 | @end |
| 27 | |
| 28 | @implementation AbstractLoadingWC |
| 29 | { |
| 30 | struct { |
| 31 | unsigned int didComplete:1; |
| 32 | unsigned int didCompleteWithActionCode:1; |
| 33 | } delegateRespondsTo; |
| 34 | } |
| 35 | |
| 36 | - (id)initWithWindowNibName:(NSString *)nibName delegate:(id <LoadingWCDelegate>) del actionCode:(NSInteger) code |
| 37 | { |
| 38 | if ((self = [super initWithWindowNibName:nibName]) != nil) { |
| 39 | [self setDelegate:del]; |
| 40 | self.actionCode = code; |
| 41 | } |
| 42 | return self; |
| 43 | } |
| 44 | |
| 45 | - (id)initWithDelegate:(id <LoadingWCDelegate>) del actionCode:(NSInteger) code |
| 46 | { |
| 47 | [NSException raise:NSInternalInconsistencyException |
| 48 | format:@"You must override %@ in a subclass",NSStringFromSelector(_cmd)]; |
| 49 | return nil; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | - (void)windowDidLoad |
| 54 | { |
| 55 | [super windowDidLoad]; |
| 56 | [initialContainer setHidden:NO]; |
| 57 | [progressContainer setHidden:YES]; |
| 58 | [errorContainer setHidden:YES]; |
| 59 | [finalContainer setHidden:YES]; |
| 60 | } |
| 61 | |
| 62 | - (IBAction) cancelPressed:(id)sender |
| 63 | { |
| 64 | [self close]; |
| 65 | } |
| 66 | |
| 67 | - (IBAction)completeAction:(id)sender |
| 68 | { |
| 69 | [NSException raise:NSInternalInconsistencyException |
| 70 | format:@"You must override %@ in a subclass",NSStringFromSelector(_cmd)]; |
| 71 | } |
| 72 | |
| 73 | - (void)close |
| 74 | { |
| 75 | [NSApp endSheet:self.window]; |
| 76 | [self.window orderOut:self]; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | - (void)showLoading |
| 81 | { |
| 82 | [initialContainer setHidden:YES]; |
| 83 | [progressContainer setHidden:NO]; |
| 84 | [errorContainer setHidden:YES]; |
| 85 | [finalContainer setHidden:YES]; |
| 86 | } |
| 87 | |
| 88 | - (void)showError |
| 89 | { |
| 90 | [initialContainer setHidden:YES]; |
| 91 | [progressContainer setHidden:YES]; |
| 92 | [errorContainer setHidden:NO]; |
| 93 | [finalContainer setHidden:YES]; |
| 94 | } |
| 95 | |
| 96 | - (void)showFinal |
| 97 | { |
| 98 | [initialContainer setHidden:YES]; |
| 99 | [progressContainer setHidden:YES]; |
| 100 | [errorContainer setHidden:YES]; |
| 101 | [finalContainer setHidden:NO]; |
| 102 | } |
| 103 | |
| 104 | @end |