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 | #ifndef GEOIP_H |
---|
20 | #define GEOIP_H |
---|
21 | |
---|
22 | #include <QPair> |
---|
23 | #include <QString> |
---|
24 | #include <QUrl> |
---|
25 | |
---|
26 | class QByteArray; |
---|
27 | |
---|
28 | /** |
---|
29 | * @brief Interface for GeoIP retrievers. |
---|
30 | * |
---|
31 | * A GeoIP retriever takes a configured URL (from the config file) |
---|
32 | * and can handle the data returned from its interpretation of that |
---|
33 | * configured URL, returning a region and zone. |
---|
34 | */ |
---|
35 | class GeoIP |
---|
36 | { |
---|
37 | public: |
---|
38 | using RegionZonePair = QPair<QString, QString>; |
---|
39 | |
---|
40 | virtual ~GeoIP(); |
---|
41 | |
---|
42 | /** @brief Handle a (successful) request by interpreting the data. |
---|
43 | * |
---|
44 | * Should return a ( <zone>, <region> ) pair, e.g. |
---|
45 | * ( "Europe", "Amsterdam" ). This is called **only** if the |
---|
46 | * request to the fullUrl was successful; the handler |
---|
47 | * is free to read as much, or as little, data as it |
---|
48 | * likes. On error, returns a RegionZonePair with empty |
---|
49 | * strings (e.g. ( "", "" ) ). |
---|
50 | */ |
---|
51 | virtual RegionZonePair processReply( const QByteArray& ) = 0; |
---|
52 | |
---|
53 | /** @brief Splits a region/zone string into a pair. |
---|
54 | * |
---|
55 | * Cleans up the string by removing backslashes (\\) |
---|
56 | * since some providers return silly-escaped names. Replaces |
---|
57 | * spaces with _ since some providers return human-readable names. |
---|
58 | * Splits on the first / in the resulting string, or returns a |
---|
59 | * pair of empty QStrings if it can't. (e.g. America/North Dakota/Beulah |
---|
60 | * will return "America", "North_Dakota/Beulah"). |
---|
61 | */ |
---|
62 | static RegionZonePair splitTZString( const QString& s ); |
---|
63 | |
---|
64 | protected: |
---|
65 | GeoIP( const QString& e = QString() ); |
---|
66 | |
---|
67 | QString m_element; // string for selecting from data |
---|
68 | } ; |
---|
69 | |
---|
70 | #endif |
---|