QSimpleUpdater
A simple auto-updater system for Qt applications
Downloader.h
1 /*
2  * Copyright (c) 2014-2016 Alex Spataru <alex_spataru@outlook.com>
3  *
4  * This file is part of the QSimpleUpdater library, which is released under
5  * the DBAD license, you can read a copy of it below:
6  *
7  * DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
8  * DISTRIBUTION AND MODIFICATION:
9  *
10  * Do whatever you like with the original work, just don't be a dick.
11  * Being a dick includes - but is not limited to - the following instances:
12  *
13  * 1a. Outright copyright infringement - Don't just copy this and change the
14  * name.
15  * 1b. Selling the unmodified original with no work done what-so-ever, that's
16  * REALLY being a dick.
17  * 1c. Modifying the original work to contain hidden harmful content.
18  * That would make you a PROPER dick.
19  *
20  * If you become rich through modifications, related works/services, or
21  * supporting the original work, share the love.
22  * Only a dick would make loads off this work and not buy the original works
23  * creator(s) a pint.
24  *
25  * Code is provided with no warranty. Using somebody else's code and bitching
26  * when it goes wrong makes you a DONKEY dick.
27  * Fix the problem yourself. A non-dick would submit the fix back.
28  */
29 
30 #ifndef DOWNLOAD_DIALOG_H
31 #define DOWNLOAD_DIALOG_H
32 
33 #include <QDialog>
34 #include <ui_Downloader.h>
35 
36 namespace Ui {
37 class Downloader;
38 }
39 
40 class QNetworkReply;
41 class QNetworkAccessManager;
42 
46 class Downloader : public QWidget {
47  Q_OBJECT
48 
49  signals:
50  void downloadFinished (const QString& url, const QString& filepath);
51 
52  public:
53  explicit Downloader (QWidget* parent = 0);
54  ~Downloader();
55 
56  bool useCustomInstallProcedures() const;
57 
58  public slots:
59  void startDownload (const QUrl& url);
60  void setUseCustomInstallProcedures (const bool& custom);
61 
62  private slots:
63  void openDownload();
64  void installUpdate();
65  void cancelDownload();
66  void onDownloadFinished();
67  void calculateSizes (qint64 received, qint64 total);
68  void updateProgress (qint64 received, qint64 total);
69  void calculateTimeRemaining (qint64 received, qint64 total);
70 
71  private:
72  qreal round (const qreal& input);
73 
74  private:
75  uint m_startTime;
76  QString m_filePath;
77  Ui::Downloader* m_ui;
78  QNetworkReply* m_reply;
79  bool m_useCustomProcedures;
80  QNetworkAccessManager* m_manager;
81 };
82 
83 #endif
Definition: Downloader.h:36
Implements an integrated file downloader with a nice UI.
Definition: Downloader.h:46