Falkon Develop
Cross-platform Qt-based web browser
downloadmanager.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef DOWNLOADMANAGER_H
19#define DOWNLOADMANAGER_H
20
21#include <QWidget>
22#include <QPointer>
23#include <QBasicTimer>
24
25#include "qzcommon.h"
26
27namespace Ui
28{
29class DownloadManager;
30}
31
32class QUrl;
33class QNetworkAccessManager;
34class QListWidgetItem;
35class QWebEngineDownloadRequest;
36class QWinTaskbarButton;
37
38class DownloadItem;
40class WebPage;
41
42class FALKON_EXPORT DownloadManager : public QWidget
43{
44 Q_OBJECT
45public:
46 enum DownloadOption { OpenFile, SaveFile, ExternalManager, NoOption };
47
48 struct DownloadInfo {
51
54
55 DownloadInfo(WebPage* p = nullptr) {
56 page = p;
57 suggestedFileName = QString();
58 askWhatToDo = true;
59 forceChoosingPath = false;
60 }
61 };
62
63 explicit DownloadManager(QWidget* parent = nullptr);
64 ~DownloadManager() override;
65
66 void loadSettings();
67
68 void download(QWebEngineDownloadRequest *downloadItem);
69
70 int downloadsCount() const;
71 int activeDownloadsCount() const;
72
73 bool canClose();
74
75 bool useExternalManager() const;
76 void startExternalManager(const QUrl &url);
77
78 void setLastDownloadPath(const QString &lastPath) { m_lastDownloadPath = lastPath; }
79 void setLastDownloadOption(DownloadOption option) { m_lastDownloadOption = option; }
80
81public Q_SLOTS:
82 void show();
83
84private Q_SLOTS:
85 void clearList();
86 void downloadFinished(bool success);
87
88Q_SIGNALS:
89 void resized(QSize);
94
95private:
96 void timerEvent(QTimerEvent* e) override;
97 void closeEvent(QCloseEvent* e) override;
98 void resizeEvent(QResizeEvent* e) override;
99 void keyPressEvent(QKeyEvent* e) override;
100
101 void closeDownloadTab(QWebEngineDownloadRequest *item) const;
102 QWinTaskbarButton *taskbarButton();
103
104 Ui::DownloadManager* ui;
105 DownloadManagerModel *m_model;
106 QBasicTimer m_timer;
107
108 QString m_lastDownloadPath;
109 QString m_downloadPath;
110 bool m_useNativeDialog;
111 bool m_isClosing;
112 bool m_closeOnFinish;
113 int m_activeDownloadsCount = 0;
114
115 bool m_useExternalManager;
116 QString m_externalExecutable;
117 QString m_externalArguments;
118
119 DownloadOption m_lastDownloadOption;
120
121 QPointer<QWinTaskbarButton> m_taskbarButton;
122};
123
124#endif // DOWNLOADMANAGER_H
void downloadFinished()
void resized(QSize)
void downloadAdded(DownloadItem *item)
void setLastDownloadOption(DownloadOption option)
void downloadRemoved(DownloadItem *item)
void downloadsCountChanged()
void setLastDownloadPath(const QString &lastPath)
#define FALKON_EXPORT
Definition: qzcommon.h:28
DownloadInfo(WebPage *p=nullptr)