mirror of
https://github.com/gtalent/sc9k.git
synced 2025-12-26 09:51:32 -06:00
Add settings dialog, camera controls
This commit is contained in:
54
src/cameraclient.cpp
Normal file
54
src/cameraclient.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2021 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
|
||||
#include "settingsdata.hpp"
|
||||
#include "cameraclient.hpp"
|
||||
|
||||
CameraClient::CameraClient(QObject *parent): QObject(parent) {
|
||||
setBaseUrl();
|
||||
m_pollTimer.start(1000);
|
||||
connect(&m_pollTimer, &QTimer::timeout, this, &CameraClient::poll);
|
||||
connect(m_pollingNam, &QNetworkAccessManager::finished, this, &CameraClient::handlePollResponse);
|
||||
}
|
||||
|
||||
void CameraClient::setPreset(int preset) {
|
||||
if (preset > -1) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset));
|
||||
}
|
||||
}
|
||||
|
||||
void CameraClient::setBaseUrl() {
|
||||
const auto [host, port] = getCameraConnectionData();
|
||||
m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port));
|
||||
}
|
||||
|
||||
void CameraClient::get(QString const&urlExt) {
|
||||
QUrl url(QString(m_baseUrl) + urlExt);
|
||||
QNetworkRequest rqst(url);
|
||||
auto reply = m_nam->get(rqst);
|
||||
connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater);
|
||||
}
|
||||
|
||||
void CameraClient::poll() {
|
||||
QUrl url(QString(m_baseUrl) + "/cgi-bin/param.cgi?get_device_conf");
|
||||
QNetworkRequest rqst(url);
|
||||
m_pollingNam->get(rqst);
|
||||
}
|
||||
|
||||
void CameraClient::handlePollResponse(QNetworkReply *reply) {
|
||||
reply->deleteLater();
|
||||
if (reply->error()) {
|
||||
qDebug() << "CameraClient error response:" << reply->errorString();
|
||||
emit pollFailed();
|
||||
return;
|
||||
}
|
||||
emit pollUpdate();
|
||||
}
|
||||
Reference in New Issue
Block a user