From patchwork Wed Aug 31 05:49:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17266 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 AAA67C3272 for ; Wed, 31 Aug 2022 05:49:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 75C1961FC6; Wed, 31 Aug 2022 07:49:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661924998; bh=g6D5m2WFhbwXTkn/Pct1kjEn4FTBYJsLIw9oQbIJ8Qk=; 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=orAodYh9twuu66qKripTPqVLTY3fl9WdcbV63mMSmcoORJGezTZ2YRx0Yj5l/Tb5P 5qjBCBL0tTqrD8I/VGrVjDX54OYaUH4+jzMTWAE4+deObRFhfXJZNnD1LBPYQFF20W ZqURAXj3+aXElPeRivyd9UP8cKP5oBY3T3pw9NDjyNIDY9f4bMfOiC8tQ7xhBpPhqD w8DCIRQ0U82Jb02ZCLjCvYkuWebsPDcaK4LnSHB+LmB2aOZZyfShYIQB/ltgMSdgKg xqTldMtJ15G/1tEu3oNDp0MO0R86mOfa6twXbfJcuCAejODmVBH+GvwJn33dyUakFw nEe1ea2zlr6Pg== 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 E726761F9B for ; Wed, 31 Aug 2022 07:49:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CDC57I7O"; dkim-atps=neutral Received: by mail-pg1-x530.google.com with SMTP id q9so12625361pgq.6 for ; Tue, 30 Aug 2022 22:49:56 -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=uJ1eqaShmnTXo3AJN7h1xqQNAn/WbfbO7bzaBnyOrR4=; b=CDC57I7O1aC0xphtRIMK8o5x2DhTq3RTN+44/4rY3LQGaVx8AsO6FUyRTum8f1NBQE EnjKOJc6JJZ/2vYrLk1QbR8KyEl1grXz7eReiUCRBpT621zu64kjxdeXmhQwqR94fqHN QUA8v/EJBYVAsUIAAKj0zP65W3lqJFlgfHNezzGN4ibnjLUhv7RZilrXIV5tiu8T30qL s/Eh7ZM8Rzc/HaHNoOezSih0PauX9sgjSWA+va+PczBq68ZPDKZF6rvJj9lQb8LjreDR KZLgglP2fDpd8o5ra1nEE87QObuwjEvswtU6bNvBl9YiFo759ivIbyvHPrz0yJ/FOsBu YlFg== 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=uJ1eqaShmnTXo3AJN7h1xqQNAn/WbfbO7bzaBnyOrR4=; b=J9PQwel19spnM8Frn165x5IIr6LWOr9UfvpYA6ZJJuNqcGKDoPP62Vc8BrR3ERCKKx lSO2GaQTh5/J5IfbxlHpAo6p2x0plEOAnU9PeQ8qbAqJj8C/GU96uZdjxAAqiMhWhVHI Talx8x+8rL14aUhPJWctHXca4H62DcsoZDBsHwIPOnF3FFvvAp8dJzZg4wVBhmbzUnZ7 lA6snlJtK+00X8db7mcm3C9WZkr1j1/iDvTsCawtM9Xt8olFxPk+fIHBxasig6+Ko5gB yQPbt16c/NeW5H1okkXN5yr3HJqOKgidKPMWj/xpl41NZqAIrzbzSsaHNInEwPZz8MGD V/JA== X-Gm-Message-State: ACgBeo2xPut46y28i6TfCgxFdH5qrs55rpys01IDeni0rmWEJW6KbgZL 94CL3h+hToaOVmUchdpc0TzG0fjr9zM= X-Google-Smtp-Source: AA6agR6slkzwzNZNaqO8yUabs94tydRNwznL8PJWivtYwgbbEJfKybQwgHJCA5OItMGJ0jAXOjdR9g== X-Received: by 2002:a63:84c2:0:b0:42b:f6bc:69f5 with SMTP id k185-20020a6384c2000000b0042bf6bc69f5mr12163968pgd.10.1661924995304; Tue, 30 Aug 2022 22:49:55 -0700 (PDT) Received: from devut-HP-Laptop-14q-cs0xxx.. ([103.36.82.122]) by smtp.gmail.com with ESMTPSA id q19-20020aa79833000000b00537eacc8fa6sm8307333pfl.40.2022.08.30.22.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 22:49:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 31 Aug 2022 11:19:33 +0530 Message-Id: <20220831054938.21617-3-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831054938.21617-1-utkarsh02t@gmail.com> References: <20220831054938.21617-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 2/7] 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 doesn't update to reflect the change. Add support for hotplugging / unplugging cameras. Signed-off-by: Utkarsh Tiwari Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Difference from v8: 1. Removed the part about QPointer from commit message, no longer needed. 2. s/didn't/doesn't commit msg. 3. Rename cameraRemoved to removeCamera and cameraAdded to addCamera 4. Pass QString to cameraRemoved, cameraAdded instead of libcamera::Camera 5. Removed blank line between cameraAdded, cameraRemoved 6. Optimize cameraId passing cameraCombo_ , cameraAdded, cameraRemoved. src/qcam/cam_select_dialog.cpp | 12 ++++++++++++ src/qcam/cam_select_dialog.h | 5 +++++ src/qcam/main_window.cpp | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp index a49d822b..f82930cc 100644 --- a/src/qcam/cam_select_dialog.cpp +++ b/src/qcam/cam_select_dialog.cpp @@ -48,3 +48,15 @@ std::string CameraSelectorDialog::getCameraId() { return cameraIdComboBox_->currentText().toStdString(); } + +/* Hotplug / Unplug Support. */ +void CameraSelectorDialog::addCamera(QString camearaId) +{ + cameraIdComboBox_->addItem(camearaId); +} + +void CameraSelectorDialog::removeCamera(QString cameraId) +{ + int cameraIndex = cameraIdComboBox_->findText(cameraId); + cameraIdComboBox_->removeItem(cameraIndex); +} diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h index c31f4f82..bd2dbc1e 100644 --- a/src/qcam/cam_select_dialog.h +++ b/src/qcam/cam_select_dialog.h @@ -13,6 +13,7 @@ #include #include +#include class QComboBox; @@ -27,6 +28,10 @@ public: std::string getCameraId(); + /* Hotplug / Unplug Support. */ + void addCamera(QString cameraId); + void removeCamera(QString cameraId); + private: libcamera::CameraManager *cm_; diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 14bcf03e..e8e22d49 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -587,10 +587,12 @@ void MainWindow::stopCapture() void MainWindow::processHotplug(HotplugEvent *e) { Camera *camera = e->camera(); + QString cameraId = QString::fromStdString(camera->id()); HotplugEvent::PlugEvent event = e->hotplugEvent(); if (event == HotplugEvent::HotPlug) { - cameraCombo_->addItem(QString::fromStdString(camera->id())); + cameraCombo_->addItem(cameraId); + cameraSelectorDialog_->addCamera(cameraId); } else if (event == HotplugEvent::HotUnplug) { /* Check if the currently-streaming camera is removed. */ if (camera == camera_.get()) { @@ -600,8 +602,9 @@ void MainWindow::processHotplug(HotplugEvent *e) cameraCombo_->setCurrentIndex(0); } - int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); + int camIndex = cameraCombo_->findText(cameraId); cameraCombo_->removeItem(camIndex); + cameraSelectorDialog_->removeCamera(cameraId); } }