Merge lp:~mterry/unity8/oobe-revert-geonames into lp:unity8
- oobe-revert-geonames
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Michał Sawicz |
Proposed branch: | lp:~mterry/unity8/oobe-revert-geonames |
Merge into: | lp:unity8 |
Prerequisite: | lp:~unity-team/unity8/oobe |
Diff against target: |
691 lines (+225/-199) 13 files modified
CMakeLists.txt (+0/-1) debian/control (+1/-1) plugins/Wizard/CMakeLists.txt (+4/-2) plugins/Wizard/plugin.cpp (+1/-0) plugins/Wizard/timezonemodel.cpp (+140/-156) plugins/Wizard/timezonemodel.h (+55/-22) qml/Wizard/Pages.qml (+11/-0) qml/Wizard/Pages/10-welcome.qml (+1/-0) qml/Wizard/Pages/50-timezone.qml (+3/-13) qml/Wizard/Pages/passcode-confirm.qml (+2/-1) qml/Wizard/Pages/passcode-set.qml (+2/-1) tests/mocks/Wizard/CMakeLists.txt (+4/-2) tests/mocks/Wizard/mockplugin.cpp (+1/-0) |
To merge this branch: | bzr merge lp:~mterry/unity8/oobe-revert-geonames |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michał Sawicz | Disapprove | ||
Unity8 CI Bot | continuous-integration | Needs Fixing | |
Lukáš Tinkl (community) | Needs Fixing | ||
Review via email: mp+289758@code.launchpad.net |
This proposal supersedes a proposal from 2016-03-22.
Commit message
Revert the use of geonames back to libtimezonemap in the wizard until we can fix a bug with it.
Description of the change
Revert the use of geonames back to libtimezonemap. These changes aren't perfect. It's just going back to an earlier version of the code.
To be fixed up later again to geonames once we fix a mystery freeze.
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:2159
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
UNSTABLE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Michał Sawicz (saviq) wrote : | # |
No need after all.
Unmerged revisions
- 2159. By Michael Terry
-
Revert use of geonames
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-03-22 09:09:22 +0000 | |||
3 | +++ CMakeLists.txt 2016-03-03 18:41:20 +0000 | |||
4 | @@ -58,7 +58,6 @@ | |||
5 | 58 | find_package(Qt5Sql 5.4 REQUIRED) | 58 | find_package(Qt5Sql 5.4 REQUIRED) |
6 | 59 | 59 | ||
7 | 60 | pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=13) | 60 | pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=13) |
8 | 61 | pkg_check_modules(GEONAMES REQUIRED geonames>=0.2) | ||
9 | 62 | pkg_check_modules(GIO REQUIRED gio-2.0>=2.32) | 61 | pkg_check_modules(GIO REQUIRED gio-2.0>=2.32) |
10 | 63 | pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32) | 62 | pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32) |
11 | 64 | pkg_check_modules(QMENUMODEL REQUIRED qmenumodel) | 63 | pkg_check_modules(QMENUMODEL REQUIRED qmenumodel) |
12 | 65 | 64 | ||
13 | === modified file 'debian/control' | |||
14 | --- debian/control 2016-03-22 09:09:22 +0000 | |||
15 | +++ debian/control 2016-03-22 09:09:23 +0000 | |||
16 | @@ -15,7 +15,6 @@ | |||
17 | 15 | gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815), | 15 | gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815), |
18 | 16 | libconnectivity-qt1-dev (>= 0.7.1), | 16 | libconnectivity-qt1-dev (>= 0.7.1), |
19 | 17 | libevdev-dev, | 17 | libevdev-dev, |
20 | 18 | libgeonames-dev (>= 0.2), | ||
21 | 19 | libgl1-mesa-dev[!armhf] | libgl-dev[!armhf], | 18 | libgl1-mesa-dev[!armhf] | libgl-dev[!armhf], |
22 | 20 | libgl1-mesa-dri, | 19 | libgl1-mesa-dri, |
23 | 21 | libgles2-mesa-dev[armhf], | 20 | libgles2-mesa-dev[armhf], |
24 | @@ -29,6 +28,7 @@ | |||
25 | 29 | libqt5svg5-dev, | 28 | libqt5svg5-dev, |
26 | 30 | libqt5xmlpatterns5-dev, | 29 | libqt5xmlpatterns5-dev, |
27 | 31 | libsystemsettings-dev, | 30 | libsystemsettings-dev, |
28 | 31 | libtimezonemap1-dev, | ||
29 | 32 | libudev-dev, | 32 | libudev-dev, |
30 | 33 | libunity-api-dev (>= 7.107), | 33 | libunity-api-dev (>= 7.107), |
31 | 34 | libusermetricsoutput1-dev, | 34 | libusermetricsoutput1-dev, |
32 | 35 | 35 | ||
33 | === modified file 'plugins/Wizard/CMakeLists.txt' | |||
34 | --- plugins/Wizard/CMakeLists.txt 2016-03-22 09:09:22 +0000 | |||
35 | +++ plugins/Wizard/CMakeLists.txt 2016-03-22 09:09:23 +0000 | |||
36 | @@ -1,4 +1,6 @@ | |||
38 | 1 | include_directories(${GLIB_INCLUDE_DIRS} ${GEONAMES_INCLUDE_DIRS}) | 1 | pkg_search_module(TIMEZONEMAP REQUIRED timezonemap) |
39 | 2 | |||
40 | 3 | include_directories(${GLIB_INCLUDE_DIRS} ${TIMEZONEMAP_INCLUDE_DIRS}) | ||
41 | 2 | 4 | ||
42 | 3 | add_library(Wizard-qml MODULE | 5 | add_library(Wizard-qml MODULE |
43 | 4 | plugin.cpp | 6 | plugin.cpp |
44 | @@ -10,7 +12,7 @@ | |||
45 | 10 | ) | 12 | ) |
46 | 11 | 13 | ||
47 | 12 | qt5_use_modules(Wizard-qml DBus Qml Concurrent) | 14 | qt5_use_modules(Wizard-qml DBus Qml Concurrent) |
49 | 13 | target_link_libraries(Wizard-qml ${GLIB_LDFLAGS} ${GEONAMES_LDFLAGS}) | 15 | target_link_libraries(Wizard-qml ${GLIB_LDFLAGS} ${TIMEZONEMAP_LDFLAGS}) |
50 | 14 | add_unity8_plugin(Wizard 0.1 Wizard TARGETS Wizard-qml) | 16 | add_unity8_plugin(Wizard 0.1 Wizard TARGETS Wizard-qml) |
51 | 15 | 17 | ||
52 | 16 | set(POLKIT_LIB_DIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/polkit-1") | 18 | set(POLKIT_LIB_DIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/polkit-1") |
53 | 17 | 19 | ||
54 | === modified file 'plugins/Wizard/plugin.cpp' | |||
55 | --- plugins/Wizard/plugin.cpp 2016-03-22 09:09:22 +0000 | |||
56 | +++ plugins/Wizard/plugin.cpp 2016-03-22 09:09:23 +0000 | |||
57 | @@ -30,5 +30,6 @@ | |||
58 | 30 | qmlRegisterSingletonType<System>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new System; }); | 30 | qmlRegisterSingletonType<System>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new System; }); |
59 | 31 | qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; }); | 31 | qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; }); |
60 | 32 | qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel"); | 32 | qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel"); |
61 | 33 | qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel"); | ||
62 | 33 | qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin"); | 34 | qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin"); |
63 | 34 | } | 35 | } |
64 | 35 | 36 | ||
65 | === modified file 'plugins/Wizard/timezonemodel.cpp' | |||
66 | --- plugins/Wizard/timezonemodel.cpp 2016-03-22 09:09:22 +0000 | |||
67 | +++ plugins/Wizard/timezonemodel.cpp 2016-03-22 09:09:23 +0000 | |||
68 | @@ -18,15 +18,17 @@ | |||
69 | 18 | 18 | ||
70 | 19 | #include <glib.h> | 19 | #include <glib.h> |
71 | 20 | #include <glib-object.h> | 20 | #include <glib-object.h> |
72 | 21 | #include <timezonemap/tz.h> | ||
73 | 21 | 22 | ||
74 | 22 | #include "LocalePlugin.h" | 23 | #include "LocalePlugin.h" |
75 | 23 | #include "timezonemodel.h" | 24 | #include "timezonemodel.h" |
76 | 24 | 25 | ||
77 | 25 | TimeZoneLocationModel::TimeZoneLocationModel(QObject *parent): | 26 | TimeZoneLocationModel::TimeZoneLocationModel(QObject *parent): |
78 | 26 | QAbstractListModel(parent), | 27 | QAbstractListModel(parent), |
81 | 27 | m_listUpdating(false), | 28 | m_workerThread(new TimeZonePopulateWorker()) |
80 | 28 | m_cancellable(nullptr) | ||
82 | 29 | { | 29 | { |
83 | 30 | qRegisterMetaType<TzLocationWizard>(); | ||
84 | 31 | |||
85 | 30 | m_roleNames[Qt::DisplayRole] = "displayName"; | 32 | m_roleNames[Qt::DisplayRole] = "displayName"; |
86 | 31 | m_roleNames[TimeZoneRole] = "timeZone"; | 33 | m_roleNames[TimeZoneRole] = "timeZone"; |
87 | 32 | m_roleNames[CityRole] = "city"; | 34 | m_roleNames[CityRole] = "city"; |
88 | @@ -34,52 +36,78 @@ | |||
89 | 34 | m_roleNames[OffsetRole] = "offset"; | 36 | m_roleNames[OffsetRole] = "offset"; |
90 | 35 | m_roleNames[LatitudeRole] = "latitude"; | 37 | m_roleNames[LatitudeRole] = "latitude"; |
91 | 36 | m_roleNames[LongitudeRole] = "longitude"; | 38 | m_roleNames[LongitudeRole] = "longitude"; |
92 | 39 | |||
93 | 40 | QObject::connect(m_workerThread, | ||
94 | 41 | &TimeZonePopulateWorker::resultReady, | ||
95 | 42 | this, | ||
96 | 43 | &TimeZoneLocationModel::processModelResult); | ||
97 | 44 | QObject::connect(m_workerThread, | ||
98 | 45 | &TimeZonePopulateWorker::finished, | ||
99 | 46 | this, | ||
100 | 47 | &TimeZoneLocationModel::store); | ||
101 | 48 | QObject::connect(m_workerThread, | ||
102 | 49 | &TimeZonePopulateWorker::finished, | ||
103 | 50 | m_workerThread, | ||
104 | 51 | &QObject::deleteLater); | ||
105 | 52 | |||
106 | 53 | init(); | ||
107 | 54 | } | ||
108 | 55 | |||
109 | 56 | void TimeZoneLocationModel::init() | ||
110 | 57 | { | ||
111 | 58 | beginResetModel(); | ||
112 | 59 | m_workerThread->start(); | ||
113 | 60 | } | ||
114 | 61 | |||
115 | 62 | void TimeZoneLocationModel::store() | ||
116 | 63 | { | ||
117 | 64 | m_workerThread = nullptr; | ||
118 | 65 | endResetModel(); | ||
119 | 66 | } | ||
120 | 67 | |||
121 | 68 | void TimeZoneLocationModel::processModelResult(const TzLocationWizard &location) | ||
122 | 69 | { | ||
123 | 70 | m_locations.append(location); | ||
124 | 37 | } | 71 | } |
125 | 38 | 72 | ||
126 | 39 | int TimeZoneLocationModel::rowCount(const QModelIndex &parent) const | 73 | int TimeZoneLocationModel::rowCount(const QModelIndex &parent) const |
127 | 40 | { | 74 | { |
129 | 41 | if (parent.isValid()) { | 75 | if (parent.isValid()) |
130 | 42 | return 0; | 76 | return 0; |
136 | 43 | } else if (m_filter.isEmpty()) { | 77 | return m_locations.count(); |
132 | 44 | return m_countryLocations.count(); | ||
133 | 45 | } else { | ||
134 | 46 | return m_locations.count(); | ||
135 | 47 | } | ||
137 | 48 | } | 78 | } |
138 | 49 | 79 | ||
139 | 50 | QVariant TimeZoneLocationModel::data(const QModelIndex &index, int role) const | 80 | QVariant TimeZoneLocationModel::data(const QModelIndex &index, int role) const |
140 | 51 | { | 81 | { |
148 | 52 | GeonamesCity *city; | 82 | if (index.row() >= m_locations.count() || index.row() < 0) |
142 | 53 | if (m_filter.isEmpty()) { | ||
143 | 54 | city = m_countryLocations.value(index.row()); | ||
144 | 55 | } else { | ||
145 | 56 | city = m_locations.value(index.row()); | ||
146 | 57 | } | ||
147 | 58 | if (!city) | ||
149 | 59 | return QVariant(); | 83 | return QVariant(); |
150 | 60 | 84 | ||
151 | 85 | const TzLocationWizard tz = m_locations.at(index.row()); | ||
152 | 86 | |||
153 | 87 | const QString country(tz.full_country.isEmpty() ? tz.country : tz.full_country); | ||
154 | 88 | |||
155 | 61 | switch (role) { | 89 | switch (role) { |
156 | 62 | case Qt::DisplayRole: | 90 | case Qt::DisplayRole: |
160 | 63 | return QStringLiteral("%1, %2, %3").arg(geonames_city_get_name(city)) | 91 | if (!tz.state.isEmpty()) |
161 | 64 | .arg(geonames_city_get_state(city)) | 92 | return QStringLiteral("%1, %2, %3").arg(tz.city).arg(tz.state).arg(country); |
162 | 65 | .arg(geonames_city_get_country(city)); | 93 | else |
163 | 94 | return QStringLiteral("%1, %2").arg(tz.city).arg(country); | ||
164 | 66 | case SimpleRole: | 95 | case SimpleRole: |
167 | 67 | return QStringLiteral("%1, %2").arg(geonames_city_get_name(city)) | 96 | return QStringLiteral("%1, %2").arg(tz.city).arg(country); |
166 | 68 | .arg(geonames_city_get_country(city)); | ||
168 | 69 | case TimeZoneRole: | 97 | case TimeZoneRole: |
170 | 70 | return geonames_city_get_timezone(city); | 98 | return tz.timezone; |
171 | 71 | case CountryRole: | 99 | case CountryRole: |
173 | 72 | return geonames_city_get_country(city); | 100 | return tz.country; |
174 | 73 | case CityRole: | 101 | case CityRole: |
176 | 74 | return geonames_city_get_name(city); | 102 | return tz.city; |
177 | 75 | case OffsetRole: { | 103 | case OffsetRole: { |
179 | 76 | QTimeZone tmp(geonames_city_get_timezone(city)); | 104 | QTimeZone tmp(tz.timezone.toLatin1()); |
180 | 77 | return static_cast<double>(tmp.standardTimeOffset(QDateTime::currentDateTime())) / 3600; | 105 | return static_cast<double>(tmp.standardTimeOffset(QDateTime::currentDateTime())) / 3600; |
181 | 78 | } | 106 | } |
182 | 79 | case LatitudeRole: | 107 | case LatitudeRole: |
184 | 80 | return geonames_city_get_latitude(city); | 108 | return tz.latitude; |
185 | 81 | case LongitudeRole: | 109 | case LongitudeRole: |
187 | 82 | return geonames_city_get_longitude(city); | 110 | return tz.longitude; |
188 | 83 | default: | 111 | default: |
189 | 84 | qWarning() << Q_FUNC_INFO << "Unknown role"; | 112 | qWarning() << Q_FUNC_INFO << "Unknown role"; |
190 | 85 | return QVariant(); | 113 | return QVariant(); |
191 | @@ -91,154 +119,110 @@ | |||
192 | 91 | return m_roleNames; | 119 | return m_roleNames; |
193 | 92 | } | 120 | } |
194 | 93 | 121 | ||
259 | 94 | void TimeZoneLocationModel::setModel(const QList<GeonamesCity *> &locations) | 122 | void TimeZonePopulateWorker::run() |
260 | 95 | { | 123 | { |
261 | 96 | beginResetModel(); | 124 | buildCityMap(); |
262 | 97 | 125 | } | |
263 | 98 | Q_FOREACH(GeonamesCity *city, m_locations) { | 126 | |
264 | 99 | geonames_city_free(city); | 127 | void TimeZonePopulateWorker::buildCityMap() |
265 | 100 | } | 128 | { |
266 | 101 | 129 | TzDB *tzdb = tz_load_db(); | |
267 | 102 | m_locations = locations; | 130 | GPtrArray *tz_locations = tz_get_locations(tzdb); |
268 | 103 | endResetModel(); | 131 | |
269 | 104 | } | 132 | TimeZoneLocationModel::TzLocationWizard tmpTz; |
270 | 105 | 133 | ||
271 | 106 | void TimeZoneLocationModel::filterFinished(GObject *source_object, | 134 | for (guint i = 0; i < tz_locations->len; ++i) { |
272 | 107 | GAsyncResult *res, | 135 | auto tmp = static_cast<CcTimezoneLocation *>(g_ptr_array_index(tz_locations, i)); |
273 | 108 | gpointer user_data) | 136 | gchar *en_name, *country, *zone, *state, *full_country; |
274 | 109 | { | 137 | gdouble latitude; |
275 | 110 | Q_UNUSED(source_object); | 138 | gdouble longitude; |
276 | 111 | 139 | g_object_get (tmp, "en_name", &en_name, | |
277 | 112 | g_autofree gint *cities = nullptr; | 140 | "country", &country, |
278 | 113 | guint cities_len = 0; | 141 | "zone", &zone, |
279 | 114 | g_autoptr(GError) error = nullptr; | 142 | "state", &state, |
280 | 115 | 143 | "full_country", &full_country, | |
281 | 116 | cities = geonames_query_cities_finish(res, &cities_len, &error); | 144 | "latitude", &latitude, |
282 | 117 | if (error) { | 145 | "longitude", &longitude, |
283 | 118 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { | 146 | nullptr); |
284 | 119 | TimeZoneLocationModel *model = static_cast<TimeZoneLocationModel *>(user_data); | 147 | // There are empty entries in the DB |
285 | 120 | g_clear_object(&model->m_cancellable); | 148 | if (g_strcmp0(en_name, "") != 0) { |
286 | 121 | model->setListUpdating(false); | 149 | tmpTz.city = en_name; |
287 | 122 | qWarning() << "Could not filter timezones:" << error->message; | 150 | tmpTz.country = country; |
288 | 123 | } | 151 | tmpTz.timezone = zone; |
289 | 124 | return; | 152 | tmpTz.state = state; |
290 | 125 | } | 153 | tmpTz.full_country = full_country; |
291 | 126 | 154 | tmpTz.latitude = latitude; | |
292 | 127 | QList<GeonamesCity *> locations; | 155 | tmpTz.longitude = longitude; |
293 | 128 | 156 | ||
294 | 129 | for (guint i = 0; i < cities_len; ++i) { | 157 | Q_EMIT (resultReady(tmpTz)); |
295 | 130 | GeonamesCity *city = geonames_get_city(cities[i]); | 158 | } |
296 | 131 | if (city) { | 159 | g_free (en_name); |
297 | 132 | locations.append(city); | 160 | g_free (country); |
298 | 133 | } | 161 | g_free (zone); |
299 | 134 | } | 162 | g_free (state); |
300 | 135 | 163 | g_free (full_country); | |
301 | 136 | TimeZoneLocationModel *model = static_cast<TimeZoneLocationModel *>(user_data); | 164 | } |
302 | 137 | 165 | ||
303 | 138 | g_clear_object(&model->m_cancellable); | 166 | g_ptr_array_free (tz_locations, TRUE); |
304 | 139 | 167 | tz_db_free(tzdb); | |
305 | 140 | model->setModel(locations); | 168 | } |
306 | 141 | model->setListUpdating(false); | 169 | |
307 | 142 | } | 170 | |
308 | 143 | 171 | TimeZoneFilterModel::TimeZoneFilterModel(QObject *parent) | |
309 | 144 | bool TimeZoneLocationModel::listUpdating() const | 172 | : QSortFilterProxyModel(parent) |
310 | 145 | { | 173 | { |
311 | 146 | return m_listUpdating; | 174 | setDynamicSortFilter(false); |
312 | 147 | } | 175 | setSortLocaleAware(true); |
313 | 148 | 176 | setSortRole(TimeZoneLocationModel::CityRole); | |
314 | 149 | void TimeZoneLocationModel::setListUpdating(bool listUpdating) | 177 | m_stringMatcher.setCaseSensitivity(Qt::CaseInsensitive); |
315 | 150 | { | 178 | sort(0); |
316 | 151 | if (m_listUpdating != listUpdating) { | 179 | } |
317 | 152 | m_listUpdating = listUpdating; | 180 | |
318 | 153 | Q_EMIT listUpdatingChanged(); | 181 | bool TimeZoneFilterModel::filterAcceptsRow(int row, const QModelIndex &parentIndex) const |
319 | 154 | } | 182 | { |
320 | 155 | } | 183 | if (!sourceModel()) { |
321 | 156 | 184 | return true; | |
322 | 157 | QString TimeZoneLocationModel::filter() const | 185 | } |
323 | 186 | |||
324 | 187 | if (!m_filter.isEmpty()) { // filtering by freeform text input, cf setFilter(QString) | ||
325 | 188 | const QString city = sourceModel()->index(row, 0, parentIndex).data(TimeZoneLocationModel::CityRole).toString(); | ||
326 | 189 | |||
327 | 190 | if (m_stringMatcher.indexIn(city) == 0) { // match at the beginning of the city name | ||
328 | 191 | return true; | ||
329 | 192 | } | ||
330 | 193 | } else if (!m_country.isEmpty()) { // filter by country code | ||
331 | 194 | const QString countryCode = sourceModel()->index(row, 0, parentIndex).data(TimeZoneLocationModel::CountryRole).toString(); | ||
332 | 195 | return m_country.compare(countryCode, Qt::CaseInsensitive) == 0; | ||
333 | 196 | } | ||
334 | 197 | |||
335 | 198 | return false; | ||
336 | 199 | } | ||
337 | 200 | |||
338 | 201 | QString TimeZoneFilterModel::filter() const | ||
339 | 158 | { | 202 | { |
340 | 159 | return m_filter; | 203 | return m_filter; |
341 | 160 | } | 204 | } |
342 | 161 | 205 | ||
344 | 162 | void TimeZoneLocationModel::setFilter(const QString &filter) | 206 | void TimeZoneFilterModel::setFilter(const QString &filter) |
345 | 163 | { | 207 | { |
346 | 164 | if (filter != m_filter) { | 208 | if (filter != m_filter) { |
347 | 165 | m_filter = filter; | 209 | m_filter = filter; |
348 | 210 | m_stringMatcher.setPattern(m_filter); | ||
349 | 166 | Q_EMIT filterChanged(); | 211 | Q_EMIT filterChanged(); |
372 | 167 | } | 212 | invalidate(); |
373 | 168 | 213 | } | |
352 | 169 | setListUpdating(true); | ||
353 | 170 | |||
354 | 171 | if (m_cancellable) { | ||
355 | 172 | g_cancellable_cancel(m_cancellable); | ||
356 | 173 | g_clear_object(&m_cancellable); | ||
357 | 174 | } | ||
358 | 175 | |||
359 | 176 | setModel(QList<GeonamesCity *>()); | ||
360 | 177 | |||
361 | 178 | if (filter.isEmpty()) { | ||
362 | 179 | setListUpdating(false); | ||
363 | 180 | return; | ||
364 | 181 | } | ||
365 | 182 | |||
366 | 183 | m_cancellable = g_cancellable_new(); | ||
367 | 184 | geonames_query_cities(filter.toUtf8().data(), | ||
368 | 185 | GEONAMES_QUERY_DEFAULT, | ||
369 | 186 | m_cancellable, | ||
370 | 187 | filterFinished, | ||
371 | 188 | this); | ||
374 | 189 | } | 214 | } |
375 | 190 | 215 | ||
377 | 191 | QString TimeZoneLocationModel::country() const | 216 | QString TimeZoneFilterModel::country() const |
378 | 192 | { | 217 | { |
379 | 193 | return m_country; | 218 | return m_country; |
380 | 194 | } | 219 | } |
381 | 195 | 220 | ||
388 | 196 | static bool citycmp(GeonamesCity *a, GeonamesCity *b) | 221 | void TimeZoneFilterModel::setCountry(const QString &country) |
383 | 197 | { | ||
384 | 198 | return geonames_city_get_population(b) < geonames_city_get_population(a); | ||
385 | 199 | } | ||
386 | 200 | |||
387 | 201 | void TimeZoneLocationModel::setCountry(const QString &country) | ||
389 | 202 | { | 222 | { |
390 | 203 | if (m_country == country) | 223 | if (m_country == country) |
391 | 204 | return; | 224 | return; |
392 | 205 | 225 | ||
393 | 206 | beginResetModel(); | ||
394 | 207 | |||
395 | 208 | m_country = country; | 226 | m_country = country; |
396 | 209 | |||
397 | 210 | Q_FOREACH(GeonamesCity *city, m_countryLocations) { | ||
398 | 211 | geonames_city_free(city); | ||
399 | 212 | } | ||
400 | 213 | m_countryLocations.clear(); | ||
401 | 214 | |||
402 | 215 | gint num_cities = geonames_get_n_cities(); | ||
403 | 216 | for (gint i = 0; i < num_cities; i++) { | ||
404 | 217 | GeonamesCity *city = geonames_get_city(i); | ||
405 | 218 | if (city && m_country == geonames_city_get_country_code(city)) { | ||
406 | 219 | m_countryLocations.append(city); | ||
407 | 220 | } | ||
408 | 221 | } | ||
409 | 222 | |||
410 | 223 | std::sort(m_countryLocations.begin(), m_countryLocations.end(), citycmp); | ||
411 | 224 | |||
412 | 225 | endResetModel(); | ||
413 | 226 | |||
414 | 227 | Q_EMIT countryChanged(country); | 227 | Q_EMIT countryChanged(country); |
415 | 228 | } | 228 | } |
416 | 229 | |||
417 | 230 | TimeZoneLocationModel::~TimeZoneLocationModel() | ||
418 | 231 | { | ||
419 | 232 | if (m_cancellable) { | ||
420 | 233 | g_cancellable_cancel(m_cancellable); | ||
421 | 234 | g_clear_object(&m_cancellable); | ||
422 | 235 | } | ||
423 | 236 | |||
424 | 237 | Q_FOREACH(GeonamesCity *city, m_countryLocations) { | ||
425 | 238 | geonames_city_free(city); | ||
426 | 239 | } | ||
427 | 240 | |||
428 | 241 | Q_FOREACH(GeonamesCity *city, m_locations) { | ||
429 | 242 | geonames_city_free(city); | ||
430 | 243 | } | ||
431 | 244 | } | ||
432 | 245 | 229 | ||
433 | === modified file 'plugins/Wizard/timezonemodel.h' | |||
434 | --- plugins/Wizard/timezonemodel.h 2016-03-22 09:09:22 +0000 | |||
435 | +++ plugins/Wizard/timezonemodel.h 2016-03-22 09:09:23 +0000 | |||
436 | @@ -1,5 +1,5 @@ | |||
437 | 1 | /* | 1 | /* |
439 | 2 | * Copyright (C) 2016 Canonical Ltd. | 2 | * Copyright (C) 2015 Canonical Ltd. |
440 | 3 | * | 3 | * |
441 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
442 | 5 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
443 | @@ -17,21 +17,21 @@ | |||
444 | 17 | #ifndef TIMEZONEMODEL_H | 17 | #ifndef TIMEZONEMODEL_H |
445 | 18 | #define TIMEZONEMODEL_H | 18 | #define TIMEZONEMODEL_H |
446 | 19 | 19 | ||
447 | 20 | #include <geonames.h> | ||
448 | 21 | #include <glib.h> | ||
449 | 22 | #include <QAbstractListModel> | 20 | #include <QAbstractListModel> |
450 | 21 | #include <QSortFilterProxyModel> | ||
451 | 22 | #include <QThread> | ||
452 | 23 | #include <QtConcurrent> | ||
453 | 24 | #include <QtGui/QImage> | ||
454 | 25 | |||
455 | 26 | class TimeZonePopulateWorker; | ||
456 | 23 | 27 | ||
457 | 24 | class TimeZoneLocationModel: public QAbstractListModel | 28 | class TimeZoneLocationModel: public QAbstractListModel |
458 | 25 | { | 29 | { |
459 | 26 | Q_OBJECT | 30 | Q_OBJECT |
460 | 27 | Q_PROPERTY(bool listUpdating READ listUpdating NOTIFY listUpdatingChanged) | ||
461 | 28 | Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) | ||
462 | 29 | Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) | ||
463 | 30 | Q_ENUMS(Roles) | 31 | Q_ENUMS(Roles) |
464 | 31 | |||
465 | 32 | public: | 32 | public: |
466 | 33 | explicit TimeZoneLocationModel(QObject *parent = nullptr); | 33 | explicit TimeZoneLocationModel(QObject *parent = nullptr); |
468 | 34 | ~TimeZoneLocationModel(); | 34 | ~TimeZoneLocationModel() = default; |
469 | 35 | 35 | ||
470 | 36 | enum Roles { | 36 | enum Roles { |
471 | 37 | TimeZoneRole = Qt::UserRole + 1, | 37 | TimeZoneRole = Qt::UserRole + 1, |
472 | @@ -43,11 +43,56 @@ | |||
473 | 43 | LongitudeRole | 43 | LongitudeRole |
474 | 44 | }; | 44 | }; |
475 | 45 | 45 | ||
476 | 46 | struct TzLocationWizard { | ||
477 | 47 | QString city; | ||
478 | 48 | QString country; | ||
479 | 49 | QString timezone; | ||
480 | 50 | QString state; | ||
481 | 51 | QString full_country; | ||
482 | 52 | double latitude; | ||
483 | 53 | double longitude; | ||
484 | 54 | }; | ||
485 | 55 | |||
486 | 46 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | 56 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
487 | 47 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | 57 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
488 | 48 | QHash<int, QByteArray> roleNames() const override; | 58 | QHash<int, QByteArray> roleNames() const override; |
489 | 49 | 59 | ||
491 | 50 | bool listUpdating() const; | 60 | private Q_SLOTS: |
492 | 61 | void processModelResult(const TzLocationWizard &location); | ||
493 | 62 | void store(); | ||
494 | 63 | |||
495 | 64 | private: | ||
496 | 65 | void init(); | ||
497 | 66 | QHash<int, QByteArray> m_roleNames; | ||
498 | 67 | QList<TzLocationWizard> m_locations; | ||
499 | 68 | TimeZonePopulateWorker *m_workerThread; | ||
500 | 69 | }; | ||
501 | 70 | |||
502 | 71 | Q_DECLARE_METATYPE (TimeZoneLocationModel::TzLocationWizard) | ||
503 | 72 | |||
504 | 73 | class TimeZonePopulateWorker: public QThread | ||
505 | 74 | { | ||
506 | 75 | Q_OBJECT | ||
507 | 76 | public: | ||
508 | 77 | void run() override; | ||
509 | 78 | |||
510 | 79 | Q_SIGNALS: | ||
511 | 80 | void resultReady(const TimeZoneLocationModel::TzLocationWizard &tz); | ||
512 | 81 | |||
513 | 82 | private: | ||
514 | 83 | void buildCityMap(); | ||
515 | 84 | }; | ||
516 | 85 | |||
517 | 86 | class TimeZoneFilterModel: public QSortFilterProxyModel | ||
518 | 87 | { | ||
519 | 88 | Q_OBJECT | ||
520 | 89 | Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) | ||
521 | 90 | Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) | ||
522 | 91 | |||
523 | 92 | public: | ||
524 | 93 | explicit TimeZoneFilterModel(QObject *parent = nullptr); | ||
525 | 94 | ~TimeZoneFilterModel() = default; | ||
526 | 95 | bool filterAcceptsRow(int row, const QModelIndex &parentIndex) const override; | ||
527 | 51 | 96 | ||
528 | 52 | QString filter() const; | 97 | QString filter() const; |
529 | 53 | void setFilter(const QString &filter); | 98 | void setFilter(const QString &filter); |
530 | @@ -56,25 +101,13 @@ | |||
531 | 56 | void setCountry(const QString &country); | 101 | void setCountry(const QString &country); |
532 | 57 | 102 | ||
533 | 58 | Q_SIGNALS: | 103 | Q_SIGNALS: |
534 | 59 | void listUpdatingChanged(); | ||
535 | 60 | void filterChanged(); | 104 | void filterChanged(); |
536 | 61 | void countryChanged(const QString &country); | 105 | void countryChanged(const QString &country); |
537 | 62 | 106 | ||
538 | 63 | private: | 107 | private: |
539 | 64 | void setModel(const QList<GeonamesCity *> &locations); | ||
540 | 65 | void setListUpdating(bool listUpdating); | ||
541 | 66 | static void filterFinished(GObject *source_object, | ||
542 | 67 | GAsyncResult *res, | ||
543 | 68 | gpointer user_data); | ||
544 | 69 | |||
545 | 70 | |||
546 | 71 | bool m_listUpdating; | ||
547 | 72 | QString m_filter; | 108 | QString m_filter; |
548 | 109 | QStringMatcher m_stringMatcher; | ||
549 | 73 | QString m_country; | 110 | QString m_country; |
550 | 74 | GCancellable *m_cancellable; | ||
551 | 75 | QHash<int, QByteArray> m_roleNames; | ||
552 | 76 | QList<GeonamesCity *> m_locations; | ||
553 | 77 | QList<GeonamesCity *> m_countryLocations; | ||
554 | 78 | }; | 111 | }; |
555 | 79 | 112 | ||
556 | 80 | #endif | 113 | #endif |
557 | 81 | 114 | ||
558 | === modified file 'qml/Wizard/Pages.qml' | |||
559 | --- qml/Wizard/Pages.qml 2016-03-22 09:09:22 +0000 | |||
560 | +++ qml/Wizard/Pages.qml 2016-03-22 09:09:23 +0000 | |||
561 | @@ -34,12 +34,23 @@ | |||
562 | 34 | property int passwordMethod: UbuntuSecurityPrivacyPanel.Passphrase | 34 | property int passwordMethod: UbuntuSecurityPrivacyPanel.Passphrase |
563 | 35 | property string password: "" | 35 | property string password: "" |
564 | 36 | 36 | ||
565 | 37 | property string countryCode: "US" // default country (for the timezone page) | ||
566 | 37 | property bool seenSIMPage: false // we want to see the SIM page at most once | 38 | property bool seenSIMPage: false // we want to see the SIM page at most once |
567 | 38 | 39 | ||
568 | 39 | property alias modemManager: modemManager | 40 | property alias modemManager: modemManager |
569 | 40 | property alias simManager0: simManager0 | 41 | property alias simManager0: simManager0 |
570 | 41 | property alias simManager1: simManager1 | 42 | property alias simManager1: simManager1 |
571 | 42 | 43 | ||
572 | 44 | TimeZoneModel { // preload the heavy models | ||
573 | 45 | id: tzModel | ||
574 | 46 | } | ||
575 | 47 | |||
576 | 48 | TimeZoneFilterModel { | ||
577 | 49 | id: tzFilterModel | ||
578 | 50 | sourceModel: tzModel | ||
579 | 51 | country: countryCode | ||
580 | 52 | } | ||
581 | 53 | |||
582 | 43 | theme: ThemeSettings { | 54 | theme: ThemeSettings { |
583 | 44 | name: "Ubuntu.Components.Themes.Ambiance" | 55 | name: "Ubuntu.Components.Themes.Ambiance" |
584 | 45 | } | 56 | } |
585 | 46 | 57 | ||
586 | === modified file 'qml/Wizard/Pages/10-welcome.qml' | |||
587 | --- qml/Wizard/Pages/10-welcome.qml 2016-03-22 09:09:22 +0000 | |||
588 | +++ qml/Wizard/Pages/10-welcome.qml 2016-03-22 09:09:23 +0000 | |||
589 | @@ -157,6 +157,7 @@ | |||
590 | 157 | System.updateSessionLocale(plugin.languageCodes[plugin.currentLanguage]); | 157 | System.updateSessionLocale(plugin.languageCodes[plugin.currentLanguage]); |
591 | 158 | } | 158 | } |
592 | 159 | i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change) | 159 | i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change) |
593 | 160 | root.countryCode = plugin.languageCodes[plugin.currentLanguage].split('_')[1].split('.')[0]; // extract the country code, save it for the timezone page | ||
594 | 160 | 161 | ||
595 | 161 | if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 || | 162 | if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 || |
596 | 162 | (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) || | 163 | (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) || |
597 | 163 | 164 | ||
598 | === modified file 'qml/Wizard/Pages/50-timezone.qml' | |||
599 | --- qml/Wizard/Pages/50-timezone.qml 2016-03-22 09:09:22 +0000 | |||
600 | +++ qml/Wizard/Pages/50-timezone.qml 2016-03-22 09:09:23 +0000 | |||
601 | @@ -87,6 +87,8 @@ | |||
602 | 87 | } | 87 | } |
603 | 88 | 88 | ||
604 | 89 | resetViews(); | 89 | resetViews(); |
605 | 90 | tzFilterModel.filter = Qt.binding(function() { return searchField.text; }); | ||
606 | 91 | tzFilterModel.invalidate(); | ||
607 | 90 | searchField.forceActiveFocus(); | 92 | searchField.forceActiveFocus(); |
608 | 91 | } | 93 | } |
609 | 92 | } | 94 | } |
610 | @@ -188,21 +190,9 @@ | |||
611 | 188 | anchors.left: parent.left | 190 | anchors.left: parent.left |
612 | 189 | anchors.right: parent.right | 191 | anchors.right: parent.right |
613 | 190 | currentIndex: -1 | 192 | currentIndex: -1 |
619 | 191 | model: TimeZoneModel { | 193 | model: tzFilterModel |
615 | 192 | id: timeZoneModel | ||
616 | 193 | filter: searchField.text | ||
617 | 194 | country: i18n.language.split('_')[1].split('.')[0] | ||
618 | 195 | } | ||
620 | 196 | delegate: tzComponent | 194 | delegate: tzComponent |
621 | 197 | } | 195 | } |
622 | 198 | |||
623 | 199 | ActivityIndicator { | ||
624 | 200 | anchors.centerIn: tzList | ||
625 | 201 | running: tzList.count == 0 && | ||
626 | 202 | searchField.length > 0 && | ||
627 | 203 | timeZoneModel.listUpdating | ||
628 | 204 | visible: running | ||
629 | 205 | } | ||
630 | 206 | } | 196 | } |
631 | 207 | 197 | ||
632 | 208 | Item { | 198 | Item { |
633 | 209 | 199 | ||
634 | === modified file 'qml/Wizard/Pages/passcode-confirm.qml' | |||
635 | --- qml/Wizard/Pages/passcode-confirm.qml 2016-03-22 09:09:22 +0000 | |||
636 | +++ qml/Wizard/Pages/passcode-confirm.qml 2016-03-22 09:09:23 +0000 | |||
637 | @@ -37,7 +37,8 @@ | |||
638 | 37 | UnityComponents.Lockscreen { | 37 | UnityComponents.Lockscreen { |
639 | 38 | id: lockscreen | 38 | id: lockscreen |
640 | 39 | anchors { | 39 | anchors { |
642 | 40 | fill: content | 40 | fill: parent |
643 | 41 | topMargin: customMargin | ||
644 | 41 | } | 42 | } |
645 | 42 | 43 | ||
646 | 43 | infoText: i18n.tr("Confirm passcode") | 44 | infoText: i18n.tr("Confirm passcode") |
647 | 44 | 45 | ||
648 | === modified file 'qml/Wizard/Pages/passcode-set.qml' | |||
649 | --- qml/Wizard/Pages/passcode-set.qml 2016-03-22 09:09:22 +0000 | |||
650 | +++ qml/Wizard/Pages/passcode-set.qml 2016-03-22 09:09:23 +0000 | |||
651 | @@ -48,7 +48,8 @@ | |||
652 | 48 | UnityComponents.Lockscreen { | 48 | UnityComponents.Lockscreen { |
653 | 49 | id: lockscreen | 49 | id: lockscreen |
654 | 50 | anchors { | 50 | anchors { |
656 | 51 | fill: content | 51 | fill: parent |
657 | 52 | topMargin: customMargin | ||
658 | 52 | } | 53 | } |
659 | 53 | 54 | ||
660 | 54 | infoText: i18n.tr("Choose passcode") | 55 | infoText: i18n.tr("Choose passcode") |
661 | 55 | 56 | ||
662 | === modified file 'tests/mocks/Wizard/CMakeLists.txt' | |||
663 | --- tests/mocks/Wizard/CMakeLists.txt 2016-03-22 09:09:22 +0000 | |||
664 | +++ tests/mocks/Wizard/CMakeLists.txt 2016-03-22 09:09:23 +0000 | |||
665 | @@ -1,5 +1,7 @@ | |||
666 | 1 | pkg_search_module(TIMEZONEMAP REQUIRED timezonemap) | ||
667 | 2 | |||
668 | 1 | include_directories( | 3 | include_directories( |
670 | 2 | ${GLIB_INCLUDE_DIRS} ${GEONAMES_INCLUDE_DIRS} | 4 | ${GLIB_INCLUDE_DIRS} ${TIMEZONEMAP_INCLUDE_DIRS} |
671 | 3 | ${CMAKE_SOURCE_DIR}/plugins/Wizard | 5 | ${CMAKE_SOURCE_DIR}/plugins/Wizard |
672 | 4 | ) | 6 | ) |
673 | 5 | 7 | ||
674 | @@ -13,5 +15,5 @@ | |||
675 | 13 | ) | 15 | ) |
676 | 14 | 16 | ||
677 | 15 | qt5_use_modules(MockWizard-qml DBus Qml Concurrent) | 17 | qt5_use_modules(MockWizard-qml DBus Qml Concurrent) |
679 | 16 | target_link_libraries(MockWizard-qml ${GLIB_LDFLAGS} ${GEONAMES_LDFLAGS}) | 18 | target_link_libraries(MockWizard-qml ${GLIB_LDFLAGS} ${TIMEZONEMAP_LDFLAGS}) |
680 | 17 | add_unity8_mock(Wizard 0.1 Wizard TARGETS MockWizard-qml) | 19 | add_unity8_mock(Wizard 0.1 Wizard TARGETS MockWizard-qml) |
681 | 18 | 20 | ||
682 | === modified file 'tests/mocks/Wizard/mockplugin.cpp' | |||
683 | --- tests/mocks/Wizard/mockplugin.cpp 2016-03-22 09:09:22 +0000 | |||
684 | +++ tests/mocks/Wizard/mockplugin.cpp 2016-03-22 09:09:23 +0000 | |||
685 | @@ -30,5 +30,6 @@ | |||
686 | 30 | qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new MockSystem; }); | 30 | qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new MockSystem; }); |
687 | 31 | qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; }); | 31 | qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; }); |
688 | 32 | qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel"); | 32 | qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel"); |
689 | 33 | qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel"); | ||
690 | 33 | qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin"); | 34 | qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin"); |
691 | 34 | } | 35 | } |
The changes in qml/Wizard/ Pages/passcode- confirm. qml and qml/Wizard/ Pages/passcode- set.qml are unrelated and undesired here.