Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -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 | 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" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 20 | #import <QuartzCore/QuartzCore.h> |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 21 | #include <qrencode.h> |
Anthony Léonard | 7959760 | 2017-11-13 15:47:09 -0500 | [diff] [blame] | 22 | #include <memory> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 23 | |
| 24 | //Qt |
| 25 | #import <QItemSelectionModel> |
| 26 | #import <QItemSelection> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 27 | |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 28 | //LRC |
Kateryna Kostiuk | 312f913 | 2017-04-18 12:09:06 -0400 | [diff] [blame] | 29 | #import <AvailableAccountModel.h> |
Anthony Léonard | 7959760 | 2017-11-13 15:47:09 -0500 | [diff] [blame] | 30 | #import <api/lrc.h> |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 31 | #import <api/account.h> |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 32 | #import <api/newaccountmodel.h> |
| 33 | #import <api/newcallmodel.h> |
| 34 | #import <api/behaviorcontroller.h> |
| 35 | #import <api/conversation.h> |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 36 | #import <api/contactmodel.h> |
| 37 | #import <api/contact.h> |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 38 | #import <api/datatransfermodel.h> |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 39 | #import <media/recordingmodel.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 40 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 41 | // Ring |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 42 | #import "AppDelegate.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 43 | #import "Constants.h" |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 44 | #import "CurrentCallVC.h" |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 45 | #import "MigrateRingAccountsWC.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 46 | #import "ConversationVC.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 47 | #import "PreferencesWC.h" |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 48 | #import "SmartViewVC.h" |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 49 | #import "views/IconButton.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 50 | #import "views/NSColor+RingTheme.h" |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 51 | #import "views/HoverButton.h" |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 52 | #import "utils.h" |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 53 | #import "RingWizardWC.h" |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 54 | #import "AccountSettingsVC.h" |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 55 | #import "views/CallLayer.h" |
| 56 | |
| 57 | typedef NS_ENUM(NSInteger, ViewState) { |
| 58 | SHOW_WELCOME_SCREEN = 0, |
| 59 | SHOW_CONVERSATION_SCREEN, |
| 60 | SHOW_CALL_SCREEN, |
| 61 | SHOW_SETTINGS_SCREEN, |
| 62 | }; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 63 | |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 64 | @interface RingWindowController () <MigrateRingAccountsDelegate> |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 65 | |
| 66 | @property (retain) MigrateRingAccountsWC* migrateWC; |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 67 | @property RingWizardWC* wizard; |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 68 | |
| 69 | @end |
| 70 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 71 | @implementation RingWindowController { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 72 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 73 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint; |
| 74 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYWelcomeContainerConstraint; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 75 | IBOutlet NSLayoutConstraint* ringLabelTrailingConstraint; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 76 | __unsafe_unretained IBOutlet NSView* welcomeContainer; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 77 | __unsafe_unretained IBOutlet NSView* callView; |
| 78 | __unsafe_unretained IBOutlet NSTextField* ringIDLabel; |
Kateryna Kostiuk | 85a334e | 2018-12-03 15:54:19 -0500 | [diff] [blame^] | 79 | __unsafe_unretained IBOutlet NSTextField* explanationLabel; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 80 | __unsafe_unretained IBOutlet NSButton* shareButton; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 81 | __unsafe_unretained IBOutlet NSImageView* qrcodeView; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 82 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 83 | PreferencesWC* preferencesWC; |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 84 | IBOutlet SmartViewVC* smartViewVC; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 85 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 86 | CurrentCallVC* currentCallVC; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 87 | ConversationVC* conversationVC; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 88 | AccountSettingsVC* settingsVC; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 89 | |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 90 | // toolbar menu items |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 91 | IBOutlet ChooseAccountVC* chooseAccountVC; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 92 | } |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 93 | |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 94 | static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier"; |
| 95 | NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier"; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 96 | NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemIdentifier"; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 97 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 98 | @synthesize dataTransferModel, accountModel, behaviorController; |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 99 | @synthesize wizard; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 100 | |
| 101 | -(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController |
| 102 | { |
| 103 | if (self = [self initWithWindowNibName:nibNameOrNil]) |
| 104 | { |
| 105 | self.accountModel = accountModel; |
| 106 | self.dataTransferModel = dataTransferModel; |
| 107 | self.behaviorController = behaviorController; |
| 108 | } |
| 109 | return self; |
| 110 | } |
| 111 | |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 112 | - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions |
| 113 | { |
| 114 | return (NSApplicationPresentationFullScreen | |
| 115 | NSApplicationPresentationAutoHideMenuBar | |
| 116 | NSApplicationPresentationAutoHideToolbar); |
| 117 | } |
| 118 | |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 119 | -(void)changeViewTo:(ViewState) state { |
| 120 | switch (state) { |
| 121 | case SHOW_WELCOME_SCREEN: |
| 122 | [self accountSettingsShouldOpen: NO]; |
| 123 | [conversationVC hideWithAnimation:false]; |
| 124 | [currentCallVC hideWithAnimation:false]; |
Kateryna Kostiuk | 4f37d95 | 2018-12-04 13:19:17 -0500 | [diff] [blame] | 125 | [currentCallVC cleanUp]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 126 | [currentCallVC.view removeFromSuperview]; |
| 127 | [welcomeContainer setHidden: NO]; |
| 128 | [smartViewVC.view setHidden: NO]; |
| 129 | [settingsVC hide]; |
| 130 | break; |
| 131 | case SHOW_CONVERSATION_SCREEN: |
| 132 | [self accountSettingsShouldOpen: NO]; |
| 133 | [conversationVC showWithAnimation:false]; |
| 134 | [currentCallVC hideWithAnimation:false]; |
Kateryna Kostiuk | 4f37d95 | 2018-12-04 13:19:17 -0500 | [diff] [blame] | 135 | [currentCallVC cleanUp]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 136 | [currentCallVC.view removeFromSuperview]; |
| 137 | [welcomeContainer setHidden: YES]; |
| 138 | [smartViewVC.view setHidden: NO]; |
| 139 | [settingsVC hide]; |
| 140 | break; |
| 141 | case SHOW_CALL_SCREEN: |
| 142 | [self accountSettingsShouldOpen: NO]; |
| 143 | if (![currentCallVC.view superview]) { |
| 144 | [callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil]; |
| 145 | [currentCallVC initFrame]; |
| 146 | [currentCallVC showWithAnimation:false]; |
| 147 | [conversationVC hideWithAnimation:false]; |
| 148 | [welcomeContainer setHidden: YES]; |
| 149 | [smartViewVC.view setHidden: NO]; |
| 150 | [settingsVC hide]; |
| 151 | } |
| 152 | [currentCallVC showWithAnimation:false]; |
| 153 | break; |
| 154 | case SHOW_SETTINGS_SCREEN: |
| 155 | @try { |
| 156 | [self accountSettingsShouldOpen: YES]; |
| 157 | } |
| 158 | @catch (NSException *ex) { |
| 159 | return; |
| 160 | } |
| 161 | [welcomeContainer setHidden: YES]; |
| 162 | [currentCallVC hideWithAnimation:false]; |
| 163 | [currentCallVC.view removeFromSuperview]; |
| 164 | [conversationVC hideWithAnimation:false]; |
| 165 | [smartViewVC.view setHidden: YES]; |
| 166 | [settingsVC show]; |
| 167 | break; |
| 168 | default: |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 173 | - (void)windowDidLoad { |
| 174 | [super windowDidLoad]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 175 | [self.window setMovableByWindowBackground:YES]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 176 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 177 | self.window.titleVisibility = NSWindowTitleHidden; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 178 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 179 | currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; |
Kateryna Kostiuk | 133364b | 2018-10-31 11:36:08 -0400 | [diff] [blame] | 180 | currentCallVC.delegate = self; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 181 | conversationVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self]; |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 182 | // toolbar items |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 183 | //chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:self.accountModel delegate:self]; |
| 184 | [chooseAccountVC updateWithDelegate: self andModel:self.accountModel]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 185 | settingsVC = [[AccountSettingsVC alloc] initWithNibName:@"AccountSettings" bundle:nil accountmodel:self.accountModel]; |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 186 | //[self.window.contentView addSubview:[chooseAccountVC view]]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 187 | [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 188 | [[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 189 | [[conversationVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 190 | [[settingsVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 191 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 192 | [callView addSubview:[conversationVC view] positioned:NSWindowAbove relativeTo:nil]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 193 | [self.window.contentView addSubview:[settingsVC view] positioned:NSWindowAbove relativeTo:nil]; |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 194 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 195 | [conversationVC initFrame]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 196 | [settingsVC initFrame]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 197 | @try { |
| 198 | [smartViewVC setConversationModel: [chooseAccountVC selectedAccount].conversationModel.get()]; |
| 199 | } |
| 200 | @catch (NSException *ex) { |
| 201 | NSLog(@"Caught exception %@: %@", [ex name], [ex reason]); |
| 202 | } |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 203 | |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 204 | // Fresh run, we need to make sure RingID appears |
| 205 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 206 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 207 | [self connect]; |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 208 | [self updateRingID]; |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 209 | // set download folder (default - 'Documents') |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 210 | NSString* path = [[NSUserDefaults standardUserDefaults] stringForKey:Preferences::DownloadFolder]; |
| 211 | if (!path || path.length == 0) { |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 212 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
| 213 | path = [[paths objectAtIndex:0] stringByAppendingString:@"/"]; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 214 | } |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 215 | self.dataTransferModel->downloadDirectory = std::string([path UTF8String]); |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 216 | if(appSandboxed()) { |
| 217 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
Kateryna Kostiuk | f9a72c0 | 2018-08-01 14:28:49 -0400 | [diff] [blame] | 218 | media::RecordingModel::instance().setRecordPath(QString::fromNSString([paths objectAtIndex:0])); |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 219 | } |
Kateryna Kostiuk | ef66f97 | 2018-11-02 17:10:37 -0400 | [diff] [blame] | 220 | NSToolbar *tb = [[self window] toolbar]; |
| 221 | [tb setAllowsUserCustomization:NO]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | - (void) connect |
| 225 | { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 226 | QObject::connect(self.behaviorController, |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 227 | &lrc::api::BehaviorController::showCallView, |
| 228 | [self](const std::string accountId, |
| 229 | const lrc::api::conversation::Info convInfo){ |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 230 | auto* accInfo = &self.accountModel->getAccountInfo(accountId); |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 231 | if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING) |
| 232 | [smartViewVC selectPendingList]; |
| 233 | else |
| 234 | [smartViewVC selectConversationList]; |
| 235 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 236 | [currentCallVC setCurrentCall:convInfo.callId |
| 237 | conversation:convInfo.uid |
| 238 | account:accInfo]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 239 | [self changeViewTo:SHOW_CALL_SCREEN]; |
| 240 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 241 | }); |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 242 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 243 | QObject::connect(self.behaviorController, |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 244 | &lrc::api::BehaviorController::showIncomingCallView, |
| 245 | [self](const std::string accountId, |
| 246 | const lrc::api::conversation::Info convInfo){ |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 247 | auto* accInfo = &self.accountModel->getAccountInfo(accountId); |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 248 | if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING) |
| 249 | [smartViewVC selectPendingList]; |
| 250 | else |
| 251 | [smartViewVC selectConversationList]; |
| 252 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 253 | [currentCallVC setCurrentCall:convInfo.callId |
| 254 | conversation:convInfo.uid |
| 255 | account:accInfo]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 256 | [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 257 | [self changeViewTo:SHOW_CALL_SCREEN]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 258 | }); |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 259 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 260 | QObject::connect(self.behaviorController, |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 261 | &lrc::api::BehaviorController::showChatView, |
| 262 | [self](const std::string& accountId, |
| 263 | const lrc::api::conversation::Info& convInfo){ |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 264 | auto& accInfo = self.accountModel->getAccountInfo(accountId); |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 265 | [conversationVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 266 | [smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 267 | [self changeViewTo:SHOW_CONVERSATION_SCREEN]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 268 | }); |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Implement the necessary logic to choose which Ring ID to display. |
| 273 | * This tries to choose the "best" ID to show |
| 274 | */ |
| 275 | - (void) updateRingID |
| 276 | { |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 277 | @try { |
| 278 | auto& account = [chooseAccountVC selectedAccount]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 279 | |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 280 | [ringIDLabel setStringValue:@""]; |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 281 | |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 282 | if(account.profileInfo.type != lrc::api::profile::Type::RING) { |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 283 | self.notRingAccount = YES; |
| 284 | self.isSIPAccount = YES; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 285 | return; |
| 286 | } |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 287 | self.isSIPAccount = NO; |
| 288 | self.notRingAccount = NO; |
| 289 | [ringLabelTrailingConstraint setActive:YES]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 290 | auto& registeredName = account.registeredName; |
| 291 | auto& ringID = account.profileInfo.uri; |
| 292 | NSString* uriToDisplay = nullptr; |
| 293 | if (!registeredName.empty()) { |
| 294 | uriToDisplay = @(registeredName.c_str()); |
Kateryna Kostiuk | 85a334e | 2018-12-03 15:54:19 -0500 | [diff] [blame^] | 295 | [explanationLabel setStringValue: NSLocalizedString(@"This is your Jami username. \nCopy and share it with your friends!", @"Explanation label when user have Jami username")]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 296 | } else { |
| 297 | uriToDisplay = @(ringID.c_str()); |
Kateryna Kostiuk | 85a334e | 2018-12-03 15:54:19 -0500 | [diff] [blame^] | 298 | [explanationLabel setStringValue: NSLocalizedString(@"This is your ID. \nCopy and share it with your friends!", @"Explanation label when user have just ID")]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 299 | } |
| 300 | [ringIDLabel setStringValue:uriToDisplay]; |
| 301 | [self drawQRCode:@(ringID.c_str())]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 302 | } |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 303 | @catch (NSException *ex) { |
| 304 | NSLog(@"Caught exception %@: %@", [ex name], [ex reason]); |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 305 | self.notRingAccount = YES; |
| 306 | self.isSIPAccount = NO; |
| 307 | [ringLabelTrailingConstraint setActive:NO]; |
Anthony Léonard | 70638f0 | 2018-02-05 11:10:19 -0500 | [diff] [blame] | 308 | [ringIDLabel setStringValue:NSLocalizedString(@"No account available", @"Displayed as RingID when no accounts are available for selection")]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 309 | } |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 310 | } |
| 311 | |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 312 | - (IBAction)shareRingID:(id)sender { |
| 313 | NSSharingServicePicker* sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObject:[ringIDLabel stringValue]]]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 314 | [sharingServicePicker setDelegate:self]; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 315 | [sharingServicePicker showRelativeToRect:[sender bounds] |
| 316 | ofView:sender |
| 317 | preferredEdge:NSMinYEdge]; |
| 318 | } |
| 319 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 320 | - (IBAction)toggleQRCode:(id)sender { |
| 321 | // Toggle pressed state of QRCode button |
Kateryna Kostiuk | 85a334e | 2018-12-03 15:54:19 -0500 | [diff] [blame^] | 322 | // [sender setPressed:![sender isPressed]]; |
| 323 | bool show = qrcodeView.animator.alphaValue == 0.0f ? YES: NO; |
| 324 | [self showQRCode: show]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Draw the QRCode in the qrCodeView |
| 329 | */ |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 330 | - (void)drawQRCode:(NSString*) uriToDraw |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 331 | { |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 332 | auto qrCode = QRcode_encodeString(uriToDraw.UTF8String, |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 333 | 0, |
| 334 | QR_ECLEVEL_L, // Lowest level of error correction |
| 335 | QR_MODE_8, // 8-bit data mode |
| 336 | 1); |
| 337 | if (!qrCode) { |
| 338 | return; |
| 339 | } |
| 340 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 341 | unsigned char *data = 0; |
| 342 | int width; |
| 343 | data = qrCode->data; |
| 344 | width = qrCode->width; |
| 345 | int qr_margin = 3; |
| 346 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 347 | CGFloat size = qrcodeView.frame.size.width; |
| 348 | |
| 349 | // create context |
| 350 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 351 | CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, kCGImageAlphaPremultipliedLast); |
| 352 | |
| 353 | CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size); |
| 354 | CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1); |
| 355 | CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform)); |
| 356 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 357 | float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin)); |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 358 | CGRect rectDraw = CGRectMake(0, 0, zoom, zoom); |
| 359 | |
| 360 | int ran; |
| 361 | for(int i = 0; i < width; ++i) { |
| 362 | for(int j = 0; j < width; ++j) { |
| 363 | if(*data & 1) { |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 364 | CGContextSetFillColorWithColor(ctx, [NSColor labelColor].CGColor); |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 365 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 366 | CGContextAddRect(ctx, rectDraw); |
| 367 | CGContextFillPath(ctx); |
| 368 | } else { |
| 369 | CGContextSetFillColorWithColor(ctx, [NSColor windowBackgroundColor].CGColor); |
| 370 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 371 | CGContextAddRect(ctx, rectDraw); |
| 372 | CGContextFillPath(ctx); |
| 373 | } |
| 374 | ++data; |
| 375 | } |
| 376 | } |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 377 | |
| 378 | // get image |
| 379 | auto qrCGImage = CGBitmapContextCreateImage(ctx); |
| 380 | auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size]; |
| 381 | |
| 382 | // some releases |
| 383 | CGContextRelease(ctx); |
| 384 | CGImageRelease(qrCGImage); |
| 385 | CGColorSpaceRelease(colorSpace); |
| 386 | QRcode_free(qrCode); |
| 387 | |
| 388 | [qrcodeView setImage:qrImage]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Start the in/out animation displaying the QRCode |
| 393 | * @param show should the QRCode be animated in or out |
| 394 | */ |
| 395 | - (void) showQRCode:(BOOL) show |
| 396 | { |
| 397 | static const NSInteger offset = 110; |
| 398 | [NSAnimationContext beginGrouping]; |
| 399 | NSAnimationContext.currentContext.duration = 0.5; |
| 400 | [[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; |
| 401 | qrcodeView.animator.alphaValue = show ? 1.0 : 0.0; |
| 402 | [centerYQRCodeConstraint.animator setConstant: show ? offset : 0]; |
| 403 | [centerYWelcomeContainerConstraint.animator setConstant:show ? -offset : 0]; |
| 404 | [NSAnimationContext endGrouping]; |
| 405 | } |
| 406 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 407 | - (IBAction)openPreferences:(id)sender |
| 408 | { |
Kateryna Kostiuk | bb68a1c | 2018-06-12 15:16:02 -0400 | [diff] [blame] | 409 | if (preferencesWC) { |
| 410 | [preferencesWC.window orderFront:preferencesWC.window]; |
| 411 | return; |
| 412 | } |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 413 | |
| 414 | preferencesWC = [[PreferencesWC alloc] initWithWindowNibName: @"PreferencesWindow" bundle: nil accountModel:self.accountModel dataTransferModel:self.dataTransferModel behaviourController:self.behaviorController]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 415 | [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 416 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 417 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 418 | - (IBAction)callClickedAtRow:(id)sender |
| 419 | { |
| 420 | NSTabViewItem *selectedTab = [smartViewVC.tabbar selectedTabViewItem]; |
| 421 | int index = [smartViewVC.tabbar indexOfTabViewItem:selectedTab]; |
| 422 | switch (index) { |
| 423 | case 0: |
| 424 | [smartViewVC startCallForRow:sender]; |
| 425 | break; |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 426 | default: |
| 427 | break; |
| 428 | } |
| 429 | } |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 430 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 431 | #pragma mark - Ring account migration |
| 432 | |
| 433 | - (void) migrateRingAccount:(Account*) acc |
| 434 | { |
| 435 | self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1]; |
| 436 | self.migrateWC.account = acc; |
| 437 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 438 | [self.window beginSheet:self.migrateWC.window completionHandler:nil]; |
| 439 | #else |
| 440 | [NSApp beginSheet: self.migrateWC.window |
| 441 | modalForWindow: self.window |
| 442 | modalDelegate: self |
| 443 | didEndSelector: nil |
| 444 | contextInfo: nil]; |
| 445 | #endif |
| 446 | } |
| 447 | |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 448 | // TODO: Reimplement as a blocking loop when new LRC models handle migration |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 449 | - (void)checkAccountsToMigrate |
| 450 | { |
| 451 | auto ringList = AccountModel::instance().accountsToMigrate(); |
| 452 | if (ringList.length() > 0){ |
| 453 | Account* acc = ringList.value(0); |
| 454 | [self migrateRingAccount:acc]; |
| 455 | } else { |
| 456 | // Fresh run, we need to make sure RingID appears |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 457 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 458 | |
| 459 | [self connect]; |
Kateryna Kostiuk | a724846 | 2017-04-18 16:15:31 -0400 | [diff] [blame] | 460 | [self updateRingID]; |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
| 464 | - (void)migrationDidComplete |
| 465 | { |
| 466 | [self checkAccountsToMigrate]; |
| 467 | } |
| 468 | |
| 469 | - (void)migrationDidCompleteWithError |
| 470 | { |
| 471 | [self checkAccountsToMigrate]; |
| 472 | } |
| 473 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 474 | - (void) selectAccount:(const lrc::api::account::Info&)accInfo currentRemoved:(BOOL) removed |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 475 | { |
| 476 | // If the selected account has been changed, we close any open panel |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 477 | [smartViewVC setConversationModel:accInfo.conversationModel.get()]; |
Anthony Léonard | 61e3dcf | 2017-12-27 12:19:52 -0500 | [diff] [blame] | 478 | // Welcome view informations are also updated |
| 479 | [self updateRingID]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 480 | [settingsVC setSelectedAccount:accInfo.id]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 481 | [self changeViewTo: ([settingsVC.view isHidden] || removed) ? SHOW_WELCOME_SCREEN : SHOW_SETTINGS_SCREEN]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 482 | } |
| 483 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 484 | -(void)allAccountsDeleted |
| 485 | { |
| 486 | [smartViewVC clearConversationModel]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 487 | [self changeViewTo:SHOW_WELCOME_SCREEN]; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 488 | [self updateRingID]; |
| 489 | } |
| 490 | |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 491 | -(void)rightPanelClosed |
| 492 | { |
| 493 | [smartViewVC deselect]; |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 494 | [welcomeContainer setHidden:NO]; |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 495 | } |
| 496 | |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 497 | -(void)currentConversationTrusted |
| 498 | { |
| 499 | [smartViewVC selectConversationList]; |
| 500 | } |
| 501 | |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 502 | -(void) listTypeChanged { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 503 | [self changeViewTo:SHOW_WELCOME_SCREEN]; |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 504 | } |
| 505 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 506 | - (IBAction)openAccountSettings:(NSButton *)sender |
| 507 | { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 508 | [self changeViewTo: [settingsVC.view isHidden] ? SHOW_SETTINGS_SCREEN : SHOW_WELCOME_SCREEN]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 511 | - (void) createNewAccount { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 512 | [self changeViewTo:SHOW_WELCOME_SCREEN]; |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 513 | wizard = [[RingWizardWC alloc] initWithNibName:@"RingWizard" bundle: nil accountmodel: self.accountModel]; |
| 514 | [wizard showChooseWithCancelButton: YES andAdvanced: YES]; |
| 515 | [self.window beginSheet:wizard.window completionHandler:nil]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Kateryna Kostiuk | 23222fe | 2018-11-16 14:28:02 -0500 | [diff] [blame] | 518 | - (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet |
| 519 | usingRect:(NSRect)rect |
| 520 | { |
| 521 | float titleBarHeight = self.window.frame.size.height - [NSWindow contentRectForFrameRect:self.window.frame styleMask:self.window.styleMask].size.height; |
| 522 | rect.origin.y = self.window.frame.size.height; |
| 523 | return rect; |
| 524 | } |
| 525 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 526 | -(void) accountSettingsShouldOpen: (BOOL) open { |
| 527 | if (open) { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 528 | [settingsVC setSelectedAccount: [chooseAccountVC selectedAccount].id]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 529 | } |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 530 | } |
| 531 | |
Kateryna Kostiuk | 133364b | 2018-10-31 11:36:08 -0400 | [diff] [blame] | 532 | #pragma mark - CallViewControllerDelegate |
| 533 | |
| 534 | -(void) conversationInfoUpdatedFor:(const std::string&) conversationID { |
| 535 | [smartViewVC reloadConversationWithUid:@(conversationID.c_str())]; |
| 536 | } |
| 537 | |
Kateryna Kostiuk | e350384 | 2018-12-12 16:39:45 -0500 | [diff] [blame] | 538 | -(void) showConversation:(NSString* )conversationId forAccount:(NSString*)accountId { |
| 539 | auto& accInfo = self.accountModel->getAccountInfo([accountId UTF8String]); |
| 540 | [chooseAccountVC selectAccount: accountId]; |
| 541 | [settingsVC setSelectedAccount: [accountId UTF8String]]; |
| 542 | [smartViewVC setConversationModel:accInfo.conversationModel.get()]; |
| 543 | [smartViewVC selectConversationList]; |
| 544 | [self updateRingID]; |
| 545 | auto convInfo = getConversationFromUid([conversationId UTF8String], *accInfo.conversationModel.get()); |
| 546 | auto convQueue = accInfo.conversationModel.get()->allFilteredConversations(); |
| 547 | if (convInfo != convQueue.end()) { |
| 548 | [conversationVC setConversationUid:convInfo->uid model:accInfo.conversationModel.get()]; |
| 549 | [smartViewVC selectConversation: *convInfo model:accInfo.conversationModel.get()]; |
| 550 | accInfo.conversationModel.get()->clearUnreadInteractions([conversationId UTF8String]); |
| 551 | } |
| 552 | [self changeViewTo:SHOW_CONVERSATION_SCREEN]; |
| 553 | } |
| 554 | |
| 555 | -(void) showCall:(NSString* )callId forAccount:(NSString*)accountId forConversation:(NSString*)conversationId { |
| 556 | auto& accInfo = self.accountModel->getAccountInfo([accountId UTF8String]); |
| 557 | [chooseAccountVC selectAccount: accountId]; |
| 558 | [settingsVC setSelectedAccount:accInfo.id]; |
| 559 | [smartViewVC setConversationModel:accInfo.conversationModel.get()]; |
| 560 | [self updateRingID]; |
| 561 | auto convInfo = getConversationFromUid([conversationId UTF8String], *accInfo.conversationModel.get()); |
| 562 | auto convQueue = accInfo.conversationModel.get()->allFilteredConversations(); |
| 563 | if (convInfo != convQueue.end()) { |
| 564 | if (accInfo.contactModel->getContact(convInfo->participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING) |
| 565 | [smartViewVC selectPendingList]; |
| 566 | else |
| 567 | [smartViewVC selectConversationList]; |
| 568 | [smartViewVC selectConversation: *convInfo model:accInfo.conversationModel.get()]; |
| 569 | } |
| 570 | [currentCallVC setCurrentCall:[callId UTF8String] |
| 571 | conversation:[conversationId UTF8String] |
| 572 | account:&accInfo]; |
| 573 | [self changeViewTo:SHOW_CALL_SCREEN]; |
| 574 | } |
| 575 | |
| 576 | -(void) showContactRequestFor:(NSString* )accountId contactUri:(NSString*)uri { |
| 577 | auto& accInfo = self.accountModel->getAccountInfo([accountId UTF8String]); |
| 578 | [chooseAccountVC selectAccount: accountId]; |
| 579 | [settingsVC setSelectedAccount:accInfo.id]; |
| 580 | [smartViewVC setConversationModel:accInfo.conversationModel.get()]; |
| 581 | [self updateRingID]; |
| 582 | [smartViewVC selectPendingList]; |
| 583 | auto convInfo = getConversationFromURI([uri UTF8String], *accInfo.conversationModel.get()); |
| 584 | auto convQueue = accInfo.conversationModel.get()->allFilteredConversations(); |
| 585 | if (convInfo != convQueue.end()) { |
| 586 | [conversationVC setConversationUid:convInfo->uid model:accInfo.conversationModel.get()]; |
| 587 | [smartViewVC selectConversation: *convInfo model:accInfo.conversationModel.get()]; |
| 588 | } |
| 589 | [self changeViewTo:SHOW_CONVERSATION_SCREEN]; |
| 590 | } |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 591 | @end |