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