1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-01 04:33:39 +02:00

calloverlay: reflect changes in av device list counts

- respond to audio device events to re-populate the audio input and
  output device lists
- don't show a selection menu when no devices are available
- cleanup videoinputdevicemodel

Gitlab: #411
Change-Id: I082818756bae202a67b14bfbe0a254384a777a5d
This commit is contained in:
Andreas Traczyk 2021-06-02 12:11:49 -04:00
parent a46a116af5
commit 3d53476b8a
12 changed files with 71 additions and 118 deletions

View file

@ -36,7 +36,8 @@ AvAdapter::AvAdapter(LRCInstance* instance, QObject* parent)
auto& avModel = lrcInstance_->avModel();
deviceListSize_ = avModel.getDevices().size();
connect(&avModel, &lrc::api::AVModel::deviceEvent, this, &AvAdapter::slotDeviceEvent);
connect(&avModel, &lrc::api::AVModel::audioDeviceEvent, this, &AvAdapter::onAudioDeviceEvent);
connect(&avModel, &lrc::api::AVModel::deviceEvent, this, &AvAdapter::onVideoDeviceEvent);
connect(lrcInstance_->renderer(), &RenderManager::previewFrameStarted, [this]() {
// TODO: listen to the correct signals that are needed to be added in daemon or lrc
auto callId = getCurrentCallId();
@ -235,21 +236,17 @@ AvAdapter::stopAudioMeter(bool async)
lrcInstance_->stopAudioMeter(async);
}
QString
AvAdapter::getCurrentCallId()
void
AvAdapter::onAudioDeviceEvent()
{
try {
const auto& convInfo = lrcInstance_->getConversationFromConvUid(
lrcInstance_->get_selectedConvUid());
auto call = lrcInstance_->getCallInfoForConversation(convInfo);
return call ? call->id : QString();
} catch (...) {
return QString();
}
auto& avModel = lrcInstance_->avModel();
auto inputs = avModel.getAudioInputDevices().size();
auto outputs = avModel.getAudioOutputDevices().size();
Q_EMIT audioDeviceListChanged(inputs, outputs);
}
void
AvAdapter::slotDeviceEvent()
AvAdapter::onVideoDeviceEvent()
{
auto& avModel = lrcInstance_->avModel();
auto defaultDevice = avModel.getDefaultDevice();
@ -305,11 +302,24 @@ AvAdapter::slotDeviceEvent()
}
}
Q_EMIT videoDeviceListChanged(currentDeviceListSize == 0);
Q_EMIT videoDeviceListChanged(currentDeviceListSize);
deviceListSize_ = currentDeviceListSize;
}
QString
AvAdapter::getCurrentCallId()
{
try {
const auto& convInfo = lrcInstance_->getConversationFromConvUid(
lrcInstance_->get_selectedConvUid());
auto call = lrcInstance_->getCallInfoForConversation(convInfo);
return call ? call->id : QString();
} catch (...) {
return QString();
}
}
int
AvAdapter::getScreenNumber() const
{

View file

@ -37,8 +37,8 @@ public:
Q_SIGNALS:
// Emitted when the size of the video capture device list changes.
void videoDeviceListChanged(bool listIsEmpty);
void audioDeviceListChanged(int inputs, int outputs);
void videoDeviceListChanged(int inputs);
void screenCaptured(int screenNumber, QString source);
@ -75,6 +75,10 @@ protected:
Q_INVOKABLE void startAudioMeter(bool async);
Q_INVOKABLE void stopAudioMeter(bool async);
private Q_SLOTS:
void onAudioDeviceEvent();
void onVideoDeviceEvent();
private:
// Get screens arrangement rect relative to primary screen.
const QRect getAllScreensBoundingRect();
@ -88,9 +92,6 @@ private:
// Used to track the capture device count.
int deviceListSize_;
// Device changed slot.
void slotDeviceEvent();
// Get the screen number
int getScreenNumber() const;
};

View file

@ -28,8 +28,15 @@ import net.jami.Constants 1.0
ComboBox {
id: root
property string tooltipText:""
property string tooltipText
property string comboBoxBackgroundColor: JamiTheme.editBackgroundColor
property string placeholderText
displayText: currentIndex !== -1 ?
currentText :
(placeholderText !== "" ?
placeholderText :
JamiStrings.notAvailable)
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.visible: hovered && (tooltipText.length > 0)
@ -39,8 +46,11 @@ ComboBox {
width: root.width
contentItem: Text {
text: {
var currentItem = root.delegateModel.items.get(index)
return currentItem.model[root.textRole].toString()
if (index >= 0) {
var currentItem = root.delegateModel.items.get(index)
return currentItem.model[root.textRole].toString()
}
return ""
}
color: JamiTheme.textColor
font: root.font
@ -106,9 +116,10 @@ ComboBox {
padding: 1
contentItem: ListView {
id: listView
clip: true
implicitHeight: contentHeight
model: root.delegateModel
model: root.delegateModel
currentIndex: root.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }

View file

@ -226,6 +226,7 @@ Item {
property string shareFile: qsTr("Share file")
property string viewPlugin: qsTr("View plugin")
property string noVideoDevice: qsTr("No video device")
property string notAvailable: qsTr("N/A")
// Chatview header
property string hideChatView: qsTr("Hide chat view")

View file

@ -58,9 +58,16 @@ Control {
Connections {
target: AvAdapter
// TODO: audio device list updates
function onVideoDeviceListChanged(listIsEmpty) {
function onAudioDeviceListChanged(inputs, outputs) {
audioInputDeviceListModel.reset();
audioInputMenuAction.enabled = inputs
audioOutputDeviceListModel.reset();
audioOutputMenuAction.enabled = outputs
}
function onVideoDeviceListChanged(inputs) {
videoInputDeviceListModel.reset();
videoInputMenuAction.enabled = inputs
}
}
@ -68,6 +75,7 @@ Control {
Action {
id: audioInputMenuAction
text: JamiStrings.selectAudioInputDevice
Component.onCompleted: enabled = audioInputDeviceListModel.rowCount()
property var listModel: AudioDeviceModel {
id: audioInputDeviceListModel
lrcInstance: LRCInstance
@ -84,6 +92,7 @@ Control {
Action {
id: audioOutputMenuAction
text: JamiStrings.selectAudioOutputDevice
Component.onCompleted: enabled = audioOutputDeviceListModel.rowCount()
property var listModel: AudioDeviceModel {
id: audioOutputDeviceListModel
lrcInstance: LRCInstance
@ -100,6 +109,7 @@ Control {
Action {
id: videoInputMenuAction
text: JamiStrings.selectVideoDevice
Component.onCompleted: enabled = videoInputDeviceListModel.rowCount()
property var listModel: VideoInputDeviceModel {
id: videoInputDeviceListModel
lrcInstance: LRCInstance

View file

@ -159,7 +159,7 @@ ItemDelegate {
indicator: null
visible: menuAction !== undefined && !UrgentCount
visible: menuAction !== undefined && !UrgentCount && menuAction.enabled
y: isVertical ? 0 : -4
x: isVertical ? -4 : 0

View file

@ -215,8 +215,8 @@ Rectangle {
Connections {
target: AvAdapter
function onVideoDeviceListChanged(listIsEmpty) {
previewRenderer.visible = !listIsEmpty
function onVideoDeviceListChanged(inputs) {
previewRenderer.visible = (inputs !== 0)
}
}

View file

@ -49,7 +49,6 @@ Rectangle {
width: Math.min(JamiTheme.maximumWidthSettingsView, root.width)
// Audio
AudioSettings {
id: audioSettings
@ -60,7 +59,6 @@ Rectangle {
itemWidth: preferredColumnWidth
}
// Video
VideoSettings {
id: videoSettings

View file

@ -39,6 +39,8 @@ RowLayout {
property string tipText: ""
property string role: ""
property alias placeholderText: comboBoxOfLayout.placeholderText
signal indexChanged
function setCurrentIndex(index, emitIndexChanged = false) {

View file

@ -50,20 +50,19 @@ ColumnLayout {
deviceComboBoxSetting.comboModel.reset()
var count = deviceComboBoxSetting.comboModel.deviceCount()
var deviceListIsEmpty = count === 0
previewWidget.visible = count > 0
deviceComboBoxSetting.setEnabled(count > 0)
resolutionComboBoxSetting.setEnabled(count > 0)
fpsComboBoxSetting.setEnabled(count > 0)
if (deviceListIsEmpty) {
if (count === 0) {
resolutionComboBoxSetting.comboModel.reset()
fpsComboBoxSetting.comboModel.reset()
} else {
deviceComboBoxSetting.setCurrentIndex(
deviceComboBoxSetting.comboModel.getCurrentIndex(), true)
}
deviceComboBoxSetting.setCurrentIndex(
deviceComboBoxSetting.comboModel.getCurrentIndex(), true)
hardwareAccelControl.checked = AVModel.getHardwareAcceleration()
}
@ -132,8 +131,8 @@ ColumnLayout {
}
try {
SettingsAdapter.set_Video_Settings_Rate_And_Resolution(
AVModel.getCurrentVideoCaptureDevice(),rate, resolution)
SettingsAdapter.set_Video_Settings_Rate_And_Resolution(
AVModel.getCurrentVideoCaptureDevice(),rate, resolution)
updatePreviewRatio(resolution)
} catch(error){ console.warn(error.message) }
}
@ -176,6 +175,8 @@ ColumnLayout {
onIndexChanged: {
slotDeviceBoxCurrentIndexChanged(modelIndex)
}
placeholderText: JamiStrings.noVideoDevice
}
SettingsComboBox {
@ -220,7 +221,6 @@ ColumnLayout {
}
}
// Toggle switch to enable hardware acceleration
ToggleSwitch {
id: hardwareAccelControl

View file

@ -20,9 +20,6 @@
#include "lrcinstance.h"
#include "api/account.h"
#include "api/contact.h"
#include "api/conversation.h"
#include "api/newdevicemodel.h"
VideoInputDeviceModel::VideoInputDeviceModel(QObject* parent)
@ -35,32 +32,11 @@ int
VideoInputDeviceModel::rowCount(const QModelIndex& parent) const
{
if (!parent.isValid() && lrcInstance_) {
/*
* Count.
*/
int deviceListSize = lrcInstance_->avModel().getDevices().size();
if (deviceListSize > 0) {
return deviceListSize;
} else {
return 1;
}
return lrcInstance_->avModel().getDevices().size();
}
/*
* A valid QModelIndex returns 0 as no entry has sub-elements.
*/
return 0;
}
int
VideoInputDeviceModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
/*
* Only need one column.
*/
return 1;
}
QVariant
VideoInputDeviceModel::data(const QModelIndex& index, int role) const
{
@ -69,15 +45,6 @@ VideoInputDeviceModel::data(const QModelIndex& index, int role) const
return QVariant();
}
if (deviceList.size() == 0 && index.row() == 0) {
switch (role) {
case Role::DeviceName:
return QVariant(QObject::tr("No device"));
case Role::DeviceName_UTF8:
return QVariant(QObject::tr("No device").toUtf8());
}
}
if (deviceList.size() <= index.row()) {
return QVariant();
}
@ -117,37 +84,6 @@ VideoInputDeviceModel::roleNames() const
return roles;
}
QModelIndex
VideoInputDeviceModel::index(int row, int column, const QModelIndex& parent) const
{
Q_UNUSED(parent);
if (column != 0) {
return QModelIndex();
}
if (row >= 0 && row < rowCount()) {
return createIndex(row, column);
}
return QModelIndex();
}
QModelIndex
VideoInputDeviceModel::parent(const QModelIndex& child) const
{
Q_UNUSED(child);
return QModelIndex();
}
Qt::ItemFlags
VideoInputDeviceModel::flags(const QModelIndex& index) const
{
auto flags = QAbstractItemModel::flags(index) | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable;
if (!index.isValid()) {
return QAbstractItemModel::flags(index);
}
return flags;
}
void
VideoInputDeviceModel::reset()
{

View file

@ -38,27 +38,11 @@ public:
explicit VideoInputDeviceModel(QObject* parent = nullptr);
~VideoInputDeviceModel();
/*
* QAbstractListModel override.
*/
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
/*
* Override role name as access point in qml.
*/
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex& child) const;
Qt::ItemFlags flags(const QModelIndex& index) const;
/*
* This function is to reset the model when there's new account added.
*/
Q_INVOKABLE void reset();
/*
* This function is to reset the model when there's new account added.
*/
Q_INVOKABLE int deviceCount();
// get model index of the current device