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