From 1b8f137dee446c6379755c4e248f92172681752e Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 13 Nov 2019 21:35:57 +0100 Subject: [PATCH] improved UI for jsonapi and webui pages --- libretroshare/src/jsonapi/jsonapi.cpp | 1 + .../src/gui/settings/JsonApiPage.cc | 44 +++++++++++-------- retroshare-gui/src/gui/settings/JsonApiPage.h | 1 + retroshare-gui/src/gui/settings/WebuiPage.cpp | 4 +- retroshare-gui/src/main.cpp | 4 ++ 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp index 3b3ab0e6f..74511dcbd 100644 --- a/libretroshare/src/jsonapi/jsonapi.cpp +++ b/libretroshare/src/jsonapi/jsonapi.cpp @@ -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"); } diff --git a/retroshare-gui/src/gui/settings/JsonApiPage.cc b/retroshare-gui/src/gui/settings/JsonApiPage.cc index f8a045dff..f5226da10 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.cc +++ b/retroshare-gui/src/gui/settings/JsonApiPage.cc @@ -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) diff --git a/retroshare-gui/src/gui/settings/JsonApiPage.h b/retroshare-gui/src/gui/settings/JsonApiPage.h index a6e12de9a..97eb5407b 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.h +++ b/retroshare-gui/src/gui/settings/JsonApiPage.h @@ -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 diff --git a/retroshare-gui/src/gui/settings/WebuiPage.cpp b/retroshare-gui/src/gui/settings/WebuiPage.cpp index 84a3e38ee..d1337a4a4 100644 --- a/retroshare-gui/src/gui/settings/WebuiPage.cpp +++ b/retroshare-gui/src/gui/settings/WebuiPage.cpp @@ -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 diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 3b17e2e76..2ca3e1284 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -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