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 CONFIG += c++1z force_debug_info
...@@ -22,6 +22,7 @@ SOURCES += \ ...@@ -22,6 +22,7 @@ SOURCES += \
audio/aubio/onsetanalysis.cpp \ audio/aubio/onsetanalysis.cpp \
audio/aubio/tempoanalysis.cpp \ audio/aubio/tempoanalysis.cpp \
audio/audioeventdata.cpp \ audio/audioeventdata.cpp \
audio/remotevolume.cpp \
audio/systemvolume.cpp \ audio/systemvolume.cpp \
dmx/channel.cpp \ dmx/channel.cpp \
gui/audioeventdataview.cpp \ gui/audioeventdataview.cpp \
...@@ -107,6 +108,7 @@ HEADERS += \ ...@@ -107,6 +108,7 @@ HEADERS += \
audio/aubio/onsetanalysis.h \ audio/aubio/onsetanalysis.h \
audio/aubio/tempoanalysis.h \ audio/aubio/tempoanalysis.h \
audio/audioeventdata.h \ audio/audioeventdata.h \
audio/remotevolume.h \
audio/systemvolume.h \ audio/systemvolume.h \
dmx/deviceprototype.h \ dmx/deviceprototype.h \
dmx/channel.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 @@ ...@@ -8,6 +8,8 @@
#include "updater.h" #include "updater.h"
#include "usermanagment.h" #include "usermanagment.h"
#include "audio/audiocapturemanager.h" #include "audio/audiocapturemanager.h"
#include "audio/remotevolume.h"
#include "audio/systemvolume.h"
#include "dmx/HardwareInterface.h" #include "dmx/HardwareInterface.h"
#include "dmx/channel.h" #include "dmx/channel.h"
#include "dmx/device.h" #include "dmx/device.h"
...@@ -264,6 +266,7 @@ int main(int argc, char *argv[]) { ...@@ -264,6 +266,7 @@ int main(int argc, char *argv[]) {
// Load Settings and ApplicationData // Load Settings and ApplicationData
Settings::setLocalSettingFile(QFileInfo(QStringLiteral("settings.ini"))); Settings::setLocalSettingFile(QFileInfo(QStringLiteral("settings.ini")));
Settings settings; Settings settings;
RemoteVolume remoteVolume(settings);
QString file(settings.getJsonSettingsFilePath()); QString file(settings.getJsonSettingsFilePath());
if (!QFile::exists(file)) { if (!QFile::exists(file)) {
file = QStringLiteral("QTJSONFile.json"); file = QStringLiteral("QTJSONFile.json");
...@@ -364,6 +367,7 @@ int main(int argc, char *argv[]) { ...@@ -364,6 +367,7 @@ int main(int argc, char *argv[]) {
engine.rootContext()->setContextProperty(QStringLiteral("dmxOutputValues"),&Driver::dmxValueModel); engine.rootContext()->setContextProperty(QStringLiteral("dmxOutputValues"),&Driver::dmxValueModel);
engine.rootContext()->setContextProperty(QStringLiteral("AudioManager"), &Audio::AudioCaptureManager::get()); engine.rootContext()->setContextProperty(QStringLiteral("AudioManager"), &Audio::AudioCaptureManager::get());
engine.rootContext()->setContextProperty(QStringLiteral("SlideShow"), &SlideShow::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/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/qml/SlideShowWindow.qml"))); engine.load(QUrl(QStringLiteral("qrc:/qml/SlideShowWindow.qml")));
......
...@@ -12,7 +12,7 @@ Pane{ ...@@ -12,7 +12,7 @@ Pane{
GridLayout{ GridLayout{
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
rowSpacing: 6 rowSpacing: 4
columns: 2 columns: 2
Label{ Label{
text: "Settings file path:" text: "Settings file path:"
...@@ -238,6 +238,7 @@ Pane{ ...@@ -238,6 +238,7 @@ Pane{
text: "System Volume:" text: "System Volume:"
} }
RowLayout { RowLayout {
Layout.bottomMargin: -10
Label { Label {
text: System.volume < 0 ? "Not availible" : ((volumeSlider.value * 100).toFixed(0) + "%") text: System.volume < 0 ? "Not availible" : ((volumeSlider.value * 100).toFixed(0) + "%")
Layout.preferredWidth: 30 Layout.preferredWidth: 30
...@@ -257,6 +258,30 @@ Pane{ ...@@ -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 { Loader {
......
...@@ -12,19 +12,64 @@ Settings::Settings(QObject *parent) : QObject(parent), settings(OrganisationName ...@@ -12,19 +12,64 @@ Settings::Settings(QObject *parent) : QObject(parent), settings(OrganisationName
jsonSettingsFileSavePath = getJsonSettingsFilePath(); 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){ void Settings::setValue(const QString &key, const QVariant &value){
if(localSettings){ if (localSettings) {
if(localSettings->contains(key)){ if (localSettings->contains(key)) {
localSettings->setValue(key,value); localSettings->setValue(key, value);
} }
} }
settings.setValue(key,value); settings.setValue(key, value);
} }
QVariant Settings::value(const QString &key, const QVariant &defaultValue) const{ QVariant Settings::value(const QString &key, const QVariant &defaultValue) const{
if(localSettings){ if (localSettings) {
if(localSettings->contains(key)){ if (localSettings->contains(key)) {
return localSettings->value(key,defaultValue); return localSettings->value(key, defaultValue);
} }
} }
return settings.value(key,defaultValue); return settings.value(key, defaultValue);
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <QFile> #include <QFile>
#include <QObject> #include <QObject>
#include <QSettings> #include <QSettings>
#include <QSysInfo>
#include <optional> #include <optional>
#define MAKE_STRING(s) #s #define MAKE_STRING(s) #s
...@@ -56,6 +57,8 @@ class Settings : public QObject { ...@@ -56,6 +57,8 @@ class Settings : public QObject {
Q_PROPERTY(QString compilerFlags READ getCompilerFlags WRITE setCompilerFlags NOTIFY compilerFlagsChanged) Q_PROPERTY(QString compilerFlags READ getCompilerFlags WRITE setCompilerFlags NOTIFY compilerFlagsChanged)
Q_PROPERTY(QString compilerLibraryFlags READ getCompilerLibraryFlags WRITE setCompilerLibraryFlags NOTIFY compilerLibraryFlagsChanged) Q_PROPERTY(QString compilerLibraryFlags READ getCompilerLibraryFlags WRITE setCompilerLibraryFlags NOTIFY compilerLibraryFlagsChanged)
Q_PROPERTY(QString includePath READ getIncludePath WRITE setIncludePath NOTIFY includePathChanged) 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(int theme READ getTheme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(unsigned int updatePauseInMs READ getUpdatePauseInMs WRITE setUpdatePauseInMs NOTIFY updatePauseInMsChanged) Q_PROPERTY(unsigned int updatePauseInMs READ getUpdatePauseInMs WRITE setUpdatePauseInMs NOTIFY updatePauseInMsChanged)
static inline QFileInfo localSettingsFile; static inline QFileInfo localSettingsFile;
...@@ -76,29 +79,26 @@ protected: ...@@ -76,29 +79,26 @@ protected:
public: public:
explicit Settings(QObject *parent = nullptr); explicit Settings(QObject *parent = nullptr);
Q_INVOKABLE bool setJsonSettingsFilePath(const QString &file, bool loadFromPath) { /**
if(file == getJsonSettingsFilePath()) { * @brief setJsonSettingsFilePath only sets the settings file path to the given path. For an advanced
return false; * variant see setJsonSettingsFilePath(const QString&, bool)
} * @param file the new filepath
if (loadFromPath) { */
if (!QFile::exists(file)) { void setJsonSettingsFilePath(const QString &file);
return false;
} /**
// it was load/save path, but we dident loaded and now have a new load path * @brief setJsonSettingsFilePath sets the settings file path and handles the new file. If loadFromPath is
this->loadFromJsonSettingsFilePath = true; * true, shouldLoadFromSettingsPath() will return false and getJsonSettingsFileSavePath() will return
setValue(QStringLiteral("jsonSettingsFilePath"), file); * the old path. If loadFromPath is false, shouldLoadFromSettingsPath() will return false. The signal
emit jsonSettingsFilePathChanged(); * saveAs(QString) will be emitted. getJsonSettingsFileSavePath() will return the new path.
*
} else { * @param file the new settings file path
// it was load or save path, but we dident loaded and now want to save * @param loadFromPath true if the settings should be loaded from the new file, false if the settings should
this->loadFromJsonSettingsFilePath = false; * be written to the new path
this->jsonSettingsFileSavePath = file; * @return false, if file == getJsonSettingsFilePath() or loadFromPath is true and the file does not exists.
setValue(QStringLiteral("jsonSettingsFilePath"), file); * True otherwise
emit jsonSettingsFilePathChanged(); */
emit saveAs(file); Q_INVOKABLE bool setJsonSettingsFilePath(const QString &file, bool loadFromPath);
}
return true;
}
[[nodiscard]] QString getJsonSettingsFilePath() const { return value(QStringLiteral("jsonSettingsFilePath")).toString(); } [[nodiscard]] QString getJsonSettingsFilePath() const { return value(QStringLiteral("jsonSettingsFilePath")).toString(); }
/** /**
* @brief getJsonSettingsFileSavePath returns the path, to which the settings file should be written * @brief getJsonSettingsFileSavePath returns the path, to which the settings file should be written
...@@ -181,6 +181,12 @@ public: ...@@ -181,6 +181,12 @@ public:
} }
QString getCompilerLibraryFlags() const { return Modules::Compiler::compilerLibraryFlags; } 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) { void setTheme(int theme) {
if (theme != getTheme()) { if (theme != getTheme()) {
setValue(QStringLiteral("theme"), theme); setValue(QStringLiteral("theme"), theme);
...@@ -228,6 +234,8 @@ signals: ...@@ -228,6 +234,8 @@ signals:
void includePathChanged(); void includePathChanged();
void themeChanged(); void themeChanged();
void saveAs(QString path); void saveAs(QString path);
void computerNameChanged();
void remoteVolumeControlChanged();
public slots: public slots:
}; };
......
...@@ -81,6 +81,7 @@ public: ...@@ -81,6 +81,7 @@ public:
MODIFY_THEME = 27, MODIFY_THEME = 27,
SAVE_SLIDE_SHOW_SETTINGS = 28, SAVE_SLIDE_SHOW_SETTINGS = 28,
CHANGE_SYSTEM_VOLUME = 29, CHANGE_SYSTEM_VOLUME = 29,
ENABLE_REMOTE_VOLUME_CONTROL = 30,
}; };
Q_ENUM(Permission) 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