[libcamera-devel,v7,2/8] qcam: Support Hotplug for Camera Selection Dialog
diff mbox series

Message ID 20220809205042.344923-3-utkarsh02t@gmail.com
State Superseded
Headers show
Series
  • Introduce capture scripts to qcam
Related show

Commit Message

Utkarsh Tiwari Aug. 9, 2022, 8:50 p.m. UTC
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@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@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(+)

Patch
diff mbox series

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);
 	}
 }