0000952: Download manager
This commit is contained in:
parent
2896efe584
commit
26d1751aeb
|
@ -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<ParameterGrp> 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
class QWebView;
|
||||
class QUrl;
|
||||
class QNetworkRequest;
|
||||
class QNetworkReply;
|
||||
|
||||
namespace WebGui {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user