2018-07-17 06:10:35 -05:00
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2021-01-04 04:04:45 -06:00
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
2018-07-17 06:10:35 -05:00
// This software is released under the PostgreSQL Licence
//
// MenuActions.cpp - Common file for menu actions.
//
//////////////////////////////////////////////////////////////////////////
2020-07-28 05:43:05 -05:00
# include "pgAdmin4.h"
2018-07-17 06:10:35 -05:00
# include "MenuActions.h"
2020-07-28 05:43:05 -05:00
# include <QApplication>
2018-07-19 05:32:40 -05:00
# include <QClipboard>
2020-07-28 05:43:05 -05:00
# include <QDesktopServices>
# include <QEventLoop>
2018-07-17 06:10:35 -05:00
# include <QMessageBox>
2020-07-28 05:43:05 -05:00
# include <QProcess>
# include <QSettings>
2018-07-17 06:10:35 -05:00
2020-06-16 04:23:40 -05:00
MenuActions : : MenuActions ( )
2018-07-17 06:10:35 -05:00
{
}
void MenuActions : : setAppServerUrl ( QString appServerUrl )
{
m_appServerUrl = appServerUrl ;
}
// Create a new application browser window on user request
2020-07-29 07:56:41 -05:00
void MenuActions : : onNew ( ) const
2018-07-17 06:10:35 -05:00
{
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 04:40:49 -06:00
QMessageBox : : critical ( Q_NULLPTR , QString ( QWidget : : tr ( " Fatal Error " ) ) , error ) ;
2018-07-17 06:10:35 -05:00
exit ( 1 ) ;
}
}
}
2018-07-19 05:32:40 -05:00
// Copy the application server URL to the clipboard
2020-07-29 07:56:41 -05:00
void MenuActions : : onCopyUrl ( ) const
2018-07-19 05:32:40 -05:00
{
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( m_appServerUrl ) ;
}
2018-07-17 06:10:35 -05:00
// Show the config dialogue
void MenuActions : : onConfig ( )
{
2020-07-28 05:43:05 -05:00
if ( ! m_configWindow )
m_configWindow = new ConfigWindow ( ) ;
2018-07-17 06:10:35 -05:00
2020-09-08 01:30:24 -05:00
m_configWindow - > setConfigValues ( ) ;
2020-07-28 05:43:05 -05:00
m_configWindow - > show ( ) ;
m_configWindow - > raise ( ) ;
m_configWindow - > activateWindow ( ) ;
connect ( m_configWindow , SIGNAL ( accepted ( bool ) ) , this , SLOT ( onConfigDone ( bool ) ) ) ;
}
2018-07-17 06:10:35 -05:00
2020-07-29 05:01:38 -05:00
void MenuActions : : onConfigDone ( bool needRestart ) const
2020-07-28 05:43:05 -05:00
{
2020-07-29 05:01:38 -05:00
if ( needRestart & & QMessageBox : : Yes = = QMessageBox : : question ( Q_NULLPTR ,
tr ( " Shut down server? " ) ,
tr ( " The pgAdmin 4 server must be restarted for changes to take effect. Do you want to shut down the server now? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) )
2020-07-28 05:43:05 -05:00
{
2020-07-29 05:01:38 -05:00
exit ( 0 ) ;
2018-07-17 06:10:35 -05:00
}
}
// Show the log window
void MenuActions : : onLog ( )
{
QSettings settings ;
if ( ! m_logWindow )
2020-07-28 05:43:05 -05:00
m_logWindow = new LogWindow ( ) ;
2018-07-17 06:10:35 -05:00
m_logWindow - > show ( ) ;
m_logWindow - > raise ( ) ;
m_logWindow - > activateWindow ( ) ;
2020-07-28 05:43:05 -05:00
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
2018-07-17 06:10:35 -05:00
2020-05-07 05:01:02 -05:00
m_logWindow - > LoadLog ( ) ;
2018-07-17 06:10:35 -05:00
}
// Exit
void MenuActions : : onQuit ( )
{
2020-07-28 05:43:05 -05:00
if ( QMessageBox : : Yes = = QMessageBox : : question ( Q_NULLPTR , tr ( " Shut down server? " ) , tr ( " Are you sure you want to shut down the pgAdmin 4 server? " ) , QMessageBox : : Yes | QMessageBox : : No ) )
2018-07-17 06:10:35 -05:00
{
// Emit the signal to shut down the python server.
emit shutdownSignal ( m_appServerUrl ) ;
2020-07-28 05:43:05 -05:00
QApplication : : quit ( ) ;
2018-07-17 06:10:35 -05:00
}
}