blob: f91608008e5defd08f8c05127bce3fa896b03f42 [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
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500220 setCallPanelVisibility(false);
Andreas Traczykfc33a492018-12-14 13:53:13 -0500221
222 ui->containerWidget->setVisible(false);
Edric Milaret627500d2015-03-27 16:41:40 -0400223}
224
225CallWidget::~CallWidget()
226{
227 delete ui;
Edric Milaretc7ab5502015-06-15 11:18:02 -0400228 delete menu_;
Edric Milaret00a32252016-01-19 10:37:13 -0500229}
230
Andreas Traczykfc33a492018-12-14 13:53:13 -0500231void
232CallWidget::navigated(bool to)
233{
234 ui->containerWidget->setVisible(to);
235 if (to) {
236 updateSmartList();
237 connectConversationModel();
Andreas Traczyk3fc824d2019-01-02 15:20:21 -0500238 try {
239 auto accountList = LRCInstance::accountModel().getAccountList();
240 if (accountList.size() == 1) {
241 auto index = Utils::indexInVector(accountList, LRCInstance::getCurrAccId());
242 if (index != -1) {
243 slotAccountChanged(index);
244 }
245 }
246 } catch (...) {}
Andreas Traczykb15c83a2018-12-31 12:29:25 -0500247 ui->currentAccountComboBox->updateComboBoxDisplay();
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500248 auto selectedConvUid = LRCInstance::getSelectedConvUid();
249 auto convModel = LRCInstance::getCurrentConversationModel();
250 auto conversation = Utils::getConversationFromUid(selectedConvUid, *convModel);
251 if (!selectedConvUid.empty() && conversation != convModel->allFilteredConversations().end()) {
252 selectSmartlistItem(selectedConvUid);
253 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
254 } else {
255 backToWelcomePage();
256 }
Andreas Traczykfc33a492018-12-14 13:53:13 -0500257 } else {
258 QObject::disconnect(smartlistSelectionConnection_);
259 smartListModel_.reset(nullptr);
260 }
261}
262
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500263void CallWidget::updateCustomUI()
264{
265}
266
Andreas Traczykb81281e2018-12-13 13:13:28 -0500267int
268CallWidget::getLeftPanelWidth()
269{
270 return ui->currentAccountComboBox->width();
271}
272
Edric Milaret00a32252016-01-19 10:37:13 -0500273void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400274CallWidget::onIncomingMessage(const std::string& convUid,
275 uint64_t interactionId,
276 const lrc::api::interaction::Info& interaction)
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400277{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400278 Q_UNUSED(interactionId);
Edric Milaret00a32252016-01-19 10:37:13 -0500279 if (!QApplication::focusWidget()) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400280 auto convModel = LRCInstance::getCurrentConversationModel();
281 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500282 if (conversation == convModel->allFilteredConversations().end()) {
283 return;
284 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400285 auto bestName = Utils::bestNameForConversation(*conversation, *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400286 Utils::showSystemNotification(this,
287 QString(tr("Message incoming from %1"))
Andreas Traczyk43c08232018-10-31 13:42:09 -0400288 .arg(QString::fromStdString(bestName)));
Edric Milaret00a32252016-01-19 10:37:13 -0500289 }
Andreas Traczyk1d8159a2018-12-13 15:48:24 -0500290 updateConversationsFilterWidget();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500291 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400292 return;
293 }
294
295 auto convModel = LRCInstance::getCurrentConversationModel();
296 convModel->clearUnreadInteractions(convUid);
297 auto currentConversation = Utils::getConversationFromUid(convUid, *convModel);
298 if (currentConversation == convModel->allFilteredConversations().end()) {
299 return;
300 }
301 ui->messageView->printNewInteraction(*convModel, interactionId, interaction);
Edric Milareta0ebd062016-01-13 12:18:23 -0500302}
303
304void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400305CallWidget::setupSmartListContextMenu(const QPoint& pos)
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400306{
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400307 QPoint globalPos = ui->smartList->mapToGlobal(pos);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400308 auto index = ui->smartList->indexAt(pos);
309 if (not index.isValid()) {
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400310 return;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400311 }
312
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400313 auto convModel = LRCInstance::getCurrentConversationModel();
314 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID))
315 .value<QString>()
316 .toStdString();
317 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
318 auto contactUid = (*conversation).participants.at(0);
319 auto contact = LRCInstance::getCurrentAccountInfo().contactModel.get()->getContact(contactUid);
320
321 if (!Utils::isContactValid(contactUid, *convModel)) {
322 return;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400323 }
324
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400325 QMenu menu;
326
327 // video call
328 auto videoCallAction = new QAction(tr("Start video call"), this);
329 menu.addAction(videoCallAction);
330 connect(videoCallAction, &QAction::triggered,
331 [this, convUid, conversation, convModel]() {
332 convModel->placeCall(convUid);
333 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500334 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400335 selectConversation(*conversation, *convModel);
336 }
337 });
338 // audio call
339 auto audioCallAction = new QAction(tr("Start audio call"), this);
340 menu.addAction(audioCallAction);
341 connect(audioCallAction, &QAction::triggered,
342 [this, convUid, conversation, convModel]() {
343 convModel->placeAudioOnlyCall(convUid);
344 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500345 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400346 selectConversation(*conversation, *convModel);
347 }
348 });
349
350 if (contact.profileInfo.type == lrc::api::profile::Type::RING) {
351 // separator
352 menu.addSeparator();
353
354 // clear conversation
355 auto clearConversationAction = new QAction(tr("Clear conversation"), this);
356 menu.addAction(clearConversationAction);
357 connect(clearConversationAction, &QAction::triggered,
358 [convUid]() {
359 LRCInstance::getCurrentConversationModel()->clearHistory(convUid);
360 });
Sébastien Blin31fccce2018-12-13 11:27:05 -0500361 // remove contact
362 auto removeContactAction = new QAction(tr("Remove contact"), this);
363 menu.addAction(removeContactAction);
364 connect(removeContactAction, &QAction::triggered,
365 [convUid]() {
366 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
367 });
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400368 // block contact
369 auto blockContactAction = new QAction(tr("Block contact"), this);
370 menu.addAction(blockContactAction);
371 connect(blockContactAction, &QAction::triggered,
372 [convUid]() {
373 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
374 });
375
376 // separator
377 menu.addSeparator();
378
379 // copy number(infohash)
380 auto copyNumberAction = new QAction(tr("Copy number"), this);
381 menu.addAction(copyNumberAction);
382 connect(copyNumberAction, &QAction::triggered,
383 [contact]() {
384 QApplication::clipboard()->setText(
385 QString::fromStdString(contact.profileInfo.uri)
386 );
387 });
388 }
Andreas Traczyk43c08232018-10-31 13:42:09 -0400389 smartListModel_->isContextMenuOpen = true;
Olivier SOLDANOcc28a0d2017-07-21 13:53:31 -0400390 menu.exec(globalPos);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400391 smartListModel_->isContextMenuOpen = false;
Edric Milareta0ebd062016-01-13 12:18:23 -0500392}
393
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400394void
395CallWidget::setupQRCode(QString ringID)
Edric Milarete19c4cd2016-02-12 10:19:44 -0500396{
Anthony Léonarda86a8972016-12-15 10:33:47 -0500397 auto rcode = QRcode_encodeString(ringID.toStdString().c_str(),
Edric Milaret6d0e5312016-04-04 16:30:22 -0400398 0, //Let the version be decided by libqrencode
399 QR_ECLEVEL_L, // Lowest level of error correction
Edric Milarete19c4cd2016-02-12 10:19:44 -0500400 QR_MODE_8, // 8-bit data mode
401 1);
402 if (not rcode) {
403 qWarning() << "Failed to generate QR code: " << strerror(errno);
404 return;
405 }
406
407 auto margin = 5;
408 int qrwidth = rcode->width + margin * 2;
409 QImage result(QSize(qrwidth, qrwidth), QImage::Format_Mono);
410 QPainter painter;
411 painter.begin(&result);
412 painter.setClipRect(QRect(0, 0, qrwidth, qrwidth));
413 painter.setPen(QPen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
414 painter.setBrush(Qt::black);
415 painter.fillRect(QRect(0, 0, qrwidth, qrwidth), Qt::white);
Edric Milaret74474f52016-05-16 13:36:23 -0400416 unsigned char* p;
Edric Milarete19c4cd2016-02-12 10:19:44 -0500417 p = rcode->data;
418 for(int y = 0; y < rcode->width; y++) {
Edric Milaret74474f52016-05-16 13:36:23 -0400419 unsigned char* row = (p + (y * rcode->width));
Edric Milarete19c4cd2016-02-12 10:19:44 -0500420 for(int x = 0; x < rcode->width; x++) {
421 if(*(row + x) & 0x1) {
422 painter.drawRect(margin + x, margin + y, 1, 1);
423 }
424 }
425
426 }
427 painter.end();
428 QRcode_free(rcode);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400429 ui->qrLabel->setPixmap(QPixmap::fromImage(result.scaled(QSize(qrSize_, qrSize_),
430 Qt::KeepAspectRatio)));
Edric Milarete19c4cd2016-02-12 10:19:44 -0500431}
432
Edric Milaret627500d2015-03-27 16:41:40 -0400433void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400434CallWidget::on_smartList_clicked(const QModelIndex& index)
Edric Milaret00d34f22016-05-09 16:30:29 -0400435{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400436 Q_UNUSED(index);
Edric Milaret627500d2015-03-27 16:41:40 -0400437}
438
439void
440CallWidget::on_acceptButton_clicked()
441{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400442 auto convModel = LRCInstance::getCurrentConversationModel();
443 auto callModel = LRCInstance::getCurrentCallModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500444 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400445 callModel->accept(conversation->callId);
Edric Milaret627500d2015-03-27 16:41:40 -0400446}
447
448void
449CallWidget::on_refuseButton_clicked()
450{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400451 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500452 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400453 LRCInstance::getCurrentCallModel()->hangUp(conversation->callId);
454 showConversationView();
Edric Milaret6456baa2015-05-21 12:18:07 -0400455}
Edric Milaretc7ab5502015-06-15 11:18:02 -0400456
457void
Edric Milareted0b2802015-10-01 15:10:02 -0400458CallWidget::on_cancelButton_clicked()
Edric Milaretd8528fa2015-07-07 14:13:51 -0400459{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400460 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500461 auto conversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), *convModel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400462 LRCInstance::getCurrentCallModel()->hangUp(conversation->callId);
463 showConversationView();
Edric Milaretd8528fa2015-07-07 14:13:51 -0400464}
Edric Milareted0b2802015-10-01 15:10:02 -0400465
466void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400467CallWidget::showConversationView()
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400468{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400469 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
470 ui->messageView->setFocus();
Sébastien Blin93bd2062018-12-17 15:57:16 -0500471 if (ui->messagesWidget->isHidden()) {
472 ui->messagesWidget->show();
473 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400474}
475
476void
477CallWidget::selectSmartlistItem(const std::string & convUid)
478{
479 if (convUid.empty()) {
480 return;
481 }
482 ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect);
483 auto convModel = LRCInstance::getCurrentConversationModel();
484 auto conversation = Utils::getConversationFromUid(convUid, *convModel);
485 if (conversation == convModel->allFilteredConversations().end()) {
486 return;
487 }
488 auto contactURI = QString::fromStdString((*conversation).participants[0]);
489 if (contactURI.isEmpty() ||
490 convModel->owner.contactModel->getContact(contactURI.toStdString()).profileInfo.type == lrc::api::profile::Type::TEMPORARY) {
491 return;
492 }
493 for (int row = 0; row < smartListModel_->rowCount(); row++) {
494 QModelIndex index = smartListModel_->index(row);
495 auto indexContactURI = index.data(SmartListModel::Role::URI).value<QString>();
496 if (indexContactURI == contactURI) {
497 ui->smartList->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
498 return;
499 }
500 }
Olivier SOLDANO9657fd12017-03-27 16:06:53 -0400501}
502
503void
Nicolas Jager97a21b42015-12-03 16:55:45 -0500504CallWidget::on_smartList_doubleClicked(const QModelIndex& index)
Edric Milareted0b2802015-10-01 15:10:02 -0400505{
Olivier SOLDANO70279d32017-07-18 15:21:34 -0400506 if (!index.isValid())
507 return;
508
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500509 LRCInstance::getCurrentConversationModel()->placeCall(LRCInstance::getSelectedConvUid());
Edric Milareted0b2802015-10-01 15:10:02 -0400510
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500511 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(LRCInstance::getSelectedConvUid())));
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400512}
Olivier SOLDANOad0fabb2016-11-25 09:08:01 -0500513
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400514QImage
515CallWidget::imageForConv(const std::string& convUid)
516{
517 return Utils::conversationPhoto(convUid, LRCInstance::getCurrentAccountInfo());
518}
Olivier SOLDANOad0fabb2016-11-25 09:08:01 -0500519
Edric Milareted0b2802015-10-01 15:10:02 -0400520void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400521CallWidget::smartListSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Olivier SOLDANO61065ec2016-11-11 16:31:34 -0500522{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400523 Q_UNUSED(deselected);
524 QModelIndexList indices = selected.indexes();
525
526 if (indices.isEmpty()) {
Edric Milareted0b2802015-10-01 15:10:02 -0400527 return;
Anthony Léonardecfe7422017-05-04 14:14:37 -0400528 }
Edric Milareted0b2802015-10-01 15:10:02 -0400529
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400530 auto selectedIndex = indices.at(0);
Olivier SOLDANO703caba2016-11-15 16:18:55 -0500531
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400532 if (not selectedIndex.isValid()) {
533 return;
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400534 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400535
536 selectConversation(selectedIndex);
Edric Milareted0b2802015-10-01 15:10:02 -0400537}
538
539void
540CallWidget::placeCall()
541{
Nicolas Jager97a21b42015-12-03 16:55:45 -0500542 if (ui->ringContactLineEdit->text().isEmpty())
Edric Milareted0b2802015-10-01 15:10:02 -0400543 return;
Nicolas Jager97a21b42015-12-03 16:55:45 -0500544 Call* c = CallModel::instance().dialingCall(PhoneDirectoryModel::instance().getNumber(ui->ringContactLineEdit->text()));
Edric Milareted0b2802015-10-01 15:10:02 -0400545 c->performAction(Call::Action::ACCEPT);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500546 ui->ringContactLineEdit->clear();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400547 auto photoRect = ui->callingPhoto->frameGeometry();
Edric1bed3f92016-05-19 10:24:48 -0400548 ui->callingPhoto->setPixmap(
549 QPixmap::fromImage(
550 GlobalInstances::pixmapManipulator()
Andreas Traczyk43c08232018-10-31 13:42:09 -0400551 .callPhoto(c, QSize(photoRect.width(), photoRect.height()))
552 .value<QImage>()));
Edric Milareted0b2802015-10-01 15:10:02 -0400553}
554
555void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400556CallWidget::conversationsButtonClicked()
557{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400558 ui->btnConversations->setChecked(true);
559 ui->btnInvites->setChecked(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400560 setConversationFilter(lrc::api::profile::Type::RING);
561}
562
563void
564CallWidget::invitationsButtonClicked()
565{
Andreas Traczyk43c08232018-10-31 13:42:09 -0400566 ui->btnConversations->setChecked(false);
567 ui->btnInvites->setChecked(true);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400568 setConversationFilter(lrc::api::profile::Type::PENDING);
569}
570
571void
Nicolas Jager74fe46f2016-02-29 14:55:09 -0500572CallWidget::settingsButtonClicked()
Edric Milareted0b2802015-10-01 15:10:02 -0400573{
Andreas Traczyk7548e732018-12-12 10:47:21 -0500574 emit NavigationRequested(ScreenEnum::SetttingsScreen);
Edric Milareted0b2802015-10-01 15:10:02 -0400575}
576
577void
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400578CallWidget::processContactLineEdit()
Nicolas Jager97a21b42015-12-03 16:55:45 -0500579{
Anthony Léonardaa90e1a2016-10-12 11:24:17 -0400580 auto contactLineText = ui->ringContactLineEdit->text();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400581 setConversationFilter(contactLineText);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500582}
583
584void
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400585CallWidget::on_ringContactLineEdit_returnPressed()
Nicolas Jager97a21b42015-12-03 16:55:45 -0500586{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400587 // select current temporary item and show conversation
588 auto convModel = LRCInstance::getCurrentConversationModel();
589 auto conversations = convModel->allFilteredConversations();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400590 if (!conversations.empty() &&
591 Utils::isContactValid(conversations.at(0).participants.at(0), *convModel)) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400592 selectConversation(smartListModel_->index(0));
593 }
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400594}
595
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400596void CallWidget::slotAcceptInviteClicked(const QModelIndex & index)
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400597{
Andreas Traczyk43865372018-12-27 12:12:35 -0500598 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
599 LRCInstance::getCurrentConversationModel()->makePermanent(convUid);
600 ui->messageView->setInvitation(false);
Nicolas Jager97a21b42015-12-03 16:55:45 -0500601}
602
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400603void CallWidget::slotBlockInviteClicked(const QModelIndex & index)
Nicolas Jager97a21b42015-12-03 16:55:45 -0500604{
Andreas Traczyk43865372018-12-27 12:12:35 -0500605 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
606 if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
607 backToWelcomePage();
608 }
609 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400610}
611
612void CallWidget::slotIgnoreInviteClicked(const QModelIndex & index)
613{
Andreas Traczyk43865372018-12-27 12:12:35 -0500614 auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
615 if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
616 backToWelcomePage();
617 }
618 LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400619}
620
621void CallWidget::slotCustomContextMenuRequested(const QPoint& pos)
622{
623 setupSmartListContextMenu(pos);
624}
625
Isa Nanic601de1d2018-10-23 11:37:26 -0400626void CallWidget::slotAccountChanged(int index)
627{
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500628 try {
629 auto accountList = LRCInstance::accountModel().getAccountList();
630 setSelectedAccount(accountList.at(index));
631 } catch (...) {
Andreas Traczyk43865372018-12-27 12:12:35 -0500632 qWarning() << "CallWidget::slotAccountChanged exception";
Andreas Traczyk6ace34f2018-12-14 14:31:23 -0500633 }
Isa Nanic601de1d2018-10-23 11:37:26 -0400634}
635
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400636void CallWidget::slotShowCallView(const std::string& accountId,
637 const lrc::api::conversation::Info& convInfo)
638{
639 Q_UNUSED(accountId);
640 Q_UNUSED(convInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400641 qDebug() << "slotShowCallView";
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500642 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400643 ui->callStackWidget->setCurrentWidget(ui->videoPage);
Sébastien Blin93bd2062018-12-17 15:57:16 -0500644 ui->videoWidget->showChatviewIfToggled();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400645 hideMiniSpinner();
646}
647
648void CallWidget::slotShowIncomingCallView(const std::string& accountId,
Andreas Traczyk43c08232018-10-31 13:42:09 -0400649 const lrc::api::conversation::Info& convInfo)
650{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400651 Q_UNUSED(accountId);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400652 qDebug() << "slotShowIncomingCallView";
653
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400654 auto callModel = LRCInstance::getCurrentCallModel();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400655
656 if (!callModel->hasCall(convInfo.callId)) {
Nicolas Jager97a21b42015-12-03 16:55:45 -0500657 return;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400658 }
Nicolas Jager97a21b42015-12-03 16:55:45 -0500659
Andreas Traczyk43c08232018-10-31 13:42:09 -0400660 auto convModel = LRCInstance::getCurrentConversationModel();
661 ui->callerPhoto->setPixmap(QPixmap::fromImage(imageForConv(convInfo.uid)));
662 auto bestName = QString::fromStdString(Utils::bestNameForConversation(convInfo, *convModel));
663 auto bestId = QString::fromStdString(Utils::bestIdForConversation(convInfo, *convModel));
664 auto finalBestId = (bestName != bestId) ? bestId : "";
665
666 auto call = callModel->getCall(convInfo.callId);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500667 auto isCallSelected = LRCInstance::getSelectedConvUid() == convInfo.uid;
Andreas Traczyk43c08232018-10-31 13:42:09 -0400668
669 if (call.isOutgoing) {
670 if (isCallSelected) {
671 miniSpinner_->start();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400672 ui->spinnerLabel->show();
673 ui->callStackWidget->setCurrentWidget(ui->outgoingCallPage);
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500674 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400675 }
676 } else {
677 if (!QApplication::focusWidget()) {
678 auto formattedName = Utils::bestNameForConversation(convInfo, *convModel);
679 Utils::showSystemNotification(this,
680 QString(tr("Call incoming from %1")).arg(QString::fromStdString(formattedName)));
681 }
682 selectSmartlistItem(convInfo.uid);
683 auto selectedAccountId = LRCInstance::getCurrentAccountInfo().id;
684 auto accountProperties = LRCInstance::accountModel().getAccountConfig(selectedAccountId);
685 if (accountProperties.autoAnswer) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400686 ui->callStackWidget->setCurrentWidget(ui->videoPage);
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500687 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400688 } else if (isCallSelected) {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400689 ui->callStackWidget->setCurrentWidget(ui->incomingCallPage);
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500690 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400691 }
692 }
693
Sébastien Blin93bd2062018-12-17 15:57:16 -0500694 if (ui->messagesWidget->isHidden()) {
695 ui->messagesWidget->show();
696 }
697
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400698 ui->videoWidget->pushRenderer(convInfo.callId);
Andreas Traczykfd0d7c02018-10-30 17:14:06 -0400699
Andreas Traczyk43c08232018-10-31 13:42:09 -0400700 QFontMetrics primaryCallLabelFontMetrics(ui->callingBestNameLabel->font());
701 QFontMetrics sencondaryCallLabelFontMetrics(ui->callingBestIdLabel->font());
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400702
Andreas Traczyk43c08232018-10-31 13:42:09 -0400703 QString elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callerBestNameLabel->width());
704 ui->callerBestNameLabel->setText(elidedLabel);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400705
Andreas Traczyk43c08232018-10-31 13:42:09 -0400706 elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callingBestNameLabel->width());
707 ui->callingBestNameLabel->setText(elidedLabel);
708
709 elidedLabel = sencondaryCallLabelFontMetrics.elidedText(finalBestId, Qt::ElideRight, ui->callingBestIdLabel->width());
710 ui->callingBestIdLabel->setText(elidedLabel);
711
712 ui->smartList->update();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400713}
714
715void CallWidget::slotShowChatView(const std::string& accountId,
Andreas Traczyk43c08232018-10-31 13:42:09 -0400716 const lrc::api::conversation::Info& convInfo)
717{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400718 Q_UNUSED(accountId);
719 Q_UNUSED(convInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400720
Andreas Traczyk0147bf12019-01-03 20:46:03 -0500721 setCallPanelVisibility(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400722 showConversationView();
Nicolas Jager97a21b42015-12-03 16:55:45 -0500723}
Edric Milaretab12d022015-12-04 16:09:44 -0500724
725void
Sébastien Blin93bd2062018-12-17 15:57:16 -0500726CallWidget::slotToggleFullScreenClicked()
727{
728 if (ui->mainActivityWidget->isFullScreen()) {
729 ui->stackedWidget->addWidget(ui->mainActivityWidget);
730 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
731 ui->mainActivityWidget->showNormal();
732 } else {
733 ui->stackedWidget->removeWidget(ui->mainActivityWidget);
734 ui->mainActivityWidget->setParent(0);
735 ui->mainActivityWidget->showFullScreen();
736 }
737}
738
739void
740CallWidget::slotVideoViewDestroyed(const std::string& callid)
741{
742 auto convUid = LRCInstance::getSelectedConvUid();
743 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
Sébastien Blin93bd2062018-12-17 15:57:16 -0500744 auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
Sébastien Blin62b08ac2018-12-14 16:18:04 -0500745 if (conversation != currentConversationModel->allFilteredConversations().end() &&
746 callid != conversation->callId) {
747 return;
748 }
Sébastien Blin93bd2062018-12-17 15:57:16 -0500749 if (ui->mainActivityWidget->isFullScreen()) {
750 ui->stackedWidget->addWidget(ui->mainActivityWidget);
751 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
752 ui->mainActivityWidget->showNormal();
753 }
754 showConversationView();
755}
756
757void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400758CallWidget::setSelectedAccount(const std::string& accountId)
759{
760 LRCInstance::setSelectedAccountId(accountId);
761
762 // First, we get back to the welcome view (except if in call)
763 if (ui->stackedWidget->currentWidget() != ui->videoPage &&
764 ui->stackedWidget->currentWidget() != ui->welcomePage) {
765 Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
766 }
767
768 // We setup the ringIdLabel and the QRCode
769 auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
770 auto id = accountInfo.registeredName.empty() ? accountInfo.profileInfo.uri : accountInfo.registeredName;
771 auto isRingAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING;
772 if (isRingAccount) {
773 ui->ringIdLabel->setText(QString::fromStdString(id));
774 setupQRCode(QString::fromStdString(accountInfo.profileInfo.uri));
775 }
776
777 updateSmartList();
778 currentTypeFilter_ = accountInfo.profileInfo.type;
779 LRCInstance::getCurrentConversationModel()->setFilter(accountInfo.profileInfo.type);
780 updateConversationsFilterWidget();
781 connectConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500782 connectAccount(accountId);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400783}
784
785void CallWidget::setConversationFilter(lrc::api::profile::Type filter)
786{
787 if (currentTypeFilter_ == filter) {
788 return;
789 }
790 currentTypeFilter_ = filter;
791 LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_);
792}
793
794void CallWidget::updateConversationsFilterWidget()
795{
796 auto invites = LRCInstance::getCurrentAccountInfo().contactModel->pendingRequestCount();
797 if (invites == 0 && currentTypeFilter_ == lrc::api::profile::Type::PENDING) {
798 currentTypeFilter_ = lrc::api::profile::Type::RING;
799 LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_);
800 }
801 ui->conversationsFilterWidget->setVisible(invites);
Andreas Traczyk1d8159a2018-12-13 15:48:24 -0500802 ui->conversationsFilterWidget->updateBadges();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400803 ui->conversationsFilterWidget->update();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400804}
805
806void CallWidget::setConversationFilter(const QString & filter)
807{
808 LRCInstance::getCurrentConversationModel()->setFilter(filter.toStdString());
Anthony Léonardd47179c2017-03-28 10:39:10 -0400809}
810
811void
Edric Milaret6b68a482016-02-01 15:23:44 -0500812CallWidget::showIMOutOfCall(const QModelIndex& nodeIdx)
Edric Milaretab12d022015-12-04 16:09:44 -0500813{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400814 QString displayName = nodeIdx.data(static_cast<int>(SmartListModel::Role::DisplayName)).toString();
815 QString displayId = nodeIdx.data(static_cast<int>(SmartListModel::Role::DisplayID)).toString();
816 QString contactURI = nodeIdx.data(static_cast<int>(SmartListModel::Role::URI)).toString();
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400817
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400818 bool isContact = false;
Isa Nanic6e4a39a2018-12-04 14:26:02 -0500819 auto selectedAccountId = LRCInstance::getCurrAccId();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400820 auto& accountInfo = LRCInstance::accountModel().getAccountInfo(selectedAccountId);
821 bool isRINGAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING;
822 try {
823 accountInfo.contactModel->getContact(contactURI.toStdString());
824 isContact = true;
825 }
826 catch (...) {}
827
Olivier SOLDANO31b9aac2017-07-14 15:50:09 -0400828 ui->imNameLabel->setText(QString(tr("%1", "%1 is the contact username"))
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400829 .arg(displayName));
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400830
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400831 if (isRINGAccount && displayName != displayId){
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400832 ui->imIdLabel->show();
833 ui->imIdLabel->setText(QString(tr("%1", "%1 is the contact unique identifier"))
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400834 .arg(displayId));
Olivier SOLDANO483f9682017-07-26 11:57:49 -0400835 } else {
836 ui->imIdLabel->hide();
837 }
838
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400839 bool shouldShowSendContactRequestBtn = !isContact && isRINGAccount;
Andreas Traczyk912242e2018-10-29 14:44:44 -0400840 ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn);
Olivier SOLDANO815d92f2017-07-13 14:05:36 -0400841
Andreas Traczyk43c08232018-10-31 13:42:09 -0400842 auto convModel = LRCInstance::getCurrentConversationModel();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500843 auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
Andreas Traczyk43c08232018-10-31 13:42:09 -0400844 *convModel);
845 ui->messageView->clear();
Andreas Traczyk43865372018-12-27 12:12:35 -0500846 ui->messageView->printHistory(*convModel, currentConversation->interactions, true);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400847
Andreas Traczyk43c08232018-10-31 13:42:09 -0400848 // Contact Avatars
849 auto accInfo = &LRCInstance::getCurrentAccountInfo();
850 auto contactUri = currentConversation->participants.front();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400851 try {
Andreas Traczyk43c08232018-10-31 13:42:09 -0400852 auto& contact = accInfo->contactModel->getContact(contactUri);
Sébastien Blin942d1022018-12-13 09:49:03 -0500853 auto bestName = Utils::bestNameForConversation(*currentConversation, *convModel);
854 ui->messageView->setInvitation(
855 (contact.profileInfo.type == lrc::api::profile::Type::PENDING),
856 bestName,
857 accInfo->contactModel->getContactProfileId(contact.profileInfo.uri)
858 );
Andreas Traczyk43c08232018-10-31 13:42:09 -0400859 if (!contact.profileInfo.avatar.empty()) {
860 ui->messageView->setSenderImage(
861 accInfo->contactModel->getContactProfileId(contactUri),
862 contact.profileInfo.avatar);
863 } else {
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500864 auto avatar = Utils::conversationPhoto(LRCInstance::getSelectedConvUid(), *accInfo);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400865 QByteArray ba;
866 QBuffer bu(&ba);
867 avatar.save(&bu, "PNG");
868 std::string avatarString = ba.toBase64().toStdString();
869 ui->messageView->setSenderImage(
870 accInfo->contactModel->getContactProfileId(contactUri),
871 avatarString);
872 }
873 } catch (...) { }
Edric Milaretab12d022015-12-04 16:09:44 -0500874}
Edric Milaretfa05d972016-01-13 16:22:04 -0500875
876void
Edric Milaret8001f6f2016-01-27 09:55:12 -0500877CallWidget::on_ringContactLineEdit_textChanged(const QString& text)
Edric Milaretfa05d972016-01-13 16:22:04 -0500878{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400879 Q_UNUSED(text);
880 processContactLineEdit();
Edric Milaretfa05d972016-01-13 16:22:04 -0500881}
Edric Milareta0ebd062016-01-13 12:18:23 -0500882
Nicolas Jagerca850292016-01-17 14:11:10 -0500883void
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400884CallWidget::backToWelcomePage()
Edric Milareta0ebd062016-01-13 12:18:23 -0500885{
Andreas Traczyk39fa4d02019-01-03 17:32:07 -0500886 qDebug() << "backToWelcomePage";
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400887 deselectConversation();
Andreas Traczyk43c08232018-10-31 13:42:09 -0400888 ui->messageView->hideMessages();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400889 ui->stackedWidget->setCurrentWidget(ui->welcomePage);
Nicolas Jagerca850292016-01-17 14:11:10 -0500890}
891
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400892void
893CallWidget::hideMiniSpinner()
Olivier SOLDANO19193412017-06-06 12:03:36 -0400894{
895 if(ui->spinnerLabel->isVisible()){
896 miniSpinner_->stop();
897 ui->spinnerLabel->hide();
898 }
899}
900
Nicolas Jagerca850292016-01-17 14:11:10 -0500901void
Olivier SOLDANO2bcdfd72017-05-02 14:37:19 -0400902CallWidget::on_imBackButton_clicked()
903{
904 backToWelcomePage();
905}
906
907void
Edric Milaret1e598592016-09-02 10:10:01 -0400908CallWidget::on_qrButton_toggled(bool checked)
909{
910 ui->qrLabel->setVisible(checked);
911}
912
913void
Edric Milaret4097d2f2016-02-09 14:41:50 -0500914CallWidget::on_shareButton_clicked()
915{
Sébastien Blincba5b522018-12-10 12:48:36 -0500916 Utils::InvokeMailto(tr("Contact me on Jami"), tr("My Id is : ") + ui->ringIdLabel->text());
Edric Milaret4097d2f2016-02-09 14:41:50 -0500917}
Anthony Léonardaa90e1a2016-10-12 11:24:17 -0400918
919void
Andreas Traczyk912242e2018-10-29 14:44:44 -0400920CallWidget::on_sendContactRequestButton_clicked()
Olivier SOLDANOdd878662017-03-27 16:00:06 -0400921{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500922 LRCInstance::getCurrentConversationModel()->makePermanent(LRCInstance::getSelectedConvUid());
Andreas Traczyk43865372018-12-27 12:12:35 -0500923 ui->sendContactRequestButton->hide();
Olivier SOLDANOdd878662017-03-27 16:00:06 -0400924}
925
Olivier SOLDANO47aa97f2017-04-04 10:40:00 -0400926void
Andreas Traczyk912242e2018-10-29 14:44:44 -0400927CallWidget::on_btnAudioCall_clicked()
928{
929 auto convUid = LRCInstance::getSelectedConvUid();
930 LRCInstance::getCurrentConversationModel()->placeAudioOnlyCall(convUid);
931 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
932}
933
934void
935CallWidget::on_btnVideoCall_clicked()
936{
937 auto convUid = LRCInstance::getSelectedConvUid();
938 LRCInstance::getCurrentConversationModel()->placeCall(convUid);
939 ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid)));
940}
941
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400942bool
943CallWidget::connectConversationModel()
Anthony Léonard5cc76412017-04-21 16:52:25 -0400944{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400945 auto currentConversationModel = LRCInstance::getCurrentAccountInfo().conversationModel.get();
946
947 if (ui->smartList->selectionModel()) {
948 ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect);
Anthony Léonard5cc76412017-04-21 16:52:25 -0400949 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400950
951 QObject::disconnect(modelSortedConnection_);
952 QObject::disconnect(modelUpdatedConnection_);
953 QObject::disconnect(filterChangedConnection_);
954 QObject::disconnect(newConversationConnection_);
955 QObject::disconnect(conversationRemovedConnection_);
956 QObject::disconnect(conversationClearedConnection);
957 QObject::disconnect(interactionStatusUpdatedConnection_);
958 QObject::disconnect(newInteractionConnection_);
Andreas Traczyk43c08232018-10-31 13:42:09 -0400959 QObject::disconnect(interactionRemovedConnection_);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400960
961 modelSortedConnection_ = QObject::connect(
962 currentConversationModel, &lrc::api::ConversationModel::modelSorted,
963 [this]() {
964 updateConversationsFilterWidget();
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -0500965 selectSmartlistItem(LRCInstance::getSelectedConvUid());
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400966 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400967 }
968 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400969 modelUpdatedConnection_ = QObject::connect(
970 currentConversationModel, &lrc::api::ConversationModel::conversationUpdated,
971 [this](const std::string& convUid) {
972 Q_UNUSED(convUid);
973 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400974 }
975 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400976 filterChangedConnection_ = QObject::connect(
977 currentConversationModel, &lrc::api::ConversationModel::filterChanged,
978 [this]() {
979 updateSmartList();
980 updateConversationsFilterWidget();
981 ui->smartList->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400982 }
983 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400984 newConversationConnection_ = QObject::connect(
985 currentConversationModel, &lrc::api::ConversationModel::newConversation,
986 [this](const std::string& convUid) {
987 updateSmartList();
988 updateConversationForNewContact(convUid);
989 ui->conversationsFilterWidget->update();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400990 }
991 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400992 conversationRemovedConnection_ = QObject::connect(
993 currentConversationModel, &lrc::api::ConversationModel::conversationRemoved,
994 [this]() {
995 backToWelcomePage();
Isa Nanic37ccc1c2018-10-26 14:16:28 -0400996 }
997 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -0400998 conversationClearedConnection = QObject::connect(
999 currentConversationModel, &lrc::api::ConversationModel::conversationCleared,
1000 [this](const std::string& convUid) {
Andreas Traczyk43c08232018-10-31 13:42:09 -04001001 ui->messageView->clear();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001002 // if currently selected,
1003 // switch to welcome screen (deselecting current smartlist item )
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001004 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001005 return;
1006 }
1007 backToWelcomePage();
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001008 }
1009 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001010 interactionStatusUpdatedConnection_ = QObject::connect(
1011 currentConversationModel, &lrc::api::ConversationModel::interactionStatusUpdated,
Andreas Traczyk43c08232018-10-31 13:42:09 -04001012 [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) {
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001013 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001014 return;
1015 }
Andreas Traczyk43c08232018-10-31 13:42:09 -04001016 auto& currentAccountInfo = LRCInstance::getCurrentAccountInfo();
1017 auto currentConversationModel = currentAccountInfo.conversationModel.get();
1018 currentConversationModel->clearUnreadInteractions(convUid);
1019 ui->conversationsFilterWidget->update();
1020 ui->messageView->updateInteraction(*currentConversationModel, interactionId, interaction);
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001021 }
1022 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001023 newInteractionConnection_ = QObject::connect(
1024 currentConversationModel, &lrc::api::ConversationModel::newInteraction,
1025 [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) {
1026 onIncomingMessage(convUid, interactionId, interaction);
Andreas Traczyk4b4bfde2018-12-19 09:53:22 -05001027 if (interaction.type == lrc::api::interaction::Type::CALL) {
1028 return;
1029 }
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001030 if (convUid == LRCInstance::getSelectedConvUid()) {
Andreas Traczyk4b4bfde2018-12-19 09:53:22 -05001031 ui->videoWidget->simulateShowChatview(true);
1032 }
Isa Nanic37ccc1c2018-10-26 14:16:28 -04001033 }
1034 );
Andreas Traczyk43c08232018-10-31 13:42:09 -04001035 interactionRemovedConnection_ = QObject::connect(
1036 currentConversationModel, &lrc::api::ConversationModel::interactionRemoved,
1037 [this](const std::string& convUid, uint64_t interactionId) {
1038 Q_UNUSED(convUid);
1039 ui->messageView->removeInteraction(interactionId);
1040 }
1041 );
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001042 currentConversationModel->setFilter("");
1043 // clear search field
1044 ui->ringContactLineEdit->setText("");
1045 return true;
1046}
1047
1048void
1049CallWidget::updateConversationView(const std::string& convUid)
1050{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001051 if (convUid != LRCInstance::getSelectedConvUid()) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001052 return;
1053 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001054}
1055
1056void
1057CallWidget::selectConversation(const QModelIndex& index)
1058{
1059 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1060
1061 if (currentConversationModel == nullptr || !index.isValid()) {
1062 return;
1063 }
1064
1065 const auto item = currentConversationModel->filteredConversation(index.row());
1066
1067 if (selectConversation(item, *currentConversationModel)) {
Andreas Traczyk43c08232018-10-31 13:42:09 -04001068 showIMOutOfCall(index);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001069 auto convUid = LRCInstance::getSelectedConvUid();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001070 if (!lastConvUid_.compare(convUid)) {
1071 return;
1072 }
1073 lastConvUid_.assign(convUid);
1074 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1075 auto callModel = LRCInstance::getCurrentCallModel();
1076 auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel);
1077 const auto item = currentConversationModel->filteredConversation(index.row());
Andreas Traczyk43c08232018-10-31 13:42:09 -04001078 if (callModel->hasCall(conversation->callId) && item.callId == conversation->callId) {
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001079 setCallPanelVisibility(true);
Andreas Traczyk43c08232018-10-31 13:42:09 -04001080 return;
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001081 }
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001082 setCallPanelVisibility(false);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001083 }
Anthony Léonard5cc76412017-04-21 16:52:25 -04001084}
Anthony Léonardecfe7422017-05-04 14:14:37 -04001085
Anthony Léonard041ad392017-07-14 16:44:09 -04001086bool
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001087CallWidget::selectConversation( const lrc::api::conversation::Info& item,
1088 lrc::api::ConversationModel& convModel)
Anthony Léonard041ad392017-07-14 16:44:09 -04001089{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001090 if (LRCInstance::getSelectedConvUid() == item.uid) {
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001091 return false;
1092 } else if (item.participants.size() > 0) {
1093 convModel.selectConversation(item.uid);
1094 LRCInstance::setSelectedConvId(item.uid);
1095 convModel.clearUnreadInteractions(item.uid);
1096 ui->conversationsFilterWidget->update();
1097 return true;
Anthony Léonard041ad392017-07-14 16:44:09 -04001098 }
Anthony Léonard041ad392017-07-14 16:44:09 -04001099}
1100
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001101void
1102CallWidget::deselectConversation()
Anthony Léonardecfe7422017-05-04 14:14:37 -04001103{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001104 auto currentConversationModel = LRCInstance::getCurrentConversationModel();
1105
1106 if (currentConversationModel == nullptr) {
1107 return;
1108 }
1109
1110 currentConversationModel->selectConversation("");
1111 LRCInstance::setSelectedConvId("");
1112
1113 ui->smartList->selectionModel()->clear();
1114 disconnect(imConnection_);
Anthony Léonardecfe7422017-05-04 14:14:37 -04001115}
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001116
1117void
1118CallWidget::updateConversationForNewContact(const std::string& convUid)
1119{
1120 auto convModel = LRCInstance::getCurrentConversationModel();
1121 if (convModel == nullptr) {
1122 return;
1123 }
1124 ui->ringContactLineEdit->setText("");
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001125 auto selectedUid = LRCInstance::getSelectedConvUid();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001126 auto it = Utils::getConversationFromUid(convUid, *convModel);
1127 if (it != convModel->allFilteredConversations().end()) {
1128 try {
1129 auto contact = convModel->owner.contactModel->getContact(it->participants[0]);
1130 if (!contact.profileInfo.uri.empty() && contact.profileInfo.uri.compare(selectedUid) == 0) {
1131 LRCInstance::setSelectedConvId(convUid);
1132 convModel->selectConversation(convUid);
1133 }
1134 } catch (...) {
1135 return;
1136 }
1137 }
1138}
1139
1140void
1141CallWidget::updateSmartList()
1142{
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001143 if (!ui->smartList->model()) {
1144 smartListModel_.reset(new SmartListModel(LRCInstance::getCurrAccId(), this));
1145 ui->smartList->setModel(smartListModel_.get());
1146 ui->smartList->setItemDelegate(new ConversationItemDelegate());
1147 } else {
1148 smartListModel_->setAccount(LRCInstance::getCurrAccId());
1149 }
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001150
1151 // smartlist selection
1152 QObject::disconnect(smartlistSelectionConnection_);
1153 smartlistSelectionConnection_ = connect(ui->smartList->selectionModel(),
1154 SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
1155 this,
1156 SLOT(smartListSelectionChanged(QItemSelection, QItemSelection)));
1157}
1158
1159void
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001160CallWidget::updateComboBox()
1161{
1162 ui->currentAccountComboBox->updateComboBoxDisplay();
1163}
1164
1165void
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001166CallWidget::update()
1167{
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001168 updateSmartList();
1169 updateConversationsFilterWidget();
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001170 updateComboBox();
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001171 connectConversationModel();
Isa Nanic601de1d2018-10-23 11:37:26 -04001172}
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001173
1174void
1175CallWidget::connectAccount(const std::string& accId)
1176{
1177 auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get();
1178 disconnect(callStatusChangedConnection_);
1179 callStatusChangedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::callStatusChanged,
1180 [this, accId](const std::string& callId) {
1181 auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get();
1182 auto call = callModel->getCall(callId);
1183 switch (call.status) {
1184 case lrc::api::call::Status::INVALID:
1185 case lrc::api::call::Status::INACTIVE:
1186 case lrc::api::call::Status::ENDED:
1187 case lrc::api::call::Status::PEER_BUSY:
1188 case lrc::api::call::Status::TIMEOUT:
1189 case lrc::api::call::Status::TERMINATING:
1190 {
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001191 setCallPanelVisibility(false);
Andreas Traczyk6b5ad3e2019-01-02 17:04:36 -05001192 showConversationView();
1193 break;
1194 }
1195 default:
1196 break;
1197 }
1198 });
1199 auto& contactModel = LRCInstance::getCurrentAccountInfo().contactModel;
1200 disconnect(contactAddedConnection_);
1201 contactAddedConnection_ = connect(contactModel.get(), &lrc::api::ContactModel::contactAdded,
1202 [this, &contactModel](const std::string & contactId) {
1203 auto convModel = LRCInstance::getCurrentConversationModel();
1204 auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
1205 *convModel);
1206 if (currentConversation == convModel->allFilteredConversations().end()) {
1207 return;
1208 }
1209 if (contactId == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) {
1210 ui->messageView->clear();
1211 ui->messageView->printHistory(*convModel, currentConversation->interactions);
1212 }
1213 });
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001214}
1215
1216void
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001217CallWidget::setCallPanelVisibility(bool visible)
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001218{
1219 ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget);
Andreas Traczyk0147bf12019-01-03 20:46:03 -05001220 ui->callStackWidget->setVisible(visible);
1221 ui->imBackButton->setVisible(!visible);
1222 ui->btnAudioCall->setVisible(!visible);
1223 ui->btnVideoCall->setVisible(!visible);
Andreas Traczyk39fa4d02019-01-03 17:32:07 -05001224}