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