Warning, /plasma-bigscreen/calamares-bigscreen-branding/bigscreen/Map.qml is written in an unsupported language. File is not indexed.
0001 /* === This file is part of Calamares - <https://calamares.io> ===
0002 *
0003 * SPDX-FileCopyrightText: 2020 Anke Boersma <demm@kaosx.us>
0004 * SPDX-License-Identifier: GPL-3.0-or-later
0005 *
0006 * Calamares is Free Software: see the License-Identifier above.
0007 *
0008 */
0009
0010 import QtQuick 2.10
0011 import QtQuick.Controls 2.10
0012 import QtQuick.Window 2.14
0013 import QtQuick.Layouts 1.3
0014
0015 import org.kde.kirigami 2.7 as Kirigami
0016
0017 import QtLocation 5.14
0018 import QtPositioning 5.14
0019
0020 Column {
0021 width: parent.width
0022
0023 // These are used by the map query to initially center the
0024 // map on the user's likely location. They are updated by
0025 // getIp() which does a more accurate GeoIP lookup than
0026 // the default one in Calamares
0027 property var cityName: ""
0028 property var countryName: ""
0029
0030 /* This is an extra GeoIP lookup, which will find better-accuracy
0031 * location data for the user's IP, and then sets the current timezone
0032 * and map location. Call it from Component.onCompleted so that
0033 * it happens "on time" before the page is shown.
0034 */
0035 function getIpOnline() {
0036 var xhr = new XMLHttpRequest
0037
0038 xhr.onreadystatechange = function() {
0039 if (xhr.readyState === XMLHttpRequest.DONE) {
0040 var responseJSON = JSON.parse(xhr.responseText)
0041 var tz = responseJSON.timezone
0042 var ct = responseJSON.city
0043 var cy = responseJSON.country
0044
0045 cityName = ct
0046 countryName = cy
0047
0048 config.setCurrentLocation(tz)
0049 }
0050 }
0051
0052 // Define the target of the request
0053 xhr.open("GET", "https://get.geojs.io/v1/ip/geo.json")
0054 // Execute the request
0055 xhr.send()
0056 }
0057
0058 /* This is an "offline" GeoIP lookup -- it just follows what
0059 * Calamares itself has figured out with its GeoIP or configuration.
0060 * Call it from the **Component** onActivate() -- in localeq.qml --
0061 * so it happens as the page is shown.
0062 */
0063 function getIpOffline() {
0064 cityName = config.currentLocation.zone
0065 countryName = config.currentLocation.countryCode
0066 }
0067
0068 /* This is an **accurate** TZ lookup method: it queries an
0069 * online service for the TZ at the given coordinates. It
0070 * requires an internet connection, though, and the distribution
0071 * will need to have an account with geonames to not hit the
0072 * daily query limit.
0073 *
0074 * See below, in MouseArea, for calling the right method.
0075 */
0076 function getTzOnline() {
0077 var xhr = new XMLHttpRequest
0078 var latC = map.center.latitude
0079 var lonC = map.center.longitude
0080
0081 xhr.onreadystatechange = function() {
0082 if (xhr.readyState === XMLHttpRequest.DONE) {
0083 var responseJSON = JSON.parse(xhr.responseText)
0084 var tz2 = responseJSON.timezoneId
0085
0086 config.setCurrentLocation(tz2)
0087 }
0088 }
0089
0090 console.log("Online lookup", latC, lonC)
0091 // Needs to move to localeq.conf, each distribution will need their own account
0092 xhr.open("GET", "http://api.geonames.org/timezoneJSON?lat=" + latC + "&lng=" + lonC + "&username=SOME_USERNAME")
0093 xhr.send()
0094 }
0095
0096 /* This is a quick TZ lookup method: it uses the existing
0097 * Calamares "closest TZ" code, which has lots of caveats.
0098 *
0099 * See below, in MouseArea, for calling the right method.
0100 */
0101 function getTzOffline() {
0102 var latC = map.center.latitude
0103 var lonC = map.center.longitude
0104 var tz = config.zonesModel.lookup(latC, lonC)
0105 console.log("Offline lookup", latC, lonC)
0106 config.setCurrentLocation(tz.region, tz.zone)
0107 }
0108
0109 Rectangle {
0110 width: parent.width
0111 height: parent.height / 1.28
0112
0113 Plugin {
0114 id: mapPlugin
0115 name: "esri" // "esri", "here", "itemsoverlay", "mapbox", "mapboxgl", "osm"
0116 }
0117
0118 Map {
0119 id: map
0120 anchors.fill: parent
0121 plugin: mapPlugin
0122 activeMapType: supportedMapTypes[0]
0123 //might be desirable to set zoom level configurable?
0124 zoomLevel: 5
0125 bearing: 0
0126 tilt: 0
0127 copyrightsVisible : true
0128 fieldOfView : 0
0129
0130 GeocodeModel {
0131 id: geocodeModel
0132 plugin: mapPlugin
0133 autoUpdate: true
0134 query: Address {
0135 id: address
0136 city: cityName
0137 country: countryName
0138 }
0139
0140 onLocationsChanged: {
0141 if (count == 1) {
0142 map.center.latitude = get(0).coordinate.latitude
0143 map.center.longitude = get(0).coordinate.longitude
0144 }
0145 }
0146 }
0147
0148 MapQuickItem {
0149 id: marker
0150 anchorPoint.x: image.width/4
0151 anchorPoint.y: image.height
0152 coordinate: QtPositioning.coordinate(
0153 map.center.latitude,
0154 map.center.longitude)
0155 //coordinate: QtPositioning.coordinate(40.730610, -73.935242) // New York
0156
0157 sourceItem: Image {
0158 id: image
0159 width: 32
0160 height: 32
0161 source: "img/pin.svg"
0162 }
0163 }
0164
0165 MouseArea {
0166 acceptedButtons: Qt.LeftButton
0167 anchors.fill: map
0168 hoverEnabled: true
0169 property var coordinate: map.toCoordinate(Qt.point(mouseX, mouseY))
0170 Label {
0171 x: parent.mouseX - width -5
0172 y: parent.mouseY - height - 5
0173 text: "%1, %2".arg(
0174 parent.coordinate.latitude).arg(parent.coordinate.longitude)
0175 }
0176
0177 onClicked: {
0178 marker.coordinate = coordinate
0179 map.center.latitude = coordinate.latitude
0180 map.center.longitude = coordinate.longitude
0181
0182 // Pick a TZ lookup method here (quick:offline, accurate:online)
0183 getTzOffline();
0184 }
0185 }
0186 }
0187
0188 Column {
0189 anchors.bottom: parent.bottom
0190 anchors.right: parent.right
0191 anchors.bottomMargin: 5
0192 anchors.rightMargin: 10
0193
0194 MouseArea {
0195 width: 32
0196 height:32
0197 cursorShape: Qt.PointingHandCursor
0198 Image {
0199 source: "img/plus.png"
0200 anchors.centerIn: parent
0201 width: 36
0202 height: 36
0203 }
0204
0205 onClicked: map.zoomLevel++
0206 }
0207
0208 MouseArea {
0209 width: 32
0210 height:32
0211 cursorShape: Qt.PointingHandCursor
0212 Image {
0213 source: "img/minus.png"
0214 anchors.centerIn: parent
0215 width: 32
0216 height: 32
0217 }
0218
0219 onClicked: map.zoomLevel--
0220 }
0221 }
0222 }
0223
0224 Rectangle {
0225 width: parent.width
0226 height: 100
0227 anchors.horizontalCenter: parent.horizontalCenter
0228
0229 Item {
0230 id: location
0231 Kirigami.Theme.inherit: false
0232 Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
0233 anchors.horizontalCenter: parent.horizontalCenter
0234
0235 Rectangle {
0236 anchors.centerIn: parent
0237 width: 300
0238 height: 30
0239 color: Kirigami.Theme.backgroundColor
0240
0241 Text {
0242 id: tzText
0243 text: qsTr("Timezone: %1").arg(config.currentTimezoneName)
0244 color: Kirigami.Theme.textColor
0245 anchors.centerIn: parent
0246 }
0247
0248 /* If you want an extra (and accurate) GeoIP lookup,
0249 * enable this one and disable the offline lookup in
0250 * onActivate().
0251 Component.onCompleted: getIpOnline();
0252 */
0253 }
0254 }
0255
0256 Text {
0257 anchors.top: location.bottom
0258 anchors.topMargin: 20
0259 padding: 10
0260 width: parent.width
0261 wrapMode: Text.WordWrap
0262 horizontalAlignment: Text.AlignHCenter
0263 Kirigami.Theme.backgroundColor: Kirigami.Theme.backgroundColor
0264 text: qsTr("Please select your preferred location on the map so the installer can suggest the locale
0265 and timezone settings for you. You can fine-tune the suggested settings below. Search the map by dragging
0266 to move and using the +/- buttons to zoom in/out or use mouse scrolling for zooming.")
0267 }
0268 }
0269 }