1) Fixed issue of opening Query Tool and Debugger in new Tab with QT 5.8 and annulen webkit
 2) Moved unload event of window from javascript files to html.
 3) Change alertify messages for debugger.
 4) Closed all connections created by debugger. Previously only one connection has been closed.
This commit is contained in:
Neel Patel 2017-05-09 13:03:44 +05:30 committed by Akshay Joshi
parent 63d42745ef
commit d0e9c82fea
11 changed files with 292 additions and 133 deletions

View File

@ -73,8 +73,18 @@ BrowserWindow::BrowserWindow(QString url)
m_tabGridLayout = new QGridLayout(m_pgAdminMainTab);
m_tabGridLayout->setContentsMargins(0, 0, 0, 0);
m_mainWebView = new WebViewWindow(m_pgAdminMainTab);
#ifdef PGADMIN4_USE_WEBENGINE
m_mainWebView->setPage(new WebEnginePage());
m_mainWebView->page()->setNetworkAccessManager(m_netAccessMan);
#else
m_cookieJar = new QNetworkCookieJar();
m_netAccessMan = new QNetworkAccessManager();
m_netAccessMan->setCookieJar(m_cookieJar);
m_mainWebView->setPage(new WebViewPage());
m_mainWebView->page()->setNetworkAccessManager(m_netAccessMan);
m_mainWebView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
m_mainWebView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
#endif
#ifdef PGADMIN4_DEBUG
@ -107,6 +117,8 @@ BrowserWindow::BrowserWindow(QString url)
#else
// Register the slot when click on the URL link form main menu bar
connect(m_mainWebView, SIGNAL(linkClicked(const QUrl &)),SLOT(urlLinkClicked(const QUrl &)));
// Register the slot when click on the URL link for QWebPage
connect(m_mainWebView->page(), SIGNAL(createTabWindowKit(QWebPage * &)),SLOT(createNewTabWindowKit(QWebPage * &)));
#endif
// Register the slot on tab index change
@ -120,6 +132,7 @@ BrowserWindow::BrowserWindow(QString url)
m_mainWebView->page()->setForwardUnsupportedContent(true);
connect(m_mainWebView->page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(download(const QNetworkRequest &)));
connect(m_mainWebView->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(unsupportedContent(QNetworkReply*)));
m_mainWebView->page()->setForwardUnsupportedContent(true);
m_mainWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
#endif
@ -150,6 +163,13 @@ BrowserWindow::BrowserWindow(QString url)
m_mainWebView->setUrl(m_appServerUrl);
}
// Destructor
BrowserWindow::~BrowserWindow()
{
if (m_tabWidget)
delete m_tabWidget;
}
// Save the window geometry on close
void BrowserWindow::closeEvent(QCloseEvent *event)
{
@ -787,9 +807,9 @@ void BrowserWindow::closetabs()
// If QTabWidget contains only one tab then hide the TabBar window
if ((totalTabs - 1) < 2)
m_tabWidget->tabBar()->setVisible(false);
m_tabWidget->tabBar()->setVisible(false);
else
m_tabWidget->tabBar()->setVisible(true);
m_tabWidget->tabBar()->setVisible(true);
QObject *senderPtr = QObject::sender();
if (senderPtr != NULL)
@ -806,7 +826,24 @@ void BrowserWindow::closetabs()
// free the allocated memory when the tab is closed
if (tab != NULL)
{
QList<QWidget*> widgetList = tab->findChildren<QWidget*>();
foreach (QWidget* widgetPtr, widgetList)
{
if (widgetPtr != NULL)
{
webviewPtr = dynamic_cast<WebViewWindow*>(widgetPtr);
if (webviewPtr != NULL)
{
// Trigger the action for tab window close so unload event
// will be called and resources will be freed properly.
webviewPtr->page()->triggerAction(QWebPage::RequestClose);
}
}
}
delete tab;
}
// Adjust the tab index value if the tab is closed in between
for (loopCount = 1; loopCount < totalTabs; loopCount++)
@ -905,6 +942,7 @@ void BrowserWindow::tabTitleChanged(const QString &str)
}
}
void BrowserWindow::current_dir_path(const QString &dir)
{
m_dir = dir;
@ -914,6 +952,72 @@ void BrowserWindow::current_dir_path(const QString &dir)
settings.setValue("Browser/LastSaveLocation", m_last_open_folder_path);
}
#ifndef PGADMIN4_USE_WEBENGINE
void BrowserWindow::createNewTabWindowKit(QWebPage * &p)
{
m_addNewTab = new QWidget(m_tabWidget);
m_addNewGridLayout = new QGridLayout(m_addNewTab);
m_addNewGridLayout->setContentsMargins(0, 0, 0, 0);
m_addNewWebView = new WebViewWindow(m_addNewTab);
m_addNewWebView->setPage(new WebViewPage());
m_addNewWebView->setZoomFactor(m_mainWebView->zoomFactor());
m_addNewWebView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
m_addNewWebView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
m_widget = new QWidget(m_addNewTab);
m_toolBtnBack = new QToolButton(m_widget);
m_toolBtnBack->setFixedHeight(PGA_BTN_SIZE);
m_toolBtnBack->setFixedWidth(PGA_BTN_SIZE);
m_toolBtnBack->setIcon(QIcon(":/back.png"));
m_toolBtnBack->setToolTip(tr("Go back"));
m_toolBtnBack->setDisabled(true);
m_toolBtnForward = new QToolButton(m_widget);
m_toolBtnForward->setFixedHeight(PGA_BTN_SIZE);
m_toolBtnForward->setFixedWidth(PGA_BTN_SIZE);
m_toolBtnForward->setIcon(QIcon(":/forward.png"));
m_toolBtnForward->setToolTip(tr("Go forward"));
m_toolBtnForward->setDisabled(true);
QPushButton *m_btnClose = new QPushButton(m_widget);
m_btnClose->setFixedHeight(PGA_BTN_SIZE);
m_btnClose->setFixedWidth(PGA_BTN_SIZE);
m_btnClose->setIcon(QIcon(":/close.png"));
m_btnClose->setToolTip(tr("Close tab"));
m_horizontalLayout = new QHBoxLayout(m_widget);
m_horizontalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
m_horizontalLayout->setSpacing(1);
m_horizontalLayout->addWidget(m_toolBtnBack);
m_horizontalLayout->addWidget(m_toolBtnForward);
// Register the slot on titleChange so set the tab text accordingly
connect(m_addNewWebView, SIGNAL(titleChanged(const QString &)), SLOT(tabTitleChanged(const QString &)));
// Register the slot on toolbutton to show the previous history of web
connect(m_toolBtnBack, SIGNAL(clicked()), this, SLOT(goBackPage()));
// Register the slot on toolbutton to show the next history of web
connect(m_toolBtnForward, SIGNAL(clicked()), this, SLOT(goForwardPage()));
// Register the slot on close button , added manually
connect(m_btnClose, SIGNAL(clicked()), SLOT(closetabs()));
m_addNewGridLayout->addWidget(m_addNewWebView, 0, 0, 1, 1);
m_tabWidget->addTab(m_addNewTab, QString());
m_tabWidget->tabBar()->setVisible(true);
m_tabWidget->setCurrentIndex((m_tabWidget->count() - 1));
// Set the back and forward button on tab
m_tabWidget->tabBar()->setTabButton((m_tabWidget->count() - 1), QTabBar::LeftSide, m_widget);
m_tabWidget->tabBar()->setTabButton((m_tabWidget->count() - 1), QTabBar::RightSide, m_btnClose);
m_addNewWebView->setTabIndex((m_tabWidget->count() - 1));
m_addNewWebView->page()->setNetworkAccessManager(m_netAccessMan);
p = m_addNewWebView->page();
}
#endif
#ifdef PGADMIN4_USE_WEBENGINE
// Below slot will be called when link is required to open in new tab.
void BrowserWindow::createNewTabWindow(QWebEnginePage * &p)

View File

@ -17,19 +17,23 @@
#include "WebViewWindow.h"
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#ifdef PGADMIN4_USE_WEBENGINE
#include <QtWebEngineWidgets>
#include <QtWidgets>
#ifdef PGADMIN4_USE_WEBENGINE
#include <QtWebEngineWidgets>
#else
#include <QtWebKitWidgets>
#include <QNetworkCookieJar>
#include <QNetworkAccessManager>
#endif
#else
#include <QtWebKitWidgets>
#endif
#else
#include <QMainWindow>
#ifdef PGADMIN4_USE_WEBENGINE
#include <QtWebEngineView>
#else
#include <QWebView>
#endif
#include <QMainWindow>
#ifdef PGADMIN4_USE_WEBENGINE
#include <QtWebEngineView>
#else
#include <QWebView>
#endif
#endif
QT_BEGIN_NAMESPACE
@ -43,6 +47,7 @@ class BrowserWindow : public QMainWindow
public:
BrowserWindow(QString url);
~BrowserWindow();
protected:
void closeEvent(QCloseEvent *event);
@ -83,6 +88,8 @@ public slots:
void createNewTabWindow(QWebEnginePage * &);
void downloadEngineFileProgress(qint64 , qint64 );
void downloadEngineFinished();
#else
void createNewTabWindowKit(QWebPage * &);
#endif
private:
@ -118,8 +125,12 @@ private:
QString m_last_open_folder_path;
QString m_dir;
QNetworkReply *m_reply;
#ifdef PGADMIN4_USE_WEBENGINE
QWebEngineDownloadItem *m_download;
#else
QNetworkCookieJar *m_cookieJar;
QNetworkAccessManager *m_netAccessMan;
#endif
void createActions();

View File

@ -14,6 +14,11 @@
// App headers
#include "WebViewWindow.h"
#ifndef PGADMIN4_USE_WEBENGINE
#include <QWebPage>
#include <QNetworkRequest>
#endif
// Override QWebEnginePage to handle link delegation
#ifdef PGADMIN4_USE_WEBENGINE
bool WebEnginePage::acceptNavigationRequest(const QUrl & url, NavigationType type, bool isMainFrame)
@ -67,3 +72,42 @@ int WebViewWindow::getTabIndex() const
{
return m_tabIndex;
}
#ifndef PGADMIN4_USE_WEBENGINE
WebViewPage::WebViewPage(QObject *parent)
: QWebPage(parent)
{
}
bool WebViewPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
Q_UNUSED(type);
Q_UNUSED(request);
Q_UNUSED(frame);
return true;
}
QWebPage *WebViewPage::createWindow(QWebPage::WebWindowType type)
{
if (type == QWebPage::WebBrowserWindow)
{
QWebPage *_page = NULL;
emit createTabWindowKit(_page);
return _page;
}
return NULL;
}
bool WebViewPage::javaScriptConfirm(QWebFrame * frame, const QString & msg)
{
// If required, override the QDialog to give custom confirmation message to user.
Q_UNUSED(frame);
Q_UNUSED(msg);
return false;
}
WebViewPage::~WebViewPage()
{
}
#endif

View File

@ -58,4 +58,23 @@ private:
};
#ifndef PGADMIN4_USE_WEBENGINE
class WebViewPage : public QWebPage
{
Q_OBJECT
public:
WebViewPage(QObject *parent = 0);
~WebViewPage();
protected:
virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
QWebPage *createWindow(QWebPage::WebWindowType type);
bool javaScriptConfirm(QWebFrame * frame, const QString & msg);
signals:
void createTabWindowKit(QWebPage * &);
};
#endif
#endif // WEBVIEWWINDOW_H

View File

@ -265,6 +265,13 @@ function($, pgAdmin, R, S) {
loadingDiv = $('#fetching_data'),
msgDiv = loadingDiv.find('.sql-editor-busy-text');
// Register unload event on window close.
window.onbeforeunload = function(ev) {
$.ajax({
url: "{{ url_for('datagrid.index') }}" + "close/" + {{ uniqueId }},
method: 'GET'
});
};
// Get the controller object from pgAdmin.SqlEditor
var sqlEditorController = pgAdmin.SqlEditor.create(editorPanel);

View File

@ -333,14 +333,6 @@ define(
if (res.data.newBrowserTab) {
var newWin = window.open(baseUrl, '_blank');
// Listen on the window closed event.
newWin.addEventListener("unload", function(e){
$.ajax({
url: "{{ url_for('datagrid.index') }}" + "close/" + res.data.gridTransId,
method: 'GET'
});
}, false);
// add a load listener to the window so that the title gets changed on page load
newWin.addEventListener("load", function() {
newWin.document.title = panel_title;
@ -381,8 +373,7 @@ define(
},
error: function(e) {
alertify.alert(
'SQL Tool Initialize Error',
e.responseJSON.errormsg
'SQL Tool Initialize Error'
);
}
});
@ -447,14 +438,6 @@ define(
if (res.data.newBrowserTab) {
var newWin = window.open(baseUrl, '_blank');
// Listen on the window closed event.
newWin.addEventListener("unload", function(e){
$.ajax({
url: "{{ url_for('datagrid.index') }}" + "close/" + res.data.gridTransId,
method: 'GET'
});
}, false);
// add a load listener to the window so that the title gets changed on page load
newWin.addEventListener("load", function() {
newWin.document.title = panel_title;
@ -498,8 +481,7 @@ define(
},
error: function(e) {
alertify.alert(
"{{ _('Query Tool Initialize Error') }}",
e.responseJSON.errormsg
"{{ _('Query Tool Initialize Error') }}"
);
}
});

View File

@ -510,7 +510,8 @@ def close(trans_id):
trans_id
- unique transaction id.
"""
# As debugger data is not in session that means we have already deleted and close the target
# As debugger data is not in session that means we have already
# deleted and close the target
if 'debuggerData' not in session:
return make_json_response(data={'status': True})
@ -523,30 +524,17 @@ def close(trans_id):
try:
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(obj['server_id'])
conn = manager.connection(did=obj['database_id'], conn_id=obj['conn_id'])
except Exception as e:
return internal_server_error(errormsg=str(e))
# find the debugger version and execute the query accordingly
dbg_version = obj['debugger_version']
if dbg_version <= 2:
template_path = 'debugger/sql/v1'
else:
template_path = 'debugger/sql/v2'
# Release the connection
if conn.connected():
# on successful connection cancel the running transaction
status, result = conn.cancel_transaction(obj['conn_id'], obj['database_id'])
conn.cancel_transaction(obj['conn_id'], obj['database_id'])
conn = manager.connection(did=obj['database_id'], conn_id=obj['exe_conn_id'])
conn.cancel_transaction(obj['exe_conn_id'], obj['database_id'])
manager.release(conn_id=obj['conn_id'])
manager.release(conn_id=obj['exe_conn_id'])
# Delete the existing debugger data in session variable
del session['debuggerData'][str(trans_id)]
del session['functionData'][str(trans_id)]
# Release the connection acquired during the debugging
manager.release(did=obj['database_id'], conn_id=obj['conn_id'])
return make_json_response(data={'status': True})
else:
return make_json_response(data={'status': False})
except Exception as e:
return internal_server_error(errormsg=str(e))
@blueprint.route('/restart/<int:trans_id>', methods=['GET'])

View File

@ -1,19 +1,25 @@
{% extends "base.html" %}
{% block title %}{{ _('Debugger - ') + function_name }}{% endblock %}
{% block init_script %}
try {
require(
['pgadmin', 'pgadmin.tools.debugger.direct'],
function(pgAdmin, pgDirectDebug) {
pgDirectDebug.init({{ uniqueId }}, {{ debug_type }});
},
function() {
/* TODO:: Show proper error dialog */
console.log(arguments);
});
require(
['pgadmin', 'pgadmin.tools.debugger.direct'],
function(pgAdmin, pgDirectDebug) {
pgDirectDebug.init({{ uniqueId }}, {{ debug_type }});
window.onbeforeunload = function(ev) {
$.ajax({
url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}",
method: 'GET'
});
};
},
function() {
console.log(arguments);
});
} catch (err) {
/* Show proper error dialog */
console.log(err);
console.log(err);
}
{% endblock %}
{% block body %}

View File

@ -242,16 +242,7 @@ define(
var url = "{{ url_for('debugger.index') }}" + "direct/" + res.data.debuggerTransId;
if (res.data.newBrowserTab) {
var newWin = window.open(url, '_blank');
// Listen on the window closed event.
newWin.addEventListener("unload", function(e){
var closeUrl = "{{ url_for('debugger.index') }}" + "close/" + res.data.debuggerTransId;
$.ajax({
url: closeUrl,
method: 'GET'
});
}, false);
window.open(url, '_blank');
} else {
pgBrowser.Events.once(
'pgadmin-browser:frame:urlloaded:frm_debugger', function(frame) {
@ -345,16 +336,7 @@ define(
var url = "{{ url_for('debugger.index') }}" + "direct/" + res.data.debuggerTransId;
if (res.data.newBrowserTab) {
var newWin = window.open(url, '_blank');
// Listen on the window closed event.
newWin.addEventListener("unload", function(e){
var closeUrl = "{{ url_for('debugger.index') }}" + "close/" + res.data.debuggerTransId;
$.ajax({
url: closeUrl,
method: 'GET'
});
}, false);
window.open(url, '_blank');
} else {
pgBrowser.Events.once(
'pgadmin-browser:frame:urlloaded:frm_debugger', function(frame) {

View File

@ -554,16 +554,7 @@ define(
var url = "{{ url_for('debugger.index') }}" + "direct/" + res.data.debuggerTransId;
if (res.data.newBrowserTab) {
var newWin = window.open(url, '_blank');
// Listen on the window closed event.
newWin.addEventListener("unload", function(e){
var closeUrl = "{{ url_for('debugger.index') }}" + "close/" + res.data.debuggerTransId;
$.ajax({
url: closeUrl,
method: 'GET'
});
}, false);
window.open(url, '_blank');
} else {
pgBrowser.Events.once(
'pgadmin-browser:frame:urlloaded:frm_debugger', function(frame) {

View File

@ -43,7 +43,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger: Breakpoint set execution error'
'Debugger Error',
'Error while setting debugging breakpoint.'
);
}
});
@ -102,13 +103,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Error fetching breakpoint information'
'Debugger Error',
'Error while fetching breakpoint information.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Error fetching breakpoint information'
'Debugger Error',
'Error while fetching breakpoint information.'
);
}
});
@ -132,13 +135,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Start execution error'
'Debugger Error',
'Error while starting debugging session.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Start execution error'
'Debugger Error',
'Error while starting debugging session.'
);
}
});
@ -170,13 +175,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Execution error'
'Debugger Error',
'Error while executing requested debugging information.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Execution error'
'Debugger Error',
'Error while executing requested debugging information.'
);
}
});
@ -207,13 +214,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Error fetching variable information'
'Debugger Error',
'Error while fetching variable information.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Error fetching variable information'
'Debugger Error',
'Error while fetching variable information.'
);
}
});
@ -237,13 +246,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Error fetching stack information'
'Debugger Error',
'Error while fetching stack information.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Error fetching stack information'
'Debugger Error',
'Error while fetching stack information.'
);
}
});
@ -367,13 +378,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger Poll Result Error'
'Debugger Error',
'Error while polling result.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger Poll Result Error'
'Debugger Error',
'Error while polling result.'
);
}
});
@ -559,8 +572,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger poll end execution error',
e.responseJSON.errormsg
'Debugger Error',
'Error while polling result.'
);
}
});
@ -619,8 +632,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger listener starting error',
e.responseJSON.errormsg
'Debugger Error',
'Error while polling result.'
);
}
});
@ -665,13 +678,15 @@ define(
}
else {
Alertify.alert(
'Debugger: Continue execution error'
'Debugger Error',
'Error while executing continue in debugging session.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Continue execution error'
'Debugger Error',
'Error while executing continue in debugging session.'
);
}
});
@ -699,13 +714,15 @@ define(
}
else {
Alertify.alert(
'Debugger: Step over execution error'
'Debugger Error',
'Error while executing step over in debugging session.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Step over execution error'
'Debugger Error',
'Error while executing step over in debugging session.'
);
}
});
@ -732,13 +749,15 @@ define(
}
else {
Alertify.alert(
'Debugger: Step into execution error'
'Debugger Error',
'Error while executing step into in debugging session.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Step into execution error'
'Debugger Error',
'Error while executing step into in debugging session.'
);
}
});
@ -779,13 +798,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Stop execution error'
'Debugger Error',
'Error while executing stop in debugging session.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Stop execution error'
'Debugger Error',
'Error while executing stop in debugging session.'
);
}
});
@ -841,13 +862,15 @@ define(
}
else if (res.data.status === 'NotConnected') {
Alertify.alert(
'Debugger: Toggle breakpoint execution error'
'Debugger Error',
'Error while toggling breakpoint.'
);
}
},
error: function(e) {
Alertify.alert(
'Debugger: Toggle breakpoint execution error'
'Debugger Error',
'Error while toggling breakpoint.'
);
}
});
@ -904,7 +927,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger: Clear all breakpoint execution error'
'Debugger Error',
'Error while clearing all breakpoint.'
);
}
});
@ -1164,8 +1188,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger: Deposit value execution error',
e.responseJSON.errormsg
'Debugger Error',
'Error while depositing variable value.'
);
}
});
@ -1193,8 +1217,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger: Select frame execution error',
e.responseJSON.errormsg
'Debugger Error',
'Error while selecting frame.'
);
}
});
@ -1364,8 +1388,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger listener starting error',
e.responseJSON.errormsg
'Debugger Error',
'Error while starting debugging listener.'
);
}
});
@ -1385,8 +1409,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger listener starting error',
e.responseJSON.errormsg
'Debugger Error',
'Error while starting debugging listener.'
);
}
});
@ -1424,7 +1448,8 @@ define(
},
error: function(e) {
Alertify.alert(
'Debugger: Error fetching messages information'
'Debugger Error',
'Error while fetching messages information.'
);
}
});