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