improved UI for jsonapi and webui pages

This commit is contained in:
csoler 2019-11-13 21:35:57 +01:00
parent 9007d266a8
commit 1b8f137dee
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 33 additions and 21 deletions

View File

@ -141,6 +141,7 @@ void JsonApiServer::start(uint16_t port, const std::string& bindAddress, const s
mBindAddress = bindAddress;
mNewAccessRequestCallback = callback;
std::cerr << "(II) Srtating Json API on port " << port << ", address " << bindAddress << std::endl;
RsThread::start("JsonApiServer");
}

View File

@ -32,14 +32,26 @@
JsonApiPage::JsonApiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
{
ui.setupUi(this);
connect( ui.addTokenPushButton, &QPushButton::clicked,
this, &JsonApiPage::addTokenClicked);
connect( ui.removeTokenPushButton, &QPushButton::clicked,
this, &JsonApiPage::removeTokenClicked );
connect( ui.tokensListView, &QListView::clicked,
this, &JsonApiPage::tokenClicked );
connect( ui.applyConfigPushButton, &QPushButton::clicked,
this, &JsonApiPage::onApplyClicked );
connect( ui.enableCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableJsonApi(bool)));
connect( ui.addTokenPushButton, SIGNAL(clicked()), this, SLOT(addTokenClicked()));
connect( ui.removeTokenPushButton, SIGNAL(clicked()), this, SLOT(removeTokenClicked() ));
connect( ui.tokensListView, SIGNAL(clicked()), this, SLOT(tokenClicked() ));
connect( ui.applyConfigPushButton, SIGNAL(clicked()), this, SLOT(onApplyClicked() ));
}
void JsonApiPage::enableJsonApi(bool checked)
{
ui.addTokenPushButton->setEnabled(checked);
ui.applyConfigPushButton->setEnabled(checked);
ui.removeTokenPushButton->setEnabled(checked);
ui.tokensListView->setEnabled(checked);
Settings->setJsonApiEnabled(checked);
if(checked)
checkStartJsonApi();
else
checkShutdownJsonApi();
}
bool JsonApiPage::updateParams(QString &errmsg)
@ -64,19 +76,13 @@ bool JsonApiPage::updateParams(QString &errmsg)
}
QString listenAddress = ui.listenAddressLineEdit->text();
if(listenAddress != Settings->getJsonApiListenAddress())
{
Settings->setJsonApiListenAddress(listenAddress);
changed = true;
}
if(changed)
{
checkShutdownJsonApi();
ok = checkStartJsonApi();
}
if(!ok) errmsg = "Could not start JSON API Server!";
return ok;
}
@ -98,8 +104,6 @@ QString JsonApiPage::helpText() const { return ""; }
/*static*/ bool JsonApiPage::checkStartJsonApi()
{
checkShutdownJsonApi();
if(Settings->getJsonApiEnabled())
JsonApiServer::instance().start( Settings->getJsonApiPort(), Settings->getJsonApiListenAddress().toStdString() );
@ -141,8 +145,10 @@ QString JsonApiPage::helpText() const { return ""; }
void JsonApiPage::onApplyClicked(bool)
{
QString errmsg;
updateParams(errmsg);
// restart
checkShutdownJsonApi();
checkStartJsonApi();
}
void JsonApiPage::addTokenClicked(bool)

View File

@ -53,6 +53,7 @@ public slots:
void addTokenClicked(bool);
void removeTokenClicked(bool);
void tokenClicked(const QModelIndex& index);
void enableJsonApi(bool checked);
private:
Ui::JsonApiPage ui; /// Qt Designer generated object

View File

@ -50,8 +50,6 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString)));
connect(ui.startWebBrowser_PB, SIGNAL(clicked()), this, SLOT(onStartWebBrowserClicked()));
connect(ui.webInterfaceFilesDirectory_PB, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
checkStartWebui();
}
WebuiPage::~WebuiPage()
@ -159,6 +157,8 @@ void WebuiPage::onEnableCBClicked(bool checked)
ui.startWebBrowser_PB->setEnabled(checked);
QString S;
Settings->setWebinterfaceEnabled(checked);
if(checked)
checkStartWebui();
else

View File

@ -572,6 +572,10 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
#ifdef RS_WEBUI
WebuiPage::checkStartWebui(); // normally we should rather save the UI flags internally to p3webui
#endif
#ifdef RS_JSONAPI
JsonApiPage::checkStartJsonApi();
#endif // RS_JSONAPI