Merge lp:~jonas-drange/ubuntu-system-settings/lp1492260 into lp:ubuntu-system-settings

Proposed by Jonas G. Drange
Status: Merged
Approved by: Ken VanDine
Approved revision: 1534
Merged at revision: 1531
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/lp1492260
Merge into: lp:ubuntu-system-settings
Diff against target: 177 lines (+37/-29)
4 files modified
plugins/time-date/ChooseTimeZone.qml (+4/-2)
plugins/time-date/PageComponent.qml (+3/-1)
plugins/time-date/timezonelocationmodel.cpp (+23/-20)
plugins/time-date/timezonelocationmodel.h (+7/-6)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-system-settings/lp1492260
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+270541@code.launchpad.net

Commit message

[time-date] Migrate threaded code to worker-object pattern, move sorting to a worker thread from the GUI thread, and only instantiate UbuntuTimeDatePanel plugin once.

Description of the change

NOTE: When you select a city/timezone, exit the panel and then re-enter it; there's a bug where it looks like more than one timezone is selected. This was not introduced by this branch and has been filed here, bug 1494860.

* Sorting of tz list ran in the main thread (this was the main contributor to the ui blockage). Sorting now happens in a separate thread.
* We're no longer sublassing QThread per recommendation from QT, instead we use a worker-object pattern.
* The UbuntuTimeDatePanel plugin was instantiated twice which, so the timezone map build was run twice. The plugin is now transferred from PageComponent to ChooseTimeZone via pagestack.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

The TZ failure in the last run was real, but should be fixed in r1534. A new CI run has started.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Excellent work, looks good and works well!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/time-date/ChooseTimeZone.qml'
2--- plugins/time-date/ChooseTimeZone.qml 2014-06-11 13:05:23 +0000
3+++ plugins/time-date/ChooseTimeZone.qml 2015-09-11 14:56:13 +0000
4@@ -27,13 +27,15 @@
5 ItemPage {
6 title: i18n.tr("Time zone")
7
8+ property UbuntuTimeDatePanel timeDatePanel
9+
10 Timer {
11 id: goBackTimer
12 onTriggered: pageStack.pop()
13 }
14
15- UbuntuTimeDatePanel {
16- id: timeDatePanel
17+ Connections {
18+ target: timeDatePanel
19 onTimeZoneChanged: {
20 // Protect against the tz being changed externally
21 if (locationsListView.manuallySelected !== "")
22
23=== modified file 'plugins/time-date/PageComponent.qml'
24--- plugins/time-date/PageComponent.qml 2015-08-04 18:14:04 +0000
25+++ plugins/time-date/PageComponent.qml 2015-09-11 14:56:13 +0000
26@@ -69,7 +69,9 @@
27 text: timeDatePanel.timeZone.replace("_", " ")
28 value: getUTCOffset()
29 progression: true
30- onClicked: pageStack.push(Qt.resolvedUrl("ChooseTimeZone.qml"))
31+ onClicked: pageStack.push(Qt.resolvedUrl("ChooseTimeZone.qml"), {
32+ timeDatePanel: timeDatePanel
33+ })
34 }
35
36 SettingsItemTitle {
37
38=== modified file 'plugins/time-date/timezonelocationmodel.cpp'
39--- plugins/time-date/timezonelocationmodel.cpp 2015-05-12 12:10:57 +0000
40+++ plugins/time-date/timezonelocationmodel.cpp 2015-09-11 14:56:13 +0000
41@@ -29,36 +29,40 @@
42 QAbstractTableModel(parent),
43 modelUpdating(true),
44 m_pattern(),
45- m_workerThread(new TimeZonePopulateWorker()),
46+ m_workerThread(new QThread()),
47+ m_populateWorker(new TimeZonePopulateWorker()),
48 m_watcher()
49 {
50 qRegisterMetaType<TzLocation>();
51+ qRegisterMetaType<QList<TimeZoneLocationModel::TzLocation> >();
52
53 QObject::connect(m_workerThread,
54+ SIGNAL(started()),
55+ m_populateWorker,
56+ SLOT(run()));
57+ QObject::connect(m_populateWorker,
58 &TimeZonePopulateWorker::resultReady,
59 this,
60- &TimeZoneLocationModel::processModelResult);
61- QObject::connect(m_workerThread,
62- &TimeZonePopulateWorker::finished,
63- this,
64 &TimeZoneLocationModel::store);
65 QObject::connect(m_workerThread,
66- &TimeZonePopulateWorker::finished,
67+ SIGNAL(finished()),
68 m_workerThread,
69- &QObject::deleteLater);
70- QObject::connect(m_workerThread,
71- &TimeZonePopulateWorker::finished,
72- this,
73- &TimeZoneLocationModel::modelUpdated);
74+ SLOT(deleteLater()));
75+ QObject::connect(m_populateWorker,
76+ SIGNAL(finished()),
77+ m_populateWorker,
78+ SLOT(deleteLater()));
79
80- m_workerThread->start();
81+ m_populateWorker->moveToThread(m_workerThread);
82+ m_workerThread->start(QThread::IdlePriority);
83 }
84
85-void TimeZoneLocationModel::store()
86+void TimeZoneLocationModel::store(QList<TzLocation> sortedLocations)
87 {
88+ m_originalLocations = sortedLocations;
89 m_workerThread = nullptr;
90 modelUpdating = false;
91- qSort(m_originalLocations.begin(), m_originalLocations.end());
92+
93 QObject::connect(&m_watcher,
94 &QFutureWatcher<TzLocation>::finished,
95 this,
96@@ -68,11 +72,6 @@
97 filter(m_pattern);
98 }
99
100-void TimeZoneLocationModel::processModelResult(TzLocation location)
101-{
102- m_originalLocations.append(location);
103-}
104-
105 void TimeZoneLocationModel::setModel(QList<TzLocation> locations)
106 {
107 beginResetModel();
108@@ -190,10 +189,12 @@
109 void TimeZonePopulateWorker::run()
110 {
111 buildCityMap();
112+ emit finished();
113 }
114
115 void TimeZonePopulateWorker::buildCityMap()
116 {
117+ QList<TimeZoneLocationModel::TzLocation> locations;
118 TzDB *tzdb = tz_load_db();
119 GPtrArray *tz_locations = tz_get_locations(tzdb);
120
121@@ -222,9 +223,11 @@
122 g_free (state);
123 g_free (full_country);
124
125- Q_EMIT (resultReady(tmpTz));
126+ locations.append(tmpTz);
127 }
128
129+ qSort(locations.begin(), locations.end());
130+ Q_EMIT (resultReady(locations));
131 g_ptr_array_free (tz_locations, TRUE);
132 }
133
134
135=== modified file 'plugins/time-date/timezonelocationmodel.h'
136--- plugins/time-date/timezonelocationmodel.h 2014-07-23 13:53:48 +0000
137+++ plugins/time-date/timezonelocationmodel.h 2015-09-11 14:56:13 +0000
138@@ -76,8 +76,7 @@
139 void modelUpdated();
140
141 public Q_SLOTS:
142- void processModelResult(TzLocation);
143- void store();
144+ void store(QList<TzLocation> sortedLocations);
145 void filterFinished();
146
147 private:
148@@ -85,7 +84,8 @@
149 QList<TzLocation> m_originalLocations;
150 QString m_pattern;
151
152- TimeZonePopulateWorker *m_workerThread;
153+ QThread *m_workerThread;
154+ TimeZonePopulateWorker *m_populateWorker;
155
156 bool substringFilter(const QString& input);
157 QFutureWatcher<TzLocation> m_watcher;
158@@ -94,15 +94,16 @@
159
160 Q_DECLARE_METATYPE (TimeZoneLocationModel::TzLocation)
161
162-class TimeZonePopulateWorker : public QThread
163+class TimeZonePopulateWorker : public QObject
164 {
165 Q_OBJECT
166
167-public:
168+public slots:
169 void run();
170
171 Q_SIGNALS:
172- void resultReady(TimeZoneLocationModel::TzLocation);
173+ void resultReady(const QList<TimeZoneLocationModel::TzLocation> &sortedList);
174+ void finished();
175
176 private:
177 void buildCityMap();

Subscribers

People subscribed via source and target branches