File indexing completed on 2025-01-05 04:00:11

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2020-11-14
0007  * Description : Files downloader
0008  *
0009  * SPDX-FileCopyrightText: 2020-2021 by Maik Qualmann <metzpinguin at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_FILES_DOWNLOADER_H
0016 #define DIGIKAM_FILES_DOWNLOADER_H
0017 
0018 // Qt includes
0019 
0020 #include <QDialog>
0021 #include <QSettings>
0022 #include <QNetworkReply>
0023 
0024 // Local includes
0025 
0026 #include "digikam_export.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 // ----------------------------------------------------------------------------
0032 
0033 class DIGIKAM_EXPORT DownloadInfo
0034 {
0035 public:
0036 
0037     DownloadInfo();
0038     DownloadInfo(const QString& _path,
0039                  const QString& _name,
0040                  const QString& _hash,
0041                  const qint64&  _size);
0042     DownloadInfo(const DownloadInfo& other);
0043     ~DownloadInfo();
0044 
0045     DownloadInfo& operator=(const DownloadInfo& other);
0046 
0047     /**
0048      * The file path on the server
0049      */
0050     QString path;
0051 
0052     /**
0053      * The file name on the server
0054      */
0055     QString name;
0056 
0057     /**
0058      * The file hash as SHA256
0059      */
0060     QString hash;
0061 
0062     /**
0063      * The file size
0064      */
0065     qint64  size;
0066 };
0067 
0068 // ----------------------------------------------------------------------------
0069 
0070 class DIGIKAM_EXPORT FilesDownloader : public QDialog
0071 {
0072     Q_OBJECT
0073 
0074 public:
0075 
0076     explicit FilesDownloader(QWidget* const parent = nullptr);
0077     ~FilesDownloader() override;
0078 
0079     bool checkDownloadFiles() const;
0080     void startDownload();
0081 
0082 private:
0083 
0084     void download();
0085     void nextDownload();
0086     void createRequest(const QUrl& url);
0087     void printDownloadInfo(const QUrl& url);
0088     bool downloadExists(const DownloadInfo& info) const;
0089 
0090     QString getFacesEnginePath()                  const;
0091     void createDownloadInfo();
0092 
0093 private Q_SLOTS:
0094 
0095     void reject() override;
0096     void slotDownload();
0097     void slotHelp();
0098     void slotUpdateDownloadInfo();
0099     void slotDownloaded(QNetworkReply* reply);
0100     void slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
0101 
0102 private:
0103 
0104     // Disable
0105     FilesDownloader(const FilesDownloader&)            = delete;
0106     FilesDownloader& operator=(const FilesDownloader&) = delete;
0107 
0108 private:
0109 
0110     class Private;
0111     Private* const d;
0112 };
0113 
0114 } // namespace Digikam
0115 
0116 #endif // DIGIKAM_FILES_DOWNLOADER_H