2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#ifndef DOWNLOADMANAGER_H
|
|
|
|
#define DOWNLOADMANAGER_H
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QBasicTimer>
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2011-03-04 15:40:45 +01:00
|
|
|
#include "ecwin7.h"
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
namespace Ui
|
|
|
|
{
|
|
|
|
class DownloadManager;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
class QNetworkReply;
|
|
|
|
class QNetworkRequest;
|
|
|
|
class QListWidgetItem;
|
|
|
|
class QUrl;
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
class DownloadItem;
|
|
|
|
class EcWin7;
|
2011-03-20 17:42:56 +01:00
|
|
|
class NetworkManager;
|
2011-11-08 15:20:53 +01:00
|
|
|
class WebPage;
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_EXPORT DownloadManager : public QWidget
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-01 19:21:49 +01:00
|
|
|
enum DownloadOption { OpenFile, SaveFile, ExternalManager, NoOption };
|
2011-12-06 19:18:06 +01:00
|
|
|
|
2012-08-14 18:53:55 +02:00
|
|
|
struct DownloadInfo {
|
|
|
|
WebPage* page;
|
|
|
|
QString suggestedFileName;
|
|
|
|
|
|
|
|
bool askWhatToDo;
|
|
|
|
bool forceChoosingPath;
|
|
|
|
|
|
|
|
DownloadInfo(WebPage* p = 0) {
|
|
|
|
page = p;
|
|
|
|
suggestedFileName = QString();
|
|
|
|
askWhatToDo = true;
|
|
|
|
forceChoosingPath = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
explicit DownloadManager(QWidget* parent = 0);
|
2011-03-02 16:57:41 +01:00
|
|
|
~DownloadManager();
|
|
|
|
|
2011-05-25 14:26:36 +02:00
|
|
|
void loadSettings();
|
|
|
|
|
2012-08-14 18:53:55 +02:00
|
|
|
void download(const QNetworkRequest &request, const DownloadInfo &info);
|
|
|
|
void handleUnsupportedContent(QNetworkReply* reply, const DownloadInfo &info);
|
2012-03-23 13:58:31 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
bool canClose();
|
2012-08-14 11:52:06 +02:00
|
|
|
|
|
|
|
bool useExternalManager() const;
|
|
|
|
void startExternalManager(const QUrl &url);
|
|
|
|
|
2011-10-18 14:30:17 +02:00
|
|
|
void setLastDownloadPath(const QString &lastPath) { m_lastDownloadPath = lastPath; }
|
2011-12-06 19:18:06 +01:00
|
|
|
void setLastDownloadOption(const DownloadOption &option) { m_lastDownloadOption = option; }
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-18 14:30:17 +02:00
|
|
|
public slots:
|
|
|
|
void show();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-28 12:02:37 +01:00
|
|
|
#ifdef W7TASKBAR
|
2011-03-02 16:57:41 +01:00
|
|
|
protected:
|
2013-01-19 23:22:30 +01:00
|
|
|
#if (QT_VERSION < 0x050000)
|
2011-03-17 17:03:04 +01:00
|
|
|
virtual bool winEvent(MSG* message, long* result);
|
2013-01-19 23:22:30 +01:00
|
|
|
#else
|
|
|
|
virtual bool nativeEvent(const QByteArray &eventType, void* _message, long* result);
|
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void clearList();
|
|
|
|
void deleteItem(DownloadItem* item);
|
2011-05-08 12:54:49 +02:00
|
|
|
|
2011-09-30 19:22:50 +02:00
|
|
|
void itemCreated(QListWidgetItem* item, DownloadItem* downItem);
|
|
|
|
void downloadFinished(bool success);
|
2011-05-08 12:54:49 +02:00
|
|
|
|
2011-05-25 14:26:36 +02:00
|
|
|
signals:
|
|
|
|
void resized(QSize);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
private:
|
2012-01-28 12:02:37 +01:00
|
|
|
#ifdef W7TASKBAR
|
2011-03-02 16:57:41 +01:00
|
|
|
EcWin7 win7;
|
|
|
|
#endif
|
2012-04-20 14:49:16 +02:00
|
|
|
void timerEvent(QTimerEvent* e);
|
2011-03-17 17:03:04 +01:00
|
|
|
void closeEvent(QCloseEvent* e);
|
2011-11-06 17:01:23 +01:00
|
|
|
void resizeEvent(QResizeEvent* e);
|
2012-04-20 14:49:16 +02:00
|
|
|
void keyPressEvent(QKeyEvent* e);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
Ui::DownloadManager* ui;
|
2011-03-20 17:42:56 +01:00
|
|
|
NetworkManager* m_networkManager;
|
2011-09-30 19:22:50 +02:00
|
|
|
QBasicTimer m_timer;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QString m_lastDownloadPath;
|
|
|
|
QString m_downloadPath;
|
2011-05-25 14:26:36 +02:00
|
|
|
bool m_useNativeDialog;
|
2011-03-02 16:57:41 +01:00
|
|
|
bool m_isClosing;
|
2011-10-30 16:32:36 +01:00
|
|
|
bool m_closeOnFinish;
|
2011-12-06 19:18:06 +01:00
|
|
|
|
2012-01-28 15:37:11 +01:00
|
|
|
bool m_useExternalManager;
|
|
|
|
QString m_externalExecutable;
|
|
|
|
QString m_externalArguments;
|
|
|
|
|
2011-12-06 19:18:06 +01:00
|
|
|
DownloadOption m_lastDownloadOption;
|
2011-03-02 16:57:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DOWNLOADMANAGER_H
|