qcam: Don't ask for a camera when only one exists
If there is only one camera exposed by libcamera, there is little value in asking the user to choose it. Automatically select it, and remove the need to ask the user to select 'ok' from a Dialog box. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
9d1c26588b
commit
74208ea5d1
2 changed files with 27 additions and 16 deletions
|
@ -66,14 +66,14 @@ void MainWindow::updateTitle()
|
|||
setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps");
|
||||
}
|
||||
|
||||
int MainWindow::openCamera(CameraManager *cm)
|
||||
std::string MainWindow::chooseCamera(CameraManager *cm)
|
||||
{
|
||||
std::string cameraName;
|
||||
|
||||
if (!options_.isSet(OptCamera)) {
|
||||
QStringList cameras;
|
||||
bool result;
|
||||
|
||||
if (cm->cameras().size() == 1)
|
||||
return cm->cameras()[0]->name();
|
||||
|
||||
for (const std::shared_ptr<Camera> &cam : cm->cameras())
|
||||
cameras.append(QString::fromStdString(cam->name()));
|
||||
|
||||
|
@ -81,13 +81,23 @@ int MainWindow::openCamera(CameraManager *cm)
|
|||
"Camera:", cameras, 0,
|
||||
false, &result);
|
||||
if (!result)
|
||||
return -EINVAL;
|
||||
return std::string();
|
||||
|
||||
cameraName = name.toStdString();
|
||||
} else {
|
||||
cameraName = static_cast<std::string>(options_[OptCamera]);
|
||||
return name.toStdString();
|
||||
}
|
||||
|
||||
int MainWindow::openCamera(CameraManager *cm)
|
||||
{
|
||||
std::string cameraName;
|
||||
|
||||
if (options_.isSet(OptCamera))
|
||||
cameraName = static_cast<std::string>(options_[OptCamera]);
|
||||
else
|
||||
cameraName = chooseCamera(cm);
|
||||
|
||||
if (cameraName == "")
|
||||
return -EINVAL;
|
||||
|
||||
camera_ = cm->get(cameraName);
|
||||
if (!camera_) {
|
||||
std::cout << "Camera " << cameraName << " not found"
|
||||
|
|
|
@ -43,6 +43,7 @@ private Q_SLOTS:
|
|||
void updateTitle();
|
||||
|
||||
private:
|
||||
std::string chooseCamera(CameraManager *cm);
|
||||
int openCamera(CameraManager *cm);
|
||||
|
||||
int startCapture();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue