~martin-borho/ubuntu-weather-app/keyboard-shortcuts

« back to all changes in this revision

Viewing changes to components/SettingsSheet.qml

  • Committer: Martin Borho
  • Date: 2014-02-15 14:31:10 UTC
  • mfrom: (187.1.10 trunk)
  • Revision ID: martin@borho.net-20140215143110-gij32mdfm2mah342
merged from trunk, resolved conflict

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
                delegate: unitsSelectorDelegate
83
83
                model: precipitationUnitsSelectorModel
84
84
                selectedIndex: (settings["precip_units"] === "in") ? 1 : 0;
 
85
                // Precipitation units not available at TWC
 
86
                visible: (serviceSelector.selectedIndex !== 0) ?  1 : 0
 
87
                opacity: (serviceSelector.selectedIndex !== 0) ?  1 : 0
 
88
                Behavior on visible {
 
89
                    enabled: (serviceSelector.selectedIndex === 0)
 
90
                    NumberAnimation { duration:  1500}
 
91
                }
 
92
                Behavior on opacity {
 
93
                    NumberAnimation {
 
94
                        easing: UbuntuAnimation.StandardEasingReverse;
 
95
                        duration: UbuntuAnimation.SlowDuration
 
96
                    }
 
97
                }
 
98
            }
 
99
 
 
100
            ListModel {
 
101
                id: serviceSelectorModel
 
102
                ListElement { name: "twcOption"; label: "The Weather Channel" }
 
103
                ListElement { name: "owmOption"; label: "Openweathermap" }
 
104
            }
 
105
 
 
106
            OptionSelector {
 
107
                id: serviceSelector
 
108
                objectName: "ServiceSelector"
 
109
                text: i18n.tr("Weather Service")
 
110
                delegate: unitsSelectorDelegate
 
111
                model: serviceSelectorModel
 
112
                selectedIndex: (settings["service"] === "openweathermap") ? 1 : 0;
85
113
            }
86
114
        }
87
115
 
99
127
        Connections { target: mainView; onEscapeKey: cancelSheet() }
100
128
 
101
129
        onConfirmClicked: {
102
 
            var refresh = false,
 
130
            var refresh_from_storage = false,
 
131
                refresh_from_service = false,
103
132
                selectedUnit = (temperatureUnitsSelector.selectedIndex === 0) ? "metric" : "imperial",
104
133
                selectedWindUnit = (windUnitsSelector.selectedIndex === 0) ? "kmh" : "mph",
105
 
                selectedPrecipUnit = (precipitationUnitsSelector.selectedIndex === 0) ? "mm" : "in";
 
134
                selectedPrecipUnit = (precipitationUnitsSelector.selectedIndex === 0) ? "mm" : "in",
 
135
                selectedService = (serviceSelector.selectedIndex === 0) ? "weatherchannel" : "openweathermap";
106
136
            // check if temperaure scale was changed
107
137
            if(settings["units"] !== selectedUnit) {
108
138
                storage.saveSetting("units", selectedUnit);
109
 
                refresh = true;
 
139
                refresh_from_storage = true;
110
140
            }
111
141
            //
112
142
            if(settings["wind_units"] !== selectedWindUnit) {
113
143
                storage.saveSetting("wind_units", selectedWindUnit);
114
 
                refresh = true;
 
144
                refresh_from_storage = true;
115
145
            }
116
146
            //
117
147
            if(settings["precip_units"] !== selectedPrecipUnit) {
118
148
                storage.saveSetting("precip_units", selectedPrecipUnit);
119
 
                refresh = true;
 
149
                refresh_from_storage = true;
 
150
            }
 
151
            //
 
152
            if(settings["service"] !== selectedService) {
 
153
                storage.saveSetting("service", selectedService);
 
154
                refresh_from_service = true;
120
155
            }
121
156
            // handling of other settings here
122
157
            // ....
123
158
 
124
159
            // a setting was changed, reload settings and refresh the location tabs
125
 
            if(refresh === true) {
 
160
            if(refresh_from_storage === true || refresh_from_service === true) {
126
161
                storage.getSettings(function(storedSettings) {
127
162
                    for(var settingName in storedSettings) {
128
163
                        settings[settingName] = storedSettings[settingName];
129
164
                    }
130
 
                    refreshData(true);
 
165
                    refreshData(refresh_from_storage, refresh_from_service);
131
166
                });
132
167
            }
133
168
            Theme.palette.selected.backgroundText = "#f4f4e8"