Skip to content

Commit

Permalink
code cleanup (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
infra-monkey authored Feb 20, 2022
1 parent 465ffd0 commit 6138f5d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 75 deletions.
11 changes: 5 additions & 6 deletions QWebcamSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ void QWebcamSettings::populateDeviceList() {
if (!m_config_grouplist.contains(serial)){
VideoDevice* new_device = new VideoDevice(cameraInfo,serial,vendorid,modelid);
m_device_list.append(new_device);
// m_device_list.append(VideoDevice(serial,cameraInfo.description(),cameraInfo.deviceName(),vendorid,modelid));
m_devicename_list << cameraInfo.description();
}
}
Expand Down Expand Up @@ -335,11 +334,11 @@ void QWebcamSettings::resetCrtlToDefault(QString ctrl_name) {
if (ctrl_name == "saturation") {
if (ret) {Q_EMIT saturationChanged();}
}
if (ctrl_name == "zoom_absolute") {
if (ret) {
Q_EMIT opticalZoomChanged();
Q_EMIT digitalZoomChanged();
}
if (ctrl_name == "zoom_optical") {
if (ret) {Q_EMIT opticalZoomChanged();}
}
if (ctrl_name == "zoom_digital") {
if (ret) {Q_EMIT digitalZoomChanged();}
}
if (ctrl_name == "focus_automatic_continuous") {
if (ret) {Q_EMIT autoFocusChanged();}
Expand Down
28 changes: 2 additions & 26 deletions QWebcamSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,18 @@ class QWebcamSettings : public KQuickAddons::ConfigModule

Q_PROPERTY(qreal brightness READ getBrightness WRITE setBrightness NOTIFY brightnessChanged)
Q_PROPERTY(int brightness_spin READ getBrightnessSpin NOTIFY brightnessChanged)
// Q_PROPERTY(qreal brightness_min READ getBrightnessMin NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal brightness_max READ getBrightnessMax NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal brightness_step READ getBrightnessStep NOTIFY deviceIndexChanged)
Q_PROPERTY(qreal brightness_visible READ getBrightnessVisible NOTIFY deviceIndexChanged)

Q_PROPERTY(qreal contrast READ getContrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(int contrast_spin READ getContrastSpin NOTIFY contrastChanged)
// Q_PROPERTY(qreal contrast_min READ getContrastMin NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal contrast_max READ getContrastMax NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal contrast_step READ getContrastStep NOTIFY deviceIndexChanged)
Q_PROPERTY(qreal contrast_visible READ getContrastVisible NOTIFY deviceIndexChanged)

Q_PROPERTY(qreal sharpness READ getSharpness WRITE setSharpness NOTIFY sharpnessChanged)
Q_PROPERTY(int sharpness_spin READ getSharpnessSpin NOTIFY sharpnessChanged)
// Q_PROPERTY(qreal sharpness_min READ getSharpnessMin NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal sharpness_max READ getSharpnessMax NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal sharpness_step READ getSharpnessStep NOTIFY deviceIndexChanged)
Q_PROPERTY(qreal sharpness_visible READ getSharpnessVisible NOTIFY deviceIndexChanged)

Q_PROPERTY(qreal saturation READ getSaturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(int saturation_spin READ getSaturationSpin NOTIFY saturationChanged)
// Q_PROPERTY(qreal saturation_min READ getSaturationMin NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal saturation_max READ getSaturationMax NOTIFY deviceIndexChanged)
// Q_PROPERTY(qreal saturation_step READ getSaturationStep NOTIFY deviceIndexChanged)
Q_PROPERTY(qreal saturation_visible READ getSaturationVisible NOTIFY deviceIndexChanged)

Q_PROPERTY(qreal optical_zoom READ getOpticalZoom WRITE setOpticalZoom NOTIFY opticalZoomChanged)
Expand Down Expand Up @@ -92,33 +80,21 @@ class QWebcamSettings : public KQuickAddons::ConfigModule
int getFormatIndex(){return this->m_current_device->getFormatIndex();};
qreal getBrightness() {return this->m_current_device->getBrightness();};
int getBrightnessSpin() {return (int)(this->m_current_device->getBrightness() * 100);};
// qreal getBrightnessMin() {return this->m_current_device->getBrightnessMin();};
// qreal getBrightnessMax() {return this->m_current_device->getBrightnessMax();};
// qreal getBrightnessStep() {return this->m_current_device->getBrightnessStep();};
bool getBrightnessVisible() {return this->m_current_device->getBrightnessVisible();};
qreal getContrast() {return this->m_current_device->getContrast();};
qreal getContrastSpin() {return (int)(this->m_current_device->getContrast() * 100);};
// qreal getContrastMin() {return this->m_current_device->getContrastMin();};
// qreal getContrastMax() {return this->m_current_device->getContrastMax();};
// qreal getContrastStep() {return this->m_current_device->getContrastStep();};
bool getContrastVisible() {return this->m_current_device->getContrastVisible();};
qreal getSharpness() {return this->m_current_device->getSharpness();};
int getSharpnessSpin() {return (int)(this->m_current_device->getSharpness() * 100);};
// qreal getSharpnessMin() {return this->m_current_device->getSharpnessMin();};
// qreal getSharpnessMax() {return this->m_current_device->getSharpnessMax();};
// qreal getSharpnessStep() {return this->m_current_device->getSharpnessStep();};
bool getSharpnessVisible() {return this->m_current_device->getSharpnessVisible();};
qreal getSaturation() {return this->m_current_device->getSaturation();};
int getSaturationSpin() {return (int)(this->m_current_device->getSaturation() * 100);};
// qreal getSaturationMin() {return this->m_current_device->getSaturationMin();};
// qreal getSaturationMax() {return this->m_current_device->getSaturationMax();};
// qreal getSaturationStep() {return this->m_current_device->getSaturationStep();};
bool getSaturationVisible() {return this->m_current_device->getSaturationVisible();};
qreal getOpticalZoom() {return this->m_current_device->getOpticalZoom();};
qreal getOpticalZoomMax() {return this->m_current_device->getOpticalZoomMax();};
bool getOpticalZoomVisible() {return this->m_current_device->getOpticalZoomVisible();};
qreal getDigitalZoom() {return this->m_current_device->getDigitalZoom();};
qreal getDigitalZoomPrev() {qCDebug(webcam_settings_kcm) << "QWebcamSettings::getDigitalZoomPrev" << 1+(this->m_current_device->getDigitalZoom()/10);return 1+(this->m_current_device->getDigitalZoom()/10);};
qreal getDigitalZoomPrev() {return 1+(this->m_current_device->getDigitalZoom()/10);};
qreal getDigitalZoomMax() {return this->m_current_device->getDigitalZoomMax();};
bool getDigitalZoomVisible() {return this->m_current_device->getDigitalZoomVisible();};
int getAutoFocus(){return this->m_current_device->getAutoFocus();};
Expand All @@ -127,7 +103,7 @@ class QWebcamSettings : public KQuickAddons::ConfigModule
qreal getFocusMin() {return this->m_current_device->getFocusMin();};
qreal getFocusMax() {return this->m_current_device->getFocusMax();};
qreal getFocusStep() {return this->m_current_device->getFocusStep();};
bool getFocusVisible() {qCDebug(webcam_settings_kcm) << "QWebcamSettings::getFocusVisible" << this->m_current_device->getFocusVisible();return this->m_current_device->getFocusVisible();};
bool getFocusVisible() {return this->m_current_device->getFocusVisible();};
void load() override;
void save() override;
void defaults() override;
Expand Down
4 changes: 0 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
code:
load values from saved data if available.

UI:
allow to preview the camera in the page
1 change: 0 additions & 1 deletion UdevHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ActionReply UdevHelper::applyudevrules(const QVariantMap &args)
}
std::string("udevadm control --reload-rules");
exec_cmd(cmd);
//reply.addData("contents", args["contents"].toStringList());
return reply;
}

Expand Down
22 changes: 9 additions & 13 deletions VideoDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ VideoDevice::VideoDevice(const QCameraInfo camerainfo,QString device_serial, QSt
qCDebug(webcam_settings_kcm) << "VideoDevice::VideoDevice" << m_device_name << m_device_path << m_device_vendor_id << m_device_model_id;
initializeCtrls();
initializeFormats();
// m_current_format_index = 0;
}
VideoDevice::~VideoDevice() {}

Expand All @@ -38,7 +37,6 @@ void VideoDevice::initializeCtrls() {
}

void VideoDevice::initializeCtrl(const QString ctrl_label) {
// qCDebug(webcam_settings_kcm) << "VideoDevice::initializeCtrl for device " << m_device_name;
bool is_defined;
std::string line,cmd;
if (m_is_dummy_device){
Expand All @@ -55,7 +53,6 @@ void VideoDevice::initializeCtrl(const QString ctrl_label) {
if (ctrl_label == "brightness") {
m_ctrl_brightness_visible = is_defined;
m_ctrl_brightness["value"] = 0;
// m_ctrl_brightness["default"] = 0;
m_ctrl_brightness["min"] = 0;
m_ctrl_brightness["max"] = 0;
m_ctrl_brightness["step"] = 0;
Expand Down Expand Up @@ -186,7 +183,6 @@ void VideoDevice::initializeCtrl(const QString ctrl_label) {
<< "max: " << m_ctrl_focus["max"]
<< "step: " << m_ctrl_focus["step"]
<< "default: " << m_ctrl_focus["default"];
qCDebug(webcam_settings_kcm) << "VideoDevice::initializeCtrl Focus Absolute: value: " << m_ctrl_focus_visible;
}
}

Expand Down Expand Up @@ -339,7 +335,7 @@ bool VideoDevice::setSaturation(qreal value){
}

void VideoDevice::setZoom(qreal optical_value,qreal digital_value){
qCDebug(webcam_settings_kcm) << "VideoDevice::setAbsoluteZoom" << optical_value << digital_value;
qCDebug(webcam_settings_kcm) << "VideoDevice::setZoom" << optical_value << digital_value;
m_current_camera->focus()->zoomTo(optical_value,digital_value);
}

Expand Down Expand Up @@ -405,8 +401,10 @@ bool VideoDevice::resetCrtlToDefault(QString ctrl_name) {
if (ctrl_name == "saturation") {
ret = setSaturation(0);
}
if (ctrl_name == "zoom_absolute") {
if (ctrl_name == "zoom_optical") {
ret = setOpticalZoom(0);
}
if (ctrl_name == "zoom_digital") {
ret = setDigitalZoom(0);
}
if (ctrl_name == "focus_automatic_continuous") {
Expand Down Expand Up @@ -458,12 +456,13 @@ QString VideoDevice::getCtrlOptions(){
return ctrl_options;
}


//Still needed for the focus controls. To be changed if possible
void VideoDevice::applyControlValue(QString ctrl_name,QString value){
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue";
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + ctrl_name + "=" + value;
std::string cmd;
cmd = std::string("v4l2-ctl -d " + getVideoDevicePath().toStdString() + " --set-ctrl " + ctrl_name.toStdString() +"=" + value.toStdString());
exec_cmd(cmd);
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + ctrl_name + "=" + value;
}

int VideoDevice::getControlValueV4L(bool scaled,qreal value, qreal ctrl_max, qreal ctrl_step){
Expand All @@ -477,19 +476,17 @@ int VideoDevice::getControlValueV4L(bool scaled,qreal value, qreal ctrl_max, qre
}
void VideoDevice::applyControlValue(bool scaled,QString ctrl_name,qreal value, qreal ctrl_max, qreal ctrl_step){
int converted_value = getControlValueV4L(scaled,value,ctrl_max,ctrl_step);
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue";
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + ctrl_name + "=" + QString::number(converted_value);
std::string cmd;
cmd = std::string("v4l2-ctl -d " + getVideoDevicePath().toStdString() + " --set-ctrl " + ctrl_name.toStdString() +"=" + std::to_string(converted_value));
exec_cmd(cmd);
qCDebug(webcam_settings_kcm) << "VideoDevice::applyControlValue: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + ctrl_name + "=" + QString::number(converted_value);
}

void VideoDevice::applyConfiguration(){
qCDebug(webcam_settings_kcm) << "VideoDevice::applyConfiguration";
qCDebug(webcam_settings_kcm) << "VideoDevice::applyConfiguration: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + getCtrlOptions() + " --set-fmt-video width=" + QString::number(getCurrentFormatWidth()) + ",height=" + QString::number(getCurrentFormatHeight()) + ",pixelformat=" + getCurrentFormatName() + ",field=none";
std::string cmd;
cmd = std::string("v4l2-ctl -d " + getVideoDevicePath().toStdString() + " --set-ctrl " + getCtrlOptions().toStdString() + " --set-fmt-video width=" + std::to_string(getCurrentFormatWidth()) + ",height=" + std::to_string(getCurrentFormatHeight()) + ",pixelformat=" + getCurrentFormatName().toStdString()) + ",field=none";
exec_cmd(cmd);
qCDebug(webcam_settings_kcm) << "VideoDevice::applyConfiguration: " << "v4l2-ctl -d " + getVideoDevicePath() + " --set-ctrl " + getCtrlOptions() + " --set-fmt-video width=" + QString::number(getCurrentFormatWidth()) + ",height=" + QString::number(getCurrentFormatHeight()) + ",pixelformat=" + getCurrentFormatName() + ",field=none";
}

bool VideoDevice::resetToDefault(){
Expand All @@ -502,7 +499,6 @@ bool VideoDevice::resetToDefault(){
}

QString VideoDevice::getUdevRule(){
qCDebug(webcam_settings_kcm) << "VideoDevice::getUdevRules";
qCDebug(webcam_settings_kcm) << "VideoDevice::getUdevRules for device" << getVideoDevicePath() << getVideoDeviceVendorId() << getVideoDeviceModelId();
qCDebug(webcam_settings_kcm) << "VideoDevice::getUdevRules resolution" << getCurrentFormatName() ;
QString rule = "SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"" + getVideoDeviceVendorId() + "\", ATTRS{idProduct}==\"" + getVideoDeviceModelId() + "\", PROGRAM=\"/usr/bin/v4l2-ctl --set-ctrl " + getCtrlOptions();
Expand Down
20 changes: 2 additions & 18 deletions VideoDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QCamera>
#include <QCameraInfo>
#include <QCameraImageProcessing>
#include <QCameraFocus>

class VideoDevice : public QObject {
public:
Expand All @@ -29,39 +30,23 @@ class VideoDevice : public QObject {
int getFormatIndex(){return m_current_format_index;};
bool setBrightness(qreal);
qreal getBrightness(){return m_ctrl_brightness["value"];};
// double getBrightnessMin(){return m_ctrl_brightness["min"];};
// double getBrightnessMax(){return m_ctrl_brightness["max"];};
// double getBrightnessStep(){return m_ctrl_brightness["step"];};
// double getBrightnessDefault(){return m_ctrl_brightness["default"];};
bool getBrightnessVisible(){return m_ctrl_brightness_visible;};
bool setContrast(qreal);
qreal getContrast(){return m_ctrl_contrast["value"];};
// double getContrastMin(){return m_ctrl_contrast["min"];};
// double getContrastMax(){return m_ctrl_contrast["max"];};
// double getContrastStep(){return m_ctrl_contrast["step"];};
// double getContrastDefault(){return m_ctrl_contrast["default"];};
bool getContrastVisible(){return m_ctrl_contrast_visible;};
bool setSharpness(qreal);
qreal getSharpness(){return m_ctrl_sharpness["value"];};
// double getSharpnessMin(){return m_ctrl_sharpness["min"];};
// double getSharpnessMax(){return m_ctrl_sharpness["max"];};
// double getSharpnessStep(){return m_ctrl_sharpness["step"];};
// double getSharpnessDefault(){return m_ctrl_sharpness["default"];};
bool getSharpnessVisible(){return m_ctrl_sharpness_visible;};
bool setSaturation(qreal);
qreal getSaturation(){return m_ctrl_saturation["value"];};
// double getSaturationMin(){return m_ctrl_saturation["min"];};
// double getSaturationMax(){return m_ctrl_saturation["max"];};
// double getSaturationStep(){return m_ctrl_saturation["step"];};
// double getSaturationDefault(){return m_ctrl_saturation["default"];};
bool getSaturationVisible(){return m_ctrl_saturation_visible;};
bool setOpticalZoom(qreal);
qreal getOpticalZoom(){return m_ctrl_zoom_optical["value"];};
double getOpticalZoomMax(){return m_ctrl_zoom_optical["max"];};
bool getOpticalZoomVisible(){return m_ctrl_zoom_optical_visible;};
bool setDigitalZoom(qreal);
qreal getDigitalZoom(){return m_ctrl_zoom_digital["value"];};
double getDigitalZoomMax(){qCDebug(webcam_settings_kcm) << "VideoDevice::getDigitalZoomMax" << m_ctrl_zoom_digital["max"];return m_ctrl_zoom_digital["max"];};
double getDigitalZoomMax(){return m_ctrl_zoom_digital["max"];};
bool getDigitalZoomVisible(){return m_ctrl_zoom_digital_visible;};
bool setAutoFocus(int);
int getAutoFocus(){return m_ctrl_auto_focus["value"];};
Expand All @@ -74,7 +59,6 @@ class VideoDevice : public QObject {
double getFocusStep(){return m_ctrl_focus["step"];};
double getFocusDefault(){return m_ctrl_focus["default"];};
bool getFocusVisible(){return (!getAutoFocus() && m_ctrl_focus_visible);};
// double getCtrlDefaultValue(QString);
bool resetCrtlToDefault(QString);
QString getCtrlOptions();
void applyConfiguration();
Expand Down
4 changes: 2 additions & 2 deletions kcm_webcam_settings.spec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%global kf5_version 5.85.0
%global qt5_version 5.15.2
Name: {{{ git_dir_name }}}
Version: 0.0.3
Release: 2
Version: 0.0.4
Release: 1
Summary: KDE Plasma system-settings module to configure your webcam
License: GPLv3+
URL: https://github.com/infra-monkey/kcm_webcam_settings
Expand Down
13 changes: 8 additions & 5 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ KCM.SimpleKCM {
}
Kirigami.FormLayout {
id: formId
Layout.fillWidth: true
Controls.CheckBox {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft
visible: true
implicitWidth: 217
implicitHeight: 45
//implicitWidth: 217
//implicitHeight: 45
id: previewCheckbox
checked: false
text: i18n("Preview webcam")
Expand All @@ -170,9 +173,10 @@ KCM.SimpleKCM {
}
Basic.Item {
id: previewSpace

visible: previewCheckbox.checked
implicitWidth: 320
implicitHeight: 180
implicitWidth: 352
implicitHeight: 288
VideoOutput {
id: previewOutput
visible: previewSpace.visible
Expand Down Expand Up @@ -390,7 +394,6 @@ KCM.SimpleKCM {
from: 0
value: kcm.optical_zoom
to: kcm.optical_zoom_max
//stepSize: 5
property int decimals: 2
validator: Basic.DoubleValidator {
bottom: Math.min(opticalZoomSpinbox.from, opticalZoomSpinbox.to)
Expand Down

0 comments on commit 6138f5d

Please sign in to comment.