[libcamera-devel,v8,4/8] qcam: CamSelectDialog: Display Location and Model propety of camera
diff mbox series

Message ID 20220810150349.414043-5-utkarsh02t@gmail.com
State Accepted
Headers show
Series
  • Introduce capture scripts to qcam
Related show

Commit Message

Utkarsh Tiwari Aug. 10, 2022, 3:03 p.m. UTC
The camera selection dialog currently only displays the camera Id.
Display the camera location and camera model if available.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
Difference from v7:
	1. Nothing
 src/qcam/cam_select_dialog.cpp | 52 ++++++++++++++++++++++++++++++++++
 src/qcam/cam_select_dialog.h   | 10 +++++++
 2 files changed, 62 insertions(+)

Comments

Utkarsh Tiwari Aug. 15, 2022, 4:43 p.m. UTC | #1
On Wed, Aug 10, 2022 at 8:34 PM Utkarsh Tiwari <utkarsh02t@gmail.com> wrote:

> The camera selection dialog currently only displays the camera Id.
> Display the camera location and camera model if available.
>
> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
> Difference from v7:
>         1. Nothing
>  src/qcam/cam_select_dialog.cpp | 52 ++++++++++++++++++++++++++++++++++
>  src/qcam/cam_select_dialog.h   | 10 +++++++
>  2 files changed, 62 insertions(+)
>
> diff --git a/src/qcam/cam_select_dialog.cpp
> b/src/qcam/cam_select_dialog.cpp
> index d8982800..f97ad6eb 100644
> --- a/src/qcam/cam_select_dialog.cpp
> +++ b/src/qcam/cam_select_dialog.cpp
> @@ -7,6 +7,7 @@
>
>  #include "cam_select_dialog.h"
>
> +#include <memory>
>  #include <string>
>
>  #include <libcamera/camera.h>
> @@ -30,6 +31,14 @@
> CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager
> *cameraManag
>         for (const auto &cam : cm_->cameras())
>
> cameraIdComboBox_->addItem(QString::fromStdString(cam->id()));
>
> +       /* Set camera information labels. */
> +       cameraLocation_ = new QLabel;
> +       cameraModel_ = new QLabel;
> +
> +       handleCameraChange();
> +       connect(cameraIdComboBox_, &QComboBox::currentTextChanged,
> +               this, &CameraSelectorDialog::handleCameraChange);
> +
>         /* Setup the QDialogButton Box */
>         QDialogButtonBox *buttonBox =
>                 new QDialogButtonBox(QDialogButtonBox::Ok |
> @@ -41,7 +50,10 @@
> CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager
> *cameraManag
>                 this, &QDialog::reject);
>
>         /* Set the layout. */
> +
>         layout->addRow("Camera:", cameraIdComboBox_);
> +       layout->addRow("Location:", cameraLocation_);
> +       layout->addRow("Model:", cameraModel_);
>         layout->addWidget(buttonBox);
>  }
>
> @@ -63,3 +75,43 @@ void
> CameraSelectorDialog::cameraRemoved(libcamera::Camera *camera)
>
>         cameraIdComboBox_->removeItem(cameraIndex);
>  }
> +
> +/* Camera Information */
> +void CameraSelectorDialog::handleCameraChange()
> +{
> +       updateCamInfo(cm_->get(getCameraId()));
> +}
>

This function can be  removed and we can shift the cm_->get(getCameraId())
in the updateCamInfo
itself.

> +
> +void CameraSelectorDialog::updateCamInfo(const
> std::shared_ptr<libcamera::Camera> &camera)
> +{
> +       if (!camera)
> +               return;
> +
> +       const libcamera::ControlList &cameraProperties =
> camera->properties();
> +
> +       const auto &location =
> +               cameraProperties.get(libcamera::properties::Location);
> +       if (location) {
> +               switch (*location) {
> +               case libcamera::properties::CameraLocationFront:
> +                       cameraLocation_->setText("Internal front camera");
> +                       break;
> +               case libcamera::properties::CameraLocationBack:
> +                       cameraLocation_->setText("Internal back camera");
> +                       break;
> +               case libcamera::properties::CameraLocationExternal:
> +                       cameraLocation_->setText("External camera");
> +                       break;
> +               default:
> +                       cameraLocation_->setText("Unknown");
> +               }
> +       } else {
> +               cameraLocation_->setText("Unknown");
> +       }
> +
> +       const auto &model = cameraProperties
> +                                   .get(libcamera::properties::Model)
> +                                   .value_or("Unknown");
> +
> +       cameraModel_->setText(QString::fromStdString(model));
> +}
> diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
> index 04c71fd8..16475af6 100644
> --- a/src/qcam/cam_select_dialog.h
> +++ b/src/qcam/cam_select_dialog.h
> @@ -11,9 +11,12 @@
>
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
> +#include <libcamera/controls.h>
> +#include <libcamera/property_ids.h>
>
>  #include <QComboBox>
>  #include <QDialog>
> +#include <QLabel>
>
>  class CameraSelectorDialog : public QDialog
>  {
> @@ -30,9 +33,16 @@ public:
>         void cameraAdded(libcamera::Camera *camera);
>
>         void cameraRemoved(libcamera::Camera *camera);
> +
> +       /* Camera Information */
> +       void updateCamInfo(const std::shared_ptr<libcamera::Camera>
> &camera);
> +       void handleCameraChange();
> +
>  private:
>         libcamera::CameraManager *cm_;
>
>         /* UI elements. */
>         QComboBox *cameraIdComboBox_;
> +       QLabel *cameraLocation_;
> +       QLabel *cameraModel_;
>  };
> --
> 2.25.1
>
>
Laurent Pinchart Aug. 23, 2022, 2:09 a.m. UTC | #2
Hi Utkarsh,

Thank you for the patch.

On Mon, Aug 15, 2022 at 10:13:49PM +0530, Utkarsh Tiwari via libcamera-devel wrote:
> On Wed, Aug 10, 2022 at 8:34 PM Utkarsh Tiwari <utkarsh02t@gmail.com> wrote:
> 
> > The camera selection dialog currently only displays the camera Id.
> > Display the camera location and camera model if available.
> >
> > Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> > Difference from v7:
> >         1. Nothing
> >  src/qcam/cam_select_dialog.cpp | 52 ++++++++++++++++++++++++++++++++++
> >  src/qcam/cam_select_dialog.h   | 10 +++++++
> >  2 files changed, 62 insertions(+)
> >
> > diff --git a/src/qcam/cam_select_dialog.cpp
> > b/src/qcam/cam_select_dialog.cpp
> > index d8982800..f97ad6eb 100644
> > --- a/src/qcam/cam_select_dialog.cpp
> > +++ b/src/qcam/cam_select_dialog.cpp
> > @@ -7,6 +7,7 @@
> >
> >  #include "cam_select_dialog.h"
> >
> > +#include <memory>
> >  #include <string>
> >
> >  #include <libcamera/camera.h>
> > @@ -30,6 +31,14 @@ CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManag
> >         for (const auto &cam : cm_->cameras())
> > 		cameraIdComboBox_->addItem(QString::fromStdString(cam->id()));
> >
> > +       /* Set camera information labels. */
> > +       cameraLocation_ = new QLabel;
> > +       cameraModel_ = new QLabel;
> > +
> > +       handleCameraChange();
> > +       connect(cameraIdComboBox_, &QComboBox::currentTextChanged,
> > +               this, &CameraSelectorDialog::handleCameraChange);
> > +
> >         /* Setup the QDialogButton Box */
> >         QDialogButtonBox *buttonBox =
> >                 new QDialogButtonBox(QDialogButtonBox::Ok |
> > @@ -41,7 +50,10 @@ CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManag
> >                 this, &QDialog::reject);
> >
> >         /* Set the layout. */
> > +

No need for a blank line.

> >         layout->addRow("Camera:", cameraIdComboBox_);
> > +       layout->addRow("Location:", cameraLocation_);
> > +       layout->addRow("Model:", cameraModel_);
> >         layout->addWidget(buttonBox);
> >  }
> >
> > @@ -63,3 +75,43 @@ void CameraSelectorDialog::cameraRemoved(libcamera::Camera *camera)
> >
> >         cameraIdComboBox_->removeItem(cameraIndex);
> >  }
> > +
> > +/* Camera Information */
> > +void CameraSelectorDialog::handleCameraChange()
> > +{
> > +       updateCamInfo(cm_->get(getCameraId()));
> > +}
> 
> This function can be  removed and we can shift the cm_->get(getCameraId())
> in the updateCamInfo
> itself.

Indeed.

> > +void CameraSelectorDialog::updateCamInfo(const std::shared_ptr<libcamera::Camera> &camera)
> > +{
> > +       if (!camera)
> > +               return;
> > +
> > +       const libcamera::ControlList &cameraProperties = camera->properties();

You can call the variable just 'properties', that will shorten lines
below.

> > +
> > +       const auto &location =
> > +               cameraProperties.get(libcamera::properties::Location);
> > +       if (location) {
> > +               switch (*location) {
> > +               case libcamera::properties::CameraLocationFront:
> > +                       cameraLocation_->setText("Internal front camera");
> > +                       break;
> > +               case libcamera::properties::CameraLocationBack:
> > +                       cameraLocation_->setText("Internal back camera");
> > +                       break;
> > +               case libcamera::properties::CameraLocationExternal:
> > +                       cameraLocation_->setText("External camera");
> > +                       break;
> > +               default:
> > +                       cameraLocation_->setText("Unknown");
> > +               }
> > +       } else {
> > +               cameraLocation_->setText("Unknown");
> > +       }
> > +
> > +       const auto &model = cameraProperties
> > +                                   .get(libcamera::properties::Model)
> > +                                   .value_or("Unknown");
> > +
> > +       cameraModel_->setText(QString::fromStdString(model));
> > +}
> > diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
> > index 04c71fd8..16475af6 100644
> > --- a/src/qcam/cam_select_dialog.h
> > +++ b/src/qcam/cam_select_dialog.h
> > @@ -11,9 +11,12 @@
> >
> >  #include <libcamera/camera.h>
> >  #include <libcamera/camera_manager.h>
> > +#include <libcamera/controls.h>
> > +#include <libcamera/property_ids.h>
> >
> >  #include <QComboBox>
> >  #include <QDialog>
> > +#include <QLabel>

QLabel can be forward-declared.

> >
> >  class CameraSelectorDialog : public QDialog
> >  {
> > @@ -30,9 +33,16 @@ public:
> >         void cameraAdded(libcamera::Camera *camera);
> >
> >         void cameraRemoved(libcamera::Camera *camera);
> > +
> > +       /* Camera Information */
> > +       void updateCamInfo(const std::shared_ptr<libcamera::Camera> &camera);

You should include <memory>, but the best would probably be to pass a
normal pointer to the camera to this function, calling camera.get() in
the caller.

> > +       void handleCameraChange();
> > +
> >  private:
> >         libcamera::CameraManager *cm_;
> >
> >         /* UI elements. */
> >         QComboBox *cameraIdComboBox_;
> > +       QLabel *cameraLocation_;
> > +       QLabel *cameraModel_;
> >  };
> >

Patch
diff mbox series

diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp
index d8982800..f97ad6eb 100644
--- a/src/qcam/cam_select_dialog.cpp
+++ b/src/qcam/cam_select_dialog.cpp
@@ -7,6 +7,7 @@ 
 
 #include "cam_select_dialog.h"
 
+#include <memory>
 #include <string>
 
 #include <libcamera/camera.h>
@@ -30,6 +31,14 @@  CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManag
 	for (const auto &cam : cm_->cameras())
 		cameraIdComboBox_->addItem(QString::fromStdString(cam->id()));
 
+	/* Set camera information labels. */
+	cameraLocation_ = new QLabel;
+	cameraModel_ = new QLabel;
+
+	handleCameraChange();
+	connect(cameraIdComboBox_, &QComboBox::currentTextChanged,
+		this, &CameraSelectorDialog::handleCameraChange);
+
 	/* Setup the QDialogButton Box */
 	QDialogButtonBox *buttonBox =
 		new QDialogButtonBox(QDialogButtonBox::Ok |
@@ -41,7 +50,10 @@  CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManag
 		this, &QDialog::reject);
 
 	/* Set the layout. */
+
 	layout->addRow("Camera:", cameraIdComboBox_);
+	layout->addRow("Location:", cameraLocation_);
+	layout->addRow("Model:", cameraModel_);
 	layout->addWidget(buttonBox);
 }
 
@@ -63,3 +75,43 @@  void CameraSelectorDialog::cameraRemoved(libcamera::Camera *camera)
 
 	cameraIdComboBox_->removeItem(cameraIndex);
 }
+
+/* Camera Information */
+void CameraSelectorDialog::handleCameraChange()
+{
+	updateCamInfo(cm_->get(getCameraId()));
+}
+
+void CameraSelectorDialog::updateCamInfo(const std::shared_ptr<libcamera::Camera> &camera)
+{
+	if (!camera)
+		return;
+
+	const libcamera::ControlList &cameraProperties = camera->properties();
+
+	const auto &location =
+		cameraProperties.get(libcamera::properties::Location);
+	if (location) {
+		switch (*location) {
+		case libcamera::properties::CameraLocationFront:
+			cameraLocation_->setText("Internal front camera");
+			break;
+		case libcamera::properties::CameraLocationBack:
+			cameraLocation_->setText("Internal back camera");
+			break;
+		case libcamera::properties::CameraLocationExternal:
+			cameraLocation_->setText("External camera");
+			break;
+		default:
+			cameraLocation_->setText("Unknown");
+		}
+	} else {
+		cameraLocation_->setText("Unknown");
+	}
+
+	const auto &model = cameraProperties
+				    .get(libcamera::properties::Model)
+				    .value_or("Unknown");
+
+	cameraModel_->setText(QString::fromStdString(model));
+}
diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
index 04c71fd8..16475af6 100644
--- a/src/qcam/cam_select_dialog.h
+++ b/src/qcam/cam_select_dialog.h
@@ -11,9 +11,12 @@ 
 
 #include <libcamera/camera.h>
 #include <libcamera/camera_manager.h>
+#include <libcamera/controls.h>
+#include <libcamera/property_ids.h>
 
 #include <QComboBox>
 #include <QDialog>
+#include <QLabel>
 
 class CameraSelectorDialog : public QDialog
 {
@@ -30,9 +33,16 @@  public:
 	void cameraAdded(libcamera::Camera *camera);
 
 	void cameraRemoved(libcamera::Camera *camera);
+
+	/* Camera Information */
+	void updateCamInfo(const std::shared_ptr<libcamera::Camera> &camera);
+	void handleCameraChange();
+
 private:
 	libcamera::CameraManager *cm_;
 
 	/* UI elements. */
 	QComboBox *cameraIdComboBox_;
+	QLabel *cameraLocation_;
+	QLabel *cameraModel_;
 };