geoip.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /**
00023  * \file geoip.h
00024  * \version $Id: geoip.h 1563 2006-12-26 06:06:04Z edmanm $
00025  * \brief Associates an IP with a geographic location
00026  */
00027 
00028 #ifndef _GEOIP_H
00029 #define _GEOIP_H
00030 
00031 #include <QString>
00032 #include <QHostAddress>
00033 
00034 
00035 class GeoIp
00036 {
00037 public:
00038   /** Default constructor */
00039   GeoIp() : _latitude(0xFFFF), _longitude(0xFFFF) {}
00040   /** Constructor. */
00041   GeoIp(QHostAddress ip);
00042 
00043   /** Constructor */
00044   GeoIp(QHostAddress ip, float latitude, float longitude, 
00045         QString city, QString state, QString country);
00046   
00047   /** Creates a GeoIp object from a string. */
00048   static GeoIp fromString(QString geoip);
00049   /** Builds a comma-delimited string of GeoIp fields. */
00050   QString toString() const;
00051 
00052   /** Returns the IP address for this object. */
00053   QHostAddress ip() const { return _ip; }
00054   /** Returns the latitude coordinate for this IP. */
00055   float latitude() const { return _latitude; }
00056   /** Returns the longitude coordinate for this IP. */
00057   float longitude() const { return _longitude; }
00058   /** Returns the city in which this IP lives. */
00059   QString city() const { return _city; }
00060   /** Returns the state or district in which this IP lives. */
00061   QString state() const { return _state; }
00062   /** Returns the country in which this IP lives. */
00063   QString country() const { return _country; }
00064   /** Returns a human-readable string of city, region(state), and country. */
00065   QString toLocation() const;
00066 
00067   /** Returns true if the GeoIp object is invalid. */
00068   bool isEmpty() const;
00069   /** Returns true if the GeoIp object is valid, but no location information
00070    * is known for the associated IP address. */
00071    bool isUnknown() const;
00072 
00073 private:
00074   QHostAddress _ip; /**< IP address for this location. */
00075   float _latitude;  /**< Latitudinal coordinate for this IP's location. */
00076   float _longitude; /**< Longitudinal coordinate for this IP's location. */
00077   QString _city;    /**< City in which this IP lives. */
00078   QString _state;   /**< State or district in which this IP lives. */
00079   QString _country; /**< Country in which this IP lives. */
00080 };
00081 
00082 #endif
00083 

Generated on Wed Sep 5 15:49:27 2007 for Vidalia by  doxygen 1.5.3