1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-04 06:03:21 +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(); auto& avModel = lrcInstance_->avModel();
deviceListSize_ = avModel.getDevices().size(); 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]() { connect(lrcInstance_->renderer(), &RenderManager::previewFrameStarted, [this]() {
// TODO: listen to the correct signals that are needed to be added in daemon or lrc // TODO: listen to the correct signals that are needed to be added in daemon or lrc
auto callId = getCurrentCallId(); auto callId = getCurrentCallId();
@ -235,21 +236,17 @@ AvAdapter::stopAudioMeter(bool async)
lrcInstance_->stopAudioMeter(async); lrcInstance_->stopAudioMeter(async);
} }
QString void
AvAdapter::getCurrentCallId() AvAdapter::onAudioDeviceEvent()
{ {
try { auto& avModel = lrcInstance_->avModel();
const auto& convInfo = lrcInstance_->getConversationFromConvUid( auto inputs = avModel.getAudioInputDevices().size();
lrcInstance_->get_selectedConvUid()); auto outputs = avModel.getAudioOutputDevices().size();
auto call = lrcInstance_->getCallInfoForConversation(convInfo); Q_EMIT audioDeviceListChanged(inputs, outputs);
return call ? call->id : QString();
} catch (...) {
return QString();
}
} }
void void
AvAdapter::slotDeviceEvent() AvAdapter::onVideoDeviceEvent()
{ {
auto& avModel = lrcInstance_->avModel(); auto& avModel = lrcInstance_->avModel();
auto defaultDevice = avModel.getDefaultDevice(); auto defaultDevice = avModel.getDefaultDevice();
@ -305,11 +302,24 @@ AvAdapter::slotDeviceEvent()
} }
} }
Q_EMIT videoDeviceListChanged(currentDeviceListSize == 0); Q_EMIT videoDeviceListChanged(currentDeviceListSize);
deviceListSize_ = 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 int
AvAdapter::getScreenNumber() const AvAdapter::getScreenNumber() const
{ {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -20,9 +20,6 @@
#include "lrcinstance.h" #include "lrcinstance.h"
#include "api/account.h"
#include "api/contact.h"
#include "api/conversation.h"
#include "api/newdevicemodel.h" #include "api/newdevicemodel.h"
VideoInputDeviceModel::VideoInputDeviceModel(QObject* parent) VideoInputDeviceModel::VideoInputDeviceModel(QObject* parent)
@ -35,32 +32,11 @@ int
VideoInputDeviceModel::rowCount(const QModelIndex& parent) const VideoInputDeviceModel::rowCount(const QModelIndex& parent) const
{ {
if (!parent.isValid() && lrcInstance_) { if (!parent.isValid() && lrcInstance_) {
/* return lrcInstance_->avModel().getDevices().size();
* Count.
*/
int deviceListSize = lrcInstance_->avModel().getDevices().size();
if (deviceListSize > 0) {
return deviceListSize;
} else {
return 1;
}
} }
/*
* A valid QModelIndex returns 0 as no entry has sub-elements.
*/
return 0; return 0;
} }
int
VideoInputDeviceModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
/*
* Only need one column.
*/
return 1;
}
QVariant QVariant
VideoInputDeviceModel::data(const QModelIndex& index, int role) const VideoInputDeviceModel::data(const QModelIndex& index, int role) const
{ {
@ -69,15 +45,6 @@ VideoInputDeviceModel::data(const QModelIndex& index, int role) const
return QVariant(); 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()) { if (deviceList.size() <= index.row()) {
return QVariant(); return QVariant();
} }
@ -117,37 +84,6 @@ VideoInputDeviceModel::roleNames() const
return roles; 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 void
VideoInputDeviceModel::reset() VideoInputDeviceModel::reset()
{ {

View file

@ -38,27 +38,11 @@ public:
explicit VideoInputDeviceModel(QObject* parent = nullptr); explicit VideoInputDeviceModel(QObject* parent = nullptr);
~VideoInputDeviceModel(); ~VideoInputDeviceModel();
/*
* QAbstractListModel override.
*/
int rowCount(const QModelIndex& parent = QModelIndex()) const 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; 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; 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(); Q_INVOKABLE void reset();
/*
* This function is to reset the model when there's new account added.
*/
Q_INVOKABLE int deviceCount(); Q_INVOKABLE int deviceCount();
// get model index of the current device // get model index of the current device