From 8e29818bb3ac8f0188d886f008330b1e8af76340 Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 30 Sep 2011 19:22:50 +0200 Subject: [PATCH] Hopefully fixed one crash and one possible crash in download manager --- bin/locale/sk_SK.qm | Bin 73069 -> 73058 bytes src/QupZilla.pro | 8 +- src/data/html/test.html | 46 ------ src/downloads/downloadfilehelper.cpp | 190 ++++++++++++++++++++++++ src/downloads/downloadfilehelper.h | 54 +++++++ src/downloads/downloaditem.cpp | 37 ++--- src/downloads/downloaditem.h | 2 +- src/downloads/downloadmanager.cpp | 168 ++------------------- src/downloads/downloadmanager.h | 26 +--- src/downloads/downloadmanager.ui | 11 +- src/downloads/downloadoptionsdialog.cpp | 2 +- src/downloads/downloadoptionsdialog.h | 2 +- translations/cs_CZ.ts | 2 +- translations/sk_SK.ts | 4 +- 14 files changed, 282 insertions(+), 270 deletions(-) delete mode 100644 src/data/html/test.html create mode 100644 src/downloads/downloadfilehelper.cpp create mode 100644 src/downloads/downloadfilehelper.h diff --git a/bin/locale/sk_SK.qm b/bin/locale/sk_SK.qm index e305a83d72a5c583c57619073351e3aef6105c18..833d0ae7751b086ad0020b99e0b6682b355e3816 100644 GIT binary patch delta 5246 zcmX9?c|c9+8-C8c_ndq0x#!+XA#2%^LK-v%VPeQqjR{dmq#8^1u})p0K?=EIER!ue zF|rKFXt89gEM*N7hOuXvpDn+qIe*mCJ?Gr-yx;S@@AJN2&yMQ;I;vY%-_{HG$^!i8 z0{Eo^BmGo7w+HCe5@^*P=yMFHpQ2*lNyL1hJO=0=4ICdqTm{4h*OXu?H~_qJKGXsu1GntGpi# zaq(W@VIssN9kke+W^W)kxtBxSW(QXJLfjP&oKJ?B&&M8}gjjeQIJ8m4M-}#Af|D&2 zZqY%2v#W}Y@1XevPvD9O_mVK+!dZA!?Q+9X6+iEXM^*5fYQv){$W3`@Q58h`3ACts z+ZG#IRK0CWCOoS-1C^W5dglXRk1xEEB7j7HeB~E&MM~bhyUu4K<5$!SPlU5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fpe2T=}j&bE8vJrR}Y7V4|Pm-M$lGGbp{svXR^NE4{~!hoicalYO2t zIQR%>*)K}KQgShGt1@CGbK?h-GRnXPwAw=n_IS-BL5VVbLlVz!wUl{%4)eL1$^zdE z=29 zsA8W^DqbvB&R=t3E`%sq2^8Vn6Xo)(V4jNY%JsRF-f~oVc#gReqg5VPFJaQIQc7;R zAQ;aoDy0I|Zs2dWy=27KGtD)A{h5cO7_+-Y5Cn{Z%aM=7_G;(A{i~D+=VvWtobe1uFJ# zr{er5bJC$}G}hIQhm~w~vdzbgDYVNO=8Sb*tE7iH^O83mYm|!jnmVdfZfLJ&e!r?G z^RJ8fQ!1%5Y0dwQtj%LZEA!`FPV~7}7Ts~Kk}<{Nlzo+}lvyfiR`FbO-BNuhSG}~t zQllfOD)h6s)J)_t<&~xB7YEOeRV{6LvTCM#S$>#IYx+Ie(zQ`B&k&0&Js;kp6k{#@ zJ6X?5M^U-C1r)&N;>cd}zrS&0IPE z%yNJ8D$Z{cezUyl98S}GX(@ZfY;>!p;x3zt|4y;W$L|4+^Hl8pNX31(RlM=l>eM%# z6YpND>-#4xz^m4}-+QvMhpG4>=^F}yleNAtnR@ia>XEdA|0tMkZJxS~g5*9f|G?=Z z-rBw{E%N)?)^15FfY0I9L3K%Ch3nQ4KN#88YFUHwSh;WCTEqTs$3~pvcweRAq`KCq zk2I3lG1h(2S_+w9J?rfQWX-dli#x=9##^t4_2uy7XT9NDiM$-PKH0`_ZKc-dpUKbA zH7Z`6X)QiEjmI^?`tizb3YTyFMZ=}0NDL+mB_RTc>$NQ5om46e_floIpf1dxGVaw*9hxce7$8RGW>b#rr SLyI8S6t_T|kWw_#p7wvt-HLMn diff --git a/src/QupZilla.pro b/src/QupZilla.pro index b7df21d39..43be4358d 100644 --- a/src/QupZilla.pro +++ b/src/QupZilla.pro @@ -134,7 +134,8 @@ SOURCES += main.cpp\ preferences/thememanager.cpp \ network/qupzillaschemehandler.cpp \ tools/globalfunctions.cpp \ - other/pagescreen.cpp + other/pagescreen.cpp \ + downloads/downloadfilehelper.cpp HEADERS += \ 3rdparty/qtwin.h \ @@ -229,7 +230,8 @@ HEADERS += \ preferences/thememanager.h \ network/qupzillaschemehandler.h \ tools/globalfunctions.h \ - other/pagescreen.h + other/pagescreen.h \ + downloads/downloadfilehelper.h FORMS += \ preferences/autofillmanager.ui \ @@ -294,3 +296,5 @@ win32:LIBS += User32.lib Ole32.lib Shell32.lib ShlWapi.lib Gdi32.lib ComCtl32.li + + diff --git a/src/data/html/test.html b/src/data/html/test.html deleted file mode 100644 index 2c6b55ecb..000000000 --- a/src/data/html/test.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - -CSS Rounded Corners + Liquid + Images - - - - - -
-
-

This is a header

-
-
-

This is for your content.

-
-
- - diff --git a/src/downloads/downloadfilehelper.cpp b/src/downloads/downloadfilehelper.cpp new file mode 100644 index 000000000..5fb1e2eae --- /dev/null +++ b/src/downloads/downloadfilehelper.cpp @@ -0,0 +1,190 @@ +#include "downloadfilehelper.h" +#include "webpage.h" +#include "webview.h" +#include "downloadoptionsdialog.h" +#include "mainapplication.h" +#include "qupzilla.h" +#include "downloaditem.h" +#include "downloadmanager.h" + +DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog) + : QObject() + , m_lastDownloadPath(lastDownloadPath) + , m_downloadPath(downloadPath) + , m_useNativeDialog(useNativeDialog) + , m_reply(0) + , m_openFileChoosed(false) + , m_iconProvider(new QFileIconProvider) +{ +} + +////////////////////////////////////////////////////// +//// Getting where to download requested file +//// in 3 functions, as we are using non blocking +//// dialogs ( this is important to make secure downloading +//// on windows working properly ) +////////////////////////////////////////////////////// + +void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo) +{ + m_timer = new QTime(); + m_timer->start(); + m_h_fileName = getFileName(reply); + m_reply = reply; + + QFileInfo info(reply->url().toString()); + QTemporaryFile tempFile("XXXXXX."+info.suffix()); + tempFile.open(); + QFileInfo tempInfo(tempFile.fileName()); + m_fileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30); + QString mimeType = m_iconProvider->type(tempInfo); + + //Get Download Page and Close Empty Tab + QNetworkRequest request = m_reply->request(); + QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); + WebPage* webPage = (WebPage*)(v.value()); + if (webPage) { + if (!webPage->mainFrame()->url().isEmpty()) + m_downloadPage = webPage->mainFrame()->url(); + else if (webPage->history()->canGoBack()) + m_downloadPage = webPage->history()->backItem().url(); + else if (webPage->history()->count() == 0) + webPage->getView()->closeTab(); + } + + if (askWhatToDo) { + DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_fileIcon, mimeType, reply->url(), mApp->activeWindow()); + dialog->show(); + connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int))); + } else + optionsDialogAccepted(2); +} + +void DownloadFileHelper::optionsDialogAccepted(int finish) +{ + m_openFileChoosed = false; + switch (finish) { + case 0: //Cancelled + if (m_timer) + delete m_timer; + return; + break; + case 1: //Open + m_openFileChoosed = true; + break; + case 2: //Save + break; + } + + if (!m_openFileChoosed) { + if (m_downloadPath.isEmpty()) { + if (m_useNativeDialog) { + fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName)); + } else { + 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(m_downloadPath + m_h_fileName, true); + } else + fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName, true); +} + +void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoGenerated) +{ + m_userFileName = name; + if (m_userFileName.isEmpty()) { + m_reply->abort(); + if (m_timer) + delete m_timer; + return; + } + + int pos = m_userFileName.lastIndexOf("/"); + if (pos != -1) { + int size = m_userFileName.size(); + m_path = m_userFileName.left(pos+1); + m_fileName = m_userFileName.right(size-pos-1); + } + + if (fileNameAutoGenerated && QFile::exists(m_userFileName)) { + QString _tmpFileName = m_fileName; + int i = 1; + while (QFile::exists(m_path + "/" + _tmpFileName)) { + _tmpFileName = m_fileName; + int index = _tmpFileName.lastIndexOf("."); + + if (index == -1) { + _tmpFileName.append("("+QString::number(i)+")"); + } else { + _tmpFileName = _tmpFileName.mid(0, index) + "("+QString::number(i)+")" + _tmpFileName.mid(index); + } + i++; + } + m_fileName = _tmpFileName; + } + + if (!m_path.contains(QDir::tempPath())) + m_lastDownloadPath = m_path; + + QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + settings.beginGroup("DownloadManager"); + settings.setValue("lastDownloadPath", m_lastDownloadPath); + settings.endGroup(); + + QListWidgetItem* item = new QListWidgetItem(m_listWidget); + DownloadItem* downItem = new DownloadItem(item, m_reply, m_path, m_fileName, m_fileIcon, m_timer, m_openFileChoosed, m_downloadPage); + + emit itemCreated(item, downItem); +} + +////////////////////////////////////////////////////// +//// End here +////////////////////////////////////////////////////// + +QString DownloadFileHelper::getFileName(QNetworkReply* reply) +{ + QString path; + if (reply->hasRawHeader("Content-Disposition")) { + QString value = reply->rawHeader("Content-Disposition"); + int pos = value.indexOf("filename="); + if (pos!=-1) { + QString name = value.mid(pos + 9); + if (name.startsWith('"') && name.endsWith('"')) + name = name.mid(1, name.size() - 2); + path = name; + } + } + if (path.isEmpty()) + path = reply->url().path(); + + QFileInfo info(path); + QString baseName = info.completeBaseName(); + QString endName = info.suffix(); + + if (baseName.isEmpty()) { + baseName = tr("NoNameDownload"); + } + + if (!endName.isEmpty()) + endName="."+endName; + + QString name = baseName+endName; + if (name.startsWith("\"")) + name = name.mid(1); + if (name.endsWith("\";")) + name.remove("\";"); + + return name; +} + +DownloadFileHelper::~DownloadFileHelper() +{ + delete m_iconProvider; +} diff --git a/src/downloads/downloadfilehelper.h b/src/downloads/downloadfilehelper.h new file mode 100644 index 000000000..e447cda91 --- /dev/null +++ b/src/downloads/downloadfilehelper.h @@ -0,0 +1,54 @@ +#ifndef DOWNLOADFILEHELPER_H +#define DOWNLOADFILEHELPER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class DownloadItem; +class DownloadFileHelper : public QObject +{ + Q_OBJECT +public: + explicit DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog); + ~DownloadFileHelper(); + + void setListWidget(QListWidget* tw) { m_listWidget = tw; } + void handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo); + +signals: + void itemCreated(QListWidgetItem* item, DownloadItem* downItem); + +private slots: + void optionsDialogAccepted(int finish); + void fileNameChoosed(const QString &name, bool fileNameAutoGenerated = false); + +private: + QString getFileName(QNetworkReply* reply); + + QString m_lastDownloadPath; + QString m_downloadPath; + bool m_useNativeDialog; + + QTime* m_timer; + QString m_path; + QString m_fileName; + QString m_userFileName; + QString m_h_fileName; + QNetworkReply* m_reply; + QPixmap m_fileIcon; + QUrl m_downloadPage; + bool m_openFileChoosed; + + QListWidget* m_listWidget; + QFileIconProvider* m_iconProvider; + +}; + +#endif // DOWNLOADFILEHELPER_H diff --git a/src/downloads/downloaditem.cpp b/src/downloads/downloaditem.cpp index 5219b6ad3..7c91c28f6 100644 --- a/src/downloads/downloaditem.cpp +++ b/src/downloads/downloaditem.cpp @@ -25,18 +25,18 @@ //#define DOWNMANAGER_DEBUG -DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString path, QString fileName, QPixmap fileIcon, QTime* timer, bool openAfterFinishedDownload, QWidget* parent) - : QWidget(parent) - ,ui(new Ui::DownloadItem) - ,m_item(item) - ,m_reply(reply) - ,m_path(path) - ,m_fileName(fileName) - ,m_downTimer(timer) - ,m_downUrl(reply->url()) - ,m_downloadPage(QUrl()) - ,m_downloading(false) - ,m_openAfterFinish(openAfterFinishedDownload) +DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QString &path, const QString &fileName, const QPixmap &fileIcon, QTime* timer, bool openAfterFinishedDownload, const QUrl &downloadPage) + : QWidget() + , ui(new Ui::DownloadItem) + , m_item(item) + , m_reply(reply) + , m_path(path) + , m_fileName(fileName) + , m_downTimer(timer) + , m_downUrl(reply->url()) + , m_downloadPage(downloadPage) + , m_downloading(false) + , m_openAfterFinish(openAfterFinishedDownload) { #ifdef DOWNMANAGER_DEBUG qDebug() << __FUNCTION__ << item << reply << path << fileName; @@ -85,19 +85,6 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString error(m_reply->error()); } show(); - - //Get Download Page - QNetworkRequest request = m_reply->request(); - QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); - WebPage* webPage = (WebPage*)(v.value()); - if (webPage) { - if (!webPage->mainFrame()->url().isEmpty()) - m_downloadPage = webPage->mainFrame()->url(); - else if (webPage->history()->canGoBack()) - m_downloadPage = webPage->history()->backItem().url(); -// else if (webPage->history()->count() == 0) -// webPage->getView()->closeTab(); - } } void DownloadItem::parentResized(const QSize &size) diff --git a/src/downloads/downloaditem.h b/src/downloads/downloaditem.h index d9281e99b..f8d83e30c 100644 --- a/src/downloads/downloaditem.h +++ b/src/downloads/downloaditem.h @@ -42,7 +42,7 @@ class DownloadItem : public QWidget Q_OBJECT public: - explicit DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString path, QString fileName, QPixmap fileIcon, QTime* timer, bool openAfterFinishedDownload, QWidget* parent = 0); + explicit DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QString &path, const QString &fileName, const QPixmap &fileIcon, QTime* timer, bool openAfterFinishedDownload, const QUrl &downloadPage); bool isDownloading() { return m_downloading; } bool isCancelled(); QTime remainingTime() { return m_remTime; } diff --git a/src/downloads/downloadmanager.cpp b/src/downloads/downloadmanager.cpp index eafa4a458..259430987 100644 --- a/src/downloads/downloadmanager.cpp +++ b/src/downloads/downloadmanager.cpp @@ -26,6 +26,7 @@ #include "desktopnotificationsfactory.h" #include "globalfunctions.h" #include "webpage.h" +#include "downloadfilehelper.h" DownloadManager::DownloadManager(QWidget* parent) : QWidget(parent) @@ -41,7 +42,6 @@ DownloadManager::DownloadManager(QWidget* parent) : ui->clearButton->setIcon(QIcon::fromTheme("edit-clear")); qz_centerWidgetOnScreen(this); - m_iconProvider = new QFileIconProvider(); m_networkManager = mApp->networkManager(); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearList())); @@ -154,140 +154,27 @@ 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) { - m_htimer = new QTime(); - m_htimer->start(); - m_h_fileName = getFileName(reply); - m_hreply = reply; + DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog); + h->setListWidget(ui->list); + h->handleUnsupportedContent(reply, askWhatToDo); - QFileInfo info(reply->url().toString()); - QTemporaryFile tempFile("XXXXXX."+info.suffix()); - tempFile.open(); - QFileInfo tempInfo(tempFile.fileName()); - m_hfileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30); - QString mimeType = m_iconProvider->type(tempInfo); - - //Get Download Page and Close Empty Tab - QNetworkRequest request = m_hreply->request(); - QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); - WebPage* webPage = (WebPage*)(v.value()); - if (webPage && webPage->mainFrame()->url().isEmpty() && !webPage->history()->canGoBack() && webPage->history()->count() == 0) - webPage->getView()->closeTab(); - - if (askWhatToDo) { - 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 - optionsDialogAccepted(2); + connect(h, SIGNAL(itemCreated(QListWidgetItem*,DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*,DownloadItem*))); } -void DownloadManager::optionsDialogAccepted(int finish) +void DownloadManager::itemCreated(QListWidgetItem *item, DownloadItem *downItem) { - m_hOpenFileChoosed = false; - switch (finish) { - case 0: //Cancelled - if (m_htimer) - delete m_htimer; - return; - break; - case 1: //Open - m_hOpenFileChoosed = true; - break; - case 2: //Save - break; - } - - if (!m_hOpenFileChoosed) { - if (m_downloadPath.isEmpty()) { - if (m_useNativeDialog) { - fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName)); - } else { - 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(m_downloadPath + m_h_fileName, true); - } else - fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName, true); -} - -void DownloadManager::fileNameChoosed(const QString &name, bool fileNameAutoGenerated) -{ - m_huserFileName = name; - if (m_huserFileName.isEmpty()) { - m_hreply->abort(); - if (m_htimer) - delete m_htimer; - 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 (fileNameAutoGenerated && QFile::exists(m_huserFileName)) { - QString _tmpFileName = m_hfileName; - int i = 1; - while (QFile::exists(m_hpath + "/" + _tmpFileName)) { - _tmpFileName = m_hfileName; - int index = _tmpFileName.lastIndexOf("."); - - if (index == -1) { - _tmpFileName.append("("+QString::number(i)+")"); - } else { - _tmpFileName = _tmpFileName.mid(0, index) + "("+QString::number(i)+")" + _tmpFileName.mid(index); - } - i++; - } - m_hfileName = _tmpFileName; - } - - if (!m_hpath.contains(QDir::tempPath())) - m_lastDownloadPath = m_hpath; - - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); - settings.beginGroup("DownloadManager"); - settings.setValue("lastDownloadPath",m_lastDownloadPath); - settings.endGroup(); - - QListWidgetItem* item = new QListWidgetItem(ui->list); - DownloadItem* downItem = new DownloadItem(item, m_hreply, m_hpath, m_hfileName, m_hfileIcon, m_htimer, m_hOpenFileChoosed, this); + downItem->setParent(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) { @@ -322,42 +209,6 @@ void DownloadManager::deleteItem(DownloadItem* item) delete item; } -QString DownloadManager::getFileName(QNetworkReply* reply) -{ - QString path; - if (reply->hasRawHeader("Content-Disposition")) { - QString value = reply->rawHeader("Content-Disposition"); - int pos = value.indexOf("filename="); - if (pos!=-1) { - QString name = value.mid(pos + 9); - if (name.startsWith('"') && name.endsWith('"')) - name = name.mid(1, name.size() - 2); - path = name; - } - } - if (path.isEmpty()) - path = reply->url().path(); - - QFileInfo info(path); - QString baseName = info.completeBaseName(); - QString endName = info.suffix(); - - if (baseName.isEmpty()) { - baseName = tr("NoNameDownload"); - } - - if (!endName.isEmpty()) - endName="."+endName; - - QString name = baseName+endName; - if (name.startsWith("\"")) - name = name.mid(1); - if (name.endsWith("\";")) - name.remove("\";"); - - return name; -} - bool DownloadManager::canClose() { if (m_isClosing) @@ -398,5 +249,4 @@ DownloadManager::~DownloadManager() { delete ui; delete m_networkManager; - delete m_iconProvider; } diff --git a/src/downloads/downloadmanager.h b/src/downloads/downloadmanager.h index cd322bed9..f3af9514f 100644 --- a/src/downloads/downloadmanager.h +++ b/src/downloads/downloadmanager.h @@ -20,13 +20,10 @@ #include #include -#include #include #include #include -#include #include -#include #include #include #include @@ -34,6 +31,7 @@ #include #include #include +#include #include "ecwin7.h" @@ -68,12 +66,10 @@ protected: private slots: void clearList(); void deleteItem(DownloadItem* item); + + void itemCreated(QListWidgetItem* item, DownloadItem* downItem); void downloadFinished(bool success); - - void optionsDialogAccepted(int finish); - void fileNameChoosed(const QString &name, bool fileNameAutoGenerated = false); - signals: void resized(QSize); @@ -82,31 +78,17 @@ private: EcWin7 win7; #endif void timerEvent(QTimerEvent* event); - QString getFileName(QNetworkReply* reply); void closeEvent(QCloseEvent* e); void resizeEvent(QResizeEvent *e); Ui::DownloadManager* ui; NetworkManager* m_networkManager; - QFileIconProvider* m_iconProvider; + QBasicTimer m_timer; QString m_lastDownloadPath; QString m_downloadPath; bool m_useNativeDialog; - - QBasicTimer m_timer; - bool m_isClosing; - - // Variables used by HandleUnsupportContent: - QTime* m_htimer; - 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 diff --git a/src/downloads/downloadmanager.ui b/src/downloads/downloadmanager.ui index 0d1a1ae6a..1c7387d6f 100644 --- a/src/downloads/downloadmanager.ui +++ b/src/downloads/downloadmanager.ui @@ -23,18 +23,9 @@ 0 - + 0 - - 0 - - - 0 - - - 4 - diff --git a/src/downloads/downloadoptionsdialog.cpp b/src/downloads/downloadoptionsdialog.cpp index 6ef18123c..b4dae36ae 100644 --- a/src/downloads/downloadoptionsdialog.cpp +++ b/src/downloads/downloadoptionsdialog.cpp @@ -18,7 +18,7 @@ #include "downloadoptionsdialog.h" #include "ui_downloadoptionsdialog.h" -DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget *parent) +DownloadOptionsDialog::DownloadOptionsDialog(const QString &fileName, const QPixmap &fileIcon, const QString &mimeType, const QUrl &url, QWidget* parent) : QDialog(parent) , ui(new Ui::DownloadOptionsDialog) { diff --git a/src/downloads/downloadoptionsdialog.h b/src/downloads/downloadoptionsdialog.h index 2285b7ffb..4fcc231d6 100644 --- a/src/downloads/downloadoptionsdialog.h +++ b/src/downloads/downloadoptionsdialog.h @@ -31,7 +31,7 @@ class DownloadOptionsDialog : public QDialog Q_OBJECT public: - explicit DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget* parent = 0); + explicit DownloadOptionsDialog(const QString &fileName, const QPixmap &fileIcon, const QString &mimeType, const QUrl &url, QWidget* parent = 0); ~DownloadOptionsDialog(); private slots: diff --git a/translations/cs_CZ.ts b/translations/cs_CZ.ts index b14ddd10c..1a70a2aef 100644 --- a/translations/cs_CZ.ts +++ b/translations/cs_CZ.ts @@ -1035,7 +1035,7 @@ nebyl nalezen! Správce stahování - + Clear Vyčistit diff --git a/translations/sk_SK.ts b/translations/sk_SK.ts index 371b6e299..55133f37f 100644 --- a/translations/sk_SK.ts +++ b/translations/sk_SK.ts @@ -1038,7 +1038,7 @@ p, li { white-space: pre-wrap; } Správca sťahovania - + Clear Vyčistiť @@ -1063,7 +1063,7 @@ p, li { white-space: pre-wrap; } What should QupZilla do with this file? - + Čo by mala QupZilla urobiť s tímto súborom?