blob: b6ced4d0dca8857601a4683d5e2798856d8976cc [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"
Andreas Traczyk868c3d62019-01-03 21:05:40 -050057#include "mainwindow.h"
Edric Milaret25236d92016-03-28 09:40:58 -040058
Nicolas Jager97a21b42015-12-03 16:55:45 -050059CallWidget::CallWidget(QWidget* parent) :
Nicolas Jager74fe46f2016-02-29 14:55:09 -050060 NavWidget(parent),
Edric Milaret7d40a4a2015-05-13 13:01:15 -040061 ui(new Ui::CallWidget),
Andreas Traczyk43c08232018-10-31 13:42:09 -040062 menu_(new QMenu())
Edric Milaret627500d2015-03-27 16:41:40 -040063{
64 ui->setupUi(this);
65
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040066 using namespace lrc::api;
Nicolas Jagerca850292016-01-17 14:11:10 -050067
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040068 QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
Edric Milaret3aca8e32015-06-12 10:01:40 -040069
Sébastien Blincba5b522018-12-10 12:48:36 -050070 QPixmap logo(":/images/logo-jami-standard-coul.png");
Edric Milareted0b2802015-10-01 15:10:02 -040071 ui->ringLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation));
72 ui->ringLogo->setAlignment(Qt::AlignHCenter);
73
Edric Milaret1e598592016-09-02 10:10:01 -040074 ui->qrLabel->hide();
Edric Milarete19c4cd2016-02-12 10:19:44 -050075
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040076 videoRenderer_ = nullptr;
Edric Milaret627500d2015-03-27 16:41:40 -040077
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040078 // this line is not welcome here, and must be removed
79 ProfileModel::instance().addCollection<LocalProfileCollection>(LoadOptions::FORCE_ENABLED);
Edric Milaret627500d2015-03-27 16:41:40 -040080
Andreas Traczyk43c08232018-10-31 13:42:09 -040081 QSettings settings;
82
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040083 // select last used account if stored in registry
84 auto accountList = LRCInstance::accountModel().getAccountList();
85 if (!accountList.empty()) {
86 std::string accountIdToStartWith;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040087 if (settings.contains(SettingsKey::selectedAccount)) {
88 accountIdToStartWith = settings
89 .value(SettingsKey::selectedAccount, true)
90 .value<QString>()
91 .toStdString();
92 if (Utils::indexInVector(accountList, accountIdToStartWith) == -1) {
93 accountIdToStartWith = accountList.at(0);
Olivier SOLDANOaf8f2822017-07-11 12:15:18 -040094 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040095 }
96 else {
97 accountIdToStartWith = accountList.at(0);
98 }
99 setSelectedAccount(accountIdToStartWith);
Isa Nanic601de1d2018-10-23 11:37:26 -0400100 // get account index and set the currentAccountComboBox
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400101 auto index = Utils::indexInVector(accountList, accountIdToStartWith);
102 if (index != -1) {
Isa Nanic601de1d2018-10-23 11:37:26 -0400103 ui->currentAccountComboBox->setCurrentIndex(index);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400104 }
Edric Milaret627500d2015-03-27 16:41:40 -0400105 }
Olivier SOLDANO2100f1c2017-09-06 16:45:20 -0400106
Andreas Traczyk43c08232018-10-31 13:42:09 -0400107 if (settings.contains(SettingsKey::mainSplitterState)) {
108 auto splitterStates = settings.value(SettingsKey::mainSplitterState).toByteArray();
109 ui->mainActivitySplitter->restoreState(splitterStates);
110 }
111
112 ui->mainActivitySplitter->setCollapsible(0, false);
Sébastien Blin93bd2062018-12-17 15:57:16 -0500113 ui->mainActivitySplitter->setCollapsible(1, false);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400114 ui->splitter->setCollapsible(0, false);
115 ui->splitter->setCollapsible(1, false);
116
Isa Nanic601de1d2018-10-23 11:37:26 -0400117 //disable dropdown shadow on combobox
118 ui->currentAccountComboBox->view()->window()->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
119
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400120 // conversation list
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400121 ui->smartList->setContextMenuPolicy(Qt::CustomContextMenu);
122
123 // setup searchingfor mini spinner
124 miniSpinner_ = new QMovie(":/images/waiting.gif");
125 ui->spinnerLabel->setMovie(miniSpinner_);
126 ui->spinnerLabel->hide();
127
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400128 // connections
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400129 connect(ui->currentAccountComboBox, &CurrentAccountComboBox::settingsButtonClicked,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400130 this, &CallWidget::settingsButtonClicked);
131
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500132 connect(ui->currentAccountComboBox, &CurrentAccountComboBox::newAccountClicked,
133 [this]() {
134 emit NavigationRequested(ScreenEnum::WizardScreen);
135 });
136
Andreas Traczyk43c08232018-10-31 13:42:09 -0400137 connect(ui->videoWidget, &VideoView::setChatVisibility,
138 [this](bool visible) {
Sébastien Blin93bd2062018-12-17 15:57:16 -0500139 if (visible) {
140 ui->messagesWidget->show();
141 } else {
142 ui->messagesWidget->hide();
143 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400144 });
145
146 connect(ui->mainActivitySplitter, &QSplitter::splitterMoved,
147 [this](int pos, int index) {
Andreas Traczyk14c3e862018-12-26 14:02:30 -0500148 Q_UNUSED(index);
149 Q_UNUSED(pos);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400150 QSettings settings;
151 settings.setValue(SettingsKey::mainSplitterState, ui->mainActivitySplitter->saveState());
152 });
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400153
154 connect(ui->videoWidget, &VideoView::videoSettingsClicked,
155 this, &CallWidget::settingsButtonClicked);
156
Sébastien Blin62b08ac2018-12-14 16:18:04 -0500157 connect(ui->videoWidget, &VideoView::toggleFullScreenClicked,
158 this, &CallWidget::slotToggleFullScreenClicked);
159
160 connect(ui->videoWidget, &VideoView::closing,
161 this, &CallWidget::slotVideoViewDestroyed);
162
Andreas Traczyk43c08232018-10-31 13:42:09 -0400163 connect(ui->btnConversations, &QPushButton::clicked,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400164 this, &CallWidget::conversationsButtonClicked);
165
Andreas Traczyk43c08232018-10-31 13:42:09 -0400166 connect(ui->btnInvites, &QPushButton::clicked,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400167 this, &CallWidget::invitationsButtonClicked);
168
Andreas Traczyk43c08232018-10-31 13:42:09 -0400169 connect(ui->smartList, &QTreeView::customContextMenuRequested,
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400170 this, &CallWidget::slotCustomContextMenuRequested);
171
172 connect(ui->smartList, &SmartListView::btnAcceptInviteClicked,
173 this, &CallWidget::slotAcceptInviteClicked);
174
175 connect(ui->smartList, &SmartListView::btnBlockInviteClicked,
176 this, &CallWidget::slotBlockInviteClicked);
177
178 connect(ui->smartList, &SmartListView::btnIgnoreInviteClicked,
179 this, &CallWidget::slotIgnoreInviteClicked);
180
181 connect(&LRCInstance::behaviorController(), &BehaviorController::showCallView,
182 this, &CallWidget::slotShowCallView);
183
184 connect(&LRCInstance::behaviorController(), &BehaviorController::showIncomingCallView,
185 this, &CallWidget::slotShowIncomingCallView);
186
187 connect(&LRCInstance::behaviorController(), &BehaviorController::showChatView,
188 this, &CallWidget::slotShowChatView);
Andreas Traczyk55f92cb2018-10-23 12:26:25 -0400189
Isa Nanic601de1d2018-10-23 11:37:26 -0400190 connect(ui->currentAccountComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
191 this, &CallWidget::slotAccountChanged);
192
Andreas Traczyk912242e2018-10-29 14:44:44 -0400193 connect(ui->sendContactRequestButton, &QPushButton::clicked,
194 this, &CallWidget::on_sendContactRequestButton_clicked);
195
196 connect(ui->btnAudioCall, &QPushButton::clicked,
197 this, &CallWidget::on_sendContactRequestButton_clicked);
198
199 connect(ui->btnVideoCall, &QPushButton::clicked,
200 this, &CallWidget::on_sendContactRequestButton_clicked);
201
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400202 connect(ui->currentAccountComboBox, QOverload<int>::of(&CurrentAccountComboBox::currentIndexChanged),
203 [this] {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400204 ui->btnConversations->setChecked(true);
205 ui->btnInvites->setChecked(false);
206 });
207
Andreas Traczyk43865372018-12-27 12:12:35 -0500208 connect(ui->messageView, &MessageWebView::conversationRemoved,
209 [this] {
210 backToWelcomePage();
211 });
212
Andreas Traczyk55f92cb2018-10-23 12:26:25 -0400213 // set first view to welcome view
214 ui->stackedWidget->setCurrentWidget(ui->welcomePage);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400215 ui->btnConversations->setChecked(true);
216
217 // chat view
218 ui->messageView->buildView();
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500219
Andreas Traczykb81281e2018-12-13 13:13:28 -0500220 // hide the call stack
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500221 setCallPanelVisibility(false);
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{
Andreas Traczyk868c3d62019-01-03 21:05:40 -0500266 auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
267 if (scalingRatio > 1.0) {
268 ui->messageView->setZoomFactor(1.15);
269 } else {
270 ui->messageView->setZoomFactor(1.0);
271 }
272
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500273}
274
Andreas Traczykb81281e2018-12-13 13:13:28 -0500275int
276CallWidget::getLeftPanelWidth()
277{
278 return ui->currentAccountComboBox->width();
279}
280
Edric Milaret00a32252016-01-19 10:37:13 -0500281void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400282CallWidget::onIncomingMessage(const std::string& convUid,
283 uint64_t interactionId,
284 const lrc::api::interaction::Info& interaction)
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400285{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400286 Q_UNUSED(interactionId);
Edric Milaret00a32252016-01-19 10:37:13 -0500287 if (!QApplication::focusWidget()) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400288 auto convModel = LRCInstance::getCurrentConversationModel();
289 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500290 if (conversation == convModel->allFilteredConversations().end()) {
291 return;
292 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400293 auto bestName = Utils::bestNameForConversation(*conversation, *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400294 Utils::showSystemNotification(this,
295 QString(tr("Message incoming from %1"))
Andreas Traczyk43c08232018-10-31 13:42:09 -0400296 .arg(QString::fromStdString(bestName)));
Edric Milaret00a32252016-01-19 10:37:13 -0500297 }
Andreas Traczyk1d8159a2018-12-13 15:48:24 -0500298 updateConversationsFilterWidget();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500299 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400300 return;
301 }
302
303 auto convModel = LRCInstance::getCurrentConversationModel();
304 convModel->clearUnreadInteractions(convUid);
305 auto currentConversation = Utils::getConversationFromUid(convUid, *convModel);
306 if (currentConversation == convModel->allFilteredConversations().end()) {
307 return;
308 }
309 ui->messageView->printNewInteraction(*convModel, interactionId, interaction);
Edric Milareta0ebd062016-01-13 12:18:23 -0500310}
311
312void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400313CallWidget::setupSmartListContextMenu(const QPoint& pos)
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400314{
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400315 QPoint globalPos = ui->smartList->mapToGlobal(pos);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400316 auto index = ui->smartList->indexAt(pos);
317 if (not index.isValid()) {
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400318 return;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400319 }
320
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400321 auto convModel = LRCInstance::getCurrentConversationModel();
322 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID))
323 .value<QString>()
324 .toStdString();
325 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
326 auto contactUid = (*conversation).participants.at(0);
327 auto contact = LRCInstance::getCurrentAccountInfo().contactModel.get()->getContact(contactUid);
328
329 if (!Utils::isContactValid(contactUid, *convModel)) {
330 return;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400331 }
332
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400333 QMenu menu;
334
335 // video call
336 auto videoCallAction = new QAction(tr("Start video call"), this);
337 menu.addAction(videoCallAction);
338 connect(videoCallAction, &QAction::triggered,
339 [this, convUid, conversation, convModel]() {
340 convModel->placeCall(convUid);
341 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500342 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400343 selectConversation(*conversation, *convModel);
344 }
345 });
346 // audio call
347 auto audioCallAction = new QAction(tr("Start audio call"), this);
348 menu.addAction(audioCallAction);
349 connect(audioCallAction, &QAction::triggered,
350 [this, convUid, conversation, convModel]() {
351 convModel->placeAudioOnlyCall(convUid);
352 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500353 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400354 selectConversation(*conversation, *convModel);
355 }
356 });
357
358 if (contact.profileInfo.type == lrc::api::profile::Type::RING) {
359 // separator
360 menu.addSeparator();
361
362 // clear conversation
363 auto clearConversationAction = new QAction(tr("Clear conversation"), this);
364 menu.addAction(clearConversationAction);
365 connect(clearConversationAction, &QAction::triggered,
366 [convUid]() {
367 LRCInstance::getCurrentConversationModel()->clearHistory(convUid);
368 });
Sébastien Blin31fccce2018-12-13 11:27:05 -0500369 // remove contact
370 auto removeContactAction = new QAction(tr("Remove contact"), this);
371 menu.addAction(removeContactAction);
372 connect(removeContactAction, &QAction::triggered,
373 [convUid]() {
374 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
375 });
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400376 // block contact
377 auto blockContactAction = new QAction(tr("Block contact"), this);
378 menu.addAction(blockContactAction);
379 connect(blockContactAction, &QAction::triggered,
380 [convUid]() {
381 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
382 });
383
384 // separator
385 menu.addSeparator();
386
387 // copy number(infohash)
388 auto copyNumberAction = new QAction(tr("Copy number"), this);
389 menu.addAction(copyNumberAction);
390 connect(copyNumberAction, &QAction::triggered,
391 [contact]() {
392 QApplication::clipboard()->setText(
393 QString::fromStdString(contact.profileInfo.uri)
394 );
395 });
396 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400397 smartListModel_->isContextMenuOpen = true;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400398 menu.exec(globalPos);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400399 smartListModel_->isContextMenuOpen = false;
Edric Milareta0ebd062016-01-13 12:18:23 -0500400}
401
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400402void
403CallWidget::setupQRCode(QString ringID)
Edric Milarete19c4cd2016-02-12 10:19:44 -0500404{
Anthony Léonarda86a8972016-12-15 10:33:47 -0500405 auto rcode = QRcode_encodeString(ringID.toStdString().c_str(),
Edric Milaret6d0e5312016-04-04 16:30:22 -0400406 0, //Let the version be decided by libqrencode
407 QR_ECLEVEL_L, // Lowest level of error correction
Edric Milarete19c4cd2016-02-12 10:19:44 -0500408 QR_MODE_8, // 8-bit data mode
409 1);
410 if (not rcode) {
411 qWarning() << "Failed to generate QR code: " << strerror(errno);
412 return;
413 }
414
415 auto margin = 5;
416 int qrwidth = rcode->width + margin * 2;
417 QImage result(QSize(qrwidth, qrwidth), QImage::Format_Mono);
418 QPainter painter;
419 painter.begin(&result);
420 painter.setClipRect(QRect(0, 0, qrwidth, qrwidth));
421 painter.setPen(QPen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
422 painter.setBrush(Qt::black);
423 painter.fillRect(QRect(0, 0, qrwidth, qrwidth), Qt::white);
Edric Milaret74474f52016-05-16 13:36:23 -0400424 unsigned char* p;
Edric Milarete19c4cd2016-02-12 10:19:44 -0500425 p = rcode->data;
426 for(int y = 0; y < rcode->width; y++) {
Edric Milaret74474f52016-05-16 13:36:23 -0400427 unsigned char* row = (p + (y * rcode->width));
Edric Milarete19c4cd2016-02-12 10:19:44 -0500428 for(int x = 0; x < rcode->width; x++) {
429 if(*(row + x) & 0x1) {
430 painter.drawRect(margin + x, margin + y, 1, 1);
431 }
432 }
433
434 }
435 painter.end();
436 QRcode_free(rcode);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400437 ui->qrLabel->setPixmap(QPixmap::fromImage(result.scaled(QSize(qrSize_, qrSize_),
438 Qt::KeepAspectRatio)));
Edric Milarete19c4cd2016-02-12 10:19:44 -0500439}
440
Edric Milaret627500d2015-03-27 16:41:40 -0400441void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400442CallWidget::on_smartList_clicked(const QModelIndex& index)
Edric Milaret00d34f22016-05-09 16:30:29 -0400443{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400444 Q_UNUSED(index);
Edric Milaret627500d2015-03-27 16:41:40 -0400445}
446
447void
448CallWidget::on_acceptButton_clicked()
449{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400450 auto convModel = LRCInstance::getCurrentConversationModel();
451 auto callModel = LRCInstance::getCurrentCallModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500452 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400453 callModel->accept(conversation->callId);
Edric Milaret627500d2015-03-27 16:41:40 -0400454}
455
456void
457CallWidget::on_refuseButton_clicked()
458{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400459 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500460 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400461 LRCInstance::getCurrentCallModel()->hangUp(conversation->callId);
462 showConversationView();
Edric Milaret6456baa2015-05-21 12:18:07 -0400463}
Edric Milaretc7ab5502015-06-15 11:18:02 -0400464
465void
Edric Milareted0b2802015-10-01 15:10:02 -0400466CallWidget::on_cancelButton_clicked()
Edric Milaretd8528fa2015-07-07 14:13:51 -0400467{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400468 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500469 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400470 LRCInstance::getCurrentCallModel()->hangUp(conversation->callId);
471 showConversationView();
Edric Milaretd8528fa2015-07-07 14:13:51 -0400472}
Edric Milareted0b2802015-10-01 15:10:02 -0400473
474void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400475CallWidget::showConversationView()
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400476{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400477 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
478 ui->messageView->setFocus();
Sébastien Blin93bd2062018-12-17 15:57:16 -0500479 if (ui->messagesWidget->isHidden()) {
480 ui->messagesWidget->show();
481 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400482}
483
484void
485CallWidget::selectSmartlistItem(const std::string & convUid)
486{
487 if (convUid.empty()) {
488 return;
489 }
490 ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect);
491 auto convModel = LRCInstance::getCurrentConversationModel();
492 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
493 if (conversation == convModel->allFilteredConversations().end()) {
494 return;
495 }
496 auto contactURI = QString::fromStdString((*conversation).participants[0]);
497 if (contactURI.isEmpty() ||
498 convModel->owner.contactModel->getContact(contactURI.toStdString()).profileInfo.type == lrc::api::profile::Type::TEMPORARY) {
499 return;
500 }
501 for (int row = 0; row < smartListModel_->rowCount(); row++) {
502 QModelIndex index = smartListModel_->index(row);
503 auto indexContactURI = index.data(SmartListModel::Role::URI).value<QString>();
504 if (indexContactURI == contactURI) {
505 ui->smartList->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
506 return;
507 }
508 }
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400509}
510
511void
Nicolas Jager97a21b42015-12-03 16:55:45 -0500512CallWidget::on_smartList_doubleClicked(const QModelIndex& index)
Edric Milareted0b2802015-10-01 15:10:02 -0400513{
Olivier SOLDANO70279d32017-07-18 15:21:34 -0400514 if (!index.isValid())
515 return;
516
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500517 LRCInstance::getCurrentConversationModel()->placeCall(LRCInstance::getSelectedConvUid());
Edric Milareted0b2802015-10-01 15:10:02 -0400518
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500519 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(LRCInstance::getSelectedConvUid())));
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400520}
Olivier SOLDANOad0fabb2016-11-25 09:08:01 -0500521
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400522QImage
523CallWidget::imageForConv(const std::string& convUid)
524{
525 return Utils::conversationPhoto(convUid, LRCInstance::getCurrentAccountInfo());
526}
Olivier SOLDANOad0fabb2016-11-25 09:08:01 -0500527
Edric Milareted0b2802015-10-01 15:10:02 -0400528void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400529CallWidget::smartListSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Olivier SOLDANO61065ec2016-11-11 16:31:34 -0500530{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400531 Q_UNUSED(deselected);
532 QModelIndexList indices = selected.indexes();
533
534 if (indices.isEmpty()) {
Edric Milareted0b2802015-10-01 15:10:02 -0400535 return;
Anthony Léonardecfe7422017-05-04 14:14:37 -0400536 }
Edric Milareted0b2802015-10-01 15:10:02 -0400537
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400538 auto selectedIndex = indices.at(0);
Olivier SOLDANO703caba2016-11-15 16:18:55 -0500539
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400540 if (not selectedIndex.isValid()) {
541 return;
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400542 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400543
544 selectConversation(selectedIndex);
Edric Milareted0b2802015-10-01 15:10:02 -0400545}
546
547void
548CallWidget::placeCall()
549{
Nicolas Jager97a21b42015-12-03 16:55:45 -0500550 if (ui->ringContactLineEdit->text().isEmpty())
Edric Milareted0b2802015-10-01 15:10:02 -0400551 return;
Nicolas Jager97a21b42015-12-03 16:55:45 -0500552 Call* c = CallModel::instance().dialingCall(PhoneDirectoryModel::instance().getNumber(ui->ringContactLineEdit->text()));
Edric Milareted0b2802015-10-01 15:10:02 -0400553 c->performAction(Call::Action::ACCEPT);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500554 ui->ringContactLineEdit->clear();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400555 auto photoRect = ui->callingPhoto->frameGeometry();
Edric1bed3f92016-05-19 10:24:48 -0400556 ui->callingPhoto->setPixmap(
557 QPixmap::fromImage(
558 GlobalInstances::pixmapManipulator()
Andreas Traczyk43c08232018-10-31 13:42:09 -0400559 .callPhoto(c, QSize(photoRect.width(), photoRect.height()))
560 .value<QImage>()));
Edric Milareted0b2802015-10-01 15:10:02 -0400561}
562
563void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400564CallWidget::conversationsButtonClicked()
565{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400566 ui->btnConversations->setChecked(true);
567 ui->btnInvites->setChecked(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400568 setConversationFilter(lrc::api::profile::Type::RING);
569}
570
571void
572CallWidget::invitationsButtonClicked()
573{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400574 ui->btnConversations->setChecked(false);
575 ui->btnInvites->setChecked(true);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400576 setConversationFilter(lrc::api::profile::Type::PENDING);
577}
578
579void
Nicolas Jager74fe46f2016-02-29 14:55:09 -0500580CallWidget::settingsButtonClicked()
Edric Milareted0b2802015-10-01 15:10:02 -0400581{
Andreas Traczyk7548e732018-12-12 10:47:21 -0500582 emit NavigationRequested(ScreenEnum::SetttingsScreen);
Edric Milareted0b2802015-10-01 15:10:02 -0400583}
584
585void
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400586CallWidget::processContactLineEdit()
Nicolas Jager97a21b42015-12-03 16:55:45 -0500587{
Anthony Léonardaa90e1a2016-10-12 11:24:17 -0400588 auto contactLineText = ui->ringContactLineEdit->text();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400589 setConversationFilter(contactLineText);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500590}
591
592void
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400593CallWidget::on_ringContactLineEdit_returnPressed()
Nicolas Jager97a21b42015-12-03 16:55:45 -0500594{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400595 // select current temporary item and show conversation
596 auto convModel = LRCInstance::getCurrentConversationModel();
597 auto conversations = convModel->allFilteredConversations();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400598 if (!conversations.empty() &&
599 Utils::isContactValid(conversations.at(0).participants.at(0), *convModel)) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400600 selectConversation(smartListModel_->index(0));
601 }
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400602}
603
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400604void CallWidget::slotAcceptInviteClicked(const QModelIndex & index)
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400605{
Andreas Traczyk43865372018-12-27 12:12:35 -0500606 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
607 LRCInstance::getCurrentConversationModel()->makePermanent(convUid);
608 ui->messageView->setInvitation(false);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500609}
610
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400611void CallWidget::slotBlockInviteClicked(const QModelIndex & index)
Nicolas Jager97a21b42015-12-03 16:55:45 -0500612{
Andreas Traczyk43865372018-12-27 12:12:35 -0500613 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
614 if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
615 backToWelcomePage();
616 }
617 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400618}
619
620void CallWidget::slotIgnoreInviteClicked(const QModelIndex & index)
621{
Andreas Traczyk43865372018-12-27 12:12:35 -0500622 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
623 if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
624 backToWelcomePage();
625 }
626 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400627}
628
629void CallWidget::slotCustomContextMenuRequested(const QPoint& pos)
630{
631 setupSmartListContextMenu(pos);
632}
633
Isa Nanic601de1d2018-10-23 11:37:26 -0400634void CallWidget::slotAccountChanged(int index)
635{
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500636 try {
637 auto accountList = LRCInstance::accountModel().getAccountList();
638 setSelectedAccount(accountList.at(index));
639 } catch (...) {
Andreas Traczyk43865372018-12-27 12:12:35 -0500640 qWarning() << "CallWidget::slotAccountChanged exception";
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500641 }
Isa Nanic601de1d2018-10-23 11:37:26 -0400642}
643
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400644void CallWidget::slotShowCallView(const std::string& accountId,
645 const lrc::api::conversation::Info& convInfo)
646{
647 Q_UNUSED(accountId);
648 Q_UNUSED(convInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400649 qDebug() << "slotShowCallView";
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500650 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400651 ui->callStackWidget->setCurrentWidget(ui->videoPage);
Sébastien Blin93bd2062018-12-17 15:57:16 -0500652 ui->videoWidget->showChatviewIfToggled();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400653 hideMiniSpinner();
654}
655
656void CallWidget::slotShowIncomingCallView(const std::string& accountId,
Andreas Traczyk43c08232018-10-31 13:42:09 -0400657 const lrc::api::conversation::Info& convInfo)
658{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400659 Q_UNUSED(accountId);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400660 qDebug() << "slotShowIncomingCallView";
661
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400662 auto callModel = LRCInstance::getCurrentCallModel();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400663
664 if (!callModel->hasCall(convInfo.callId)) {
Nicolas Jager97a21b42015-12-03 16:55:45 -0500665 return;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400666 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500667
Andreas Traczyk43c08232018-10-31 13:42:09 -0400668 auto convModel = LRCInstance::getCurrentConversationModel();
669 ui->callerPhoto->setPixmap(QPixmap::fromImage(imageForConv(convInfo.uid)));
670 auto bestName = QString::fromStdString(Utils::bestNameForConversation(convInfo, *convModel));
671 auto bestId = QString::fromStdString(Utils::bestIdForConversation(convInfo, *convModel));
672 auto finalBestId = (bestName != bestId) ? bestId : "";
673
674 auto call = callModel->getCall(convInfo.callId);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500675 auto isCallSelected = LRCInstance::getSelectedConvUid() == convInfo.uid;
Andreas Traczyk43c08232018-10-31 13:42:09 -0400676
677 if (call.isOutgoing) {
678 if (isCallSelected) {
679 miniSpinner_->start();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400680 ui->spinnerLabel->show();
681 ui->callStackWidget->setCurrentWidget(ui->outgoingCallPage);
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500682 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400683 }
684 } else {
685 if (!QApplication::focusWidget()) {
686 auto formattedName = Utils::bestNameForConversation(convInfo, *convModel);
687 Utils::showSystemNotification(this,
688 QString(tr("Call incoming from %1")).arg(QString::fromStdString(formattedName)));
689 }
690 selectSmartlistItem(convInfo.uid);
691 auto selectedAccountId = LRCInstance::getCurrentAccountInfo().id;
692 auto accountProperties = LRCInstance::accountModel().getAccountConfig(selectedAccountId);
693 if (accountProperties.autoAnswer) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400694 ui->callStackWidget->setCurrentWidget(ui->videoPage);
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500695 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400696 } else if (isCallSelected) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400697 ui->callStackWidget->setCurrentWidget(ui->incomingCallPage);
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500698 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400699 }
700 }
701
Sébastien Blin93bd2062018-12-17 15:57:16 -0500702 if (ui->messagesWidget->isHidden()) {
703 ui->messagesWidget->show();
704 }
705
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400706 ui->videoWidget->pushRenderer(convInfo.callId);
Andreas Traczykfd0d7c02018-10-30 17:14:06 -0400707
Andreas Traczyk43c08232018-10-31 13:42:09 -0400708 QFontMetrics primaryCallLabelFontMetrics(ui->callingBestNameLabel->font());
709 QFontMetrics sencondaryCallLabelFontMetrics(ui->callingBestIdLabel->font());
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400710
Andreas Traczyk43c08232018-10-31 13:42:09 -0400711 QString elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callerBestNameLabel->width());
712 ui->callerBestNameLabel->setText(elidedLabel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400713
Andreas Traczyk43c08232018-10-31 13:42:09 -0400714 elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callingBestNameLabel->width());
715 ui->callingBestNameLabel->setText(elidedLabel);
716
717 elidedLabel = sencondaryCallLabelFontMetrics.elidedText(finalBestId, Qt::ElideRight, ui->callingBestIdLabel->width());
718 ui->callingBestIdLabel->setText(elidedLabel);
719
720 ui->smartList->update();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400721}
722
723void CallWidget::slotShowChatView(const std::string& accountId,
Andreas Traczyk43c08232018-10-31 13:42:09 -0400724 const lrc::api::conversation::Info& convInfo)
725{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400726 Q_UNUSED(accountId);
727 Q_UNUSED(convInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400728
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500729 setCallPanelVisibility(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400730 showConversationView();
Nicolas Jager97a21b42015-12-03 16:55:45 -0500731}
Edric Milaretab12d022015-12-04 16:09:44 -0500732
733void
Sébastien Blin93bd2062018-12-17 15:57:16 -0500734CallWidget::slotToggleFullScreenClicked()
735{
736 if (ui->mainActivityWidget->isFullScreen()) {
737 ui->stackedWidget->addWidget(ui->mainActivityWidget);
738 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
739 ui->mainActivityWidget->showNormal();
740 } else {
741 ui->stackedWidget->removeWidget(ui->mainActivityWidget);
742 ui->mainActivityWidget->setParent(0);
743 ui->mainActivityWidget->showFullScreen();
744 }
745}
746
747void
748CallWidget::slotVideoViewDestroyed(const std::string& callid)
749{
750 auto convUid = LRCInstance::getSelectedConvUid();
751 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
Sébastien Blin93bd2062018-12-17 15:57:16 -0500752 auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
Sébastien Blin62b08ac2018-12-14 16:18:04 -0500753 if (conversation != currentConversationModel->allFilteredConversations().end() &&
754 callid != conversation->callId) {
755 return;
756 }
Sébastien Blin93bd2062018-12-17 15:57:16 -0500757 if (ui->mainActivityWidget->isFullScreen()) {
758 ui->stackedWidget->addWidget(ui->mainActivityWidget);
759 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
760 ui->mainActivityWidget->showNormal();
761 }
762 showConversationView();
763}
764
765void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400766CallWidget::setSelectedAccount(const std::string& accountId)
767{
768 LRCInstance::setSelectedAccountId(accountId);
769
770 // First, we get back to the welcome view (except if in call)
771 if (ui->stackedWidget->currentWidget() != ui->videoPage &&
772 ui->stackedWidget->currentWidget() != ui->welcomePage) {
773 Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
774 }
775
776 // We setup the ringIdLabel and the QRCode
777 auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
778 auto id = accountInfo.registeredName.empty() ? accountInfo.profileInfo.uri : accountInfo.registeredName;
779 auto isRingAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING;
780 if (isRingAccount) {
781 ui->ringIdLabel->setText(QString::fromStdString(id));
782 setupQRCode(QString::fromStdString(accountInfo.profileInfo.uri));
783 }
784
785 updateSmartList();
786 currentTypeFilter_ = accountInfo.profileInfo.type;
787 LRCInstance::getCurrentConversationModel()->setFilter(accountInfo.profileInfo.type);
788 updateConversationsFilterWidget();
789 connectConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500790 connectAccount(accountId);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400791}
792
793void CallWidget::setConversationFilter(lrc::api::profile::Type filter)
794{
795 if (currentTypeFilter_ == filter) {
796 return;
797 }
798 currentTypeFilter_ = filter;
799 LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_);
800}
801
802void CallWidget::updateConversationsFilterWidget()
803{
804 auto invites = LRCInstance::getCurrentAccountInfo().contactModel->pendingRequestCount();
805 if (invites == 0 && currentTypeFilter_ == lrc::api::profile::Type::PENDING) {
806 currentTypeFilter_ = lrc::api::profile::Type::RING;
807 LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_);
808 }
809 ui->conversationsFilterWidget->setVisible(invites);
Andreas Traczyk1d8159a2018-12-13 15:48:24 -0500810 ui->conversationsFilterWidget->updateBadges();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400811 ui->conversationsFilterWidget->update();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400812}
813
814void CallWidget::setConversationFilter(const QString & filter)
815{
816 LRCInstance::getCurrentConversationModel()->setFilter(filter.toStdString());
Anthony Léonardd47179c2017-03-28 10:39:10 -0400817}
818
819void
Edric Milaret6b68a482016-02-01 15:23:44 -0500820CallWidget::showIMOutOfCall(const QModelIndex& nodeIdx)
Edric Milaretab12d022015-12-04 16:09:44 -0500821{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400822 QString displayName = nodeIdx.data(static_cast<int>(SmartListModel::Role::DisplayName)).toString();
823 QString displayId = nodeIdx.data(static_cast<int>(SmartListModel::Role::DisplayID)).toString();
824 QString contactURI = nodeIdx.data(static_cast<int>(SmartListModel::Role::URI)).toString();
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400825
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400826 bool isContact = false;
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500827 auto selectedAccountId = LRCInstance::getCurrAccId();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400828 auto& accountInfo = LRCInstance::accountModel().getAccountInfo(selectedAccountId);
829 bool isRINGAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING;
830 try {
831 accountInfo.contactModel->getContact(contactURI.toStdString());
832 isContact = true;
833 }
834 catch (...) {}
835
Olivier SOLDANO31b9aac2017-07-14 15:50:09 -0400836 ui->imNameLabel->setText(QString(tr("%1", "%1 is the contact username"))
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400837 .arg(displayName));
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400838
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400839 if (isRINGAccount && displayName != displayId){
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400840 ui->imIdLabel->show();
841 ui->imIdLabel->setText(QString(tr("%1", "%1 is the contact unique identifier"))
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400842 .arg(displayId));
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400843 } else {
844 ui->imIdLabel->hide();
845 }
846
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400847 bool shouldShowSendContactRequestBtn = !isContact && isRINGAccount;
Andreas Traczyk912242e2018-10-29 14:44:44 -0400848 ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn);
Olivier SOLDANO815d92f2017-07-13 14:05:36 -0400849
Andreas Traczyk43c08232018-10-31 13:42:09 -0400850 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500851 auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
Andreas Traczyk43c08232018-10-31 13:42:09 -0400852 *convModel);
853 ui->messageView->clear();
Andreas Traczyk43865372018-12-27 12:12:35 -0500854 ui->messageView->printHistory(*convModel, currentConversation->interactions, true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400855
Andreas Traczyk43c08232018-10-31 13:42:09 -0400856 // Contact Avatars
857 auto accInfo = &LRCInstance::getCurrentAccountInfo();
858 auto contactUri = currentConversation->participants.front();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400859 try {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400860 auto& contact = accInfo->contactModel->getContact(contactUri);
Sébastien Blin942d1022018-12-13 09:49:03 -0500861 auto bestName = Utils::bestNameForConversation(*currentConversation, *convModel);
862 ui->messageView->setInvitation(
863 (contact.profileInfo.type == lrc::api::profile::Type::PENDING),
864 bestName,
865 accInfo->contactModel->getContactProfileId(contact.profileInfo.uri)
866 );
Andreas Traczyk43c08232018-10-31 13:42:09 -0400867 if (!contact.profileInfo.avatar.empty()) {
868 ui->messageView->setSenderImage(
869 accInfo->contactModel->getContactProfileId(contactUri),
870 contact.profileInfo.avatar);
871 } else {
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500872 auto avatar = Utils::conversationPhoto(LRCInstance::getSelectedConvUid(), *accInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400873 QByteArray ba;
874 QBuffer bu(&ba);
875 avatar.save(&bu, "PNG");
876 std::string avatarString = ba.toBase64().toStdString();
877 ui->messageView->setSenderImage(
878 accInfo->contactModel->getContactProfileId(contactUri),
879 avatarString);
880 }
881 } catch (...) { }
Edric Milaretab12d022015-12-04 16:09:44 -0500882}
Edric Milaretfa05d972016-01-13 16:22:04 -0500883
884void
Edric Milaret8001f6f2016-01-27 09:55:12 -0500885CallWidget::on_ringContactLineEdit_textChanged(const QString& text)
Edric Milaretfa05d972016-01-13 16:22:04 -0500886{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400887 Q_UNUSED(text);
888 processContactLineEdit();
Edric Milaretfa05d972016-01-13 16:22:04 -0500889}
Edric Milareta0ebd062016-01-13 12:18:23 -0500890
Nicolas Jagerca850292016-01-17 14:11:10 -0500891void
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400892CallWidget::backToWelcomePage()
Edric Milareta0ebd062016-01-13 12:18:23 -0500893{
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500894 qDebug() << "backToWelcomePage";
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400895 deselectConversation();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400896 ui->messageView->hideMessages();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400897 ui->stackedWidget->setCurrentWidget(ui->welcomePage);
Nicolas Jagerca850292016-01-17 14:11:10 -0500898}
899
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400900void
901CallWidget::hideMiniSpinner()
Olivier SOLDANO19193412017-06-06 12:03:36 -0400902{
903 if(ui->spinnerLabel->isVisible()){
904 miniSpinner_->stop();
905 ui->spinnerLabel->hide();
906 }
907}
908
Nicolas Jagerca850292016-01-17 14:11:10 -0500909void
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400910CallWidget::on_imBackButton_clicked()
911{
912 backToWelcomePage();
913}
914
915void
Edric Milaret1e598592016-09-02 10:10:01 -0400916CallWidget::on_qrButton_toggled(bool checked)
917{
918 ui->qrLabel->setVisible(checked);
919}
920
921void
Edric Milaret4097d2f2016-02-09 14:41:50 -0500922CallWidget::on_shareButton_clicked()
923{
Sébastien Blincba5b522018-12-10 12:48:36 -0500924 Utils::InvokeMailto(tr("Contact me on Jami"), tr("My Id is : ") + ui->ringIdLabel->text());
Edric Milaret4097d2f2016-02-09 14:41:50 -0500925}
Anthony Léonardaa90e1a2016-10-12 11:24:17 -0400926
927void
Andreas Traczyk912242e2018-10-29 14:44:44 -0400928CallWidget::on_sendContactRequestButton_clicked()
Olivier SOLDANOdd878662017-03-27 16:00:06 -0400929{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500930 LRCInstance::getCurrentConversationModel()->makePermanent(LRCInstance::getSelectedConvUid());
Andreas Traczyk43865372018-12-27 12:12:35 -0500931 ui->sendContactRequestButton->hide();
Olivier SOLDANOdd878662017-03-27 16:00:06 -0400932}
933
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400934void
Andreas Traczyk912242e2018-10-29 14:44:44 -0400935CallWidget::on_btnAudioCall_clicked()
936{
937 auto convUid = LRCInstance::getSelectedConvUid();
938 LRCInstance::getCurrentConversationModel()->placeAudioOnlyCall(convUid);
939 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
940}
941
942void
943CallWidget::on_btnVideoCall_clicked()
944{
945 auto convUid = LRCInstance::getSelectedConvUid();
946 LRCInstance::getCurrentConversationModel()->placeCall(convUid);
947 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
948}
949
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400950bool
951CallWidget::connectConversationModel()
Anthony Léonard5cc76412017-04-21 16:52:25 -0400952{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400953 auto currentConversationModel = LRCInstance::getCurrentAccountInfo().conversationModel.get();
954
955 if (ui->smartList->selectionModel()) {
956 ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect);
Anthony Léonard5cc76412017-04-21 16:52:25 -0400957 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400958
959 QObject::disconnect(modelSortedConnection_);
960 QObject::disconnect(modelUpdatedConnection_);
961 QObject::disconnect(filterChangedConnection_);
962 QObject::disconnect(newConversationConnection_);
963 QObject::disconnect(conversationRemovedConnection_);
964 QObject::disconnect(conversationClearedConnection);
965 QObject::disconnect(interactionStatusUpdatedConnection_);
966 QObject::disconnect(newInteractionConnection_);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400967 QObject::disconnect(interactionRemovedConnection_);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400968
969 modelSortedConnection_ = QObject::connect(
970 currentConversationModel, &lrc::api::ConversationModel::modelSorted,
971 [this]() {
972 updateConversationsFilterWidget();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500973 selectSmartlistItem(LRCInstance::getSelectedConvUid());
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400974 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400975 }
976 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400977 modelUpdatedConnection_ = QObject::connect(
978 currentConversationModel, &lrc::api::ConversationModel::conversationUpdated,
979 [this](const std::string& convUid) {
980 Q_UNUSED(convUid);
981 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400982 }
983 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400984 filterChangedConnection_ = QObject::connect(
985 currentConversationModel, &lrc::api::ConversationModel::filterChanged,
986 [this]() {
987 updateSmartList();
988 updateConversationsFilterWidget();
989 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400990 }
991 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400992 newConversationConnection_ = QObject::connect(
993 currentConversationModel, &lrc::api::ConversationModel::newConversation,
994 [this](const std::string& convUid) {
995 updateSmartList();
996 updateConversationForNewContact(convUid);
997 ui->conversationsFilterWidget->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400998 }
999 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001000 conversationRemovedConnection_ = QObject::connect(
1001 currentConversationModel, &lrc::api::ConversationModel::conversationRemoved,
1002 [this]() {
1003 backToWelcomePage();
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001004 }
1005 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001006 conversationClearedConnection = QObject::connect(
1007 currentConversationModel, &lrc::api::ConversationModel::conversationCleared,
1008 [this](const std::string& convUid) {
Andreas Traczyk43c08232018-10-31 13:42:09 -04001009 ui->messageView->clear();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001010 // if currently selected,
1011 // switch to welcome screen (deselecting current smartlist item )
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001012 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001013 return;
1014 }
1015 backToWelcomePage();
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001016 }
1017 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001018 interactionStatusUpdatedConnection_ = QObject::connect(
1019 currentConversationModel, &lrc::api::ConversationModel::interactionStatusUpdated,
Andreas Traczyk43c08232018-10-31 13:42:09 -04001020 [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) {
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001021 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001022 return;
1023 }
Andreas Traczyk43c08232018-10-31 13:42:09 -04001024 auto& currentAccountInfo = LRCInstance::getCurrentAccountInfo();
1025 auto currentConversationModel = currentAccountInfo.conversationModel.get();
1026 currentConversationModel->clearUnreadInteractions(convUid);
1027 ui->conversationsFilterWidget->update();
1028 ui->messageView->updateInteraction(*currentConversationModel, interactionId, interaction);
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001029 }
1030 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001031 newInteractionConnection_ = QObject::connect(
1032 currentConversationModel, &lrc::api::ConversationModel::newInteraction,
1033 [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) {
1034 onIncomingMessage(convUid, interactionId, interaction);
Andreas Traczyk4b4bfde2018-12-19 09:53:22 -05001035 if (interaction.type == lrc::api::interaction::Type::CALL) {
1036 return;
1037 }
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001038 if (convUid == LRCInstance::getSelectedConvUid()) {
Andreas Traczyk4b4bfde2018-12-19 09:53:22 -05001039 ui->videoWidget->simulateShowChatview(true);
1040 }
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001041 }
1042 );
Andreas Traczyk43c08232018-10-31 13:42:09 -04001043 interactionRemovedConnection_ = QObject::connect(
1044 currentConversationModel, &lrc::api::ConversationModel::interactionRemoved,
1045 [this](const std::string& convUid, uint64_t interactionId) {
1046 Q_UNUSED(convUid);
1047 ui->messageView->removeInteraction(interactionId);
1048 }
1049 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001050 currentConversationModel->setFilter("");
1051 // clear search field
1052 ui->ringContactLineEdit->setText("");
1053 return true;
1054}
1055
1056void
1057CallWidget::updateConversationView(const std::string& convUid)
1058{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001059 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001060 return;
1061 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001062}
1063
1064void
1065CallWidget::selectConversation(const QModelIndex& index)
1066{
1067 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1068
1069 if (currentConversationModel == nullptr || !index.isValid()) {
1070 return;
1071 }
1072
1073 const auto item = currentConversationModel->filteredConversation(index.row());
1074
1075 if (selectConversation(item, *currentConversationModel)) {
Andreas Traczyk43c08232018-10-31 13:42:09 -04001076 showIMOutOfCall(index);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001077 auto convUid = LRCInstance::getSelectedConvUid();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001078 if (!lastConvUid_.compare(convUid)) {
1079 return;
1080 }
1081 lastConvUid_.assign(convUid);
1082 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1083 auto callModel = LRCInstance::getCurrentCallModel();
1084 auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
1085 const auto item = currentConversationModel->filteredConversation(index.row());
Andreas Traczyk43c08232018-10-31 13:42:09 -04001086 if (callModel->hasCall(conversation->callId) && item.callId == conversation->callId) {
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001087 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -04001088 return;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001089 }
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001090 setCallPanelVisibility(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001091 }
Anthony Léonard5cc76412017-04-21 16:52:25 -04001092}
Anthony Léonardecfe7422017-05-04 14:14:37 -04001093
Anthony Léonard041ad392017-07-14 16:44:09 -04001094bool
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001095CallWidget::selectConversation( const lrc::api::conversation::Info& item,
1096 lrc::api::ConversationModel& convModel)
Anthony Léonard041ad392017-07-14 16:44:09 -04001097{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001098 if (LRCInstance::getSelectedConvUid() == item.uid) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001099 return false;
1100 } else if (item.participants.size() > 0) {
1101 convModel.selectConversation(item.uid);
1102 LRCInstance::setSelectedConvId(item.uid);
1103 convModel.clearUnreadInteractions(item.uid);
1104 ui->conversationsFilterWidget->update();
1105 return true;
Anthony Léonard041ad392017-07-14 16:44:09 -04001106 }
Anthony Léonard041ad392017-07-14 16:44:09 -04001107}
1108
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001109void
1110CallWidget::deselectConversation()
Anthony Léonardecfe7422017-05-04 14:14:37 -04001111{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001112 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1113
1114 if (currentConversationModel == nullptr) {
1115 return;
1116 }
1117
1118 currentConversationModel->selectConversation("");
1119 LRCInstance::setSelectedConvId("");
1120
1121 ui->smartList->selectionModel()->clear();
1122 disconnect(imConnection_);
Anthony Léonardecfe7422017-05-04 14:14:37 -04001123}
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001124
1125void
1126CallWidget::updateConversationForNewContact(const std::string& convUid)
1127{
1128 auto convModel = LRCInstance::getCurrentConversationModel();
1129 if (convModel == nullptr) {
1130 return;
1131 }
1132 ui->ringContactLineEdit->setText("");
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001133 auto selectedUid = LRCInstance::getSelectedConvUid();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001134 auto it = Utils::getConversationFromUid(convUid, *convModel);
1135 if (it != convModel->allFilteredConversations().end()) {
1136 try {
1137 auto contact = convModel->owner.contactModel->getContact(it->participants[0]);
1138 if (!contact.profileInfo.uri.empty() && contact.profileInfo.uri.compare(selectedUid) == 0) {
1139 LRCInstance::setSelectedConvId(convUid);
1140 convModel->selectConversation(convUid);
1141 }
1142 } catch (...) {
1143 return;
1144 }
1145 }
1146}
1147
1148void
1149CallWidget::updateSmartList()
1150{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001151 if (!ui->smartList->model()) {
1152 smartListModel_.reset(new SmartListModel(LRCInstance::getCurrAccId(), this));
1153 ui->smartList->setModel(smartListModel_.get());
1154 ui->smartList->setItemDelegate(new ConversationItemDelegate());
1155 } else {
1156 smartListModel_->setAccount(LRCInstance::getCurrAccId());
1157 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001158
1159 // smartlist selection
1160 QObject::disconnect(smartlistSelectionConnection_);
1161 smartlistSelectionConnection_ = connect(ui->smartList->selectionModel(),
1162 SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
1163 this,
1164 SLOT(smartListSelectionChanged(QItemSelection, QItemSelection)));
1165}
1166
1167void
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001168CallWidget::updateComboBox()
1169{
1170 ui->currentAccountComboBox->updateComboBoxDisplay();
1171}
1172
1173void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001174CallWidget::update()
1175{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001176 updateSmartList();
1177 updateConversationsFilterWidget();
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001178 updateComboBox();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001179 connectConversationModel();
Isa Nanic601de1d2018-10-23 11:37:26 -04001180}
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001181
1182void
1183CallWidget::connectAccount(const std::string& accId)
1184{
1185 auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get();
1186 disconnect(callStatusChangedConnection_);
1187 callStatusChangedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::callStatusChanged,
1188 [this, accId](const std::string& callId) {
1189 auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get();
1190 auto call = callModel->getCall(callId);
1191 switch (call.status) {
1192 case lrc::api::call::Status::INVALID:
1193 case lrc::api::call::Status::INACTIVE:
1194 case lrc::api::call::Status::ENDED:
1195 case lrc::api::call::Status::PEER_BUSY:
1196 case lrc::api::call::Status::TIMEOUT:
1197 case lrc::api::call::Status::TERMINATING:
1198 {
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001199 setCallPanelVisibility(false);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001200 showConversationView();
1201 break;
1202 }
1203 default:
1204 break;
1205 }
1206 });
1207 auto& contactModel = LRCInstance::getCurrentAccountInfo().contactModel;
1208 disconnect(contactAddedConnection_);
1209 contactAddedConnection_ = connect(contactModel.get(), &lrc::api::ContactModel::contactAdded,
1210 [this, &contactModel](const std::string & contactId) {
1211 auto convModel = LRCInstance::getCurrentConversationModel();
1212 auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
1213 *convModel);
1214 if (currentConversation == convModel->allFilteredConversations().end()) {
1215 return;
1216 }
1217 if (contactId == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) {
1218 ui->messageView->clear();
1219 ui->messageView->printHistory(*convModel, currentConversation->interactions);
1220 }
1221 });
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001222}
1223
1224void
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001225CallWidget::setCallPanelVisibility(bool visible)
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001226{
1227 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001228 ui->callStackWidget->setVisible(visible);
1229 ui->imBackButton->setVisible(!visible);
1230 ui->btnAudioCall->setVisible(!visible);
1231 ui->btnVideoCall->setVisible(!visible);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001232}