Vidalia 0.3.1
GeoIpRecord.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file GeoIpRecord.cpp
13** \brief Associates an IP with a geographic location
14*/
15
16#include "GeoIpRecord.h"
17
18#include <QStringList>
19
20/** Verifies a latitude is between -90.0 and 90.0 degrees. */
21#define IS_VALID_LATITUDE(x) (((x) >= -90.0) && ((x) <= 90.0))
22/** Verifies a longitude is between -180.0 and 180.0 degrees. */
23#define IS_VALID_LONGITUDE(x) (((x) >= -180.0) && ((x) <= 180.0))
24
25
27{
28 _latitude = 0.0;
29 _longitude = 0.0;
30}
31
32GeoIpRecord::GeoIpRecord(const QHostAddress &ip, float latitude, float longitude,
33 const QString &country, const QString &countryCode)
34{
35 _ip = ip;
40}
41
42GeoIpRecord::GeoIpRecord(const QHostAddress &ip, float latitude, float longitude,
43 const QString &city, const QString &region,
44 const QString &country, const QString &countryCode)
45{
46 _ip = ip;
49 _city = city;
53}
54
55bool
57{
58 return (! _ip.isNull()
61}
62
63QString
65{
66 QStringList location;
67
68 /* Add the city name (if present) */
69 if (!_city.isEmpty())
70 location << _city;
71
72 /* Add the full state or region name (if present) */
73 if (!_region.isEmpty() && _region != _city)
74 location << _region;
75
76 /* Add the country name or the country code (if present) */
77 if (!_country.isEmpty())
78 location << _country;
79 else if (!_countryCode.isEmpty())
80 location << _countryCode;
81
82 return location.join(", ");
83}
84
#define IS_VALID_LATITUDE(x)
Definition: GeoIpRecord.cpp:21
#define IS_VALID_LONGITUDE(x)
Definition: GeoIpRecord.cpp:23
QString region() const
Definition: GeoIpRecord.h:64
float longitude() const
Definition: GeoIpRecord.h:54
QString city() const
Definition: GeoIpRecord.h:59
QString _city
Definition: GeoIpRecord.h:93
float _longitude
Definition: GeoIpRecord.h:92
float _latitude
Definition: GeoIpRecord.h:91
QString country() const
Definition: GeoIpRecord.h:69
QString countryCode() const
Definition: GeoIpRecord.h:75
QString toString() const
Definition: GeoIpRecord.cpp:64
QString _country
Definition: GeoIpRecord.h:95
QHostAddress _ip
Definition: GeoIpRecord.h:90
QString _region
Definition: GeoIpRecord.h:94
QHostAddress ip() const
Definition: GeoIpRecord.h:44
QString _countryCode
Definition: GeoIpRecord.h:96
float latitude() const
Definition: GeoIpRecord.h:49
bool isValid() const
Definition: GeoIpRecord.cpp:56