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