on bbbdccd help sign in
unity8/qml/Wizard/Pages/here-terms.qml
121 lines 3.5 kB history raw
1/*
2 * Copyright (C) 2014,2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import AccountsService 0.1
19import Qt.labs.folderlistmodel 2.1
20import Ubuntu.Components 1.3
21import Ubuntu.Web 0.2
22import ".." as LocalComponents
24LocalComponents.Page {
25 objectName: "hereTermsPage"
27 title: i18n.tr("Terms & Conditions")
28 customBack: true
30 FolderListModel {
31 id: termsModel
32 folder: AccountsService.hereLicensePath
33 nameFilters: ["*.html"]
34 showDirs: false
35 showOnlyReadable: true
36 onCountChanged: loadFileContent()
37 }
39 function makeFileName(lang, country) {
40 return lang + "_" + country + ".html"
41 }
43 function defaultCountryForLanguage(lang) {
44 if (lang === "da") return "DK"
45 if (lang === "en") return "US"
46 if (lang === "ko") return "KR"
47 if (lang === "zh") return "CN"
48 return lang.toUpperCase()
49 }
51 function determineFileName() {
52 var codes = i18n.language.split(".")[0].split("_")
53 var defaultCountry = defaultCountryForLanguage(codes[0])
54 if (codes.count === 1)
55 codes = [codes[0], defaultCountry]
56 var perfectMatch = makeFileName(codes[0], codes[1])
57 var nearMatch = makeFileName(codes[0], defaultCountry)
58 var nearMatchExists = false
60 for (var i = 0; i < termsModel.count; i++) {
61 var fileName = termsModel.get(i, "fileName")
62 if (fileName == perfectMatch) {
63 return perfectMatch
64 } else if (fileName == nearMatch) {
65 nearMatchExists = true
66 }
67 }
69 if (nearMatchExists) {
70 return nearMatch
71 } else {
72 return makeFileName("en", "US")
73 }
74 }
76 function loadFileContent() {
77 var xhr = new XMLHttpRequest
78 xhr.open("GET", AccountsService.hereLicensePath + "/" + determineFileName())
79 xhr.onreadystatechange = function() {
80 if (xhr.readyState == XMLHttpRequest.DONE) {
81 termsLabel.text = xhr.responseText
82 }
83 }
84 xhr.send()
85 }
87 onBackClicked: {
88 if (webview.visible) {
89 termsLabel.visible = true
90 } else {
91 pageStack.prev()
92 }
93 }
95 Column {
96 id: column
97 anchors.fill: content
99 Label {
100 id: termsLabel
101 objectName: "termsLabel"
102 anchors.left: parent.left
103 anchors.right: parent.right
104 wrapMode: Text.Wrap
105 linkColor: theme.palette.normal.foregroundText
106 onLinkActivated: {
107 webview.url = link
108 termsLabel.visible = false
109 }
110 }
112 WebView {
113 id: webview
114 objectName: "webview"
115 anchors.left: parent.left
116 anchors.right: parent.right
117 height: parent.height
118 visible: !termsLabel.visible
119 }
120 }