Commit da6dcc39 authored by Andreas Traczyk's avatar Andreas Traczyk

videoview: use device friendly name in context menu

Change-Id: Ic1b6d05bf8fe729359bb76769770a5b4922b7e62
parent 3bfd7fd9
......@@ -1047,16 +1047,11 @@ void SettingsWidget::slotDeviceBoxCurrentIndexChanged(int index)
.toStdString();
auto devices = LRCInstance::avModel().getDevices();
try {
auto iter = std::find_if(devices.begin(), devices.end(),
[deviceName](const std::string& d) {
auto settings = LRCInstance::avModel().getDeviceSettings(d);
return settings.name == deviceName;
});
if (iter == devices.end()) {
auto deviceId = LRCInstance::avModel().getDeviceIdFromName(deviceName);
if (deviceId.empty()) {
qWarning() << "Couldn't find device: " << deviceName.c_str();
return;
}
auto deviceId = *iter;
LRCInstance::avModel().setCurrentVideoCaptureDevice(deviceId);
LRCInstance::avModel().setDefaultDevice(deviceId);
setFormatListForDevice(deviceId);
......
......@@ -191,23 +191,30 @@ VideoView::showContextMenu(const QPoint& position)
auto devices = LRCInstance::avModel().getDevices();
auto device = LRCInstance::avModel().getCurrentVideoCaptureDevice();
for (auto d : devices) {
auto deviceName = QString::fromStdString(d).toUtf8();
auto deviceAction = new QAction(deviceName, this);
menu.addAction(deviceAction);
deviceAction->setCheckable(true);
if (d == activeDevice.name) {
deviceAction->setChecked(true);
}
connect(deviceAction, &QAction::triggered,
[this, deviceName]() {
auto device = deviceName.toStdString();
if (LRCInstance::avModel().getCurrentVideoCaptureDevice() == device) {
return;
}
LRCInstance::avModel().switchInputTo(device);
resetPreview();
LRCInstance::avModel().setCurrentVideoCaptureDevice(device);
});
try {
auto settings = LRCInstance::avModel().getDeviceSettings(d);
QString deviceName = QString::fromStdString(settings.name).toUtf8();
auto deviceAction = new QAction(deviceName, this);
menu.addAction(deviceAction);
deviceAction->setCheckable(true);
if (d == activeDevice.name) {
deviceAction->setChecked(true);
}
connect(deviceAction, &QAction::triggered,
[this, deviceName]() {
auto deviceId = LRCInstance::avModel().getDeviceIdFromName(deviceName.toStdString());
if (deviceId.empty()) {
qWarning() << "Couldn't find device: " << deviceName;
return;
}
if (LRCInstance::avModel().getCurrentVideoCaptureDevice() == deviceId) {
return;
}
LRCInstance::avModel().switchInputTo(deviceId);
resetPreview();
LRCInstance::avModel().setCurrentVideoCaptureDevice(deviceId);
});
} catch (...) {}
}
menu.addSeparator();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment