From c877a6e5c873f0024819c37244020a358ff66d3d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 11 Sep 2023 22:55:42 +0200 Subject: [PATCH] improved login of on/off and parameter display in webui/jsonapi config pages --- .../src/gui/settings/JsonApiPage.cc | 16 +++++++++++++- retroshare-gui/src/gui/settings/WebuiPage.cpp | 21 ++++++++++++++++++- retroshare-gui/src/gui/settings/WebuiPage.h | 4 ++++ retroshare-gui/src/gui/settings/WebuiPage.ui | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/settings/JsonApiPage.cc b/retroshare-gui/src/gui/settings/JsonApiPage.cc index 136b37d56..4e33c05e6 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.cc +++ b/retroshare-gui/src/gui/settings/JsonApiPage.cc @@ -29,6 +29,8 @@ #include #include +#define IMAGE_LEDOFF ":/images/ledoff1.png" +#define IMAGE_LEDON ":/images/ledon1.png" JsonApiPage::JsonApiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/) { @@ -122,7 +124,19 @@ void JsonApiPage::load() QString::fromStdString(it.first) + ":" + QString::fromStdString(it.second) ); - whileBlocking(ui.tokensListView)->setModel(new QStringListModel(newTk)); + whileBlocking(ui.tokensListView)->setModel(new QStringListModel(newTk)); + + QStringList newTk2; + + for(const auto& it : rsJsonApi->getResourceProviders()) + newTk2.push_back( QString::fromStdString(it.get().getName())) ; + + whileBlocking(ui.providersListView)->setModel(new QStringListModel(newTk2)); + + if(rsJsonApi->isRunning()) + ui.statusLabelLED->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_LEDON)) ; + else + ui.statusLabelLED->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_LEDOFF)) ; } bool JsonApiPage::checkStartJsonApi() diff --git a/retroshare-gui/src/gui/settings/WebuiPage.cpp b/retroshare-gui/src/gui/settings/WebuiPage.cpp index 073d775ae..cccf54369 100644 --- a/retroshare-gui/src/gui/settings/WebuiPage.cpp +++ b/retroshare-gui/src/gui/settings/WebuiPage.cpp @@ -27,6 +27,7 @@ #include #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "retroshare/rswebui.h" #include "retroshare/rsjsonapi.h" @@ -40,6 +41,8 @@ resource_api::ApiServerLocal* WebuiPage::apiServerLocal = 0; #endif resource_api::RsControlModule* WebuiPage::controlModule = 0; +#define IMAGE_LEDOFF ":/images/ledoff1.png" +#define IMAGE_LEDON ":/images/ledon1.png" WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/) { @@ -50,6 +53,15 @@ 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())); + + mEventsHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr /* event */) + { + std::cerr << "Caught JSONAPI event in webui!" << std::endl; + RsQThreadUtils::postToObject([=]() { load(); }, this ); + }, + mEventsHandlerId, RsEventType::JSON_API ); } WebuiPage::~WebuiPage() @@ -127,6 +139,13 @@ void WebuiPage::loadParams() if(it != smap.end()) whileBlocking(ui.password_LE)->setText(QString::fromStdString(it->second)); + + if(rsWebUi->isRunning() && rsJsonApi->isRunning()) + ui.statusLabelLED->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_LEDON)) ; + else + ui.statusLabelLED->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_LEDOFF)) ; +#else + ui.statusLabelLED->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_LEDOFF)) ; #endif } @@ -172,7 +191,6 @@ QString WebuiPage::helpText() const void WebuiPage::onEnableCBClicked(bool checked) { ui.params_GB->setEnabled(checked); - ui.apply_PB->setEnabled(checked); ui.startWebBrowser_PB->setEnabled(checked); QString S; } @@ -203,6 +221,7 @@ void WebuiPage::onApplyClicked() else checkShutdownWebui(); } + load(); } void WebuiPage::onStartWebBrowserClicked() { showWebui(); } diff --git a/retroshare-gui/src/gui/settings/WebuiPage.h b/retroshare-gui/src/gui/settings/WebuiPage.h index ad20d6afb..391612cf8 100644 --- a/retroshare-gui/src/gui/settings/WebuiPage.h +++ b/retroshare-gui/src/gui/settings/WebuiPage.h @@ -20,6 +20,8 @@ #pragma once +#include "retroshare/rsevents.h" + #include "retroshare-gui/configpage.h" #include "gui/common/FilesDefs.h" #include "ui_WebuiPage.h" @@ -82,4 +84,6 @@ private: static resource_api::ApiServerLocal* apiServerLocal; #endif static resource_api::RsControlModule* controlModule; + + RsEventsHandlerId_t mEventsHandlerId; }; diff --git a/retroshare-gui/src/gui/settings/WebuiPage.ui b/retroshare-gui/src/gui/settings/WebuiPage.ui index e48cd31c5..91d59736f 100644 --- a/retroshare-gui/src/gui/settings/WebuiPage.ui +++ b/retroshare-gui/src/gui/settings/WebuiPage.ui @@ -39,7 +39,7 @@ - TextLabel + Status: