1// SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4import QtQuick.Controls 2.0
5import QtQuick 2.7
6import QtQuick.Layouts 1.1
7import "../../constants" 1.0
8import "../../modules/"
9import "../../modules/helpers"
10
11Menu {
12    id: locationsMenu
13    modal: true
14    transformOrigin: Menu.Center
15    padding: 0
16    property string locName
17    property bool isReadOnly
18    background: Rectangle {
19        implicitWidth: 200
20        color: Num.sysPalette.base
21        radius: 5
22    }
23
24    function openMenu(name) {
25        locName = name
26        isReadOnly = LocationDialogLite.isReadOnly(name)
27
28        open()
29    }
30
31    Column {
32        width: parent.width
33        spacing: 10
34
35        KSLabel {
36            id: name
37            text: locName
38            wrapMode: Label.WrapAtWordBoundaryOrAnywhere
39            width: parent.width
40            font.pointSize: 12
41            anchors {
42                left: parent.left
43                leftMargin: 10
44            }
45        }
46
47        Rectangle {
48            color: "grey"
49            width: parent.width - 10
50            height: 1
51            anchors {
52                horizontalCenter: parent.horizontalCenter
53            }
54        }
55    }
56
57    KSMenuItem {
58        text: xi18n("Set as my location")
59        onTriggered: {
60            if(LocationDialogLite.setLocation(locName)) {
61                skyMapLite.notification.showNotification(xi18n("Set %1 as the current location", locName))
62            } else {
63                skyMapLite.notification.showNotification(xi18n("Could not set as the current location", locName))
64            }
65            locationDialog.filterCities()
66        }
67    }
68
69    KSMenuItem {
70        text: isReadOnly ? xi18n("View") : xi18n("Edit")
71        onTriggered: {
72            if(isReadOnly) {
73                locationEdit.openEdit(locName, true)
74            } else {
75                locationEdit.openEdit(locName, false)
76            }
77        }
78    }
79
80    KSMenuItem {
81        enabled: !isReadOnly
82        text: xi18n("Delete")
83        onTriggered: {
84            LocationDialogLite.deleteCity(locName)
85            skyMapLite.notification.showNotification(xi18n("Deleted location %1", locName))
86            locationDialog.filterCities()
87        }
88    }
89}
90