mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 14:12:43 -04:00
improved UI of webUI and JsonAPI and interaction between these two (unfinished)
This commit is contained in:
parent
c90fab0136
commit
d83f0125f3
7 changed files with 169 additions and 86 deletions
|
@ -23,6 +23,7 @@
|
||||||
#include "rsharesettings.h"
|
#include "rsharesettings.h"
|
||||||
#include "jsonapi/jsonapi.h"
|
#include "jsonapi/jsonapi.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
|
#include "util/qtthreadsutils.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
@ -58,7 +59,16 @@ JsonApiPage::JsonApiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
||||||
|
|
||||||
ui.listenAddressLineEdit->setValidator(ipValidator);
|
ui.listenAddressLineEdit->setValidator(ipValidator);
|
||||||
|
|
||||||
|
mEventHandlerId = 0;
|
||||||
|
|
||||||
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> /* event */)
|
||||||
|
{
|
||||||
|
std::cerr << "Caught JSONAPI event!" << std::endl;
|
||||||
|
RsQThreadUtils::postToObject([=]() { load(); }, this );
|
||||||
|
},
|
||||||
|
mEventHandlerId, RsEventType::JSON_API );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JsonApiPage::helpText() const
|
QString JsonApiPage::helpText() const
|
||||||
{
|
{
|
||||||
return tr("<h1><img width=\"24\" src=\":/icons/help_64.png\"> Webinterface</h1> \
|
return tr("<h1><img width=\"24\" src=\":/icons/help_64.png\"> Webinterface</h1> \
|
||||||
|
@ -101,9 +111,9 @@ bool JsonApiPage::updateParams()
|
||||||
|
|
||||||
void JsonApiPage::load()
|
void JsonApiPage::load()
|
||||||
{
|
{
|
||||||
whileBlocking(ui.portSpinBox)->setValue(Settings->getJsonApiPort());
|
whileBlocking(ui.portSpinBox)->setValue(rsJsonApi->listeningPort());
|
||||||
whileBlocking(ui.listenAddressLineEdit)->setText(Settings->getJsonApiListenAddress());
|
whileBlocking(ui.listenAddressLineEdit)->setText(QString::fromStdString(rsJsonApi->getBindingAddress()));
|
||||||
whileBlocking(ui.enableCheckBox)->setChecked(Settings->getJsonApiEnabled());
|
whileBlocking(ui.enableCheckBox)->setChecked(rsJsonApi->isRunning());
|
||||||
|
|
||||||
QStringList newTk;
|
QStringList newTk;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "retroshare/rsevents.h"
|
||||||
|
|
||||||
#include "retroshare-gui/configpage.h"
|
#include "retroshare-gui/configpage.h"
|
||||||
#include "gui/common/FilesDefs.h"
|
#include "gui/common/FilesDefs.h"
|
||||||
#include "ui_JsonApiPage.h"
|
#include "ui_JsonApiPage.h"
|
||||||
|
@ -63,4 +65,6 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::JsonApiPage ui; /// Qt Designer generated object
|
Ui::JsonApiPage ui; /// Qt Designer generated object
|
||||||
|
RsEventsHandlerId_t mEventHandlerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="WebuiPageVLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="jsonApiGroupBox">
|
<widget class="QGroupBox" name="jsonApiGroupBox">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
|
@ -25,7 +25,9 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>JSON API Server</string>
|
<string>JSON API Server</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="enableCheckBox">
|
<widget class="QCheckBox" name="enableCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -34,42 +36,32 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Port:</string>
|
<string>Status:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="portSpinBox">
|
<widget class="QLabel" name="statusLabelLED">
|
||||||
<property name="minimum">
|
|
||||||
<number>1024</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>65535</number>
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<number>9092</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Listen Address:</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="pixmap">
|
||||||
</item>
|
<pixmap resource="../images.qrc">:/images/ledoff1.png</pixmap>
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="listenAddressLineEdit">
|
|
||||||
<property name="text">
|
|
||||||
<string>127.0.0.1</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -107,16 +99,68 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Listen Address:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="listenAddressLineEdit">
|
||||||
|
<property name="text">
|
||||||
|
<string>127.0.0.1</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Port:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="portSpinBox">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1024</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>65535</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>9092</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Authenticated Tokens</string>
|
<string>Authenticated Tokens:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="tokensListView"/>
|
<widget class="QListView" name="tokensListView"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Registered services:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListView" name="providersListView"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -142,6 +186,8 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../images.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -73,22 +73,12 @@ void WebuiPage::selectWebInterfaceDirectory()
|
||||||
bool WebuiPage::updateParams(QString &errmsg)
|
bool WebuiPage::updateParams(QString &errmsg)
|
||||||
{
|
{
|
||||||
std::cerr << "WebuiPage::save()" << std::endl;
|
std::cerr << "WebuiPage::save()" << std::endl;
|
||||||
bool ok = true;
|
|
||||||
bool changed = false;
|
|
||||||
if(ui.enableWebUI_CB->isChecked() != Settings->getWebinterfaceEnabled())
|
|
||||||
changed = true;
|
|
||||||
if(ui.webInterfaceFiles_LE->text() != Settings->getWebinterfaceFilesDirectory())
|
|
||||||
changed = true;
|
|
||||||
|
|
||||||
if(changed)
|
|
||||||
{
|
|
||||||
// store config
|
// store config
|
||||||
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
|
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
|
||||||
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
|
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
|
||||||
|
|
||||||
rsWebUi->setHtmlFilesDirectory(ui.webInterfaceFiles_LE->text().toStdString());
|
return true;
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::onPasswordValueChanged(QString password)
|
void WebuiPage::onPasswordValueChanged(QString password)
|
||||||
|
@ -112,10 +102,20 @@ void WebuiPage::onPasswordValueChanged(QString password)
|
||||||
|
|
||||||
bool WebuiPage::restart()
|
bool WebuiPage::restart()
|
||||||
{
|
{
|
||||||
return checkStartWebui();
|
if(ui.password_LE->text().isNull())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(nullptr,tr("Missing passphrase"),tr("Please set a passphrase to proect the access to the WEB interface."));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::load()
|
rsWebUi->setUserPassword(ui.password_LE->text().toStdString());
|
||||||
|
rsWebUi->setHtmlFilesDirectory(ui.webInterfaceFiles_LE->text().toStdString());
|
||||||
|
rsWebUi->restart();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebuiPage::loadParams()
|
||||||
{
|
{
|
||||||
std::cerr << "WebuiPage::load()" << std::endl;
|
std::cerr << "WebuiPage::load()" << std::endl;
|
||||||
whileBlocking(ui.enableWebUI_CB)->setChecked(Settings->getWebinterfaceEnabled());
|
whileBlocking(ui.enableWebUI_CB)->setChecked(Settings->getWebinterfaceEnabled());
|
||||||
|
@ -138,11 +138,9 @@ QString WebuiPage::helpText() const
|
||||||
<p>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.</p>");
|
<p>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.</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*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->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
|
||||||
rsWebUi->restart();
|
rsWebUi->restart();
|
||||||
|
|
||||||
|
@ -177,13 +175,6 @@ void WebuiPage::onEnableCBClicked(bool checked)
|
||||||
ui.apply_PB->setEnabled(checked);
|
ui.apply_PB->setEnabled(checked);
|
||||||
ui.startWebBrowser_PB->setEnabled(checked);
|
ui.startWebBrowser_PB->setEnabled(checked);
|
||||||
QString S;
|
QString S;
|
||||||
|
|
||||||
Settings->setWebinterfaceEnabled(checked);
|
|
||||||
|
|
||||||
if(checked)
|
|
||||||
checkStartWebui();
|
|
||||||
else
|
|
||||||
checkShutdownWebui();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::onPortValueChanged(int /*value*/)
|
void WebuiPage::onPortValueChanged(int /*value*/)
|
||||||
|
@ -199,18 +190,19 @@ void WebuiPage::onAllIPCBClicked(bool /*checked*/)
|
||||||
}
|
}
|
||||||
void WebuiPage::onApplyClicked()
|
void WebuiPage::onApplyClicked()
|
||||||
{
|
{
|
||||||
rsWebUi->setUserPassword(ui.password_LE->text().toStdString());
|
|
||||||
|
|
||||||
QString errmsg;
|
QString errmsg;
|
||||||
updateParams(errmsg);
|
updateParams(errmsg);
|
||||||
|
|
||||||
|
if(ui.enableWebUI_CB->isChecked())
|
||||||
|
{
|
||||||
if(!restart())
|
if(!restart())
|
||||||
{
|
{
|
||||||
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
|
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
emit passwordChanged();
|
checkShutdownWebui();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::onStartWebBrowserClicked() { showWebui(); }
|
void WebuiPage::onStartWebBrowserClicked() { showWebui(); }
|
||||||
|
|
|
@ -42,11 +42,11 @@ public:
|
||||||
~WebuiPage();
|
~WebuiPage();
|
||||||
|
|
||||||
/** Loads the settings for this page */
|
/** 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 QPixmap iconPixmap() const override { return FilesDefs::getPixmapFromQtResourcePath(":/icons/settings/webinterface.svg") ; }
|
||||||
virtual QString pageName() const { return tr("Webinterface") ; }
|
virtual QString pageName() const override { return tr("Webinterface") ; }
|
||||||
virtual QString helpText() const;
|
virtual QString helpText() const override ;
|
||||||
|
|
||||||
// call this after start of libretroshare/Retroshare
|
// call this after start of libretroshare/Retroshare
|
||||||
// checks the settings and starts the webinterface if required
|
// checks the settings and starts the webinterface if required
|
||||||
|
@ -67,10 +67,9 @@ public slots:
|
||||||
void onApplyClicked();
|
void onApplyClicked();
|
||||||
void onStartWebBrowserClicked();
|
void onStartWebBrowserClicked();
|
||||||
|
|
||||||
signals:
|
|
||||||
void passwordChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void loadParams();
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
Ui::WebuiPage ui;
|
Ui::WebuiPage ui;
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,16 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>960</width>
|
<width>570</width>
|
||||||
<height>717</height>
|
<height>646</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="enableWebUI_CB">
|
<widget class="QCheckBox" name="enableWebUI_CB">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -21,6 +23,38 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="statusLabelLED">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="pixmap">
|
||||||
|
<pixmap resource="../images.qrc">:/images/ledoff1.png</pixmap>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="params_GB">
|
<widget class="QGroupBox" name="params_GB">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
|
|
@ -180,8 +180,6 @@ SettingsPage::initStackedWidget()
|
||||||
#ifdef RS_WEBUI
|
#ifdef RS_WEBUI
|
||||||
WebuiPage *webui_p = new WebuiPage() ;
|
WebuiPage *webui_p = new WebuiPage() ;
|
||||||
addPage(new WebuiPage() );
|
addPage(new WebuiPage() );
|
||||||
|
|
||||||
QObject::connect(webui_p,SIGNAL(passwordChanged()),jsonapi_p,SLOT(load()));
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue