Skip to content

Commit 776bf04

Browse files
committed
Add import/export for payload mapping
1 parent 67b73be commit 776bf04

File tree

6 files changed

+134
-10
lines changed

6 files changed

+134
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Checking *Attempt to execute unrecognized payloads in PowerShell* will blindly t
6161

6262
#### Responses
6363

64-
When the function has run, a response will be published in topic `<chosen_topic>/<payload_name>/response` with a message, which in some cases is empty. For WebSocket, a text message with the format `<payload_name>/response/message` is sent back to the server. The response can be used as an acknoledgement that the command was received and executed.
64+
When the function has run, a response will be published in topic `<chosen_topic>/<payload_name>/response` with a message, which in some cases is empty. For WebSocket, a text message with the format `<payload_name>/response/message` is sent back to the server. The response can be used as an acknowledgement that the command was received and executed.
6565

6666
## Screenshots
6767

disorient.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 0.3.0
1+
VERSION = 0.4.0
22

33
include(disorient.pri)
44

forms/mainwindow.ui

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<enum>QTabWidget::North</enum>
5252
</property>
5353
<property name="currentIndex">
54-
<number>2</number>
54+
<number>1</number>
5555
</property>
5656
<widget class="QWidget" name="tab_5">
5757
<attribute name="icon">
@@ -689,11 +689,91 @@
689689
</spacer>
690690
</item>
691691
<item>
692-
<widget class="QCheckBox" name="checkBoxAllowWildcards">
693-
<property name="text">
694-
<string>Allow keyword arguments in payloads</string>
692+
<layout class="QHBoxLayout" name="horizontalLayout_6" stretch="10,1,1">
693+
<property name="spacing">
694+
<number>0</number>
695695
</property>
696-
</widget>
696+
<property name="bottomMargin">
697+
<number>0</number>
698+
</property>
699+
<item>
700+
<widget class="QCheckBox" name="checkBoxAllowWildcards">
701+
<property name="text">
702+
<string>Allow keyword arguments in payloads</string>
703+
</property>
704+
</widget>
705+
</item>
706+
<item>
707+
<widget class="QPushButton" name="pushButtonImportPayloadMap">
708+
<property name="sizePolicy">
709+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
710+
<horstretch>0</horstretch>
711+
<verstretch>0</verstretch>
712+
</sizepolicy>
713+
</property>
714+
<property name="maximumSize">
715+
<size>
716+
<width>20</width>
717+
<height>20</height>
718+
</size>
719+
</property>
720+
<property name="toolTip">
721+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Import payload mapping from a JSON file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
722+
</property>
723+
<property name="styleSheet">
724+
<string notr="true"/>
725+
</property>
726+
<property name="text">
727+
<string/>
728+
</property>
729+
<property name="icon">
730+
<iconset resource="../resources/resources.qrc">
731+
<normaloff>:/icons/import.png</normaloff>:/icons/import.png</iconset>
732+
</property>
733+
<property name="iconSize">
734+
<size>
735+
<width>12</width>
736+
<height>12</height>
737+
</size>
738+
</property>
739+
</widget>
740+
</item>
741+
<item>
742+
<widget class="QPushButton" name="pushButtonExportPayloadMap">
743+
<property name="sizePolicy">
744+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
745+
<horstretch>0</horstretch>
746+
<verstretch>0</verstretch>
747+
</sizepolicy>
748+
</property>
749+
<property name="maximumSize">
750+
<size>
751+
<width>20</width>
752+
<height>20</height>
753+
</size>
754+
</property>
755+
<property name="toolTip">
756+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Export payload mapping to a JSON file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
757+
</property>
758+
<property name="styleSheet">
759+
<string notr="true"/>
760+
</property>
761+
<property name="text">
762+
<string/>
763+
</property>
764+
<property name="icon">
765+
<iconset resource="../resources/resources.qrc">
766+
<normaloff>:/icons/export.png</normaloff>:/icons/export.png</iconset>
767+
</property>
768+
<property name="iconSize">
769+
<size>
770+
<width>12</width>
771+
<height>12</height>
772+
</size>
773+
</property>
774+
</widget>
775+
</item>
776+
</layout>
697777
</item>
698778
<item>
699779
<widget class="QCheckBox" name="checkBoxExecPermission">

include/mainwindow.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <QDateTime>
1414
#include <QComboBox>
1515
#include <QJsonObject>
16+
#include <QJsonDocument>
1617
#include "endpoint.h"
1718
#include "inputwebsocket.h"
1819
#include "inputmqtt.h"
@@ -42,7 +43,7 @@ class MainWindow : public QMainWindow
4243
void setupPayloadTable();
4344
void setupStyles();
4445
void savePayloadMap();
45-
void loadPayloadMap();
46+
void loadPayloadMap(const QJsonDocument &file = QJsonDocument());
4647
QString timestamp();
4748
QVector<QString> getAllAudioDevices();
4849
void removeFromRegistry(const QString &key);
@@ -59,6 +60,8 @@ private slots:
5960
void on_lineEditMqttTopic_textChanged(const QString &arg1);
6061
void on_pushButtonRefreshDisplays_clicked();
6162
void on_pushButtonRefreshAudio_clicked();
63+
void on_pushButtonExportPayloadMap_clicked();
64+
void on_pushButtonImportPayloadMap_clicked();
6265

6366
private:
6467
Ui::MainWindow *m_ui;

resources/resources.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
<file>icons/status.png</file>
1010
<file>icons/icon.ico</file>
1111
<file>icons/plus.png</file>
12+
<file>icons/export.png</file>
13+
<file>icons/import.png</file>
1214
</qresource>
1315
</RCC>

src/mainwindow.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "ui_mainwindow.h"
33
#include "constants.h"
44
#include <QJsonArray>
5+
#include <QFileDialog>
6+
#include <QJsonDocument>
57
#include "comboboxitemdelegate.h"
68

79
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), m_endpoint(new Endpoint), m_iWebSocket(new InputWebSocket), m_iMqtt(new InputMqtt), m_audioDevice(new AudioEndpointController)
@@ -280,6 +282,9 @@ bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, long* r
280282

281283
void MainWindow::loadSettingsFromRegistry()
282284
{
285+
restoreGeometry(readFromRegistry("geometry").toByteArray());
286+
restoreState(readFromRegistry("windowState").toByteArray());
287+
283288
//Setting for last known WebSocket address
284289
QUrl lastWsUrl = readFromRegistry(Names::SettingLastWsAddress).toUrl();
285290
m_ui->lineEditWebSocketAddr->setText(lastWsUrl.toString());
@@ -383,9 +388,14 @@ void MainWindow::savePayloadMap()
383388
payloadTable->repaint();
384389
}
385390

386-
void MainWindow::loadPayloadMap()
391+
void MainWindow::loadPayloadMap(const QJsonDocument &file)
387392
{
388-
QJsonObject payloadObject = readFromRegistry(Names::SettingPayloadMap).toJsonObject();
393+
QJsonObject payloadObject;
394+
if(file.isEmpty()) {
395+
payloadObject = readFromRegistry(Names::SettingPayloadMap).toJsonObject();
396+
} else {
397+
payloadObject = file.object();
398+
}
389399

390400
auto payloadTable = m_ui->tableWidget;
391401

@@ -420,6 +430,9 @@ void MainWindow::loadPayloadMap()
420430

421431
void MainWindow::on_pushButtonSaveSettings_clicked()
422432
{
433+
writeToRegistry("geometry", saveGeometry());
434+
writeToRegistry("windowState", saveState());
435+
423436
//Autostart enabled
424437
QSettings bootSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
425438
QString path = QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
@@ -525,3 +538,29 @@ void MainWindow::on_pushButtonRefreshAudio_clicked()
525538
m_ui->comboBoxAudioList->clear();
526539
setupAudioCombobox(m_audioDevice->getAllAudioDevices());
527540
}
541+
542+
void MainWindow::on_pushButtonExportPayloadMap_clicked()
543+
{
544+
QJsonDocument doc;
545+
doc.setObject(m_payloadMap);
546+
QString fileName = QFileDialog::getSaveFileName(this, "Save Payload Mapping", "", "JSON (*.json)");
547+
if(fileName.isEmpty())
548+
return;
549+
else {
550+
QFile file(fileName);
551+
file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
552+
file.write(doc.toJson(QJsonDocument::Compact));
553+
file.close();
554+
}
555+
}
556+
557+
void MainWindow::on_pushButtonImportPayloadMap_clicked()
558+
{
559+
QString fileName = QFileDialog::getOpenFileName(this, "Load Payload Mapping", "", "JSON (*.json)");
560+
QFile file(fileName);
561+
file.open(QIODevice::ReadOnly | QIODevice::Text);
562+
QJsonParseError jsonParseError;
563+
QJsonDocument importFile = QJsonDocument::fromJson(file.readAll(), &jsonParseError);
564+
file.close();
565+
loadPayloadMap(importFile);
566+
}

0 commit comments

Comments
 (0)