aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-08 09:26:34 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-08 09:26:34 +0100
commit7db6cde62ee6df76df798f108b747398de8ab26b (patch)
treeed0bda680a7f2d02f877d153a8b8c7307d3e8cb5
parent170f1d1dc4291aaac001e69002f5c80d03798e52 (diff)
half fix menu bar and update automation
-rw-r--r--confui/mainwindow.cpp37
-rw-r--r--confui/mainwindow.h9
-rw-r--r--confui/mesh_connector.cpp21
-rw-r--r--confui/mesh_connector.h3
-rw-r--r--confui/ui_automation.cpp21
-rw-r--r--confui/ui_automation.h13
-rw-r--r--confui/ui_node.cpp6
-rw-r--r--confui/ui_node.h4
-rw-r--r--confui/ui_tab_automations.cpp4
-rw-r--r--confui/ui_tab_node_overview.cpp4
10 files changed, 91 insertions, 31 deletions
diff --git a/confui/mainwindow.cpp b/confui/mainwindow.cpp
index 2d06268..1f3e333 100644
--- a/confui/mainwindow.cpp
+++ b/confui/mainwindow.cpp
@@ -8,26 +8,51 @@
CDMeshConnector* g_cd_mesh_connector = nullptr;
+CDMainWindow::~CDMainWindow() {
+ delete this->mesh_connector;
+}
+
CDMainWindow::CDMainWindow(QWidget *parent) : QMainWindow(parent) {
g_cd_mesh_connector = new CDMeshConnector();
this->mesh_connector = g_cd_mesh_connector;
- QMenuBar* menu_bar = new QMenuBar(this);
- menu_bar->addMenu("ayo");
+ menu_bar = new QMenuBar(this);
QTabWidget* tab_bar_widget = new QTabWidget(this);
- this->automations_widget = new CDAutomationsTabWidget(this);
- this->node_overview_widget = new CDNodeOverviewTabWidget(this);
+
+ automations_widget = new CDAutomationsTabWidget(this);
+ node_overview_widget = new CDNodeOverviewTabWidget(this);
tab_bar_widget->addTab(this->node_overview_widget, "node overview");
tab_bar_widget->addTab(this->automations_widget, "automations");
setMenuBar(menu_bar);
setCentralWidget(tab_bar_widget);
+ update();
+}
+
+void CDMainWindow::update() {
setWindowTitle("confui");
+
+ menu_bar->clear();
+ QMenu* menu_options = menu_bar->addMenu("options");
+
+ QAction* menu_options_refresh = menu_options->addAction("refresh node list");
+ connect(menu_options_refresh, &QAction::triggered, this, &CDMainWindow::menu_refresh);
+
+ menu_options->addAction("add automation");
+
+ QMenu* menu_options_serialport = menu_options->addMenu("serial port (FIXME)");
+
+ menu_options_serialport->addAction("FIXME A");
+ menu_options_serialport->addAction("FIXME B");
}
-CDMainWindow::~CDMainWindow() {
- delete this->mesh_connector;
+void CDMainWindow::menu_refresh() {
+ update();
+}
+
+void CDMainWindow::menu_add_automation() {
+
}
diff --git a/confui/mainwindow.h b/confui/mainwindow.h
index a4e7a59..d689f2e 100644
--- a/confui/mainwindow.h
+++ b/confui/mainwindow.h
@@ -12,12 +12,17 @@ class CDNodeOverviewTabWidget;
class CDMainWindow : public QMainWindow {
Q_OBJECT
+private:
+ QMenuBar* menu_bar = nullptr;
+ CDAutomationsTabWidget* automations_widget = nullptr;
+ CDNodeOverviewTabWidget* node_overview_widget = nullptr;
public:
CDMeshConnector *mesh_connector = nullptr;
- CDAutomationsTabWidget* automations_widget = nullptr;
- CDNodeOverviewTabWidget* node_overview_widget = nullptr;
CDMainWindow(QWidget *parent = nullptr);
~CDMainWindow();
+ virtual void update();
+ virtual void menu_refresh();
+ virtual void menu_add_automation();
};
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index 19f899e..c87d8c5 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -40,10 +40,10 @@ CDMeshConnector::CDMeshConnector() {
_nodes.push_back(temp_node_berta);
_nodes.push_back(temp_node_gerrit);
- set_link(temp_node_berta, temp_node_berta, CD_AUTOMATION_TYPE_TOGGLE);
- set_link(temp_node_berta, temp_node_gerrit, CD_AUTOMATION_TYPE_TOGGLE);
- set_link(temp_node_gerrit, temp_node_berta, CD_AUTOMATION_TYPE_TURN_OFF);
- set_link(temp_node_gerrit, temp_node_gerrit, CD_AUTOMATION_TYPE_TURN_ON);
+ create_link(temp_node_berta, temp_node_berta, CD_AUTOMATION_TYPE_TOGGLE);
+ create_link(temp_node_berta, temp_node_gerrit, CD_AUTOMATION_TYPE_TOGGLE);
+ create_link(temp_node_gerrit, temp_node_berta, CD_AUTOMATION_TYPE_TURN_OFF);
+ create_link(temp_node_gerrit, temp_node_gerrit, CD_AUTOMATION_TYPE_TURN_ON);
return;
}
@@ -96,16 +96,21 @@ vector<cd_s_automation*> CDMeshConnector::get_config() {
return automations;
}
-cd_link_t CDMeshConnector::set_link(cd_s_node* button, cd_s_node* light, enum cd_e_automation_type action) {
+void CDMeshConnector::set_link(cd_link_t link, cd_s_automation* automation) {
+ _links[link] = automation;
+ printf("link[%d] = %.*s %s %.*s\n", link, (int) automation->button->name_len, automation->button->name, automation->type == CD_AUTOMATION_TYPE_TOGGLE ? "toggles" : automation->type == CD_AUTOMATION_TYPE_TURN_OFF ? "turns off" : "turns on", (int) automation->light->name_len, automation->light->name);
+}
+
+cd_link_t CDMeshConnector::create_link(cd_s_node* button, cd_s_node* light, enum cd_e_automation_type type) {
cd_s_automation* automation = (cd_s_automation*) malloc(sizeof(cd_s_automation));
automation->button = button;
automation->light = light;
- automation->type = action;
+ automation->type = type;
cd_link_t link = get_new_map_id();
- _links[link] = automation;
+ printf("(new) ");
+ set_link(link, automation);
- printf("new link[%d]: %.*s %s %.*s\n", link, (int) button->name_len, button->name, action == CD_AUTOMATION_TYPE_TOGGLE ? "toggles" : action == CD_AUTOMATION_TYPE_TURN_OFF ? "turns off" : "turns on", (int) light->name_len, light->name);
return link;
}
diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h
index 2d9931e..220974a 100644
--- a/confui/mesh_connector.h
+++ b/confui/mesh_connector.h
@@ -50,7 +50,8 @@ public:
virtual map<cd_mac_addr_cpp_t, cd_s_node*> get_nodes(bool provisioned);
virtual vector<cd_s_node*> get_raw_nodes();
virtual vector<cd_s_automation*> get_config();
- virtual cd_link_t set_link(cd_s_node* button, cd_s_node* light, enum cd_e_automation_type action);
+ virtual cd_link_t create_link(cd_s_node* button, cd_s_node* light, enum cd_e_automation_type action);
+ virtual void set_link(cd_link_t link, cd_s_automation* automation);
virtual void remove_link(cd_link_t link_handle);
virtual cd_s_node* get_node_by_id(cd_mac_addr_t address);
virtual void update_node(cd_s_node* node_ptr);
diff --git a/confui/ui_automation.cpp b/confui/ui_automation.cpp
index 2a04edb..3c555cd 100644
--- a/confui/ui_automation.cpp
+++ b/confui/ui_automation.cpp
@@ -4,9 +4,7 @@
using std::pair;
CDAutomationWidget::~CDAutomationWidget() { }
-CDAutomationWidget::CDAutomationWidget(cd_s_automation* automation, QWidget* parent) : QWidget(parent) {
- set_automation(automation);
-
+CDAutomationWidget::CDAutomationWidget(QWidget* parent) : QWidget(parent) {
main_layout = new QHBoxLayout;
dropdown_button = new QComboBox;
@@ -24,7 +22,8 @@ CDAutomationWidget::CDAutomationWidget(cd_s_automation* automation, QWidget* par
setLayout(main_layout);
}
-void CDAutomationWidget::set_automation(cd_s_automation* automation) {
+void CDAutomationWidget::set_automation(cd_link_t link, cd_s_automation* automation) {
+ _id = link;
_automation = automation;
}
@@ -33,6 +32,8 @@ void CDAutomationWidget::update() {
map<cd_mac_addr_cpp_t, cd_s_node*> nodes = g_cd_mesh_connector->get_nodes(false);
+ dropdown_button->clear();
+ dropdown_light->clear();
for (pair<cd_mac_addr_cpp_t, cd_s_node*> node : nodes) {
QString label = "";
label.append(QString::fromLocal8Bit(node.second->name, node.second->name_len));
@@ -45,6 +46,8 @@ void CDAutomationWidget::update() {
dropdown_light->addItem(label, userData);
}
+ if (_automation == nullptr) return;
+
dropdown_button->setCurrentIndex(dropdown_button->findData(QString::fromLocal8Bit((char*) _automation->button->address, 6)));
dropdown_action->clear();
@@ -55,3 +58,13 @@ void CDAutomationWidget::update() {
dropdown_light->setCurrentIndex(dropdown_light->findData(QString::fromLocal8Bit((char*) _automation->light->address, 6)));
}
+
+bool CDAutomationWidget::conf_valid() {
+ return true;
+}
+
+void CDAutomationWidget::apply() {
+ if (!conf_valid()) return;
+
+ g_cd_mesh_connector->set_link(_id, _automation);
+}
diff --git a/confui/ui_automation.h b/confui/ui_automation.h
index d69c4d7..2c081e3 100644
--- a/confui/ui_automation.h
+++ b/confui/ui_automation.h
@@ -12,7 +12,8 @@ class CDAutomationWidget : public QWidget {
Q_OBJECT
private:
- cd_s_automation* _automation;
+ cd_s_automation* _automation = nullptr;
+ cd_link_t _id;
QHBoxLayout* main_layout;
QComboBox* dropdown_button;
@@ -21,8 +22,14 @@ private:
QPushButton* button_remove;
public:
- CDAutomationWidget(cd_s_automation* automation, QWidget *parent = nullptr);
+ CDAutomationWidget(QWidget *parent = nullptr);
virtual ~CDAutomationWidget();
+ /** @brief redraw ui with new values */
virtual void update();
- virtual void set_automation(cd_s_automation* automation);
+ /** @brief register automation that this widget controls */
+ virtual void set_automation(cd_link_t link, cd_s_automation* automation);
+ /** @brief test if all fields are valid / entered */
+ virtual bool conf_valid();
+ /** @brief apply new automation rule */
+ virtual void apply();
};
diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp
index c810c29..f369fba 100644
--- a/confui/ui_node.cpp
+++ b/confui/ui_node.cpp
@@ -1,9 +1,7 @@
#include "ui_node.h"
CDNodeWidget::~CDNodeWidget() { }
-CDNodeWidget::CDNodeWidget(cd_s_node* node, QWidget *parent) : QWidget(parent) {
- set_node(node);
-
+CDNodeWidget::CDNodeWidget(QWidget *parent) : QWidget(parent) {
main_layout = new QHBoxLayout;
switch_on_off = new QCheckBox;
button_add_remove = new QPushButton;
@@ -28,6 +26,8 @@ void CDNodeWidget::set_node(cd_s_node* node) {
}
void CDNodeWidget::update() {
+ if (_node == nullptr) return;
+
QString node_name = QString::fromLocal8Bit(_node->name, _node->name_len);
label_node_name->setText(node_name);
diff --git a/confui/ui_node.h b/confui/ui_node.h
index 93fc296..9e12b60 100644
--- a/confui/ui_node.h
+++ b/confui/ui_node.h
@@ -13,7 +13,7 @@ class CDNodeWidget : public QWidget {
Q_OBJECT
private:
- cd_s_node* _node;
+ cd_s_node* _node = nullptr;
QHBoxLayout* main_layout;
QLabel* label_node_name;
@@ -22,7 +22,7 @@ private:
QPushButton* button_add_remove;
public:
- CDNodeWidget(cd_s_node* node, QWidget *parent = nullptr);
+ CDNodeWidget(QWidget *parent = nullptr);
virtual ~CDNodeWidget();
virtual void update();
virtual void set_node(cd_s_node* node);
diff --git a/confui/ui_tab_automations.cpp b/confui/ui_tab_automations.cpp
index 18b3073..0702d20 100644
--- a/confui/ui_tab_automations.cpp
+++ b/confui/ui_tab_automations.cpp
@@ -50,7 +50,9 @@ void CDAutomationsTabWidget::update() {
if (widgets.count(link.first)) { // node is already in list
widgets[link.first]->update();
} else {
- widgets[link.first] = new CDAutomationWidget(link.second, this);
+ widgets[link.first] = new CDAutomationWidget(this);
+ widgets[link.first]->set_automation(link.first, link.second);
+ widgets[link.first]->update();
}
automations->addWidget(widgets[link.first]);
}
diff --git a/confui/ui_tab_node_overview.cpp b/confui/ui_tab_node_overview.cpp
index 3625249..d0280cf 100644
--- a/confui/ui_tab_node_overview.cpp
+++ b/confui/ui_tab_node_overview.cpp
@@ -25,7 +25,9 @@ void CDNodeOverviewTabWidget::update() {
if (node_widgets.count(node.first)) { // node is already in list
node_widgets[node.first]->update();
} else {
- node_widgets[node.first] = new CDNodeWidget(node.second, this);
+ node_widgets[node.first] = new CDNodeWidget(this);
+ node_widgets[node.first]->set_node(node.second);
+ node_widgets[node.first]->update();
}
main_layout->addWidget(node_widgets[node.first]);
}