parent
2091b3d60c
commit
db0584f81e
13 changed files with 268 additions and 12 deletions
@ -0,0 +1,65 @@ |
|||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser |
||||||
|
* Copyright (C) 2019 Javier Llorente <javier@opensuse.org> |
||||||
|
* |
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */ |
||||||
|
#include "downloadmanagermodel.h" |
||||||
|
|
||||||
|
DownloadManagerModel::DownloadManagerModel(QObject *parent) |
||||||
|
: QAbstractListModel(parent) |
||||||
|
{ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
int DownloadManagerModel::rowCount(const QModelIndex &parent) const |
||||||
|
{ |
||||||
|
Q_UNUSED(parent); |
||||||
|
return count(); |
||||||
|
} |
||||||
|
|
||||||
|
QVariant DownloadManagerModel::data(const QModelIndex &index, int role) const |
||||||
|
{ |
||||||
|
if (role == Qt::DisplayRole) { |
||||||
|
const DownloadItem *item = m_downloads.at(index.row()); |
||||||
|
return item; |
||||||
|
} |
||||||
|
return QVariant(); |
||||||
|
} |
||||||
|
|
||||||
|
void DownloadManagerModel::addDownload(DownloadItem *item) |
||||||
|
{ |
||||||
|
m_downloads.append(item); |
||||||
|
connect(item, &DownloadItem::deleteItem, this, &DownloadManagerModel::removeDownload); |
||||||
|
emit downloadAdded(item); |
||||||
|
} |
||||||
|
|
||||||
|
void DownloadManagerModel::removeDownload(DownloadItem *item) |
||||||
|
{ |
||||||
|
if (item && !item->isDownloading()) { |
||||||
|
delete item; |
||||||
|
emit downloadRemoved(item); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int DownloadManagerModel::count() const |
||||||
|
{ |
||||||
|
return m_downloads.count(); |
||||||
|
} |
||||||
|
|
||||||
|
DownloadItem *DownloadManagerModel::at(int index) |
||||||
|
{ |
||||||
|
return m_downloads.at(index); |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,45 @@ |
|||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser |
||||||
|
* Copyright (C) 2019 Javier Llorente <javier@opensuse.org> |
||||||
|
* |
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */ |
||||||
|
#ifndef DOWNLOADMANAGERMODEL_H |
||||||
|
#define DOWNLOADMANAGERMODEL_H |
||||||
|
|
||||||
|
#include <QAbstractListModel> |
||||||
|
#include "downloaditem.h" |
||||||
|
|
||||||
|
class DownloadManagerModel : public QAbstractListModel |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
DownloadManagerModel(QObject *parent = nullptr); |
||||||
|
int rowCount(const QModelIndex &parent) const; |
||||||
|
QVariant data(const QModelIndex &index, int role) const; |
||||||
|
void addDownload(DownloadItem *item); |
||||||
|
void removeDownload(DownloadItem *item); |
||||||
|
int count() const; |
||||||
|
DownloadItem *at(int index); |
||||||
|
|
||||||
|
private: |
||||||
|
QList<DownloadItem *> m_downloads; |
||||||
|
|
||||||
|
signals: |
||||||
|
void downloadAdded(DownloadItem *item); |
||||||
|
void downloadRemoved(DownloadItem *item); |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // DOWNLOADMANAGERMODEL_H
|
||||||
@ -0,0 +1,44 @@ |
|||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser |
||||||
|
* Copyright (C) 2019 Javier Llorente <javier@opensuse.org> |
||||||
|
* |
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */ |
||||||
|
#include "downloadkjob.h" |
||||||
|
|
||||||
|
DownloadKJob::DownloadKJob(const QUrl &url, const QString &path, const QString &fileName, QObject *parent) |
||||||
|
: KJob(parent), |
||||||
|
m_url(url), |
||||||
|
m_path(path), |
||||||
|
m_fileName(fileName) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void DownloadKJob::start() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void DownloadKJob::updateDescription() |
||||||
|
{ |
||||||
|
emit description(this, tr("Downloading"), |
||||||
|
qMakePair<QString, QString>(tr("Source"), m_url.toDisplayString()), |
||||||
|
qMakePair<QString, QString>(tr("Destination"), QString("%1/%2").arg(m_path, m_fileName))); |
||||||
|
} |
||||||
|
|
||||||
|
void DownloadKJob::progress(double currSpeed, qint64 received, qint64 total) |
||||||
|
{ |
||||||
|
setProcessedAmount(Bytes, received); |
||||||
|
setTotalAmount(Bytes, total); |
||||||
|
emit speed(this, currSpeed); |
||||||
|
} |
||||||
@ -0,0 +1,44 @@ |
|||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser |
||||||
|
* Copyright (C) 2019 Javier Llorente <javier@opensuse.org> |
||||||
|
* |
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */ |
||||||
|
#ifndef DOWNLOADKJOB_H |
||||||
|
#define DOWNLOADKJOB_H |
||||||
|
|
||||||
|
#include "qzcommon.h" |
||||||
|
#include <KJob> |
||||||
|
#include <QUrl> |
||||||
|
|
||||||
|
class FALKON_EXPORT DownloadKJob : public KJob |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
DownloadKJob(const QUrl &url, const QString &path, const QString &fileName, QObject *parent = nullptr); |
||||||
|
void start(); |
||||||
|
void updateDescription(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void progress(double currSpeed, qint64 received, qint64 total); |
||||||
|
|
||||||
|
private: |
||||||
|
QUrl m_url; |
||||||
|
QString m_path; |
||||||
|
QString m_fileName; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
#endif // DOWNLOADKJOB_H
|
||||||
Loading…
Reference in new issue