blob: 8dbd78e1f79d6eec4dfa540a491d2663270be972 [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Sébastien Blin68abac92019-01-02 17:41:31 -05002 * Copyright (C) 2015-2019 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -04004 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> *
5 * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04006 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
Isa Nanic37ccc1c2018-10-26 14:16:28 -04007 * Author: Isa Nanic <isa.nanic@savoirfairelinux.com> *
Edric Milaret627500d2015-03-27 16:41:40 -04008 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 3 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
21 **************************************************************************/
22
23#include "callwidget.h"
24#include "ui_callwidget.h"
25
Andreas Traczyk912242e2018-10-29 14:44:44 -040026#include <QScrollBar>
Edric Milaret43f3c1e2015-07-16 17:52:47 -040027#include <QClipboard>
Edric Milaret70ae8782016-04-18 16:10:44 -040028#include <QDesktopServices>
Isa Nanic601de1d2018-10-23 11:37:26 -040029#include <QComboBox>
Andreas Traczyk43c08232018-10-31 13:42:09 -040030#include <QWebEngineScript>
Edric Milaret43f3c1e2015-07-16 17:52:47 -040031
Sébastien Blin942d1022018-12-13 09:49:03 -050032#include <algorithm>
Edric Milaret53f57b62015-05-11 11:02:17 -040033#include <memory>
Edric Milaret627500d2015-03-27 16:41:40 -040034
Edric Milarete19c4cd2016-02-12 10:19:44 -050035#include "qrencode.h"
36
Edric Milaret43f3c1e2015-07-16 17:52:47 -040037//ERROR is defined in windows.h
38#include "utils.h"
39#undef ERROR
Edric Milareta0ebd062016-01-13 12:18:23 -050040#undef interface
Edric Milaret43f3c1e2015-07-16 17:52:47 -040041
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040042// lrc
Edric Milareta0ebd062016-01-13 12:18:23 -050043#include "globalinstances.h"
Olivier SOLDANO69361192017-04-20 10:32:05 -040044#include "profilemodel.h"
Olivier SOLDANO69361192017-04-20 10:32:05 -040045#include "localprofilecollection.h"
Anthony Léonardd47179c2017-03-28 10:39:10 -040046
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040047// client
Edric Milaret559bda52015-04-29 17:02:31 -040048#include "wizarddialog.h"
Edric Milaret83b248c2015-06-02 11:42:23 -040049#include "windowscontactbackend.h"
Edric Milaret2cf34292015-06-22 16:27:03 -040050#include "globalsystemtray.h"
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040051#include "conversationitemdelegate.h"
Edric Milareta0ebd062016-01-13 12:18:23 -050052#include "pixbufmanipulator.h"
Edric Milaret70ae8782016-04-18 16:10:44 -040053#include "settingskey.h"
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040054#include "lrcinstance.h"
Andreas Traczyk43c08232018-10-31 13:42:09 -040055#include "animationhelpers.h"
56#include "ringthemeutils.h"
Edric Milaret25236d92016-03-28 09:40:58 -040057
Nicolas Jager97a21b42015-12-03 16:55:45 -050058CallWidget::CallWidget(QWidget* parent) :
Nicolas Jager74fe46f2016-02-29 14:55:09 -050059 NavWidget(parent),
Edric Milaret7d40a4a2015-05-13 13:01:15 -040060 ui(new Ui::CallWidget),
Andreas Traczyk43c08232018-10-31 13:42:09 -040061 menu_(new QMenu())
Edric Milaret627500d2015-03-27 16:41:40 -040062{
63 ui->setupUi(this);
64
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040065 using namespace lrc::api;
Nicolas Jagerca850292016-01-17 14:11:10 -050066
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040067 QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
Edric Milaret3aca8e32015-06-12 10:01:40 -040068
Sébastien Blincba5b522018-12-10 12:48:36 -050069 QPixmap logo(":/images/logo-jami-standard-coul.png");
Edric Milareted0b2802015-10-01 15:10:02 -040070 ui->ringLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation));
71 ui->ringLogo->setAlignment(Qt::AlignHCenter);
72
Edric Milaret1e598592016-09-02 10:10:01 -040073 ui->qrLabel->hide();
Edric Milarete19c4cd2016-02-12 10:19:44 -050074
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040075 videoRenderer_ = nullptr;
Edric Milaret627500d2015-03-27 16:41:40 -040076
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040077 // this line is not welcome here, and must be removed
78 ProfileModel::instance().addCollection<LocalProfileCollection>(LoadOptions::FORCE_ENABLED);
Edric Milaret627500d2015-03-27 16:41:40 -040079
Andreas Traczyk43c08232018-10-31 13:42:09 -040080 QSettings settings;
81
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040082 // select last used account if stored in registry
83 auto accountList = LRCInstance::accountModel().getAccountList();
84 if (!accountList.empty()) {
85 std::string accountIdToStartWith;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040086 if (settings.contains(SettingsKey::selectedAccount)) {
87 accountIdToStartWith = settings
88 .value(SettingsKey::selectedAccount, true)
89 .value<QString>()
90 .toStdString();
91 if (Utils::indexInVector(accountList, accountIdToStartWith) == -1) {
92 accountIdToStartWith = accountList.at(0);
Olivier SOLDANOaf8f2822017-07-11 12:15:18 -040093 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040094 }
95 else {
96 accountIdToStartWith = accountList.at(0);
97 }
98 setSelectedAccount(accountIdToStartWith);
Isa Nanic601de1d2018-10-23 11:37:26 -040099 // get account index and set the currentAccountComboBox
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400100 auto index = Utils::indexInVector(accountList, accountIdToStartWith);
101 if (index != -1) {
Isa Nanic601de1d2018-10-23 11:37:26 -0400102 ui->currentAccountComboBox->setCurrentIndex(index);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400103 }
Edric Milaret627500d2015-03-27 16:41:40 -0400104 }
Olivier SOLDANO2100f1c2017-09-06 16:45:20 -0400105
Andreas Traczyk43c08232018-10-31 13:42:09 -0400106 if (settings.contains(SettingsKey::mainSplitterState)) {
107 auto splitterStates = settings.value(SettingsKey::mainSplitterState).toByteArray();
108 ui->mainActivitySplitter->restoreState(splitterStates);
109 }
110
111 ui->mainActivitySplitter->setCollapsible(0, false);
Sébastien Blin93bd2062018-12-17 15:57:16 -0500112 ui->mainActivitySplitter->setCollapsible(1, false);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400113 ui->splitter->setCollapsible(0, false);
114 ui->splitter->setCollapsible(1, false);
115
Isa Nanic601de1d2018-10-23 11:37:26 -0400116 //disable dropdown shadow on combobox
117 ui->currentAccountComboBox->view()->window()->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
118
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400119 // conversation list
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400120 ui->smartList->setContextMenuPolicy(Qt::CustomContextMenu);
121
122 // setup searchingfor mini spinner
123 miniSpinner_ = new QMovie(":/images/waiting.gif");
124 ui->spinnerLabel->setMovie(miniSpinner_);
125 ui->spinnerLabel->hide();
126
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400127 // connections
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400128 connect(ui->currentAccountComboBox, &CurrentAccountComboBox::settingsButtonClicked,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400129 this, &CallWidget::settingsButtonClicked);
130
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500131 connect(ui->currentAccountComboBox, &CurrentAccountComboBox::newAccountClicked,
132 [this]() {
133 emit NavigationRequested(ScreenEnum::WizardScreen);
134 });
135
Andreas Traczyk43c08232018-10-31 13:42:09 -0400136 connect(ui->videoWidget, &VideoView::setChatVisibility,
137 [this](bool visible) {
Sébastien Blin93bd2062018-12-17 15:57:16 -0500138 if (visible) {
139 ui->messagesWidget->show();
140 } else {
141 ui->messagesWidget->hide();
142 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400143 });
144
145 connect(ui->mainActivitySplitter, &QSplitter::splitterMoved,
146 [this](int pos, int index) {
Andreas Traczyk14c3e862018-12-26 14:02:30 -0500147 Q_UNUSED(index);
148 Q_UNUSED(pos);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400149 QSettings settings;
150 settings.setValue(SettingsKey::mainSplitterState, ui->mainActivitySplitter->saveState());
151 });
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400152
153 connect(ui->videoWidget, &VideoView::videoSettingsClicked,
154 this, &CallWidget::settingsButtonClicked);
155
Sébastien Blin62b08ac2018-12-14 16:18:04 -0500156 connect(ui->videoWidget, &VideoView::toggleFullScreenClicked,
157 this, &CallWidget::slotToggleFullScreenClicked);
158
159 connect(ui->videoWidget, &VideoView::closing,
160 this, &CallWidget::slotVideoViewDestroyed);
161
Andreas Traczyk43c08232018-10-31 13:42:09 -0400162 connect(ui->btnConversations, &QPushButton::clicked,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400163 this, &CallWidget::conversationsButtonClicked);
164
Andreas Traczyk43c08232018-10-31 13:42:09 -0400165 connect(ui->btnInvites, &QPushButton::clicked,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400166 this, &CallWidget::invitationsButtonClicked);
167
Andreas Traczyk43c08232018-10-31 13:42:09 -0400168 connect(ui->smartList, &QTreeView::customContextMenuRequested,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400169 this, &CallWidget::slotCustomContextMenuRequested);
170
171 connect(ui->smartList, &SmartListView::btnAcceptInviteClicked,
172 this, &CallWidget::slotAcceptInviteClicked);
173
174 connect(ui->smartList, &SmartListView::btnBlockInviteClicked,
175 this, &CallWidget::slotBlockInviteClicked);
176
177 connect(ui->smartList, &SmartListView::btnIgnoreInviteClicked,
178 this, &CallWidget::slotIgnoreInviteClicked);
179
180 connect(&LRCInstance::behaviorController(), &BehaviorController::showCallView,
181 this, &CallWidget::slotShowCallView);
182
183 connect(&LRCInstance::behaviorController(), &BehaviorController::showIncomingCallView,
184 this, &CallWidget::slotShowIncomingCallView);
185
186 connect(&LRCInstance::behaviorController(), &BehaviorController::showChatView,
187 this, &CallWidget::slotShowChatView);
Andreas Traczyk55f92cb2018-10-23 12:26:25 -0400188
Isa Nanic601de1d2018-10-23 11:37:26 -0400189 connect(ui->currentAccountComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
190 this, &CallWidget::slotAccountChanged);
191
Andreas Traczyk912242e2018-10-29 14:44:44 -0400192 connect(ui->sendContactRequestButton, &QPushButton::clicked,
193 this, &CallWidget::on_sendContactRequestButton_clicked);
194
195 connect(ui->btnAudioCall, &QPushButton::clicked,
196 this, &CallWidget::on_sendContactRequestButton_clicked);
197
198 connect(ui->btnVideoCall, &QPushButton::clicked,
199 this, &CallWidget::on_sendContactRequestButton_clicked);
200
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400201 connect(ui->currentAccountComboBox, QOverload<int>::of(&CurrentAccountComboBox::currentIndexChanged),
202 [this] {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400203 ui->btnConversations->setChecked(true);
204 ui->btnInvites->setChecked(false);
205 });
206
Andreas Traczyk43865372018-12-27 12:12:35 -0500207 connect(ui->messageView, &MessageWebView::conversationRemoved,
208 [this] {
209 backToWelcomePage();
210 });
211
Andreas Traczyk55f92cb2018-10-23 12:26:25 -0400212 // set first view to welcome view
213 ui->stackedWidget->setCurrentWidget(ui->welcomePage);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400214 ui->btnConversations->setChecked(true);
215
216 // chat view
217 ui->messageView->buildView();
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500218
Andreas Traczykb81281e2018-12-13 13:13:28 -0500219 // hide the call stack
220 ui->callStackWidget->hide();
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500221 ui->messagingHeaderWidget->show();
Andreas Traczykfc33a492018-12-14 13:53:13 -0500222
223 ui->containerWidget->setVisible(false);
Edric Milaret627500d2015-03-27 16:41:40 -0400224}
225
226CallWidget::~CallWidget()
227{
228 delete ui;
Edric Milaretc7ab5502015-06-15 11:18:02 -0400229 delete menu_;
Edric Milaret00a32252016-01-19 10:37:13 -0500230}
231
Andreas Traczykfc33a492018-12-14 13:53:13 -0500232void
233CallWidget::navigated(bool to)
234{
235 ui->containerWidget->setVisible(to);
236 if (to) {
237 updateSmartList();
238 connectConversationModel();
Andreas Traczyk3fc824d2019-01-02 15:20:21 -0500239 try {
240 auto accountList = LRCInstance::accountModel().getAccountList();
241 if (accountList.size() == 1) {
242 auto index = Utils::indexInVector(accountList, LRCInstance::getCurrAccId());
243 if (index != -1) {
244 slotAccountChanged(index);
245 }
246 }
247 } catch (...) {}
Andreas Traczykb15c83a2018-12-31 12:29:25 -0500248 ui->currentAccountComboBox->updateComboBoxDisplay();
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500249 auto selectedConvUid = LRCInstance::getSelectedConvUid();
250 auto convModel = LRCInstance::getCurrentConversationModel();
251 auto conversation = Utils::getConversationFromUid(selectedConvUid, *convModel);
252 if (!selectedConvUid.empty() && conversation != convModel->allFilteredConversations().end()) {
253 selectSmartlistItem(selectedConvUid);
254 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
255 } else {
256 backToWelcomePage();
257 }
Andreas Traczykfc33a492018-12-14 13:53:13 -0500258 } else {
259 QObject::disconnect(smartlistSelectionConnection_);
260 smartListModel_.reset(nullptr);
261 }
262}
263
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500264void CallWidget::updateCustomUI()
265{
266}
267
Andreas Traczykb81281e2018-12-13 13:13:28 -0500268int
269CallWidget::getLeftPanelWidth()
270{
271 return ui->currentAccountComboBox->width();
272}
273
Edric Milaret00a32252016-01-19 10:37:13 -0500274void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400275CallWidget::onIncomingMessage(const std::string& convUid,
276 uint64_t interactionId,
277 const lrc::api::interaction::Info& interaction)
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400278{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400279 Q_UNUSED(interactionId);
Edric Milaret00a32252016-01-19 10:37:13 -0500280 if (!QApplication::focusWidget()) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400281 auto convModel = LRCInstance::getCurrentConversationModel();
282 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500283 if (conversation == convModel->allFilteredConversations().end()) {
284 return;
285 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400286 auto bestName = Utils::bestNameForConversation(*conversation, *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400287 Utils::showSystemNotification(this,
288 QString(tr("Message incoming from %1"))
Andreas Traczyk43c08232018-10-31 13:42:09 -0400289 .arg(QString::fromStdString(bestName)));
Edric Milaret00a32252016-01-19 10:37:13 -0500290 }
Andreas Traczyk1d8159a2018-12-13 15:48:24 -0500291 updateConversationsFilterWidget();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500292 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400293 return;
294 }
295
296 auto convModel = LRCInstance::getCurrentConversationModel();
297 convModel->clearUnreadInteractions(convUid);
298 auto currentConversation = Utils::getConversationFromUid(convUid, *convModel);
299 if (currentConversation == convModel->allFilteredConversations().end()) {
300 return;
301 }
302 ui->messageView->printNewInteraction(*convModel, interactionId, interaction);
Edric Milareta0ebd062016-01-13 12:18:23 -0500303}
304
305void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400306CallWidget::setupSmartListContextMenu(const QPoint& pos)
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400307{
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400308 QPoint globalPos = ui->smartList->mapToGlobal(pos);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400309 auto index = ui->smartList->indexAt(pos);
310 if (not index.isValid()) {
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400311 return;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400312 }
313
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400314 auto convModel = LRCInstance::getCurrentConversationModel();
315 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID))
316 .value<QString>()
317 .toStdString();
318 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
319 auto contactUid = (*conversation).participants.at(0);
320 auto contact = LRCInstance::getCurrentAccountInfo().contactModel.get()->getContact(contactUid);
321
322 if (!Utils::isContactValid(contactUid, *convModel)) {
323 return;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400324 }
325
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400326 QMenu menu;
327
328 // video call
329 auto videoCallAction = new QAction(tr("Start video call"), this);
330 menu.addAction(videoCallAction);
331 connect(videoCallAction, &QAction::triggered,
332 [this, convUid, conversation, convModel]() {
333 convModel->placeCall(convUid);
334 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500335 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400336 selectConversation(*conversation, *convModel);
337 }
338 });
339 // audio call
340 auto audioCallAction = new QAction(tr("Start audio call"), this);
341 menu.addAction(audioCallAction);
342 connect(audioCallAction, &QAction::triggered,
343 [this, convUid, conversation, convModel]() {
344 convModel->placeAudioOnlyCall(convUid);
345 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500346 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400347 selectConversation(*conversation, *convModel);
348 }
349 });
350
351 if (contact.profileInfo.type == lrc::api::profile::Type::RING) {
352 // separator
353 menu.addSeparator();
354
355 // clear conversation
356 auto clearConversationAction = new QAction(tr("Clear conversation"), this);
357 menu.addAction(clearConversationAction);
358 connect(clearConversationAction, &QAction::triggered,
359 [convUid]() {
360 LRCInstance::getCurrentConversationModel()->clearHistory(convUid);
361 });
Sébastien Blin31fccce2018-12-13 11:27:05 -0500362 // remove contact
363 auto removeContactAction = new QAction(tr("Remove contact"), this);
364 menu.addAction(removeContactAction);
365 connect(removeContactAction, &QAction::triggered,
366 [convUid]() {
367 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
368 });
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400369 // block contact
370 auto blockContactAction = new QAction(tr("Block contact"), this);
371 menu.addAction(blockContactAction);
372 connect(blockContactAction, &QAction::triggered,
373 [convUid]() {
374 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
375 });
376
377 // separator
378 menu.addSeparator();
379
380 // copy number(infohash)
381 auto copyNumberAction = new QAction(tr("Copy number"), this);
382 menu.addAction(copyNumberAction);
383 connect(copyNumberAction, &QAction::triggered,
384 [contact]() {
385 QApplication::clipboard()->setText(
386 QString::fromStdString(contact.profileInfo.uri)
387 );
388 });
389 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400390 smartListModel_->isContextMenuOpen = true;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400391 menu.exec(globalPos);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400392 smartListModel_->isContextMenuOpen = false;
Edric Milareta0ebd062016-01-13 12:18:23 -0500393}
394
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400395void
396CallWidget::setupQRCode(QString ringID)
Edric Milarete19c4cd2016-02-12 10:19:44 -0500397{
Anthony Léonarda86a8972016-12-15 10:33:47 -0500398 auto rcode = QRcode_encodeString(ringID.toStdString().c_str(),
Edric Milaret6d0e5312016-04-04 16:30:22 -0400399 0, //Let the version be decided by libqrencode
400 QR_ECLEVEL_L, // Lowest level of error correction
Edric Milarete19c4cd2016-02-12 10:19:44 -0500401 QR_MODE_8, // 8-bit data mode
402 1);
403 if (not rcode) {
404 qWarning() << "Failed to generate QR code: " << strerror(errno);
405 return;
406 }
407
408 auto margin = 5;
409 int qrwidth = rcode->width + margin * 2;
410 QImage result(QSize(qrwidth, qrwidth), QImage::Format_Mono);
411 QPainter painter;
412 painter.begin(&result);
413 painter.setClipRect(QRect(0, 0, qrwidth, qrwidth));
414 painter.setPen(QPen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
415 painter.setBrush(Qt::black);
416 painter.fillRect(QRect(0, 0, qrwidth, qrwidth), Qt::white);
Edric Milaret74474f52016-05-16 13:36:23 -0400417 unsigned char* p;
Edric Milarete19c4cd2016-02-12 10:19:44 -0500418 p = rcode->data;
419 for(int y = 0; y < rcode->width; y++) {
Edric Milaret74474f52016-05-16 13:36:23 -0400420 unsigned char* row = (p + (y * rcode->width));
Edric Milarete19c4cd2016-02-12 10:19:44 -0500421 for(int x = 0; x < rcode->width; x++) {
422 if(*(row + x) & 0x1) {
423 painter.drawRect(margin + x, margin + y, 1, 1);
424 }
425 }
426
427 }
428 painter.end();
429 QRcode_free(rcode);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400430 ui->qrLabel->setPixmap(QPixmap::fromImage(result.scaled(QSize(qrSize_, qrSize_),
431 Qt::KeepAspectRatio)));
Edric Milarete19c4cd2016-02-12 10:19:44 -0500432}
433
Edric Milaret627500d2015-03-27 16:41:40 -0400434void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400435CallWidget::on_smartList_clicked(const QModelIndex& index)
Edric Milaret00d34f22016-05-09 16:30:29 -0400436{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400437 Q_UNUSED(index);
Edric Milaret627500d2015-03-27 16:41:40 -0400438}
439
440void
441CallWidget::on_acceptButton_clicked()
442{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400443 auto convModel = LRCInstance::getCurrentConversationModel();
444 auto callModel = LRCInstance::getCurrentCallModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500445 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400446 callModel->accept(conversation->callId);
Edric Milaret627500d2015-03-27 16:41:40 -0400447}
448
449void
450CallWidget::on_refuseButton_clicked()
451{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400452 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500453 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400454 LRCInstance::getCurrentCallModel()->hangUp(conversation->callId);
455 showConversationView();
Edric Milaret6456baa2015-05-21 12:18:07 -0400456}
Edric Milaretc7ab5502015-06-15 11:18:02 -0400457
458void
Edric Milareted0b2802015-10-01 15:10:02 -0400459CallWidget::on_cancelButton_clicked()
Edric Milaretd8528fa2015-07-07 14:13:51 -0400460{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400461 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500462 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400463 LRCInstance::getCurrentCallModel()->hangUp(conversation->callId);
464 showConversationView();
Edric Milaretd8528fa2015-07-07 14:13:51 -0400465}
Edric Milareted0b2802015-10-01 15:10:02 -0400466
467void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400468CallWidget::showConversationView()
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400469{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400470 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
471 ui->messageView->setFocus();
Sébastien Blin93bd2062018-12-17 15:57:16 -0500472 if (ui->messagesWidget->isHidden()) {
473 ui->messagesWidget->show();
474 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400475}
476
477void
478CallWidget::selectSmartlistItem(const std::string & convUid)
479{
480 if (convUid.empty()) {
481 return;
482 }
483 ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect);
484 auto convModel = LRCInstance::getCurrentConversationModel();
485 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
486 if (conversation == convModel->allFilteredConversations().end()) {
487 return;
488 }
489 auto contactURI = QString::fromStdString((*conversation).participants[0]);
490 if (contactURI.isEmpty() ||
491 convModel->owner.contactModel->getContact(contactURI.toStdString()).profileInfo.type == lrc::api::profile::Type::TEMPORARY) {
492 return;
493 }
494 for (int row = 0; row < smartListModel_->rowCount(); row++) {
495 QModelIndex index = smartListModel_->index(row);
496 auto indexContactURI = index.data(SmartListModel::Role::URI).value<QString>();
497 if (indexContactURI == contactURI) {
498 ui->smartList->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
499 return;
500 }
501 }
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400502}
503
504void
Nicolas Jager97a21b42015-12-03 16:55:45 -0500505CallWidget::on_smartList_doubleClicked(const QModelIndex& index)
Edric Milareted0b2802015-10-01 15:10:02 -0400506{
Olivier SOLDANO70279d32017-07-18 15:21:34 -0400507 if (!index.isValid())
508 return;
509
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500510 LRCInstance::getCurrentConversationModel()->placeCall(LRCInstance::getSelectedConvUid());
Edric Milareted0b2802015-10-01 15:10:02 -0400511
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500512 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(LRCInstance::getSelectedConvUid())));
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400513}
Olivier SOLDANOad0fabb2016-11-25 09:08:01 -0500514
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400515QImage
516CallWidget::imageForConv(const std::string& convUid)
517{
518 return Utils::conversationPhoto(convUid, LRCInstance::getCurrentAccountInfo());
519}
Olivier SOLDANOad0fabb2016-11-25 09:08:01 -0500520
Edric Milareted0b2802015-10-01 15:10:02 -0400521void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400522CallWidget::smartListSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Olivier SOLDANO61065ec2016-11-11 16:31:34 -0500523{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400524 Q_UNUSED(deselected);
525 QModelIndexList indices = selected.indexes();
526
527 if (indices.isEmpty()) {
Edric Milareted0b2802015-10-01 15:10:02 -0400528 return;
Anthony Léonardecfe7422017-05-04 14:14:37 -0400529 }
Edric Milareted0b2802015-10-01 15:10:02 -0400530
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400531 auto selectedIndex = indices.at(0);
Olivier SOLDANO703caba2016-11-15 16:18:55 -0500532
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400533 if (not selectedIndex.isValid()) {
534 return;
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400535 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400536
537 selectConversation(selectedIndex);
Edric Milareted0b2802015-10-01 15:10:02 -0400538}
539
540void
541CallWidget::placeCall()
542{
Nicolas Jager97a21b42015-12-03 16:55:45 -0500543 if (ui->ringContactLineEdit->text().isEmpty())
Edric Milareted0b2802015-10-01 15:10:02 -0400544 return;
Nicolas Jager97a21b42015-12-03 16:55:45 -0500545 Call* c = CallModel::instance().dialingCall(PhoneDirectoryModel::instance().getNumber(ui->ringContactLineEdit->text()));
Edric Milareted0b2802015-10-01 15:10:02 -0400546 c->performAction(Call::Action::ACCEPT);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500547 ui->ringContactLineEdit->clear();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400548 auto photoRect = ui->callingPhoto->frameGeometry();
Edric1bed3f92016-05-19 10:24:48 -0400549 ui->callingPhoto->setPixmap(
550 QPixmap::fromImage(
551 GlobalInstances::pixmapManipulator()
Andreas Traczyk43c08232018-10-31 13:42:09 -0400552 .callPhoto(c, QSize(photoRect.width(), photoRect.height()))
553 .value<QImage>()));
Edric Milareted0b2802015-10-01 15:10:02 -0400554}
555
556void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400557CallWidget::conversationsButtonClicked()
558{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400559 ui->btnConversations->setChecked(true);
560 ui->btnInvites->setChecked(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400561 setConversationFilter(lrc::api::profile::Type::RING);
562}
563
564void
565CallWidget::invitationsButtonClicked()
566{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400567 ui->btnConversations->setChecked(false);
568 ui->btnInvites->setChecked(true);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400569 setConversationFilter(lrc::api::profile::Type::PENDING);
570}
571
572void
Nicolas Jager74fe46f2016-02-29 14:55:09 -0500573CallWidget::settingsButtonClicked()
Edric Milareted0b2802015-10-01 15:10:02 -0400574{
Andreas Traczyk7548e732018-12-12 10:47:21 -0500575 emit NavigationRequested(ScreenEnum::SetttingsScreen);
Edric Milareted0b2802015-10-01 15:10:02 -0400576}
577
578void
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400579CallWidget::processContactLineEdit()
Nicolas Jager97a21b42015-12-03 16:55:45 -0500580{
Anthony Léonardaa90e1a2016-10-12 11:24:17 -0400581 auto contactLineText = ui->ringContactLineEdit->text();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400582 setConversationFilter(contactLineText);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500583}
584
585void
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400586CallWidget::on_ringContactLineEdit_returnPressed()
Nicolas Jager97a21b42015-12-03 16:55:45 -0500587{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400588 // select current temporary item and show conversation
589 auto convModel = LRCInstance::getCurrentConversationModel();
590 auto conversations = convModel->allFilteredConversations();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400591 if (!conversations.empty() &&
592 Utils::isContactValid(conversations.at(0).participants.at(0), *convModel)) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400593 selectConversation(smartListModel_->index(0));
594 }
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400595}
596
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400597void CallWidget::slotAcceptInviteClicked(const QModelIndex & index)
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400598{
Andreas Traczyk43865372018-12-27 12:12:35 -0500599 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
600 LRCInstance::getCurrentConversationModel()->makePermanent(convUid);
601 ui->messageView->setInvitation(false);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500602}
603
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400604void CallWidget::slotBlockInviteClicked(const QModelIndex & index)
Nicolas Jager97a21b42015-12-03 16:55:45 -0500605{
Andreas Traczyk43865372018-12-27 12:12:35 -0500606 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
607 if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
608 backToWelcomePage();
609 }
610 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400611}
612
613void CallWidget::slotIgnoreInviteClicked(const QModelIndex & index)
614{
Andreas Traczyk43865372018-12-27 12:12:35 -0500615 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
616 if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
617 backToWelcomePage();
618 }
619 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400620}
621
622void CallWidget::slotCustomContextMenuRequested(const QPoint& pos)
623{
624 setupSmartListContextMenu(pos);
625}
626
Isa Nanic601de1d2018-10-23 11:37:26 -0400627void CallWidget::slotAccountChanged(int index)
628{
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500629 try {
630 auto accountList = LRCInstance::accountModel().getAccountList();
631 setSelectedAccount(accountList.at(index));
632 } catch (...) {
Andreas Traczyk43865372018-12-27 12:12:35 -0500633 qWarning() << "CallWidget::slotAccountChanged exception";
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500634 }
Isa Nanic601de1d2018-10-23 11:37:26 -0400635}
636
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400637void CallWidget::slotShowCallView(const std::string& accountId,
638 const lrc::api::conversation::Info& convInfo)
639{
640 Q_UNUSED(accountId);
641 Q_UNUSED(convInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400642 qDebug() << "slotShowCallView";
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500643 showCallPanel();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400644 ui->callStackWidget->setCurrentWidget(ui->videoPage);
Sébastien Blin93bd2062018-12-17 15:57:16 -0500645 ui->videoWidget->showChatviewIfToggled();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400646 hideMiniSpinner();
647}
648
649void CallWidget::slotShowIncomingCallView(const std::string& accountId,
Andreas Traczyk43c08232018-10-31 13:42:09 -0400650 const lrc::api::conversation::Info& convInfo)
651{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400652 Q_UNUSED(accountId);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400653 qDebug() << "slotShowIncomingCallView";
654
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400655 auto callModel = LRCInstance::getCurrentCallModel();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400656
657 if (!callModel->hasCall(convInfo.callId)) {
Nicolas Jager97a21b42015-12-03 16:55:45 -0500658 return;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400659 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500660
Andreas Traczyk43c08232018-10-31 13:42:09 -0400661 auto convModel = LRCInstance::getCurrentConversationModel();
662 ui->callerPhoto->setPixmap(QPixmap::fromImage(imageForConv(convInfo.uid)));
663 auto bestName = QString::fromStdString(Utils::bestNameForConversation(convInfo, *convModel));
664 auto bestId = QString::fromStdString(Utils::bestIdForConversation(convInfo, *convModel));
665 auto finalBestId = (bestName != bestId) ? bestId : "";
666
667 auto call = callModel->getCall(convInfo.callId);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500668 auto isCallSelected = LRCInstance::getSelectedConvUid() == convInfo.uid;
Andreas Traczyk43c08232018-10-31 13:42:09 -0400669
670 if (call.isOutgoing) {
671 if (isCallSelected) {
672 miniSpinner_->start();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400673 ui->spinnerLabel->show();
674 ui->callStackWidget->setCurrentWidget(ui->outgoingCallPage);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500675 showCallPanel();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400676 }
677 } else {
678 if (!QApplication::focusWidget()) {
679 auto formattedName = Utils::bestNameForConversation(convInfo, *convModel);
680 Utils::showSystemNotification(this,
681 QString(tr("Call incoming from %1")).arg(QString::fromStdString(formattedName)));
682 }
683 selectSmartlistItem(convInfo.uid);
684 auto selectedAccountId = LRCInstance::getCurrentAccountInfo().id;
685 auto accountProperties = LRCInstance::accountModel().getAccountConfig(selectedAccountId);
686 if (accountProperties.autoAnswer) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400687 ui->callStackWidget->setCurrentWidget(ui->videoPage);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500688 showCallPanel();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400689 } else if (isCallSelected) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400690 ui->callStackWidget->setCurrentWidget(ui->incomingCallPage);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500691 showCallPanel();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400692 }
693 }
694
Sébastien Blin93bd2062018-12-17 15:57:16 -0500695 if (ui->messagesWidget->isHidden()) {
696 ui->messagesWidget->show();
697 }
698
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400699 ui->videoWidget->pushRenderer(convInfo.callId);
Andreas Traczykfd0d7c02018-10-30 17:14:06 -0400700
Andreas Traczyk43c08232018-10-31 13:42:09 -0400701 QFontMetrics primaryCallLabelFontMetrics(ui->callingBestNameLabel->font());
702 QFontMetrics sencondaryCallLabelFontMetrics(ui->callingBestIdLabel->font());
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400703
Andreas Traczyk43c08232018-10-31 13:42:09 -0400704 QString elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callerBestNameLabel->width());
705 ui->callerBestNameLabel->setText(elidedLabel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400706
Andreas Traczyk43c08232018-10-31 13:42:09 -0400707 elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callingBestNameLabel->width());
708 ui->callingBestNameLabel->setText(elidedLabel);
709
710 elidedLabel = sencondaryCallLabelFontMetrics.elidedText(finalBestId, Qt::ElideRight, ui->callingBestIdLabel->width());
711 ui->callingBestIdLabel->setText(elidedLabel);
712
713 ui->smartList->update();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400714}
715
716void CallWidget::slotShowChatView(const std::string& accountId,
Andreas Traczyk43c08232018-10-31 13:42:09 -0400717 const lrc::api::conversation::Info& convInfo)
718{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400719 Q_UNUSED(accountId);
720 Q_UNUSED(convInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400721
Andreas Traczyk43c08232018-10-31 13:42:09 -0400722 ui->callStackWidget->hide();
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500723 ui->messagingHeaderWidget->show();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400724 showConversationView();
Nicolas Jager97a21b42015-12-03 16:55:45 -0500725}
Edric Milaretab12d022015-12-04 16:09:44 -0500726
727void
Sébastien Blin93bd2062018-12-17 15:57:16 -0500728CallWidget::slotToggleFullScreenClicked()
729{
730 if (ui->mainActivityWidget->isFullScreen()) {
731 ui->stackedWidget->addWidget(ui->mainActivityWidget);
732 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
733 ui->mainActivityWidget->showNormal();
734 } else {
735 ui->stackedWidget->removeWidget(ui->mainActivityWidget);
736 ui->mainActivityWidget->setParent(0);
737 ui->mainActivityWidget->showFullScreen();
738 }
739}
740
741void
742CallWidget::slotVideoViewDestroyed(const std::string& callid)
743{
744 auto convUid = LRCInstance::getSelectedConvUid();
745 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
Sébastien Blin93bd2062018-12-17 15:57:16 -0500746 auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
Sébastien Blin62b08ac2018-12-14 16:18:04 -0500747 if (conversation != currentConversationModel->allFilteredConversations().end() &&
748 callid != conversation->callId) {
749 return;
750 }
Sébastien Blin93bd2062018-12-17 15:57:16 -0500751 if (ui->mainActivityWidget->isFullScreen()) {
752 ui->stackedWidget->addWidget(ui->mainActivityWidget);
753 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
754 ui->mainActivityWidget->showNormal();
755 }
756 showConversationView();
757}
758
759void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400760CallWidget::setSelectedAccount(const std::string& accountId)
761{
762 LRCInstance::setSelectedAccountId(accountId);
763
764 // First, we get back to the welcome view (except if in call)
765 if (ui->stackedWidget->currentWidget() != ui->videoPage &&
766 ui->stackedWidget->currentWidget() != ui->welcomePage) {
767 Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
768 }
769
770 // We setup the ringIdLabel and the QRCode
771 auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
772 auto id = accountInfo.registeredName.empty() ? accountInfo.profileInfo.uri : accountInfo.registeredName;
773 auto isRingAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING;
774 if (isRingAccount) {
775 ui->ringIdLabel->setText(QString::fromStdString(id));
776 setupQRCode(QString::fromStdString(accountInfo.profileInfo.uri));
777 }
778
779 updateSmartList();
780 currentTypeFilter_ = accountInfo.profileInfo.type;
781 LRCInstance::getCurrentConversationModel()->setFilter(accountInfo.profileInfo.type);
782 updateConversationsFilterWidget();
783 connectConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500784 connectAccount(accountId);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400785}
786
787void CallWidget::setConversationFilter(lrc::api::profile::Type filter)
788{
789 if (currentTypeFilter_ == filter) {
790 return;
791 }
792 currentTypeFilter_ = filter;
793 LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_);
794}
795
796void CallWidget::updateConversationsFilterWidget()
797{
798 auto invites = LRCInstance::getCurrentAccountInfo().contactModel->pendingRequestCount();
799 if (invites == 0 && currentTypeFilter_ == lrc::api::profile::Type::PENDING) {
800 currentTypeFilter_ = lrc::api::profile::Type::RING;
801 LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_);
802 }
803 ui->conversationsFilterWidget->setVisible(invites);
Andreas Traczyk1d8159a2018-12-13 15:48:24 -0500804 ui->conversationsFilterWidget->updateBadges();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400805 ui->conversationsFilterWidget->update();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400806}
807
808void CallWidget::setConversationFilter(const QString & filter)
809{
810 LRCInstance::getCurrentConversationModel()->setFilter(filter.toStdString());
Anthony Léonardd47179c2017-03-28 10:39:10 -0400811}
812
813void
Edric Milaret6b68a482016-02-01 15:23:44 -0500814CallWidget::showIMOutOfCall(const QModelIndex& nodeIdx)
Edric Milaretab12d022015-12-04 16:09:44 -0500815{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400816 QString displayName = nodeIdx.data(static_cast<int>(SmartListModel::Role::DisplayName)).toString();
817 QString displayId = nodeIdx.data(static_cast<int>(SmartListModel::Role::DisplayID)).toString();
818 QString contactURI = nodeIdx.data(static_cast<int>(SmartListModel::Role::URI)).toString();
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400819
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400820 bool isContact = false;
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500821 auto selectedAccountId = LRCInstance::getCurrAccId();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400822 auto& accountInfo = LRCInstance::accountModel().getAccountInfo(selectedAccountId);
823 bool isRINGAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING;
824 try {
825 accountInfo.contactModel->getContact(contactURI.toStdString());
826 isContact = true;
827 }
828 catch (...) {}
829
Olivier SOLDANO31b9aac2017-07-14 15:50:09 -0400830 ui->imNameLabel->setText(QString(tr("%1", "%1 is the contact username"))
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400831 .arg(displayName));
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400832
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400833 if (isRINGAccount && displayName != displayId){
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400834 ui->imIdLabel->show();
835 ui->imIdLabel->setText(QString(tr("%1", "%1 is the contact unique identifier"))
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400836 .arg(displayId));
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400837 } else {
838 ui->imIdLabel->hide();
839 }
840
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400841 bool shouldShowSendContactRequestBtn = !isContact && isRINGAccount;
Andreas Traczyk912242e2018-10-29 14:44:44 -0400842 ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn);
Olivier SOLDANO815d92f2017-07-13 14:05:36 -0400843
Andreas Traczyk43c08232018-10-31 13:42:09 -0400844 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500845 auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
Andreas Traczyk43c08232018-10-31 13:42:09 -0400846 *convModel);
847 ui->messageView->clear();
Andreas Traczyk43865372018-12-27 12:12:35 -0500848 ui->messageView->printHistory(*convModel, currentConversation->interactions, true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400849
Andreas Traczyk43c08232018-10-31 13:42:09 -0400850 // Contact Avatars
851 auto accInfo = &LRCInstance::getCurrentAccountInfo();
852 auto contactUri = currentConversation->participants.front();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400853 try {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400854 auto& contact = accInfo->contactModel->getContact(contactUri);
Sébastien Blin942d1022018-12-13 09:49:03 -0500855 auto bestName = Utils::bestNameForConversation(*currentConversation, *convModel);
856 ui->messageView->setInvitation(
857 (contact.profileInfo.type == lrc::api::profile::Type::PENDING),
858 bestName,
859 accInfo->contactModel->getContactProfileId(contact.profileInfo.uri)
860 );
Andreas Traczyk43c08232018-10-31 13:42:09 -0400861 if (!contact.profileInfo.avatar.empty()) {
862 ui->messageView->setSenderImage(
863 accInfo->contactModel->getContactProfileId(contactUri),
864 contact.profileInfo.avatar);
865 } else {
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500866 auto avatar = Utils::conversationPhoto(LRCInstance::getSelectedConvUid(), *accInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400867 QByteArray ba;
868 QBuffer bu(&ba);
869 avatar.save(&bu, "PNG");
870 std::string avatarString = ba.toBase64().toStdString();
871 ui->messageView->setSenderImage(
872 accInfo->contactModel->getContactProfileId(contactUri),
873 avatarString);
874 }
875 } catch (...) { }
Edric Milaretab12d022015-12-04 16:09:44 -0500876}
Edric Milaretfa05d972016-01-13 16:22:04 -0500877
878void
Edric Milaret8001f6f2016-01-27 09:55:12 -0500879CallWidget::on_ringContactLineEdit_textChanged(const QString& text)
Edric Milaretfa05d972016-01-13 16:22:04 -0500880{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400881 Q_UNUSED(text);
882 processContactLineEdit();
Edric Milaretfa05d972016-01-13 16:22:04 -0500883}
Edric Milareta0ebd062016-01-13 12:18:23 -0500884
Nicolas Jagerca850292016-01-17 14:11:10 -0500885void
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400886CallWidget::backToWelcomePage()
Edric Milareta0ebd062016-01-13 12:18:23 -0500887{
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500888 qDebug() << "backToWelcomePage";
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400889 deselectConversation();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400890 ui->messageView->hideMessages();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400891 ui->stackedWidget->setCurrentWidget(ui->welcomePage);
Nicolas Jagerca850292016-01-17 14:11:10 -0500892}
893
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400894void
895CallWidget::hideMiniSpinner()
Olivier SOLDANO19193412017-06-06 12:03:36 -0400896{
897 if(ui->spinnerLabel->isVisible()){
898 miniSpinner_->stop();
899 ui->spinnerLabel->hide();
900 }
901}
902
Nicolas Jagerca850292016-01-17 14:11:10 -0500903void
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400904CallWidget::on_imBackButton_clicked()
905{
906 backToWelcomePage();
907}
908
909void
Edric Milaret1e598592016-09-02 10:10:01 -0400910CallWidget::on_qrButton_toggled(bool checked)
911{
912 ui->qrLabel->setVisible(checked);
913}
914
915void
Edric Milaret4097d2f2016-02-09 14:41:50 -0500916CallWidget::on_shareButton_clicked()
917{
Sébastien Blincba5b522018-12-10 12:48:36 -0500918 Utils::InvokeMailto(tr("Contact me on Jami"), tr("My Id is : ") + ui->ringIdLabel->text());
Edric Milaret4097d2f2016-02-09 14:41:50 -0500919}
Anthony Léonardaa90e1a2016-10-12 11:24:17 -0400920
921void
Andreas Traczyk912242e2018-10-29 14:44:44 -0400922CallWidget::on_sendContactRequestButton_clicked()
Olivier SOLDANOdd878662017-03-27 16:00:06 -0400923{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500924 LRCInstance::getCurrentConversationModel()->makePermanent(LRCInstance::getSelectedConvUid());
Andreas Traczyk43865372018-12-27 12:12:35 -0500925 ui->sendContactRequestButton->hide();
Olivier SOLDANOdd878662017-03-27 16:00:06 -0400926}
927
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400928void
Andreas Traczyk912242e2018-10-29 14:44:44 -0400929CallWidget::on_btnAudioCall_clicked()
930{
931 auto convUid = LRCInstance::getSelectedConvUid();
932 LRCInstance::getCurrentConversationModel()->placeAudioOnlyCall(convUid);
933 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
934}
935
936void
937CallWidget::on_btnVideoCall_clicked()
938{
939 auto convUid = LRCInstance::getSelectedConvUid();
940 LRCInstance::getCurrentConversationModel()->placeCall(convUid);
941 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
942}
943
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400944bool
945CallWidget::connectConversationModel()
Anthony Léonard5cc76412017-04-21 16:52:25 -0400946{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400947 auto currentConversationModel = LRCInstance::getCurrentAccountInfo().conversationModel.get();
948
949 if (ui->smartList->selectionModel()) {
950 ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect);
Anthony Léonard5cc76412017-04-21 16:52:25 -0400951 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400952
953 QObject::disconnect(modelSortedConnection_);
954 QObject::disconnect(modelUpdatedConnection_);
955 QObject::disconnect(filterChangedConnection_);
956 QObject::disconnect(newConversationConnection_);
957 QObject::disconnect(conversationRemovedConnection_);
958 QObject::disconnect(conversationClearedConnection);
959 QObject::disconnect(interactionStatusUpdatedConnection_);
960 QObject::disconnect(newInteractionConnection_);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400961 QObject::disconnect(interactionRemovedConnection_);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400962
963 modelSortedConnection_ = QObject::connect(
964 currentConversationModel, &lrc::api::ConversationModel::modelSorted,
965 [this]() {
966 updateConversationsFilterWidget();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500967 selectSmartlistItem(LRCInstance::getSelectedConvUid());
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400968 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400969 }
970 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400971 modelUpdatedConnection_ = QObject::connect(
972 currentConversationModel, &lrc::api::ConversationModel::conversationUpdated,
973 [this](const std::string& convUid) {
974 Q_UNUSED(convUid);
975 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400976 }
977 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400978 filterChangedConnection_ = QObject::connect(
979 currentConversationModel, &lrc::api::ConversationModel::filterChanged,
980 [this]() {
981 updateSmartList();
982 updateConversationsFilterWidget();
983 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400984 }
985 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400986 newConversationConnection_ = QObject::connect(
987 currentConversationModel, &lrc::api::ConversationModel::newConversation,
988 [this](const std::string& convUid) {
989 updateSmartList();
990 updateConversationForNewContact(convUid);
991 ui->conversationsFilterWidget->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400992 }
993 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400994 conversationRemovedConnection_ = QObject::connect(
995 currentConversationModel, &lrc::api::ConversationModel::conversationRemoved,
996 [this]() {
997 backToWelcomePage();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400998 }
999 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001000 conversationClearedConnection = QObject::connect(
1001 currentConversationModel, &lrc::api::ConversationModel::conversationCleared,
1002 [this](const std::string& convUid) {
Andreas Traczyk43c08232018-10-31 13:42:09 -04001003 ui->messageView->clear();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001004 // if currently selected,
1005 // switch to welcome screen (deselecting current smartlist item )
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001006 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001007 return;
1008 }
1009 backToWelcomePage();
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001010 }
1011 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001012 interactionStatusUpdatedConnection_ = QObject::connect(
1013 currentConversationModel, &lrc::api::ConversationModel::interactionStatusUpdated,
Andreas Traczyk43c08232018-10-31 13:42:09 -04001014 [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) {
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001015 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001016 return;
1017 }
Andreas Traczyk43c08232018-10-31 13:42:09 -04001018 auto& currentAccountInfo = LRCInstance::getCurrentAccountInfo();
1019 auto currentConversationModel = currentAccountInfo.conversationModel.get();
1020 currentConversationModel->clearUnreadInteractions(convUid);
1021 ui->conversationsFilterWidget->update();
1022 ui->messageView->updateInteraction(*currentConversationModel, interactionId, interaction);
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001023 }
1024 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001025 newInteractionConnection_ = QObject::connect(
1026 currentConversationModel, &lrc::api::ConversationModel::newInteraction,
1027 [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) {
1028 onIncomingMessage(convUid, interactionId, interaction);
Andreas Traczyk4b4bfde2018-12-19 09:53:22 -05001029 if (interaction.type == lrc::api::interaction::Type::CALL) {
1030 return;
1031 }
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001032 if (convUid == LRCInstance::getSelectedConvUid()) {
Andreas Traczyk4b4bfde2018-12-19 09:53:22 -05001033 ui->videoWidget->simulateShowChatview(true);
1034 }
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001035 }
1036 );
Andreas Traczyk43c08232018-10-31 13:42:09 -04001037 interactionRemovedConnection_ = QObject::connect(
1038 currentConversationModel, &lrc::api::ConversationModel::interactionRemoved,
1039 [this](const std::string& convUid, uint64_t interactionId) {
1040 Q_UNUSED(convUid);
1041 ui->messageView->removeInteraction(interactionId);
1042 }
1043 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001044 currentConversationModel->setFilter("");
1045 // clear search field
1046 ui->ringContactLineEdit->setText("");
1047 return true;
1048}
1049
1050void
1051CallWidget::updateConversationView(const std::string& convUid)
1052{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001053 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001054 return;
1055 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001056}
1057
1058void
1059CallWidget::selectConversation(const QModelIndex& index)
1060{
1061 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1062
1063 if (currentConversationModel == nullptr || !index.isValid()) {
1064 return;
1065 }
1066
1067 const auto item = currentConversationModel->filteredConversation(index.row());
1068
1069 if (selectConversation(item, *currentConversationModel)) {
Andreas Traczyk43c08232018-10-31 13:42:09 -04001070 showIMOutOfCall(index);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001071 auto convUid = LRCInstance::getSelectedConvUid();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001072 if (!lastConvUid_.compare(convUid)) {
1073 return;
1074 }
1075 lastConvUid_.assign(convUid);
1076 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1077 auto callModel = LRCInstance::getCurrentCallModel();
1078 auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
1079 const auto item = currentConversationModel->filteredConversation(index.row());
Andreas Traczyk43c08232018-10-31 13:42:09 -04001080 if (callModel->hasCall(conversation->callId) && item.callId == conversation->callId) {
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001081 showCallPanel();
Andreas Traczyk43c08232018-10-31 13:42:09 -04001082 return;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001083 }
Andreas Traczyk43c08232018-10-31 13:42:09 -04001084 ui->callStackWidget->hide();
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001085 ui->messagingHeaderWidget->show();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001086 }
Anthony Léonard5cc76412017-04-21 16:52:25 -04001087}
Anthony Léonardecfe7422017-05-04 14:14:37 -04001088
Anthony Léonard041ad392017-07-14 16:44:09 -04001089bool
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001090CallWidget::selectConversation( const lrc::api::conversation::Info& item,
1091 lrc::api::ConversationModel& convModel)
Anthony Léonard041ad392017-07-14 16:44:09 -04001092{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001093 if (LRCInstance::getSelectedConvUid() == item.uid) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001094 return false;
1095 } else if (item.participants.size() > 0) {
1096 convModel.selectConversation(item.uid);
1097 LRCInstance::setSelectedConvId(item.uid);
1098 convModel.clearUnreadInteractions(item.uid);
1099 ui->conversationsFilterWidget->update();
1100 return true;
Anthony Léonard041ad392017-07-14 16:44:09 -04001101 }
Anthony Léonard041ad392017-07-14 16:44:09 -04001102}
1103
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001104void
1105CallWidget::deselectConversation()
Anthony Léonardecfe7422017-05-04 14:14:37 -04001106{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001107 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1108
1109 if (currentConversationModel == nullptr) {
1110 return;
1111 }
1112
1113 currentConversationModel->selectConversation("");
1114 LRCInstance::setSelectedConvId("");
1115
1116 ui->smartList->selectionModel()->clear();
1117 disconnect(imConnection_);
Anthony Léonardecfe7422017-05-04 14:14:37 -04001118}
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001119
1120void
1121CallWidget::updateConversationForNewContact(const std::string& convUid)
1122{
1123 auto convModel = LRCInstance::getCurrentConversationModel();
1124 if (convModel == nullptr) {
1125 return;
1126 }
1127 ui->ringContactLineEdit->setText("");
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001128 auto selectedUid = LRCInstance::getSelectedConvUid();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001129 auto it = Utils::getConversationFromUid(convUid, *convModel);
1130 if (it != convModel->allFilteredConversations().end()) {
1131 try {
1132 auto contact = convModel->owner.contactModel->getContact(it->participants[0]);
1133 if (!contact.profileInfo.uri.empty() && contact.profileInfo.uri.compare(selectedUid) == 0) {
1134 LRCInstance::setSelectedConvId(convUid);
1135 convModel->selectConversation(convUid);
1136 }
1137 } catch (...) {
1138 return;
1139 }
1140 }
1141}
1142
1143void
1144CallWidget::updateSmartList()
1145{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001146 if (!ui->smartList->model()) {
1147 smartListModel_.reset(new SmartListModel(LRCInstance::getCurrAccId(), this));
1148 ui->smartList->setModel(smartListModel_.get());
1149 ui->smartList->setItemDelegate(new ConversationItemDelegate());
1150 } else {
1151 smartListModel_->setAccount(LRCInstance::getCurrAccId());
1152 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001153
1154 // smartlist selection
1155 QObject::disconnect(smartlistSelectionConnection_);
1156 smartlistSelectionConnection_ = connect(ui->smartList->selectionModel(),
1157 SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
1158 this,
1159 SLOT(smartListSelectionChanged(QItemSelection, QItemSelection)));
1160}
1161
1162void
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001163CallWidget::updateComboBox()
1164{
1165 ui->currentAccountComboBox->updateComboBoxDisplay();
1166}
1167
1168void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001169CallWidget::update()
1170{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001171 updateSmartList();
1172 updateConversationsFilterWidget();
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001173 updateComboBox();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001174 connectConversationModel();
Isa Nanic601de1d2018-10-23 11:37:26 -04001175}
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001176
1177void
1178CallWidget::connectAccount(const std::string& accId)
1179{
1180 auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get();
1181 disconnect(callStatusChangedConnection_);
1182 callStatusChangedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::callStatusChanged,
1183 [this, accId](const std::string& callId) {
1184 auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get();
1185 auto call = callModel->getCall(callId);
1186 switch (call.status) {
1187 case lrc::api::call::Status::INVALID:
1188 case lrc::api::call::Status::INACTIVE:
1189 case lrc::api::call::Status::ENDED:
1190 case lrc::api::call::Status::PEER_BUSY:
1191 case lrc::api::call::Status::TIMEOUT:
1192 case lrc::api::call::Status::TERMINATING:
1193 {
1194 ui->callStackWidget->hide();
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001195 ui->messagingHeaderWidget->show();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001196 showConversationView();
1197 break;
1198 }
1199 default:
1200 break;
1201 }
1202 });
1203 auto& contactModel = LRCInstance::getCurrentAccountInfo().contactModel;
1204 disconnect(contactAddedConnection_);
1205 contactAddedConnection_ = connect(contactModel.get(), &lrc::api::ContactModel::contactAdded,
1206 [this, &contactModel](const std::string & contactId) {
1207 auto convModel = LRCInstance::getCurrentConversationModel();
1208 auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
1209 *convModel);
1210 if (currentConversation == convModel->allFilteredConversations().end()) {
1211 return;
1212 }
1213 if (contactId == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) {
1214 ui->messageView->clear();
1215 ui->messageView->printHistory(*convModel, currentConversation->interactions);
1216 }
1217 });
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001218}
1219
1220void
1221CallWidget::showCallPanel()
1222{
1223 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
1224 ui->callStackWidget->show();
1225 ui->imBackButton->hide();
1226 ui->imBackButton->hide();
1227 ui->btnAudioCall->hide();
1228 ui->btnVideoCall->hide();
1229}