generalinfotip.cpp
1 //------------------------------------------------------------------------------
2 // generalinfotip.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "generalinfotip.h"
24 
25 #include "ip2c/ip2c.h"
26 #include "serverapi/server.h"
27 
28 DClass<GeneralInfoTip>
29 {
30  public:
31  ServerCPtr server;
32 };
33 
34 DPointered(GeneralInfoTip)
35 
36 GeneralInfoTip::GeneralInfoTip(const ServerCPtr &server)
37 {
38  d->server = server;
39 }
40 
41 GeneralInfoTip::~GeneralInfoTip()
42 {
43 }
44 
45 QString GeneralInfoTip::generateHTML()
46 {
47  QString ret;
48  if (d->server->isKnown())
49  {
50  ret += QString(d->server->name()).replace('>', "&gt;").replace('<', "&lt;") + "\n";
51  ret += labelString(tr("Version"), d->server->gameVersion());
52  ret += labelString(tr("E-mail"), d->server->email());
53  ret += labelString(tr("URL"), d->server->webSite());
54  }
55 
56  IP2CCountryInfo countryInfo = IP2C::instance()->obtainCountryInfo(d->server->address());
57 
58  if (countryInfo.isValid())
59  {
60  if (!ret.isEmpty())
61  {
62  ret += "\n";
63  }
64 
65  ret += tr("Location: %1\n").arg(countryInfo.name);
66  }
67 
68  return ret;
69 }
70 
71 QString GeneralInfoTip::labelString(QString label, QString valueString)
72 {
73  if (valueString.isEmpty())
74  {
75  return QString();
76  }
77  else
78  {
79  return label + ": " + valueString + "\n";
80  }
81 }
IP2CCountryInfo obtainCountryInfo(unsigned int ipaddress)
Definition: ip2c.cpp:152
Flag and name of the country.