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