Seamly2D
Code documentation
fvupdater.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  **
3  ** Copyright (c) 2012 Linas Valiukas and others.
4  **
5  ** Permission is hereby granted, free of charge, to any person obtaining a
6  *copy of this
7  ** software and associated documentation files (the "Software"), to deal in
8  *the Software
9  ** without restriction, including without limitation the rights to use, copy,
10  *modify,
11  ** merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  *and to
13  ** permit persons to whom the Software is furnished to do so, subject to the
14  *following conditions:
15  **
16  ** The above copyright notice and this permission notice shall be included in
17  *all copies or
18  ** substantial portions of the Software.
19  **
20  ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  *IMPLIED, INCLUDING BUT
22  ** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23  *PURPOSE AND
24  ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25  *LIABLE FOR ANY CLAIM,
26  ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27  *OTHERWISE, ARISING FROM,
28  ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29  *THE SOFTWARE.
30  **
31  ******************************************************************************************************/
32 
33 #ifndef FVUPDATER_H
34 #define FVUPDATER_H
35 
36 #include <QMetaObject>
37 #include <QMutex>
38 #include <QNetworkAccessManager>
39 #include <QObject>
40 #include <QPointer>
41 #include <QString>
42 #include <QUrl>
43 #include <QNetworkReply>
44 #include <QtGlobal>
45 
46 extern const QString defaultFeedURL;
47 class QFile;
48 class FvUpdater : public QObject {
49  Q_OBJECT
50 
51 public:
52  // Singleton
53  static FvUpdater *sharedUpdater();
54  static void drop();
55 
56  // Set / get feed URL
57  void SetFeedURL(const QUrl &feedURL);
58  void SetFeedURL(const QString &feedURL);
59  QString GetFeedURL() const;
60 
61  bool IsDropOnFinish() const;
62  void SetDropOnFinish(bool value);
63 signals:
64  void setProgress(int);
65 public slots:
66  // Check for updates
67  bool CheckForUpdates(bool silentAsMuchAsItCouldGet = true);
68 
69  // Aliases
70  bool CheckForUpdatesSilent();
72 
73 protected:
74  friend class FvUpdateWindow; // Uses GetProposedUpdate() and others
75 
76 
77 protected slots:
78 
79 
80 private slots:
82  void networkError(QNetworkReply::NetworkError);
83  void getFileSize();
84 
85 private:
86  //
87  // Singleton business
88  //
89  Q_DISABLE_COPY(FvUpdater)
90  FvUpdater(); // Hide main constructor
91  virtual ~FvUpdater(); // Hide main destructor
92 
93  static QPointer<FvUpdater> m_Instance; // Singleton instance
94 
95  // If true, don't show the error dialogs and the "no updates." dialog
96  // (silentAsMuchAsItCouldGet from CheckForUpdates() goes here)
97  // Useful for automatic update checking upon application startup.
99 
100  //
101  // HTTP feed fetcher infrastructure
102  //
103  QUrl m_feedURL; // Feed URL that will be fetched
104  QNetworkAccessManager m_qnam;
105  QPointer<QNetworkReply> m_reply;
108  int m_fileSize{};
109  QString m_releaseName{};
110 
111  void startDownloadFeed(const QUrl &url); // Start downloading feed
112  void startDownloadFile(QUrl url, QString name); // Start downloading file
113  void fileDownloadFinished(QFile *downloadedFile, QString name);
114  void cancelDownloadFeed(); // Stop downloading the current feed
115 
116  // Dialogs (notifications)
117  // Show an error message
118  void showErrorDialog(const QString &message,
119  bool showEvenInSilentMode = false);
120  // Show an informational message
121  void showInformationDialog(const QString &message,
122  bool showEvenInSilentMode = false);
123 
124  bool showConfirmationDialog(const QString &message,
125  bool showEvenInSilentMode = false);
126 
127 
128  // bool jsonParsing(); //
129  bool releaseIsNewer(const QString &releaseTag);
130  void getPLatformSpecificInstaller(QJsonArray assets);
131 };
132 
133 #endif // FVUPDATER_H
bool CheckForUpdatesNotSilent()
Definition: fvupdater.cpp:172
bool showConfirmationDialog(const QString &message, bool showEvenInSilentMode=false)
Definition: fvupdater.cpp:420
bool releaseIsNewer(const QString &releaseTag)
Definition: fvupdater.cpp:440
void cancelDownloadFeed()
Definition: fvupdater.cpp:305
void SetDropOnFinish(bool value)
Definition: fvupdater.cpp:109
bool CheckForUpdates(bool silentAsMuchAsItCouldGet=true)
Definition: fvupdater.cpp:112
void SetFeedURL(const QUrl &feedURL)
Definition: fvupdater.cpp:95
virtual ~FvUpdater()
Definition: fvupdater.cpp:90
QNetworkAccessManager m_qnam
Definition: fvupdater.h:104
bool m_dropOnFinish
Definition: fvupdater.h:107
bool m_httpRequestAborted
Definition: fvupdater.h:106
void httpFeedDownloadFinished()
Definition: fvupdater.cpp:313
QPointer< QNetworkReply > m_reply
Definition: fvupdater.h:105
friend class FvUpdateWindow
Definition: fvupdater.h:74
QUrl m_feedURL
Definition: fvupdater.h:103
void setProgress(int)
static void drop()
Definition: fvupdater.cpp:74
void startDownloadFeed(const QUrl &url)
Definition: fvupdater.cpp:278
bool CheckForUpdatesSilent()
Definition: fvupdater.cpp:155
void getPLatformSpecificInstaller(QJsonArray assets)
Definition: fvupdater.cpp:357
void getFileSize()
Definition: fvupdater.cpp:180
int m_fileSize
Definition: fvupdater.h:108
QString GetFeedURL() const
Definition: fvupdater.cpp:103
static QPointer< FvUpdater > m_Instance
Definition: fvupdater.h:93
void fileDownloadFinished(QFile *downloadedFile, QString name)
Definition: fvupdater.cpp:237
QString m_releaseName
Definition: fvupdater.h:109
static FvUpdater * sharedUpdater()
Definition: fvupdater.cpp:62
void showInformationDialog(const QString &message, bool showEvenInSilentMode=false)
Definition: fvupdater.cpp:404
bool m_silentAsMuchAsItCouldGet
Definition: fvupdater.h:98
void showErrorDialog(const QString &message, bool showEvenInSilentMode=false)
Definition: fvupdater.cpp:387
bool IsDropOnFinish() const
Definition: fvupdater.cpp:106
void networkError(QNetworkReply::NetworkError)
Definition: fvupdater.cpp:450
void startDownloadFile(QUrl url, QString name)
Definition: fvupdater.cpp:187
const QString defaultFeedURL
Definition: fvupdater.cpp:57