mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
improved UI of webUI and JsonAPI and interaction between these two (unfinished)
This commit is contained in:
parent
c90fab0136
commit
d83f0125f3
@ -23,6 +23,7 @@
|
||||
#include "rsharesettings.h"
|
||||
#include "jsonapi/jsonapi.h"
|
||||
#include "util/misc.h"
|
||||
#include "util/qtthreadsutils.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QStringListModel>
|
||||
@ -58,7 +59,16 @@ JsonApiPage::JsonApiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
||||
|
||||
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
|
||||
{
|
||||
return tr("<h1><img width=\"24\" src=\":/icons/help_64.png\"> Webinterface</h1> \
|
||||
@ -101,9 +111,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;
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "retroshare/rsevents.h"
|
||||
|
||||
#include "retroshare-gui/configpage.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "ui_JsonApiPage.h"
|
||||
@ -63,4 +65,6 @@ public slots:
|
||||
|
||||
private:
|
||||
Ui::JsonApiPage ui; /// Qt Designer generated object
|
||||
RsEventsHandlerId_t mEventHandlerId;
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="WebuiPageVLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="jsonApiGroupBox">
|
||||
<property name="minimumSize">
|
||||
@ -25,51 +25,43 @@
|
||||
<property name="title">
|
||||
<string>JSON API Server</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableCheckBox">
|
||||
<property name="text">
|
||||
<string>Enable RetroShare JSON API Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QCheckBox" name="enableCheckBox">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
<string>Enable RetroShare JSON API Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="portSpinBox">
|
||||
<property name="minimum">
|
||||
<number>1024</number>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>9092</number>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Listen Address:</string>
|
||||
<string>Status:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="listenAddressLineEdit">
|
||||
<widget class="QLabel" name="statusLabelLED">
|
||||
<property name="text">
|
||||
<string>127.0.0.1</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../images.qrc">:/images/ledoff1.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -107,16 +99,68 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Authenticated Tokens</string>
|
||||
<string>Authenticated Tokens:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="tokensListView"/>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
@ -142,6 +186,8 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -73,22 +73,12 @@ void WebuiPage::selectWebInterfaceDirectory()
|
||||
bool WebuiPage::updateParams(QString &errmsg)
|
||||
{
|
||||
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
|
||||
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
|
||||
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
|
||||
// store config
|
||||
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
|
||||
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
|
||||
|
||||
rsWebUi->setHtmlFilesDirectory(ui.webInterfaceFiles_LE->text().toStdString());
|
||||
}
|
||||
return ok;
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebuiPage::onPasswordValueChanged(QString password)
|
||||
@ -112,10 +102,20 @@ void WebuiPage::onPasswordValueChanged(QString password)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
rsWebUi->setUserPassword(ui.password_LE->text().toStdString());
|
||||
rsWebUi->setHtmlFilesDirectory(ui.webInterfaceFiles_LE->text().toStdString());
|
||||
rsWebUi->restart();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebuiPage::load()
|
||||
void WebuiPage::loadParams()
|
||||
{
|
||||
std::cerr << "WebuiPage::load()" << std::endl;
|
||||
whileBlocking(ui.enableWebUI_CB)->setChecked(Settings->getWebinterfaceEnabled());
|
||||
@ -138,13 +138,11 @@ 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>");
|
||||
}
|
||||
|
||||
/*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;
|
||||
}
|
||||
@ -177,13 +175,6 @@ void WebuiPage::onEnableCBClicked(bool checked)
|
||||
ui.apply_PB->setEnabled(checked);
|
||||
ui.startWebBrowser_PB->setEnabled(checked);
|
||||
QString S;
|
||||
|
||||
Settings->setWebinterfaceEnabled(checked);
|
||||
|
||||
if(checked)
|
||||
checkStartWebui();
|
||||
else
|
||||
checkShutdownWebui();
|
||||
}
|
||||
|
||||
void WebuiPage::onPortValueChanged(int /*value*/)
|
||||
@ -199,18 +190,19 @@ void WebuiPage::onAllIPCBClicked(bool /*checked*/)
|
||||
}
|
||||
void WebuiPage::onApplyClicked()
|
||||
{
|
||||
rsWebUi->setUserPassword(ui.password_LE->text().toStdString());
|
||||
|
||||
QString errmsg;
|
||||
updateParams(errmsg);
|
||||
|
||||
if(!restart())
|
||||
if(ui.enableWebUI_CB->isChecked())
|
||||
{
|
||||
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
|
||||
return;
|
||||
if(!restart())
|
||||
{
|
||||
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
checkShutdownWebui();
|
||||
}
|
||||
|
||||
emit passwordChanged();
|
||||
}
|
||||
|
||||
void WebuiPage::onStartWebBrowserClicked() { showWebui(); }
|
||||
|
@ -42,11 +42,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 +67,9 @@ public slots:
|
||||
void onApplyClicked();
|
||||
void onStartWebBrowserClicked();
|
||||
|
||||
signals:
|
||||
void passwordChanged();
|
||||
|
||||
private:
|
||||
virtual void loadParams();
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::WebuiPage ui;
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>960</width>
|
||||
<height>717</height>
|
||||
<width>570</width>
|
||||
<height>646</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -15,11 +15,45 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableWebUI_CB">
|
||||
<property name="text">
|
||||
<string>Enable Retroshare WEB Interface</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableWebUI_CB">
|
||||
<property name="text">
|
||||
<string>Enable Retroshare WEB Interface</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QGroupBox" name="params_GB">
|
||||
|
@ -180,8 +180,6 @@ SettingsPage::initStackedWidget()
|
||||
#ifdef RS_WEBUI
|
||||
WebuiPage *webui_p = new WebuiPage() ;
|
||||
addPage(new WebuiPage() );
|
||||
|
||||
QObject::connect(webui_p,SIGNAL(passwordChanged()),jsonapi_p,SLOT(load()));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user