[libcamera-devel] [PATCH v7 2/8] qcam: Support Hotplug for Camera Selection Dialog

Utkarsh Tiwari utkarsh02t at gmail.com
Tue Aug 9 22:50:36 CEST 2022


Currently if there is HotPlug event when the user is on the Camera
selection dialog, the QComboBox didn't update to reflect the change.

If the QDialog exists then alert it for the Hotplug event. The check
for QDialog existance is done by QPointer.

Signed-off-by: Utkarsh Tiwari <utkarsh02t at gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
Difference:
	1. Moved functions implementation to its own .cpp
 src/qcam/cam_select_dialog.cpp | 14 ++++++++++++++
 src/qcam/cam_select_dialog.h   |  4 ++++
 src/qcam/main_window.cpp       |  4 ++++
 3 files changed, 22 insertions(+)

diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp
index dceaa590..d8982800 100644
--- a/src/qcam/cam_select_dialog.cpp
+++ b/src/qcam/cam_select_dialog.cpp
@@ -49,3 +49,17 @@ std::string CameraSelectorDialog::getCameraId()
 {
 	return cameraIdComboBox_->currentText().toStdString();
 }
+
+/* Hotplug / Unplug Support. */
+void CameraSelectorDialog::cameraAdded(libcamera::Camera *camera)
+{
+	cameraIdComboBox_->addItem(QString::fromStdString(camera->id()));
+}
+
+void CameraSelectorDialog::cameraRemoved(libcamera::Camera *camera)
+{
+	int cameraIndex = cameraIdComboBox_->findText(
+		QString::fromStdString(camera->id()));
+
+	cameraIdComboBox_->removeItem(cameraIndex);
+}
diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
index 8e54f916..567083ae 100644
--- a/src/qcam/cam_select_dialog.h
+++ b/src/qcam/cam_select_dialog.h
@@ -29,6 +29,10 @@ public:
 
 	std::string getCameraId();
 
+	/* Hotplug / Unplug Support. */
+	void cameraAdded(libcamera::Camera *camera);
+
+	void cameraRemoved(libcamera::Camera *camera);
 private:
 	libcamera::CameraManager *cm_;
 
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 48479f35..377b4650 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -593,6 +593,8 @@ void MainWindow::processHotplug(HotplugEvent *e)
 
 	if (event == HotplugEvent::HotPlug) {
 		cameraCombo_->addItem(QString::fromStdString(camera->id()));
+
+		cameraSelectorDialog_->cameraAdded(camera);
 	} else if (event == HotplugEvent::HotUnplug) {
 		/* Check if the currently-streaming camera is removed. */
 		if (camera == camera_.get()) {
@@ -604,6 +606,8 @@ void MainWindow::processHotplug(HotplugEvent *e)
 
 		int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id()));
 		cameraCombo_->removeItem(camIndex);
+
+		cameraSelectorDialog_->cameraRemoved(camera);
 	}
 }
 
-- 
2.25.1



More information about the libcamera-devel mailing list