27 #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;
92 const QPixmap& flag(
const QString& countryShortName);
94 bool isDataAccessLocked()
const
96 return bDataAccessLocked;
102 const IP2CData&
lookupIP(
unsigned int ipaddress);
103 const IP2CData&
lookupIP(
const QHostAddress &ipaddress) {
return lookupIP(ipaddress.toIPv4Address()); }
105 int numKnownEntries()
const {
return database.size(); }
113 void setDataAccessLockEnabled(
bool b) { bDataAccessLocked = b; }
123 QMutexLocker dataAccessMutexLocker(&dataAccessMutex);
124 database = sortedCountryData;
128 inline bool isLANAddress(
unsigned ipv4Address)
130 const static unsigned LAN_1_BEGIN = QHostAddress(
"10.0.0.0").toIPv4Address();
131 const static unsigned LAN_1_END = QHostAddress(
"10.255.255.255").toIPv4Address();
132 const static unsigned LAN_2_BEGIN = QHostAddress(
"172.16.0.0").toIPv4Address();
133 const static unsigned LAN_2_END = QHostAddress(
"172.31.255.255").toIPv4Address();
134 const static unsigned LAN_3_BEGIN = QHostAddress(
"192.168.0.0").toIPv4Address();
135 const static unsigned LAN_3_END = QHostAddress(
"192.168.255.255").toIPv4Address();
138 (ipv4Address >= LAN_1_BEGIN && ipv4Address <= LAN_1_END)
139 || (ipv4Address >= LAN_2_BEGIN && ipv4Address <= LAN_2_END)
140 || (ipv4Address >= LAN_3_BEGIN && ipv4Address <= LAN_3_END)
144 inline bool isLocalhostAddress(
unsigned ipv4Address)
146 const static unsigned LOCALHOST_BEGIN = QHostAddress(
"127.0.0.0").toIPv4Address();
147 const static unsigned LOCALHOST_END = QHostAddress(
"127.255.255.255").toIPv4Address();
149 return (ipv4Address >= LOCALHOST_BEGIN && ipv4Address <= LOCALHOST_END);
153 static QMutex instanceMutex;
154 static IP2C *staticInstance;
163 bool bDataAccessLocked;
164 QMutex dataAccessMutex;
165 QList<IP2CData> database;
166 QHash<QString, QPixmap> flags;
167 const IP2CData invalidData;
void setDatabase(const QList< IP2CData > &sortedCountryData)
Sets database contents to the list specified.
IP2CCountryInfo obtainCountryInfo(unsigned int ipaddress)
void appendEntryToDatabase(const IP2CData &entry)
Adds new country entry to the database.
const IP2CData & lookupIP(unsigned int ipaddress)
IP to Country database handler.
Flag and name of the country.