=== modified file 'app/components/CurrentLocation.qml'
--- app/components/CurrentLocation.qml 2015-06-18 01:42:03 +0000
+++ app/components/CurrentLocation.qml 2015-07-27 00:58:09 +0000
@@ -41,7 +41,7 @@
}
function searchResponseHandler(msgObject) {
- if (!msgObject.error) {
+ if (!msgObject.error && settings.detectCurrentLocation) {
console.log("Loc to add:", JSON.stringify(msgObject.result.locations[0]))
storage.updateCurrentLocation(msgObject.result.locations[0])
}
@@ -51,7 +51,7 @@
PositionSource {
id: currentPosition
updateInterval: 1000
- active: true
+ active: settings.detectCurrentLocation
onPositionChanged: {
var coord = currentPosition.position.coordinate
@@ -75,9 +75,22 @@
onCountChanged: {
// Update the currentLocation if one is found and it does not match the stored location
if (count > 0 && currentLocation.string !== geocodeModel.get(0).address.city) {
- var loc = geocodeModel.get(0)
- currentLocation.string = loc.address.city
- searchForLocation(loc.coordinate.latitude, loc.coordinate.longitude)
+ search();
+ }
+ }
+
+ function search() {
+ var loc = geocodeModel.get(0)
+ currentLocation.string = loc.address.city
+ searchForLocation(loc.coordinate.latitude, loc.coordinate.longitude)
+ }
+ }
+
+ Connections {
+ target: settings
+ onDetectCurrentLocationChanged: {
+ if (settings.detectCurrentLocation) {
+ geocodeModel.search();
}
}
}
=== modified file 'app/ubuntu-weather-app.qml'
--- app/ubuntu-weather-app.qml 2015-07-25 22:06:50 +0000
+++ app/ubuntu-weather-app.qml 2015-07-27 00:58:09 +0000
@@ -132,6 +132,7 @@
*/
property int current: 0
+ property bool detectCurrentLocation: true
property int refreshInterval: 1800
property string precipUnits
property string service
@@ -142,6 +143,17 @@
property bool addedCurrentLocation: false
property bool migrated: false
+ onDetectCurrentLocationChanged: {
+ if (!detectCurrentLocation) {
+ if (addedCurrentLocation) {
+ storage.removeLocation(-1); // indexes are increased by 1
+ addedCurrentLocation = false;
+ }
+
+ refreshData();
+ }
+ }
+
Component.onCompleted: {
if (units === "") { // No settings so load defaults
console.debug("No settings, using defaults")
@@ -233,8 +245,10 @@
function moveLocation(from, to) {
// Indexes are offset by 1 to account for current location
- from += 1
- to += 1
+ if (settings.addedCurrentLocation) {
+ from += 1
+ to += 1
+ }
// Update settings to respect new changes
if (from === settings.current) {
@@ -253,7 +267,10 @@
// Remove a location from the list
function removeLocation(index) {
// Indexes are offset by 1 to account for current location
- index += 1
+ if (settings.addedCurrentLocation) {
+ index += 1
+ }
+
if (settings.current >= index) { // Update settings to respect new changes
settings.current -= settings.current;
}
@@ -279,7 +296,11 @@
var locations = []
for (i=0; i < indexes.length; i++) {
- locations.push(locationsList[indexes[i] + 1].db.id)
+ if (settings.addedCurrentLocation) {
+ locations.push(locationsList[indexes[i] + 1].db.id)
+ } else {
+ locations.push(locationsList[indexes[i]].db.id)
+ }
}
storage.clearMultiLocation(locations);
=== modified file 'app/ui/LocationsPage.qml'
--- app/ui/LocationsPage.qml 2015-06-28 19:04:43 +0000
+++ app/ui/LocationsPage.qml 2015-07-27 00:58:09 +0000
@@ -50,7 +50,7 @@
removable: true
thisPage: locationsPage
- onRemoved: storage.removeMultiLocations(selectedItems.slice())
+ onRemoved: storage.removeMultiLocations(selectedItems.slice());
}
]
@@ -72,7 +72,7 @@
left: parent.left
right: parent.right
}
- height: settings.addedCurrentLocation ? units.gu(8) : units.gu(0)
+ height: settings.addedCurrentLocation && settings.detectCurrentLocation ? units.gu(8) : units.gu(0)
interactive: false
model: currentLocationModel
delegate: WeatherListItem {
@@ -160,6 +160,7 @@
onItemClicked: {
settings.current = index + 1;
+
pageStack.pop()
}
onReorder: {
=== modified file 'app/ui/SettingsPage.qml'
--- app/ui/SettingsPage.qml 2015-06-28 22:54:14 +0000
+++ app/ui/SettingsPage.qml 2015-07-27 00:58:09 +0000
@@ -42,5 +42,10 @@
title: i18n.tr("Refresh Interval")
onClicked: mainPageStack.push(Qt.resolvedUrl("settings/RefreshIntervalPage.qml"))
}
+
+ StandardListItem {
+ title: i18n.tr("Location")
+ onClicked: mainPageStack.push(Qt.resolvedUrl("settings/LocationPage.qml"))
+ }
}
}
=== added file 'app/ui/settings/LocationPage.qml'
--- app/ui/settings/LocationPage.qml 1970-01-01 00:00:00 +0000
+++ app/ui/settings/LocationPage.qml 2015-07-27 00:58:09 +0000
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Canonical Ltd
+ *
+ * This file is part of Ubuntu Weather App
+ *
+ * Ubuntu Weather App is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Ubuntu Weather App is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+import QtQuick 2.4
+import Ubuntu.Components 1.2
+import Ubuntu.Components.ListItems 1.0 as ListItem
+
+Page {
+ title: i18n.tr("Location")
+
+ ListItem.Standard {
+ control: CheckBox {
+ checked: settings.detectCurrentLocation
+
+ onCheckedChanged: settings.detectCurrentLocation = checked;
+ }
+ text: i18n.tr("Detect current location")
+
+ onClicked: control.checked = !control.checked
+ }
+}
=== modified file 'debian/changelog'
--- debian/changelog 2015-07-25 21:53:40 +0000
+++ debian/changelog 2015-07-27 00:58:09 +0000
@@ -10,6 +10,8 @@
[ Andrew Hayzen ]
* Add mocked locations for autopilot and add a test using the data
+ * Add setting to disable auto detecting location
+ * When running under autopilot do not auto detect location
-- Victor Thompson Mon, 01 Jun 2015 20:11:23 -0500
=== modified file 'po/com.ubuntu.weather.pot'
--- po/com.ubuntu.weather.pot 2015-07-18 19:08:21 +0000
+++ po/com.ubuntu.weather.pot 2015-07-27 00:58:09 +0000
@@ -8,7 +8,7 @@
msgstr ""
"Project-Id-Version: ubuntu-weather-app\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-07-18 18:04+0100\n"
+"POT-Creation-Date: 2015-07-27 01:55+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -18,31 +18,31 @@
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
-#: ../app/components/DayDelegate.qml:193
+#: ../app/components/DayDelegate.qml:199
msgid "Chance of rain"
msgstr ""
-#: ../app/components/DayDelegate.qml:202
+#: ../app/components/DayDelegate.qml:205
msgid "Winds"
msgstr ""
-#: ../app/components/DayDelegate.qml:209
+#: ../app/components/DayDelegate.qml:212
msgid "UV Index"
msgstr ""
-#: ../app/components/DayDelegate.qml:214
+#: ../app/components/DayDelegate.qml:217
msgid "Pollen"
msgstr ""
-#: ../app/components/DayDelegate.qml:220
+#: ../app/components/DayDelegate.qml:223
msgid "Humidity"
msgstr ""
-#: ../app/components/DayDelegate.qml:226
+#: ../app/components/DayDelegate.qml:229
msgid "Sunrise"
msgstr ""
-#: ../app/components/DayDelegate.qml:232
+#: ../app/components/DayDelegate.qml:235
msgid "Sunset"
msgstr ""
@@ -66,11 +66,11 @@
msgid "Cancel selection"
msgstr ""
-#: ../app/ubuntu-weather-app.qml:168
+#: ../app/ubuntu-weather-app.qml:184
msgid "Searching for current location..."
msgstr ""
-#: ../app/ubuntu-weather-app.qml:177
+#: ../app/ubuntu-weather-app.qml:193
msgid "Add a manual location"
msgstr ""
@@ -122,7 +122,7 @@
msgid "Units"
msgstr ""
-#: ../app/ui/SettingsPage.qml:37 ../app/ui/settings/DataProviderPage.qml:24
+#: ../app/ui/SettingsPage.qml:37 ../app/ui/settings/DataProviderPage.qml:25
msgid "Data Provider"
msgstr ""
@@ -130,10 +130,18 @@
msgid "Refresh Interval"
msgstr ""
+#: ../app/ui/SettingsPage.qml:47 ../app/ui/settings/LocationPage.qml:24
+msgid "Location"
+msgstr ""
+
#: ../app/ui/settings/DataProviderPage.qml:37
msgid "Provider"
msgstr ""
+#: ../app/ui/settings/LocationPage.qml:32
+msgid "Detect current location"
+msgstr ""
+
#: ../app/ui/settings/RefreshIntervalPage.qml:30
#: ../app/ui/settings/RefreshIntervalPage.qml:31
#: ../app/ui/settings/RefreshIntervalPage.qml:32
=== modified file 'tests/autopilot/ubuntu_weather_app/databases/CMakeLists.txt'
--- tests/autopilot/ubuntu_weather_app/databases/CMakeLists.txt 2015-07-25 13:52:18 +0000
+++ tests/autopilot/ubuntu_weather_app/databases/CMakeLists.txt 2015-07-27 00:58:09 +0000
@@ -1,6 +1,6 @@
# make the database files visible on qtcreator
file(GLOB PYTHON_TEST_DATABASE_FILES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- *.ini)
+ *.ini *.conf)
add_custom_target(ubuntu-weather-app_PYTHONTestDatabaseFiles ALL SOURCES ${PYTHON_TEST_DATABASE_FILES})
=== added file 'tests/autopilot/ubuntu_weather_app/databases/location_added.conf'
--- tests/autopilot/ubuntu_weather_app/databases/location_added.conf 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/databases/location_added.conf 2015-07-27 00:58:09 +0000
@@ -0,0 +1,3 @@
+[weatherSettings]
+detectCurrentLocation=false
+migrated=true
=== modified file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2015-07-23 00:50:12 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2015-07-27 00:58:09 +0000
@@ -223,7 +223,7 @@
return result
- def load_vars(self):
+ def load_database_vars(self):
self.app_dir = os.path.join(
os.environ.get('HOME'),
".local/share/com.ubuntu.weather")
@@ -235,30 +235,68 @@
os.path.join(os.path.dirname(__file__), '..', 'files'))
-class UbuntuWeatherAppTestCase(BaseTestCaseWithPatchedHome, DatabaseMixin):
+class SettingsMixin(object):
+
+ """
+ Helper functions for dealing with the settings file
+ """
+
+ def create_settings_with_location_added(self):
+ logger.debug("Creating settings with location added")
+
+ if not os.path.exists(self.settings_dir):
+ os.makedirs(self.settings_dir)
+
+ shutil.copyfile(self.settings_location_added, self.settings_filepath)
+
+ self.assertThat(
+ lambda: os.path.exists(self.settings_filepath),
+ Eventually(Equals(True)))
+
+ def load_settings_vars(self):
+ self.db_dir = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), '..', 'databases'))
+ self.settings_dir = os.path.join(
+ os.environ.get('HOME'),
+ ".config/com.ubuntu.weather")
+ self.settings_filepath = os.path.join(self.settings_dir,
+ 'com.ubuntu.weather.conf')
+ self.settings_location_added = os.path.join(self.db_dir,
+ "location_added.conf")
+
+
+class UbuntuWeatherAppTestCase(BaseTestCaseWithPatchedHome, DatabaseMixin,
+ SettingsMixin):
"""Base test case that launches the ubuntu-weather-app."""
def setUp(self):
super(UbuntuWeatherAppTestCase, self).setUp()
- self.load_vars()
+ self.load_database_vars()
self.create_blank_db()
+ self.load_settings_vars()
+ self.create_settings_with_location_added()
+
self.app = UbuntuWeatherApp(self.launcher())
class UbuntuWeatherAppTestCaseWithData(BaseTestCaseWithPatchedHome,
- DatabaseMixin):
+ DatabaseMixin,
+ SettingsMixin):
"""Base test case that launches the ubuntu-weather-app with data."""
def setUp(self):
super(UbuntuWeatherAppTestCaseWithData, self).setUp()
- self.load_vars()
+ self.load_database_vars()
self.create_blank_db()
+ self.load_settings_vars()
+ self.create_settings_with_location_added()
+
logger.debug("Adding fake data to new database")
self.add_locations_to_database()