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

Utkarsh Tiwari utkarsh02t at gmail.com
Sat Aug 6 21:04:31 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>
---
 src/qcam/cam_select_dialog.h | 14 ++++++++++++++
 src/qcam/main_window.cpp     |  6 ++++++
 2 files changed, 20 insertions(+)

diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
index c23bad59..ee65eb88 100644
--- a/src/qcam/cam_select_dialog.h
+++ b/src/qcam/cam_select_dialog.h
@@ -56,6 +56,20 @@ public:
 		return cameraIdComboBox_->currentText().toStdString();
 	}
 
+	/* Hotplug / Unplug Support. */
+	void cameraAdded(libcamera::Camera *camera)
+	{
+		cameraIdComboBox_->addItem(QString::fromStdString(camera->id()));
+	}
+
+	void cameraRemoved(libcamera::Camera *camera)
+	{
+		int cameraIndex = cameraIdComboBox_->findText(
+			QString::fromStdString(camera->id()));
+
+		cameraIdComboBox_->removeItem(cameraIndex);
+	}
+
 private:
 	libcamera::CameraManager *cm_;
 
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 758e2c94..dd30817d 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -594,6 +594,9 @@ void MainWindow::processHotplug(HotplugEvent *e)
 
 	if (event == HotplugEvent::HotPlug) {
 		cameraCombo_->addItem(QString::fromStdString(camera->id()));
+
+		if (camSelectDialog_)
+			camSelectDialog_->cameraAdded(camera);
 	} else if (event == HotplugEvent::HotUnplug) {
 		/* Check if the currently-streaming camera is removed. */
 		if (camera == camera_.get()) {
@@ -605,6 +608,9 @@ void MainWindow::processHotplug(HotplugEvent *e)
 
 		int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id()));
 		cameraCombo_->removeItem(camIndex);
+
+		if (camSelectDialog_)
+			camSelectDialog_->cameraRemoved(camera);
 	}
 }
 
-- 
2.25.1



More information about the libcamera-devel mailing list