File indexing completed on 2024-05-12 04:58:05
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2017 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 DOWNLOADITEM_H 0019 #define DOWNLOADITEM_H 0020 0021 #include <QWidget> 0022 #include <QFile> 0023 #include <QBasicTimer> 0024 #include <QUrl> 0025 #include <QNetworkReply> 0026 #include <QElapsedTimer> 0027 #include <QTime> 0028 #include <QElapsedTimer> 0029 0030 #include "qzcommon.h" 0031 0032 namespace Ui 0033 { 0034 class DownloadItem; 0035 } 0036 0037 class QListWidgetItem; 0038 class QWebEngineDownloadRequest; 0039 0040 class DownloadManager; 0041 0042 class FALKON_EXPORT DownloadItem : public QWidget 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 explicit DownloadItem(QListWidgetItem* item, QWebEngineDownloadRequest* downloadItem, const QString &path, const QString &fileName, bool openFile, DownloadManager* manager); 0048 bool isDownloading() const { return m_downloading; } 0049 bool isCancelled(); 0050 QTime remainingTime() const { return m_remTime; } 0051 double currentSpeed() const { return m_currSpeed; } 0052 int progress(); 0053 QUrl url() const; 0054 QString path() const; 0055 QString fileName() const; 0056 ~DownloadItem() override; 0057 void setDownTimer(const QElapsedTimer &timer) { m_downTimer = timer; } 0058 0059 void startDownloading(); 0060 0061 static QString remaingTimeToString(QTime time); 0062 static QString currentSpeedToString(double speed); 0063 0064 Q_SIGNALS: 0065 void deleteItem(DownloadItem*); 0066 void downloadFinished(bool success); 0067 void progressChanged(double currSpeed, qint64 received, qint64 total); 0068 0069 private Q_SLOTS: 0070 void parentResized(const QSize &size); 0071 void finished(); 0072 void receivedOrTotalBytesChanged(); 0073 void stop(); 0074 void pauseResume(); 0075 void openFile(); 0076 void openFolder(); 0077 void customContextMenuRequested(const QPoint &pos); 0078 void clear(); 0079 0080 void copyDownloadLink(); 0081 0082 private: 0083 void updateDownloadInfo(double currSpeed, qint64 received, qint64 total); 0084 void mouseDoubleClickEvent(QMouseEvent* e) override; 0085 0086 Ui::DownloadItem* ui; 0087 0088 QListWidgetItem* m_item; 0089 QWebEngineDownloadRequest* m_download; 0090 QString m_path; 0091 QString m_fileName; 0092 QElapsedTimer m_downTimer; 0093 QTime m_remTime; 0094 QUrl m_downUrl; 0095 bool m_openFile; 0096 0097 bool m_downloading; 0098 bool m_downloadStopped; 0099 double m_currSpeed; 0100 qint64 m_received; 0101 qint64 m_total; 0102 }; 0103 0104 #endif // DOWNLOADITEM_H