[{"id":24740,"web_url":"https://patchwork.libcamera.org/comment/24740/","msgid":"<YwQ1RAdE5tBMLAgp@pendragon.ideasonboard.com>","date":"2022-08-23T02:02:44","subject":"Re: [libcamera-devel] [PATCH v8 3/8] qcam: MainWindow: Replace\n\tcameraCombo_ with CameraSelectorDialog","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 10, 2022 at 08:33:44PM +0530, Utkarsh Tiwari via libcamera-devel wrote:\n> Replace the cameraCombo_ on the toolbar with a QPushButton which\n> displays the CameraSelectorDialog. This would allow the user to view\n> information about the camera when switching.\n> \n> The QPushButton text is set to the camera Id currently in use.\n> \n> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n> Difference from v7:\n> \t1. Moved firstCameraSelect_ from 8/8 to here because if we were previously\n> \t\tsupplied camera id on the cmdline we always used that and sdisabled the\n> \t\tshowing of the dialog\n>  src/qcam/main_window.cpp | 51 ++++++++++++++++++++--------------------\n>  src/qcam/main_window.h   |  6 +++--\n>  2 files changed, 30 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 9ec94708..d1b8d2dd 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -98,7 +98,8 @@ private:\n>  \n>  MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n>  \t: saveRaw_(nullptr), cameraSelectorDialog_(nullptr), options_(options),\n> -\t  cm_(cm), allocator_(nullptr), isCapturing_(false), captureRaw_(false)\n> +\t  cm_(cm), allocator_(nullptr), isCapturing_(false), captureRaw_(false),\n> +\t  firstCameraSelect_(true)\n>  {\n>  \tint ret;\n>  \n> @@ -193,14 +194,11 @@ int MainWindow::createToolbars()\n>  \tconnect(action, &QAction::triggered, this, &MainWindow::quit);\n>  \n>  \t/* Camera selector. */\n> -\tcameraCombo_ = new QComboBox();\n> -\tconnect(cameraCombo_, QOverload<int>::of(&QComboBox::activated),\n> +\tcameraSelectButton_ = new QPushButton;\n> +\tconnect(cameraSelectButton_, &QPushButton::clicked,\n>  \t\tthis, &MainWindow::switchCamera);\n>  \n> -\tfor (const std::shared_ptr<Camera> &cam : cm_->cameras())\n> -\t\tcameraCombo_->addItem(QString::fromStdString(cam->id()));\n> -\n> -\ttoolbar_->addWidget(cameraCombo_);\n> +\ttoolbar_->addWidget(cameraSelectButton_);\n>  \n>  \ttoolbar_->addSeparator();\n>  \n> @@ -260,14 +258,18 @@ void MainWindow::updateTitle()\n>   * Camera Selection\n>   */\n>  \n> -void MainWindow::switchCamera(int index)\n> +void MainWindow::switchCamera()\n>  {\n>  \t/* Get and acquire the new camera. */\n> -\tconst auto &cameras = cm_->cameras();\n> -\tif (static_cast<unsigned int>(index) >= cameras.size())\n> +\tstd::string newCameraId = chooseCamera();\n> +\n> +\tif (newCameraId.empty())\n>  \t\treturn;\n>  \n> -\tconst std::shared_ptr<Camera> &cam = cameras[index];\n> +\tif (camera_ && newCameraId == camera_->id())\n> +\t\treturn;\n> +\n> +\tconst std::shared_ptr<Camera> &cam = cm_->get(newCameraId);\n>  \n>  \tif (cam->acquire()) {\n>  \t\tqInfo() << \"Failed to acquire camera\" << cam->id().c_str();\n> @@ -298,12 +300,17 @@ std::string MainWindow::chooseCamera()\n>  \t * Use the camera specified on the command line, if any, or display the\n>  \t * camera selection dialog box otherwise.\n>  \t */\n> -\tif (options_.isSet(OptCamera))\n> +\tif (firstCameraSelect_ && options_.isSet(OptCamera)) {\n> +\t\tfirstCameraSelect_ = false;\n>  \t\treturn static_cast<std::string>(options_[OptCamera]);\n> +\t}\n\nHow about moving this to MainWindow::openCamera() (in patch 1/8) ? You\ncould then drop the firstCameraSelect_ variable.\n\n>  \n> -\tif (cameraSelectorDialog_->exec() == QDialog::Accepted)\n> -\t\treturn cameraSelectorDialog_->getCameraId();\n> -\telse\n> +\tif (cameraSelectorDialog_->exec() == QDialog::Accepted) {\n> +\t\tstd::string cameraId = cameraSelectorDialog_->getCameraId();\n> +\t\tcameraSelectButton_->setText(QString::fromStdString(cameraId));\n> +\n> +\t\treturn cameraId;\n> +\t} else\n>  \t\treturn std::string();\n\nYou need curly braces around this too as per our coding style. Another\noption would be\n\n\tif (cameraSelectorDialog_->exec() != QDialog::Accepted)\n\t\treturn std::string();\n\n\tstd::string cameraId = cameraSelectorDialog_->getCameraId();\n\tcameraSelectButton_->setText(QString::fromStdString(cameraId));\n\n\treturn cameraId;\n\nwhich I think looks nicer, but it's up to you.\n\nThis being said, I would move the setText() call to\nMainWindow::switchCamera() as you need a setText() in\nMainWindow::openCamera() to handle the first open.\n\n>  }\n>  \n> @@ -327,8 +334,8 @@ int MainWindow::openCamera()\n>  \t\treturn -EBUSY;\n>  \t}\n>  \n> -\t/* Set the combo-box entry with the currently selected Camera. */\n> -\tcameraCombo_->setCurrentText(QString::fromStdString(cameraName));\n> +\t/* Set the camera switch button with the currently selected Camera id. */\n> +\tcameraSelectButton_->setText(QString::fromStdString(cameraName));\n>  \n>  \treturn 0;\n>  }\n> @@ -592,22 +599,16 @@ void MainWindow::processHotplug(HotplugEvent *e)\n>  \tCamera *camera = e->camera();\n>  \tHotplugEvent::PlugEvent event = e->hotplugEvent();\n>  \n> -\tif (event == HotplugEvent::HotPlug) {\n> -\t\tcameraCombo_->addItem(QString::fromStdString(camera->id()));\n> -\n> +\tif (event == HotplugEvent::HotPlug)\n>  \t\tcameraSelectorDialog_->cameraAdded(camera);\n\nPlease keep the curly braces, we require then for all branches of an if,\nor for none of them.\n\n> -\t} else if (event == HotplugEvent::HotUnplug) {\n> +\telse if (event == HotplugEvent::HotUnplug) {\n>  \t\t/* Check if the currently-streaming camera is removed. */\n>  \t\tif (camera == camera_.get()) {\n>  \t\t\ttoggleCapture(false);\n>  \t\t\tcamera_->release();\n>  \t\t\tcamera_.reset();\n> -\t\t\tcameraCombo_->setCurrentIndex(0);\n>  \t\t}\n>  \n> -\t\tint camIndex = cameraCombo_->findText(QString::fromStdString(camera->id()));\n> -\t\tcameraCombo_->removeItem(camIndex);\n> -\n>  \t\tcameraSelectorDialog_->cameraRemoved(camera);\n>  \t}\n>  }\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index 4ad5e6e9..f9ea8bd3 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -23,6 +23,7 @@\n>  #include <QMainWindow>\n>  #include <QMutex>\n>  #include <QObject>\n> +#include <QPushButton>\n\nYou can also drop the QComboBox above.\n\nWith those changes,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  #include <QQueue>\n>  #include <QTimer>\n>  \n> @@ -60,7 +61,7 @@ private Q_SLOTS:\n>  \tvoid quit();\n>  \tvoid updateTitle();\n>  \n> -\tvoid switchCamera(int index);\n> +\tvoid switchCamera();\n>  \tvoid toggleCapture(bool start);\n>  \n>  \tvoid saveImageAs();\n> @@ -90,7 +91,7 @@ private:\n>  \t/* UI elements */\n>  \tQToolBar *toolbar_;\n>  \tQAction *startStopAction_;\n> -\tQComboBox *cameraCombo_;\n> +\tQPushButton *cameraSelectButton_;\n>  \tQAction *saveRaw_;\n>  \tViewFinder *viewfinder_;\n>  \n> @@ -116,6 +117,7 @@ private:\n>  \t/* Capture state, buffers queue and statistics */\n>  \tbool isCapturing_;\n>  \tbool captureRaw_;\n> +\tbool firstCameraSelect_;\n>  \tlibcamera::Stream *vfStream_;\n>  \tlibcamera::Stream *rawStream_;\n>  \tstd::map<const libcamera::Stream *, QQueue<libcamera::FrameBuffer *>> freeBuffers_;","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 9B6C1C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Aug 2022 02:02:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F1A8961FC0;\n\tTue, 23 Aug 2022 04:02:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F1E260E25\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Aug 2022 04:02:49 +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 90F2E2B3;\n\tTue, 23 Aug 2022 04:02:48 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661220171;\n\tbh=+wT38vJzhYKJis4tFFRbpJjnJRuqCT6bj57NBs7yK2I=;\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=mf1Np/meCJCoPbSCKJFDgsr14JtJq2DCkcURQ8ZBA1Vjv9X6iNVHMQSaPSjvL8Zdx\n\tuKH/2E5s23j4ag740Ww39xCMJnUDIU8Vq0xOBAZethlWiF88RiJ02XvLbi/dj0Ipl9\n\tupuOD5yA4g9UONW4MJmparKM9E/rOF38m3waevMoL7uTKu2uSjvEo4FPtoLh/f2rsE\n\tF1xVIiCSEWGShZCT3v+TBw5jV366V3lrXU5V7YF6NWL4mzmR/zZXC1GtX4nAs7Z2Bw\n\twrEZWbNxaUzzi3Zzz1tSQ3AlXFbPnhpQbQ7vEcTc/xCsMY8byj36W+6dIWP+7VyU1a\n\tgyN6YOQDPaBGw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661220168;\n\tbh=+wT38vJzhYKJis4tFFRbpJjnJRuqCT6bj57NBs7yK2I=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Hq7Q/yYW1fHh0qaM5fvbahqi21PVT8++CeYCoX/V16x2/jlMu2c5Mld4Uy4Oc1/wp\n\twT75m4q8MRRg20gwisyKSc5dnmGIVFzsD+fmYuBEMjKk2sRnfVsDEq+snUNWdrXN92\n\tH3culbWhzsmkyuJ81aHh3gz+K056/fbVpkwoKH5g="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Hq7Q/yYW\"; dkim-atps=neutral","Date":"Tue, 23 Aug 2022 05:02:44 +0300","To":"Utkarsh Tiwari <utkarsh02t@gmail.com>","Message-ID":"<YwQ1RAdE5tBMLAgp@pendragon.ideasonboard.com>","References":"<20220810150349.414043-1-utkarsh02t@gmail.com>\n\t<20220810150349.414043-4-utkarsh02t@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220810150349.414043-4-utkarsh02t@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v8 3/8] qcam: MainWindow: Replace\n\tcameraCombo_ with CameraSelectorDialog","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>"}}]