matrixion/src/dialogs/PlaceCall.cpp

104 lines
3.7 KiB
C++
Raw Normal View History

2020-08-06 00:56:44 +03:00
#include <QComboBox>
2020-07-11 02:19:48 +03:00
#include <QLabel>
#include <QPushButton>
#include <QString>
#include <QVBoxLayout>
2020-08-06 00:56:44 +03:00
#include "ChatPage.h"
2020-07-11 02:19:48 +03:00
#include "Config.h"
2020-08-06 00:56:44 +03:00
#include "UserSettingsPage.h"
2020-07-23 04:15:45 +03:00
#include "Utils.h"
2020-08-06 00:56:44 +03:00
#include "WebRTCSession.h"
2020-07-11 02:19:48 +03:00
#include "dialogs/PlaceCall.h"
2020-07-23 04:15:45 +03:00
#include "ui/Avatar.h"
2020-07-11 02:19:48 +03:00
namespace dialogs {
2020-08-01 21:31:10 +03:00
PlaceCall::PlaceCall(const QString &callee,
const QString &displayName,
const QString &roomName,
const QString &avatarUrl,
2020-08-06 00:56:44 +03:00
QSharedPointer<UserSettings> settings,
2020-08-01 21:31:10 +03:00
QWidget *parent)
: QWidget(parent)
2020-07-11 02:19:48 +03:00
{
2020-08-06 00:56:44 +03:00
std::string errorMessage;
if (!WebRTCSession::instance().init(&errorMessage)) {
emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage));
emit close();
return;
}
audioDevices_ = WebRTCSession::instance().getAudioSourceNames(
settings->defaultAudioSource().toStdString());
if (audioDevices_.empty()) {
emit ChatPage::instance()->showNotification("No audio sources found.");
emit close();
return;
}
2020-07-11 02:19:48 +03:00
setAutoFillBackground(true);
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
setWindowModality(Qt::WindowModal);
setAttribute(Qt::WA_DeleteOnClose, true);
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setMargin(conf::modals::WIDGET_MARGIN);
2020-07-24 01:36:10 +03:00
auto buttonLayout = new QHBoxLayout;
2020-07-11 02:19:48 +03:00
buttonLayout->setSpacing(15);
buttonLayout->setMargin(0);
2020-07-23 04:15:45 +03:00
QFont f;
f.setPointSizeF(f.pointSizeF());
auto avatar = new Avatar(this, QFontMetrics(f).height() * 3);
if (!avatarUrl.isEmpty())
2020-08-01 21:31:10 +03:00
avatar->setImage(avatarUrl);
2020-07-23 04:15:45 +03:00
else
2020-08-01 21:31:10 +03:00
avatar->setLetter(utils::firstChar(roomName));
2020-08-06 00:56:44 +03:00
const int iconSize = 18;
2020-08-01 21:31:10 +03:00
voiceBtn_ = new QPushButton(tr("Voice"), this);
voiceBtn_->setIcon(QIcon(":/icons/icons/ui/place-call.png"));
voiceBtn_->setIconSize(QSize(iconSize, iconSize));
2020-07-11 02:19:48 +03:00
voiceBtn_->setDefault(true);
cancelBtn_ = new QPushButton(tr("Cancel"), this);
2020-07-23 04:15:45 +03:00
buttonLayout->addWidget(avatar);
2020-08-06 00:56:44 +03:00
buttonLayout->addStretch();
2020-07-11 02:19:48 +03:00
buttonLayout->addWidget(voiceBtn_);
buttonLayout->addWidget(cancelBtn_);
2020-08-01 21:31:10 +03:00
QString name = displayName.isEmpty() ? callee : displayName;
2020-07-23 04:15:45 +03:00
QLabel *label = new QLabel("Place a call to " + name + "?", this);
2020-07-11 02:19:48 +03:00
2020-08-06 00:56:44 +03:00
auto deviceLayout = new QHBoxLayout;
auto audioLabel = new QLabel(this);
audioLabel->setPixmap(QIcon(":/icons/icons/ui/microphone-unmute.png")
.pixmap(QSize(iconSize * 1.2, iconSize * 1.2)));
auto deviceList = new QComboBox(this);
for (const auto &d : audioDevices_)
deviceList->addItem(QString::fromStdString(d));
deviceLayout->addStretch();
deviceLayout->addWidget(audioLabel);
deviceLayout->addWidget(deviceList);
2020-07-11 02:19:48 +03:00
layout->addWidget(label);
layout->addLayout(buttonLayout);
2020-08-06 00:56:44 +03:00
layout->addLayout(deviceLayout);
2020-07-11 02:19:48 +03:00
2020-08-06 00:56:44 +03:00
connect(voiceBtn_, &QPushButton::clicked, this, [this, deviceList, settings]() {
WebRTCSession::instance().setAudioSource(deviceList->currentIndex());
settings->setDefaultAudioSource(
QString::fromStdString(audioDevices_[deviceList->currentIndex()]));
2020-07-11 02:19:48 +03:00
emit voice();
emit close();
});
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
emit cancel();
emit close();
});
}
}