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_;