@@ -26,28 +26,60 @@ LocalComponents.Page {
26 title: i18n.tr("Region")
26 title: i18n.tr("Region")
27 forwardButtonSourceComponent: forwardButton
27 forwardButtonSourceComponent: forwardButton
29− readonly property var preferedCountries: LocalePlugin.countriesForLanguage(root.language)
31 Component.onCompleted: {
29 Component.onCompleted: {
30+ if (!modemManager.available) { // don't wait for the modem if it's not there
38+ print("Modems changed")
46+ if (simManager0.present && simManager0.mobileCountryCode) {
47+ detectedCountry = LocalePlugin.mccToCountryCode(simManager0.mobileCountryCode)
48+ print("SIM 0 detected country:", detectedCountry)
49+ } else if (simManager1.present && simManager1.mobileCountryCode) {
50+ detectedCountry = LocalePlugin.mccToCountryCode(simManager1.mobileCountryCode)
51+ print("SIM 1 detected country:", detectedCountry)
52+ } else if (!detectedCountry) {
53+ detectedCountry = preferedCountry() // fallback to prefered country
54+ print("No SIM country detected, falling back to prefered country:", detectedCountry)
32− populateModel(preferedCountries);
57+ populateModel(detectedCountry)
60+ // return a prefered country for a language, but only if there's exactly one
61+ function preferedCountry()
63+ var countries = Object.keys(LocalePlugin.countriesForLanguage(root.language))
64+ if (countries.length === 1) {
67+ // TODO should we ultimately fallback to "US" here?
35− function populateModel(preferedCountries)
70+ function populateModel(preferedCountry)
37 var countries = LocalePlugin.countries();
72 var countries = LocalePlugin.countries();
74+ var selectedIndex = -1
38 //console.log("All countries:" + countries);
75 //console.log("All countries:" + countries);
76+ print("Prefered country", preferedCountry)
39 Object.keys(countries).map(function(code) { // prepare the object
77 Object.keys(countries).map(function(code) { // prepare the object
40 //console.log("Got country:" + code);
78 //console.log("Got country:" + code);
41− return { "code": code, "country": countries[code] || code,
79+ return { "code": code, "country": countries[code] || code };
42− "dept": Object.keys(preferedCountries).indexOf(code) !== -1 ? i18n.tr("Prefered") : i18n.tr("All") };
44− .sort(function(a, b) { // group by status, sort by country name
81+ .sort(function(a, b) { // sort by country name
45− if (a.dept === b.dept) {
46− return a.country.localeCompare(b.country);
82+ return a.country.localeCompare(b.country);
47− } else if (a.dept === i18n.tr("Prefered")) {
52 .forEach(function(country) { // build the model
84 .forEach(function(country) { // build the model
53 //console.debug("Adding country:" + country.code);
85 //console.debug("Adding country:" + country.code);
@@ -55,9 +87,18 @@ LocalComponents.Page {
57 model.append(country);
89 model.append(country);
90+ if (preferedCountry && country.code === preferedCountry) { // preselect the prefered country, if any
91+ selectedIndex = index;
92+ selectCountry(country.code, selectedIndex)
59 busyIndicator.running = false;
96 busyIndicator.running = false;
60 busyIndicator.visible = false;
97 busyIndicator.visible = false;
99+ if (selectedIndex !== -1) {
100+ regionsListView.positionViewAtIndex(selectedIndex, ListView.Center)
63 function selectCountry(code, index)
104 function selectCountry(code, index)