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 2362 2008-02-29 04:30:11Z edmanm $ 00014 ** \brief Associates an IP with a geographic location 00015 */ 00016 00017 #ifndef _GEOIP_H 00018 #define _GEOIP_H 00019 00020 #include <QString> 00021 #include <QHostAddress> 00022 00023 00024 class GeoIp 00025 { 00026 public: 00027 /** Default constructor */ 00028 GeoIp() : _latitude(0xFFFF), _longitude(0xFFFF) {} 00029 /** Constructor. */ 00030 GeoIp(QHostAddress ip); 00031 00032 /** Constructor */ 00033 GeoIp(QHostAddress ip, float latitude, float longitude, 00034 QString city, QString state, QString country); 00035 00036 /** Creates a GeoIp object from a string. */ 00037 static GeoIp fromString(QString geoip); 00038 /** Builds a comma-delimited string of GeoIp fields. */ 00039 QString toString() const; 00040 00041 /** Returns the IP address for this object. */ 00042 QHostAddress ip() const { return _ip; } 00043 /** Returns the latitude coordinate for this IP. */ 00044 float latitude() const { return _latitude; } 00045 /** Returns the longitude coordinate for this IP. */ 00046 float longitude() const { return _longitude; } 00047 /** Returns the city in which this IP lives. */ 00048 QString city() const { return _city; } 00049 /** Returns the state or district in which this IP lives. */ 00050 QString state() const { return _state; } 00051 /** Returns the country in which this IP lives. */ 00052 QString country() const { return _country; } 00053 /** Returns a human-readable string of city, region(state), and country. */ 00054 QString toLocation() const; 00055 00056 /** Returns true if the GeoIp object is invalid. */ 00057 bool isEmpty() const; 00058 /** Returns true if the GeoIp object is valid, but no location information 00059 * is known for the associated IP address. */ 00060 bool isUnknown() const; 00061 00062 private: 00063 QHostAddress _ip; /**< IP address for this location. */ 00064 float _latitude; /**< Latitudinal coordinate for this IP's location. */ 00065 float _longitude; /**< Longitudinal coordinate for this IP's location. */ 00066 QString _city; /**< City in which this IP lives. */ 00067 QString _state; /**< State or district in which this IP lives. */ 00068 QString _country; /**< Country in which this IP lives. */ 00069 }; 00070 00071 #endif 00072