source: calamares/trunk/fuentes/src/modules/locale/GeoIPXML.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 17 months ago

sync with github

File size: 1.9 KB
Line 
1/* === This file is part of Calamares - <http://github.com/calamares> ===
2 *
3 *   Copyright 2018, Adriaan de Groot <groot@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "GeoIPXML.h"
20
21#include "utils/Logger.h"
22
23#include <QNetworkReply>
24#include <QtXml/QDomDocument>
25
26GeoIPXML::GeoIPXML( const QString& element )
27    : GeoIP( element.isEmpty() ? QLatin1String( "TimeZone" ) : element )
28{
29}
30
31GeoIP::RegionZonePair
32GeoIPXML::processReply( const QByteArray& data )
33{
34    QString domError;
35    int errorLine, errorColumn;
36
37    QDomDocument doc;
38    if ( doc.setContent( data, false, &domError, &errorLine, &errorColumn ) )
39    {
40        const auto tzElements = doc.elementsByTagName( m_element );
41        cDebug() << "GeoIP found" << tzElements.length() << "elements";
42        for ( int it = 0; it < tzElements.length(); ++it )
43        {
44            auto e = tzElements.at(it).toElement();
45            auto tz = splitTZString( e.text() );
46            if ( !tz.first.isEmpty() )
47                return tz;
48        }
49
50        // None of them valid
51        cWarning() << "GeopIP XML had no recognizable timezone";
52        return qMakePair( QString(), QString() );
53    }
54    else
55    {
56        cWarning() << "GeoIP XML data error:" << domError << "(line" << errorLine << errorColumn << ')';
57    }
58
59    return qMakePair( QString(), QString() );
60}
Note: See TracBrowser for help on using the repository browser.