[{"id":2958,"web_url":"https://patchwork.libcamera.org/comment/2958/","msgid":"<20191025104035.GA4740@pendragon.ideasonboard.com>","date":"2019-10-25T10:40:35","subject":"Re: [libcamera-devel] [PATCH] qcam: Don't ask for a camera when\n\tonly one exists","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Fri, Oct 25, 2019 at 11:35:43AM +0100, Kieran Bingham wrote:\n> If there is only one camera exposed by libcamera, there is little value\n> in asking the user to choose it.\n> \n> Automatically select it, and remove the need to ask the user to select\n> 'ok' from a Dialog box.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/qcam/main_window.cpp | 33 +++++++++++++++++++++++----------\n>  src/qcam/main_window.h   |  1 +\n>  2 files changed, 24 insertions(+), 10 deletions(-)\n> \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index ef4ad4a22dca..19a8801eafac 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -66,27 +66,40 @@ void MainWindow::updateTitle()\n>  \tsetWindowTitle(title_ + \" : \" + QString::number(fps, 'f', 2) + \" fps\");\n>  }\n>  \n> -int MainWindow::openCamera(CameraManager *cm)\n> +std::string MainWindow::chooseCamera(CameraManager *cm)\n>  {\n> -\tstd::string cameraName;\n> +\tQString name;\n> +\tbool result;\n>  \n> -\tif (!options_.isSet(OptCamera)) {\n> +\tif (cm->cameras().size() == 1)\n> +\t\treturn cm->cameras()[0]->name();\n> +\n> +\tfor (const std::shared_ptr<Camera> &cam : cm->cameras()) {\n>  \t\tQStringList cameras;\n> -\t\tbool result;\n>  \n> -\t\tfor (const std::shared_ptr<Camera> &cam : cm->cameras())\n> -\t\t\tcameras.append(QString::fromStdString(cam->name()));\n> +\t\tcameras.append(QString::fromStdString(cam->name()));\n>  \n>  \t\tQString name = QInputDialog::getItem(this, \"Select Camera\",\n>  \t\t\t\t\t\t     \"Camera:\", cameras, 0,\n>  \t\t\t\t\t\t     false, &result);\n\nShouldn't this be outside of the for loop ?\n\n>  \t\tif (!result)\n> -\t\t\treturn -EINVAL;\n> +\t\t\treturn \"\";\n\nYou can return std::string() to avoid the conversion from const char *.\n\nApart from that,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t}\n>  \n> -\t\tcameraName = name.toStdString();\n> -\t} else {\n> +\treturn name.toStdString();\n> +}\n> +\n> +int MainWindow::openCamera(CameraManager *cm)\n> +{\n> +\tstd::string cameraName;\n> +\n> +\tif (options_.isSet(OptCamera))\n>  \t\tcameraName = static_cast<std::string>(options_[OptCamera]);\n> -\t}\n> +\telse\n> +\t\tcameraName = chooseCamera(cm);\n> +\n> +\tif (cameraName == \"\")\n> +\t\treturn -EINVAL;\n>  \n>  \tcamera_ = cm->get(cameraName);\n>  \tif (!camera_) {\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index 6873155aaa03..30dd8743104d 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -43,6 +43,7 @@ private Q_SLOTS:\n>  \tvoid updateTitle();\n>  \n>  private:\n> +\tstd::string chooseCamera(CameraManager *cm);\n>  \tint openCamera(CameraManager *cm);\n>  \n>  \tint startCapture();","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 E5E7E61378\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Oct 2019 12:40:42 +0200 (CEST)","from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net\n\t[93.2.121.143])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6CC8733A;\n\tFri, 25 Oct 2019 12:40:42 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1572000042;\n\tbh=7aqijVh5VZWnGPKdnN4GBJ8mfuBISK3Nxl8kIfKHbK0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L04+36t4dLgxlAGvsWu7PN4geE4D+UNm7wvYUIArKQN7ByCxHD6zl5oZu3bbf7ioC\n\tXoz7Y0UNcCnFblRhmp2b1L4bBtN/kMkXMBesgN4NtKmg59sSsROr7pugUDx+m1SUiR\n\tmiEQg2n7zRqPd8vt+C53lmJf7lz4yLaPo2aJe2d0=","Date":"Fri, 25 Oct 2019 13:40:35 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20191025104035.GA4740@pendragon.ideasonboard.com>","References":"<20191025103543.23058-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191025103543.23058-1-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] qcam: Don't ask for a camera when\n\tonly one exists","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>","X-List-Received-Date":"Fri, 25 Oct 2019 10:40:43 -0000"}}]