From patchwork Wed May 6 10:33:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 3691 Return-Path: Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E7D2A603F2 for ; Wed, 6 May 2020 12:33:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="jtje/80o"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=YOzeV9I0yRCuhBhV55Ws1NbDSeCQGxCmgAVL0q5ysaE=; b=jtje/80o3Ku1vQc6g82jTIXcGCV4jRBKtvAb1W/kr2AVD6smFQGTN9fK6mE8Q2m7JMhz yha/UEaKOocQgrDRUa9FpLCPK/dRDbOn2ucIEkeGzWjbu5D77pKnHOBiYpH0zclOg/jVcL M3o4SLesMrzuCU5jRVDBU8ynidq1qSeT4= Received: by filter0135p3las1.sendgrid.net with SMTP id filter0135p3las1-28320-5EB29293-45 2020-05-06 10:33:55.453271144 +0000 UTC m=+1773090.744415389 Received: from mail.uajain.com (unknown) by ismtpd0005p1hnd1.sendgrid.net (SG) with ESMTP id oB1VGW0fSQGdyZH1_tqsxQ for ; Wed, 06 May 2020 10:33:54.946 +0000 (UTC) From: Umang Jain Date: Wed, 06 May 2020 10:33:55 +0000 (UTC) Message-Id: <20200506103346.3433-4-email@uajain.com> In-Reply-To: <20200506103346.3433-1-email@uajain.com> References: <20200506103346.3433-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcHcG1g99dnq0SJ9KzJgHEPq0KUG1dy9EmNymiHJrtKW61eXuBmqlYgdA/DCg/Df/zF8XfxjcYG4KGtvldMEXReScn5tVjNs0JYiWUAD+Zc02gAIwZ1T/lL7QDkhChpE98EahJ5S/jIUrr7fYLgfhb6BSgYCzY8axiTccO0xO7G2Vdv9mG9jwLklSjB71Hx6II To: libcamera-devel Subject: [libcamera-devel] [PATCH 3/4] qcam: main_window: Introduce hotplug support 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-List-Received-Date: Wed, 06 May 2020 10:33:57 -0000 Signed-off-by: Umang Jain --- src/qcam/main_window.cpp | 31 +++++++++++++++++++++++++++++++ src/qcam/main_window.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7de0895..9db1647 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -71,6 +71,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) setCentralWidget(viewfinder_); adjustSize(); + /* Hotplug/unplug support */ + cm_->cameraAdded.connect(this, &MainWindow::addNewCamera); + cm_->cameraRemoved.connect(this, &MainWindow::removeCamera); + /* Open the camera and start capture. */ ret = openCamera(); if (ret < 0) { @@ -525,6 +529,33 @@ void MainWindow::stopCapture() setWindowTitle(title_); } +/* ----------------------------------------------------------------------------- + * Camera hotplugging support + */ + +void MainWindow::addNewCamera(Camera *cam) +{ + qInfo() << "Adding new camera: " << cam->name().c_str(); + cameraCombo_->addItem(QString::fromStdString(cam->name())); +} + +void MainWindow::removeCamera(Camera *cam) +{ + int camIndex = cameraCombo_->findText(QString::fromStdString(cam->name())); + + /* Check if the currently-streaming camera is removed. + * + * \todo Also analyse the edge-case where the only available + * camera is removed. */ + if (camIndex == cameraCombo_->currentIndex()) { + toggleCapture(false); + cameraCombo_->setCurrentIndex(0); + } + + qInfo() << "Removing camera: " << cam->name().c_str(); + cameraCombo_->removeItem(camIndex); +} + /* ----------------------------------------------------------------------------- * Image Save */ diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 59fa2d9..cb2fa26 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -87,6 +87,9 @@ private: int startCapture(); void stopCapture(); + void addNewCamera(Camera *camera); + void removeCamera(Camera *camera); + void requestComplete(Request *request); void processCapture(); void processViewfinder(FrameBuffer *buffer);