mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
fixed start/stop of webinterface from GUI
This commit is contained in:
parent
d19d1685de
commit
9007d266a8
@ -452,7 +452,22 @@ void JsonApiServer::setNewAccessRequestCallback(
|
|||||||
const std::function<bool (const std::string&)>& callback )
|
const std::function<bool (const std::string&)>& callback )
|
||||||
{ mNewAccessRequestCallback = callback; }
|
{ mNewAccessRequestCallback = callback; }
|
||||||
|
|
||||||
void JsonApiServer::shutdown() { mService.stop(); }
|
void JsonApiServer::shutdown()
|
||||||
|
{
|
||||||
|
mService.stop();
|
||||||
|
|
||||||
|
RsThread::ask_for_stop();
|
||||||
|
|
||||||
|
std::cerr << "Stopping JsonApiServer" ;
|
||||||
|
|
||||||
|
while(isRunning())
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
std::cerr << "." ;
|
||||||
|
std::cerr.flush();
|
||||||
|
}
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
bool JsonApiServer::requestNewTokenAutorization(const std::string& token)
|
bool JsonApiServer::requestNewTokenAutorization(const std::string& token)
|
||||||
{
|
{
|
||||||
|
@ -144,7 +144,7 @@ public:
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::cerr << "Starting web service on port " << std::dec << _listening_port << std::endl;
|
std::cerr << "(II) Starting web service on port " << std::dec << _listening_port << std::endl;
|
||||||
_service->start( settings );
|
_service->start( settings );
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
@ -153,7 +153,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "(II) Shutting down webui service." << std::endl;
|
std::cerr << "(II) webui service stopped." << std::endl;
|
||||||
}
|
}
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
@ -162,7 +162,10 @@ public:
|
|||||||
RsThread::ask_for_stop();
|
RsThread::ask_for_stop();
|
||||||
|
|
||||||
while(isRunning())
|
while(isRunning())
|
||||||
sleep(1);
|
{
|
||||||
|
std::cerr << "(II) shutting down webui service." << std::endl;
|
||||||
|
rstime::rs_usleep(1000*1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setListeningPort(uint16_t p) { _listening_port = p ; }
|
void setListeningPort(uint16_t p) { _listening_port = p ; }
|
||||||
|
@ -48,6 +48,7 @@ bool JsonApiPage::updateParams(QString &errmsg)
|
|||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
bool enabled = ui.enableCheckBox->isChecked();
|
bool enabled = ui.enableCheckBox->isChecked();
|
||||||
|
|
||||||
if( enabled != Settings->getJsonApiEnabled())
|
if( enabled != Settings->getJsonApiEnabled())
|
||||||
{
|
{
|
||||||
Settings->setJsonApiEnabled(enabled);
|
Settings->setJsonApiEnabled(enabled);
|
||||||
@ -55,6 +56,7 @@ bool JsonApiPage::updateParams(QString &errmsg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t port = static_cast<uint16_t>(ui.portSpinBox->value());
|
uint16_t port = static_cast<uint16_t>(ui.portSpinBox->value());
|
||||||
|
|
||||||
if(port != Settings->getJsonApiPort())
|
if(port != Settings->getJsonApiPort())
|
||||||
{
|
{
|
||||||
Settings->setJsonApiPort(port);
|
Settings->setJsonApiPort(port);
|
||||||
@ -106,14 +108,17 @@ QString JsonApiPage::helpText() const { return ""; }
|
|||||||
|
|
||||||
/*static*/ void JsonApiPage::checkShutdownJsonApi()
|
/*static*/ void JsonApiPage::checkShutdownJsonApi()
|
||||||
{
|
{
|
||||||
JsonApiServer::instance().shutdown();
|
if(!JsonApiServer::instance().isRunning())
|
||||||
|
return;
|
||||||
|
|
||||||
|
JsonApiServer::instance().shutdown(); // this is a blocking call until the thread is terminated.
|
||||||
|
|
||||||
|
#ifdef SUSPENDED_CODE
|
||||||
/* It is important to make a copy of +jsonApiServer+ pointer so the old
|
/* It is important to make a copy of +jsonApiServer+ pointer so the old
|
||||||
* object can be deleted later, while the original pointer is
|
* object can be deleted later, while the original pointer is
|
||||||
* reassigned */
|
* reassigned */
|
||||||
|
|
||||||
QProgressDialog* pd = new QProgressDialog(
|
QProgressDialog* pd = new QProgressDialog("Stopping JSON API Server", QString(), 0, 3000);
|
||||||
"Stopping JSON API Server", QString(), 0, 3000);
|
|
||||||
QTimer* prtm = new QTimer;
|
QTimer* prtm = new QTimer;
|
||||||
prtm->setInterval(16); // 60 FPS
|
prtm->setInterval(16); // 60 FPS
|
||||||
connect( prtm, &QTimer::timeout,
|
connect( prtm, &QTimer::timeout,
|
||||||
@ -131,6 +136,7 @@ QString JsonApiPage::helpText() const { return ""; }
|
|||||||
prtm->deleteLater();
|
prtm->deleteLater();
|
||||||
pd->deleteLater();
|
pd->deleteLater();
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonApiPage::onApplyClicked(bool)
|
void JsonApiPage::onApplyClicked(bool)
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>521</width>
|
<width>545</width>
|
||||||
<height>393</height>
|
<height>569</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -123,7 +123,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="applyConfigPushButton">
|
<widget class="QPushButton" name="applyConfigPushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Restart JSON API Server to apply settings</string>
|
<string>Apply settings</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -50,6 +50,8 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
|||||||
connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString)));
|
connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString)));
|
||||||
connect(ui.startWebBrowser_PB, SIGNAL(clicked()), this, SLOT(onStartWebBrowserClicked()));
|
connect(ui.startWebBrowser_PB, SIGNAL(clicked()), this, SLOT(onStartWebBrowserClicked()));
|
||||||
connect(ui.webInterfaceFilesDirectory_PB, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
|
connect(ui.webInterfaceFilesDirectory_PB, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
|
||||||
|
|
||||||
|
checkStartWebui();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebuiPage::~WebuiPage()
|
WebuiPage::~WebuiPage()
|
||||||
@ -110,9 +112,9 @@ void WebuiPage::load()
|
|||||||
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
|
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
|
||||||
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
|
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
|
||||||
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
|
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
|
||||||
onEnableCBClicked(Settings->getWebinterfaceEnabled());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString WebuiPage::helpText() const
|
QString WebuiPage::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> \
|
||||||
@ -123,7 +125,7 @@ QString WebuiPage::helpText() const
|
|||||||
/*static*/ bool WebuiPage::checkStartWebui()
|
/*static*/ bool WebuiPage::checkStartWebui()
|
||||||
{
|
{
|
||||||
if(!Settings->getWebinterfaceEnabled())
|
if(!Settings->getWebinterfaceEnabled())
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
rsWebUI->setListeningPort(Settings->getWebinterfacePort());
|
rsWebUI->setListeningPort(Settings->getWebinterfacePort());
|
||||||
rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
|
rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
|
||||||
@ -156,7 +158,11 @@ 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;
|
||||||
updateParams(S);
|
|
||||||
|
if(checked)
|
||||||
|
checkStartWebui();
|
||||||
|
else
|
||||||
|
checkShutdownWebui();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::onPortValueChanged(int /*value*/)
|
void WebuiPage::onPortValueChanged(int /*value*/)
|
||||||
|
@ -572,10 +572,6 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
|
|||||||
|
|
||||||
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
|
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
|
||||||
|
|
||||||
#ifdef RS_WEBUI
|
|
||||||
WebuiPage::checkStartWebui();
|
|
||||||
#endif // ENABLE_WEBUI
|
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
JsonApiPage::checkStartJsonApi();
|
JsonApiPage::checkStartJsonApi();
|
||||||
#endif // RS_JSONAPI
|
#endif // RS_JSONAPI
|
||||||
|
Loading…
Reference in New Issue
Block a user