on xenial help sign in
Use u-s-s plugin rather than our own code
commitb12b21372edc7b703aca48e84f15bca02d805e21 authorMichael Terry <michael.terry@canonical.com> dateWed 24 Feb 2016, 14:56 (11 years ago) parentae1f4f5
10 files changed+5−373
debian/control−1 plugins/Wizard/CMakeLists.txt+2−5 plugins/Wizard/plugin.cpp−3 plugins/Wizard/timezonemodel.cpp−228 plugins/Wizard/timezonemodel.h−113 qml/Wizard/Pages.qml−11 qml/Wizard/Pages/10-welcome.qml−1 qml/Wizard/Pages/50-timezone.qml+2−3 tests/mocks/Wizard/CMakeLists.txt+1−5 tests/mocks/Wizard/mockplugin.cpp−3
debian/control−1
@@ -28,7 +28,6 @@ Build-Depends: cmake,
2828 libqt5svg5-dev,
2929 libqt5xmlpatterns5-dev,
3030 libsystemsettings-dev,
31− libtimezonemap1-dev,
3231 libudev-dev,
3332 libunity-api-dev (>= 7.106),
3433 libusermetricsoutput1-dev,
plugins/Wizard/CMakeLists.txt+2−5
@@ -1,18 +1,15 @@
1−pkg_search_module(TIMEZONEMAP REQUIRED timezonemap)
2−
3−include_directories(${GLIB_INCLUDE_DIRS} ${TIMEZONEMAP_INCLUDE_DIRS})
1+include_directories(${GLIB_INCLUDE_DIRS})
42
53add_library(Wizard-qml MODULE
64 plugin.cpp
75 PageList.cpp
86 System.cpp
97 LocalePlugin.cpp
10− timezonemodel.cpp
118 Status.cpp
129)
1310
1411qt5_use_modules(Wizard-qml DBus Qml Concurrent)
15−target_link_libraries(Wizard-qml ${GLIB_LDFLAGS} ${TIMEZONEMAP_LDFLAGS})
12+target_link_libraries(Wizard-qml ${GLIB_LDFLAGS})
1613add_unity8_plugin(Wizard 0.1 Wizard TARGETS Wizard-qml)
1714
1815set(POLKIT_LIB_DIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/polkit-1")
plugins/Wizard/plugin.cpp−3
@@ -17,7 +17,6 @@
1717#include "plugin.h"
1818#include "PageList.h"
1919#include "System.h"
20−#include "timezonemodel.h"
2120#include "LocalePlugin.h"
2221#include "Status.h"
2322
@@ -29,7 +28,5 @@ void WizardPlugin::registerTypes(const char *uri)
2928 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
3029 qmlRegisterSingletonType<System>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new System; });
3130 qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; });
32− qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel");
33− qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
3431 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
3532}
plugins/Wizard/timezonemodel.cppdeleted−228
@@ -1,228 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it
5− * under the terms of the GNU General Public License version 3, as published
6− * by the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but
9− * WITHOUT ANY WARRANTY; without even the implied warranties of
10− * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11− * PURPOSE. See the GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License along
14− * with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include <QDebug>
18−
19−#include <glib.h>
20−#include <glib-object.h>
21−#include <timezonemap/tz.h>
22−
23−#include "LocalePlugin.h"
24−#include "timezonemodel.h"
25−
26−TimeZoneLocationModel::TimeZoneLocationModel(QObject *parent):
27− QAbstractListModel(parent),
28− m_workerThread(new TimeZonePopulateWorker())
29−{
30− qRegisterMetaType<TzLocationWizard>();
31−
32− m_roleNames[Qt::DisplayRole] = "displayName";
33− m_roleNames[TimeZoneRole] = "timeZone";
34− m_roleNames[CityRole] = "city";
35− m_roleNames[CountryRole] = "country";
36− m_roleNames[OffsetRole] = "offset";
37− m_roleNames[LatitudeRole] = "latitude";
38− m_roleNames[LongitudeRole] = "longitude";
39−
40− QObject::connect(m_workerThread,
41− &TimeZonePopulateWorker::resultReady,
42− this,
43− &TimeZoneLocationModel::processModelResult);
44− QObject::connect(m_workerThread,
45− &TimeZonePopulateWorker::finished,
46− this,
47− &TimeZoneLocationModel::store);
48− QObject::connect(m_workerThread,
49− &TimeZonePopulateWorker::finished,
50− m_workerThread,
51− &QObject::deleteLater);
52−
53− init();
54−}
55−
56−void TimeZoneLocationModel::init()
57−{
58− beginResetModel();
59− m_workerThread->start();
60−}
61−
62−void TimeZoneLocationModel::store()
63−{
64− m_workerThread = nullptr;
65− endResetModel();
66−}
67−
68−void TimeZoneLocationModel::processModelResult(const TzLocationWizard &location)
69−{
70− m_locations.append(location);
71−}
72−
73−int TimeZoneLocationModel::rowCount(const QModelIndex &parent) const
74−{
75− if (parent.isValid())
76− return 0;
77− return m_locations.count();
78−}
79−
80−QVariant TimeZoneLocationModel::data(const QModelIndex &index, int role) const
81−{
82− if (index.row() >= m_locations.count() || index.row() < 0)
83− return QVariant();
84−
85− const TzLocationWizard tz = m_locations.at(index.row());
86−
87− const QString country(tz.full_country.isEmpty() ? tz.country : tz.full_country);
88−
89− switch (role) {
90− case Qt::DisplayRole:
91− if (!tz.state.isEmpty())
92− return QStringLiteral("%1, %2, %3").arg(tz.city).arg(tz.state).arg(country);
93− else
94− return QStringLiteral("%1, %2").arg(tz.city).arg(country);
95− case SimpleRole:
96− return QStringLiteral("%1, %2").arg(tz.city).arg(country);
97− case TimeZoneRole:
98− return tz.timezone;
99− case CountryRole:
100− return tz.country;
101− case CityRole:
102− return tz.city;
103− case OffsetRole: {
104− QTimeZone tmp(tz.timezone.toLatin1());
105− return static_cast<double>(tmp.standardTimeOffset(QDateTime::currentDateTime())) / 3600;
106− }
107− case LatitudeRole:
108− return tz.latitude;
109− case LongitudeRole:
110− return tz.longitude;
111− default:
112− qWarning() << Q_FUNC_INFO << "Unknown role";
113− return QVariant();
114− }
115−}
116−
117−QHash<int, QByteArray> TimeZoneLocationModel::roleNames() const
118−{
119− return m_roleNames;
120−}
121−
122−void TimeZonePopulateWorker::run()
123−{
124− buildCityMap();
125−}
126−
127−void TimeZonePopulateWorker::buildCityMap()
128−{
129− TzDB *tzdb = tz_load_db();
130− GPtrArray *tz_locations = tz_get_locations(tzdb);
131−
132− TimeZoneLocationModel::TzLocationWizard tmpTz;
133−
134− for (guint i = 0; i < tz_locations->len; ++i) {
135− auto tmp = static_cast<CcTimezoneLocation *>(g_ptr_array_index(tz_locations, i));
136− gchar *en_name, *country, *zone, *state, *full_country;
137− gdouble latitude;
138− gdouble longitude;
139− g_object_get (tmp, "en_name", &en_name,
140− "country", &country,
141− "zone", &zone,
142− "state", &state,
143− "full_country", &full_country,
144− "latitude", &latitude,
145− "longitude", &longitude,
146− nullptr);
147− // There are empty entries in the DB
148− if (g_strcmp0(en_name, "") != 0) {
149− tmpTz.city = en_name;
150− tmpTz.country = country;
151− tmpTz.timezone = zone;
152− tmpTz.state = state;
153− tmpTz.full_country = full_country;
154− tmpTz.latitude = latitude;
155− tmpTz.longitude = longitude;
156−
157− Q_EMIT (resultReady(tmpTz));
158− }
159− g_free (en_name);
160− g_free (country);
161− g_free (zone);
162− g_free (state);
163− g_free (full_country);
164− }
165−
166− g_ptr_array_free (tz_locations, TRUE);
167− tz_db_free(tzdb);
168−}
169−
170−
171−TimeZoneFilterModel::TimeZoneFilterModel(QObject *parent)
172− : QSortFilterProxyModel(parent)
173−{
174− setDynamicSortFilter(false);
175− setSortLocaleAware(true);
176− setSortRole(TimeZoneLocationModel::CityRole);
177− m_stringMatcher.setCaseSensitivity(Qt::CaseInsensitive);
178− sort(0);
179−}
180−
181−bool TimeZoneFilterModel::filterAcceptsRow(int row, const QModelIndex &parentIndex) const
182−{
183− if (!sourceModel()) {
184− return true;
185− }
186−
187− if (!m_filter.isEmpty()) { // filtering by freeform text input, cf setFilter(QString)
188− const QString city = sourceModel()->index(row, 0, parentIndex).data(TimeZoneLocationModel::CityRole).toString();
189−
190− if (m_stringMatcher.indexIn(city) == 0) { // match at the beginning of the city name
191− return true;
192− }
193− } else if (!m_country.isEmpty()) { // filter by country code
194− const QString countryCode = sourceModel()->index(row, 0, parentIndex).data(TimeZoneLocationModel::CountryRole).toString();
195− return m_country.compare(countryCode, Qt::CaseInsensitive) == 0;
196− }
197−
198− return false;
199−}
200−
201−QString TimeZoneFilterModel::filter() const
202−{
203− return m_filter;
204−}
205−
206−void TimeZoneFilterModel::setFilter(const QString &filter)
207−{
208− if (filter != m_filter) {
209− m_filter = filter;
210− m_stringMatcher.setPattern(m_filter);
211− Q_EMIT filterChanged();
212− invalidate();
213− }
214−}
215−
216−QString TimeZoneFilterModel::country() const
217−{
218− return m_country;
219−}
220−
221−void TimeZoneFilterModel::setCountry(const QString &country)
222−{
223− if (m_country == country)
224− return;
225−
226− m_country = country;
227− Q_EMIT countryChanged(country);
228−}
plugins/Wizard/timezonemodel.hdeleted−113
@@ -1,113 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it
5− * under the terms of the GNU General Public License version 3, as published
6− * by the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but
9− * WITHOUT ANY WARRANTY; without even the implied warranties of
10− * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11− * PURPOSE. See the GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License along
14− * with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef TIMEZONEMODEL_H
18−#define TIMEZONEMODEL_H
19−
20−#include <QAbstractListModel>
21−#include <QSortFilterProxyModel>
22−#include <QThread>
23−#include <QtConcurrent>
24−#include <QtGui/QImage>
25−
26−class TimeZonePopulateWorker;
27−
28−class TimeZoneLocationModel: public QAbstractListModel
29−{
30− Q_OBJECT
31− Q_ENUMS(Roles)
32−public:
33− explicit TimeZoneLocationModel(QObject *parent = nullptr);
34− ~TimeZoneLocationModel() = default;
35−
36− enum Roles {
37− TimeZoneRole = Qt::UserRole + 1,
38− CityRole,
39− CountryRole,
40− SimpleRole,
41− OffsetRole,
42− LatitudeRole,
43− LongitudeRole
44− };
45−
46− struct TzLocationWizard {
47− QString city;
48− QString country;
49− QString timezone;
50− QString state;
51− QString full_country;
52− double latitude;
53− double longitude;
54− };
55−
56− int rowCount(const QModelIndex &parent = QModelIndex()) const override;
57− QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
58− QHash<int, QByteArray> roleNames() const override;
59−
60−private Q_SLOTS:
61− void processModelResult(const TzLocationWizard &location);
62− void store();
63−
64−private:
65− void init();
66− QHash<int, QByteArray> m_roleNames;
67− QList<TzLocationWizard> m_locations;
68− TimeZonePopulateWorker *m_workerThread;
69−};
70−
71−Q_DECLARE_METATYPE (TimeZoneLocationModel::TzLocationWizard)
72−
73−class TimeZonePopulateWorker: public QThread
74−{
75− Q_OBJECT
76−public:
77− void run() override;
78−
79−Q_SIGNALS:
80− void resultReady(const TimeZoneLocationModel::TzLocationWizard &tz);
81−
82−private:
83− void buildCityMap();
84−};
85−
86−class TimeZoneFilterModel: public QSortFilterProxyModel
87−{
88− Q_OBJECT
89− Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
90− Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged)
91−
92−public:
93− explicit TimeZoneFilterModel(QObject *parent = nullptr);
94− ~TimeZoneFilterModel() = default;
95− bool filterAcceptsRow(int row, const QModelIndex &parentIndex) const override;
96−
97− QString filter() const;
98− void setFilter(const QString &filter);
99−
100− QString country() const;
101− void setCountry(const QString &country);
102−
103−Q_SIGNALS:
104− void filterChanged();
105− void countryChanged(const QString &country);
106−
107−private:
108− QString m_filter;
109− QStringMatcher m_stringMatcher;
110− QString m_country;
111−};
112−
113−#endif
qml/Wizard/Pages.qml−11
@@ -34,23 +34,12 @@ Item {
3434 property int passwordMethod: UbuntuSecurityPrivacyPanel.Passphrase
3535 property string password: ""
3636
37− property string countryCode: "US" // default country (for the timezone page)
3837 property bool seenSIMPage: false // we want to see the SIM page at most once
3938
4039 property alias modemManager: modemManager
4140 property alias simManager0: simManager0
4241 property alias simManager1: simManager1
4342
44− TimeZoneModel { // preload the heavy models
45− id: tzModel
46− }
47−
48− TimeZoneFilterModel {
49− id: tzFilterModel
50− sourceModel: tzModel
51− country: countryCode
52− }
53−
5443 UbuntuSecurityPrivacyPanel {
5544 id: securityPrivacy
5645 objectName: "securityPrivacy"
qml/Wizard/Pages/10-welcome.qml−1
@@ -155,7 +155,6 @@ LocalComponents.Page {
155155 System.updateSessionLocale(plugin.languageCodes[plugin.currentLanguage]);
156156 }
157157 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
158− root.countryCode = plugin.languageCodes[plugin.currentLanguage].split('_')[1].split('.')[0]; // extract the country code, save it for the timezone page
159158
160159 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
161160 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
qml/Wizard/Pages/50-timezone.qml+2−3
@@ -87,8 +87,7 @@ LocalComponents.Page {
8787 }
8888
8989 resetViews();
90− tzFilterModel.filter = Qt.binding(function() { return searchField.text; });
91− tzFilterModel.invalidate();
90+ timeDatePanel.filter = Qt.binding(function() { return searchField.text; });
9291 theme.palette.normal.backgroundText = "#cdcdcd";
9392 searchField.forceActiveFocus();
9493 }
@@ -205,7 +204,7 @@ LocalComponents.Page {
205204 objectName: "tzList"
206205 clip: true
207206 currentIndex: -1
208− model: tzFilterModel
207+ model: timeDatePanel.timeZoneModel
209208 delegate: tzComponent
210209 }
211210 }
tests/mocks/Wizard/CMakeLists.txt+1−5
@@ -1,7 +1,4 @@
1−pkg_search_module(TIMEZONEMAP REQUIRED timezonemap)
2−
31include_directories(
4− ${GLIB_INCLUDE_DIRS} ${TIMEZONEMAP_INCLUDE_DIRS}
52 ${CMAKE_SOURCE_DIR}/plugins/Wizard
63)
74
@@ -9,11 +6,10 @@ add_library(MockWizard-qml MODULE
96 mockplugin.cpp
107 MockSystem.cpp
118 ${CMAKE_SOURCE_DIR}/plugins/Wizard/PageList.cpp
12− ${CMAKE_SOURCE_DIR}/plugins/Wizard/timezonemodel.cpp
139 ${CMAKE_SOURCE_DIR}/plugins/Wizard/LocalePlugin.cpp
1410 ${CMAKE_SOURCE_DIR}/plugins/Wizard/Status.cpp
1511)
1612
1713qt5_use_modules(MockWizard-qml DBus Qml Concurrent)
18−target_link_libraries(MockWizard-qml ${GLIB_LDFLAGS} ${TIMEZONEMAP_LDFLAGS})
14+target_link_libraries(MockWizard-qml ${GLIB_LDFLAGS})
1915add_unity8_mock(Wizard 0.1 Wizard TARGETS MockWizard-qml)
tests/mocks/Wizard/mockplugin.cpp−3
@@ -17,7 +17,6 @@
1717#include "mockplugin.h"
1818#include "MockSystem.h"
1919#include "PageList.h"
20−#include "timezonemodel.h"
2120#include "LocalePlugin.h"
2221#include "Status.h"
2322
@@ -29,7 +28,5 @@ void MockWizardPlugin::registerTypes(const char *uri)
2928 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
3029 qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new MockSystem; });
3130 qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; });
32− qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel");
33− qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
3431 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
3532}