Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Sébastien Blin | 68abac9 | 2019-01-02 17:41:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2019 by Savoir-faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
Olivier SOLDANO | 47aa97f | 2017-04-04 10:40:00 -0400 | [diff] [blame] | 4 | * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> * |
| 5 | * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> * |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 6 | * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 7 | * Author: Isa Nanic <isa.nanic@savoirfairelinux.com> * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 8 | * * |
| 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 Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 26 | #include <QScrollBar> |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 27 | #include <QClipboard> |
Edric Milaret | 70ae878 | 2016-04-18 16:10:44 -0400 | [diff] [blame] | 28 | #include <QDesktopServices> |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 29 | #include <QComboBox> |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 30 | #include <QWebEngineScript> |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 31 | |
Sébastien Blin | 942d102 | 2018-12-13 09:49:03 -0500 | [diff] [blame] | 32 | #include <algorithm> |
Edric Milaret | 53f57b6 | 2015-05-11 11:02:17 -0400 | [diff] [blame] | 33 | #include <memory> |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 34 | |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 35 | #include <qrencode.h> |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 36 | |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 37 | //ERROR is defined in windows.h |
| 38 | #include "utils.h" |
| 39 | #undef ERROR |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 40 | #undef interface |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 41 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 42 | // lrc |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 43 | #include "globalinstances.h" |
Olivier SOLDANO | 6936119 | 2017-04-20 10:32:05 -0400 | [diff] [blame] | 44 | #include "profilemodel.h" |
Olivier SOLDANO | 6936119 | 2017-04-20 10:32:05 -0400 | [diff] [blame] | 45 | #include "localprofilecollection.h" |
Anthony Léonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 46 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 47 | // client |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 48 | #include "windowscontactbackend.h" |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 49 | #include "globalsystemtray.h" |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 50 | #include "conversationitemdelegate.h" |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 51 | #include "pixbufmanipulator.h" |
Edric Milaret | 70ae878 | 2016-04-18 16:10:44 -0400 | [diff] [blame] | 52 | #include "settingskey.h" |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 53 | #include "lrcinstance.h" |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 54 | #include "animationhelpers.h" |
| 55 | #include "ringthemeutils.h" |
Andreas Traczyk | 868c3d6 | 2019-01-03 21:05:40 -0500 | [diff] [blame] | 56 | #include "mainwindow.h" |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 57 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 58 | CallWidget::CallWidget(QWidget* parent) : |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 59 | NavWidget(parent), |
Edric Milaret | 7d40a4a | 2015-05-13 13:01:15 -0400 | [diff] [blame] | 60 | ui(new Ui::CallWidget), |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 61 | menu_(new QMenu()) |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 62 | { |
| 63 | ui->setupUi(this); |
| 64 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 65 | using namespace lrc::api; |
Nicolas Jager | ca85029 | 2016-01-17 14:11:10 -0500 | [diff] [blame] | 66 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 67 | QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); |
Edric Milaret | 3aca8e3 | 2015-06-12 10:01:40 -0400 | [diff] [blame] | 68 | |
Sébastien Blin | cba5b52 | 2018-12-10 12:48:36 -0500 | [diff] [blame] | 69 | QPixmap logo(":/images/logo-jami-standard-coul.png"); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 70 | ui->ringLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation)); |
| 71 | ui->ringLogo->setAlignment(Qt::AlignHCenter); |
| 72 | |
Edric Milaret | 1e59859 | 2016-09-02 10:10:01 -0400 | [diff] [blame] | 73 | ui->qrLabel->hide(); |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 74 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 75 | videoRenderer_ = nullptr; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 76 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 77 | // this line is not welcome here, and must be removed |
| 78 | ProfileModel::instance().addCollection<LocalProfileCollection>(LoadOptions::FORCE_ENABLED); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 79 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 80 | QSettings settings; |
| 81 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 82 | // select last used account if stored in registry |
| 83 | auto accountList = LRCInstance::accountModel().getAccountList(); |
| 84 | if (!accountList.empty()) { |
| 85 | std::string accountIdToStartWith; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 86 | 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 SOLDANO | af8f282 | 2017-07-11 12:15:18 -0400 | [diff] [blame] | 93 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 94 | } |
| 95 | else { |
| 96 | accountIdToStartWith = accountList.at(0); |
| 97 | } |
| 98 | setSelectedAccount(accountIdToStartWith); |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 99 | // get account index and set the currentAccountComboBox |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 100 | auto index = Utils::indexInVector(accountList, accountIdToStartWith); |
| 101 | if (index != -1) { |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 102 | ui->currentAccountComboBox->setCurrentIndex(index); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 103 | } |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 104 | } |
Olivier SOLDANO | 2100f1c | 2017-09-06 16:45:20 -0400 | [diff] [blame] | 105 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 106 | 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 Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 112 | ui->mainActivitySplitter->setCollapsible(1, false); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 113 | |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 114 | //disable dropdown shadow on combobox |
| 115 | ui->currentAccountComboBox->view()->window()->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); |
| 116 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 117 | // conversation list |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 118 | ui->smartList->setContextMenuPolicy(Qt::CustomContextMenu); |
| 119 | |
| 120 | // setup searchingfor mini spinner |
| 121 | miniSpinner_ = new QMovie(":/images/waiting.gif"); |
| 122 | ui->spinnerLabel->setMovie(miniSpinner_); |
| 123 | ui->spinnerLabel->hide(); |
| 124 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 125 | // connections |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 126 | connect(ui->currentAccountComboBox, &CurrentAccountComboBox::settingsButtonClicked, |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 127 | this, &CallWidget::settingsButtonClicked); |
| 128 | |
Andreas Traczyk | 6ace34f | 2018-12-14 14:31:23 -0500 | [diff] [blame] | 129 | connect(ui->currentAccountComboBox, &CurrentAccountComboBox::newAccountClicked, |
| 130 | [this]() { |
| 131 | emit NavigationRequested(ScreenEnum::WizardScreen); |
| 132 | }); |
| 133 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 134 | connect(ui->videoWidget, &VideoView::setChatVisibility, |
| 135 | [this](bool visible) { |
Sébastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 136 | if (visible) { |
| 137 | ui->messagesWidget->show(); |
| 138 | } else { |
| 139 | ui->messagesWidget->hide(); |
| 140 | } |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 141 | }); |
| 142 | |
| 143 | connect(ui->mainActivitySplitter, &QSplitter::splitterMoved, |
| 144 | [this](int pos, int index) { |
Andreas Traczyk | 14c3e86 | 2018-12-26 14:02:30 -0500 | [diff] [blame] | 145 | Q_UNUSED(index); |
| 146 | Q_UNUSED(pos); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 147 | QSettings settings; |
| 148 | settings.setValue(SettingsKey::mainSplitterState, ui->mainActivitySplitter->saveState()); |
| 149 | }); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 150 | |
| 151 | connect(ui->videoWidget, &VideoView::videoSettingsClicked, |
| 152 | this, &CallWidget::settingsButtonClicked); |
| 153 | |
Sébastien Blin | 62b08ac | 2018-12-14 16:18:04 -0500 | [diff] [blame] | 154 | connect(ui->videoWidget, &VideoView::toggleFullScreenClicked, |
| 155 | this, &CallWidget::slotToggleFullScreenClicked); |
| 156 | |
| 157 | connect(ui->videoWidget, &VideoView::closing, |
| 158 | this, &CallWidget::slotVideoViewDestroyed); |
| 159 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 160 | connect(ui->btnConversations, &QPushButton::clicked, |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 161 | this, &CallWidget::conversationsButtonClicked); |
| 162 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 163 | connect(ui->btnInvites, &QPushButton::clicked, |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 164 | this, &CallWidget::invitationsButtonClicked); |
| 165 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 166 | connect(ui->smartList, &QTreeView::customContextMenuRequested, |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 167 | this, &CallWidget::slotCustomContextMenuRequested); |
| 168 | |
| 169 | connect(ui->smartList, &SmartListView::btnAcceptInviteClicked, |
| 170 | this, &CallWidget::slotAcceptInviteClicked); |
| 171 | |
| 172 | connect(ui->smartList, &SmartListView::btnBlockInviteClicked, |
| 173 | this, &CallWidget::slotBlockInviteClicked); |
| 174 | |
| 175 | connect(ui->smartList, &SmartListView::btnIgnoreInviteClicked, |
| 176 | this, &CallWidget::slotIgnoreInviteClicked); |
| 177 | |
| 178 | connect(&LRCInstance::behaviorController(), &BehaviorController::showCallView, |
| 179 | this, &CallWidget::slotShowCallView); |
| 180 | |
| 181 | connect(&LRCInstance::behaviorController(), &BehaviorController::showIncomingCallView, |
| 182 | this, &CallWidget::slotShowIncomingCallView); |
| 183 | |
| 184 | connect(&LRCInstance::behaviorController(), &BehaviorController::showChatView, |
| 185 | this, &CallWidget::slotShowChatView); |
Andreas Traczyk | 55f92cb | 2018-10-23 12:26:25 -0400 | [diff] [blame] | 186 | |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 187 | connect(ui->currentAccountComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), |
| 188 | this, &CallWidget::slotAccountChanged); |
| 189 | |
Andreas Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 190 | connect(ui->sendContactRequestButton, &QPushButton::clicked, |
| 191 | this, &CallWidget::on_sendContactRequestButton_clicked); |
| 192 | |
| 193 | connect(ui->btnAudioCall, &QPushButton::clicked, |
| 194 | this, &CallWidget::on_sendContactRequestButton_clicked); |
| 195 | |
| 196 | connect(ui->btnVideoCall, &QPushButton::clicked, |
| 197 | this, &CallWidget::on_sendContactRequestButton_clicked); |
| 198 | |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 199 | connect(ui->currentAccountComboBox, QOverload<int>::of(&CurrentAccountComboBox::currentIndexChanged), |
| 200 | [this] { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 201 | ui->btnConversations->setChecked(true); |
| 202 | ui->btnInvites->setChecked(false); |
| 203 | }); |
| 204 | |
Andreas Traczyk | 4386537 | 2018-12-27 12:12:35 -0500 | [diff] [blame] | 205 | connect(ui->messageView, &MessageWebView::conversationRemoved, |
| 206 | [this] { |
| 207 | backToWelcomePage(); |
| 208 | }); |
| 209 | |
Andreas Traczyk | 55f92cb | 2018-10-23 12:26:25 -0400 | [diff] [blame] | 210 | // set first view to welcome view |
| 211 | ui->stackedWidget->setCurrentWidget(ui->welcomePage); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 212 | ui->btnConversations->setChecked(true); |
| 213 | |
| 214 | // chat view |
| 215 | ui->messageView->buildView(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 216 | |
Andreas Traczyk | b81281e | 2018-12-13 13:13:28 -0500 | [diff] [blame] | 217 | // hide the call stack |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 218 | setCallPanelVisibility(false); |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 219 | |
| 220 | ui->containerWidget->setVisible(false); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | CallWidget::~CallWidget() |
| 224 | { |
| 225 | delete ui; |
Edric Milaret | c7ab550 | 2015-06-15 11:18:02 -0400 | [diff] [blame] | 226 | delete menu_; |
Edric Milaret | 00a3225 | 2016-01-19 10:37:13 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 229 | void |
| 230 | CallWidget::navigated(bool to) |
| 231 | { |
| 232 | ui->containerWidget->setVisible(to); |
| 233 | if (to) { |
| 234 | updateSmartList(); |
| 235 | connectConversationModel(); |
Andreas Traczyk | 3fc824d | 2019-01-02 15:20:21 -0500 | [diff] [blame] | 236 | try { |
| 237 | auto accountList = LRCInstance::accountModel().getAccountList(); |
| 238 | if (accountList.size() == 1) { |
| 239 | auto index = Utils::indexInVector(accountList, LRCInstance::getCurrAccId()); |
| 240 | if (index != -1) { |
| 241 | slotAccountChanged(index); |
| 242 | } |
| 243 | } |
| 244 | } catch (...) {} |
Andreas Traczyk | b15c83a | 2018-12-31 12:29:25 -0500 | [diff] [blame] | 245 | ui->currentAccountComboBox->updateComboBoxDisplay(); |
Andreas Traczyk | 39fa4d0 | 2019-01-03 17:32:07 -0500 | [diff] [blame] | 246 | auto selectedConvUid = LRCInstance::getSelectedConvUid(); |
| 247 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 248 | auto conversation = Utils::getConversationFromUid(selectedConvUid, *convModel); |
| 249 | if (!selectedConvUid.empty() && conversation != convModel->allFilteredConversations().end()) { |
| 250 | selectSmartlistItem(selectedConvUid); |
| 251 | ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget); |
| 252 | } else { |
| 253 | backToWelcomePage(); |
| 254 | } |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 255 | } else { |
| 256 | QObject::disconnect(smartlistSelectionConnection_); |
| 257 | smartListModel_.reset(nullptr); |
| 258 | } |
| 259 | } |
| 260 | |
Andreas Traczyk | 59ba48a | 2019-01-04 16:12:03 -0500 | [diff] [blame] | 261 | void |
| 262 | CallWidget::updateCustomUI() |
Andreas Traczyk | 6ace34f | 2018-12-14 14:31:23 -0500 | [diff] [blame] | 263 | { |
Andreas Traczyk | 868c3d6 | 2019-01-03 21:05:40 -0500 | [diff] [blame] | 264 | auto scalingRatio = MainWindow::instance().getCurrentScalingRatio(); |
| 265 | if (scalingRatio > 1.0) { |
| 266 | ui->messageView->setZoomFactor(1.15); |
| 267 | } else { |
| 268 | ui->messageView->setZoomFactor(1.0); |
| 269 | } |
| 270 | |
Andreas Traczyk | 6ace34f | 2018-12-14 14:31:23 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Andreas Traczyk | b81281e | 2018-12-13 13:13:28 -0500 | [diff] [blame] | 273 | int |
| 274 | CallWidget::getLeftPanelWidth() |
| 275 | { |
| 276 | return ui->currentAccountComboBox->width(); |
| 277 | } |
| 278 | |
Edric Milaret | 00a3225 | 2016-01-19 10:37:13 -0500 | [diff] [blame] | 279 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 280 | CallWidget::onIncomingMessage(const std::string& convUid, |
| 281 | uint64_t interactionId, |
| 282 | const lrc::api::interaction::Info& interaction) |
Olivier SOLDANO | 9657fd1 | 2017-03-27 16:06:53 -0400 | [diff] [blame] | 283 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 284 | Q_UNUSED(interactionId); |
Edric Milaret | 00a3225 | 2016-01-19 10:37:13 -0500 | [diff] [blame] | 285 | if (!QApplication::focusWidget()) { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 286 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 287 | auto conversation = Utils::getConversationFromUid(convUid, *convModel); |
Andreas Traczyk | 39fa4d0 | 2019-01-03 17:32:07 -0500 | [diff] [blame] | 288 | if (conversation == convModel->allFilteredConversations().end()) { |
| 289 | return; |
| 290 | } |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 291 | auto bestName = Utils::bestNameForConversation(*conversation, *convModel); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 292 | Utils::showSystemNotification(this, |
| 293 | QString(tr("Message incoming from %1")) |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 294 | .arg(QString::fromStdString(bestName))); |
Edric Milaret | 00a3225 | 2016-01-19 10:37:13 -0500 | [diff] [blame] | 295 | } |
Andreas Traczyk | 1d8159a | 2018-12-13 15:48:24 -0500 | [diff] [blame] | 296 | updateConversationsFilterWidget(); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 297 | if (convUid != LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | |
| 301 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 302 | convModel->clearUnreadInteractions(convUid); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 303 | auto convInfo = Utils::getSelectedConversation(); |
| 304 | if (!convInfo.uid.empty()) { |
| 305 | ui->messageView->printNewInteraction(*convModel, interactionId, interaction); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 306 | } |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 310 | CallWidget::setupSmartListContextMenu(const QPoint& pos) |
Olivier SOLDANO | 9657fd1 | 2017-03-27 16:06:53 -0400 | [diff] [blame] | 311 | { |
Olivier SOLDANO | cc28a0d | 2017-07-21 13:53:31 -0400 | [diff] [blame] | 312 | QPoint globalPos = ui->smartList->mapToGlobal(pos); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 313 | auto index = ui->smartList->indexAt(pos); |
| 314 | if (not index.isValid()) { |
Olivier SOLDANO | cc28a0d | 2017-07-21 13:53:31 -0400 | [diff] [blame] | 315 | return; |
Olivier SOLDANO | cc28a0d | 2017-07-21 13:53:31 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 318 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 319 | auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)) |
| 320 | .value<QString>() |
| 321 | .toStdString(); |
| 322 | auto conversation = Utils::getConversationFromUid(convUid, *convModel); |
| 323 | auto contactUid = (*conversation).participants.at(0); |
| 324 | auto contact = LRCInstance::getCurrentAccountInfo().contactModel.get()->getContact(contactUid); |
| 325 | |
| 326 | if (!Utils::isContactValid(contactUid, *convModel)) { |
| 327 | return; |
Olivier SOLDANO | cc28a0d | 2017-07-21 13:53:31 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 330 | QMenu menu; |
| 331 | |
| 332 | // video call |
| 333 | auto videoCallAction = new QAction(tr("Start video call"), this); |
| 334 | menu.addAction(videoCallAction); |
| 335 | connect(videoCallAction, &QAction::triggered, |
| 336 | [this, convUid, conversation, convModel]() { |
| 337 | convModel->placeCall(convUid); |
| 338 | ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid))); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 339 | if (convUid != LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 340 | selectConversation(*conversation, *convModel); |
| 341 | } |
| 342 | }); |
| 343 | // audio call |
| 344 | auto audioCallAction = new QAction(tr("Start audio call"), this); |
| 345 | menu.addAction(audioCallAction); |
| 346 | connect(audioCallAction, &QAction::triggered, |
| 347 | [this, convUid, conversation, convModel]() { |
| 348 | convModel->placeAudioOnlyCall(convUid); |
| 349 | ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convUid))); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 350 | if (convUid != LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 351 | selectConversation(*conversation, *convModel); |
| 352 | } |
| 353 | }); |
| 354 | |
| 355 | if (contact.profileInfo.type == lrc::api::profile::Type::RING) { |
| 356 | // separator |
| 357 | menu.addSeparator(); |
| 358 | |
| 359 | // clear conversation |
| 360 | auto clearConversationAction = new QAction(tr("Clear conversation"), this); |
| 361 | menu.addAction(clearConversationAction); |
| 362 | connect(clearConversationAction, &QAction::triggered, |
| 363 | [convUid]() { |
| 364 | LRCInstance::getCurrentConversationModel()->clearHistory(convUid); |
| 365 | }); |
Sébastien Blin | 31fccce | 2018-12-13 11:27:05 -0500 | [diff] [blame] | 366 | // remove contact |
| 367 | auto removeContactAction = new QAction(tr("Remove contact"), this); |
| 368 | menu.addAction(removeContactAction); |
| 369 | connect(removeContactAction, &QAction::triggered, |
| 370 | [convUid]() { |
| 371 | LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false); |
| 372 | }); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 373 | // block contact |
| 374 | auto blockContactAction = new QAction(tr("Block contact"), this); |
| 375 | menu.addAction(blockContactAction); |
| 376 | connect(blockContactAction, &QAction::triggered, |
| 377 | [convUid]() { |
| 378 | LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true); |
| 379 | }); |
| 380 | |
| 381 | // separator |
| 382 | menu.addSeparator(); |
| 383 | |
| 384 | // copy number(infohash) |
| 385 | auto copyNumberAction = new QAction(tr("Copy number"), this); |
| 386 | menu.addAction(copyNumberAction); |
| 387 | connect(copyNumberAction, &QAction::triggered, |
| 388 | [contact]() { |
| 389 | QApplication::clipboard()->setText( |
| 390 | QString::fromStdString(contact.profileInfo.uri) |
| 391 | ); |
| 392 | }); |
| 393 | } |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 394 | smartListModel_->isContextMenuOpen = true; |
Olivier SOLDANO | cc28a0d | 2017-07-21 13:53:31 -0400 | [diff] [blame] | 395 | menu.exec(globalPos); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 396 | smartListModel_->isContextMenuOpen = false; |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 397 | } |
| 398 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 399 | void |
| 400 | CallWidget::setupQRCode(QString ringID) |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 401 | { |
Anthony Léonard | a86a897 | 2016-12-15 10:33:47 -0500 | [diff] [blame] | 402 | auto rcode = QRcode_encodeString(ringID.toStdString().c_str(), |
Edric Milaret | 6d0e531 | 2016-04-04 16:30:22 -0400 | [diff] [blame] | 403 | 0, //Let the version be decided by libqrencode |
| 404 | QR_ECLEVEL_L, // Lowest level of error correction |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 405 | QR_MODE_8, // 8-bit data mode |
| 406 | 1); |
| 407 | if (not rcode) { |
| 408 | qWarning() << "Failed to generate QR code: " << strerror(errno); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | auto margin = 5; |
| 413 | int qrwidth = rcode->width + margin * 2; |
| 414 | QImage result(QSize(qrwidth, qrwidth), QImage::Format_Mono); |
| 415 | QPainter painter; |
| 416 | painter.begin(&result); |
| 417 | painter.setClipRect(QRect(0, 0, qrwidth, qrwidth)); |
| 418 | painter.setPen(QPen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); |
| 419 | painter.setBrush(Qt::black); |
| 420 | painter.fillRect(QRect(0, 0, qrwidth, qrwidth), Qt::white); |
Edric Milaret | 74474f5 | 2016-05-16 13:36:23 -0400 | [diff] [blame] | 421 | unsigned char* p; |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 422 | p = rcode->data; |
| 423 | for(int y = 0; y < rcode->width; y++) { |
Edric Milaret | 74474f5 | 2016-05-16 13:36:23 -0400 | [diff] [blame] | 424 | unsigned char* row = (p + (y * rcode->width)); |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 425 | for(int x = 0; x < rcode->width; x++) { |
| 426 | if(*(row + x) & 0x1) { |
| 427 | painter.drawRect(margin + x, margin + y, 1, 1); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | } |
| 432 | painter.end(); |
| 433 | QRcode_free(rcode); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 434 | ui->qrLabel->setPixmap(QPixmap::fromImage(result.scaled(QSize(qrSize_, qrSize_), |
| 435 | Qt::KeepAspectRatio))); |
Edric Milaret | e19c4cd | 2016-02-12 10:19:44 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 438 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 439 | CallWidget::on_smartList_clicked(const QModelIndex& index) |
Edric Milaret | 00d34f2 | 2016-05-09 16:30:29 -0400 | [diff] [blame] | 440 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 441 | Q_UNUSED(index); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void |
| 445 | CallWidget::on_acceptButton_clicked() |
| 446 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 447 | auto convInfo = Utils::getSelectedConversation(); |
| 448 | if (!convInfo.uid.empty()) { |
| 449 | LRCInstance::getCurrentCallModel()->accept(convInfo.callId); |
| 450 | } |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void |
| 454 | CallWidget::on_refuseButton_clicked() |
| 455 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 456 | auto convInfo = Utils::getSelectedConversation(); |
| 457 | if (!convInfo.uid.empty()) { |
| 458 | LRCInstance::getCurrentCallModel()->hangUp(convInfo.callId); |
| 459 | showConversationView(); |
| 460 | } |
Edric Milaret | 6456baa | 2015-05-21 12:18:07 -0400 | [diff] [blame] | 461 | } |
Edric Milaret | c7ab550 | 2015-06-15 11:18:02 -0400 | [diff] [blame] | 462 | |
| 463 | void |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 464 | CallWidget::on_cancelButton_clicked() |
Edric Milaret | d8528fa | 2015-07-07 14:13:51 -0400 | [diff] [blame] | 465 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 466 | on_refuseButton_clicked(); |
Edric Milaret | d8528fa | 2015-07-07 14:13:51 -0400 | [diff] [blame] | 467 | } |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 468 | |
| 469 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 470 | CallWidget::showConversationView() |
Olivier SOLDANO | 9657fd1 | 2017-03-27 16:06:53 -0400 | [diff] [blame] | 471 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 472 | if (LRCInstance::getSelectedConvUid().empty()) { |
| 473 | backToWelcomePage(); |
| 474 | return; |
| 475 | } |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 476 | ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget); |
| 477 | ui->messageView->setFocus(); |
Sébastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 478 | if (ui->messagesWidget->isHidden()) { |
| 479 | ui->messagesWidget->show(); |
| 480 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 483 | bool |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 484 | CallWidget::selectSmartlistItem(const std::string & convUid) |
| 485 | { |
Andreas Traczyk | 9c9d46b | 2019-01-07 16:13:17 -0500 | [diff] [blame] | 486 | if (convUid.empty() || !ui->smartList->selectionModel()) |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 487 | return false; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 488 | ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect); |
| 489 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 490 | auto conversation = Utils::getConversationFromUid(convUid, *convModel); |
| 491 | if (conversation == convModel->allFilteredConversations().end()) { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 492 | return false; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 493 | } |
| 494 | auto contactURI = QString::fromStdString((*conversation).participants[0]); |
| 495 | if (contactURI.isEmpty() || |
| 496 | convModel->owner.contactModel->getContact(contactURI.toStdString()).profileInfo.type == lrc::api::profile::Type::TEMPORARY) { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 497 | return false; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 498 | } |
| 499 | for (int row = 0; row < smartListModel_->rowCount(); row++) { |
| 500 | QModelIndex index = smartListModel_->index(row); |
| 501 | auto indexContactURI = index.data(SmartListModel::Role::URI).value<QString>(); |
| 502 | if (indexContactURI == contactURI) { |
| 503 | ui->smartList->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 504 | return true; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 505 | } |
| 506 | } |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 507 | return false; |
Olivier SOLDANO | 9657fd1 | 2017-03-27 16:06:53 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 511 | CallWidget::on_smartList_doubleClicked(const QModelIndex& index) |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 512 | { |
Olivier SOLDANO | 70279d3 | 2017-07-18 15:21:34 -0400 | [diff] [blame] | 513 | if (!index.isValid()) |
| 514 | return; |
| 515 | |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 516 | selectConversation(index); |
| 517 | |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 518 | LRCInstance::getCurrentConversationModel()->placeCall(LRCInstance::getSelectedConvUid()); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 519 | |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 520 | ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(LRCInstance::getSelectedConvUid()))); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 521 | } |
Olivier SOLDANO | ad0fabb | 2016-11-25 09:08:01 -0500 | [diff] [blame] | 522 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 523 | QImage |
| 524 | CallWidget::imageForConv(const std::string& convUid) |
| 525 | { |
| 526 | return Utils::conversationPhoto(convUid, LRCInstance::getCurrentAccountInfo()); |
| 527 | } |
Olivier SOLDANO | ad0fabb | 2016-11-25 09:08:01 -0500 | [diff] [blame] | 528 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 529 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 530 | CallWidget::smartListSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) |
Olivier SOLDANO | 61065ec | 2016-11-11 16:31:34 -0500 | [diff] [blame] | 531 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 532 | Q_UNUSED(deselected); |
| 533 | QModelIndexList indices = selected.indexes(); |
| 534 | |
| 535 | if (indices.isEmpty()) { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 536 | return; |
Anthony Léonard | ecfe742 | 2017-05-04 14:14:37 -0400 | [diff] [blame] | 537 | } |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 538 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 539 | auto selectedIndex = indices.at(0); |
Olivier SOLDANO | 703caba | 2016-11-15 16:18:55 -0500 | [diff] [blame] | 540 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 541 | if (not selectedIndex.isValid()) { |
| 542 | return; |
Olivier SOLDANO | 2bcdfd7 | 2017-05-02 14:37:19 -0400 | [diff] [blame] | 543 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 544 | |
| 545 | selectConversation(selectedIndex); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 549 | CallWidget::conversationsButtonClicked() |
| 550 | { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 551 | ui->btnConversations->setChecked(true); |
| 552 | ui->btnInvites->setChecked(false); |
Andreas Traczyk | dc17c81 | 2019-01-11 15:35:20 -0500 | [diff] [blame] | 553 | ui->ringContactLineEdit->setPlaceholderString(tr("Find a new or existing contact")); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 554 | setConversationFilter(lrc::api::profile::Type::RING); |
| 555 | } |
| 556 | |
| 557 | void |
| 558 | CallWidget::invitationsButtonClicked() |
| 559 | { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 560 | ui->btnConversations->setChecked(false); |
| 561 | ui->btnInvites->setChecked(true); |
Andreas Traczyk | dc17c81 | 2019-01-11 15:35:20 -0500 | [diff] [blame] | 562 | ui->ringContactLineEdit->setPlaceholderString(tr("Search your received invitations")); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 563 | setConversationFilter(lrc::api::profile::Type::PENDING); |
| 564 | } |
| 565 | |
| 566 | void |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 567 | CallWidget::settingsButtonClicked() |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 568 | { |
Andreas Traczyk | 7548e73 | 2018-12-12 10:47:21 -0500 | [diff] [blame] | 569 | emit NavigationRequested(ScreenEnum::SetttingsScreen); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void |
Olivier SOLDANO | 47aa97f | 2017-04-04 10:40:00 -0400 | [diff] [blame] | 573 | CallWidget::processContactLineEdit() |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 574 | { |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 575 | auto contactLineText = ui->ringContactLineEdit->text(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 576 | setConversationFilter(contactLineText); |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | void |
Olivier SOLDANO | 47aa97f | 2017-04-04 10:40:00 -0400 | [diff] [blame] | 580 | CallWidget::on_ringContactLineEdit_returnPressed() |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 581 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 582 | // select current temporary item and show conversation |
| 583 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 584 | auto conversations = convModel->allFilteredConversations(); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 585 | if (!conversations.empty() && |
| 586 | Utils::isContactValid(conversations.at(0).participants.at(0), *convModel)) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 587 | selectConversation(smartListModel_->index(0)); |
| 588 | } |
Olivier SOLDANO | 47aa97f | 2017-04-04 10:40:00 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 591 | void CallWidget::slotAcceptInviteClicked(const QModelIndex & index) |
Olivier SOLDANO | 47aa97f | 2017-04-04 10:40:00 -0400 | [diff] [blame] | 592 | { |
Andreas Traczyk | 4386537 | 2018-12-27 12:12:35 -0500 | [diff] [blame] | 593 | auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString(); |
| 594 | LRCInstance::getCurrentConversationModel()->makePermanent(convUid); |
| 595 | ui->messageView->setInvitation(false); |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 596 | } |
| 597 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 598 | void CallWidget::slotBlockInviteClicked(const QModelIndex & index) |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 599 | { |
Andreas Traczyk | 4386537 | 2018-12-27 12:12:35 -0500 | [diff] [blame] | 600 | auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString(); |
| 601 | if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) { |
| 602 | backToWelcomePage(); |
| 603 | } |
| 604 | LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | void CallWidget::slotIgnoreInviteClicked(const QModelIndex & index) |
| 608 | { |
Andreas Traczyk | 4386537 | 2018-12-27 12:12:35 -0500 | [diff] [blame] | 609 | auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString(); |
| 610 | if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) { |
| 611 | backToWelcomePage(); |
| 612 | } |
| 613 | LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | void CallWidget::slotCustomContextMenuRequested(const QPoint& pos) |
| 617 | { |
| 618 | setupSmartListContextMenu(pos); |
| 619 | } |
| 620 | |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 621 | void CallWidget::slotAccountChanged(int index) |
| 622 | { |
Andreas Traczyk | 6ace34f | 2018-12-14 14:31:23 -0500 | [diff] [blame] | 623 | try { |
| 624 | auto accountList = LRCInstance::accountModel().getAccountList(); |
| 625 | setSelectedAccount(accountList.at(index)); |
| 626 | } catch (...) { |
Andreas Traczyk | 4386537 | 2018-12-27 12:12:35 -0500 | [diff] [blame] | 627 | qWarning() << "CallWidget::slotAccountChanged exception"; |
Andreas Traczyk | 6ace34f | 2018-12-14 14:31:23 -0500 | [diff] [blame] | 628 | } |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 629 | } |
| 630 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 631 | void CallWidget::slotShowCallView(const std::string& accountId, |
| 632 | const lrc::api::conversation::Info& convInfo) |
| 633 | { |
| 634 | Q_UNUSED(accountId); |
| 635 | Q_UNUSED(convInfo); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 636 | qDebug() << "slotShowCallView"; |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 637 | setCallPanelVisibility(true); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 638 | ui->callStackWidget->setCurrentWidget(ui->videoPage); |
Sébastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 639 | ui->videoWidget->showChatviewIfToggled(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 640 | hideMiniSpinner(); |
| 641 | } |
| 642 | |
| 643 | void CallWidget::slotShowIncomingCallView(const std::string& accountId, |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 644 | const lrc::api::conversation::Info& convInfo) |
| 645 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 646 | Q_UNUSED(accountId); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 647 | qDebug() << "slotShowIncomingCallView"; |
| 648 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 649 | auto callModel = LRCInstance::getCurrentCallModel(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 650 | |
| 651 | if (!callModel->hasCall(convInfo.callId)) { |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 652 | return; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 653 | } |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 654 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 655 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 656 | ui->callerPhoto->setPixmap(QPixmap::fromImage(imageForConv(convInfo.uid))); |
| 657 | auto bestName = QString::fromStdString(Utils::bestNameForConversation(convInfo, *convModel)); |
| 658 | auto bestId = QString::fromStdString(Utils::bestIdForConversation(convInfo, *convModel)); |
| 659 | auto finalBestId = (bestName != bestId) ? bestId : ""; |
| 660 | |
| 661 | auto call = callModel->getCall(convInfo.callId); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 662 | auto isCallSelected = LRCInstance::getSelectedConvUid() == convInfo.uid; |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 663 | |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 664 | auto itemInCurrentFilter = false; |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 665 | if (call.isOutgoing) { |
| 666 | if (isCallSelected) { |
| 667 | miniSpinner_->start(); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 668 | ui->spinnerLabel->show(); |
| 669 | ui->callStackWidget->setCurrentWidget(ui->outgoingCallPage); |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 670 | setCallPanelVisibility(true); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 671 | } |
| 672 | } else { |
| 673 | if (!QApplication::focusWidget()) { |
| 674 | auto formattedName = Utils::bestNameForConversation(convInfo, *convModel); |
| 675 | Utils::showSystemNotification(this, |
| 676 | QString(tr("Call incoming from %1")).arg(QString::fromStdString(formattedName))); |
| 677 | } |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 678 | auto selectedAccountId = LRCInstance::getCurrentAccountInfo().id; |
| 679 | auto accountProperties = LRCInstance::accountModel().getAccountConfig(selectedAccountId); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 680 | if (!isCallSelected) |
| 681 | itemInCurrentFilter = selectSmartlistItem(convInfo.uid); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 682 | if (accountProperties.autoAnswer) { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 683 | ui->callStackWidget->setCurrentWidget(ui->videoPage); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 684 | } else if (isCallSelected || !itemInCurrentFilter) { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 685 | ui->callStackWidget->setCurrentWidget(ui->incomingCallPage); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 686 | } |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 687 | setCallPanelVisibility(true); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 690 | if (!itemInCurrentFilter && !isCallSelected) { |
Andreas Traczyk | 3e81c1e | 2019-01-10 16:08:12 -0500 | [diff] [blame] | 691 | if (ui->smartList->selectionModel()) |
| 692 | ui->smartList->selectionModel()->clear(); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 693 | LRCInstance::setSelectedConvId(convInfo.uid); |
| 694 | showChatView(accountId, convInfo); |
| 695 | } else if (ui->messagesWidget->isHidden()) { |
Sébastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 696 | ui->messagesWidget->show(); |
| 697 | } |
| 698 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 699 | ui->videoWidget->pushRenderer(convInfo.callId); |
Andreas Traczyk | fd0d7c0 | 2018-10-30 17:14:06 -0400 | [diff] [blame] | 700 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 701 | QFontMetrics primaryCallLabelFontMetrics(ui->callingBestNameLabel->font()); |
| 702 | QFontMetrics sencondaryCallLabelFontMetrics(ui->callingBestIdLabel->font()); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 703 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 704 | QString elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callerBestNameLabel->width()); |
| 705 | ui->callerBestNameLabel->setText(elidedLabel); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 706 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 707 | elidedLabel = primaryCallLabelFontMetrics.elidedText(bestName, Qt::ElideRight, ui->callingBestNameLabel->width()); |
| 708 | ui->callingBestNameLabel->setText(elidedLabel); |
| 709 | |
| 710 | elidedLabel = sencondaryCallLabelFontMetrics.elidedText(finalBestId, Qt::ElideRight, ui->callingBestIdLabel->width()); |
| 711 | ui->callingBestIdLabel->setText(elidedLabel); |
| 712 | |
| 713 | ui->smartList->update(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void CallWidget::slotShowChatView(const std::string& accountId, |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 717 | const lrc::api::conversation::Info& convInfo) |
| 718 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 719 | Q_UNUSED(accountId); |
| 720 | Q_UNUSED(convInfo); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 721 | |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 722 | setCallPanelVisibility(false); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 723 | showConversationView(); |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 724 | } |
Edric Milaret | ab12d02 | 2015-12-04 16:09:44 -0500 | [diff] [blame] | 725 | |
| 726 | void |
Sébastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 727 | CallWidget::slotToggleFullScreenClicked() |
| 728 | { |
| 729 | if (ui->mainActivityWidget->isFullScreen()) { |
| 730 | ui->stackedWidget->addWidget(ui->mainActivityWidget); |
| 731 | ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget); |
| 732 | ui->mainActivityWidget->showNormal(); |
| 733 | } else { |
| 734 | ui->stackedWidget->removeWidget(ui->mainActivityWidget); |
| 735 | ui->mainActivityWidget->setParent(0); |
| 736 | ui->mainActivityWidget->showFullScreen(); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | void |
| 741 | CallWidget::slotVideoViewDestroyed(const std::string& callid) |
| 742 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 743 | auto conversation = Utils::getSelectedConversation(); |
Andreas Traczyk | 8541ffa | 2019-01-18 13:59:51 -0500 | [diff] [blame] | 744 | if (conversation.uid.empty() || callid != conversation.callId) { |
Sébastien Blin | 62b08ac | 2018-12-14 16:18:04 -0500 | [diff] [blame] | 745 | return; |
| 746 | } |
Sébastien Blin | 93bd206 | 2018-12-17 15:57:16 -0500 | [diff] [blame] | 747 | if (ui->mainActivityWidget->isFullScreen()) { |
| 748 | ui->stackedWidget->addWidget(ui->mainActivityWidget); |
| 749 | ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget); |
| 750 | ui->mainActivityWidget->showNormal(); |
| 751 | } |
| 752 | showConversationView(); |
| 753 | } |
| 754 | |
| 755 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 756 | CallWidget::setSelectedAccount(const std::string& accountId) |
| 757 | { |
| 758 | LRCInstance::setSelectedAccountId(accountId); |
| 759 | |
| 760 | // First, we get back to the welcome view (except if in call) |
| 761 | if (ui->stackedWidget->currentWidget() != ui->videoPage && |
| 762 | ui->stackedWidget->currentWidget() != ui->welcomePage) { |
| 763 | Utils::setStackWidget(ui->stackedWidget, ui->welcomePage); |
| 764 | } |
| 765 | |
| 766 | // We setup the ringIdLabel and the QRCode |
| 767 | auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId); |
| 768 | auto id = accountInfo.registeredName.empty() ? accountInfo.profileInfo.uri : accountInfo.registeredName; |
| 769 | auto isRingAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING; |
| 770 | if (isRingAccount) { |
| 771 | ui->ringIdLabel->setText(QString::fromStdString(id)); |
| 772 | setupQRCode(QString::fromStdString(accountInfo.profileInfo.uri)); |
| 773 | } |
| 774 | |
| 775 | updateSmartList(); |
| 776 | currentTypeFilter_ = accountInfo.profileInfo.type; |
| 777 | LRCInstance::getCurrentConversationModel()->setFilter(accountInfo.profileInfo.type); |
| 778 | updateConversationsFilterWidget(); |
| 779 | connectConversationModel(); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 780 | connectAccount(accountId); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | void CallWidget::setConversationFilter(lrc::api::profile::Type filter) |
| 784 | { |
| 785 | if (currentTypeFilter_ == filter) { |
| 786 | return; |
| 787 | } |
| 788 | currentTypeFilter_ = filter; |
| 789 | LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_); |
| 790 | } |
| 791 | |
| 792 | void CallWidget::updateConversationsFilterWidget() |
| 793 | { |
| 794 | auto invites = LRCInstance::getCurrentAccountInfo().contactModel->pendingRequestCount(); |
| 795 | if (invites == 0 && currentTypeFilter_ == lrc::api::profile::Type::PENDING) { |
| 796 | currentTypeFilter_ = lrc::api::profile::Type::RING; |
| 797 | LRCInstance::getCurrentConversationModel()->setFilter(currentTypeFilter_); |
| 798 | } |
| 799 | ui->conversationsFilterWidget->setVisible(invites); |
Andreas Traczyk | dc17c81 | 2019-01-11 15:35:20 -0500 | [diff] [blame] | 800 | ui->searchTopLeftWidget->setVisible(invites); |
| 801 | ui->searchTopRightWidget->setVisible(invites); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 802 | ui->conversationsFilterWidget->update(); |
Andreas Traczyk | dc17c81 | 2019-01-11 15:35:20 -0500 | [diff] [blame] | 803 | ui->conversationsFilterWidget->updateBadges(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | void CallWidget::setConversationFilter(const QString & filter) |
| 807 | { |
| 808 | LRCInstance::getCurrentConversationModel()->setFilter(filter.toStdString()); |
Anthony Léonard | d47179c | 2017-03-28 10:39:10 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 812 | CallWidget::showChatView(const QModelIndex& nodeIdx) |
Edric Milaret | ab12d02 | 2015-12-04 16:09:44 -0500 | [diff] [blame] | 813 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 814 | auto convUid = nodeIdx.data(static_cast<int>(SmartListModel::Role::UID)).toString().toStdString(); |
| 815 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 816 | auto convInfo = Utils::getConversationFromUid(convUid, *convModel); |
| 817 | if (convInfo != convModel->allFilteredConversations().end()) |
| 818 | setupChatView(*convInfo); |
| 819 | } |
| 820 | |
| 821 | void |
| 822 | CallWidget::showChatView(const std::string& accountId, const lrc::api::conversation::Info& convInfo) |
| 823 | { |
| 824 | Q_UNUSED(accountId); |
| 825 | setupChatView(convInfo); |
| 826 | } |
| 827 | |
| 828 | void |
| 829 | CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo) |
| 830 | { |
| 831 | auto& accInfo = LRCInstance::getCurrentAccountInfo(); |
| 832 | auto& contact = accInfo.contactModel->getContact(convInfo.participants.at(0)); |
| 833 | QString displayName = QString::fromStdString(Utils::bestNameForContact(contact)); |
| 834 | QString displayId = QString::fromStdString(Utils::bestIdForContact(contact)); |
| 835 | QString contactURI = QString::fromStdString(convInfo.participants.at(0)); |
Olivier SOLDANO | 483f968 | 2017-07-26 11:57:49 -0400 | [diff] [blame] | 836 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 837 | bool isContact = false; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 838 | auto selectedAccountId = LRCInstance::getCurrAccId(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 839 | auto& accountInfo = LRCInstance::accountModel().getAccountInfo(selectedAccountId); |
| 840 | bool isRINGAccount = accountInfo.profileInfo.type == lrc::api::profile::Type::RING; |
| 841 | try { |
Andreas Traczyk | c4e8697 | 2019-01-18 14:11:35 -0500 | [diff] [blame^] | 842 | auto contactInfo = accountInfo.contactModel->getContact(contactURI.toStdString()); |
| 843 | if (contactInfo.isTrusted) { |
| 844 | isContact = true; |
| 845 | } |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 846 | } catch (...) {} |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 847 | |
Olivier SOLDANO | 31b9aac | 2017-07-14 15:50:09 -0400 | [diff] [blame] | 848 | ui->imNameLabel->setText(QString(tr("%1", "%1 is the contact username")) |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 849 | .arg(displayName)); |
Olivier SOLDANO | 483f968 | 2017-07-26 11:57:49 -0400 | [diff] [blame] | 850 | |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 851 | if (isRINGAccount && displayName != displayId) { |
Olivier SOLDANO | 483f968 | 2017-07-26 11:57:49 -0400 | [diff] [blame] | 852 | ui->imIdLabel->show(); |
| 853 | ui->imIdLabel->setText(QString(tr("%1", "%1 is the contact unique identifier")) |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 854 | .arg(displayId)); |
Olivier SOLDANO | 483f968 | 2017-07-26 11:57:49 -0400 | [diff] [blame] | 855 | } else { |
| 856 | ui->imIdLabel->hide(); |
| 857 | } |
| 858 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 859 | bool shouldShowSendContactRequestBtn = !isContact && isRINGAccount; |
Andreas Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 860 | ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn); |
Olivier SOLDANO | 815d92f | 2017-07-13 14:05:36 -0400 | [diff] [blame] | 861 | |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 862 | ui->messageView->setMessagesVisibility(false); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 863 | ui->messageView->clear(); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 864 | ui->messageView->setInvitation(false); |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 865 | Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesCleared, |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 866 | [this, convInfo] { |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 867 | auto convModel = LRCInstance::getCurrentConversationModel(); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 868 | ui->messageView->printHistory(*convModel, convInfo.interactions); |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 869 | Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesLoaded, |
| 870 | [this] { |
| 871 | ui->messageView->setMessagesVisibility(true); |
| 872 | }); |
| 873 | // Contact Avatars |
| 874 | auto accInfo = &LRCInstance::getCurrentAccountInfo(); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 875 | auto contactUri = convInfo.participants.front(); |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 876 | try { |
| 877 | auto& contact = accInfo->contactModel->getContact(contactUri); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 878 | auto bestName = Utils::bestNameForConversation(convInfo, *convModel); |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 879 | ui->messageView->setInvitation( |
| 880 | (contact.profileInfo.type == lrc::api::profile::Type::PENDING), |
| 881 | bestName, |
| 882 | accInfo->contactModel->getContactProfileId(contact.profileInfo.uri) |
| 883 | ); |
| 884 | if (!contact.profileInfo.avatar.empty()) { |
| 885 | ui->messageView->setSenderImage( |
| 886 | accInfo->contactModel->getContactProfileId(contactUri), |
| 887 | contact.profileInfo.avatar); |
| 888 | } else { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 889 | auto avatar = Utils::conversationPhoto(convInfo.uid, *accInfo); |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 890 | QByteArray ba; |
| 891 | QBuffer bu(&ba); |
| 892 | avatar.save(&bu, "PNG"); |
| 893 | std::string avatarString = ba.toBase64().toStdString(); |
| 894 | ui->messageView->setSenderImage( |
| 895 | accInfo->contactModel->getContactProfileId(contactUri), |
| 896 | avatarString); |
| 897 | } |
| 898 | } catch (...) {} |
| 899 | }); |
Edric Milaret | ab12d02 | 2015-12-04 16:09:44 -0500 | [diff] [blame] | 900 | } |
Edric Milaret | fa05d97 | 2016-01-13 16:22:04 -0500 | [diff] [blame] | 901 | |
| 902 | void |
Edric Milaret | 8001f6f | 2016-01-27 09:55:12 -0500 | [diff] [blame] | 903 | CallWidget::on_ringContactLineEdit_textChanged(const QString& text) |
Edric Milaret | fa05d97 | 2016-01-13 16:22:04 -0500 | [diff] [blame] | 904 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 905 | Q_UNUSED(text); |
| 906 | processContactLineEdit(); |
Edric Milaret | fa05d97 | 2016-01-13 16:22:04 -0500 | [diff] [blame] | 907 | } |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 908 | |
Nicolas Jager | ca85029 | 2016-01-17 14:11:10 -0500 | [diff] [blame] | 909 | void |
Olivier SOLDANO | 2bcdfd7 | 2017-05-02 14:37:19 -0400 | [diff] [blame] | 910 | CallWidget::backToWelcomePage() |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 911 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 912 | deselectConversation(); |
| 913 | ui->stackedWidget->setCurrentWidget(ui->welcomePage); |
Nicolas Jager | ca85029 | 2016-01-17 14:11:10 -0500 | [diff] [blame] | 914 | } |
| 915 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 916 | void |
| 917 | CallWidget::hideMiniSpinner() |
Olivier SOLDANO | 1919341 | 2017-06-06 12:03:36 -0400 | [diff] [blame] | 918 | { |
| 919 | if(ui->spinnerLabel->isVisible()){ |
| 920 | miniSpinner_->stop(); |
| 921 | ui->spinnerLabel->hide(); |
| 922 | } |
| 923 | } |
| 924 | |
Nicolas Jager | ca85029 | 2016-01-17 14:11:10 -0500 | [diff] [blame] | 925 | void |
Olivier SOLDANO | 2bcdfd7 | 2017-05-02 14:37:19 -0400 | [diff] [blame] | 926 | CallWidget::on_imBackButton_clicked() |
| 927 | { |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 928 | ui->messageView->clear(); |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 929 | Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesCleared, |
| 930 | [this] { |
| 931 | QTimer::singleShot(33, this, [this] { backToWelcomePage(); }); |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 932 | }); |
Olivier SOLDANO | 2bcdfd7 | 2017-05-02 14:37:19 -0400 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | void |
Edric Milaret | 1e59859 | 2016-09-02 10:10:01 -0400 | [diff] [blame] | 936 | CallWidget::on_qrButton_toggled(bool checked) |
| 937 | { |
| 938 | ui->qrLabel->setVisible(checked); |
| 939 | } |
| 940 | |
| 941 | void |
Edric Milaret | 4097d2f | 2016-02-09 14:41:50 -0500 | [diff] [blame] | 942 | CallWidget::on_shareButton_clicked() |
| 943 | { |
Sébastien Blin | cba5b52 | 2018-12-10 12:48:36 -0500 | [diff] [blame] | 944 | Utils::InvokeMailto(tr("Contact me on Jami"), tr("My Id is : ") + ui->ringIdLabel->text()); |
Edric Milaret | 4097d2f | 2016-02-09 14:41:50 -0500 | [diff] [blame] | 945 | } |
Anthony Léonard | aa90e1a | 2016-10-12 11:24:17 -0400 | [diff] [blame] | 946 | |
| 947 | void |
Andreas Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 948 | CallWidget::on_sendContactRequestButton_clicked() |
Olivier SOLDANO | dd87866 | 2017-03-27 16:00:06 -0400 | [diff] [blame] | 949 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 950 | auto convInfo = Utils::getSelectedConversation(); |
| 951 | if (!convInfo.uid.empty()) { |
| 952 | LRCInstance::getCurrentConversationModel()->makePermanent(convInfo.uid); |
| 953 | ui->sendContactRequestButton->hide(); |
| 954 | } |
Olivier SOLDANO | dd87866 | 2017-03-27 16:00:06 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Olivier SOLDANO | 47aa97f | 2017-04-04 10:40:00 -0400 | [diff] [blame] | 957 | void |
Andreas Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 958 | CallWidget::on_btnAudioCall_clicked() |
| 959 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 960 | auto convInfo = Utils::getSelectedConversation(); |
| 961 | if (!convInfo.uid.empty()) { |
| 962 | LRCInstance::getCurrentConversationModel()->placeAudioOnlyCall(convInfo.uid); |
| 963 | ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convInfo.uid))); |
| 964 | } |
Andreas Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | void |
| 968 | CallWidget::on_btnVideoCall_clicked() |
| 969 | { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 970 | auto convInfo = Utils::getSelectedConversation(); |
| 971 | if (!convInfo.uid.empty()) { |
| 972 | LRCInstance::getCurrentConversationModel()->placeCall(convInfo.uid); |
| 973 | ui->callingPhoto->setPixmap(QPixmap::fromImage(imageForConv(convInfo.uid))); |
| 974 | } |
Andreas Traczyk | 912242e | 2018-10-29 14:44:44 -0400 | [diff] [blame] | 975 | } |
| 976 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 977 | bool |
| 978 | CallWidget::connectConversationModel() |
Anthony Léonard | 5cc7641 | 2017-04-21 16:52:25 -0400 | [diff] [blame] | 979 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 980 | auto currentConversationModel = LRCInstance::getCurrentAccountInfo().conversationModel.get(); |
| 981 | |
| 982 | if (ui->smartList->selectionModel()) { |
| 983 | ui->smartList->selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Deselect); |
Anthony Léonard | 5cc7641 | 2017-04-21 16:52:25 -0400 | [diff] [blame] | 984 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 985 | |
| 986 | QObject::disconnect(modelSortedConnection_); |
| 987 | QObject::disconnect(modelUpdatedConnection_); |
| 988 | QObject::disconnect(filterChangedConnection_); |
| 989 | QObject::disconnect(newConversationConnection_); |
| 990 | QObject::disconnect(conversationRemovedConnection_); |
| 991 | QObject::disconnect(conversationClearedConnection); |
| 992 | QObject::disconnect(interactionStatusUpdatedConnection_); |
| 993 | QObject::disconnect(newInteractionConnection_); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 994 | QObject::disconnect(interactionRemovedConnection_); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 995 | |
| 996 | modelSortedConnection_ = QObject::connect( |
| 997 | currentConversationModel, &lrc::api::ConversationModel::modelSorted, |
| 998 | [this]() { |
| 999 | updateConversationsFilterWidget(); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 1000 | selectSmartlistItem(Utils::getSelectedConversation().uid); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1001 | ui->smartList->update(); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1002 | } |
| 1003 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1004 | modelUpdatedConnection_ = QObject::connect( |
| 1005 | currentConversationModel, &lrc::api::ConversationModel::conversationUpdated, |
| 1006 | [this](const std::string& convUid) { |
| 1007 | Q_UNUSED(convUid); |
| 1008 | ui->smartList->update(); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1009 | } |
| 1010 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1011 | filterChangedConnection_ = QObject::connect( |
| 1012 | currentConversationModel, &lrc::api::ConversationModel::filterChanged, |
| 1013 | [this]() { |
| 1014 | updateSmartList(); |
| 1015 | updateConversationsFilterWidget(); |
| 1016 | ui->smartList->update(); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1017 | } |
| 1018 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1019 | newConversationConnection_ = QObject::connect( |
| 1020 | currentConversationModel, &lrc::api::ConversationModel::newConversation, |
| 1021 | [this](const std::string& convUid) { |
| 1022 | updateSmartList(); |
| 1023 | updateConversationForNewContact(convUid); |
| 1024 | ui->conversationsFilterWidget->update(); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1025 | } |
| 1026 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1027 | conversationRemovedConnection_ = QObject::connect( |
| 1028 | currentConversationModel, &lrc::api::ConversationModel::conversationRemoved, |
| 1029 | [this]() { |
| 1030 | backToWelcomePage(); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1031 | } |
| 1032 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1033 | conversationClearedConnection = QObject::connect( |
| 1034 | currentConversationModel, &lrc::api::ConversationModel::conversationCleared, |
| 1035 | [this](const std::string& convUid) { |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1036 | ui->messageView->clear(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1037 | // if currently selected, |
| 1038 | // switch to welcome screen (deselecting current smartlist item ) |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1039 | if (convUid != LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | backToWelcomePage(); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1043 | } |
| 1044 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1045 | interactionStatusUpdatedConnection_ = QObject::connect( |
| 1046 | currentConversationModel, &lrc::api::ConversationModel::interactionStatusUpdated, |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1047 | [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) { |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1048 | if (convUid != LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1049 | return; |
| 1050 | } |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1051 | auto& currentAccountInfo = LRCInstance::getCurrentAccountInfo(); |
| 1052 | auto currentConversationModel = currentAccountInfo.conversationModel.get(); |
| 1053 | currentConversationModel->clearUnreadInteractions(convUid); |
| 1054 | ui->conversationsFilterWidget->update(); |
| 1055 | ui->messageView->updateInteraction(*currentConversationModel, interactionId, interaction); |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1056 | } |
| 1057 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1058 | newInteractionConnection_ = QObject::connect( |
| 1059 | currentConversationModel, &lrc::api::ConversationModel::newInteraction, |
| 1060 | [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) { |
| 1061 | onIncomingMessage(convUid, interactionId, interaction); |
Andreas Traczyk | 4b4bfde | 2018-12-19 09:53:22 -0500 | [diff] [blame] | 1062 | if (interaction.type == lrc::api::interaction::Type::CALL) { |
| 1063 | return; |
| 1064 | } |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1065 | if (convUid == LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | 4b4bfde | 2018-12-19 09:53:22 -0500 | [diff] [blame] | 1066 | ui->videoWidget->simulateShowChatview(true); |
| 1067 | } |
Isa Nanic | 37ccc1c | 2018-10-26 14:16:28 -0400 | [diff] [blame] | 1068 | } |
| 1069 | ); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1070 | interactionRemovedConnection_ = QObject::connect( |
| 1071 | currentConversationModel, &lrc::api::ConversationModel::interactionRemoved, |
| 1072 | [this](const std::string& convUid, uint64_t interactionId) { |
| 1073 | Q_UNUSED(convUid); |
| 1074 | ui->messageView->removeInteraction(interactionId); |
| 1075 | } |
| 1076 | ); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1077 | currentConversationModel->setFilter(""); |
| 1078 | // clear search field |
| 1079 | ui->ringContactLineEdit->setText(""); |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
| 1083 | void |
| 1084 | CallWidget::updateConversationView(const std::string& convUid) |
| 1085 | { |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1086 | if (convUid != LRCInstance::getSelectedConvUid()) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1087 | return; |
| 1088 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | void |
| 1092 | CallWidget::selectConversation(const QModelIndex& index) |
| 1093 | { |
| 1094 | auto currentConversationModel = LRCInstance::getCurrentConversationModel(); |
| 1095 | |
| 1096 | if (currentConversationModel == nullptr || !index.isValid()) { |
| 1097 | return; |
| 1098 | } |
| 1099 | |
| 1100 | const auto item = currentConversationModel->filteredConversation(index.row()); |
| 1101 | |
| 1102 | if (selectConversation(item, *currentConversationModel)) { |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 1103 | showChatView(index); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1104 | auto convUid = LRCInstance::getSelectedConvUid(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1105 | if (!lastConvUid_.compare(convUid)) { |
| 1106 | return; |
| 1107 | } |
| 1108 | lastConvUid_.assign(convUid); |
| 1109 | auto currentConversationModel = LRCInstance::getCurrentConversationModel(); |
| 1110 | auto callModel = LRCInstance::getCurrentCallModel(); |
| 1111 | auto conversation = Utils::getConversationFromUid(convUid, *currentConversationModel); |
| 1112 | const auto item = currentConversationModel->filteredConversation(index.row()); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1113 | if (callModel->hasCall(conversation->callId) && item.callId == conversation->callId) { |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 1114 | setCallPanelVisibility(true); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1115 | return; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1116 | } |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 1117 | setCallPanelVisibility(false); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1118 | } |
Anthony Léonard | 5cc7641 | 2017-04-21 16:52:25 -0400 | [diff] [blame] | 1119 | } |
Anthony Léonard | ecfe742 | 2017-05-04 14:14:37 -0400 | [diff] [blame] | 1120 | |
Anthony Léonard | 041ad39 | 2017-07-14 16:44:09 -0400 | [diff] [blame] | 1121 | bool |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1122 | CallWidget::selectConversation( const lrc::api::conversation::Info& item, |
| 1123 | lrc::api::ConversationModel& convModel) |
Anthony Léonard | 041ad39 | 2017-07-14 16:44:09 -0400 | [diff] [blame] | 1124 | { |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1125 | if (LRCInstance::getSelectedConvUid() == item.uid) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1126 | return false; |
| 1127 | } else if (item.participants.size() > 0) { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1128 | LRCInstance::setSelectedConvId(item.uid); |
Andreas Traczyk | 1cf20c7 | 2019-01-09 19:42:32 -0500 | [diff] [blame] | 1129 | convModel.selectConversation(item.uid); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1130 | convModel.clearUnreadInteractions(item.uid); |
| 1131 | ui->conversationsFilterWidget->update(); |
| 1132 | return true; |
Anthony Léonard | 041ad39 | 2017-07-14 16:44:09 -0400 | [diff] [blame] | 1133 | } |
Anthony Léonard | 041ad39 | 2017-07-14 16:44:09 -0400 | [diff] [blame] | 1134 | } |
| 1135 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1136 | void |
| 1137 | CallWidget::deselectConversation() |
Anthony Léonard | ecfe742 | 2017-05-04 14:14:37 -0400 | [diff] [blame] | 1138 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1139 | auto currentConversationModel = LRCInstance::getCurrentConversationModel(); |
| 1140 | |
| 1141 | if (currentConversationModel == nullptr) { |
| 1142 | return; |
| 1143 | } |
| 1144 | |
| 1145 | currentConversationModel->selectConversation(""); |
| 1146 | LRCInstance::setSelectedConvId(""); |
| 1147 | |
| 1148 | ui->smartList->selectionModel()->clear(); |
| 1149 | disconnect(imConnection_); |
Anthony Léonard | ecfe742 | 2017-05-04 14:14:37 -0400 | [diff] [blame] | 1150 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1151 | |
| 1152 | void |
| 1153 | CallWidget::updateConversationForNewContact(const std::string& convUid) |
| 1154 | { |
| 1155 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 1156 | if (convModel == nullptr) { |
| 1157 | return; |
| 1158 | } |
| 1159 | ui->ringContactLineEdit->setText(""); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1160 | auto selectedUid = LRCInstance::getSelectedConvUid(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1161 | auto it = Utils::getConversationFromUid(convUid, *convModel); |
| 1162 | if (it != convModel->allFilteredConversations().end()) { |
| 1163 | try { |
| 1164 | auto contact = convModel->owner.contactModel->getContact(it->participants[0]); |
| 1165 | if (!contact.profileInfo.uri.empty() && contact.profileInfo.uri.compare(selectedUid) == 0) { |
| 1166 | LRCInstance::setSelectedConvId(convUid); |
| 1167 | convModel->selectConversation(convUid); |
| 1168 | } |
| 1169 | } catch (...) { |
| 1170 | return; |
| 1171 | } |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | void |
| 1176 | CallWidget::updateSmartList() |
| 1177 | { |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1178 | if (!ui->smartList->model()) { |
| 1179 | smartListModel_.reset(new SmartListModel(LRCInstance::getCurrAccId(), this)); |
| 1180 | ui->smartList->setModel(smartListModel_.get()); |
| 1181 | ui->smartList->setItemDelegate(new ConversationItemDelegate()); |
| 1182 | } else { |
| 1183 | smartListModel_->setAccount(LRCInstance::getCurrAccId()); |
| 1184 | } |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1185 | |
| 1186 | // smartlist selection |
| 1187 | QObject::disconnect(smartlistSelectionConnection_); |
| 1188 | smartlistSelectionConnection_ = connect(ui->smartList->selectionModel(), |
| 1189 | SIGNAL(selectionChanged(QItemSelection, QItemSelection)), |
| 1190 | this, |
| 1191 | SLOT(smartListSelectionChanged(QItemSelection, QItemSelection))); |
| 1192 | } |
| 1193 | |
| 1194 | void |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 1195 | CallWidget::updateComboBox() |
| 1196 | { |
| 1197 | ui->currentAccountComboBox->updateComboBoxDisplay(); |
| 1198 | } |
| 1199 | |
| 1200 | void |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1201 | CallWidget::update() |
| 1202 | { |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1203 | updateSmartList(); |
| 1204 | updateConversationsFilterWidget(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 1205 | updateComboBox(); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1206 | connectConversationModel(); |
Isa Nanic | 601de1d | 2018-10-23 11:37:26 -0400 | [diff] [blame] | 1207 | } |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1208 | |
| 1209 | void |
| 1210 | CallWidget::connectAccount(const std::string& accId) |
| 1211 | { |
| 1212 | auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get(); |
| 1213 | disconnect(callStatusChangedConnection_); |
| 1214 | callStatusChangedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::callStatusChanged, |
| 1215 | [this, accId](const std::string& callId) { |
| 1216 | auto callModel = LRCInstance::accountModel().getAccountInfo(accId).callModel.get(); |
| 1217 | auto call = callModel->getCall(callId); |
| 1218 | switch (call.status) { |
| 1219 | case lrc::api::call::Status::INVALID: |
| 1220 | case lrc::api::call::Status::INACTIVE: |
| 1221 | case lrc::api::call::Status::ENDED: |
| 1222 | case lrc::api::call::Status::PEER_BUSY: |
| 1223 | case lrc::api::call::Status::TIMEOUT: |
| 1224 | case lrc::api::call::Status::TERMINATING: |
| 1225 | { |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 1226 | setCallPanelVisibility(false); |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 1227 | showConversationView(); |
| 1228 | break; |
| 1229 | } |
| 1230 | default: |
| 1231 | break; |
| 1232 | } |
| 1233 | }); |
| 1234 | auto& contactModel = LRCInstance::getCurrentAccountInfo().contactModel; |
| 1235 | disconnect(contactAddedConnection_); |
| 1236 | contactAddedConnection_ = connect(contactModel.get(), &lrc::api::ContactModel::contactAdded, |
| 1237 | [this, &contactModel](const std::string & contactId) { |
| 1238 | auto convModel = LRCInstance::getCurrentConversationModel(); |
| 1239 | auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(), |
| 1240 | *convModel); |
| 1241 | if (currentConversation == convModel->allFilteredConversations().end()) { |
| 1242 | return; |
| 1243 | } |
| 1244 | if (contactId == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) { |
| 1245 | ui->messageView->clear(); |
| 1246 | ui->messageView->printHistory(*convModel, currentConversation->interactions); |
| 1247 | } |
| 1248 | }); |
Andreas Traczyk | 39fa4d0 | 2019-01-03 17:32:07 -0500 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | void |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 1252 | CallWidget::setCallPanelVisibility(bool visible) |
Andreas Traczyk | 39fa4d0 | 2019-01-03 17:32:07 -0500 | [diff] [blame] | 1253 | { |
| 1254 | ui->stackedWidget->setCurrentWidget(ui->mainActivityWidget); |
Andreas Traczyk | 0147bf1 | 2019-01-03 20:46:03 -0500 | [diff] [blame] | 1255 | ui->imBackButton->setVisible(!visible); |
| 1256 | ui->btnAudioCall->setVisible(!visible); |
| 1257 | ui->btnVideoCall->setVisible(!visible); |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 1258 | ui->callStackWidget->setVisible(visible); |
Andreas Traczyk | 39fa4d0 | 2019-01-03 17:32:07 -0500 | [diff] [blame] | 1259 | } |