[libcamera-devel,v2,4/4] qcam: CamSelectDialog: Display Location and Model propety of camera
diff mbox series

Message ID 20220806190433.59128-5-utkarsh02t@gmail.com
State Superseded
Headers show
Series
  • Improve Camera Selection GUI in QCam
Related show

Commit Message

Utkarsh Tiwari Aug. 6, 2022, 7:04 p.m. UTC
The camera selection dialog currently only displays the camera Id.
Display the camera location and camera model if available.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
---
 src/qcam/cam_select_dialog.h | 54 ++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

Patch
diff mbox series

diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
index a5189ec3..0200d374 100644
--- a/src/qcam/cam_select_dialog.h
+++ b/src/qcam/cam_select_dialog.h
@@ -12,11 +12,14 @@ 
 
 #include <libcamera/camera.h>
 #include <libcamera/camera_manager.h>
+#include <libcamera/controls.h>
+#include <libcamera/property_ids.h>
 
 #include <QComboBox>
 #include <QDialog>
 #include <QDialogButtonBox>
 #include <QFormLayout>
+#include <QLabel>
 #include <QString>
 
 class CamSelectDialog : public QDialog
@@ -34,6 +37,17 @@  public:
 		for (const auto &cam : cm_->cameras())
 			cameraIdComboBox_->addItem(QString::fromStdString(cam->id()));
 
+		/* Set camera information labels. */
+		cameraLocation_ = new QLabel;
+		cameraModel_ = new QLabel;
+
+		updateCamInfo(cm_->get(getCurrentCamera()));
+		connect(cameraIdComboBox_, &QComboBox::currentTextChanged,
+			this, [&]() {
+				updateCamInfo(cm_->get(
+					cameraIdComboBox_->currentText().toStdString()));
+			});
+
 		/* Setup the QDialogButton Box */
 		QDialogButtonBox *dialogButtonBox =
 			new QDialogButtonBox(QDialogButtonBox::Ok |
@@ -46,6 +60,8 @@  public:
 
 		/* Set the layout. */
 		camSelectDialogLayout->addRow("Camera: ", cameraIdComboBox_);
+		camSelectDialogLayout->addRow("Location: ", cameraLocation_);
+		camSelectDialogLayout->addRow("Model: ", cameraModel_);
 		camSelectDialogLayout->addWidget(dialogButtonBox);
 	}
 
@@ -75,9 +91,47 @@  public:
 		cameraIdComboBox_->removeItem(cameraIndex);
 	}
 
+	/* Camera Information */
+	void updateCamInfo(const std::shared_ptr<libcamera::Camera> &camera)
+	{
+		if (camera == nullptr)
+			return;
+
+		const libcamera::ControlList &cameraProperties = camera->properties();
+
+		const auto &location =
+			cameraProperties.get(libcamera::properties::Location);
+		if (location) {
+			switch (*location) {
+			case libcamera::properties::CameraLocationFront:
+				cameraLocation_->setText("Internal front camera ");
+				break;
+			case libcamera::properties::CameraLocationBack:
+				cameraLocation_->setText("Internal back camera ");
+				break;
+			case libcamera::properties::CameraLocationExternal:
+				cameraLocation_->setText("External camera ");
+				break;
+			default:
+				cameraLocation_->setText(QString());
+			}
+		} else {
+			cameraLocation_->setText(QString());
+		}
+
+		const auto &model = cameraProperties.get(libcamera::properties::Model);
+
+		if (model)
+			cameraModel_->setText(QString::fromStdString(*model));
+		else
+			cameraModel_->setText(QString());
+	}
+
 private:
 	libcamera::CameraManager *cm_;
 
 	/* UI elements. */
 	QComboBox *cameraIdComboBox_;
+	QLabel *cameraLocation_;
+	QLabel *cameraModel_;
 };