From patchwork Wed Aug 10 15:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17067 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 21D7CC3272 for ; Wed, 10 Aug 2022 15:04:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D092063330; Wed, 10 Aug 2022 17:04:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660143841; bh=k1ygg5cAr3MHmyh7/K9n38RIh+/ZsJClzfGBFmKNHc4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iG9YSM2B7HetCGoqsi0rRCS/qf9b2G2wpIAeoVPSU2qQ49agzydpLOJeoypovra4t LSTNVUVPg/gIA/H00IQirEbqIirJU5hVkZbkLpNOawppDeklcy+xhSRwFeNFSnk3mh lRdCe6I0kuUEeU6PPqFm1C3KShgGLzPvF7rbBUqNpGof/Hhiwx22RZyvPhdfD8eyi2 2Z6+zgtodpgnCX4lb+iwW+Uv+rnKssVs91wPXczC7hHWZKbnLHrd6biasFbDOcrDss FXqqhvlWvLv08jX1Q1msVicb5DIawAc/57/eMjyFaPfMFidw1ZnLjPkmBdvSz4sVWu plyIjyK160dsw== Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B5676332C for ; Wed, 10 Aug 2022 17:03:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ROzwz1dA"; dkim-atps=neutral Received: by mail-pg1-x530.google.com with SMTP id l64so14641199pge.0 for ; Wed, 10 Aug 2022 08:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=nTSKjqEoOIkLDAJNk+hwruS61OgtqBGKbBboEl9JhZc=; b=ROzwz1dAwnOLN/DuOGoH9imuw7ta3Xl7c0V167yOz5Us0ZdeJTzOtDrdq83boBXzcV BDgr59DAYxWmfWar04ked6E2+3MNLU8bvnQ2wuw8x/q95+pXjuXee+szhW7Zo6QKYBKO iSHGB+UKBiNlbadBfNRqVUmCO0V9f4k6FEebwo4ZiQIPTYbkZ48ZPZvyd0a8uomwAd/+ 54bK3fDG9vZOAyWEH1xvbnCCPGFFNqBVqYfSo50UGe+BUE6ZXRS5owrB5UDFm59V0DdW oRY3mfMfTbq4Uo5Mcj3qsnRY13Q4jvjwFtPoMnY5NqMYjVfQsyqb2U0a19zweM09hb9V 7gag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=nTSKjqEoOIkLDAJNk+hwruS61OgtqBGKbBboEl9JhZc=; b=polQDav8Oj6QU2ILIQFx2Kims9v4SabXMcCDbi0dpgP8dSTegQEyY6lYEqMpjed7Xw vWmVQyE++dkinxQJv+VoQWgTE8DwmdkTpoqsJ9sLOArLmFMS/JXbAOXKC5pEX7jimhkk Pf32NTkrOC3W/K7b+wpm0bocOrgZCDiqhbDj4K5OKlyUrXc2IJ9mhB1VBXYjoGkZEGxd SNcgiC6QlgFBFAY3KKg9nmRzjrY73p6ScLrDJoN4NCdDC/qBGCUVw9HbKgG2tzHYa1Df aKV20Gmey8FZY2MsvePKrVgSFsK69jwHxIrBwueBibmHf22n4Yn1w6BrCv2oYBCshiFl Szsw== X-Gm-Message-State: ACgBeo3JxerEu6WJYr4sPDP+YyCTivvYq77cQO1jTshYjvtPnbNjZjkn YxXzITCbnL2csXBYCYWfNVSS2efPvUI= X-Google-Smtp-Source: AA6agR4utrwDXyXtJVov/NkofvwP2GWKIqT5Y3NCZNtfb+FZJZMQJo43ARjsL94S5fC/0y23FiTUdQ== X-Received: by 2002:a05:6a00:cc1:b0:52d:a29d:fb1 with SMTP id b1-20020a056a000cc100b0052da29d0fb1mr27805499pfv.56.1660143837456; Wed, 10 Aug 2022 08:03:57 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d2bc:2a55:4cae:bf8f:f4ed]) by smtp.gmail.com with ESMTPSA id b3-20020a1709027e0300b0016f1319d2a7sm12882624plm.297.2022.08.10.08.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 08:03:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Aug 2022 20:33:42 +0530 Message-Id: <20220810150349.414043-2-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810150349.414043-1-utkarsh02t@gmail.com> References: <20220810150349.414043-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 1/8] qcam: Use QDialog for selection of cameras at startup X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Utkarsh Tiwari via libcamera-devel From: Utkarsh Tiwari Reply-To: Utkarsh Tiwari Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Currently we use QInputDialog convenience dialogs to allow the user to select a camera. This doesn't allow adding of more information (such as camera location, model etc). Create a QDialog with a QFormLayout that shows a QComboBox with camera Ids. Use a QDialogButtonBox to provide buttons for accepting and cancelling the action. The CameraSelectorDialog is only initialized the first time when the MainWindow is created. From this commit we cease to auto select the camera if only a single camera is available to libcamera. We would always display the selection dialog with the exception being that being if the camera is supplied by the console. Signed-off-by: Utkarsh Tiwari Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Difference from v7: 1. Updated the commit message to inform of the behavioural change in selecting the first camera. src/qcam/cam_select_dialog.cpp | 51 ++++++++++++++++++++++++++++++++++ src/qcam/cam_select_dialog.h | 34 +++++++++++++++++++++++ src/qcam/main_window.cpp | 44 +++++++++++------------------ src/qcam/main_window.h | 3 ++ src/qcam/meson.build | 2 ++ 5 files changed, 106 insertions(+), 28 deletions(-) create mode 100644 src/qcam/cam_select_dialog.cpp create mode 100644 src/qcam/cam_select_dialog.h diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp new file mode 100644 index 00000000..dceaa590 --- /dev/null +++ b/src/qcam/cam_select_dialog.cpp @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Utkarsh Tiwari + * + * cam_select_dialog.cpp - qcam - Camera Selection dialog + */ + +#include "cam_select_dialog.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManager, + QWidget *parent) + : QDialog(parent), cm_(cameraManager) +{ + /* Use a QFormLayout for the dialog. */ + QFormLayout *layout = new QFormLayout(this); + + /* Setup the camera id combo-box. */ + cameraIdComboBox_ = new QComboBox; + for (const auto &cam : cm_->cameras()) + cameraIdComboBox_->addItem(QString::fromStdString(cam->id())); + + /* Setup the QDialogButton Box */ + QDialogButtonBox *buttonBox = + new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + + connect(buttonBox, &QDialogButtonBox::accepted, + this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, + this, &QDialog::reject); + + /* Set the layout. */ + layout->addRow("Camera:", cameraIdComboBox_); + layout->addWidget(buttonBox); +} + +std::string CameraSelectorDialog::getCameraId() +{ + return cameraIdComboBox_->currentText().toStdString(); +} diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h new file mode 100644 index 00000000..5544f49a --- /dev/null +++ b/src/qcam/cam_select_dialog.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Utkarsh Tiwari + * + * cam_select_dialog.h - qcam - Camera Selection dialog + */ + +#pragma once + +#include + +#include +#include + +#include +#include + +class CameraSelectorDialog : public QDialog +{ + Q_OBJECT +public: + CameraSelectorDialog(libcamera::CameraManager *cameraManager, + QWidget *parent); + + ~CameraSelectorDialog() = default; + + std::string getCameraId(); + +private: + libcamera::CameraManager *cm_; + + /* UI elements. */ + QComboBox *cameraIdComboBox_; +}; diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7433d647..e794221a 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include "../cam/image.h" +#include "cam_select_dialog.h" #include "dng_writer.h" #ifndef QT_NO_OPENGL #include "viewfinder_gl.h" @@ -97,8 +97,8 @@ private: }; MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) - : saveRaw_(nullptr), options_(options), cm_(cm), allocator_(nullptr), - isCapturing_(false), captureRaw_(false) + : saveRaw_(nullptr), cameraSelectorDialog_(nullptr), options_(options), + cm_(cm), allocator_(nullptr), isCapturing_(false), captureRaw_(false) { int ret; @@ -290,38 +290,26 @@ void MainWindow::switchCamera(int index) std::string MainWindow::chooseCamera() { - QStringList cameras; - bool result; - - /* If only one camera is available, use it automatically. */ - if (cm_->cameras().size() == 1) - return cm_->cameras()[0]->id(); - - /* Present a dialog box to pick a camera. */ - for (const std::shared_ptr &cam : cm_->cameras()) - cameras.append(QString::fromStdString(cam->id())); - - QString id = QInputDialog::getItem(this, "Select Camera", - "Camera:", cameras, 0, - false, &result); - if (!result) - return std::string(); - - return id.toStdString(); -} - -int MainWindow::openCamera() -{ - std::string cameraName; + /* Construct the selection dialog, only the first time. */ + if (!cameraSelectorDialog_) + cameraSelectorDialog_ = new CameraSelectorDialog(cm_, this); /* * Use the camera specified on the command line, if any, or display the * camera selection dialog box otherwise. */ if (options_.isSet(OptCamera)) - cameraName = static_cast(options_[OptCamera]); + return static_cast(options_[OptCamera]); + + if (cameraSelectorDialog_->exec() == QDialog::Accepted) + return cameraSelectorDialog_->getCameraId(); else - cameraName = chooseCamera(); + return std::string(); +} + +int MainWindow::openCamera() +{ + std::string cameraName = chooseCamera(); if (cameraName == "") return -EINVAL; diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index fc70920f..4ad5e6e9 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -28,6 +28,7 @@ #include "../cam/stream_options.h" +#include "cam_select_dialog.h" #include "viewfinder.h" class QAction; @@ -99,6 +100,8 @@ private: QString title_; QTimer titleTimer_; + CameraSelectorDialog *cameraSelectorDialog_; + /* Options */ const OptionsParser::Options &options_; diff --git a/src/qcam/meson.build b/src/qcam/meson.build index c46f4631..61861ea6 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -18,6 +18,7 @@ qcam_sources = files([ '../cam/image.cpp', '../cam/options.cpp', '../cam/stream_options.cpp', + 'cam_select_dialog.cpp', 'format_converter.cpp', 'main.cpp', 'main_window.cpp', @@ -26,6 +27,7 @@ qcam_sources = files([ ]) qcam_moc_headers = files([ + 'cam_select_dialog.h', 'main_window.h', 'viewfinder_qt.h', ])