Vidalia 0.2.10
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file GeoIpRecord.h 00013 ** \version $Id: GeoIpRecord.h 4378 2010-08-05 20:28:54Z edmanm $ 00014 ** \brief Associates an IP with a geographic location 00015 */ 00016 00017 #ifndef _GEOIPRECORD_H 00018 #define _GEOIPRECORD_H 00019 00020 #include <QHash> 00021 #include <QString> 00022 #include <QHostAddress> 00023 00024 00025 class GeoIpRecord 00026 { 00027 public: 00028 /** Default constructor. Creates an empty GeoIpRecord object. 00029 */ 00030 GeoIpRecord(); 00031 00032 /** 00033 */ 00034 GeoIpRecord(const QHostAddress &ip, float latitude, float longitude, 00035 const QString &country, const QString &countryCode); 00036 00037 /** 00038 */ 00039 GeoIpRecord(const QHostAddress &ip, float latitude, float longitude, 00040 const QString &city, const QString ®ion, 00041 const QString &country, const QString &countryCode); 00042 00043 /** Returns the IP address associated with this GeoIP object. 00044 */ 00045 QHostAddress ip() const { return _ip; } 00046 00047 /** Returns the latitude portion of the geographic coordinates associated 00048 * with this IP address or range of IP addresses. 00049 */ 00050 float latitude() const { return _latitude; } 00051 00052 /** Returns the longitude portion of the geographic coordinates associated 00053 * with this IP address or range of IP addresses. 00054 */ 00055 float longitude() const { return _longitude; } 00056 00057 /** Returns the name of the city associated with this IP address, if known. 00058 * Otherwise, returns an empty QString. 00059 */ 00060 QString city() const { return _city; } 00061 00062 /** Returns the full region name (e.g., state) in which this IP address 00063 * resides, if known. Otherwise, returns an empty QString. 00064 */ 00065 QString region() const { return _region; } 00066 00067 /** Returns the full name of the country associated with this IP address 00068 * or range of IP addresses, if known. Otherwise, returns an empty QString. 00069 */ 00070 QString country() const { return _country; } 00071 00072 /** Returns the ISO 3166-1 alpha-2 two-letter country code of the country 00073 * associated with this IP address or range of IP addresses, if known. 00074 * Otherwise, returns an empty QString. 00075 */ 00076 QString countryCode() const { return _countryCode; } 00077 00078 /** Returns a human-readable string of city, region(state), and country. 00079 * Some fields may be absent if they are not known. If no fields are known, 00080 * this will return an empty QString. 00081 */ 00082 QString toString() const; 00083 00084 /** Returns true if the GeoIpRecord object is valid. A valid GeoIpRecord object must 00085 * have valid IP address, valid latitude and longitude coordinates and a 00086 * two-letter country code. 00087 */ 00088 bool isValid() const; 00089 00090 private: 00091 QHostAddress _ip; /**< IP address for this location. */ 00092 float _latitude; /**< Latitudinal coordinate for this IP's location. */ 00093 float _longitude; /**< Longitudinal coordinate for this IP's location. */ 00094 QString _city; /**< City in which this IP lives. */ 00095 QString _region; /**< State or district in which this IP lives. */ 00096 QString _country; /**< Country in which this IP lives. */ 00097 QString _countryCode; /**< ISO-3166-1 alpha-2 country code. */ 00098 }; 00099 00100 #endif 00101