2 * Copyright (C) 2014,2015 Canonical, Ltd.
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.
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.
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/>.
18 import AccountsService 0.1
19 import Qt.labs.folderlistmodel 2.1
20 import Ubuntu.Components 1.3
22 import ".." as LocalComponents
24 LocalComponents.Page {
25 objectName: "hereTermsPage"
27 title: i18n.tr("Terms & Conditions")
32 folder: AccountsService.hereLicensePath
33 nameFilters: ["*.html"]
35 showOnlyReadable: true
36 onCountChanged: loadFileContent()
39 function makeFileName(lang, country) {
40 return lang + "_" + country + ".html"
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()
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) {
64 } else if (fileName == nearMatch) {
65 nearMatchExists = true
69 if (nearMatchExists) {
72 return makeFileName("en", "US")
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
88 if (webview.visible) {
89 termsLabel.visible = true
101 objectName: "termsLabel"
102 anchors.left: parent.left
103 anchors.right: parent.right
105 linkColor: theme.palette.normal.foregroundText
108 termsLabel.visible = false
114 objectName: "webview"
115 anchors.left: parent.left
116 anchors.right: parent.right
117 height: parent.height
118 visible: !termsLabel.visible