Commit 6a5da4c9 authored by Leander Schulten's avatar Leander Schulten

New Feature: Remote Volume Control. Add Permission, Settings

parent 6fb683f4
Pipeline #198970 passed with stage
in 5 minutes and 31 seconds
QT += qml quick networkauth network
QT += qml quick networkauth network websockets
CONFIG += c++1z force_debug_info
......@@ -22,6 +22,7 @@ SOURCES += \
audio/aubio/onsetanalysis.cpp \
audio/aubio/tempoanalysis.cpp \
audio/audioeventdata.cpp \
audio/remotevolume.cpp \
audio/systemvolume.cpp \
dmx/channel.cpp \
gui/audioeventdataview.cpp \
......@@ -107,6 +108,7 @@ HEADERS += \
audio/aubio/onsetanalysis.h \
audio/aubio/tempoanalysis.h \
audio/audioeventdata.h \
audio/remotevolume.h \
audio/systemvolume.h \
dmx/deviceprototype.h \
dmx/channel.h \
......
#include "remotevolume.h"
#include "systemvolume.h"
RemoteVolume::RemoteVolume(Settings &settings) : settings(settings) {
QObject::connect(&settings, &Settings::computerNameChanged, [this]() {
if (isConnected()) {
webSocket.sendTextMessage("Name:" + this->settings.getComputerName());
}
});
QObject::connect(&settings, &Settings::remoteVolumeControlChanged, [this]() {
if (this->settings.remoteVolumeControl()) {
if (!isConnected()) {
connect();
}
} else {
webSocket.close();
}
});
QObject::connect(&webSocket, &QWebSocket::connected, [this]() {
webSocket.sendTextMessage("Name:" + this->settings.getComputerName());
webSocket.sendTextMessage("Value:" + QString::number(SystemVolume::get().getVolume()));
});
QObject::connect(&webSocket, &QWebSocket::textMessageReceived, [](const QString &message) {
bool ok;
double vol = message.toDouble(&ok);
if (ok) {
SystemVolume::get().setVolume(vol);
}
});
QObject::connect(&SystemVolume::get(), &SystemVolume::volumeChanged, [this]() {
if (webSocket.isValid()) {
webSocket.sendTextMessage("Value:" + QString::number(SystemVolume::get().getVolume()));
}
});
if (settings.remoteVolumeControl()) {
connect();
}
}
void RemoteVolume::connect() {
webSocket.open(QUrl(QStringLiteral("wss://orga.symposion.hilton.rwth-aachen.de/volumeClient")));
}
#ifndef REMOTEVOLUME_H
#define REMOTEVOLUME_H
#include <QWebSocket>
#include <settings.h>
class RemoteVolume
{
QWebSocket webSocket;
Settings &settings;
public:
RemoteVolume(Settings &settings);
void connect();
[[nodiscard]] bool isConnected() const { return webSocket.isValid(); }
};
#endif // REMOTEVOLUME_H
......@@ -8,6 +8,8 @@
#include "updater.h"
#include "usermanagment.h"
#include "audio/audiocapturemanager.h"
#include "audio/remotevolume.h"
#include "audio/systemvolume.h"
#include "dmx/HardwareInterface.h"
#include "dmx/channel.h"
#include "dmx/device.h"
......@@ -264,6 +266,7 @@ int main(int argc, char *argv[]) {
// Load Settings and ApplicationData
Settings::setLocalSettingFile(QFileInfo(QStringLiteral("settings.ini")));
Settings settings;
RemoteVolume remoteVolume(settings);
QString file(settings.getJsonSettingsFilePath());
if (!QFile::exists(file)) {
file = QStringLiteral("QTJSONFile.json");
......@@ -364,6 +367,7 @@ int main(int argc, char *argv[]) {
engine.rootContext()->setContextProperty(QStringLiteral("dmxOutputValues"),&Driver::dmxValueModel);
engine.rootContext()->setContextProperty(QStringLiteral("AudioManager"), &Audio::AudioCaptureManager::get());
engine.rootContext()->setContextProperty(QStringLiteral("SlideShow"), &SlideShow::get());
engine.rootContext()->setContextProperty(QStringLiteral("System"), &SystemVolume::get());
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/qml/SlideShowWindow.qml")));
......
......@@ -12,7 +12,7 @@ Pane{
GridLayout{
anchors.left: parent.left
anchors.right: parent.right
rowSpacing: 6
rowSpacing: 4
columns: 2
Label{
text: "Settings file path:"
......@@ -238,6 +238,7 @@ Pane{
text: "System Volume:"
}
RowLayout {
Layout.bottomMargin: -10
Label {
text: System.volume < 0 ? "Not availible" : ((volumeSlider.value * 100).toFixed(0) + "%")
Layout.preferredWidth: 30
......@@ -257,6 +258,30 @@ Pane{
}
}
Label {
text: "Remote Volume Control"
}
RowLayout {
Layout.topMargin: -30
Layout.bottomMargin: -30
Layout.leftMargin: -7
enabled: UserManagment.currentUser.havePermission(Permission.ENABLE_REMOTE_VOLUME_CONTROL)
CheckBox {
text: "enabled"
checked: Settings.remoteVolumeControl
onCheckedChanged: Settings.remoteVolumeControl = checked
}
Label {
Layout.leftMargin: 10
text: "Computer Name:"
}
TextInputField {
text: Settings.computerName
onTextChanged: Settings.computerName = text
}
}
}
Loader {
......
......@@ -12,19 +12,64 @@ Settings::Settings(QObject *parent) : QObject(parent), settings(OrganisationName
jsonSettingsFileSavePath = getJsonSettingsFilePath();
}
void Settings::setJsonSettingsFilePath(const QString &file) {
if (file == getJsonSettingsFilePath()) {
setValue(QStringLiteral("jsonSettingsFilePath"), file);
emit jsonSettingsFilePathChanged();
}
}
bool Settings::setJsonSettingsFilePath(const QString &file, bool loadFromPath) {
if (file == getJsonSettingsFilePath()) {
return false;
}
if (loadFromPath) {
if (!QFile::exists(file)) {
return false;
}
// it was load/save path, but we dident loaded and now have a new load path
this->loadFromJsonSettingsFilePath = true;
setValue(QStringLiteral("jsonSettingsFilePath"), file);
emit jsonSettingsFilePathChanged();
} else {
// it was load or save path, but we dident loaded and now want to save
this->loadFromJsonSettingsFilePath = false;
this->jsonSettingsFileSavePath = file;
setValue(QStringLiteral("jsonSettingsFilePath"), file);
emit jsonSettingsFilePathChanged();
emit saveAs(file);
}
return true;
}
void Settings::setComputerName(const QString &name) {
if (name != getComputerName()) {
setValue(QStringLiteral("ComputerName"), name);
emit computerNameChanged();
}
}
void Settings::remoteVolumeControl(bool enable) {
if (enable != remoteVolumeControl()) {
setValue(QStringLiteral("remoteVolumeControl"), enable);
emit remoteVolumeControlChanged();
}
}
void Settings::setValue(const QString &key, const QVariant &value){
if(localSettings){
if(localSettings->contains(key)){
localSettings->setValue(key,value);
if (localSettings) {
if (localSettings->contains(key)) {
localSettings->setValue(key, value);
}
}
settings.setValue(key,value);
settings.setValue(key, value);
}
QVariant Settings::value(const QString &key, const QVariant &defaultValue) const{
if(localSettings){
if(localSettings->contains(key)){
return localSettings->value(key,defaultValue);
if (localSettings) {
if (localSettings->contains(key)) {
return localSettings->value(key, defaultValue);
}
}
return settings.value(key,defaultValue);
return settings.value(key, defaultValue);
}
......@@ -7,6 +7,7 @@
#include <QFile>
#include <QObject>
#include <QSettings>
#include <QSysInfo>
#include <optional>
#define MAKE_STRING(s) #s
......@@ -56,6 +57,8 @@ class Settings : public QObject {
Q_PROPERTY(QString compilerFlags READ getCompilerFlags WRITE setCompilerFlags NOTIFY compilerFlagsChanged)
Q_PROPERTY(QString compilerLibraryFlags READ getCompilerLibraryFlags WRITE setCompilerLibraryFlags NOTIFY compilerLibraryFlagsChanged)
Q_PROPERTY(QString includePath READ getIncludePath WRITE setIncludePath NOTIFY includePathChanged)
Q_PROPERTY(QString computerName READ getComputerName WRITE setComputerName NOTIFY computerNameChanged)
Q_PROPERTY(bool remoteVolumeControl READ remoteVolumeControl WRITE remoteVolumeControl NOTIFY remoteVolumeControlChanged)
Q_PROPERTY(int theme READ getTheme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(unsigned int updatePauseInMs READ getUpdatePauseInMs WRITE setUpdatePauseInMs NOTIFY updatePauseInMsChanged)
static inline QFileInfo localSettingsFile;
......@@ -76,29 +79,26 @@ protected:
public:
explicit Settings(QObject *parent = nullptr);
Q_INVOKABLE bool setJsonSettingsFilePath(const QString &file, bool loadFromPath) {
if(file == getJsonSettingsFilePath()) {
return false;
}
if (loadFromPath) {
if (!QFile::exists(file)) {
return false;
}
// it was load/save path, but we dident loaded and now have a new load path
this->loadFromJsonSettingsFilePath = true;
setValue(QStringLiteral("jsonSettingsFilePath"), file);
emit jsonSettingsFilePathChanged();
} else {
// it was load or save path, but we dident loaded and now want to save
this->loadFromJsonSettingsFilePath = false;
this->jsonSettingsFileSavePath = file;
setValue(QStringLiteral("jsonSettingsFilePath"), file);
emit jsonSettingsFilePathChanged();
emit saveAs(file);
}
return true;
}
/**
* @brief setJsonSettingsFilePath only sets the settings file path to the given path. For an advanced
* variant see setJsonSettingsFilePath(const QString&, bool)
* @param file the new filepath
*/
void setJsonSettingsFilePath(const QString &file);
/**
* @brief setJsonSettingsFilePath sets the settings file path and handles the new file. If loadFromPath is
* true, shouldLoadFromSettingsPath() will return false and getJsonSettingsFileSavePath() will return
* the old path. If loadFromPath is false, shouldLoadFromSettingsPath() will return false. The signal
* saveAs(QString) will be emitted. getJsonSettingsFileSavePath() will return the new path.
*
* @param file the new settings file path
* @param loadFromPath true if the settings should be loaded from the new file, false if the settings should
* be written to the new path
* @return false, if file == getJsonSettingsFilePath() or loadFromPath is true and the file does not exists.
* True otherwise
*/
Q_INVOKABLE bool setJsonSettingsFilePath(const QString &file, bool loadFromPath);
[[nodiscard]] QString getJsonSettingsFilePath() const { return value(QStringLiteral("jsonSettingsFilePath")).toString(); }
/**
* @brief getJsonSettingsFileSavePath returns the path, to which the settings file should be written
......@@ -181,6 +181,12 @@ public:
}
QString getCompilerLibraryFlags() const { return Modules::Compiler::compilerLibraryFlags; }
void setComputerName(const QString &name);
[[nodiscard]] QString getComputerName() const { return value(QStringLiteral("ComputerName"), QSysInfo::machineHostName()).toString(); }
void remoteVolumeControl(bool enable);
[[nodiscard]] bool remoteVolumeControl() const { return value(QStringLiteral("remoteVolumeControl"), false).toBool(); }
void setTheme(int theme) {
if (theme != getTheme()) {
setValue(QStringLiteral("theme"), theme);
......@@ -228,6 +234,8 @@ signals:
void includePathChanged();
void themeChanged();
void saveAs(QString path);
void computerNameChanged();
void remoteVolumeControlChanged();
public slots:
};
......
......@@ -81,6 +81,7 @@ public:
MODIFY_THEME = 27,
SAVE_SLIDE_SHOW_SETTINGS = 28,
CHANGE_SYSTEM_VOLUME = 29,
ENABLE_REMOTE_VOLUME_CONTROL = 30,
};
Q_ENUM(Permission)
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment