From patchwork Fri Oct 25 11:02:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 2219 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0DDA61378 for ; Fri, 25 Oct 2019 13:02:28 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 56C2E33A; Fri, 25 Oct 2019 13:02:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572001348; bh=9ga87JOwdahmqd8pYF/fVRL7KeQ1unYNRpSuMLfjqtM=; h=From:To:Cc:Subject:Date:From; b=vUe6EJSrSYjins5kDAJgDmTxfh3bXuQzEnBHmOJGQ8uZ8Q/akK2nEq2zPn816NEyR sU8sKIIc35jg8b92sk/RsoWRDDc2r7MzJH0Pv3RMwZTulxAMEeSivCnuT8GSxhpSdd F/Arck7+DMwOq+W4g7hsVpK+T2wE5jCP7plWtUr4= From: Kieran Bingham To: LibCamera Devel Date: Fri, 25 Oct 2019 12:02:24 +0100 Message-Id: <20191025110224.25604-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] qcam: Don't ask for a camera when only one exists 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-List-Received-Date: Fri, 25 Oct 2019 11:02:29 -0000 If there is only one camera exposed by libcamera, there is little value in asking the user to choose it. Automatically select it, and remove the need to ask the user to select 'ok' from a Dialog box. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- v2: - I have no idea what (or rather why) I screwed up the preivous but it was very wrong. - I think I saw the loop and for some reason thought I copy/pasted it wrong and it was supposed to contain the whole block - so I (erroneously) expanded the scope of the loop.. Ooops. I'll go back to sleep. - This one works and is tested on a single, and multiple cameras ;-D --- src/qcam/main_window.cpp | 40 +++++++++++++++++++++++++--------------- src/qcam/main_window.h | 1 + 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index ef4ad4a22dca..3d5630922723 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -66,27 +66,37 @@ void MainWindow::updateTitle() setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps"); } -int MainWindow::openCamera(CameraManager *cm) +std::string MainWindow::chooseCamera(CameraManager *cm) { - std::string cameraName; + QStringList cameras; + bool result; + + if (cm->cameras().size() == 1) + return cm->cameras()[0]->name(); - if (!options_.isSet(OptCamera)) { - QStringList cameras; - bool result; + for (const std::shared_ptr &cam : cm->cameras()) + cameras.append(QString::fromStdString(cam->name())); - for (const std::shared_ptr &cam : cm->cameras()) - cameras.append(QString::fromStdString(cam->name())); + QString name = QInputDialog::getItem(this, "Select Camera", + "Camera:", cameras, 0, + false, &result); + if (!result) + return std::string(); - QString name = QInputDialog::getItem(this, "Select Camera", - "Camera:", cameras, 0, - false, &result); - if (!result) - return -EINVAL; + return name.toStdString(); +} - cameraName = name.toStdString(); - } else { +int MainWindow::openCamera(CameraManager *cm) +{ + std::string cameraName; + + if (options_.isSet(OptCamera)) cameraName = static_cast(options_[OptCamera]); - } + else + cameraName = chooseCamera(cm); + + if (cameraName == "") + return -EINVAL; camera_ = cm->get(cameraName); if (!camera_) { diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 6873155aaa03..30dd8743104d 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -43,6 +43,7 @@ private Q_SLOTS: void updateTitle(); private: + std::string chooseCamera(CameraManager *cm); int openCamera(CameraManager *cm); int startCapture();