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:
@@ -66,27 +66,37 @@ void MainWindow::updateTitle()
|
||||
setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps");
|
||||
}
|
||||
|
||||
std::string MainWindow::chooseCamera(CameraManager *cm)
|
||||
{
|
||||
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()));
|
||||
|
||||
QString name = QInputDialog::getItem(this, "Select Camera",
|
||||
"Camera:", cameras, 0,
|
||||
false, &result);
|
||||
if (!result)
|
||||
return std::string();
|
||||
|
||||
return name.toStdString();
|
||||
}
|
||||
|
||||
int MainWindow::openCamera(CameraManager *cm)
|
||||
{
|
||||
std::string cameraName;
|
||||
|
||||
if (!options_.isSet(OptCamera)) {
|
||||
QStringList cameras;
|
||||
bool result;
|
||||
|
||||
for (const std::shared_ptr<Camera> &cam : cm->cameras())
|
||||
cameras.append(QString::fromStdString(cam->name()));
|
||||
|
||||
QString name = QInputDialog::getItem(this, "Select Camera",
|
||||
"Camera:", cameras, 0,
|
||||
false, &result);
|
||||
if (!result)
|
||||
return -EINVAL;
|
||||
|
||||
cameraName = name.toStdString();
|
||||
} else {
|
||||
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_) {
|
||||
|
||||
@@ -43,6 +43,7 @@ private Q_SLOTS:
|
||||
void updateTitle();
|
||||
|
||||
private:
|
||||
std::string chooseCamera(CameraManager *cm);
|
||||
int openCamera(CameraManager *cm);
|
||||
|
||||
int startCapture();
|
||||
|
||||
Reference in New Issue
Block a user