Retroshare provides a JSON API allowing other softwares to communicate with its core using token-controlled HTTP requests to http://localhost:[port]. \ + Please refer to the Retroshare documentation for how to use this feature.
\ +Unless you know what you're doing, you shouldn't need to change anything in this page. \ + The web interface for instance will automatically register its own token to the JSON API which will be visible \ + in the list of authenticated tokens after you enable it.
"); +} void JsonApiPage::enableJsonApi(bool checked) { ui.addTokenPushButton->setEnabled(checked); @@ -93,9 +128,9 @@ bool JsonApiPage::updateParams() void JsonApiPage::load() { - whileBlocking(ui.portSpinBox)->setValue(Settings->getJsonApiPort()); - whileBlocking(ui.listenAddressLineEdit)->setText(Settings->getJsonApiListenAddress()); - whileBlocking(ui.enableCheckBox)->setChecked(Settings->getJsonApiEnabled()); + whileBlocking(ui.portSpinBox)->setValue(rsJsonApi->listeningPort()); + whileBlocking(ui.listenAddressLineEdit)->setText(QString::fromStdString(rsJsonApi->getBindingAddress())); + whileBlocking(ui.enableCheckBox)->setChecked(rsJsonApi->isRunning()); QStringList newTk; @@ -104,10 +139,20 @@ 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)); -QString JsonApiPage::helpText() const { return ""; } + 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/JsonApiPage.h b/retroshare-gui/src/gui/settings/JsonApiPage.h index 7f69bbd1e..ef28a4294 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.h +++ b/retroshare-gui/src/gui/settings/JsonApiPage.h @@ -20,6 +20,8 @@ #pragma once +#include "retroshare/rsevents.h" + #include "retroshare-gui/configpage.h" #include "gui/common/FilesDefs.h" #include "ui_JsonApiPage.h" @@ -31,7 +33,7 @@ class JsonApiPage : public ConfigPage public: JsonApiPage(QWidget * parent = nullptr, Qt::WindowFlags flags = 0); - ~JsonApiPage() override = default; + ~JsonApiPage() override ; virtual QPixmap iconPixmap() const override { @@ -63,4 +65,6 @@ public slots: private: Ui::JsonApiPage ui; /// Qt Designer generated object + RsEventsHandlerId_t mEventHandlerId; }; + diff --git a/retroshare-gui/src/gui/settings/JsonApiPage.ui b/retroshare-gui/src/gui/settings/JsonApiPage.ui index 24b534712..f8d31e38f 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.ui +++ b/retroshare-gui/src/gui/settings/JsonApiPage.ui @@ -13,7 +13,7 @@Warning: don't expose the webinterface to the internet, because there is no access control and no encryption. If you want to use the webinterface over the internet, use a SSH tunnel or a proxy to secure the connection.
"); } -/*static*/ bool WebuiPage::checkStartWebui() +/*static*/ bool WebuiPage::checkStartWebui() // This is supposed to be called from main(). But normally the parameters below (including the paswd + // for the webUI should be saved in p3webui instead. { - if(!Settings->getWebinterfaceEnabled()) - return false; - - rsWebUi->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString()); - rsWebUi->restart(); + rsWebUi->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString()); + rsWebUi->restart(); return true; } @@ -173,15 +199,21 @@ 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; + QString errmsg; + updateParams(errmsg); - Settings->setWebinterfaceEnabled(checked); + ui.params_GB->setEnabled(checked); + ui.startWebBrowser_PB->setEnabled(checked); + ui.apply_PB->setEnabled(checked); if(checked) - checkStartWebui(); + { + if(!restart()) + { + QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface."); + return; + } + } else checkShutdownWebui(); } @@ -199,18 +231,12 @@ void WebuiPage::onAllIPCBClicked(bool /*checked*/) } void WebuiPage::onApplyClicked() { - rsWebUi->setUserPassword(ui.password_LE->text().toStdString()); - QString errmsg; updateParams(errmsg); - if(!restart()) - { - QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface."); - return; - } + restart(); - emit passwordChanged(); + load(); } void WebuiPage::onStartWebBrowserClicked() { showWebui(); } diff --git a/retroshare-gui/src/gui/settings/WebuiPage.h b/retroshare-gui/src/gui/settings/WebuiPage.h index 9ba8886ac..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" @@ -42,11 +44,11 @@ public: ~WebuiPage(); /** Loads the settings for this page */ - virtual void load(); + virtual void load() override { loadParams() ; } - virtual QPixmap iconPixmap() const { return FilesDefs::getPixmapFromQtResourcePath(":/icons/settings/webinterface.svg") ; } - virtual QString pageName() const { return tr("Webinterface") ; } - virtual QString helpText() const; + virtual QPixmap iconPixmap() const override { return FilesDefs::getPixmapFromQtResourcePath(":/icons/settings/webinterface.svg") ; } + virtual QString pageName() const override { return tr("Webinterface") ; } + virtual QString helpText() const override ; // call this after start of libretroshare/Retroshare // checks the settings and starts the webinterface if required @@ -67,10 +69,9 @@ public slots: void onApplyClicked(); void onStartWebBrowserClicked(); -signals: - void passwordChanged(); - private: + virtual void loadParams(); + /** Qt Designer generated object */ Ui::WebuiPage ui; @@ -83,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 5ca37e9b6..91d59736f 100644 --- a/retroshare-gui/src/gui/settings/WebuiPage.ui +++ b/retroshare-gui/src/gui/settings/WebuiPage.ui @@ -6,8 +6,8 @@