Debian Codegraph @

src/app/qml/ui/settings/RefreshIntervalPage.qml

raw
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: refreshIntervalPage
25 height: refreshIntervalSetting.height
26
27 ListModel {
28 id: refreshModel
29 function initialize() {
30 refreshModel.append({"interval": 600, "text": i18n.tr("%1 minute", "%1 minutes", 10).arg(10)})
31 refreshModel.append({"interval": 900, "text": i18n.tr("%1 minute", "%1 minutes", 15).arg(15)})
32 refreshModel.append({"interval": 1800, "text": i18n.tr("%1 minute", "%1 minutes", 30).arg(30)})
33 refreshModel.append({"interval": 3600, "text": i18n.tr("%1 hour", "%1 hours", 1).arg(1)})
34 refreshModel.append({"interval": 7200, "text": i18n.tr("%1 hour", "%1 hours", 2).arg(2)})
35 refreshModel.append({"interval": 14400, "text": i18n.tr("%1 hour", "%1 hours", 4).arg(4)})
36 }
37 }
38
39 OptionSelector {
40 id: refreshIntervalSetting
41 text: i18n.tr("Refresh Interval")
42 model: refreshModel
43 containerHeight: itemHeight * refreshModel.count
44 delegate: OptionSelectorDelegate {
45 text: model.text
46 height: units.gu(4)
47 }
48 onDelegateClicked: {
49 settings.refreshInterval = model.get(index).interval
50 refreshData(false, true);
51 }
52 Component.onCompleted: {
53 /*
54 The Component.onCompleted of the OptionSelector finishes BEFORE
55 the onCompleted events of the delegates or the model.
56 That is why the initialize() needs to be called here rather than
57 in the Component.onCompleted of the ListModel.
58 */
59 refreshModel.initialize()
60 for (var i = 0; i < refreshModel.count; ++i) {
61 if (refreshModel.get(i).interval === settings.refreshInterval) {
62 refreshIntervalSetting.selectedIndex = i
63 return
64 }
65 }
66 refreshIntervalSetting.selectedIndex = 0 // in case no match is found due to broken settings
67 }
68 }
69 }