ip2cupdater.h
1 //------------------------------------------------------------------------------
2 // ip2cupdater.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; 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 "Blzut3" <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #ifndef __IP2CUPDATER_H__
24 #define __IP2CUPDATER_H__
25 
26 #include <QByteArray>
27 #include <QObject>
28 #include <QNetworkReply>
29 
30 class FixedNetworkAccessManager;
31 
40 class IP2CUpdater : public QObject
41 {
42  Q_OBJECT
43 
44  public:
45  enum UpdateStatus
46  {
47  UpToDate,
48  UpdateNeeded,
49  UpdateCheckError
50  };
51 
52  IP2CUpdater(QObject *parent = NULL);
53  ~IP2CUpdater();
54 
55  void downloadDatabase();
56  const QByteArray& downloadedData();
57 
58  const QString& filePath() const { return pathToFile; }
59 
71  bool getRollbackData();
72 
73  bool hasDownloadedData() const { return !retrievedData.isEmpty(); }
74  bool hasRollbackData() const { return !rollbackData.isEmpty(); }
75 
76  bool isWorking() const;
77 
88  void needsUpdate(const QString& filePath);
89 
90 
103  bool rollback();
104 
113  bool saveDownloadedData();
114 
115  void setFilePath(const QString& filePath) { pathToFile = filePath; }
116 
117  signals:
121  void databaseDownloadFinished(const QByteArray& downloadedData);
122  void downloadProgress(qint64 value, qint64 max);
126  void updateNeeded(int status);
127 
128  private:
129  static const QUrl dbChecksumUrl();
130  static const QUrl dbDownloadUrl();
131 
132  FixedNetworkAccessManager* pNetworkAccessManager;
133  QNetworkReply* pCurrentNetworkReply;
134 
143  QString pathToFile;
144  QByteArray retrievedData;
145  QByteArray rollbackData;
146 
147  void abort();
148  void get(const QUrl &url, const char *finishedSlot);
149  bool handleRedirect(QNetworkReply &reply, const char *finishedSlot);
150  bool save(const QByteArray& saveWhat);
151 
152  private slots:
153  void checksumDownloadFinished();
154  void downloadFinished();
155 };
156 
157 #endif
IP2CUpdater is responsible for downloading a new version of database from the site.
Definition: ip2cupdater.h:40
bool getRollbackData()
Obtains rollback data from pathToFile file.
void databaseDownloadFinished(const QByteArray &downloadedData)
In case of failure the downloadedData array will be empty.
bool rollback()
Saves data to the pathToFile file. This data must be first obtained through the rollback method...
void needsUpdate(const QString &filePath)
Checks if IP2C file must be updated.
bool saveDownloadedData()
Saves recently downloaded data to the pathToFile file.
void updateNeeded(int status)
Emitted status is one of UpdateStatus enum values.