summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan de Groot <groot@kde.org>2019-05-09 15:15:03 -0400
committerAdriaan de Groot <groot@kde.org>2019-05-09 15:15:03 -0400
commitcb7c38dabac4dba625a081cfa7d21cec66694df5 (patch)
treef901bfa5a704981a347f6e051f3da08f73583b53
parent44559d24bdfeb4391332f3d8814f172f777d2b72 (diff)
[welcome] Support GeoIP country lookup
-rw-r--r--src/modules/welcome/WelcomeViewStep.cpp22
-rw-r--r--src/modules/welcome/welcome.conf13
2 files changed, 35 insertions, 0 deletions
diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp
index d1c2cc840..91745967e 100644
--- a/src/modules/welcome/WelcomeViewStep.cpp
+++ b/src/modules/welcome/WelcomeViewStep.cpp
@@ -22,10 +22,12 @@
#include "WelcomePage.h"
#include "checker/GeneralRequirements.h"
+#include "geoip/Handler.h"
#include "modulesystem/ModuleManager.h"
#include "utils/Logger.h"
#include "utils/Variant.h"
+#include <QFutureWatcher>
#include <QVariant>
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin<WelcomeViewStep>(); )
@@ -112,6 +114,26 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
else
cWarning() << "no valid requirements map found in welcome "
"module configuration.";
+
+ bool ok = false;
+ QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
+ if ( ok )
+ {
+ using FWString = QFutureWatcher< QString >;
+
+ auto* handler = new CalamaresUtils::GeoIP::Handler(
+ CalamaresUtils::getString( geoip, "style" ),
+ CalamaresUtils::getString( geoip, "url" ),
+ CalamaresUtils::getString( geoip, "selector" ) );
+ auto* future = new FWString();
+ connect( future, &FWString::finished, [f=future, h=handler]()
+ {
+ cDebug() << "GeoIP result for welcome=" << f->future().result();
+ f->deleteLater();
+ delete h;
+ } );
+ future->setFuture( handler->queryRaw() );
+ }
}
Calamares::RequirementsList WelcomeViewStep::checkRequirements()
diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf
index 52492ffef..fcef45a59 100644
--- a/src/modules/welcome/welcome.conf
+++ b/src/modules/welcome/welcome.conf
@@ -47,3 +47,16 @@ requirements:
# - storage
- ram
# - root
+
+# GeoIP checking
+#
+# This can be used to pre-select a language based on the country
+# the user is currently in. It *assumes* that there's internet
+# connectivity, though. Configuration is like in the locale module,
+# but remember to use a URL that returns full data **and** to
+# use a selector that will pick the country, not the timezone.
+
+geoip:
+ style: "xml"
+ url: "https://geoip.kde.org/v1/ubiquity" # extended XML format
+ selector: "CountryCode" # blank uses default, which is wrong