[{"id":24364,"web_url":"https://patchwork.libcamera.org/comment/24364/","msgid":"<e399fa23-e26e-19c8-39d9-21d7b2acd133@ideasonboard.com>","date":"2022-08-04T09:22:00","subject":"Re: [libcamera-devel] [PATCH 2/4] qcam: Support Hotplug for Camera\n\tSelection Dialog","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Utkarsh\n\nThank you for the patch.\n\nOn 8/3/22 23:25, Utkarsh Tiwari via libcamera-devel wrote:\n> Currently if there is HotPlug event when the user is on the Camera\n> selection dialog, the QComboBox didn't update to reflect the change.\n>\n> If the cameraIdComboBox_ contains a valid QComboBox then update it to\n> reflect the HotPlug change. Check the validity of QComboBox pointer by\n> guarding it with a QPointer.\n>\n> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n> ---\n>   src/qcam/main_window.cpp | 23 +++++++++++++++--------\n>   src/qcam/main_window.h   |  4 ++++\n>   2 files changed, 19 insertions(+), 8 deletions(-)\n>\n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 7761a6c6..80a73b68 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -293,18 +293,15 @@ void MainWindow::switchCamera(int index)\n>   \n>   std::string MainWindow::chooseCamera()\n>   {\n> -\tQStringList cameras;\n>   \tstd::string result;\n>   \n>   \t/* Present a dialog box to pick a camera. */\n>   \tQDialog *cameraSelectDialog = new QDialog(this);\n>   \n>   \t/* Setup a QComboBox to display camera Ids. */\n> +\tcameraIdComboBox_ = new QComboBox;\n>   \tfor (const std::shared_ptr<Camera> &cam : cm_->cameras())\n> -\t\tcameras.push_back(QString::fromStdString(cam->id()));\n> -\n> -\tQComboBox *cameraIdComboBox = new QComboBox;\n> -\tcameraIdComboBox->addItems(cameras);\n> +\t\tcameraIdComboBox_->addItem(QString::fromStdString(cam->id()));\n>   \n>   \t/* Setup QDialogButtonBox. */\n>   \tQDialogButtonBox *dialogButtonBox = new QDialogButtonBox;\n> @@ -313,7 +310,7 @@ std::string MainWindow::chooseCamera()\n>   \n>   \tconnect(dialogButtonBox, &QDialogButtonBox::accepted,\n>   \t\tthis, [&]() {\n> -\t\t\tresult = cameraIdComboBox->currentText().toStdString();\n> +\t\t\tresult = cameraIdComboBox_->currentText().toStdString();\n>   \t\t\tcameraSelectDialog->accept();\n>   \t\t});\n>   \n> @@ -325,7 +322,7 @@ std::string MainWindow::chooseCamera()\n>   \n>   \t/* Setup the layout for the dialog. */\n>   \tQFormLayout *cameraSelectLayout = new QFormLayout(cameraSelectDialog);\n> -\tcameraSelectLayout->addRow(\"Camera: \", cameraIdComboBox);\n> +\tcameraSelectLayout->addRow(\"Camera: \", cameraIdComboBox_);\n>   \tcameraSelectLayout->addWidget(dialogButtonBox);\n>   \n>   \tcameraSelectDialog->exec();\n> @@ -628,7 +625,12 @@ void MainWindow::processHotplug(HotplugEvent *e)\n>   \tHotplugEvent::PlugEvent event = e->hotplugEvent();\n>   \n>   \tif (event == HotplugEvent::HotPlug) {\n> -\t\tcameraCombo_->addItem(QString::fromStdString(camera->id()));\n> +\t\tQString cameraId = QString::fromStdString(camera->id());\n> +\t\tcameraCombo_->addItem(cameraId);\n> +\n> +\t\t/* Update cameraIdCombox_ to include the new camera. */\n> +\t\tif (cameraIdComboBox_)\n> +\t\t\tcameraIdComboBox_->addItem(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> @@ -638,6 +640,11 @@ void MainWindow::processHotplug(HotplugEvent *e)\n>   \t\t\tcameraCombo_->setCurrentIndex(0);\n>   \t\t}\n>   \n> +\t\tif (cameraIdComboBox_) {\n> +\t\t\tint cameraIdIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id()));\n> +\t\t\tcameraIdComboBox_->removeItem(cameraIdIndex);\n> +\t\t}\n> +\n>   \t\tint camIndex = cameraCombo_->findText(QString::fromStdString(camera->id()));\n>   \t\tcameraCombo_->removeItem(camIndex);\n>   \t}\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index fc70920f..b8122eb9 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -23,7 +23,9 @@\n>   #include <QMainWindow>\n>   #include <QMutex>\n>   #include <QObject>\n> +#include <QPointer>\n>   #include <QQueue>\n> +#include <QStringList>\n>   #include <QTimer>\n>   \n>   #include \"../cam/stream_options.h\"\n> @@ -99,6 +101,8 @@ private:\n>   \tQString title_;\n>   \tQTimer titleTimer_;\n>   \n> +\tQPointer<QComboBox> cameraIdComboBox_;\n\n\nYou can simply start with a private cameraIdComboBox_ member in 1/4, \nrather than defining it locally, then making it private here.\n\n> +\n>   \t/* Options */\n>   \tconst OptionsParser::Options &options_;\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 0A139C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Aug 2022 09:22:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 68F566332B;\n\tThu,  4 Aug 2022 11:22:07 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 808F6603E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Aug 2022 11:22:06 +0200 (CEST)","from [IPV6:2401:4900:1f3f:fafd:9392:a984:1cd6:f7b] (unknown\n\t[IPv6:2401:4900:1f3f:fafd:9392:a984:1cd6:f7b])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8E40F481;\n\tThu,  4 Aug 2022 11:22:05 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659604927;\n\tbh=qASBnatRSJaNQe+gTNbAzgm0BmkSV2Ojk2QtU92fMWc=;\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:\n\tFrom;\n\tb=EdGH6V9P68YRxhu+vxo7CLfEOIkpLnmf3tOBH85kEoZgR+AR+atW2t6PIALS49dcZ\n\tb+GhaczPV35So/H23qtSN8WJu8AtVP31rGK89iwl5n3jbAnJvCKem/yKO2Fvdl5fh8\n\thGpkKAqrSI8UWXDzufz2nnrf1s3WSPHSsrtaw+HsRNNPv7cGWCoqQMo7VKfzBEfIfs\n\tEfph8Dvw4QiqR486rMQFJYGB1Gg70Kv+HBXs2kiZWA/y4DN2Lu/3NPmf9cwhliXFLC\n\tj4xnkP3S69eYm/wPd5/IxWJ0xNc60BnWoCMDxkUqgq9Blf14rn15O9jAdjO0hQMK+p\n\tW8vfVBe0q0SXg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659604926;\n\tbh=qASBnatRSJaNQe+gTNbAzgm0BmkSV2Ojk2QtU92fMWc=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=nqUeV9tUFRw7zqYERNFEC33NiZI2ar3qpg7N/aTcHW50Lb58zAfwFWN3jbrsEmogR\n\tcMqXDczrY0qRvfFYBiyVvpjtWrEyGXupQbYk5CBNZpQPDEEVtjK1aoLPxDr7l5Q2Zh\n\tGoV5T9ogE+2ddNxgrsW8OQZajm08jpMnjR5+x5yg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"nqUeV9tU\"; dkim-atps=neutral","Message-ID":"<e399fa23-e26e-19c8-39d9-21d7b2acd133@ideasonboard.com>","Date":"Thu, 4 Aug 2022 14:52:00 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Utkarsh Tiwari <utkarsh02t@gmail.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220803175517.175332-1-utkarsh02t@gmail.com>\n\t<20220803175517.175332-3-utkarsh02t@gmail.com>","In-Reply-To":"<20220803175517.175332-3-utkarsh02t@gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 2/4] qcam: Support Hotplug for Camera\n\tSelection 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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]