From patchwork Wed Aug 3 17:55:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16956 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 2FF02C3272 for ; Wed, 3 Aug 2022 17:55:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6AAA6330F; Wed, 3 Aug 2022 19:55:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659549329; bh=Zk7ObCaikQB0Rr/hkHevWBkMzOIDVn8qxqSX+MzNb+g=; 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=t9b0exwnBGKBHwv21mAFmTtqr4Qkf/vM16X0+HEIoDfWZ+uH5Ya7JQpXNSc8ktpXU O4Ockhd/zfjtgZTCa98u/0NfDK03cjz4RTHK2xy7P+ASGo4fZqdDAbDHPhFKUcDxHi Uc9r0z2wBzq2APNhuPbkWJ7ffuFKBrvecNI8vvVRVjPAG+7VpGL0gqMgfGyWLHOgLu k9I2vqKxFhoj+KtzE/zcwNRlBynft9+TknwOrmuvuTv/SA4APEYUd6UqYyl2dRNBLH 6+fTiYZ8c/2+2T/1R6nD0u8+kaVO9JV0Et2+AQ7Lx6UKaXNe2KfEz4JICqXxaxVTzD XuOPvQ5VhxsvA== Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A5E9D63314 for ; Wed, 3 Aug 2022 19:55:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Up5ZLgn9"; dkim-atps=neutral Received: by mail-pj1-x1035.google.com with SMTP id p14-20020a17090a74ce00b001f4d04492faso2901617pjl.4 for ; Wed, 03 Aug 2022 10:55:27 -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=IW+h5cRdAHnoLrIKdaIkEIUEf3/NheN/VmD+zgCaZpE=; b=Up5ZLgn9kJJ7hyCLjksXktJZzXDvzONCbUyqxhPtz8R7qe7FdQKmSAfGxLBZXZ6NwN KAQfzfZZNdIBYuDVlkjTsF7NgHwyARDKHPV9lqYMkGhmhw90trT+U4S01VMNTO+Cq9bi +Oi6Roa6324P6+gxmmHwZsnVGqw2X31hRy5DKaUavry+hAEFvDxhPNM+TretpbNE2TRo jqdLmondGTftQLXxFLGG5huQz/AEiz2tQ79Z9UN04Artvs4cmcHfddfJfIalEogulw3u n6+fcYw7yR2TSSXg2xiyP/9UWkQWFWm1G/W23Dam/sFKLWSNU2xuIy5lvJj4uiA8wYiZ 3ZKg== 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=IW+h5cRdAHnoLrIKdaIkEIUEf3/NheN/VmD+zgCaZpE=; b=0m3W3Pdv3KA0zMqBQxQiBwM2jHpUkJjNytRrPaIipPTsIjE56rOcsfSGycET5RLIYd uL+k05zluZhL0wcBzhxAyFU6gY9b1KLhVzul36OFLYV6xGWjwSCnJbM8111641joYz7J ubGc3V7iBAIc/JxHfZ7WpWS7GpGU4fih/8xyHO0h6oJXBcnKw1x6DfmmigApxVDnkWv7 yfQYlo+apXoeMe2Dx3YohsZIaY9y81BOHC1XDLCnYP5Mg6nAvu4CIO1bHi8IE/2qluLY MXRR8ZegHifcXPgbbOrRfqJtzUPZQuY50M8YNKgYrqoJzRuNmhQ2TrmvQcNXEFEu7pyu zDMw== X-Gm-Message-State: ACgBeo3L6N4xCYcVYWA0w14pju335qv8AICldDUEy85qsNOrFvkbTgqs eaH3ZtsxGZBGsB3Ca5q5xRPMTeGDoz4= X-Google-Smtp-Source: AA6agR5liS4sUwTq0tDRCmHVoIFReUGJ8mT10ZsLhd8Qf/DDItBmD6LokdNgH9cus8/Sns6f93LJkQ== X-Received: by 2002:a17:902:b605:b0:16d:3497:775d with SMTP id b5-20020a170902b60500b0016d3497775dmr27254994pls.1.1659549325916; Wed, 03 Aug 2022 10:55:25 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d5b8:ad21:c99c:170f:1ae]) by smtp.gmail.com with ESMTPSA id f3-20020a170902860300b0016357fd0fd1sm2193343plo.69.2022.08.03.10.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 10:55:25 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 23:25:14 +0530 Message-Id: <20220803175517.175332-2-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803175517.175332-1-utkarsh02t@gmail.com> References: <20220803175517.175332-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] qcam: Use QDialog for selection of cameras 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 QButtonBox to provide buttons for accepting and cancelling the action. Signed-off-by: Utkarsh Tiwari --- src/qcam/main_window.cpp | 47 ++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7433d647..7761a6c6 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -16,7 +16,10 @@ #include #include +#include +#include #include +#include #include #include #include @@ -291,23 +294,43 @@ 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(); + std::string result; /* Present a dialog box to pick a camera. */ + QDialog *cameraSelectDialog = new QDialog(this); + + /* Setup a QComboBox to display camera Ids. */ for (const std::shared_ptr &cam : cm_->cameras()) - cameras.append(QString::fromStdString(cam->id())); + cameras.push_back(QString::fromStdString(cam->id())); + + QComboBox *cameraIdComboBox = new QComboBox; + cameraIdComboBox->addItems(cameras); + + /* Setup QDialogButtonBox. */ + QDialogButtonBox *dialogButtonBox = new QDialogButtonBox; + dialogButtonBox->addButton(QDialogButtonBox::Cancel); + dialogButtonBox->addButton(QDialogButtonBox::Ok); + + connect(dialogButtonBox, &QDialogButtonBox::accepted, + this, [&]() { + result = cameraIdComboBox->currentText().toStdString(); + cameraSelectDialog->accept(); + }); + + connect(dialogButtonBox, &QDialogButtonBox::rejected, + this, [&]() { + result = std::string(); + cameraSelectDialog->reject(); + }); + + /* Setup the layout for the dialog. */ + QFormLayout *cameraSelectLayout = new QFormLayout(cameraSelectDialog); + cameraSelectLayout->addRow("Camera: ", cameraIdComboBox); + cameraSelectLayout->addWidget(dialogButtonBox); - QString id = QInputDialog::getItem(this, "Select Camera", - "Camera:", cameras, 0, - false, &result); - if (!result) - return std::string(); + cameraSelectDialog->exec(); - return id.toStdString(); + return result; } int MainWindow::openCamera() From patchwork Wed Aug 3 17:55:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16957 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 8E8A3C3272 for ; Wed, 3 Aug 2022 17:55:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5403263314; Wed, 3 Aug 2022 19:55:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659549332; bh=mLNMta3UTbSk0u2plTVn/eUohw6nx91/CTpD+fKK8eo=; 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=YQq93Ei4ao5WoLLXQECe8cs9eS160024s071akJ9momeeNM+hORSC8/TSf13BiB/u UTwChDeSb84yp5E89+CLPoqoLNRZvFANsefXF+OFNayTCG7psTIW+9DIGBnxvAFzbF YZqXIL2zPirodmIyKBziHV2AqUJPttnAn/bq5y3XMfQtr0PX84c4b85YIhilFz+xTo jDP/nQXJvQ760Dd+mDjjQPTEh0te2F5cr6isXo758VyP+7J/kuq1I8Zy116mJVkT3S i+KSa8aC7Vh5TyuYttQQpdD9UsCS0QZkgM441q9FJTsgquWQJ6JG7ix/XYkpRZJnB4 jy1tZ3tvvZ7+A== Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71FC16330F for ; Wed, 3 Aug 2022 19:55:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qMrflREH"; dkim-atps=neutral Received: by mail-pl1-x632.google.com with SMTP id m2so10317455pls.4 for ; Wed, 03 Aug 2022 10:55:29 -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=hS3ONz0uAfI7pW5e9nnmNXa/0jwY6YBiygvILYUDxa8=; b=qMrflREHdpzOVP73q+5P4RruPrmXfxG0qvxTfioImcLaOeFSdJ8qRcgZRuko+knKp+ kBmz53FIJjtpLPpPFKxbFpf4vWylFwnNial3A7h/E6wTxxpnOBPRPWhgplwpGzsjI3sR FyTu1ib6S4FGAr7lxRC0DM2ZklIc3NzT6BijEBFlSL+MIlVDxP/bmKeVwPDZCfhg/IbG PVgMlb7QYBGPEL5vDOKeTi43QDODWJe+HDsOQI3yDnADP7xlLL3QNdZCAi1k7yrN3CLy dojpntQnc/wXiNMo6oGbEuJ4/+JSvt4Ysi/3MlWEBzaaY5BrdY0U0yP6ZLhChYeo4fXR +3VA== 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=hS3ONz0uAfI7pW5e9nnmNXa/0jwY6YBiygvILYUDxa8=; b=YPHxBCG2cob+r1aTBHOaEGB1hTjN+/t+LZao0Zma0v1dw3ViDuCw1qlpgkRSi5TJJB xn//qkfwg0LGPf4jbG4TPHzy9XuzquvZmMd5hsX+2YMbc9eT/PIOlm9V9zCZpnmtrwLZ 3woU5L5MfDXQmSr/KRR12J3SzPrNFtjAtXDDXRJ7TQoMLVEyYA+CrROzzAJR4Z24tHsO dy2gmz7nnuioFqPVmQzCVZABcwnL5586DHY6+1Doa7JWGP5dBTPmIiPDFsl+1+NWKjas qsLZH44heakzS/7GOcN59/LVtlTrXm3v5fFuxo7wxb+hfTpnhNKCDvvN3WGGUJSk1yEm aQzA== X-Gm-Message-State: ACgBeo2hpymnjOHk7GiXrfNXfHToPuvnI9N28b/9ogfhepvqLUbnCO2j 5Fnk1f3szDk+eNoYvwqBYVcKrsXFGGM= X-Google-Smtp-Source: AA6agR6vBQrbZ4Eh/SYtkiTxc2syP+VYICSEBzhfe27ajb+SA9zNA+j0dM4IJdU6mWZstopD15WwqA== X-Received: by 2002:a17:902:e5c6:b0:16e:f3b6:ddb5 with SMTP id u6-20020a170902e5c600b0016ef3b6ddb5mr13940766plf.122.1659549327768; Wed, 03 Aug 2022 10:55:27 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d5b8:ad21:c99c:170f:1ae]) by smtp.gmail.com with ESMTPSA id f3-20020a170902860300b0016357fd0fd1sm2193343plo.69.2022.08.03.10.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 10:55:27 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 23:25:15 +0530 Message-Id: <20220803175517.175332-3-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803175517.175332-1-utkarsh02t@gmail.com> References: <20220803175517.175332-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] qcam: Support Hotplug for Camera Selection Dialog 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 if there is HotPlug event when the user is on the Camera selection dialog, the QComboBox didn't update to reflect the change. If the cameraIdComboBox_ contains a valid QComboBox then update it to reflect the HotPlug change. Check the validity of QComboBox pointer by guarding it with a QPointer. Signed-off-by: Utkarsh Tiwari --- src/qcam/main_window.cpp | 23 +++++++++++++++-------- src/qcam/main_window.h | 4 ++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7761a6c6..80a73b68 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -293,18 +293,15 @@ void MainWindow::switchCamera(int index) std::string MainWindow::chooseCamera() { - QStringList cameras; std::string result; /* Present a dialog box to pick a camera. */ QDialog *cameraSelectDialog = new QDialog(this); /* Setup a QComboBox to display camera Ids. */ + cameraIdComboBox_ = new QComboBox; for (const std::shared_ptr &cam : cm_->cameras()) - cameras.push_back(QString::fromStdString(cam->id())); - - QComboBox *cameraIdComboBox = new QComboBox; - cameraIdComboBox->addItems(cameras); + cameraIdComboBox_->addItem(QString::fromStdString(cam->id())); /* Setup QDialogButtonBox. */ QDialogButtonBox *dialogButtonBox = new QDialogButtonBox; @@ -313,7 +310,7 @@ std::string MainWindow::chooseCamera() connect(dialogButtonBox, &QDialogButtonBox::accepted, this, [&]() { - result = cameraIdComboBox->currentText().toStdString(); + result = cameraIdComboBox_->currentText().toStdString(); cameraSelectDialog->accept(); }); @@ -325,7 +322,7 @@ std::string MainWindow::chooseCamera() /* Setup the layout for the dialog. */ QFormLayout *cameraSelectLayout = new QFormLayout(cameraSelectDialog); - cameraSelectLayout->addRow("Camera: ", cameraIdComboBox); + cameraSelectLayout->addRow("Camera: ", cameraIdComboBox_); cameraSelectLayout->addWidget(dialogButtonBox); cameraSelectDialog->exec(); @@ -628,7 +625,12 @@ void MainWindow::processHotplug(HotplugEvent *e) HotplugEvent::PlugEvent event = e->hotplugEvent(); if (event == HotplugEvent::HotPlug) { - cameraCombo_->addItem(QString::fromStdString(camera->id())); + QString cameraId = QString::fromStdString(camera->id()); + cameraCombo_->addItem(cameraId); + + /* Update cameraIdCombox_ to include the new camera. */ + if (cameraIdComboBox_) + cameraIdComboBox_->addItem(cameraId); } else if (event == HotplugEvent::HotUnplug) { /* Check if the currently-streaming camera is removed. */ if (camera == camera_.get()) { @@ -638,6 +640,11 @@ void MainWindow::processHotplug(HotplugEvent *e) cameraCombo_->setCurrentIndex(0); } + if (cameraIdComboBox_) { + int cameraIdIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id())); + cameraIdComboBox_->removeItem(cameraIdIndex); + } + int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); cameraCombo_->removeItem(camIndex); } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index fc70920f..b8122eb9 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -23,7 +23,9 @@ #include #include #include +#include #include +#include #include #include "../cam/stream_options.h" @@ -99,6 +101,8 @@ private: QString title_; QTimer titleTimer_; + QPointer cameraIdComboBox_; + /* Options */ const OptionsParser::Options &options_; From patchwork Wed Aug 3 17:55:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16958 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 188ABC3275 for ; Wed, 3 Aug 2022 17:55:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C16EE63318; Wed, 3 Aug 2022 19:55:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659549332; bh=L5SUs8syTThpflIJmphIG1FYn8k+QjPN8wemRiOXVjg=; 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=A/y3NbFuwfQKWakEVWPttvaDMAxiNlVXIbFR43hA1/wUgf4CMc1bji5BxOwcQPm/r +zc8RTBzqZi7mx9SIyRjPVbKmhjKLfnaILyEr+T4KI+s5Eu0YN+DsHzxC/bLtudkmr WtnLbXKTnYxqHqTDYCqUlkx1qMTcTaiFFD6p3kO0PTBsHTuJ8Ccy0/vQp80z46K1pn cNhW4YOnRp+jZJUh8uMjUcLCkz1DJuGeluLrLYXOjTQrkx1ISduuCGrSerLn735xO3 1ou3rH9DsxweTR2j5FVMBUBsBB+0N0QUBwXuqSDjjvN8k3/Tr99xgmQlOQJI9U9l5p hHeaZUPq5z3+w== Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CF5663314 for ; Wed, 3 Aug 2022 19:55:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ee6e85WI"; dkim-atps=neutral Received: by mail-pl1-x629.google.com with SMTP id v18so17067525plo.8 for ; Wed, 03 Aug 2022 10:55:31 -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=+AYKpewvBPvWpyDdvrjVaXbdLyr0CbHI6oebH/diOL4=; b=Ee6e85WIV7IJfjNWViDN7BbUMTU/AGsxfE+JL4OM1iOaWv51QMj96CfX6bt72ZQVJp Tgz8FH5xRwiYFWbL0Nx/lKAPLbFuY49n4otymlHPpCE6Qd6WCZ/te0PTcQ8JHc9BxEKB DYVo5SqXpMDvzzAaGONfVrvxl4rti7BJGcncJCO2hfSMBO+ZzJ/lGMNBMuP+ZObd2PsO XKTXohS670lDJedzIVK9TNHp7deuTh10SVds0Gf0THpVq7TNXFa5Kx2ASimBhcHIiSME N4QVkfLtCo8NdYyLSDQTPs2jplEgBxOCPJuS0WWd6k1Q6KFNOqKQ2Epqfn0B34hni3HL pa+g== 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=+AYKpewvBPvWpyDdvrjVaXbdLyr0CbHI6oebH/diOL4=; b=6wV0A8DwiV65w3ipLqOt4TqoGQ4CAzkkZi6OkRdXZ5LBWK+pEG6RwOblP5Rsd/+TB/ M58nJoTj9Q0akwNh4dIaeGebHha7WRxA4RjdiQvP/h5RD8qcyuIs125v4nHjNPaACtz0 Gz32W5QLoSlG9pAma2kNnbxD1C2cUYKPj4mqoYvKrchCbsCAHYZ5PSEkits3PaSF+KUR qKXFf1odSigtCBUQO7cLpIlf+vs+PdOREJdsgVevq58AYKp9Jn+qH1GGTKL4a3saZKHI VGZPiDCM6qBDKOy7/829yR7mTKNSzwHu4c/PyQHdKybV92Cj63IgQggaYTnfu7tKdF2U M5JQ== X-Gm-Message-State: ACgBeo3gzulld8XbMOgsaudSM94L9v/2rdGoZtjne2Gdc72WyPYDDeiV S1gu/xHkG1s9C+MrrQXfRTVUdXhGSw4= X-Google-Smtp-Source: AA6agR5GcKUrE7wJr5TyDqUj6K7NdwxjXBZEx6fCLOo6wSM/orF2fW+QtUpIfrTMHdX9qIKl0NQa2Q== X-Received: by 2002:a17:902:cece:b0:16e:d4c3:5894 with SMTP id d14-20020a170902cece00b0016ed4c35894mr19732219plg.154.1659549329482; Wed, 03 Aug 2022 10:55:29 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d5b8:ad21:c99c:170f:1ae]) by smtp.gmail.com with ESMTPSA id f3-20020a170902860300b0016357fd0fd1sm2193343plo.69.2022.08.03.10.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 10:55:29 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 23:25:16 +0530 Message-Id: <20220803175517.175332-4-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803175517.175332-1-utkarsh02t@gmail.com> References: <20220803175517.175332-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] qcam: CameraSelectDialog: Display Location and Model propety of camera 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" The camera selection dialog currently only displays the camera Id. Display the camera location and camera model if available. Signed-off-by: Utkarsh Tiwari --- src/qcam/main_window.cpp | 69 ++++++++++++++++++++++++++++++++++++++++ src/qcam/main_window.h | 7 ++++ 2 files changed, 76 insertions(+) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 80a73b68..81fa3e60 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -291,6 +293,47 @@ void MainWindow::switchCamera(int index) startStopAction_->setChecked(true); } +QString MainWindow::getCameraLocation(const std::shared_ptr &camera) +{ + if (camera == nullptr) + return QString(); + + const ControlList &cameraProperties = camera->properties(); + const auto &location = cameraProperties.get(properties::Location); + + if (location) { + switch (*location) { + case properties::CameraLocationFront: + return "Internal front camera "; + case properties::CameraLocationBack: + return "Internal back camera "; + case properties::CameraLocationExternal: + return "External camera "; + } + } + return QString(); +} + +QString MainWindow::getCameraModel(const std::shared_ptr &camera) +{ + if (camera == nullptr) + return QString(); + + const ControlList &cameraProperties = camera->properties(); + const auto &model = cameraProperties.get(properties::Model); + + if (model) + return QString::fromStdString(*model); + + return QString(); +} + +void MainWindow::updateCameraInfo(const std::shared_ptr &camera) +{ + cameraLocation_->setText(getCameraLocation(camera)); + cameraModel_->setText(getCameraModel(camera)); +} + std::string MainWindow::chooseCamera() { std::string result; @@ -303,6 +346,29 @@ std::string MainWindow::chooseCamera() for (const std::shared_ptr &cam : cm_->cameras()) cameraIdComboBox_->addItem(QString::fromStdString(cam->id())); + /* Display Camera Informtion in the Selection Dialog. */ + cameraLocation_ = new QLabel; + cameraModel_ = new QLabel; + + std::shared_ptr currentCamera; + + /* + * When the Qdialog starts, the QComboBox would have the first + * camera's Id as its currentText. + */ + if (cm_->cameras().size()) + currentCamera = cm_->cameras()[0]; + else + currentCamera = nullptr; + + if (currentCamera) + updateCameraInfo(currentCamera); + + connect(cameraIdComboBox_, &QComboBox::currentTextChanged, + this, [&]() { + updateCameraInfo(cm_->get(cameraIdComboBox_->currentText().toStdString())); + }); + /* Setup QDialogButtonBox. */ QDialogButtonBox *dialogButtonBox = new QDialogButtonBox; dialogButtonBox->addButton(QDialogButtonBox::Cancel); @@ -323,6 +389,9 @@ std::string MainWindow::chooseCamera() /* Setup the layout for the dialog. */ QFormLayout *cameraSelectLayout = new QFormLayout(cameraSelectDialog); cameraSelectLayout->addRow("Camera: ", cameraIdComboBox_); + cameraSelectLayout->addRow("Location: ", cameraLocation_); + cameraSelectLayout->addRow("Model: ", cameraModel_); + cameraSelectLayout->addWidget(dialogButtonBox); cameraSelectDialog->exec(); diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index b8122eb9..3a1c6156 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -88,6 +89,10 @@ private: void processHotplug(HotplugEvent *e); void processViewfinder(libcamera::FrameBuffer *buffer); + QString getCameraLocation(const std::shared_ptr &camera); + QString getCameraModel(const std::shared_ptr &camera); + void updateCameraInfo(const std::shared_ptr &camera); + /* UI elements */ QToolBar *toolbar_; QAction *startStopAction_; @@ -102,6 +107,8 @@ private: QTimer titleTimer_; QPointer cameraIdComboBox_; + QLabel *cameraLocation_; + QLabel *cameraModel_; /* Options */ const OptionsParser::Options &options_; From patchwork Wed Aug 3 17:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16959 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 7978DC3272 for ; Wed, 3 Aug 2022 17:55:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 317BE63321; Wed, 3 Aug 2022 19:55:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659549335; bh=xdyTipN04m4FOCC8IhJVcDGM5cq7LQ8at0Jd+ICqVrg=; 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=gm+PtUJ7aHD5lTw9qW17XTV01Y1dsWRGWSCSXxa4vIhWHhFZHnxNkDMiMRQ6mjish XD34LcJ9d1gxW7fSD9+h3f6fzqjk/zTjgJ0WVvvZ4InRrB8dtjNdmhMPzVHrK+Ol9B 3PMvUeIni6wVKUK5ixud5j/4onHvaWNbcGK9aMaDr7pEUfTBJXeggtiH3wQ5cf0hCE GVxEfjc+6P1y/t1/WtIaOmhpY5edcN7mhilIrgcjww1alWzKEksw43pE/1qn+qIPcb 3lGFejQORPh5tCIsjVHEEB2btiBf7J8UDYZ1iA1CTu9BhM/FQ2KB6Ne4YqDNsq10QA k+2SGmvRFZpCA== Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E06586331E for ; Wed, 3 Aug 2022 19:55:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aL0D0F39"; dkim-atps=neutral Received: by mail-pg1-x533.google.com with SMTP id 13so1333932pgc.8 for ; Wed, 03 Aug 2022 10:55:32 -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=zTPzlmBu9WrbT3szxYMLbFPUmXMs8/t6CORexb8HThk=; b=aL0D0F39Gk4HZnCAbvq6I+WIPj37ffbOKxoVJCC6du8J8ua+lmKP3sngF5a5saqSLh nCMFRT9hD4hwToakL62+hHgLjkIPH9gpMk3mWNeGNop/PbzzTAt7m1DMeNLDMqDNW5Qu IMvKjYUjp1JS+xOJuDP+BzlY+7Q+XjM6u5A3zILiI0mV+JTZj7FT3iiPOe0BsaDInxac 2Y66yRrX5JCnnwe2MBcWnufCtTpjFdRi0bY1mkHa3EF+mku3GmM7In4Sg22yX0e6mY0Y f1leiMCFutgQeEBL2IcVpodS6oYIYBNgHvjTafPeW6g9L9yQIYJsXIeF92ZFN7lhGT5d Mx5g== 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=zTPzlmBu9WrbT3szxYMLbFPUmXMs8/t6CORexb8HThk=; b=nKtCxDrir/NXri9YCqiD1uh4q+o2OBFo2wWafKvA7PhbyL6fLUS6++D6bFKJpCK3Cv Uvwe6Mx8ZFDumaqED3xDlOjrddY2XoJunrlITwhW7mR3IyOFVdVKDJw8C3ZqWaenTMjP AtZVNXbXqJzzMleUFnqOkMb6tgvI8bk1Bl7pj0OERk3Umn2O8d6CBni/3xfUVunNLTom VLC/8xN7nDQuSARAdlzpQWx2S3kS4iyewWkwMjctR8cQD99H4XhsKaIYB8nw0z4EJpRI M58iBwjE47BFoVTkzNAE1Ed0C4nsD6tTJroQCy57zoSTOtrUtwBsgbT2zzOyI9DYtfYT 5AZg== X-Gm-Message-State: AJIora9T09LtYG34Fk/QTFjwtBoNeTvse2QygMQNmFDm3IwjtCgrUmJ7 TeJaAcvZmaWEi0Iv76qwQzDLHSZxYzY= X-Google-Smtp-Source: AGRyM1vRZsqdPS4tLIaAmb+MvvK0trf5ARIpltTzohntCcU6U/lgmhxjrFXAvyLqlNzXGdcAYfSdBQ== X-Received: by 2002:a63:4c4d:0:b0:41a:a125:60c9 with SMTP id m13-20020a634c4d000000b0041aa12560c9mr21780249pgl.329.1659549331193; Wed, 03 Aug 2022 10:55:31 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d5b8:ad21:c99c:170f:1ae]) by smtp.gmail.com with ESMTPSA id f3-20020a170902860300b0016357fd0fd1sm2193343plo.69.2022.08.03.10.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 10:55:30 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 23:25:17 +0530 Message-Id: <20220803175517.175332-5-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803175517.175332-1-utkarsh02t@gmail.com> References: <20220803175517.175332-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] qcam: MainWindow: Replace cameraCombo_ with cameraSelectDialog 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" Replace the cameraCombo_ on the toolbar with a QPushButton which displays the cameraSelectDialog. This would allow the user to view information about the camera when switching. The QPushButton text is set to the camera Id currently in use. Signed-off-by: Utkarsh Tiwari Reviewed-by: Umang Jain --- src/qcam/main_window.cpp | 47 ++++++++++++++++++++++------------------ src/qcam/main_window.h | 5 +++-- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 81fa3e60..2a9dcc1e 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -198,14 +198,11 @@ int MainWindow::createToolbars() connect(action, &QAction::triggered, this, &MainWindow::quit); /* Camera selector. */ - cameraCombo_ = new QComboBox(); - connect(cameraCombo_, QOverload::of(&QComboBox::activated), + cameraSelectButton_ = new QPushButton; + connect(cameraSelectButton_, &QPushButton::clicked, this, &MainWindow::switchCamera); - for (const std::shared_ptr &cam : cm_->cameras()) - cameraCombo_->addItem(QString::fromStdString(cam->id())); - - toolbar_->addWidget(cameraCombo_); + toolbar_->addWidget(cameraSelectButton_); toolbar_->addSeparator(); @@ -265,14 +262,18 @@ void MainWindow::updateTitle() * Camera Selection */ -void MainWindow::switchCamera(int index) +void MainWindow::switchCamera() { /* Get and acquire the new camera. */ - const auto &cameras = cm_->cameras(); - if (static_cast(index) >= cameras.size()) + std::string cameraId = chooseCamera(); + if (cameraId.empty()) return; - const std::shared_ptr &cam = cameras[index]; + /* Don't try the current camera. */ + if (cameraId == camera_->id()) + return; + + const std::shared_ptr &cam = cm_->get(cameraId); if (cam->acquire()) { qInfo() << "Failed to acquire camera" << cam->id().c_str(); @@ -290,6 +291,9 @@ void MainWindow::switchCamera(int index) camera_->release(); camera_ = cam; + /* Set the QPushButton text with current camera. */ + cameraSelectButton_->setText(QString::fromStdString(camera_->id())); + startStopAction_->setChecked(true); } @@ -356,10 +360,16 @@ std::string MainWindow::chooseCamera() * When the Qdialog starts, the QComboBox would have the first * camera's Id as its currentText. */ - if (cm_->cameras().size()) - currentCamera = cm_->cameras()[0]; - else - currentCamera = nullptr; + if (!isCapturing_) { + if (cm_->cameras().size()) + currentCamera = cm_->cameras()[0]; + else + currentCamera = nullptr; + } else { + int cameraIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id())); + cameraIdComboBox_->setCurrentIndex(cameraIndex); + currentCamera = camera_; + } if (currentCamera) updateCameraInfo(currentCamera); @@ -428,8 +438,8 @@ int MainWindow::openCamera() return -EBUSY; } - /* Set the combo-box entry with the currently selected Camera. */ - cameraCombo_->setCurrentText(QString::fromStdString(cameraName)); + /* Set the QPushButton text with the currently selected Camera. */ + cameraSelectButton_->setText(QString::fromStdString(cameraName)); return 0; } @@ -695,7 +705,6 @@ void MainWindow::processHotplug(HotplugEvent *e) if (event == HotplugEvent::HotPlug) { QString cameraId = QString::fromStdString(camera->id()); - cameraCombo_->addItem(cameraId); /* Update cameraIdCombox_ to include the new camera. */ if (cameraIdComboBox_) @@ -706,16 +715,12 @@ void MainWindow::processHotplug(HotplugEvent *e) toggleCapture(false); camera_->release(); camera_.reset(); - cameraCombo_->setCurrentIndex(0); } if (cameraIdComboBox_) { int cameraIdIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id())); cameraIdComboBox_->removeItem(cameraIdIndex); } - - int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); - cameraCombo_->removeItem(camIndex); } } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 3a1c6156..b15f9409 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ private Q_SLOTS: void quit(); void updateTitle(); - void switchCamera(int index); + void switchCamera(); void toggleCapture(bool start); void saveImageAs(); @@ -96,7 +97,7 @@ private: /* UI elements */ QToolBar *toolbar_; QAction *startStopAction_; - QComboBox *cameraCombo_; + QPushButton *cameraSelectButton_; QAction *saveRaw_; ViewFinder *viewfinder_;