summaryrefslogtreecommitdiff
path: root/client-qt/udm-client-qt
diff options
context:
space:
mode:
Diffstat (limited to 'client-qt/udm-client-qt')
-rw-r--r--client-qt/udm-client-qt/download_add_widget.cpp40
-rw-r--r--client-qt/udm-client-qt/download_add_widget.h2
-rw-r--r--client-qt/udm-client-qt/marked_class.h19
-rw-r--r--client-qt/udm-client-qt/udm_main.cpp36
-rw-r--r--client-qt/udm-client-qt/udm_main.h1
5 files changed, 95 insertions, 3 deletions
diff --git a/client-qt/udm-client-qt/download_add_widget.cpp b/client-qt/udm-client-qt/download_add_widget.cpp
index 813ac7a..366c7d6 100644
--- a/client-qt/udm-client-qt/download_add_widget.cpp
+++ b/client-qt/udm-client-qt/download_add_widget.cpp
@@ -76,6 +76,16 @@ download_add_widget::download_add_widget(std::list<module_info> &modules_, QWidg
void download_add_widget::combo_modules_currentIndexChanged(QString module)
{
+ current_module = module;
+ {
+ int rows = layout_settings->rowCount(), columns = layout_settings->columnCount();
+ for(int i = 0; i < rows; i++)
+ {
+ for(int ii = 0; ii < columns; ii ++)
+ delete layout_settings->itemAtPosition(i, ii);
+ }
+ }
+
for (QLayoutItem *item = layout_settings->takeAt(0); item != 0; item = layout_settings->takeAt(0))
delete item;
@@ -98,6 +108,7 @@ void download_add_widget::combo_modules_currentIndexChanged(QString module)
{
marked_class<QLineEdit> *edit = new marked_class<QLineEdit>;
edit->set_mark(ui.id());
+ edit->set_type(widget_type_e::QLineEdit_t);
layout_settings->addWidget(edit, row, 2);
}
break;
@@ -105,6 +116,7 @@ void download_add_widget::combo_modules_currentIndexChanged(QString module)
{
marked_class<QSpinBox> *edit = new marked_class<QSpinBox>;
edit->set_mark(ui.id());
+ edit->set_type(widget_type_e::QSpinBox_t);
layout_settings->addWidget(edit, row, 2);
}
break;
@@ -120,7 +132,33 @@ void download_add_widget::combo_modules_currentIndexChanged(QString module)
void download_add_widget::btn_ok_clicked()
{
-
+ int rows = layout_settings->rowCount();
+ std::map<int, std::string> settings;
+ for (int i = 0; i < rows; ++i)
+ {
+ QWidget *w_ = layout_settings->itemAtPosition(i, 2)->widget();
+ marked_class<QWidget> *w = static_cast<marked_class<QWidget> *>(w_);
+ switch(w->get_type())
+ {
+ case widget_type_e::QLineEdit_t:
+ {
+ marked_class<QLineEdit> *l = static_cast<marked_class<QLineEdit> *>(w_);
+ settings[l->get_mark()] = l->text().toStdString();
+ }
+ break;
+ case widget_type_e::QSpinBox_t:
+ {
+ marked_class<QSpinBox> *l = static_cast<marked_class<QSpinBox> *>(w_);
+ settings[l->get_mark()] = l->text().toStdString();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ emit got_download_settings(current_module.toStdString(), settings);
+ close();
+ deleteLater();
}
void download_add_widget::btn_cancel_clicked()
diff --git a/client-qt/udm-client-qt/download_add_widget.h b/client-qt/udm-client-qt/download_add_widget.h
index 744a9de..c291cce 100644
--- a/client-qt/udm-client-qt/download_add_widget.h
+++ b/client-qt/udm-client-qt/download_add_widget.h
@@ -36,6 +36,7 @@ public:
explicit download_add_widget(std::list<module_info> &modules, QWidget *parent = 0);
signals:
+ void got_download_settings(std::string module_name, std::map<int, std::string>);
public slots:
protected slots:
@@ -45,6 +46,7 @@ protected slots:
private:
std::list<module_info> &modules;
QGridLayout *layout_settings;
+ QString current_module;
};
#endif // DOWNLOAD_ADD_WIDGET_H
diff --git a/client-qt/udm-client-qt/marked_class.h b/client-qt/udm-client-qt/marked_class.h
index de5bd96..f3fef9c 100644
--- a/client-qt/udm-client-qt/marked_class.h
+++ b/client-qt/udm-client-qt/marked_class.h
@@ -23,6 +23,14 @@
#ifndef MARKED_CLASS
#define MARKED_CLASS
+enum widget_type_e
+{
+ wrong_type_t = -1,
+ QLineEdit_t = 0,
+ QSpinBox_t
+};
+
+
template <typename BASE>
class marked_class : public BASE
{
@@ -37,8 +45,19 @@ public:
return mark;
}
+ void set_type(widget_type_e t)
+ {
+ type = t;
+ }
+ widget_type_e get_type()
+ {
+ return type;
+ }
+
+
private:
int mark = -1;
+ widget_type_e type = wrong_type_t;
};
#endif // MARKED_CLASS
diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp
index ca5b397..e6ba87c 100644
--- a/client-qt/udm-client-qt/udm_main.cpp
+++ b/client-qt/udm-client-qt/udm_main.cpp
@@ -121,6 +121,7 @@ void udm_main::client_pre_connect_init()
{
if(thread_client_session)
{
+ thread_client_session->quit();
delete thread_client_session;
thread_client_session = nullptr;
}
@@ -173,7 +174,7 @@ void udm_main::server_message_received(server_msg msg)
if(msg.auth_reply().status())
{
auth_token = msg.auth_reply().auth_token();
- //TODO: update client status
+ btn_add->setEnabled(true); //we can add downloads now
lbl_state->setText(tr("State") + ": " + tr("Connected") + ", " + tr("Authenticated"));
//request modules and settings here
{
@@ -231,12 +232,16 @@ void udm_main::server_message_received(server_msg msg)
void udm_main::create_buttons()
{
btn_start = new QPushButton(this);
+ btn_start->setEnabled(false);
connect(btn_start, SIGNAL(clicked(bool)), this, SLOT(btn_start_clicked()));
btn_stop = new QPushButton(this);
+ btn_stop->setEnabled(false);
connect(btn_stop, SIGNAL(clicked(bool)), this, SLOT(btn_stop_clicked()));
btn_del = new QPushButton(this);
+ btn_del->setEnabled(false);
connect(btn_del, SIGNAL(clicked(bool)), this, SLOT(btn_del_clicked()));
btn_add = new QPushButton(this);
+ btn_add->setEnabled(false);
connect(btn_add, SIGNAL(clicked(bool)), this, SLOT(btn_add_clicked()));
button_bar = new QToolBar(this);
button_bar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
@@ -276,10 +281,29 @@ void udm_main::btn_stop_clicked()
void udm_main::btn_add_clicked()
{
download_add_widget *w = new download_add_widget(modules);
- //TODO: connect slots/signals here
+ connect(w, SIGNAL(got_download_settings(std::string, std::map<int,std::string>)), this, SLOT(got_download_settings(std::string, std::map<int,std::string>)));
w->show();
}
+void udm_main::got_download_settings(std::string module_name, std::map<int, std::string> settings)
+{
+ if(!settings.empty())
+ {
+ client_msg msg;
+ msg.set_auth_token(auth_token);
+ msg.set_type(CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_ADD);
+ client_download_add_request *r = msg.mutable_download_add_request();
+ r->set_module_name(module_name);
+ for(auto i : settings)
+ {
+ int_string_pair *p = r->add_params();
+ p->set_id(i.first);
+ p->set_value(i.second);
+ }
+ session->send_message(msg);
+ }
+}
+
void udm_main::btn_del_clicked()
{
@@ -294,6 +318,10 @@ void udm_main::client_connected(bool success, QString error_text)
msg.setText(tr("client connection error with error:") + error_text);
msg.exec();
lbl_state->setText(tr("State") + ": " + tr("Connection error"));
+ btn_add->setEnabled(false);
+ btn_del->setEnabled(false);
+ btn_start->setEnabled(false);
+ btn_stop->setEnabled(false);
}
else
{
@@ -306,5 +334,9 @@ void udm_main::client_connected(bool success, QString error_text)
void udm_main::client_disconnected()
{
+ btn_add->setEnabled(false);
+ btn_del->setEnabled(false);
+ btn_start->setEnabled(false);
+ btn_stop->setEnabled(false);
lbl_state->setText(tr("State") + ": " + tr("Disconnected"));
}
diff --git a/client-qt/udm-client-qt/udm_main.h b/client-qt/udm-client-qt/udm_main.h
index eede952..d3e07be 100644
--- a/client-qt/udm-client-qt/udm_main.h
+++ b/client-qt/udm-client-qt/udm_main.h
@@ -62,6 +62,7 @@ public slots:
void server_message_received(server_msg msg);
void client_connected(bool success, QString error_text);
void client_disconnected();
+ void got_download_settings(std::string module_name, std::map<int, std::string>);
protected slots:
void btn_start_clicked();