diff --git a/src/Gui/DownloadItem.cpp b/src/Gui/DownloadItem.cpp index a86c5527b..216a08e09 100644 --- a/src/Gui/DownloadItem.cpp +++ b/src/Gui/DownloadItem.cpp @@ -269,12 +269,32 @@ void DownloadItem::init() } } +QString DownloadItem::getDownloadDirectory() const +{ + QString exe = QString::fromAscii(App::GetApplication().getExecutableName()); + QString path = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + QString dirPath = QDir(path).filePath(exe); + Base::Reference hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp") + ->GetGroup("Preferences")->GetGroup("General"); + std::string dir = hPath->GetASCII("DownloadPath", ""); + if (!dir.empty()) { + dirPath = QString::fromUtf8(dir.c_str()); + } + + if (QFileInfo(dirPath).exists() || QDir().mkpath(dirPath)) { + return dirPath; + } + else { + return path; + } +} + void DownloadItem::getFileName() { QSettings settings; settings.beginGroup(QLatin1String("downloadmanager")); //QString defaultLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); - QString defaultLocation = Gui::FileDialog::getWorkingDirectory(); + QString defaultLocation = getDownloadDirectory(); QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), defaultLocation).toString(); if (!downloadDirectory.isEmpty()) downloadDirectory += QLatin1Char('/'); @@ -436,7 +456,7 @@ void DownloadItem::metaDataChanged() if (m_reply->hasRawHeader(QByteArray("Content-Disposition"))) { QByteArray header = m_reply->rawHeader(QByteArray("Content-Disposition")); int index = header.indexOf("filename="); - if (index > 0) { + if (index >= 0) { header = header.mid(index+9); if (header.startsWith("\"") || header.startsWith("'")) header = header.mid(1); @@ -446,7 +466,7 @@ void DownloadItem::metaDataChanged() } else { index = header.indexOf("filename*=UTF-8''"); - if (index > 0) { + if (index >= 0) { header = header.mid(index+17); if (header.startsWith("\"") || header.startsWith("'")) header = header.mid(1); diff --git a/src/Gui/DownloadItem.h b/src/Gui/DownloadItem.h index a357fffe9..2503f2ca0 100644 --- a/src/Gui/DownloadItem.h +++ b/src/Gui/DownloadItem.h @@ -141,7 +141,7 @@ private: void init(); void updateInfoLabel(); QString dataString(int size) const; - + QString getDownloadDirectory() const; QString saveFileName(const QString &directory) const; bool m_requestFileName; diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index 7e73a404c..1a72d21c7 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -143,17 +143,7 @@ void BrowserView::onLinkClicked (const QUrl & url) //QString fragment = url. fragment(); if (scheme==QString::fromLatin1("http")) { - bool ok = false; - if (ok) { - //Dialog::DownloadDialog dlg (url,this/*QString::fromLatin1("c:/temp/test.fcstd")*/); - //int result = dlg.exec(); - //if(ext ==QString::fromLatin1("fcstd") ) - // Gui::Command::doCommand(Gui::Command::Gui,"Gui.open('c:/temp/test.fcstd')"); - } - else { - load(url); - } - //OpenURLInBrowser(url.toString().toLatin1()); + load(url); } // run scripts if not from somewhere else! if ((scheme.size() < 2 || scheme==QString::fromLatin1("file"))&& host.isEmpty()) { @@ -189,7 +179,13 @@ void BrowserView::onDownloadRequested(const QNetworkRequest & request) void BrowserView::onUnsupportedContent(QNetworkReply* reply) { - Gui::Dialog::DownloadManager::getInstance()->handleUnsupportedContent(reply); + // Do not call handleUnsupportedContent() directly otherwise we won't get + // the metaDataChanged() signal of the reply. + Gui::Dialog::DownloadManager::getInstance()->download(reply->url()); + // Due to setting the policy QWebPage::DelegateAllLinks the onLinkClicked() + // slot is called even when clicking on a downloadable file but the page + // then fails to load. Thus, we reload the previous url. + view->reload(); } void BrowserView::load(const char* URL) diff --git a/src/Mod/Web/Gui/BrowserView.h b/src/Mod/Web/Gui/BrowserView.h index 3ba3ee035..64bcbd4b7 100644 --- a/src/Mod/Web/Gui/BrowserView.h +++ b/src/Mod/Web/Gui/BrowserView.h @@ -35,6 +35,7 @@ class QWebView; class QUrl; class QNetworkRequest; +class QNetworkReply; namespace WebGui {