summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();