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 GeoIp.h 00013 ** \version $Id: GeoIp.h 3768 2009-05-13 19:07:26Z edmanm $ 00014 ** \brief Associates an IP with a geographic location 00015 */ 00016 00017 #ifndef _GEOIP_H 00018 #define _GEOIP_H 00019 00020 #include <QHash> 00021 #include <QString> 00022 #include <QHostAddress> 00023 00024 00025 class GeoIp 00026 { 00027 public: 00028 /** Default constructor. Creates an empty GeoIp object. 00029 */ 00030 GeoIp(); 00031 00032 GeoIp(const QHostAddress &ip, float latitude, float longitude, 00033 const QString &city = QString(), 00034 const QString ®ion = QString(), 00035 const QString &country = QString(), 00036 const QString &countryCode = QString()); 00037 00038 /** Returns the IP address associated with this GeoIP object. 00039 */ 00040 QHostAddress ip() const { return _ip; } 00041 00042 /** Returns the latitude portion of the geographic coordinates associated 00043 * with this IP address or range of IP addresses. 00044 */ 00045 float latitude() const { return _latitude; } 00046 00047 /** Returns the longitude portion of the geographic coordinates associated 00048 * with this IP address or range of IP addresses. 00049 */ 00050 float longitude() const { return _longitude; } 00051 00052 /** Returns the name of the city associated with this IP address, if known. 00053 * Otherwise, returns an empty QString. 00054 */ 00055 QString city() const { return _city; } 00056 00057 /** Returns the full region name (e.g., state) in which this IP address 00058 * resides, if known. Otherwise, returns an empty QString. 00059 */ 00060 QString region() const { return _region; } 00061 00062 /** Returns the full name of the country associated with this IP address 00063 * or range of IP addresses, if known. Otherwise, returns an empty QString. 00064 */ 00065 QString country() const { return _country; } 00066 00067 /** Returns the ISO 3166-1 alpha-2 two-letter country code of the country 00068 * associated with this IP address or range of IP addresses, if known. 00069 * Otherwise, returns an empty QString. 00070 */ 00071 QString countryCode() const { return _countryCode; } 00072 00073 /** Returns a human-readable string of city, region(state), and country. 00074 * Some fields may be absent if they are not known. If no fields are known, 00075 * this will return an empty QString. 00076 */ 00077 QString toString() const; 00078 00079 /** Returns true if the GeoIp object is valid. A valid GeoIp object must 00080 * have valid IP address, valid latitude and longitude coordinates and a 00081 * two-letter country code. 00082 */ 00083 bool isValid() const; 00084 00085 private: 00086 QHostAddress _ip; /**< IP address for this location. */ 00087 float _latitude; /**< Latitudinal coordinate for this IP's location. */ 00088 float _longitude; /**< Longitudinal coordinate for this IP's location. */ 00089 QString _city; /**< City in which this IP lives. */ 00090 QString _region; /**< State or district in which this IP lives. */ 00091 QString _country; /**< Country in which this IP lives. */ 00092 QString _countryCode; /**< ISO-3166-1 alpha-2 country code. */ 00093 }; 00094 00095 #endif 00096