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