File indexing completed on 2024-05-12 04:58:05
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #ifndef DOWNLOADMANAGER_H 0019 #define DOWNLOADMANAGER_H 0020 0021 #include <QWidget> 0022 #include <QPointer> 0023 #include <QBasicTimer> 0024 0025 #include "qzcommon.h" 0026 0027 namespace Ui 0028 { 0029 class DownloadManager; 0030 } 0031 0032 class QUrl; 0033 class QNetworkAccessManager; 0034 class QListWidgetItem; 0035 class QWebEngineDownloadRequest; 0036 class QWinTaskbarButton; 0037 0038 class DownloadItem; 0039 class DownloadManagerModel; 0040 class WebPage; 0041 0042 class FALKON_EXPORT DownloadManager : public QWidget 0043 { 0044 Q_OBJECT 0045 public: 0046 enum DownloadOption { OpenFile, SaveFile, ExternalManager, NoOption }; 0047 0048 struct DownloadInfo { 0049 WebPage* page; 0050 QString suggestedFileName; 0051 0052 bool askWhatToDo; 0053 bool forceChoosingPath; 0054 0055 DownloadInfo(WebPage* p = nullptr) { 0056 page = p; 0057 suggestedFileName = QString(); 0058 askWhatToDo = true; 0059 forceChoosingPath = false; 0060 } 0061 }; 0062 0063 explicit DownloadManager(QWidget* parent = nullptr); 0064 ~DownloadManager() override; 0065 0066 void loadSettings(); 0067 0068 void download(QWebEngineDownloadRequest *downloadItem); 0069 0070 int downloadsCount() const; 0071 int activeDownloadsCount() const; 0072 0073 bool canClose(); 0074 0075 bool useExternalManager() const; 0076 void startExternalManager(const QUrl &url); 0077 0078 void setLastDownloadPath(const QString &lastPath) { m_lastDownloadPath = lastPath; } 0079 void setLastDownloadOption(DownloadOption option) { m_lastDownloadOption = option; } 0080 0081 public Q_SLOTS: 0082 void show(); 0083 0084 private Q_SLOTS: 0085 void clearList(); 0086 void downloadFinished(bool success); 0087 0088 Q_SIGNALS: 0089 void resized(QSize); 0090 void downloadsCountChanged(); 0091 void downloadAdded(DownloadItem *item); 0092 void downloadRemoved(DownloadItem *item); 0093 void downloadFinished(); 0094 0095 private: 0096 void timerEvent(QTimerEvent* e) override; 0097 void closeEvent(QCloseEvent* e) override; 0098 void resizeEvent(QResizeEvent* e) override; 0099 void keyPressEvent(QKeyEvent* e) override; 0100 0101 void closeDownloadTab(QWebEngineDownloadRequest *item) const; 0102 QWinTaskbarButton *taskbarButton(); 0103 0104 Ui::DownloadManager* ui; 0105 DownloadManagerModel *m_model; 0106 QBasicTimer m_timer; 0107 0108 QString m_lastDownloadPath; 0109 QString m_downloadPath; 0110 bool m_useNativeDialog; 0111 bool m_isClosing; 0112 bool m_closeOnFinish; 0113 int m_activeDownloadsCount = 0; 0114 0115 bool m_useExternalManager; 0116 QString m_externalExecutable; 0117 QString m_externalArguments; 0118 0119 DownloadOption m_lastDownloadOption; 0120 0121 QPointer<QWinTaskbarButton> m_taskbarButton; 0122 }; 0123 0124 #endif // DOWNLOADMANAGER_H