Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<entry name="widgetIconSize" type="int">
<default>0</default>
</entry>
<entry name="thunderforestAPIKey" type="String">
<default></default>
</entry>
<entry name="showFlagInCompact" type="Bool">
<default>true</default>
</entry>
Expand Down Expand Up @@ -42,6 +45,9 @@
</group>

<group name="Appearance">
<entry name="mapSize" type="int">
<default>200</default>
</entry>
<entry name="mapZoomLevel" type="int">
<default>13</default>
</entry>
Expand Down
216 changes: 145 additions & 71 deletions package/contents/ui/FullRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ import org.kde.plasma.plasmoid
import org.kde.plasma.core as PlasmaCore
import org.kde.plasma.components as PlasmaComponents

import QtLocation
import QtPositioning


Item {
readonly property int mapSize: Plasmoid.configuration.mapSize
readonly property int mapZoomLevel: Plasmoid.configuration.mapZoomLevel
readonly property bool layoutRow: Plasmoid.configuration.layoutRow
readonly property bool showHostname: Plasmoid.configuration.showHostname
Expand All @@ -34,103 +38,173 @@ Item {
readonly property bool useLinkThemeColor: Plasmoid.configuration.useLinkThemeColor
readonly property string linkColor: Plasmoid.configuration.linkColor

readonly property string thunderforestAPIKey: Plasmoid.configuration.thunderforestAPIKey

property string mapLink: "https://www.openstreetmap.org/?mlat=" + latitude + "&mlon=" + longitude + "#map=" + mapZoomLevel + "/" + latitude + "/" + longitude

id: fullRoot
// Automatically adapt to the GridLayout’s implicit size
width: labelsContainer.implicitWidth
height: labelsContainer.implicitHeight
Layout.preferredWidth: labelsContainer.implicitWidth
Layout.preferredHeight: labelsContainer.implicitHeight

function addMarker(latitude, longitude) {
debug_print("addMarker init")
var component = Qt.createComponent("Marker.qml")
if( component.status != Component.Ready )
{
if( component.status == Component.Error )
debug_print("Error creating Marker:"+ component.errorString() );
return; // or maybe throw
}
// removing previous markers
my_map.clearMapItems()
var item = component.createObject(
grid, {
coordinate: QtPositioning.coordinate(latitude, longitude)
})
my_map.addMapItem(item)
debug_print("Added Marker: lat=" + latitude + "; long=" + longitude)
}

GridLayout {
id: labelsContainer
flow: GridLayout.LeftToRight
columns: 2
id: grid
rowSpacing: 10
columnSpacing: 10
flow: layoutRow ? GridLayout.LeftToRight : GridLayout.TopToBottom

Item {
width: mapSize
height: width
Layout.alignment: layoutRow ? Qt.AlignLeft : Qt.AlignHCenter

Plugin {
id: mapPlugin
name: "osm" // "mapboxgl", "esri", ...

PluginParameter {
name: "osm.mapping.custom.host";
value: {
// catch the case that there is no proper API key
if( thunderforestAPIKey.length === 0 )
return "https://tile.thunderforest.com/atlas/%z/%x/%y.png"
else
return "https://tile.thunderforest.com/atlas/%z/%x/%y.png?apikey=" + thunderforestAPIKey
}
}

QtControls.Label {
text: i18n("IP address:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}
}

LabelDelegate {
text: jsonData !== undefined && jsonData.ip ? jsonData.ip : "N/A"
Map {
id: my_map
anchors.fill: parent
plugin: mapPlugin
center: {
if (jsonData !== undefined) {
addMarker(latitude, longitude)
return QtPositioning.coordinate(latitude, longitude)
}
addMarker(41.8902, 12.4922)
return QtPositioning.coordinate(41.8902, 12.4922) // Rome
}
activeMapType: my_map.supportedMapTypes[my_map.supportedMapTypes.length - 1]

zoomLevel: mapZoomLevel
}
}

QtControls.Label {
text: i18n("Country:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}
GridLayout {
id: labelsContainer
flow: GridLayout.LeftToRight
columns: 2

LabelDelegate {
text: jsonData !== undefined && jsonData.country ? jsonData.country : "N/A"
}
QtControls.Label {
text: i18n("IP address:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}

QtControls.Label {
text: i18n("Region:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}
LabelDelegate {
text: jsonData !== undefined && jsonData.ip ? jsonData.ip : "N/A"
}

LabelDelegate {
text: jsonData !== undefined && jsonData.region ? jsonData.region : "N/A"
}
QtControls.Label {
text: i18n("Country:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}

QtControls.Label {
text: i18n("Postal Code:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}
LabelDelegate {
text: jsonData !== undefined && jsonData.country ? jsonData.country : "N/A"
}

LabelDelegate {
text: jsonData !== undefined && jsonData.postal ? jsonData.postal : "N/A"
}
QtControls.Label {
text: i18n("Region:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}

QtControls.Label {
text: i18n("City:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}
LabelDelegate {
text: jsonData !== undefined && jsonData.region ? jsonData.region : "N/A"
}

LabelDelegate {
text: jsonData !== undefined && jsonData.city ? jsonData.city : "N/A"
}
QtControls.Label {
text: i18n("Postal Code:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}

QtControls.Label {
text: i18n("Coordinates:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}
LabelDelegate {
text: jsonData !== undefined && jsonData.postal ? jsonData.postal : "N/A"
}

LabelDelegate {
text: jsonData !== undefined && jsonData.loc ? jsonData.loc : "N/A"
}
QtControls.Label {
text: i18n("City:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}

QtControls.Label {
text: i18n("Hostname:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
visible: showHostname
}
LabelDelegate {
text: jsonData !== undefined && jsonData.city ? jsonData.city : "N/A"
}

LabelDelegate {
text: jsonData !== undefined && jsonData.hostname ? jsonData.hostname : "N/A"
visible: showHostname
}
QtControls.Label {
text: i18n("Coordinates:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
}

QtControls.Button {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: parent.width
text: jsonData !== undefined ? i18n("Open map in the browser") : "N/A"
visible: jsonData !== undefined
onClicked: {
let mapLink = "https://www.openstreetmap.org/?mlat=" + latitude + "&mlon=" + longitude + "#map=" + mapZoomLevel + "/" + latitude + "/" + longitude
debug_print("[showMap onClicked] " + mapLink)
Qt.openUrlExternally(mapLink)
LabelDelegate {
text: jsonData !== undefined && jsonData.loc ? jsonData.loc : "N/A"
}

QtControls.Label {
text: i18n("Hostname:")
color: useLabelThemeColor ? Kirigami.Theme.textColor : labelColor
visible: showHostname
}

LabelDelegate {
text: jsonData !== undefined && jsonData.hostname ? jsonData.hostname : "N/A"
visible: showHostname
}

QtControls.Button {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: parent.width
text: jsonData !== undefined ? i18n("Open map in the browser") : "N/A"
visible: jsonData !== undefined
onClicked: {
debug_print("[showMap onClicked] " + mapLink)
Qt.openUrlExternally(mapLink)
}
}
}

QtControls.Button {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: parent.width
text: i18n("Update")
onClicked: {
root._triggerReloadOnClick()
QtControls.Button {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: parent.width
text: i18n("Update")
onClicked: {
debug_print("[button onClicked]")
root._triggerReloadOnClick()
}
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions package/contents/ui/Marker.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import QtQuick 2.2
import QtLocation

MapQuickItem{
id: marker
anchorPoint.x: marker.width / 4
anchorPoint.y: marker.height
z: my_map.z + 1
sourceItem: Image{
id: icon
source: "../icons/marker.png"
sourceSize.width: 40
sourceSize.height: 40
}
}
14 changes: 14 additions & 0 deletions package/contents/ui/config/configGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ KCM.SimpleKCM {
property alias cfg_sendNotifOnIPChange: sendNotificationOnIpChange.checked
property alias cfg_triggerFile: triggerFileEdit.text

property alias cfg_thunderforestAPIKey: thunderforestAPIKeyEdit.text

Kirigami.FormLayout {

QtControls.SpinBox {
Expand All @@ -61,6 +63,18 @@ KCM.SimpleKCM {
Layout.fillHeight: true
}

QtControls.TextField {
id: thunderforestAPIKeyEdit
Kirigami.FormData.label: "Thunderforest API key\n(https://www.thunderforest.com/):"
width: 300
focus: false
selectByMouse: true
}

Item { // tighten layout
Layout.fillHeight: true
}

QtControls.ComboBox {
id: widgetIconSizeCombo
Kirigami.FormData.label: i18n("Icon size:")
Expand Down