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

Fixed issue on Windows when downloading content from secured site simply

won't work.
Added some missing tags to html highlighter
This commit is contained in:
nowrep 2011-05-08 12:54:49 +02:00
parent 5cafc27cf0
commit 6857d46d3b
8 changed files with 119 additions and 53 deletions

View File

@ -684,7 +684,12 @@ void QupZilla::aboutToShowHistoryMenu()
QMenu* menuClosedTabs = new QMenu(tr("Closed Tabs")); QMenu* menuClosedTabs = new QMenu(tr("Closed Tabs"));
int i = 0; int i = 0;
foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) { foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) {
menuClosedTabs->addAction(_iconForUrl(tab.url), tab.title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i); QString title = tab.title;
if (title.length()>40) {
title.truncate(40);
title+="..";
}
menuClosedTabs->addAction(_iconForUrl(tab.url), title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i);
i++; i++;
} }
if (i == 0) if (i == 0)

View File

@ -136,57 +136,83 @@ void DownloadManager::download(const QNetworkRequest &request, bool askWhatToDo)
handleUnsupportedContent(m_networkManager->get(request), askWhatToDo); handleUnsupportedContent(m_networkManager->get(request), askWhatToDo);
} }
//////////////////////////////////////////////////////
//// Getting where to download requested file
//// in 3 functions, as we are using non blocking
//// dialogs ( this is important to make secured downloading
//// on windows working properly )
//////////////////////////////////////////////////////
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo) void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo)
{ {
QString path; m_h_fileName = getFileName(reply);
QString fileName; m_hreply = reply;
QString userFileName;
QString _fileName = getFileName(reply);
QFileInfo info(reply->url().toString()); QFileInfo info(reply->url().toString());
QTemporaryFile tempFile("XXXXXX."+info.suffix()); QTemporaryFile tempFile("XXXXXX."+info.suffix());
tempFile.open(); tempFile.open();
QFileInfo tempInfo(tempFile.fileName()); QFileInfo tempInfo(tempFile.fileName());
QPixmap fileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30); m_hfileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30);
QString mimeType = m_iconProvider->type(tempInfo); QString mimeType = m_iconProvider->type(tempInfo);
bool openFileOptionsChoosed = false;
if (askWhatToDo) { if (askWhatToDo) {
DownloadOptionsDialog* dialog = new DownloadOptionsDialog(_fileName, fileIcon, mimeType, reply->url(), mApp->activeWindow()); DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_hfileIcon, mimeType, reply->url(), mApp->activeWindow());
switch (dialog->exec()) { dialog->show();
connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int)));
} else
optionsDialogAccepted(2);
}
void DownloadManager::optionsDialogAccepted(int finish)
{
m_hOpenFileChoosed = false;
switch (finish) {
case 0: //Cancelled case 0: //Cancelled
return; return;
break; break;
case 1: //Open case 1: //Open
openFileOptionsChoosed = true; m_hOpenFileChoosed = true;
break; break;
case 2: //Save case 2: //Save
break; break;
} }
if (!m_hOpenFileChoosed) {
if (m_downloadPath.isEmpty()) {
#ifdef Q_WS_WIN //Well, poor Windows users will use non-native file dialog for downloads
QFileDialog* dialog = new QFileDialog(mApp->getWindow());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(tr("Save file as..."));
dialog->setDirectory(m_lastDownloadPath);
dialog->selectFile(m_h_fileName);
dialog->show();
connect(dialog, SIGNAL(fileSelected(QString)), this, SLOT(fileNameChoosed(QString)));
#else
fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName));
#endif
} }
if (!openFileOptionsChoosed) {
if (m_downloadPath.isEmpty())
userFileName = QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."),m_lastDownloadPath+_fileName);
else else
userFileName = m_downloadPath+_fileName; fileNameChoosed(m_downloadPath + m_h_fileName);
} else
fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName);
}
if (userFileName.isEmpty()) { void DownloadManager::fileNameChoosed(const QString &name)
reply->abort(); {
m_huserFileName = name;
if (m_huserFileName.isEmpty()) {
m_hreply->abort();
return; return;
} }
} else
userFileName = QDir::tempPath()+"/"+_fileName;
int pos = userFileName.lastIndexOf("/"); int pos = m_huserFileName.lastIndexOf("/");
if (pos!=-1) { if (pos != -1) {
int size = userFileName.size(); int size = m_huserFileName.size();
path = userFileName.left(pos+1); m_hpath = m_huserFileName.left(pos+1);
fileName = userFileName.right(size-pos-1); m_hfileName = m_huserFileName.right(size-pos-1);
} }
if (!path.contains(QDir::tempPath())) if (!m_hpath.contains(QDir::tempPath()))
m_lastDownloadPath = path; m_lastDownloadPath = m_hpath;
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat); QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
settings.beginGroup("DownloadManager"); settings.beginGroup("DownloadManager");
@ -194,14 +220,26 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWha
settings.endGroup(); settings.endGroup();
QListWidgetItem* item = new QListWidgetItem(ui->list); QListWidgetItem* item = new QListWidgetItem(ui->list);
DownloadItem* downItem = new DownloadItem(item, reply, path, fileName, fileIcon, openFileOptionsChoosed, this); DownloadItem* downItem = new DownloadItem(item, m_hreply, m_hpath, m_hfileName, m_hfileIcon, m_hOpenFileChoosed, this);
connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*))); connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*)));
connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool))); connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool)));
ui->list->setItemWidget(item, downItem); ui->list->setItemWidget(item, downItem);
item->setSizeHint(downItem->sizeHint()); item->setSizeHint(downItem->sizeHint());
show(); show();
activateWindow(); activateWindow();
//Negating all used variables
m_hpath.clear();
m_hfileName.clear();
m_huserFileName.clear();
m_h_fileName.clear();
m_hreply = 0;
m_hfileIcon = QPixmap();
m_hOpenFileChoosed = false;
} }
//////////////////////////////////////////////////////
//// End here
//////////////////////////////////////////////////////
void DownloadManager::downloadFinished(bool success) void DownloadManager::downloadFinished(bool success)
{ {

View File

@ -69,6 +69,10 @@ private slots:
void deleteItem(DownloadItem* item); void deleteItem(DownloadItem* item);
void downloadFinished(bool success); void downloadFinished(bool success);
void optionsDialogAccepted(int finish);
void fileNameChoosed(const QString &name = "");
private: private:
#ifdef W7API #ifdef W7API
EcWin7 win7; EcWin7 win7;
@ -86,6 +90,15 @@ private:
QBasicTimer m_timer; QBasicTimer m_timer;
bool m_isClosing; bool m_isClosing;
// Variables used by HandleUnsupportContent:
QString m_hpath;
QString m_hfileName;
QString m_huserFileName;
QString m_h_fileName;
QNetworkReply* m_hreply;
QPixmap m_hfileIcon;
bool m_hOpenFileChoosed;
}; };
#endif // DOWNLOADMANAGER_H #endif // DOWNLOADMANAGER_H

View File

@ -20,7 +20,7 @@
DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget *parent) DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget *parent)
: QDialog(parent) : QDialog(parent)
,ui(new Ui::DownloadOptionsDialog) , ui(new Ui::DownloadOptionsDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->fileName->setText("<b>"+fileName+"</b>"); ui->fileName->setText("<b>"+fileName+"</b>");
@ -28,18 +28,19 @@ DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon,
ui->fileType->setText(mimeType); ui->fileType->setText(mimeType);
ui->fromServer->setText(url.host()); ui->fromServer->setText(url.host());
setWindowTitle(tr("Opening %1").arg(fileName)); setWindowTitle(tr("Opening %1").arg(fileName));
connect(this, SIGNAL(finished(int)), this, SLOT(emitDialogFinished(int)));
} }
int DownloadOptionsDialog::exec() void DownloadOptionsDialog::emitDialogFinished(int status)
{ {
int status = QDialog::exec(); if (status != 0) {
if (status == 0) if (ui->radioOpen->isChecked())
return 0; status = 1;
else if (ui->radioOpen->isChecked())
return 1;
else if (ui->radioSave->isChecked()) else if (ui->radioSave->isChecked())
return 2; status = 2;
return 2; }
emit dialogFinished(status);
} }
DownloadOptionsDialog::~DownloadOptionsDialog() DownloadOptionsDialog::~DownloadOptionsDialog()

View File

@ -20,7 +20,7 @@
#include <QDialog> #include <QDialog>
#include <QUrl> #include <QUrl>
#include <QDebug> #include <QCloseEvent>
namespace Ui { namespace Ui {
class DownloadOptionsDialog; class DownloadOptionsDialog;
@ -34,7 +34,11 @@ public:
explicit DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget* parent = 0); explicit DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget* parent = 0);
~DownloadOptionsDialog(); ~DownloadOptionsDialog();
int exec(); private slots:
void emitDialogFinished(int status);
signals:
void dialogFinished(int);
private: private:
Ui::DownloadOptionsDialog* ui; Ui::DownloadOptionsDialog* ui;

View File

@ -1,5 +1,6 @@
#include "closedtabsmanager.h" #include "closedtabsmanager.h"
#include "webview.h" #include "webview.h"
#include "qwebhistory.h"
ClosedTabsManager::ClosedTabsManager(QObject *parent) : ClosedTabsManager::ClosedTabsManager(QObject *parent) :
QObject(parent) QObject(parent)
@ -8,6 +9,9 @@ ClosedTabsManager::ClosedTabsManager(QObject *parent) :
void ClosedTabsManager::saveView(WebView* view) void ClosedTabsManager::saveView(WebView* view)
{ {
if (view->url().isEmpty() && view->history()->items().count() == 0)
return;
Tab tab; Tab tab;
tab.url = view->url(); tab.url = view->url();
tab.title = view->title(); tab.title = view->title();

View File

@ -86,7 +86,7 @@
<< "(<strong|</strong)" << "(<dt|</dt)" << "(<dd|</dd)" << "(<strong|</strong)" << "(<dt|</dt)" << "(<dd|</dd)"
<< "(<em|</em)" << "(<iframe|</iframe)" << "(<th|</th)" << "(<em|</em)" << "(<iframe|</iframe)" << "(<th|</th)"
<< "(<textarea|</textarea)" << "(<nav|</nav)" <<"(<section|</section)" << "(<textarea|</textarea)" << "(<nav|</nav)" <<"(<section|</section)"
<< "(<fieldset|</fieldset)" << "(<footer|</footer)" << "(<fieldset|</fieldset)" << "(<footer|</footer)" << "(<address|</address)"
<< "(<ol|</ol)" << "(<small|</small)" << ">"; << "(<ol|</ol)" << "(<small|</small)" << ">";
foreach (const QString &pattern, keywordPatterns) { foreach (const QString &pattern, keywordPatterns) {
rule.pattern = QRegExp(pattern); rule.pattern = QRegExp(pattern);
@ -115,6 +115,7 @@
<< "scrolling=\"" << "quality=\"" << "bgcolor=\"" << "scrolling=\"" << "quality=\"" << "bgcolor=\""
<< "allowscriptaccess=\"" << "cols=\"" << "rows=\"" << "allowscriptaccess=\"" << "cols=\"" << "rows=\""
<< "profile=\"" << "colspan=\"" << "scope=\"" << "profile=\"" << "colspan=\"" << "scope=\""
<< "data=\""
<< "href=\"" << "title=\"" << "xmlns=\""; << "href=\"" << "title=\"" << "xmlns=\"";
foreach (const QString &pattern, optionsPatterns) { foreach (const QString &pattern, optionsPatterns) {
rule.pattern = QRegExp(pattern); rule.pattern = QRegExp(pattern);

View File

@ -68,7 +68,7 @@ void WebPage::setSSLCertificate(const QSslCertificate &cert)
QSslCertificate WebPage::sslCertificate() QSslCertificate WebPage::sslCertificate()
{ {
if (m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host()))) if (mainFrame()->url().scheme() == "https" && m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host())))
return m_SslCert; return m_SslCert;
else else
return QSslCertificate(); return QSslCertificate();