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 <QNetworkAccessManager>
29 #include <QNetworkReply>
30 #include <QNetworkRequest>
31 
32 #include <wadseeker/protocols/fixednetworkaccessmanager.h>
33 
42 class IP2CUpdater : public QObject
43 {
44  Q_OBJECT
45 
46  public:
55  static bool needsUpdate(const QString& filePath, unsigned minimumUpdateAge);
56 
57  IP2CUpdater();
58  ~IP2CUpdater();
59 
60  void downloadDatabase(const QUrl& netLocation);
61  const QByteArray& downloadedData();
62 
63  const QString& filePath() const { return pathToFile; }
64 
76  bool getRollbackData();
77 
78  bool hasDownloadedData() const { return !retrievedData.isEmpty(); }
79  bool hasRollbackData() const { return !rollbackData.isEmpty(); }
80 
93  bool rollback();
94 
103  bool saveDownloadedData();
104 
105  void setFilePath(const QString& filePath) { pathToFile = filePath; }
106 
107  signals:
111  void databaseDownloadFinished(const QByteArray& downloadedData);
112  void downloadProgress(qint64 value, qint64 max);
113 
114  private:
115  FixedNetworkAccessManager* pNetworkAccessManager;
116  QNetworkReply* pCurrentNetworkReply;
117 
125  QString pathToFile;
126  QByteArray retrievedData;
127  QByteArray rollbackData;
128 
129  bool save(const QByteArray& saveWhat);
130 
131  private slots:
132  void downloadFinished();
133 };
134 
135 #endif
static bool needsUpdate(const QString &filePath, unsigned minimumUpdateAge)
Checks if IP2C file must be updated.
IP2CUpdater is responsible for downloading a new version of database from the site.
Definition: ip2cupdater.h:42
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...
bool saveDownloadedData()
Saves recently downloaded data to the pathToFile file.