Fabcoin Core  0.16.2
P2P Digital Currency
fabcoinversionchecker.h
Go to the documentation of this file.
1 #ifndef FABCOINVERSIONCHECKER_H
2 #define FABCOINVERSIONCHECKER_H
3 
4 #include <QObject>
5 
6 #define FABCOIN_RELEASES "https://github.com/fabcoinproject/fabcoin/releases"
7 
8 class Version {
9 
10 public:
11  int _major;
12  int _minor;
13  int _revision;
14 
16  SetNull();
17  }
18 
19  Version(int maj, int min, int rev){
20  SetNull();
21 
22  _major = maj;
23  _minor = min;
24  _revision = rev;
25  }
26 
27  Version(QString str){
28  SetNull();
29 
30  QStringList parts = str.split(".");
31 
32  if(!parts.isEmpty())
33  _major = parts[0].toInt();
34  if(parts.length() > 1)
35  _minor = parts[1].toInt();
36  if(parts.length() > 2)
37  _revision = parts[2].toInt();
38  }
39 
40  Version(const Version &v){
41  _major = v._major;
42  _minor = v._minor;
43  _revision = v._revision;
44  }
45 
46  bool operator >(const Version& other) const
47  {
48  return compareAll(other) > 0;
49  }
50 
51  bool operator <(const Version& other) const
52  {
53  return compareAll(other) < 0;
54  }
55 
56  bool operator ==(const Version& other) const
57  {
58  return compareAll(other) == 0;
59  }
60 
61  void SetNull()
62  {
63  _major = 0;
64  _minor = 0;
65  _revision = 0;
66  }
67 
68 private:
69  int compare(int first, int second) const
70  {
71  int diff = first - second;
72  return diff > 0 ? 1 : diff < 0 ? -1 : 0;
73  }
74  int compareAll(const Version& other) const
75  {
76  return 4 * compare(_major, other._major) +
77  2 * compare(_minor, other._minor) +
78  compare(_revision, other._revision);
79  }
80 };
81 
82 class FabcoinVersionChecker : public QObject
83 {
84  Q_OBJECT
85 public:
86  explicit FabcoinVersionChecker(QObject *parent = 0);
88 
89  bool newVersionAvailable();
90 
91 private:
92  QList<Version> getVersions();
93  Version getMaxReleaseVersion();
94 
96 };
97 
98 #endif // FABCOINVERSIONCHECKER_H
int compare(int first, int second) const
uint32_t maj(uint32_t x, uint32_t y, uint32_t z)
Definition: picosha2.h:77
bool operator>(const Version &other) const
bool operator<(const Version &other) const
Version(QString str)
ExecStats::duration min
Definition: ExecStats.cpp:35
int compareAll(const Version &other) const
Version(int maj, int min, int rev)
N diff(N const &_a, N const &_b)
Definition: Common.h:212
Version(const Version &v)
u256 toInt(json_spirit::mValue const &_v)
Definition: TestHelper.cpp:195
bool operator==(const Version &other) const