Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015 Savoir-faire Linux Inc. |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -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 | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 18 | */ |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 19 | #import "RingWindowController.h" |
| 20 | |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 21 | //LRC |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 22 | #import <accountmodel.h> |
| 23 | #import <callmodel.h> |
| 24 | #import <account.h> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 25 | #import <call.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 26 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 27 | #import "AppDelegate.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 28 | #import "Constants.h" |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 29 | #import "CurrentCallVC.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 30 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 31 | #import "PreferencesWC.h" |
| 32 | #import "views/NSColor+RingTheme.h" |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 33 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 34 | @implementation RingWindowController { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 35 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 36 | __unsafe_unretained IBOutlet NSView *callView; |
| 37 | __unsafe_unretained IBOutlet NSTextField *ringIDLabel; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 38 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 39 | PreferencesWC *preferencesWC; |
| 40 | CurrentCallVC* currentVC; |
| 41 | } |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 42 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 43 | static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier"; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 44 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 45 | - (void)windowDidLoad { |
| 46 | [super windowDidLoad]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 47 | [self.window setMovableByWindowBackground:YES]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 48 | |
| 49 | currentVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; |
| 50 | [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 51 | [[currentVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 52 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 53 | [callView addSubview:[currentVC view] positioned:NSWindowAbove relativeTo:nil]; |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 54 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 55 | [currentVC initFrame]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 56 | |
Alexandre Lision | 08abfac | 2015-09-22 12:20:51 -0400 | [diff] [blame] | 57 | // Fresh run, we need to make sure RingID appears |
| 58 | [self updateRingID]; |
| 59 | |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 60 | // Update Ring ID label based on account model changes |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame^] | 61 | QObject::connect(&AccountModel::instance(), |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 62 | &AccountModel::dataChanged, |
| 63 | [=] { |
| 64 | [self updateRingID]; |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Implement the necessary logic to choose which Ring ID to display. |
| 70 | * This tries to choose the "best" ID to show |
| 71 | */ |
| 72 | - (void) updateRingID |
| 73 | { |
| 74 | Account* registered = nullptr; |
| 75 | Account* enabled = nullptr; |
| 76 | Account* finalChoice = nullptr; |
| 77 | |
| 78 | [ringIDLabel setStringValue:@""]; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame^] | 79 | auto ringList = AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING); |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 80 | for (int i = 0 ; i < ringList.size() && !registered ; ++i) { |
| 81 | Account* acc = ringList.value(i); |
| 82 | if (acc->isEnabled()) { |
| 83 | if(!enabled) |
| 84 | enabled = finalChoice = acc; |
| 85 | if (acc->registrationState() == Account::RegistrationState::READY) { |
| 86 | registered = enabled = finalChoice = acc; |
| 87 | } |
| 88 | } else { |
| 89 | if (!finalChoice) |
| 90 | finalChoice = acc; |
| 91 | } |
| 92 | } |
| 93 | |
Alexandre Lision | 7f8351b | 2015-08-20 11:43:37 -0400 | [diff] [blame] | 94 | [ringIDLabel setStringValue:[[NSString alloc] initWithFormat:@"%@", finalChoice->username().toNSString()]]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 97 | - (IBAction)openPreferences:(id)sender |
| 98 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 99 | preferencesWC = [[PreferencesWC alloc] initWithWindowNibName:@"PreferencesWindow"]; |
| 100 | [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 101 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 102 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 103 | @end |