1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

"Save x as..." will always show file dialog.

closes #471
This commit is contained in:
nowrep 2012-08-14 18:53:55 +02:00
parent 826d85a5e1
commit d771ba728b
7 changed files with 68 additions and 40 deletions

View File

@ -1473,14 +1473,7 @@ void QupZilla::fullScreen(bool make)
void QupZilla::savePage()
{
QNetworkRequest request(weView()->url());
QString suggestedFileName = qz_getFileNameFromUrl(weView()->url());
if (!suggestedFileName.contains('.')) {
suggestedFileName.append(".html");
}
DownloadManager* dManager = mApp->downManager();
dManager->download(request, weView()->page(), false, suggestedFileName);
weView()->savePageAs();
}
void QupZilla::sendLink()

View File

@ -34,7 +34,7 @@
#include <QFileDialog>
#include <QDesktopServices>
DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog, WebPage* page)
DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog)
: QObject()
, m_lastDownloadOption(DownloadManager::SaveFile)
, m_lastDownloadPath(lastDownloadPath)
@ -46,7 +46,6 @@ DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QS
, m_listWidget(0)
, m_iconProvider(new QFileIconProvider)
, m_manager(0)
, m_webPage(page)
{
}
@ -57,15 +56,15 @@ DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QS
//// on Windows working properly )
//////////////////////////////////////////////////////
void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo, const QString &suggestedFileName)
void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, const DownloadManager::DownloadInfo &info)
{
m_timer = new QTime();
m_timer->start();
m_h_fileName = suggestedFileName.isEmpty() ? getFileName(reply) : suggestedFileName;
m_h_fileName = info.suggestedFileName.isEmpty() ? getFileName(reply) : info.suggestedFileName;
m_reply = reply;
QFileInfo info(m_h_fileName);
QTemporaryFile tempFile("XXXXXX." + info.suffix());
QFileInfo fileInfo(m_h_fileName);
QTemporaryFile tempFile("XXXXXX." + fileInfo.suffix());
tempFile.open();
tempFile.write(m_reply->peek(1024 * 1024));
QFileInfo tempInfo(tempFile.fileName());
@ -78,20 +77,20 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask
}
// Close Empty Tab
if (m_webPage) {
WebView* view = qobject_cast<WebView*>(m_webPage->view());
if (!m_webPage->url().isEmpty()) {
m_downloadPage = m_webPage->url();
if (info.page) {
WebView* view = qobject_cast<WebView*>(info.page->view());
if (!info.page->url().isEmpty()) {
m_downloadPage = info.page->url();
}
else if (m_webPage->history()->canGoBack()) {
m_downloadPage = m_webPage->history()->backItem().url();
else if (info.page->history()->canGoBack()) {
m_downloadPage = info.page->history()->backItem().url();
}
else if (view && m_webPage->history()->count() == 0) {
else if (view && info.page->history()->count() == 0) {
view->closeView();
}
}
if (askWhatToDo) {
if (info.askWhatToDo && m_downloadPath.isEmpty()) {
DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_fileIcon, mimeType, reply->url(), mApp->activeWindow());
dialog->showExternalManagerOption(m_manager->useExternalManager());
dialog->setLastDownloadOption(m_lastDownloadOption);
@ -99,6 +98,9 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask
connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int)));
}
else if (info.forceChoosingPath) {
optionsDialogAccepted(4);
}
else {
optionsDialogAccepted(2);
}
@ -106,7 +108,9 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask
void DownloadFileHelper::optionsDialogAccepted(int finish)
{
bool forceChoosingPath = false;
m_openFileChoosed = false;
switch (finish) {
case 0: // Cancelled
if (m_timer) {
@ -133,6 +137,11 @@ void DownloadFileHelper::optionsDialogAccepted(int finish)
m_reply->deleteLater();
return;
case 4: // Force opening save file dialog
m_lastDownloadOption = DownloadManager::SaveFile;
forceChoosingPath = true;
break;
default:
qWarning() << "DownloadFileHelper::optionsDialogAccepted invalid return value!";
if (m_timer) {
@ -147,7 +156,7 @@ void DownloadFileHelper::optionsDialogAccepted(int finish)
m_manager->setLastDownloadOption(m_lastDownloadOption);
if (!m_openFileChoosed) {
if (m_downloadPath.isEmpty()) {
if (m_downloadPath.isEmpty() || forceChoosingPath) {
if (m_useNativeDialog) {
fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName));
}

View File

@ -36,14 +36,14 @@ class QT_QUPZILLA_EXPORT DownloadFileHelper : public QObject
{
Q_OBJECT
public:
explicit DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog, WebPage* page);
explicit DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog);
~DownloadFileHelper();
void setListWidget(QListWidget* tw) { m_listWidget = tw; }
void setDownloadManager(DownloadManager* m) { m_manager = m; }
void setLastDownloadOption(const DownloadManager::DownloadOption &option) { m_lastDownloadOption = option; }
void handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo, const QString &suggestedFileName);
void handleUnsupportedContent(QNetworkReply* reply, const DownloadManager::DownloadInfo &info);
signals:
void itemCreated(QListWidgetItem* item, DownloadItem* downItem);
@ -74,7 +74,6 @@ private:
QListWidget* m_listWidget;
QFileIconProvider* m_iconProvider;
DownloadManager* m_manager;
WebPage* m_webPage;
};
#endif // DOWNLOADFILEHELPER_H

View File

@ -195,9 +195,9 @@ void DownloadManager::clearList()
qDeleteAll(items);
}
void DownloadManager::download(const QNetworkRequest &request, WebPage* page, bool fromPageDownload, const QString &suggestedFileName)
void DownloadManager::download(const QNetworkRequest &request, const DownloadInfo &info)
{
if (!page) {
if (!info.page) {
return;
}
@ -205,12 +205,12 @@ void DownloadManager::download(const QNetworkRequest &request, WebPage* page, bo
QNetworkRequest req = request;
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), 0);
handleUnsupportedContent(m_networkManager->get(req), page, fromPageDownload, suggestedFileName);
handleUnsupportedContent(m_networkManager->get(req), info);
}
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, WebPage* page, bool fromPageDownload, const QString &suggestedFileName)
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, const DownloadInfo &info)
{
if (!page || reply->url().scheme() == "qupzilla") {
if (!info.page || reply->url().scheme() == "qupzilla") {
return;
}
@ -223,13 +223,13 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, WebPage* pa
reply->setProperty("downReply", QVariant(true));
DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog, page);
DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog);
connect(h, SIGNAL(itemCreated(QListWidgetItem*, DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*, DownloadItem*)));
h->setLastDownloadOption(m_lastDownloadOption);
h->setDownloadManager(this);
h->setListWidget(ui->list);
h->handleUnsupportedContent(reply, fromPageDownload, suggestedFileName);
h->handleUnsupportedContent(reply, info);
}
void DownloadManager::itemCreated(QListWidgetItem* item, DownloadItem* downItem)

View File

@ -44,13 +44,28 @@ class QT_QUPZILLA_EXPORT DownloadManager : public QWidget
public:
enum DownloadOption { OpenFile, SaveFile, ExternalManager };
struct DownloadInfo {
WebPage* page;
QString suggestedFileName;
bool askWhatToDo;
bool forceChoosingPath;
DownloadInfo(WebPage* p = 0) {
page = p;
suggestedFileName = QString();
askWhatToDo = true;
forceChoosingPath = false;
}
};
explicit DownloadManager(QWidget* parent = 0);
~DownloadManager();
void loadSettings();
void download(const QNetworkRequest &request, WebPage* page, bool fromPageDownload = true, const QString &suggestedFileName = QString());
void handleUnsupportedContent(QNetworkReply* reply, WebPage* page, bool fromPageDownload = true, const QString &suggestedFileName = QString());
void download(const QNetworkRequest &request, const DownloadInfo &info);
void handleUnsupportedContent(QNetworkReply* reply, const DownloadInfo &info);
bool canClose();

View File

@ -397,7 +397,7 @@ void WebView::copyLinkToClipboard()
}
}
void WebView::downloadPage()
void WebView::savePageAs()
{
QNetworkRequest request(url());
QString suggestedFileName = qz_getFileNameFromUrl(url());
@ -405,8 +405,14 @@ void WebView::downloadPage()
suggestedFileName.append(".html");
}
DownloadManager::DownloadInfo info;
info.page = page();
info.suggestedFileName = suggestedFileName;
info.askWhatToDo = false;
info.forceChoosingPath = true;
DownloadManager* dManager = mApp->downManager();
dManager->download(request, page(), false, suggestedFileName);
dManager->download(request, info);
}
void WebView::downloadUrlToDisk()
@ -414,8 +420,14 @@ void WebView::downloadUrlToDisk()
if (QAction* action = qobject_cast<QAction*>(sender())) {
QNetworkRequest request(action->data().toUrl());
DownloadManager::DownloadInfo info;
info.page = page();
info.suggestedFileName = QString();
info.askWhatToDo = false;
info.forceChoosingPath = true;
DownloadManager* dManager = mApp->downManager();
dManager->download(request, page(), false);
dManager->download(request, info);
}
}
@ -770,7 +782,7 @@ void WebView::createPageContextMenu(QMenu* menu, const QPoint &pos)
menu->addSeparator();
menu->addAction(qIconProvider->fromTheme("user-bookmarks"), tr("Book&mark page"), this, SLOT(bookmarkLink()));
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save page as..."), this, SLOT(downloadPage()));
menu->addAction(QIcon::fromTheme("document-save"), tr("&Save page as..."), this, SLOT(savePageAs()));
menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy page link"), this, SLOT(copyLinkToClipboard()))->setData(url());
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send page link..."), this, SLOT(sendPageByMail()));
menu->addAction(QIcon::fromTheme("document-print"), tr("&Print page"), this, SLOT(printPage()));

View File

@ -75,6 +75,7 @@ public slots:
void selectAll();
void printPage(QWebFrame* frame = 0);
void sendPageByMail();
void savePageAs();
virtual void closeView() = 0;
virtual void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position) = 0;
@ -90,7 +91,6 @@ protected slots:
void openUrlInNewWindow();
void sendLinkByMail();
void copyLinkToClipboard();
void downloadPage();
void downloadUrlToDisk();
void copyImageToClipboard();
void openActionUrl();