blob: 98b62ea24cb4b0823172215c1549ed8eb7786475 [file] [log] [blame]
Kateryna Kostiuk4db61092019-10-17 16:57:40 -04001/*
2 * Copyright (C) 2019 Savoir-faire Linux Inc.
3 * Author: Kateryna Kostiuk <kateryna.kostiuk@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 "CallInConferenceVC.h"
21#import "views/IconButton.h"
22#import "NSString+Extensions.h"
23
24///LRC
25#import <api/newcallmodel.h>
26#import <api/account.h>
27#import <api/contactmodel.h>
28#import <api/contact.h>
29
30@interface CallInConferenceVC () {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040031 QString callUId;
Kateryna Kostiuk4db61092019-10-17 16:57:40 -040032 const lrc::api::account::Info *accountInfo;
33}
34
35@property (unsafe_unretained) IBOutlet NSTextField* contactNameLabel;
36@property (unsafe_unretained) IBOutlet NSTextField* callStateLabel;
37@property (unsafe_unretained) IBOutlet IconButton* cancelCallButton;
38@property QMetaObject::Connection callStateChanged;
39
40@end
41
42@implementation CallInConferenceVC
43@synthesize cancelCallButton,callStateLabel,contactNameLabel;
44
45-(id) initWithNibName:(NSString *)nibNameOrNil
46 bundle:(NSBundle *)nibBundleOrNil
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040047 callId:(const QString&)callId
Kateryna Kostiuk4db61092019-10-17 16:57:40 -040048 accountInfo:(const lrc::api::account::Info *)accInfo {
49 if (self = [self initWithNibName: nibNameOrNil bundle:nibBundleOrNil])
50 {
51 callUId = callId;
52 accountInfo = accInfo;
53 }
54 return self;
55}
56
57- (void)viewDidLoad {
58 [super viewDidLoad];
59 auto* callModel = accountInfo->callModel.get();
60 auto currentCall = callModel->getCall(callUId);
61 auto uri = currentCall.peerUri;
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040062 try {
63 auto contact = accountInfo->contactModel->getContact(uri);
64 NSString *name = contact.profileInfo.alias.toNSString();
65 name = [name removeEmptyLinesAtBorders];
66 if (name.length == 0) {
67 name = contact.registeredName.toNSString();
68 }
69 name = [name removeEmptyLinesAtBorders];
70 if (name.length == 0) {
71 name = contact.profileInfo.uri.toNSString();
72 }
73 self.contactNameLabel.stringValue = [name removeEmptyLinesAtBorders];
74 } catch (std::out_of_range& e) {
75 return;
Kateryna Kostiuk4db61092019-10-17 16:57:40 -040076 }
Kateryna Kostiuk4db61092019-10-17 16:57:40 -040077 QObject::disconnect(self.callStateChanged);
78 self.callStateChanged = QObject::connect(callModel,
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040079 &lrc::api::NewCallModel::callStatusChanged,
80 [self](const QString& callId) {
81 if (callId == callUId) {
82 [self updateCall];
83 }
84 });
Kateryna Kostiuk4db61092019-10-17 16:57:40 -040085}
86
87-(void) updateCall
88{
89 if (accountInfo == nil)
90 return;
91
92 auto* callModel = accountInfo->callModel.get();
93 if (not callModel->hasCall(callUId)) {
94 return;
95 }
96
97 auto currentCall = callModel->getCall(callUId);
98 using Status = lrc::api::call::Status;
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040099 callStateLabel.stringValue = to_string(currentCall.status).toNSString();
Kateryna Kostiuk4db61092019-10-17 16:57:40 -0400100 switch (currentCall.status) {
101 case Status::IN_PROGRESS:
102 case Status::ENDED:
103 case Status::TERMINATING:
104 case Status::PEER_BUSY:
105 case Status::TIMEOUT:
106 case Status::INVALID: {
107 QObject::disconnect(self.callStateChanged);
108 [self.delegate removePreviewForContactUri: currentCall.peerUri forCall: self.initiatorCallId];
109 break;
110 }
111 }
112}
113
114- (void)awakeFromNib
115{
116 contactNameLabel.textColor = [NSColor textColor];
117 callStateLabel.textColor = [NSColor textColor];
118}
119
120- (IBAction)hangUp:(id)sender {
121 if (accountInfo == nil)
122 return;
123
124 auto* callModel = accountInfo->callModel.get();
125 callModel->hangUp(callUId);
126}
127
128@end