From patchwork Sat Mar 19 14:25:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 15482 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 64F42BD80A for ; Sun, 20 Mar 2022 10:31:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E005604DC; Sun, 20 Mar 2022 11:31:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647772264; bh=41CrP/Dwo1WfgZMQgjQMK+ciITil5bXJaFsoTDWMe9w=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DJkE8s+AQoFwkqmtPyIECMEyFSJET2/V1r+r8P0H2MmsvObl1sqmUxEFe8snW5P4h +Q2oe4VjRe9j8hcrSH6aVt+J0jrq12/0ZZT7ZfZRrOlEReBRHOT3NNs8zWxBMSeNni Vt5iXhxC9+pmc/XR6H54Pg4ltQa3de9wRQZ42fcLMsrSZbtrQuU7+q1zXdKqRUd1gP AJNQjqWXpcB+6O20Pny8O/IQYV/8IUcaxFvoG02WWG1D9rrCtaD9mmkaHtOQOMopIC gijozqZ/Kq+FyBGK5w4ishzza1Hpkbs7SyYfgZH9gEIaxwMibcSTNKXHhXYMhHyDd5 qOd0oaDrfJwqg== Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 08D2A604D5 for ; Sat, 19 Mar 2022 15:26:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="enZF1L3+"; dkim-atps=neutral Received: by mail-pj1-x102e.google.com with SMTP id mz9-20020a17090b378900b001c657559290so10369589pjb.2 for ; Sat, 19 Mar 2022 07:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xchwSc2ENjpqAF/HQOuqXny7d7mfVk4GV/bEoL+wsas=; b=enZF1L3+nTeLEKaJ1mjbyGbgaJbN8m7ju+O0f9EA1e/pDQbY+i0InxSHGk5X4RA16B xPT5+0mgBhQk2I6X2bHouOleZkJXfiVf3fbnNCGblpNFbBWtIo6fVT7SYCMdS7obT2jT b+BLPud2WKS/EGctXS+QH26VxsmIQiDpBUjk+kPWKCEB3tqt8bHJvLClcTYZdjQWh6iw 1Aw+TKwmR8u9AZVwflQdJZPiG6Y9aqslfkIFGzUKdLFEY2G/HyCkht7pKnj51l74w13i cSe2FO5zjJF1FCyb3UUsaoB/rszwpMA7ndNPICOkMfGU5ZSwYAODUrF5QmMy2Qdt1q89 qAxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xchwSc2ENjpqAF/HQOuqXny7d7mfVk4GV/bEoL+wsas=; b=KW0Tp4zdx+hx0V6od9xEmcoVRZ0QT0pONpd9Yq+XyVXvJTCsgNxDt2NQ2iWJ0wAKwP z8on/OUp9cM8Q1bcyfEu4lDDzpx3+BoSxXAwQGA4QOM2MW7C6WWCZpugsFwwSh1TlSnt +pm+vd3ZxsTXYvMLLyFkujLHc6inwKm2GZZuwHfWZj8NoPsWGi1K64/4LqWCPIzzqJQT zrPlL0uSu7mzQ+BWTp7zDea2y3guRSFVzal18LmU+b0xG1Zqd9M+8tSlbyOshCSZEUSj iz9U5ZAVJ8dAy7Sk2DQpr11vrGEYamn7Tx2+4O2XvSOMFgeFbgB2xTnLC8dxEOrL2KB0 WsXg== X-Gm-Message-State: AOAM530lk8KeicZe4zaCU4H3GnwDkCn+Z7zvLhxzGLSOD2Xm1BHxRElu MObXV4+/2qfAIA6ilYhL9k4bW5x4+NQGNQ== X-Google-Smtp-Source: ABdhPJwTyXZczdHmlIaKgwulagGZQMdjxZRcs18nDs1MUOoW8ZKTgFhosHQ/yqqKkxR/H9VtV+9qBA== X-Received: by 2002:a17:90b:3846:b0:1c6:841b:7470 with SMTP id nl6-20020a17090b384600b001c6841b7470mr14920217pjb.193.1647699958122; Sat, 19 Mar 2022 07:25:58 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:dfd0:b6a5:262b:9d92:c4b6]) by smtp.gmail.com with ESMTPSA id z14-20020aa7888e000000b004f79f59827asm13416664pfe.139.2022.03.19.07.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 07:25:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sat, 19 Mar 2022 19:55:45 +0530 Message-Id: <20220319142545.40433-1-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 20 Mar 2022 11:31:02 +0100 Subject: [libcamera-devel] [RFC PATCH] Add CameraName to the MainWindow 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 Cc: Utkarsh Tiwari Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Showing Camera Id on the main window is quite non-intuitive for the user Implementation: A duplicate function exists in cam/main.cpp . There must be a better way to do this instead of duplication of code Signed-off-by: Utkarsh Tiwari --- src/qcam/main_window.cpp | 61 +++++++++++++++++++++++++++++++++------- src/qcam/main_window.h | 2 +- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index dd0e51f5..35e737c7 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -12,8 +12,10 @@ #include #include +#include #include + #include #include #include @@ -197,7 +199,7 @@ int MainWindow::createToolbars() this, &MainWindow::switchCamera); for (const std::shared_ptr &cam : cm_->cameras()) - cameraCombo_->addItem(QString::fromStdString(cam->id())); + cameraCombo_->addItem(QString::fromStdString(cameraName(cam.get()))); toolbar_->addWidget(cameraCombo_); @@ -287,6 +289,45 @@ void MainWindow::switchCamera(int index) startStopAction_->setChecked(true); } +std::string MainWindow::cameraName(const libcamera::Camera *camera) +{ + const ControlList &props = camera->properties(); + bool addModel = true; + std::string name; + + /* + * Construct the name from the camera location, model and ID. The model + * is only used if the location isn't present or is set to External. + */ + if (props.contains(properties::Location)) { + switch (props.get(properties::Location)) { + case properties::CameraLocationFront: + addModel = false; + name = "Internal front camera "; + break; + case properties::CameraLocationBack: + addModel = false; + name = "Internal back camera "; + break; + case properties::CameraLocationExternal: + name = "External camera "; + break; + } + } + + if (addModel && props.contains(properties::Model)) { + /* + * If the camera location is not availble use the camera model + * to build the camera name. + */ + name = "'" + props.get(properties::Model) + "' "; + } + + name += "(" + camera->id() + ")"; + + return name; +} + std::string MainWindow::chooseCamera() { QStringList cameras; @@ -311,24 +352,24 @@ std::string MainWindow::chooseCamera() int MainWindow::openCamera() { - std::string cameraName; + std::string cameraId; /* * Use the camera specified on the command line, if any, or display the * camera selection dialog box otherwise. */ if (options_.isSet(OptCamera)) - cameraName = static_cast(options_[OptCamera]); + cameraId = static_cast(options_[OptCamera]); else - cameraName = chooseCamera(); + cameraId = chooseCamera(); - if (cameraName == "") + if (cameraId == "") return -EINVAL; /* Get and acquire the camera. */ - camera_ = cm_->get(cameraName); + camera_ = cm_->get(cameraId); if (!camera_) { - qInfo() << "Camera" << cameraName.c_str() << "not found"; + qInfo() << "Camera" << cameraId.c_str() << "not found"; return -ENODEV; } @@ -339,7 +380,7 @@ int MainWindow::openCamera() } /* Set the combo-box entry with the currently selected Camera. */ - cameraCombo_->setCurrentText(QString::fromStdString(cameraName)); + cameraCombo_->setCurrentText(QString::fromStdString(cameraName(camera_.get()))); return 0; } @@ -604,7 +645,7 @@ void MainWindow::processHotplug(HotplugEvent *e) HotplugEvent::PlugEvent event = e->hotplugEvent(); if (event == HotplugEvent::HotPlug) { - cameraCombo_->addItem(QString::fromStdString(camera->id())); + cameraCombo_->addItem(QString::fromStdString(cameraName(camera))); } else if (event == HotplugEvent::HotUnplug) { /* Check if the currently-streaming camera is removed. */ if (camera == camera_.get()) { @@ -614,7 +655,7 @@ void MainWindow::processHotplug(HotplugEvent *e) cameraCombo_->setCurrentIndex(0); } - int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); + int camIndex = cameraCombo_->findText(QString::fromStdString(cameraName(camera))); cameraCombo_->removeItem(camIndex); } } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 3fbe872c..b31c584f 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -70,7 +70,7 @@ private Q_SLOTS: private: int createToolbars(); - + std::string cameraName(const libcamera::Camera *camera); std::string chooseCamera(); int openCamera();