• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • edu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • extragear
  • edu
  • kstars
  • kstars
  • auxiliary
filedownloader.h
Go to the documentation of this file.
1 /* KStars File Downloader
2  *
3  Copyright (C) 2016 Jasem Mutlaq <[email protected]>
4 
5  Adapted from https://wiki.qt.io/Download_Data_from_URL
6 
7  This application is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11  */
12 
13 #pragma once
14 
15 #include <QByteArray>
16 #include <QFile>
17 #include <QNetworkAccessManager>
18 #include <QNetworkRequest>
19 #include <QNetworkReply>
20 #include <QObject>
21 #include <QTemporaryFile>
22 
23 #include <functional>
24 
25 class QProgressDialog;
26 
27 class FileDownloader : public QObject
28 {
29  Q_OBJECT
30  public:
31  explicit FileDownloader(QObject *parent = nullptr);
32  ~FileDownloader() override = default;
33 
34  void get(const QUrl &fileUrl);
35  void post(const QUrl &fileUrl, QByteArray &data);
36  void post(const QUrl &fileUrl, QHttpMultiPart *parts);
37 
38  QByteArray downloadedData() const;
39 
40  QUrl getDownloadedFileURL() const;
41  bool setDownloadedFileURL(const QUrl &DownloadedFile);
42 
43  void setProgressDialogEnabled(bool ShowProgressDialog, const QString &textTitle = QString(),
44  const QString &textLabel = QString());
45 
46  // Callbacks to verify data before being accepted
47  void registerDataVerification(std::function<bool(const QByteArray &data)> verifyFunc) { m_verifyData = verifyFunc; }
48  void registerFileVerification(std::function<bool(const QString &filename)> verifyFile){ m_verifyFile = verifyFile; }
49 
50  signals:
51  void downloaded();
52  void canceled();
53  void error(const QString &errorString);
54  void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
55 
56  private slots:
57  void dataFinished(QNetworkReply *pReply);
58  void dataReady();
59  void slotError();
60  void setDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
61 
62  private:
63  QNetworkAccessManager m_WebCtrl;
64  QByteArray m_DownloadedData;
65 
66  // Downloaded file
67  QUrl m_DownloadedFileURL;
68 
69  // Temporary file used until download is successful
70  QTemporaryFile m_downloadTemporaryFile;
71 
72  // Network reply
73  QNetworkReply *m_Reply { nullptr };
74 
75  // Optional Progress dialog
76  bool m_ShowProgressDialog { false };
77 
78 #ifndef KSTARS_LITE
79  QProgressDialog *progressDialog { nullptr };
80 #endif
81  bool isCancelled { false };
82  QString label;
83  QString title;
84 
85  std::function<bool(const QByteArray &data)> m_verifyData;
86  std::function<bool(const QString &filename)> m_verifyFile;
87 };
FileDownloader::registerFileVerification
void registerFileVerification(std::function< bool(const QString &filename)> verifyFile)
Definition: filedownloader.h:48
QByteArray
QNetworkReply
FileDownloader::setDownloadedFileURL
bool setDownloadedFileURL(const QUrl &DownloadedFile)
Definition: filedownloader.cpp:172
FileDownloader::post
void post(const QUrl &fileUrl, QByteArray &data)
Definition: filedownloader.cpp:49
FileDownloader
Definition: filedownloader.h:27
QObject
QString
FileDownloader::downloadProgress
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
FileDownloader::getDownloadedFileURL
QUrl getDownloadedFileURL() const
Definition: filedownloader.cpp:167
QUrl
FileDownloader::registerDataVerification
void registerDataVerification(std::function< bool(const QByteArray &data)> verifyFunc)
Definition: filedownloader.h:47
QNetworkAccessManager
QHttpMultiPart
FileDownloader::downloadedData
QByteArray downloadedData() const
Definition: filedownloader.cpp:235
FileDownloader::error
void error(const QString &errorString)
FileDownloader::downloaded
void downloaded()
FileDownloader::FileDownloader
FileDownloader(QObject *parent=nullptr)
Definition: filedownloader.cpp:26
FileDownloader::canceled
void canceled()
FileDownloader::setProgressDialogEnabled
void setProgressDialogEnabled(bool ShowProgressDialog, const QString &textTitle=QString(), const QString &textLabel=QString())
Definition: filedownloader.cpp:151
QTemporaryFile
FileDownloader::~FileDownloader
~FileDownloader() override=default
QObject::parent
QObject * parent() const
QProgressDialog
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sun Dec 15 2019 03:10:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

edu API Reference

Skip menu "edu API Reference"
  •     core
  • kstars

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal