summaryrefslogtreecommitdiff
path: root/src/qcam
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2019-10-25 11:30:00 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2019-10-25 12:20:29 +0100
commit74208ea5d110530cb1fea6e724d85bb8685a896b (patch)
tree68b6a40544f1d34fdcad25db6772e6556e331bf9 /src/qcam
parent9d1c26588b100f2f8adf4408217f4a8143c9091c (diff)
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>
Diffstat (limited to 'src/qcam')
-rw-r--r--src/qcam/main_window.cpp40
-rw-r--r--src/qcam/main_window.h1
2 files changed, 26 insertions, 15 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index ef4ad4a2..3d563092 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -66,27 +66,37 @@ 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;
+ QStringList cameras;
+ bool result;
+
+ if (cm->cameras().size() == 1)
+ return cm->cameras()[0]->name();
- if (!options_.isSet(OptCamera)) {
- QStringList cameras;
- bool result;
+ for (const std::shared_ptr<Camera> &cam : cm->cameras())
+ cameras.append(QString::fromStdString(cam->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();
- QString name = QInputDialog::getItem(this, "Select Camera",
- "Camera:", cameras, 0,
- false, &result);
- if (!result)
- return -EINVAL;
+ return name.toStdString();
+}
- cameraName = name.toStdString();
- } else {
+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_) {
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index 6873155a..30dd8743 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -43,6 +43,7 @@ private Q_SLOTS:
void updateTitle();
private:
+ std::string chooseCamera(CameraManager *cm);
int openCamera(CameraManager *cm);
int startCapture();