ip2cupdater.h
1 //------------------------------------------------------------------------------
2 // ip2cupdater.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #ifndef __IP2CUPDATER_H__
24 #define __IP2CUPDATER_H__
25 
26 #include <QByteArray>
27 #include <QObject>
28 #include <QNetworkReply>
29 
37 class IP2CUpdater : public QObject
38 {
39  Q_OBJECT
40 
41  public:
42  enum UpdateStatus
43  {
44  UpToDate,
45  UpdateNeeded,
46  UpdateCheckError
47  };
48 
49  IP2CUpdater(QObject *parent = NULL);
50  ~IP2CUpdater();
51 
52  void downloadDatabase(const QString &savePath);
53  const QByteArray& downloadedData();
54 
66  bool getRollbackData(const QString &databasePath);
67 
68  bool hasDownloadedData() const { return !retrievedData.isEmpty(); }
69  bool hasRollbackData() const { return !rollbackData.isEmpty(); }
70 
71  bool isWorking() const;
72 
83  void needsUpdate(const QString& filePath);
84 
85 
98  bool rollback(const QString &savePath);
99 
108  bool saveDownloadedData(const QString &savePath);
109 
110  signals:
114  void databaseDownloadFinished(const QByteArray& downloadedData);
115  void downloadProgress(qint64 value, qint64 max);
119  void updateNeeded(int status);
120 
121  private:
122  static const QUrl dbChecksumUrl();
123  static const QUrl dbDownloadUrl();
124 
125  QNetworkAccessManager* pNetworkAccessManager;
126  QNetworkReply* pCurrentNetworkReply;
127 
128  QString lastAsyncCallPath;
129  QByteArray retrievedData;
130  QByteArray rollbackData;
131 
132  void abort();
133  void get(const QUrl &url, const char *finishedSlot);
134  bool handleRedirect(QNetworkReply &reply, const char *finishedSlot);
135  bool save(const QByteArray& saveWhat, const QString &savePath);
136 
137  private slots:
138  void checksumDownloadFinished();
139  void downloadFinished();
140 };
141 
142 #endif
IP2CUpdater is responsible for downloading a new version of database from the site.
Definition: ip2cupdater.h:37
void databaseDownloadFinished(const QByteArray &downloadedData)
In case of failure the downloadedData array will be empty.
bool saveDownloadedData(const QString &savePath)
Saves recently downloaded data to the specified file.
bool getRollbackData(const QString &databasePath)
Obtains rollback data from specified file.
void needsUpdate(const QString &filePath)
Checks if IP2C file must be updated.
bool rollback(const QString &savePath)
Saves rollback data to the specified file. This data must be first obtained through the getRollbackDa...
void updateNeeded(int status)
Emitted status is one of UpdateStatus enum values.