Skip to content
Snippets Groups Projects
Commit 085b71bd authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

videodevices: replace C++ filter proxy model with QML-SFPM

Change-Id: I348cd7acc4cccee4b5a6784cc2430156bb73667b
parent 49aadea7
Branches
Tags
No related merge requests found
...@@ -46,19 +46,16 @@ ComboBox { ...@@ -46,19 +46,16 @@ ComboBox {
width: root.width width: root.width
contentItem: Text { contentItem: Text {
text: { text: {
if (index >= 0) { if (index < 0) return ''
var currentItem = root.delegateModel.items.get(index) var currentItem = root.delegateModel.items.get(index)
return currentItem.model[root.textRole].toString() const value = currentItem.model[root.textRole]
} return value === undefined ? '' : value.toString()
return ""
} }
color: hovered ? JamiTheme.comboboxTextColorHovered : JamiTheme.textColor color: hovered ? JamiTheme.comboboxTextColorHovered : JamiTheme.textColor
elide: Text.ElideRight elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
background: Rectangle { background: Rectangle {
......
...@@ -236,14 +236,9 @@ Control { ...@@ -236,14 +236,9 @@ Control {
id: videoInputMenuAction id: videoInputMenuAction
enabled: VideoDevices.listSize !== 0 enabled: VideoDevices.listSize !== 0
text: JamiStrings.selectVideoDevice text: JamiStrings.selectVideoDevice
property var listModel: VideoDevices.devicesSourceModel() property var listModel: VideoDevices.deviceSourceModel
function accept(index) { function accept(index) {
if (VideoDevices.listSize < 1) VideoDevices.setDefaultDevice(index)
return
// TODO: change it when we can suppot showing default and
// current rendering device at the same time and
// start and stop preview logic in here should be in LRC
VideoDevices.setDefaultDevice(index, true)
} }
} }
] ]
......
...@@ -21,6 +21,8 @@ import QtQuick.Controls ...@@ -21,6 +21,8 @@ import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Qt5Compat.GraphicalEffects import Qt5Compat.GraphicalEffects
import SortFilterProxyModel 0.2
import net.jami.Models 1.1 import net.jami.Models 1.1
import net.jami.Adapters 1.1 import net.jami.Adapters 1.1
import net.jami.Enums 1.1 import net.jami.Enums 1.1
...@@ -118,13 +120,27 @@ ColumnLayout { ...@@ -118,13 +120,27 @@ ColumnLayout {
tipText: JamiStrings.selectVideoDevice tipText: JamiStrings.selectVideoDevice
placeholderText: JamiStrings.noVideoDevice placeholderText: JamiStrings.noVideoDevice
currentSelectionText: VideoDevices.defaultName currentSelectionText: VideoDevices.defaultName
comboModel: VideoDevices.devicesFilterModel()
comboModel: SortFilterProxyModel {
id: filteredDevicesModel
sourceModel: SortFilterProxyModel {
id: deviceSourceModel
sourceModel: VideoDevices.deviceSourceModel
}
filters: ValueFilter {
roleName: "DeviceName"
value: VideoDevices.defaultName
inverted: true
enabled: deviceSourceModel.count > 1
}
}
role: "DeviceName" role: "DeviceName"
onActivated: { onActivated: {
// TODO: start and stop preview logic in here should be in LRC // TODO: start and stop preview logic in here should be in LRC
VideoDevices.stopDevice(previewWidget.deviceId) VideoDevices.stopDevice(previewWidget.deviceId)
VideoDevices.setDefaultDevice(modelIndex) VideoDevices.setDefaultDevice(
filteredDevicesModel.mapToSource(modelIndex))
startPreviewing() startPreviewing()
} }
} }
...@@ -145,10 +161,24 @@ ColumnLayout { ...@@ -145,10 +161,24 @@ ColumnLayout {
labelText: JamiStrings.resolution labelText: JamiStrings.resolution
currentSelectionText: VideoDevices.defaultRes currentSelectionText: VideoDevices.defaultRes
tipText: JamiStrings.selectVideoResolution tipText: JamiStrings.selectVideoResolution
comboModel: VideoDevices.resFilterModel()
comboModel: SortFilterProxyModel {
id: filteredResModel
sourceModel: SortFilterProxyModel {
id: resSourceModel
sourceModel: VideoDevices.resSourceModel
}
filters: ValueFilter {
roleName: "Resolution"
value: VideoDevices.defaultRes
inverted: true
enabled: resSourceModel.count > 1
}
}
role: "Resolution" role: "Resolution"
onActivated: VideoDevices.setDefaultDeviceRes(modelIndex) onActivated: VideoDevices.setDefaultDeviceRes(
filteredResModel.mapToSource(modelIndex))
} }
SettingsComboBox { SettingsComboBox {
...@@ -167,10 +197,23 @@ ColumnLayout { ...@@ -167,10 +197,23 @@ ColumnLayout {
tipText: JamiStrings.selectFPS tipText: JamiStrings.selectFPS
labelText: JamiStrings.fps labelText: JamiStrings.fps
currentSelectionText: VideoDevices.defaultFps.toString() currentSelectionText: VideoDevices.defaultFps.toString()
comboModel: VideoDevices.fpsFilterModel() comboModel: SortFilterProxyModel {
id: filteredFpsModel
sourceModel: SortFilterProxyModel {
id: fpsSourceModel
sourceModel: VideoDevices.fpsSourceModel
}
filters: ValueFilter {
roleName: "FPS"
value: VideoDevices.defaultFps
inverted: true
enabled: fpsSourceModel.count > 1
}
}
role: "FPS" role: "FPS"
onActivated: VideoDevices.setDefaultDeviceFps(modelIndex) onActivated: VideoDevices.setDefaultDeviceFps(
filteredFpsModel.mapToSource(modelIndex))
} }
ToggleSwitch { ToggleSwitch {
...@@ -264,7 +307,7 @@ ColumnLayout { ...@@ -264,7 +307,7 @@ ColumnLayout {
comboModel: ListModel { id: screenSharingFpsModel } comboModel: ListModel { id: screenSharingFpsModel }
role: "FPS" role: "FPS"
Component.onCompleted: { Component.onCompleted: {
var elements = VideoDevices.getScreenSharingFpsModel() var elements = VideoDevices.sharingFpsSourceModel
for (var item in elements) { for (var item in elements) {
screenSharingFpsModel.append({"FPS": elements[item]}) screenSharingFpsModel.append({"FPS": elements[item]})
} }
......
/*! /*
* Copyright (C) 2020-2022 Savoir-faire Linux Inc. * Copyright (C) 2020-2022 Savoir-faire Linux Inc.
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
* *
...@@ -119,10 +119,8 @@ VideoFormatResolutionModel::roleNames() const ...@@ -119,10 +119,8 @@ VideoFormatResolutionModel::roleNames() const
int int
VideoFormatResolutionModel::getCurrentIndex() const VideoFormatResolutionModel::getCurrentIndex() const
{ {
QString currentDeviceId = videoDevices_->get_defaultId();
QString currentResolution = videoDevices_->get_defaultRes(); QString currentResolution = videoDevices_->get_defaultRes();
auto resultList = match(index(0, 0), Resolution, QVariant(currentResolution)); auto resultList = match(index(0, 0), Resolution, QVariant(currentResolution));
return resultList.size() > 0 ? resultList[0].row() : 0; return resultList.size() > 0 ? resultList[0].row() : 0;
} }
...@@ -183,21 +181,10 @@ VideoFormatFpsModel::getCurrentIndex() const ...@@ -183,21 +181,10 @@ VideoFormatFpsModel::getCurrentIndex() const
VideoDevices::VideoDevices(LRCInstance* lrcInstance, QObject* parent) VideoDevices::VideoDevices(LRCInstance* lrcInstance, QObject* parent)
: QObject(parent) : QObject(parent)
, lrcInstance_(lrcInstance) , lrcInstance_(lrcInstance)
, devicesFilterModel_(new CurrentItemFilterModel(this))
, resFilterModel_(new CurrentItemFilterModel(this))
, fpsFilterModel_(new CurrentItemFilterModel(this))
{ {
devicesSourceModel_ = new VideoInputDeviceModel(lrcInstance, this); deviceListModel_ = new VideoInputDeviceModel(lrcInstance, this);
resSourceModel_ = new VideoFormatResolutionModel(lrcInstance, this); resListModel_ = new VideoFormatResolutionModel(lrcInstance, this);
fpsSourceModel_ = new VideoFormatFpsModel(lrcInstance, this); fpsListModel_ = new VideoFormatFpsModel(lrcInstance, this);
devicesFilterModel_->setSourceModel(devicesSourceModel_);
resFilterModel_->setSourceModel(resSourceModel_);
fpsFilterModel_->setSourceModel(fpsSourceModel_);
devicesFilterModel_->setFilterRole(VideoInputDeviceModel::DeviceName);
resFilterModel_->setFilterRole(VideoFormatResolutionModel::Resolution);
fpsFilterModel_->setFilterRole(VideoFormatFpsModel::FPS);
connect(&lrcInstance_->avModel(), connect(&lrcInstance_->avModel(),
&lrc::api::AVModel::deviceEvent, &lrc::api::AVModel::deviceEvent,
...@@ -206,66 +193,27 @@ VideoDevices::VideoDevices(LRCInstance* lrcInstance, QObject* parent) ...@@ -206,66 +193,27 @@ VideoDevices::VideoDevices(LRCInstance* lrcInstance, QObject* parent)
auto displaySettings = lrcInstance_->avModel().getDeviceSettings(DEVICE_DESKTOP); auto displaySettings = lrcInstance_->avModel().getDeviceSettings(DEVICE_DESKTOP);
auto desktopfpsSource = lrcInstance_->avModel().getDeviceCapabilities(DEVICE_DESKTOP); auto desktopFpsSource = lrcInstance_->avModel().getDeviceCapabilities(DEVICE_DESKTOP);
if (desktopfpsSource.contains(CHANNEL_DEFAULT) && !desktopfpsSource[CHANNEL_DEFAULT].empty()) { if (desktopFpsSource.contains(CHANNEL_DEFAULT) && !desktopFpsSource[CHANNEL_DEFAULT].empty()) {
desktopfpsSourceModel_ = desktopfpsSource[CHANNEL_DEFAULT][0].second; sharingFpsListModel_ = desktopFpsSource[CHANNEL_DEFAULT][0].second;
if (desktopfpsSourceModel_.indexOf(displaySettings.rate) >= 0) if (sharingFpsListModel_.indexOf(displaySettings.rate) >= 0)
set_screenSharingDefaultFps(displaySettings.rate); set_screenSharingDefaultFps(displaySettings.rate);
} }
updateData(); updateData();
} }
VideoDevices::~VideoDevices() {} void
VideoDevices::setDefaultDevice(int index)
QVariant
VideoDevices::devicesFilterModel()
{
return QVariant::fromValue(devicesFilterModel_);
}
QVariant
VideoDevices::devicesSourceModel()
{
return QVariant::fromValue(devicesSourceModel_);
}
QVariant
VideoDevices::resFilterModel()
{
return QVariant::fromValue(resFilterModel_);
}
QVariant
VideoDevices::resSourceModel()
{
return QVariant::fromValue(resSourceModel_);
}
QVariant
VideoDevices::fpsFilterModel()
{
return QVariant::fromValue(fpsFilterModel_);
}
QVariant
VideoDevices::fpsSourceModel()
{ {
return QVariant::fromValue(fpsSourceModel_); if (!listSize_) {
return;
} }
void
VideoDevices::setDefaultDevice(int index, bool useSourceModel)
{
QString deviceId {}; QString deviceId {};
auto callId = lrcInstance_->getCurrentCallId(); auto callId = lrcInstance_->getCurrentCallId();
if (useSourceModel) deviceId = deviceListModel_
deviceId = devicesSourceModel_ ->data(deviceListModel_->index(index, 0), VideoInputDeviceModel::DeviceId)
->data(devicesSourceModel_->index(index, 0), VideoInputDeviceModel::DeviceId)
.toString();
else
deviceId = devicesFilterModel_
->data(devicesFilterModel_->index(index, 0), VideoInputDeviceModel::DeviceId)
.toString(); .toString();
lrcInstance_->avModel().setDefaultDevice(deviceId); lrcInstance_->avModel().setDefaultDevice(deviceId);
...@@ -279,11 +227,10 @@ VideoDevices::setDefaultDevice(int index, bool useSourceModel) ...@@ -279,11 +227,10 @@ VideoDevices::setDefaultDevice(int index, bool useSourceModel)
const QString const QString
VideoDevices::getDefaultDevice() VideoDevices::getDefaultDevice()
{ {
auto idx = devicesSourceModel_->getCurrentIndex(); auto idx = deviceListModel_->getCurrentIndex();
auto rendererId = QString("camera://") auto rendererId = QString("camera://")
+ devicesSourceModel_ + deviceListModel_
->data(devicesSourceModel_->index(idx, 0), ->data(deviceListModel_->index(idx, 0), VideoInputDeviceModel::DeviceId)
VideoInputDeviceModel::DeviceId)
.toString(); .toString();
return rendererId; return rendererId;
} }
...@@ -318,8 +265,8 @@ VideoDevices::setDefaultDeviceRes(int index) ...@@ -318,8 +265,8 @@ VideoDevices::setDefaultDeviceRes(int index)
{ {
auto& channelCaps = get_defaultResRateList(); auto& channelCaps = get_defaultResRateList();
auto settings = lrcInstance_->avModel().getDeviceSettings(get_defaultId()); auto settings = lrcInstance_->avModel().getDeviceSettings(get_defaultId());
settings.size = resFilterModel_ settings.size = resListModel_
->data(resFilterModel_->index(index, 0), ->data(resListModel_->index(index, 0),
VideoFormatResolutionModel::Resolution) VideoFormatResolutionModel::Resolution)
.toString(); .toString();
...@@ -339,8 +286,8 @@ VideoDevices::setDefaultDeviceFps(int index) ...@@ -339,8 +286,8 @@ VideoDevices::setDefaultDeviceFps(int index)
{ {
auto settings = lrcInstance_->avModel().getDeviceSettings(get_defaultId()); auto settings = lrcInstance_->avModel().getDeviceSettings(get_defaultId());
settings.size = get_defaultRes(); settings.size = get_defaultRes();
settings.rate = fpsFilterModel_ settings.rate = fpsListModel_
->data(fpsFilterModel_->index(index, 0), VideoFormatFpsModel::FPS_Float) ->data(fpsListModel_->index(index, 0), VideoFormatFpsModel::FPS_Float)
.toFloat(); .toFloat();
lrcInstance_->avModel().setDeviceSettings(settings); lrcInstance_->avModel().setDeviceSettings(settings);
...@@ -358,12 +305,6 @@ VideoDevices::setDisplayFPS(const QString& fps) ...@@ -358,12 +305,6 @@ VideoDevices::setDisplayFPS(const QString& fps)
set_screenSharingDefaultFps(fps.toInt()); set_screenSharingDefaultFps(fps.toInt());
} }
QVariant
VideoDevices::getScreenSharingFpsModel()
{
return QVariant::fromValue(desktopfpsSourceModel_.toList());
}
void void
VideoDevices::updateData() VideoDevices::updateData()
{ {
...@@ -377,31 +318,12 @@ VideoDevices::updateData() ...@@ -377,31 +318,12 @@ VideoDevices::updateData()
? CHANNEL_DEFAULT ? CHANNEL_DEFAULT
: defaultDeviceSettings.channel]; : defaultDeviceSettings.channel];
lrc::api::video::FrameratesList fpsList; lrc::api::video::FrameratesList fpsList;
for (int i = 0; i < currentResRateList.size(); i++) { for (int i = 0; i < currentResRateList.size(); i++) {
if (currentResRateList[i].first == defaultDeviceSettings.size) { if (currentResRateList[i].first == defaultDeviceSettings.size) {
fpsList = currentResRateList[i].second; fpsList = currentResRateList[i].second;
} }
} }
if (deviceOpen_ && defaultId_ != defaultDeviceSettings.id) {
auto callId = lrcInstance_->getCurrentCallId();
if (!callId.isEmpty()) {
auto callId = lrcInstance_->getCurrentCallId();
auto callInfos = lrcInstance_->getCallInfo(callId,
lrcInstance_->get_currentAccountId());
for (const auto& media : callInfos->mediaList) {
if (media["MUTED"] == "false" && media["ENABLED"] == "true"
&& media["SOURCE"] == getDefaultDevice()) {
/*lrcInstance_->avModel().switchInputTo("camera://" +
defaultDeviceSettings.id, callId);*/
// startDevice("camera://" + defaultDeviceSettings.id);
break;
}
}
}
}
set_defaultChannel(defaultDeviceSettings.channel); set_defaultChannel(defaultDeviceSettings.channel);
set_defaultId(defaultDeviceSettings.id); set_defaultId(defaultDeviceSettings.id);
set_defaultName(defaultDeviceSettings.name); set_defaultName(defaultDeviceSettings.name);
...@@ -409,10 +331,6 @@ VideoDevices::updateData() ...@@ -409,10 +331,6 @@ VideoDevices::updateData()
set_defaultFps(defaultDeviceSettings.rate); set_defaultFps(defaultDeviceSettings.rate);
set_defaultResRateList(currentResRateList); set_defaultResRateList(currentResRateList);
set_defaultFpsList(fpsList); set_defaultFpsList(fpsList);
devicesFilterModel_->setCurrentItemFilter(defaultDeviceSettings.name);
resFilterModel_->setCurrentItemFilter(defaultDeviceSettings.size);
fpsFilterModel_->setCurrentItemFilter(static_cast<int>(defaultDeviceSettings.rate));
} else { } else {
set_defaultChannel(""); set_defaultChannel("");
set_defaultId(""); set_defaultId("");
...@@ -421,23 +339,22 @@ VideoDevices::updateData() ...@@ -421,23 +339,22 @@ VideoDevices::updateData()
set_defaultFps(0); set_defaultFps(0);
set_defaultResRateList({}); set_defaultResRateList({});
set_defaultFpsList({}); set_defaultFpsList({});
devicesFilterModel_->setCurrentItemFilter("");
resFilterModel_->setCurrentItemFilter("");
fpsFilterModel_->setCurrentItemFilter(0);
} }
devicesSourceModel_->reset(); deviceListModel_->reset();
resSourceModel_->reset(); resListModel_->reset();
fpsSourceModel_->reset(); fpsListModel_->reset();
set_deviceSourceModel(QVariant::fromValue(deviceListModel_));
set_resSourceModel(QVariant::fromValue(resListModel_));
set_fpsSourceModel(QVariant::fromValue(fpsListModel_));
set_sharingFpsSourceModel(QVariant::fromValue(sharingFpsListModel_.toList()));
} }
void void
VideoDevices::onVideoDeviceEvent() VideoDevices::onVideoDeviceEvent()
{ {
auto& avModel = lrcInstance_->avModel(); auto& avModel = lrcInstance_->avModel();
auto* callModel = lrcInstance_->getCurrentCallModel();
auto defaultDevice = avModel.getDefaultDevice();
QString callId = lrcInstance_->getCurrentCallId(); QString callId = lrcInstance_->getCurrentCallId();
// Decide whether a device has plugged, unplugged, or nothing has changed. // Decide whether a device has plugged, unplugged, or nothing has changed.
......
/*! /*
* Copyright (C) 2020-2022 Savoir-faire Linux Inc. * Copyright (C) 2020-2022 Savoir-faire Linux Inc.
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
* *
...@@ -23,41 +23,10 @@ ...@@ -23,41 +23,10 @@
#include "api/devicemodel.h" #include "api/devicemodel.h"
#include <QSortFilterProxyModel>
#include <QObject> #include <QObject>
class VideoDevices; class VideoDevices;
class CurrentItemFilterModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit CurrentItemFilterModel(QObject* parent = nullptr)
: QSortFilterProxyModel(parent)
{}
void setCurrentItemFilter(const QVariant& filter)
{
currentItemFilter_ = filter;
}
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override
{
// Do not filter if there is only one item.
if (currentItemFilter_.isNull() || sourceModel()->rowCount() == 1)
return true;
// Exclude current item filter.
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
return index.data(filterRole()) != currentItemFilter_ && !index.parent().isValid();
}
private:
QVariant currentItemFilter_ {};
};
class VideoInputDeviceModel : public QAbstractListModel class VideoInputDeviceModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
...@@ -155,21 +124,16 @@ class VideoDevices : public QObject ...@@ -155,21 +124,16 @@ class VideoDevices : public QObject
QML_RO_PROPERTY(int, defaultFps) QML_RO_PROPERTY(int, defaultFps)
QML_PROPERTY(int, screenSharingDefaultFps) QML_PROPERTY(int, screenSharingDefaultFps)
QML_RO_PROPERTY(QVariant, deviceSourceModel)
QML_RO_PROPERTY(QVariant, resSourceModel)
QML_RO_PROPERTY(QVariant, fpsSourceModel)
QML_RO_PROPERTY(QVariant, sharingFpsSourceModel)
public: public:
explicit VideoDevices(LRCInstance* lrcInstance, QObject* parent = nullptr); explicit VideoDevices(LRCInstance* lrcInstance, QObject* parent = nullptr);
~VideoDevices(); ~VideoDevices() = default;
Q_INVOKABLE QVariant devicesFilterModel();
Q_INVOKABLE QVariant devicesSourceModel();
Q_INVOKABLE QVariant resFilterModel();
Q_INVOKABLE QVariant resSourceModel();
Q_INVOKABLE QVariant fpsFilterModel(); Q_INVOKABLE void setDefaultDevice(int index);
Q_INVOKABLE QVariant fpsSourceModel();
Q_INVOKABLE QVariant getScreenSharingFpsModel();
Q_INVOKABLE void setDefaultDevice(int index, bool useSourceModel = false);
Q_INVOKABLE const QString getDefaultDevice(); Q_INVOKABLE const QString getDefaultDevice();
Q_INVOKABLE QString startDevice(const QString& deviceId, bool force = false); Q_INVOKABLE QString startDevice(const QString& deviceId, bool force = false);
Q_INVOKABLE void stopDevice(const QString& deviceId, bool force = false); Q_INVOKABLE void stopDevice(const QString& deviceId, bool force = false);
...@@ -198,17 +162,13 @@ private: ...@@ -198,17 +162,13 @@ private:
LRCInstance* lrcInstance_; LRCInstance* lrcInstance_;
CurrentItemFilterModel* devicesFilterModel_; VideoInputDeviceModel* deviceListModel_;
CurrentItemFilterModel* resFilterModel_; VideoFormatResolutionModel* resListModel_;
CurrentItemFilterModel* fpsFilterModel_; VideoFormatFpsModel* fpsListModel_;
VideoInputDeviceModel* devicesSourceModel_;
VideoFormatResolutionModel* resSourceModel_;
VideoFormatFpsModel* fpsSourceModel_;
lrc::api::video::ResRateList defaultResRateList_; lrc::api::video::ResRateList defaultResRateList_;
lrc::api::video::FrameratesList defaultFpsList_; lrc::api::video::FrameratesList defaultFpsList_;
lrc::api::video::FrameratesList desktopfpsSourceModel_; lrc::api::video::FrameratesList sharingFpsListModel_;
constexpr static const char DEVICE_DESKTOP[] = "desktop"; constexpr static const char DEVICE_DESKTOP[] = "desktop";
constexpr static const char CHANNEL_DEFAULT[] = "default"; constexpr static const char CHANNEL_DEFAULT[] = "default";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment