mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Runtime fixes:
- Compilation error with Qt4 as "QUrlQuery" class was introduced since Qt5. - Client side download code has been removed as now we support server side download. - We should not delete sender object inside slot. If we do so it may crash the application. To avoid this, we used Qt's "deleteLater" which will delete the objects once the processing of all the events have been done.
This commit is contained in:
parent
91559c622b
commit
dcf5bfc495
@ -23,6 +23,8 @@
|
|||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#endif
|
#endif
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
// App headers
|
// App headers
|
||||||
#include "BrowserWindow.h"
|
#include "BrowserWindow.h"
|
||||||
#include "ConfigWindow.h"
|
#include "ConfigWindow.h"
|
||||||
@ -220,8 +222,6 @@ void BrowserWindow::download(const QNetworkRequest &request)
|
|||||||
{
|
{
|
||||||
// Check that request contains data for download at client side
|
// Check that request contains data for download at client side
|
||||||
QUrl name;
|
QUrl name;
|
||||||
if (checkClientDownload(name, request))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_downloadStarted)
|
if (m_downloadStarted)
|
||||||
{
|
{
|
||||||
@ -363,7 +363,7 @@ void BrowserWindow::downloadFileProgress(qint64 readData, qint64 totalData)
|
|||||||
// As downloading is finished so remove progress bar dialog
|
// As downloading is finished so remove progress bar dialog
|
||||||
if (m_progressDialog)
|
if (m_progressDialog)
|
||||||
{
|
{
|
||||||
delete m_progressDialog;
|
m_progressDialog->deleteLater();
|
||||||
m_progressDialog = NULL;
|
m_progressDialog = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +391,7 @@ void BrowserWindow::progressCanceled()
|
|||||||
|
|
||||||
if (m_progressDialog)
|
if (m_progressDialog)
|
||||||
{
|
{
|
||||||
delete m_progressDialog;
|
m_progressDialog->deleteLater();
|
||||||
m_progressDialog = NULL;
|
m_progressDialog = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,7 +420,7 @@ void BrowserWindow::downloadFinished()
|
|||||||
{
|
{
|
||||||
if (m_progressDialog)
|
if (m_progressDialog)
|
||||||
{
|
{
|
||||||
delete m_progressDialog;
|
m_progressDialog->deleteLater();
|
||||||
m_progressDialog = NULL;
|
m_progressDialog = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,10 +442,16 @@ void BrowserWindow::downloadFinished()
|
|||||||
// Below slot will be called when user directly click on any download link
|
// Below slot will be called when user directly click on any download link
|
||||||
void BrowserWindow::unsupportedContent(QNetworkReply * reply)
|
void BrowserWindow::unsupportedContent(QNetworkReply * reply)
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
// Extract filename and query from encoded URL
|
// Extract filename and query from encoded URL
|
||||||
QUrlQuery query_data(reply->url());
|
QUrlQuery query_data(reply->url());
|
||||||
QString file_name = query_data.queryItemValue("filename");
|
QString file_name = query_data.queryItemValue("filename");
|
||||||
QString query = query_data.queryItemValue("query");
|
QString query = query_data.queryItemValue("query");
|
||||||
|
#else
|
||||||
|
QUrl url(reply->url());
|
||||||
|
QString file_name = url.queryItemValue("filename");
|
||||||
|
QString query = url.queryItemValue("query");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (m_downloadStarted)
|
if (m_downloadStarted)
|
||||||
{
|
{
|
||||||
@ -658,127 +664,6 @@ void BrowserWindow::tabTitleChanged(const QString &str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Below function will be used to download the data set in encoded URL so data will be downloaded at client side.
|
|
||||||
bool BrowserWindow::checkClientDownload(const QUrl &name, const QNetworkRequest &request)
|
|
||||||
{
|
|
||||||
QString mime_type = "";
|
|
||||||
QString file_name = "";
|
|
||||||
QString write_data = "";
|
|
||||||
QString csv_data = "";
|
|
||||||
bool return_val = false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
In Qt version 5.5, "download" signal is emitted when 'download' attribute is set on 'a' tag.
|
|
||||||
In "download" signal emission, name will be empty and data will be in request object.
|
|
||||||
Earlier version ( < 5.5 ), "urlLinkClicked" signal is emitted so name will contain the object data.
|
|
||||||
*/
|
|
||||||
if (name.isEmpty())
|
|
||||||
csv_data = QFileInfo(request.url().toString()).fileName();
|
|
||||||
else
|
|
||||||
csv_data = QString::fromUtf8(name.toEncoded());
|
|
||||||
|
|
||||||
// Extract the filename and value(data) from encoded URL
|
|
||||||
QUrlQuery downloadData(csv_data);
|
|
||||||
QStringList keyValueData = csv_data.split("&");
|
|
||||||
file_name = downloadData.queryItemValue("filename");
|
|
||||||
write_data = downloadData.queryItemValue("value");
|
|
||||||
|
|
||||||
int key_value_length = keyValueData.size();
|
|
||||||
int i_count = 0;
|
|
||||||
|
|
||||||
while (i_count < key_value_length)
|
|
||||||
{
|
|
||||||
// Extract the extension after "data:" word found from encoded url.
|
|
||||||
QString start_match_string = "data:";
|
|
||||||
int s_offset = keyValueData.at(i_count).indexOf(start_match_string);
|
|
||||||
if (s_offset != -1)
|
|
||||||
{
|
|
||||||
int format_offset = keyValueData.at(i_count).indexOf("/");
|
|
||||||
mime_type = keyValueData.at(i_count).mid((format_offset+1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int split_offset = keyValueData.at(i_count).indexOf("=");
|
|
||||||
if (split_offset == -1)
|
|
||||||
{
|
|
||||||
mime_type = keyValueData.at(i_count);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
i_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write data to file
|
|
||||||
if (!write_data.isEmpty())
|
|
||||||
{
|
|
||||||
QString filename = "";
|
|
||||||
QString f_name = "";
|
|
||||||
QFileDialog saveAsdialog(this);
|
|
||||||
saveAsdialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
||||||
saveAsdialog.selectNameFilter(tr("Files (*.%1)").arg(mime_type));
|
|
||||||
saveAsdialog.setWindowTitle(tr("Save %1 file").arg(mime_type));
|
|
||||||
saveAsdialog.setDirectory(m_last_open_folder_path);
|
|
||||||
saveAsdialog.selectFile(file_name);
|
|
||||||
saveAsdialog.setDefaultSuffix(mime_type);
|
|
||||||
|
|
||||||
QObject::connect(&saveAsdialog, SIGNAL(directoryEntered(const QString &)), this, SLOT(current_dir_path(const QString &)));
|
|
||||||
m_dir = m_last_open_folder_path;
|
|
||||||
|
|
||||||
if (saveAsdialog.exec() == QDialog::Accepted) {
|
|
||||||
filename = saveAsdialog.selectedFiles().at(0);
|
|
||||||
QString filename = saveAsdialog.selectedFiles().first();
|
|
||||||
f_name = filename.replace(m_dir, "");
|
|
||||||
// Remove first character from fiename
|
|
||||||
f_name.remove(0,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear last open folder path
|
|
||||||
m_dir.clear();
|
|
||||||
|
|
||||||
return_val = true;
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
// Check that user has given valid file name or not - forward slash is not allowed in file name
|
|
||||||
// In Mac OSX, forward slash is converted to colon(:) by Qt so we need to check for colon.
|
|
||||||
if (f_name.indexOf(":") != -1)
|
|
||||||
{
|
|
||||||
QMessageBox::information(this, tr("File name error"), tr("Invalid file name"));
|
|
||||||
return return_val;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Check that user has given valid file name or not - forward slash is not allowed in file name
|
|
||||||
if (f_name.indexOf("/") != -1)
|
|
||||||
{
|
|
||||||
QMessageBox::information(this, tr("File name error"), tr("Invalid file name"));
|
|
||||||
return return_val;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if(!filename.isEmpty())
|
|
||||||
{
|
|
||||||
// Decode the encoded uri data
|
|
||||||
QString csvData = QUrl::fromPercentEncoding(write_data.toUtf8());
|
|
||||||
|
|
||||||
QFile csvfile(filename);
|
|
||||||
if (!csvfile.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
||||||
{
|
|
||||||
QMessageBox::information(this, tr("Save csv file"), tr("Error while opening file %1").arg(filename));
|
|
||||||
return return_val;
|
|
||||||
}
|
|
||||||
// Write csv data to file
|
|
||||||
qint64 data_return = csvfile.write(csvData.toUtf8().constData());
|
|
||||||
if (data_return == -1)
|
|
||||||
{
|
|
||||||
QMessageBox::information(this, tr("Save csv file"), tr("Error while writing data to file %1").arg(filename));
|
|
||||||
csvfile.close();
|
|
||||||
return return_val;
|
|
||||||
}
|
|
||||||
csvfile.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return return_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BrowserWindow::current_dir_path(const QString &dir)
|
void BrowserWindow::current_dir_path(const QString &dir)
|
||||||
{
|
{
|
||||||
m_dir = dir;
|
m_dir = dir;
|
||||||
@ -793,8 +678,6 @@ void BrowserWindow::urlLinkClicked(const QUrl &name)
|
|||||||
{
|
{
|
||||||
// Check that request contains the data download at client side
|
// Check that request contains the data download at client side
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
if (checkClientDownload(name, request))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// First check is there any tab opened with same URL then open it again.
|
// First check is there any tab opened with same URL then open it again.
|
||||||
int tabFound = findURLTab(name);
|
int tabFound = findURLTab(name);
|
||||||
|
@ -98,7 +98,6 @@ private:
|
|||||||
void createActions();
|
void createActions();
|
||||||
void pause(int seconds = 1);
|
void pause(int seconds = 1);
|
||||||
int findURLTab(const QUrl &name);
|
int findURLTab(const QUrl &name);
|
||||||
bool checkClientDownload(const QUrl &name, const QNetworkRequest &request);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BROWSERWINDOW_H
|
#endif // BROWSERWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user