1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36: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"));
int i = 0;
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++;
}
if (i == 0)

View File

@ -136,57 +136,83 @@ void DownloadManager::download(const QNetworkRequest &request, bool 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)
{
QString path;
QString fileName;
QString userFileName;
QString _fileName = getFileName(reply);
m_h_fileName = getFileName(reply);
m_hreply = reply;
QFileInfo info(reply->url().toString());
QTemporaryFile tempFile("XXXXXX."+info.suffix());
tempFile.open();
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);
bool openFileOptionsChoosed = false;
if (askWhatToDo) {
DownloadOptionsDialog* dialog = new DownloadOptionsDialog(_fileName, fileIcon, mimeType, reply->url(), mApp->activeWindow());
switch (dialog->exec()) {
case 0: //Cancelled
return;
break;
case 1: //Open
openFileOptionsChoosed = true;
break;
case 2: //Save
break;
}
}
if (!openFileOptionsChoosed) {
if (m_downloadPath.isEmpty())
userFileName = QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."),m_lastDownloadPath+_fileName);
else
userFileName = m_downloadPath+_fileName;
if (userFileName.isEmpty()) {
reply->abort();
return;
}
DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_hfileIcon, mimeType, reply->url(), mApp->activeWindow());
dialog->show();
connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int)));
} else
userFileName = QDir::tempPath()+"/"+_fileName;
optionsDialogAccepted(2);
}
int pos = userFileName.lastIndexOf("/");
if (pos!=-1) {
int size = userFileName.size();
path = userFileName.left(pos+1);
fileName = userFileName.right(size-pos-1);
void DownloadManager::optionsDialogAccepted(int finish)
{
m_hOpenFileChoosed = false;
switch (finish) {
case 0: //Cancelled
return;
break;
case 1: //Open
m_hOpenFileChoosed = true;
break;
case 2: //Save
break;
}
if (!path.contains(QDir::tempPath()))
m_lastDownloadPath = path;
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
}
else
fileNameChoosed(m_downloadPath + m_h_fileName);
} else
fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName);
}
void DownloadManager::fileNameChoosed(const QString &name)
{
m_huserFileName = name;
if (m_huserFileName.isEmpty()) {
m_hreply->abort();
return;
}
int pos = m_huserFileName.lastIndexOf("/");
if (pos != -1) {
int size = m_huserFileName.size();
m_hpath = m_huserFileName.left(pos+1);
m_hfileName = m_huserFileName.right(size-pos-1);
}
if (!m_hpath.contains(QDir::tempPath()))
m_lastDownloadPath = m_hpath;
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
settings.beginGroup("DownloadManager");
@ -194,14 +220,26 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWha
settings.endGroup();
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(downloadFinished(bool)), this, SLOT(downloadFinished(bool)));
ui->list->setItemWidget(item, downItem);
item->setSizeHint(downItem->sizeHint());
show();
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)
{

View File

@ -69,6 +69,10 @@ private slots:
void deleteItem(DownloadItem* item);
void downloadFinished(bool success);
void optionsDialogAccepted(int finish);
void fileNameChoosed(const QString &name = "");
private:
#ifdef W7API
EcWin7 win7;
@ -86,6 +90,15 @@ private:
QBasicTimer m_timer;
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

View File

@ -20,7 +20,7 @@
DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget *parent)
: QDialog(parent)
,ui(new Ui::DownloadOptionsDialog)
, ui(new Ui::DownloadOptionsDialog)
{
ui->setupUi(this);
ui->fileName->setText("<b>"+fileName+"</b>");
@ -28,18 +28,19 @@ DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon,
ui->fileType->setText(mimeType);
ui->fromServer->setText(url.host());
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)
return 0;
else if (ui->radioOpen->isChecked())
return 1;
else if (ui->radioSave->isChecked())
return 2;
return 2;
if (status != 0) {
if (ui->radioOpen->isChecked())
status = 1;
else if (ui->radioSave->isChecked())
status = 2;
}
emit dialogFinished(status);
}
DownloadOptionsDialog::~DownloadOptionsDialog()

View File

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

View File

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

View File

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

View File

@ -68,7 +68,7 @@ void WebPage::setSSLCertificate(const QSslCertificate &cert)
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;
else
return QSslCertificate();