From patchwork Sat Oct 19 10:09:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 21701 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 7B8B0BD1F1 for ; Sat, 19 Oct 2024 10:09:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E89606538C; Sat, 19 Oct 2024 12:09:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="cIoID2nc"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 172AC65380 for ; Sat, 19 Oct 2024 12:09:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729332576; x=1760868576; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=bRlaZ1nOa3qfHP+DpU354kdPacfmsnYOp84Fbriagq4=; b=cIoID2ncD/Xb+MJOy+b47KlBlw/AsxQ8VYqwT5Pbg4zPjuwnZ43p0776 dtZmEEnA/UsDF2uJtN9fYBVJuGRFvgU6j8s2oUb5k67n1A/kZrrjeLQ05 kruM+xf35f3GJ+6CPyJF6SzZMLdAlr4QObjXOQufjmPfb2ALvrz3VdGdk /2Ax3PRffPRlokcvvNtfWSRxid+qpnzkEXQzVq3iMfKyRlhuZgFfmsVDF HeQ0TzYQDzgpjHlL1K5NiYvUXa0dZO5m1VBbdq18swVaItiPwUfRUTohD fu+sVQteD84iSi/EiNedzV6tNxgbW434Z5hvajLM2aYoaqv5XW4xPRzBI g==; X-CSE-ConnectionGUID: ftx/ShmAQF+SkCcZdkIOwQ== X-CSE-MsgGUID: 0lhsEFyfRtGBxP8xiJjHsQ== X-IronPort-AV: E=McAfee;i="6700,10204,11229"; a="40228504" X-IronPort-AV: E=Sophos;i="6.11,216,1725346800"; d="scan'208";a="40228504" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2024 03:09:29 -0700 X-CSE-ConnectionGUID: Zk6buDlsSai78R3ZBVH2nw== X-CSE-MsgGUID: 1dAPtHZtTT27dy9mywlORg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,216,1725346800"; d="scan'208";a="109916210" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.97.183]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2024 03:09:29 -0700 From: Stanislaw Gruszka To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2] qcam: Automatically select the camera if only one is available Date: Sat, 19 Oct 2024 12:09:25 +0200 Message-Id: <20241019100925.42808-1-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When only a single camera is available, showing the camera selection dialog is unnecessary. It's better to automatically select the available camera without prompting the user for input. Signed-off-by: Stanislaw Gruszka Reviewed-by: Kieran Bingham --- v2: - Avoid cameras().size() vs cameras()[0] race condition - Update in code comment src/apps/qcam/main_window.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp index 5144c6b3..86ffa205 100644 --- a/src/apps/qcam/main_window.cpp +++ b/src/apps/qcam/main_window.cpp @@ -296,14 +296,23 @@ std::string MainWindow::chooseCamera() int MainWindow::openCamera() { std::string cameraName; + int num = 0; /* - * Use the camera specified on the command line, if any, or display the - * camera selection dialog box otherwise. + * Use the camera specified on the command line, if any, or select the + * only one available, otherwise display the camera selection dialog box. */ - if (options_.isSet(OptCamera)) + if (options_.isSet(OptCamera)) { cameraName = static_cast(options_[OptCamera]); - else + } else { + for (const auto &cam : cm_->cameras()) { + num++; + if (num > 1) + break; + cameraName = cam->id(); + } + } + if (num > 1) cameraName = chooseCamera(); if (cameraName == "")