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