2
* Copyright (C) 2014 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 Qt.labs.folderlistmodel 2.1
19
import SystemSettings 1.0
20
import Ubuntu.Components 1.1
21
import Ubuntu.SystemSettings.SecurityPrivacy 1.0
24
title: i18n.tr("Nokia HERE")
27
UbuntuSecurityPrivacyPanel {
33
folder: securityPrivacy.hereLicensePath
34
nameFilters: ["*.html"]
36
showOnlyReadable: true
37
onCountChanged: loadFileContent()
40
function makeFileName(lang, country) {
41
return lang + "_" + country + ".html"
44
function defaultCountryForLanguage(lang) {
45
if (lang === "da") return "DK"
46
if (lang === "en") return "US"
47
if (lang === "ko") return "KR"
48
if (lang === "zh") return "CN"
49
return lang.toUpperCase()
52
function determineFileName() {
53
var codes = i18n.language.split(".")[0].split("_")
54
var defaultCountry = defaultCountryForLanguage(codes[0])
55
if (codes.count === 1)
56
codes = [codes[0], defaultCountry]
57
var perfectMatch = makeFileName(codes[0], codes[1])
58
var nearMatch = makeFileName(codes[0], defaultCountry)
59
var nearMatchExists = false
61
for (var i = 0; i < termsModel.count; i++) {
62
var fileName = termsModel.get(i, "fileName")
63
if (fileName == perfectMatch) {
65
} else if (fileName == nearMatch) {
66
nearMatchExists = true
70
if (nearMatchExists) {
73
return makeFileName("en", "US")
77
function loadFileContent() {
78
var xhr = new XMLHttpRequest
79
xhr.open("GET", securityPrivacy.hereLicensePath + "/" + determineFileName())
80
console.warn('opening', securityPrivacy.hereLicensePath + "/" + determineFileName())
81
xhr.onreadystatechange = function() {
82
if (xhr.readyState == XMLHttpRequest.DONE) {
83
termsLabel.text = xhr.responseText
91
contentHeight: contentItem.childrenRect.height
92
boundsBehavior: (contentHeight > termsPage.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
93
/* Set the direction to workaround https://bugreports.qt-project.org/browse/QTBUG-31905
94
otherwise the UI might end up in a situation where scrolling doesn't work */
95
flickableDirection: Flickable.VerticalFlick
98
width: scrollWidget.width
116
linkColor: Theme.palette.normal.backgroundText
118
Qt.openUrlExternally(link)