[{"id":24851,"web_url":"https://patchwork.libcamera.org/comment/24851/","msgid":"<Yw8lCAq2L/H2VdqM@pendragon.ideasonboard.com>","date":"2022-08-31T09:08:24","subject":"Re: [libcamera-devel] [PATCH v9 2/7] qcam: Support Hotplug for\n\tCamera Selection Dialog","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Utkarsh,\n\nThank you for the patch.\n\nOn Wed, Aug 31, 2022 at 11:19:33AM +0530, Utkarsh Tiwari wrote:\n> Currently if there is HotPlug event when the user is on the Camera\n> selection dialog, the QComboBox doesn't update to reflect the change.\n> \n> Add support for hotplugging / unplugging cameras.\n> \n> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Difference from v8:\n>     1. Removed the part about QPointer from commit message, no longer\n>     needed.\n>     2. s/didn't/doesn't commit msg.\n>     3. Rename cameraRemoved to removeCamera and cameraAdded to addCamera\n>     4. Pass QString to cameraRemoved, cameraAdded instead of libcamera::Camera\n>     5. Removed blank line between cameraAdded, cameraRemoved\n>     6. Optimize cameraId passing cameraCombo_ , cameraAdded,\n>     cameraRemoved.\n>  src/qcam/cam_select_dialog.cpp | 12 ++++++++++++\n>  src/qcam/cam_select_dialog.h   |  5 +++++\n>  src/qcam/main_window.cpp       |  7 +++++--\n>  3 files changed, 22 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp\n> index a49d822b..f82930cc 100644\n> --- a/src/qcam/cam_select_dialog.cpp\n> +++ b/src/qcam/cam_select_dialog.cpp\n> @@ -48,3 +48,15 @@ std::string CameraSelectorDialog::getCameraId()\n>  {\n>  \treturn cameraIdComboBox_->currentText().toStdString();\n>  }\n> +\n> +/* Hotplug / Unplug Support. */\n> +void CameraSelectorDialog::addCamera(QString camearaId)\n\ns/camearaId/cameraId/\n\n> +{\n> +\tcameraIdComboBox_->addItem(camearaId);\n> +}\n> +\n> +void CameraSelectorDialog::removeCamera(QString cameraId)\n> +{\n> +\tint cameraIndex = cameraIdComboBox_->findText(cameraId);\n> +\tcameraIdComboBox_->removeItem(cameraIndex);\n> +}\n> diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h\n> index c31f4f82..bd2dbc1e 100644\n> --- a/src/qcam/cam_select_dialog.h\n> +++ b/src/qcam/cam_select_dialog.h\n> @@ -13,6 +13,7 @@\n>  #include <libcamera/camera_manager.h>\n>  \n>  #include <QDialog>\n> +#include <QString>\n>  \n>  class QComboBox;\n>  \n> @@ -27,6 +28,10 @@ public:\n>  \n>  \tstd::string getCameraId();\n>  \n> +\t/* Hotplug / Unplug Support. */\n> +\tvoid addCamera(QString cameraId);\n> +\tvoid removeCamera(QString cameraId);\n> +\n>  private:\n>  \tlibcamera::CameraManager *cm_;\n>  \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 14bcf03e..e8e22d49 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -587,10 +587,12 @@ void MainWindow::stopCapture()\n>  void MainWindow::processHotplug(HotplugEvent *e)\n>  {\n>  \tCamera *camera = e->camera();\n> +\tQString cameraId = QString::fromStdString(camera->id());\n>  \tHotplugEvent::PlugEvent event = e->hotplugEvent();\n>  \n>  \tif (event == HotplugEvent::HotPlug) {\n> -\t\tcameraCombo_->addItem(QString::fromStdString(camera->id()));\n> +\t\tcameraCombo_->addItem(cameraId);\n> +\t\tcameraSelectorDialog_->addCamera(cameraId);\n>  \t} else if (event == HotplugEvent::HotUnplug) {\n>  \t\t/* Check if the currently-streaming camera is removed. */\n>  \t\tif (camera == camera_.get()) {\n> @@ -600,8 +602,9 @@ void MainWindow::processHotplug(HotplugEvent *e)\n>  \t\t\tcameraCombo_->setCurrentIndex(0);\n>  \t\t}\n>  \n> -\t\tint camIndex = cameraCombo_->findText(QString::fromStdString(camera->id()));\n> +\t\tint camIndex = cameraCombo_->findText(cameraId);\n>  \t\tcameraCombo_->removeItem(camIndex);\n> +\t\tcameraSelectorDialog_->removeCamera(cameraId);\n>  \t}\n>  }\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 26FF7C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Aug 2022 09:08:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8C2FF61FBE;\n\tWed, 31 Aug 2022 11:08:37 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 923AE603E1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Aug 2022 11:08:36 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CB16D481;\n\tWed, 31 Aug 2022 11:08:35 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661936917;\n\tbh=tnHEN2IY5EBIh0rPbfokyUXhQU7bdtJIVfuM5m2uuOI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=NwHwFBZROg1Me13aWDzR4lTMvmcQTxXunS8lACzvWBOLffPuWAYdgod1hENYmsNkg\n\tBfzArn0sFNe03asyeKxisqPRJ9oqHR+doC8ZWheqnkklzqOedRnhphRXjUtlucmajl\n\tWrGJ2WqE2AfBw8VZUBvYsOKGxxzCEatPGtIfIoPdsVT91eIXGTNHa8YPJ5YTXjs0On\n\tY2yLpoO+W4pu1vx1nyPL/o8C3HfxbZ4USQaQVj7fQWXLQyZ++3JJCBxXeCm8H9docv\n\tyY59JqUm28YNnIQHhoLmEnK5eLZwZ6j5yyxcsZDt/OcqV7/DmzOMhBdRdnloJrUqa6\n\th0OZ/J5ccmkbQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661936916;\n\tbh=tnHEN2IY5EBIh0rPbfokyUXhQU7bdtJIVfuM5m2uuOI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=SpW8+I9dOfbTBfCN6C75WuInomGZc+7uT0+RYtra6k7Tgm5db77Kvy9G8uBzZFu5e\n\ttW0+YfU0tlGmG+++IuTjiH6bfkxzaEJM94sqLhtsldAINfcD2RzABjHdSu8OEfidS6\n\tRgGopVM6B3PO9W7vBXMkWjy7eo5yYlvRAqrohtrM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"SpW8+I9d\"; dkim-atps=neutral","Date":"Wed, 31 Aug 2022 12:08:24 +0300","To":"Utkarsh Tiwari <utkarsh02t@gmail.com>","Message-ID":"<Yw8lCAq2L/H2VdqM@pendragon.ideasonboard.com>","References":"<20220831054938.21617-1-utkarsh02t@gmail.com>\n\t<20220831054938.21617-3-utkarsh02t@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220831054938.21617-3-utkarsh02t@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v9 2/7] qcam: Support Hotplug for\n\tCamera Selection Dialog","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]