mirror of https://github.com/Nheko-Reborn/nheko
parent
ac410f46f2
commit
7124024977
@ -0,0 +1,95 @@ |
||||
import QtQuick 2.9 |
||||
import QtQuick.Controls 2.3 |
||||
import QtQuick.Dialogs 1.3 |
||||
import QtQuick.Layouts 1.2 |
||||
import im.nheko 1.0 |
||||
import "../" |
||||
|
||||
Rectangle { |
||||
|
||||
visible: CallManager.haveCallInvite |
||||
color: "#2ECC71" |
||||
implicitHeight: visible ? rowLayout.height + 8 : 0 |
||||
|
||||
MessageDialog { |
||||
id: warningDialog |
||||
icon: StandardIcon.Warning |
||||
} |
||||
|
||||
RowLayout { |
||||
id: rowLayout |
||||
|
||||
anchors.left: parent.left |
||||
anchors.right: parent.right |
||||
anchors.verticalCenter: parent.verticalCenter |
||||
anchors.leftMargin: 8 |
||||
|
||||
Avatar { |
||||
width: avatarSize |
||||
height: avatarSize |
||||
url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/") |
||||
displayName: CallManager.callParty |
||||
} |
||||
|
||||
Label { |
||||
font.pointSize: fontMetrics.font.pointSize * 1.1 |
||||
text: " " + CallManager.callParty + " " |
||||
} |
||||
|
||||
Image { |
||||
Layout.preferredWidth: 24 |
||||
Layout.preferredHeight: 24 |
||||
source: CallManager.isVideo ? "qrc:/icons/icons/ui/video-call.png" : "qrc:/icons/icons/ui/place-call.png" |
||||
} |
||||
|
||||
Label { |
||||
font.pointSize: fontMetrics.font.pointSize * 1.1 |
||||
text: CallManager.isVideo ? "Video Call" : "Voice Call" |
||||
} |
||||
|
||||
Item { |
||||
Layout.fillWidth: true |
||||
} |
||||
|
||||
Button { |
||||
icon.source: CallManager.isVideo ? "qrc:/icons/icons/ui/video-call.png" : "qrc:/icons/icons/ui/place-call.png" |
||||
palette: colors |
||||
text: qsTr("Accept") |
||||
onClicked: { |
||||
if (CallManager.mics.length == 0) { |
||||
warningDialog.text = "No microphone found."; |
||||
warningDialog.open(); |
||||
return; |
||||
} |
||||
else if (!CallManager.mics.includes(Settings.microphone)) { |
||||
warningDialog.text = "Unknown microphone: " + Settings.microphone; |
||||
warningDialog.open(); |
||||
return; |
||||
} |
||||
if (CallManager.isVideo && CallManager.cameras.length > 0 && !CallManager.cameras.includes(Settings.camera)) { |
||||
warningDialog.text = "Unknown camera: " + Settings.camera; |
||||
warningDialog.open(); |
||||
return; |
||||
} |
||||
CallManager.acceptInvite(); |
||||
} |
||||
} |
||||
|
||||
Item { |
||||
implicitWidth: 8 |
||||
} |
||||
|
||||
Button { |
||||
icon.source: "qrc:/icons/icons/ui/end-call.png" |
||||
palette: colors |
||||
text: qsTr("Decline") |
||||
onClicked: { |
||||
CallManager.hangUp(); |
||||
} |
||||
} |
||||
|
||||
Item { |
||||
implicitWidth: 16 |
||||
} |
||||
} |
||||
} |
@ -1,152 +0,0 @@ |
||||
#include <QComboBox> |
||||
#include <QLabel> |
||||
#include <QPushButton> |
||||
#include <QString> |
||||
#include <QVBoxLayout> |
||||
|
||||
#include "ChatPage.h" |
||||
#include "Config.h" |
||||
#include "UserSettingsPage.h" |
||||
#include "Utils.h" |
||||
#include "WebRTCSession.h" |
||||
#include "dialogs/AcceptCall.h" |
||||
#include "ui/Avatar.h" |
||||
|
||||
namespace dialogs { |
||||
|
||||
AcceptCall::AcceptCall(const QString &caller, |
||||
const QString &displayName, |
||||
const QString &roomName, |
||||
const QString &avatarUrl, |
||||
bool isVideo, |
||||
QWidget *parent) |
||||
: QWidget(parent) |
||||
{ |
||||
std::string errorMessage; |
||||
WebRTCSession *session = &WebRTCSession::instance(); |
||||
if (!session->havePlugins(false, &errorMessage)) { |
||||
emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage)); |
||||
emit close(); |
||||
return; |
||||
} |
||||
if (isVideo && !session->havePlugins(true, &errorMessage)) { |
||||
emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage)); |
||||
emit close(); |
||||
return; |
||||
} |
||||
|
||||
session->refreshDevices(); |
||||
microphones_ = session->getDeviceNames( |
||||
false, ChatPage::instance()->userSettings()->microphone().toStdString()); |
||||
if (microphones_.empty()) { |
||||
emit ChatPage::instance()->showNotification( |
||||
tr("Incoming call: No microphone found.")); |
||||
emit close(); |
||||
return; |
||||
} |
||||
if (isVideo) |
||||
cameras_ = session->getDeviceNames( |
||||
true, ChatPage::instance()->userSettings()->camera().toStdString()); |
||||
|
||||
setAutoFillBackground(true); |
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); |
||||
setWindowModality(Qt::WindowModal); |
||||
setAttribute(Qt::WA_DeleteOnClose, true); |
||||
|
||||
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH); |
||||
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
||||
|
||||
auto layout = new QVBoxLayout(this); |
||||
layout->setSpacing(conf::modals::WIDGET_SPACING); |
||||
layout->setMargin(conf::modals::WIDGET_MARGIN); |
||||
|
||||
QFont f; |
||||
f.setPointSizeF(f.pointSizeF()); |
||||
|
||||
QFont labelFont; |
||||
labelFont.setWeight(QFont::Medium); |
||||
|
||||
QLabel *displayNameLabel = nullptr; |
||||
if (!displayName.isEmpty() && displayName != caller) { |
||||
displayNameLabel = new QLabel(displayName, this); |
||||
labelFont.setPointSizeF(f.pointSizeF() * 2); |
||||
displayNameLabel->setFont(labelFont); |
||||
displayNameLabel->setAlignment(Qt::AlignCenter); |
||||
} |
||||
|
||||
QLabel *callerLabel = new QLabel(caller, this); |
||||
labelFont.setPointSizeF(f.pointSizeF() * 1.2); |
||||
callerLabel->setFont(labelFont); |
||||
callerLabel->setAlignment(Qt::AlignCenter); |
||||
|
||||
auto avatar = new Avatar(this, QFontMetrics(f).height() * 6); |
||||
if (!avatarUrl.isEmpty()) |
||||
avatar->setImage(avatarUrl); |
||||
else |
||||
avatar->setLetter(utils::firstChar(roomName)); |
||||
|
||||
const int iconSize = 22; |
||||
QLabel *callTypeIndicator = new QLabel(this); |
||||
callTypeIndicator->setPixmap( |
||||
QIcon(isVideo ? ":/icons/icons/ui/video-call.png" : ":/icons/icons/ui/place-call.png") |
||||
.pixmap(QSize(iconSize * 2, iconSize * 2))); |
||||
|
||||
QLabel *callTypeLabel = new QLabel(isVideo ? tr("Video Call") : tr("Voice Call"), this); |
||||
labelFont.setPointSizeF(f.pointSizeF() * 1.1); |
||||
callTypeLabel->setFont(labelFont); |
||||
callTypeLabel->setAlignment(Qt::AlignCenter); |
||||
|
||||
auto buttonLayout = new QHBoxLayout; |
||||
buttonLayout->setSpacing(18); |
||||
acceptBtn_ = new QPushButton(tr("Accept"), this); |
||||
acceptBtn_->setDefault(true); |
||||
acceptBtn_->setIcon( |
||||
QIcon(isVideo ? ":/icons/icons/ui/video-call.png" : ":/icons/icons/ui/place-call.png")); |
||||
acceptBtn_->setIconSize(QSize(iconSize, iconSize)); |
||||
|
||||
rejectBtn_ = new QPushButton(tr("Reject"), this); |
||||
rejectBtn_->setIcon(QIcon(":/icons/icons/ui/end-call.png")); |
||||
rejectBtn_->setIconSize(QSize(iconSize, iconSize)); |
||||
buttonLayout->addWidget(acceptBtn_); |
||||
buttonLayout->addWidget(rejectBtn_); |
||||
|
||||
microphoneCombo_ = new QComboBox(this); |
||||
for (const auto &m : microphones_) |
||||
microphoneCombo_->addItem(QIcon(":/icons/icons/ui/microphone-unmute.png"), |
||||
QString::fromStdString(m)); |
||||
|
||||
if (!cameras_.empty()) { |
||||
cameraCombo_ = new QComboBox(this); |
||||
for (const auto &c : cameras_) |
||||
cameraCombo_->addItem(QIcon(":/icons/icons/ui/video-call.png"), |
||||
QString::fromStdString(c)); |
||||
} |
||||
|
||||
if (displayNameLabel) |
||||
layout->addWidget(displayNameLabel, 0, Qt::AlignCenter); |
||||
layout->addWidget(callerLabel, 0, Qt::AlignCenter); |
||||
layout->addWidget(avatar, 0, Qt::AlignCenter); |
||||
layout->addWidget(callTypeIndicator, 0, Qt::AlignCenter); |
||||
layout->addWidget(callTypeLabel, 0, Qt::AlignCenter); |
||||
layout->addLayout(buttonLayout); |
||||
layout->addWidget(microphoneCombo_); |
||||
if (cameraCombo_) |
||||
layout->addWidget(cameraCombo_); |
||||
|
||||
connect(acceptBtn_, &QPushButton::clicked, this, [this]() { |
||||
ChatPage::instance()->userSettings()->setMicrophone( |
||||
QString::fromStdString(microphones_[microphoneCombo_->currentIndex()])); |
||||
if (cameraCombo_) { |
||||
ChatPage::instance()->userSettings()->setCamera( |
||||
QString::fromStdString(cameras_[cameraCombo_->currentIndex()])); |
||||
} |
||||
emit accept(); |
||||
emit close(); |
||||
}); |
||||
connect(rejectBtn_, &QPushButton::clicked, this, [this]() { |
||||
emit reject(); |
||||
emit close(); |
||||
}); |
||||
} |
||||
|
||||
} |
@ -1,39 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include <QWidget> |
||||
|
||||
class QComboBox; |
||||
class QPushButton; |
||||
class QString; |
||||
|
||||
namespace dialogs { |
||||
|
||||
class AcceptCall : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
AcceptCall(const QString &caller, |
||||
const QString &displayName, |
||||
const QString &roomName, |
||||
const QString &avatarUrl, |
||||
bool isVideo, |
||||
QWidget *parent = nullptr); |
||||
|
||||
signals: |
||||
void accept(); |
||||
void reject(); |
||||
|
||||
private: |
||||
QPushButton *acceptBtn_ = nullptr; |
||||
QPushButton *rejectBtn_ = nullptr; |
||||
QComboBox *microphoneCombo_ = nullptr; |
||||
QComboBox *cameraCombo_ = nullptr; |
||||
std::vector<std::string> microphones_; |
||||
std::vector<std::string> cameras_; |
||||
}; |
||||
|
||||
} |
Loading…
Reference in new issue