2018-07-17 11:10:35 +00:00
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2019-01-02 10:24:12 +00:00
// Copyright (C) 2013 - 2019, The pgAdmin Development Team
2018-07-17 11:10:35 +00:00
// This software is released under the PostgreSQL Licence
//
// MenuActions.cpp - Common file for menu actions.
//
//////////////////////////////////////////////////////////////////////////
# include "MenuActions.h"
// QT headers
2018-07-19 10:32:40 +00:00
# include <QClipboard>
2018-07-17 11:10:35 +00:00
# include <QMessageBox>
MenuActions : : MenuActions ( )
{
2018-12-06 10:40:49 +00:00
m_logWindow = Q_NULLPTR ;
2018-07-17 11:10:35 +00:00
m_logFile = " " ;
m_appServerUrl = " " ;
}
MenuActions : : ~ MenuActions ( )
{
}
void MenuActions : : setAppServerUrl ( QString appServerUrl )
{
m_appServerUrl = appServerUrl ;
}
void MenuActions : : setLogFile ( QString logFile )
{
m_logFile = logFile ;
}
// Create a new application browser window on user request
void MenuActions : : onNew ( )
{
QSettings settings ;
QString cmd = settings . value ( " BrowserCommand " ) . toString ( ) ;
if ( ! cmd . isEmpty ( ) )
{
cmd . replace ( " %URL% " , m_appServerUrl ) ;
QProcess : : startDetached ( cmd ) ;
}
else
{
if ( ! QDesktopServices : : openUrl ( m_appServerUrl ) )
{
QString error ( QWidget : : tr ( " Failed to open the system default web browser. Is one installed?. " ) ) ;
2018-12-06 10:40:49 +00:00
QMessageBox : : critical ( Q_NULLPTR , QString ( QWidget : : tr ( " Fatal Error " ) ) , error ) ;
2018-07-17 11:10:35 +00:00
exit ( 1 ) ;
}
}
}
2018-07-19 10:32:40 +00:00
// Copy the application server URL to the clipboard
void MenuActions : : onCopyUrl ( )
{
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( m_appServerUrl ) ;
}
2018-07-17 11:10:35 +00:00
// Show the config dialogue
void MenuActions : : onConfig ( )
{
QSettings settings ;
bool ok ;
ConfigWindow * dlg = new ConfigWindow ( ) ;
dlg - > setWindowTitle ( QString ( tr ( " %1 Configuration " ) ) . arg ( PGA_APP_NAME ) ) ;
dlg - > setBrowserCommand ( settings . value ( " BrowserCommand " ) . toString ( ) ) ;
2018-07-19 11:54:53 +00:00
dlg - > setFixedPort ( settings . value ( " FixedPort " ) . toBool ( ) ) ;
dlg - > setPortNumber ( settings . value ( " PortNumber " ) . toInt ( ) ) ;
2018-07-17 11:10:35 +00:00
dlg - > setPythonPath ( settings . value ( " PythonPath " ) . toString ( ) ) ;
dlg - > setApplicationPath ( settings . value ( " ApplicationPath " ) . toString ( ) ) ;
dlg - > setModal ( true ) ;
ok = dlg - > exec ( ) ;
QString browsercommand = dlg - > getBrowserCommand ( ) ;
2018-07-19 11:54:53 +00:00
bool fixedport = dlg - > getFixedPort ( ) ;
int portnumber = dlg - > getPortNumber ( ) ;
2018-07-17 11:10:35 +00:00
QString pythonpath = dlg - > getPythonPath ( ) ;
QString applicationpath = dlg - > getApplicationPath ( ) ;
if ( ok )
{
2018-07-19 11:54:53 +00:00
bool needRestart = ( settings . value ( " FixedPort " ) . toBool ( ) ! = fixedport | |
settings . value ( " PortNumber " ) . toInt ( ) ! = portnumber | |
settings . value ( " PythonPath " ) . toString ( ) ! = pythonpath | |
2018-07-17 11:10:35 +00:00
settings . value ( " ApplicationPath " ) . toString ( ) ! = applicationpath ) ;
settings . setValue ( " BrowserCommand " , browsercommand ) ;
2018-07-19 11:54:53 +00:00
settings . setValue ( " FixedPort " , fixedport ) ;
settings . setValue ( " PortNumber " , portnumber ) ;
2018-07-17 11:10:35 +00:00
settings . setValue ( " PythonPath " , pythonpath ) ;
settings . setValue ( " ApplicationPath " , applicationpath ) ;
if ( needRestart )
{
2018-12-06 10:40:49 +00:00
if ( QMessageBox : : Yes = = QMessageBox : : question ( Q_NULLPTR , tr ( " Shut down server? " ) , QString ( tr ( " The %1 server must be restarted for changes to take effect. Do you want to shut down the server now? " ) ) . arg ( PGA_APP_NAME ) , QMessageBox : : Yes | QMessageBox : : No ) )
2018-07-17 11:10:35 +00:00
{
exit ( 0 ) ;
}
}
}
}
// Show the log window
void MenuActions : : onLog ( )
{
QSettings settings ;
if ( ! m_logWindow )
{
2018-12-06 10:40:49 +00:00
m_logWindow = new LogWindow ( Q_NULLPTR , m_logFile ) ;
2018-07-17 11:10:35 +00:00
m_logWindow - > setWindowTitle ( QString ( tr ( " %1 Log " ) ) . arg ( PGA_APP_NAME ) ) ;
}
m_logWindow - > show ( ) ;
m_logWindow - > raise ( ) ;
m_logWindow - > activateWindow ( ) ;
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
m_logWindow - > ReadLog ( ) ;
}
// Exit
void MenuActions : : onQuit ( )
{
2018-12-06 10:40:49 +00:00
if ( QMessageBox : : Yes = = QMessageBox : : question ( Q_NULLPTR , tr ( " Shut down server? " ) , QString ( tr ( " Are you sure you want to shut down the %1 server? " ) ) . arg ( PGA_APP_NAME ) , QMessageBox : : Yes | QMessageBox : : No ) )
2018-07-17 11:10:35 +00:00
{
// Emit the signal to shut down the python server.
emit shutdownSignal ( m_appServerUrl ) ;
exit ( 0 ) ;
}
}