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 1238 2006-09-25 17:50:57Z 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(0), _longitude(0) {}
00040 
00041   /** Constructor */
00042   GeoIp(QHostAddress ip, float latitude, float longitude, 
00043         QString city, QString state, QString country);
00044   
00045   /** Creates a GeoIp object from a string. */
00046   static GeoIp fromString(QString geoip);
00047   /** Builds a comma-delimited string of GeoIp fields. */
00048   QString toString() const;
00049 
00050   /** Returns the IP address for this object. */
00051   QHostAddress ip() const { return _ip; }
00052   /** Returns the latitude coordinate for this IP. */
00053   float latitude() const { return _latitude; }
00054   /** Returns the longitude coordinate for this IP. */
00055   float longitude() const { return _longitude; }
00056   /** Returns the city in which this IP lives. */
00057   QString city() const { return _city; }
00058   /** Returns the state or district in which this IP lives. */
00059   QString state() const { return _state; }
00060   /** Returns the country in which this IP lives. */
00061   QString country() const { return _country; }
00062   /** Returns a human-readable string of city, region(state), and country. */
00063   QString toLocation() const;
00064 
00065   /** Returns true if the GeoIp object is invalid. */
00066   bool isEmpty() const;
00067 
00068 private:
00069   QHostAddress _ip; /**< IP address for this location. */
00070   float _latitude;  /**< Latitudinal coordinate for this IP's location. */
00071   float _longitude; /**< Longitudinal coordinate for this IP's location. */
00072   QString _city;    /**< City in which this IP lives. */
00073   QString _state;   /**< State or district in which this IP lives. */
00074   QString _country; /**< Country in which this IP lives. */
00075 };
00076 
00077 #endif
00078 

Generated on Mon Oct 23 20:08:15 2006 for Vidalia by  doxygen 1.5.0