From 4da327088c864aa406ca99561590557a2519fde5 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 3 Apr 2020 19:43:00 +0530 Subject: [PATCH] Added an option to prevent a browser tab being opened at startup. Fixes #5353 --- docs/en_US/desktop_deployment.rst | 6 ++ docs/en_US/release_notes_4_21.rst | 1 + runtime/ConfigWindow.cpp | 17 +++++ runtime/ConfigWindow.h | 2 + runtime/ConfigWindow.ui | 113 ++++++++++++++++++++++++------ runtime/MenuActions.cpp | 3 + runtime/pgAdmin4.cpp | 34 +++++---- 7 files changed, 142 insertions(+), 34 deletions(-) diff --git a/docs/en_US/desktop_deployment.rst b/docs/en_US/desktop_deployment.rst index b5d911ff1..3453ab73e 100644 --- a/docs/en_US/desktop_deployment.rst +++ b/docs/en_US/desktop_deployment.rst @@ -71,6 +71,12 @@ The configuration settings: +--------------------------+--------------------+---------------------------------------------------------------+ | ConnectionTimeout | Integer | The number of seconds to wait for application server startup. | +--------------------------+--------------------+---------------------------------------------------------------+ + | FixedPort | Boolean | Use a fixed network port number rather than a random one. | + +--------------------------+--------------------+---------------------------------------------------------------+ + | OpenTabAtStartup | Boolean | Open a browser tab at startup. | + +--------------------------+--------------------+---------------------------------------------------------------+ + | PortNumber | Integer | The port number to use, if using a fixed port. | + +--------------------------+--------------------+---------------------------------------------------------------+ | PythonPath | String | The Python module search path | +--------------------------+--------------------+---------------------------------------------------------------+ diff --git a/docs/en_US/release_notes_4_21.rst b/docs/en_US/release_notes_4_21.rst index 619f249ec..ec540618b 100644 --- a/docs/en_US/release_notes_4_21.rst +++ b/docs/en_US/release_notes_4_21.rst @@ -11,6 +11,7 @@ New features | `Issue #5184 `_ - Added support for parameterĀ toast_tuple_target andĀ parallel_workers of the table. | `Issue #5264 `_ - Added support of Packages, Sequences and Synonyms to the Schema Diff. +| `Issue #5353 `_ - Added an option to prevent a browser tab being opened at startup. Housekeeping ************ diff --git a/runtime/ConfigWindow.cpp b/runtime/ConfigWindow.cpp index 275d6b440..c8c06e59e 100644 --- a/runtime/ConfigWindow.cpp +++ b/runtime/ConfigWindow.cpp @@ -57,6 +57,11 @@ int ConfigWindow::getPortNumber() return ui->spinPortNumber->value(); } +bool ConfigWindow::getOpenTabAtStartup() +{ + return ui->chkOpenTabAtStartup->isChecked(); +} + QString ConfigWindow::getPythonPath() { return ui->pythonPathLineEdit->text(); @@ -92,6 +97,18 @@ void ConfigWindow::setPortNumber(int port) ui->spinPortNumber->setValue(port); } +void ConfigWindow::setOpenTabAtStartup(bool openTabAtStartup) +{ + if (openTabAtStartup) + { + ui->chkOpenTabAtStartup->setCheckState(Qt::Checked); + } + else + { + ui->chkOpenTabAtStartup->setCheckState(Qt::Unchecked); + } +} + void ConfigWindow::setPythonPath(QString path) { ui->pythonPathLineEdit->setText(path); diff --git a/runtime/ConfigWindow.h b/runtime/ConfigWindow.h index ed948d603..cafb9a14f 100644 --- a/runtime/ConfigWindow.h +++ b/runtime/ConfigWindow.h @@ -29,12 +29,14 @@ public: QString getBrowserCommand(); bool getFixedPort(); int getPortNumber(); + bool getOpenTabAtStartup(); QString getPythonPath(); QString getApplicationPath(); void setBrowserCommand(QString command); void setFixedPort(bool fixedPort); void setPortNumber(int port); + void setOpenTabAtStartup(bool openTabAtStartup); void setPythonPath(QString path); void setApplicationPath(QString path); diff --git a/runtime/ConfigWindow.ui b/runtime/ConfigWindow.ui index 8811220b2..6757f1bab 100644 --- a/runtime/ConfigWindow.ui +++ b/runtime/ConfigWindow.ui @@ -7,7 +7,7 @@ 0 0 731 - 300 + 398 @@ -228,6 +228,66 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + By default, when the pgAdmin server is started a browser tab will be automatically opened to display the user interface. Un-check this option to run the server without automatically opening the browser. + + + true + + + + + + + + + Open a Browser Window/Tab at Startup? + + + + + + + Qt::RightToLeft + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -267,17 +327,26 @@ - - - - /usr/pgadmin4/web + + + + Qt::Vertical - + + QSizePolicy::Expanding + + + + 20 + 60 + + + - - - - /usr/pgadmin4/lib/python2.7;/usr/pgadmin4/lib/python2.7/site-packages + + + + Python Path @@ -288,10 +357,17 @@ - - - - Python Path + + + + /usr/pgadmin4/lib/python2.7;/usr/pgadmin4/lib/python2.7/site-packages + + + + + + + /usr/pgadmin4/web @@ -312,18 +388,15 @@ - - + + Qt::Vertical - - QSizePolicy::Expanding - 20 - 60 + 40 diff --git a/runtime/MenuActions.cpp b/runtime/MenuActions.cpp index 5115a429c..18d578922 100644 --- a/runtime/MenuActions.cpp +++ b/runtime/MenuActions.cpp @@ -79,6 +79,7 @@ void MenuActions::onConfig() dlg->setBrowserCommand(settings.value("BrowserCommand").toString()); dlg->setFixedPort(settings.value("FixedPort").toBool()); dlg->setPortNumber(settings.value("PortNumber").toInt()); + dlg->setOpenTabAtStartup(settings.value("OpenTabAtStartup", true).toBool()); dlg->setPythonPath(settings.value("PythonPath").toString()); dlg->setApplicationPath(settings.value("ApplicationPath").toString()); dlg->setModal(true); @@ -87,6 +88,7 @@ void MenuActions::onConfig() QString browsercommand = dlg->getBrowserCommand(); bool fixedport = dlg->getFixedPort(); int portnumber = dlg->getPortNumber(); + bool opentabatstartup = dlg->getOpenTabAtStartup(); QString pythonpath = dlg->getPythonPath(); QString applicationpath = dlg->getApplicationPath(); @@ -100,6 +102,7 @@ void MenuActions::onConfig() settings.setValue("BrowserCommand", browsercommand); settings.setValue("FixedPort", fixedport); settings.setValue("PortNumber", portnumber); + settings.setValue("OpenTabAtStartup", opentabatstartup); settings.setValue("PythonPath", pythonpath); settings.setValue("ApplicationPath", applicationpath); diff --git a/runtime/pgAdmin4.cpp b/runtime/pgAdmin4.cpp index e4d164bb7..7a1b79801 100644 --- a/runtime/pgAdmin4.cpp +++ b/runtime/pgAdmin4.cpp @@ -313,6 +313,7 @@ int main(int argc, char * argv[]) dlg->setBrowserCommand(settings.value("BrowserCommand").toString()); dlg->setFixedPort(settings.value("FixedPort").toBool()); dlg->setPortNumber(settings.value("PortNumber").toInt()); + dlg->setOpenTabAtStartup(settings.value("OpenTabAtStartup", true).toBool()); dlg->setPythonPath(settings.value("PythonPath").toString()); dlg->setApplicationPath(settings.value("ApplicationPath").toString()); dlg->setModal(true); @@ -321,6 +322,7 @@ int main(int argc, char * argv[]) QString browsercommand = dlg->getBrowserCommand(); bool fixedport = dlg->getFixedPort(); int portnumber = dlg->getPortNumber(); + bool opentabatstartup = dlg->getOpenTabAtStartup(); QString pythonpath = dlg->getPythonPath(); QString applicationpath = dlg->getApplicationPath(); @@ -329,6 +331,7 @@ int main(int argc, char * argv[]) settings.setValue("BrowserCommand", browsercommand); settings.setValue("FixedPort", fixedport); settings.setValue("PortNumber", portnumber); + settings.setValue("OpenTabAtStartup", opentabatstartup); settings.setValue("PythonPath", pythonpath); settings.setValue("ApplicationPath", applicationpath); settings.sync(); @@ -416,23 +419,26 @@ int main(int argc, char * argv[]) if (floatingWindow != Q_NULLPTR) floatingWindow->enableShutdownMenu(); - QString cmd = settings.value("BrowserCommand").toString(); + if (settings.value("OpenTabAtStartup", true).toBool()) + { + QString cmd = settings.value("BrowserCommand").toString(); - if (!cmd.isEmpty()) - { - cmd.replace("%URL%", appServerUrl); - QProcess::startDetached(cmd); - } - else - { - if (!QDesktopServices::openUrl(appServerUrl)) + if (!cmd.isEmpty()) { - QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); - QMessageBox::critical(Q_NULLPTR, QString(QWidget::tr("Fatal Error")), error); + cmd.replace("%URL%", appServerUrl); + QProcess::startDetached(cmd); + } + else + { + if (!QDesktopServices::openUrl(appServerUrl)) + { + QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); + QMessageBox::critical(Q_NULLPTR, QString(QWidget::tr("Fatal Error")), error); - Logger::GetLogger()->Log(error); - Logger::ReleaseLogger(); - exit(1); + Logger::GetLogger()->Log(error); + Logger::ReleaseLogger(); + exit(1); + } } }