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