From b4988375abf69ab65c11c5e83b076de1f3ab573e Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Tue, 12 Nov 2019 14:37:27 -0500 Subject: [PATCH] chatview: restore webview navbar invitations - Complete navbar can be added by removing the TODO in callwidget.cpp, and bridging the button functionality. Change-Id: Ia8bd8b1a37c4273c80200d918c8735c7017823eb --- callwidget.cpp | 35 +++++++++++++++++++++++++++++++++++ callwidget.h | 1 + callwidget.ui | 2 +- messagewebview.cpp | 31 ++++++++++++++++++++++++++++--- messagewebview.h | 3 +++ 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/callwidget.cpp b/callwidget.cpp index a3e028f..ebf43de 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -503,6 +503,7 @@ CallWidget::showConversationView() if (ui->messagesWidget->isHidden()) { ui->messagesWidget->show(); } + updateChatviewFrame(); } bool @@ -1398,6 +1399,40 @@ CallWidget::setCallPanelVisibility(bool visible) ui->messageView->setRecordButtonsVisibility(!visible); } +void +CallWidget::updateChatviewFrame() +{ + // TODO: remove this to start using webview navbar + // instead of native qt + if (1) { + ui->messageView->displayNavbar(false); + return; + } + + auto& accInfo = LRCInstance::getCurrentAccountInfo(); + auto& convInfo = LRCInstance::getCurrentConversation(); + if (convInfo.uid.empty()) { + return; + } + auto contactUri = convInfo.participants.front(); + + lrc::api::contact::Info contactInfo; + try { + contactInfo = accInfo.contactModel->getContact(contactUri); + } catch (const std::out_of_range&) { + qDebug() << "updateChatviewFrame: failed to retrieve contactInfo"; + return; + } + + bool temp = contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY || + contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING; + + auto bestName = QString::fromStdString(Utils::bestNameForContact(contactInfo)); + auto bestId = QString::fromStdString(Utils::bestIdForContact(contactInfo)); + + ui->messageView->updateChatviewFrame(accInfo.enabled, contactInfo.isBanned, temp, bestName, bestId); +} + void CallWidget::ShowContextMenu(const QPoint& pos) { diff --git a/callwidget.h b/callwidget.h index 8da3fbe..fe05fa6 100644 --- a/callwidget.h +++ b/callwidget.h @@ -133,6 +133,7 @@ private: void updateComboBox(); void connectAccount(const std::string& accId); void setCallPanelVisibility(bool visible); + void updateChatviewFrame(); QMenu* menu_; QClipboard* clipboard_; diff --git a/callwidget.ui b/callwidget.ui index 41e00b0..3f83ff0 100644 --- a/callwidget.ui +++ b/callwidget.ui @@ -2071,7 +2071,7 @@ Copy and share it with your friends! </property> <property name="maximumSize"> <size> - <width>1000</width> + <width>16777215</width> <height>16777215</height> </size> </property> diff --git a/messagewebview.cpp b/messagewebview.cpp index 9ca20aa..0553c84 100644 --- a/messagewebview.cpp +++ b/messagewebview.cpp @@ -114,6 +114,7 @@ MessageWebView::MessageWebView(QWidget *parent) break; } }); + recordWidget_ = new RecordWidget(this); recordWidget_->getContainer()->hide(); } @@ -302,6 +303,8 @@ MessageWebView::slotLoadFinished() QString s = QString::fromLatin1("init_i18n();"); page()->runJavaScript(s, QWebEngineScript::MainWorld); + + displayNavbar(false); } void @@ -349,7 +352,7 @@ void MessageWebView::clear() void MessageWebView::setDisplayLinks(bool display) { - QString s = QString::fromLatin1("setDisplayLinks('%1');") + QString s = QString::fromLatin1("setDisplayLinks(%1);") .arg(display ? "true" : "false"); page()->runJavaScript(s, QWebEngineScript::MainWorld); } @@ -432,6 +435,28 @@ MessageWebView::setMessagesVisibility(bool visible) page()->runJavaScript(s, QWebEngineScript::MainWorld); } +void +MessageWebView::updateChatviewFrame(bool accountEnabled, bool isBanned, bool isTemporary, + const QString& alias, const QString& bestId) +{ + QString s = QString::fromLatin1("update_chatview_frame(%1, %2, %3, \"%4\", \"%5\")") + .arg(accountEnabled ? "true" : "false") + .arg(isBanned ? "true" : "false") + .arg(isTemporary ? "true" : "false") + .arg(alias) + .arg(bestId); + + page()->runJavaScript(s, QWebEngineScript::MainWorld); +} + +void +MessageWebView::displayNavbar(bool display) +{ + QString s = QString::fromLatin1("displayNavbar(%1);") + .arg(display ? "true" : "false"); + page()->runJavaScript(s, QWebEngineScript::MainWorld); +} + // JS bridging incoming Q_INVOKABLE int PrivateBridging::log(const QString& arg) @@ -603,7 +628,7 @@ PrivateBridging::sendImage(const QString& arg) } Q_INVOKABLE int -PrivateBridging::sendFile(const QString&path) +PrivateBridging::sendFile(const QString& path) { qDebug() << "JS bridging - MessageWebView::sendFile"; QFileInfo fi(path); @@ -716,4 +741,4 @@ PrivateBridging::openVideoRecorder(int spikePosX, int spikePosY) qDebug() << "JS bridging - exception during openVideoRecorder!"; } return 0; -} +} \ No newline at end of file diff --git a/messagewebview.h b/messagewebview.h index 74859ca..d782aff 100644 --- a/messagewebview.h +++ b/messagewebview.h @@ -94,6 +94,9 @@ public: void openAudioRecorder(int spikePosX,int spikePosY); void openVideoRecorder(int spikePosX,int spikePosY); void setRecordButtonsVisibility(bool visible); + void updateChatviewFrame(bool accountEnabled, bool isBanned, bool isTemporary, + const QString& alias, const QString& bestId); + void displayNavbar(bool display); protected: -- GitLab