2023-06-26 17:12:01 -04:00
|
|
|
/*
|
2025-02-06 21:47:26 -04:00
|
|
|
* Copyright (C) 2024-2025 Savoir-faire Linux Inc.
|
2023-06-26 17:12:01 -04: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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "networkmanager.h"
|
2023-11-16 15:27:07 -05:00
|
|
|
#include "connectivitymonitor.h"
|
2023-06-26 17:12:01 -04:00
|
|
|
#include "qtutils.h"
|
|
|
|
|
2023-11-16 15:27:07 -05:00
|
|
|
#include <QQmlEngine> // QML registration
|
|
|
|
#include <QApplication> // QML registration
|
|
|
|
|
2024-04-15 13:58:17 -04:00
|
|
|
class FileDownloader : public NetworkManager
|
2023-06-26 17:12:01 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2023-11-16 15:27:07 -05:00
|
|
|
QML_SINGLETON
|
2023-06-26 17:12:01 -04:00
|
|
|
|
|
|
|
QML_PROPERTY(QString, cachePath)
|
|
|
|
|
|
|
|
public:
|
2024-04-15 13:58:17 -04:00
|
|
|
static FileDownloader* create(QQmlEngine*, QJSEngine*)
|
2023-11-16 15:27:07 -05:00
|
|
|
{
|
2024-04-15 13:58:17 -04:00
|
|
|
return new FileDownloader(
|
2023-11-16 15:27:07 -05:00
|
|
|
qApp->property("ConnectivityMonitor").value<ConnectivityMonitor*>());
|
|
|
|
}
|
|
|
|
|
2024-04-15 13:58:17 -04:00
|
|
|
explicit FileDownloader(ConnectivityMonitor* cm, QObject* parent = nullptr);
|
|
|
|
~FileDownloader() = default;
|
2023-06-26 17:12:01 -04:00
|
|
|
|
2024-04-15 13:58:17 -04:00
|
|
|
// Download an image and call onDownloadFileFinished when done
|
|
|
|
Q_INVOKABLE void downloadFile(const QUrl& url, const QString& localPath);
|
2023-06-26 17:12:01 -04:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2024-04-15 13:58:17 -04:00
|
|
|
void downloadFileSuccessful(const QString& localPath);
|
|
|
|
void downloadFileFailed(const QString& localPath);
|
2023-06-26 17:12:01 -04:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
// Saves the image to the localPath and emits the appropriate signal
|
2024-04-15 13:58:17 -04:00
|
|
|
void onDownloadFileFinished(const QByteArray& reply, const QString& localPath);
|
2023-11-16 15:27:07 -05:00
|
|
|
};
|