Ubuntu Pastebin

Paste from sdgs at Tue, 11 Oct 2016 19:01:46 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import QtQuick 2.4
import Ubuntu.Components 1.3

Page {
    id: settingsPage

    property variant currentData: undefined;
    property variant forecastData: undefined;

    Component.onCompleted: console.debug("Location: ", mainView.location)

    function requestWeaCity () {
        var request = new XMLHttpRequest ();
        request.onreadystatechange = function () {
            if (request.readyState == XMLHttpRequest.DONE) {
                if (request.status == 200) {
                    currentData = JSON.parse (request.responseText);
                    print("have search results", currentData["list"].length);
                    for (var i = 0; i < currentData["list"].length; i++) {
                        var entry = currentData["list"][i]
                        print("have search result entry:", entry["id"], entry["name"], entry["weather"][0]["main"])
                        locationModel.append( { id: entry["id"], name: entry["name"], weather: entry["weather"][0]["main"] } )
                        //locationModel.append( { name: entry["name"] } )
                    }
                } else {
                    console.log ("HTTP request failed", request.status);
                }
            }
        }
        print("Have query:", "http://api.openweathermap.org/data/2.5/find?q=" + searchLocation.displayText + "&appid=753a953085551461ddf5555c772c06c2")
        request.open ("GET", "http://api.openweathermap.org/data/2.5/forecast?q=" + searchLocation.displayText + "&appid=753a953085551461ddf5555c772c06c2");
        request.send ();
    }

    header: PageHeader {
        id: pageHeader
        title: i18n.tr("Settings")
        StyleHints {
            foregroundColor: "white"
            backgroundColor: UbuntuColors.inkstone
            dividerColor: UbuntuColors.silk
        }
        trailingActionBar.actions: []
    }

    Column {
        anchors {
            fill: parent
            top: settingsPage.bottom
            topMargin: units.gu(6)
        }

        ListItem {
            ListItemLayout {
                Label {
                    text: i18n.tr("Select your location then push the back button")
                }
            }
        }

        ListItem {
            ListItemLayout {
                focus: true
                TextField { id: searchLocation; placeholderText: "Search by City or Zip Code" }
                    Keys.onEnterPressed: { requestWeaCity() }

                Button { text: "Enter"
                    onClicked: requestWeaCity() }
            }
        }
        Repeater {
            model: ListModel {
                id: locationModel
                property int selectedIndex: -1
            }
            ListItem {
                ListItemLayout {
                    title.text: model.name + " " + model.weather
                }
                onClicked: {
                    print("user clicked on", model.id, model.name, model.weather)
                    mainView.location = model
                }
            }
        }
    }
}
Download as text