| 1 |
/* |
| 2 |
* Copyright (C) 2015-2016 Canonical Ltd. |
| 3 |
* |
| 4 |
* This file is part of Lomiri Weather App |
| 5 |
* |
| 6 |
* Lomiri Weather App is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License version 3 as |
| 8 |
* published by the Free Software Foundation. |
| 9 |
* |
| 10 |
* Lomiri Weather App is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
import QtQuick 2.12 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import "../../components" |
| 22 |
|
| 23 |
Item { |
| 24 |
id: dataProviderPage |
| 25 |
height: dataProviderSetting.height |
| 26 |
|
| 27 |
ListModel { |
| 28 |
id: dataProviderModel |
| 29 |
function initialize() { |
| 30 |
// TRANSLATORS: name of the weather data service provider, only translate if needed |
| 31 |
dataProviderModel.append({"text": i18n.tr("Open-Meteo"), "value": "openmeteo"}) |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
OptionSelector { |
| 36 |
id: dataProviderSetting |
| 37 |
text: i18n.tr("Data Provider") |
| 38 |
model: dataProviderModel |
| 39 |
containerHeight: itemHeight * dataProviderModel.count |
| 40 |
delegate: OptionSelectorDelegate { |
| 41 |
text: model.text |
| 42 |
height: units.gu(4) |
| 43 |
} |
| 44 |
onDelegateClicked: { |
| 45 |
settings.service = model.get(index).value |
| 46 |
refreshData(true); |
| 47 |
} |
| 48 |
} |
| 49 |
Component.onCompleted: { |
| 50 |
/* |
| 51 |
The Component.onCompleted of the OptionSelector finishes BEFORE |
| 52 |
the onCompleted events of the delegates or the model. |
| 53 |
That is why the initialize() needs to be called here rather than |
| 54 |
in the Component.onCompleted of the ListModel. |
| 55 |
*/ |
| 56 |
dataProviderModel.initialize() |
| 57 |
for (var i = 0; i < dataProviderModel.count; ++i) { |
| 58 |
if (dataProviderModel.get(i).value === settings.service) { |
| 59 |
dataProviderSetting.selectedIndex = i |
| 60 |
return |
| 61 |
} |
| 62 |
} |
| 63 |
dataProviderSetting.selectedIndex = 0 // in case no match is found due to broken settings |
| 64 |
} |
| 65 |
|
| 66 |
// Component.onCompleted: { |
| 67 |
// // If the key file for TWC is not blank, add the service to the model |
| 68 |
// if (!!Keys.twcKey) { |
| 69 |
// dataProviderModel.append({ text: "The Weather Channel" }) |
| 70 |
// } |
| 71 |
// } |
| 72 |
} |