28 #include "ip2c/entities/ip2ccountryinfo.h"
31 #include <QHostAddress>
35 #include <QProgressBar>
48 class IP2C :
public QObject
59 QString countryFullName;
66 bool isCountryKnown()
const;
74 return ipStart != ipEnd;
78 static IP2C *instance();
79 static void deinstantiate();
81 const QPixmap flagLan;
82 const QPixmap flagLocalhost;
83 const QPixmap flagUnknown;
85 const QPixmap &flag(
const QString &countryShortName);
88 bool isDataAccessLocked()
const
90 return bDataAccessLocked;
96 const IP2CData &
lookupIP(
unsigned int ipaddress);
97 const IP2CData &
lookupIP(
const QHostAddress &ipaddress)
99 return lookupIP(ipaddress.toIPv4Address());
102 int numKnownEntries()
const
104 return database.size();
116 void setDataAccessLockEnabled(
bool b)
118 bDataAccessLocked = b;
129 database = sortedCountryData;
133 inline bool isLANAddress(
unsigned ipv4Address)
135 const static unsigned LAN_1_BEGIN = QHostAddress(
"10.0.0.0").toIPv4Address();
136 const static unsigned LAN_1_END = QHostAddress(
"10.255.255.255").toIPv4Address();
137 const static unsigned LAN_2_BEGIN = QHostAddress(
"172.16.0.0").toIPv4Address();
138 const static unsigned LAN_2_END = QHostAddress(
"172.31.255.255").toIPv4Address();
139 const static unsigned LAN_3_BEGIN = QHostAddress(
"192.168.0.0").toIPv4Address();
140 const static unsigned LAN_3_END = QHostAddress(
"192.168.255.255").toIPv4Address();
143 (ipv4Address >= LAN_1_BEGIN && ipv4Address <= LAN_1_END)
144 || (ipv4Address >= LAN_2_BEGIN && ipv4Address <= LAN_2_END)
145 || (ipv4Address >= LAN_3_BEGIN && ipv4Address <= LAN_3_END)
149 inline bool isLocalhostAddress(
unsigned ipv4Address)
151 const static unsigned LOCALHOST_BEGIN = QHostAddress(
"127.0.0.0").toIPv4Address();
152 const static unsigned LOCALHOST_END = QHostAddress(
"127.255.255.255").toIPv4Address();
154 return ipv4Address >= LOCALHOST_BEGIN && ipv4Address <= LOCALHOST_END;
158 static QMutex instanceMutex;
159 static IP2C *staticInstance;
168 bool bDataAccessLocked;
169 QList<IP2CData> database;
170 QHash<QString, QPixmap> flags;
171 const IP2CData invalidData;