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