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