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