Vidalia
0.3.1
src
vidalia
network
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
26
GeoIpRecord::GeoIpRecord
()
27
{
28
_latitude
= 0.0;
29
_longitude
= 0.0;
30
}
31
32
GeoIpRecord::GeoIpRecord
(
const
QHostAddress &ip,
float
latitude,
float
longitude,
33
const
QString &country,
const
QString &countryCode)
34
{
35
_ip
=
ip
;
36
_latitude
=
latitude
;
37
_longitude
=
longitude
;
38
_country
=
country
;
39
_countryCode
=
countryCode
;
40
}
41
42
GeoIpRecord::GeoIpRecord
(
const
QHostAddress &ip,
float
latitude,
float
longitude,
43
const
QString &city,
const
QString ®ion,
44
const
QString &country,
const
QString &countryCode)
45
{
46
_ip
=
ip
;
47
_latitude
=
latitude
;
48
_longitude
=
longitude
;
49
_city
=
city
;
50
_region
=
region
;
51
_country
=
country
;
52
_countryCode
=
countryCode
;
53
}
54
55
bool
56
GeoIpRecord::isValid
()
const
57
{
58
return
(!
_ip
.isNull()
59
&&
IS_VALID_LATITUDE
(
_latitude
)
60
&&
IS_VALID_LONGITUDE
(
_longitude
));
61
}
62
63
QString
64
GeoIpRecord::toString
()
const
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
GeoIpRecord::_latitude
float _latitude
Definition:
GeoIpRecord.h:91
IS_VALID_LONGITUDE
#define IS_VALID_LONGITUDE(x)
Definition:
GeoIpRecord.cpp:23
GeoIpRecord.h
GeoIpRecord::latitude
float latitude() const
Definition:
GeoIpRecord.h:49
GeoIpRecord::_ip
QHostAddress _ip
Definition:
GeoIpRecord.h:90
GeoIpRecord::longitude
float longitude() const
Definition:
GeoIpRecord.h:54
GeoIpRecord::ip
QHostAddress ip() const
Definition:
GeoIpRecord.h:44
IS_VALID_LATITUDE
#define IS_VALID_LATITUDE(x)
Definition:
GeoIpRecord.cpp:21
GeoIpRecord::GeoIpRecord
GeoIpRecord()
Definition:
GeoIpRecord.cpp:26
GeoIpRecord::_region
QString _region
Definition:
GeoIpRecord.h:94
GeoIpRecord::toString
QString toString() const
Definition:
GeoIpRecord.cpp:64
GeoIpRecord::countryCode
QString countryCode() const
Definition:
GeoIpRecord.h:75
GeoIpRecord::_longitude
float _longitude
Definition:
GeoIpRecord.h:92
GeoIpRecord::_countryCode
QString _countryCode
Definition:
GeoIpRecord.h:96
GeoIpRecord::country
QString country() const
Definition:
GeoIpRecord.h:69
GeoIpRecord::city
QString city() const
Definition:
GeoIpRecord.h:59
GeoIpRecord::_country
QString _country
Definition:
GeoIpRecord.h:95
GeoIpRecord::isValid
bool isValid() const
Definition:
GeoIpRecord.cpp:56
GeoIpRecord::region
QString region() const
Definition:
GeoIpRecord.h:64
GeoIpRecord::_city
QString _city
Definition:
GeoIpRecord.h:93
Generated by
1.8.17