Merge lp:~mterry/ubuntu-system-settings/timezone-name into lp:ubuntu-system-settings

Proposed by Michael Terry
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 1634
Merged at revision: 1661
Proposed branch: lp:~mterry/ubuntu-system-settings/timezone-name
Merge into: lp:ubuntu-system-settings
Diff against target: 245 lines (+69/-25)
7 files modified
debian/changelog (+6/-0)
debian/control (+1/-0)
plugins/time-date/ChooseTimeZone.qml (+3/-3)
plugins/time-date/PageComponent.qml (+2/-3)
plugins/time-date/plugin.cpp (+1/-1)
plugins/time-date/timedate.cpp (+47/-15)
plugins/time-date/timedate.h (+9/-3)
To merge this branch: bzr merge lp:~mterry/ubuntu-system-settings/timezone-name
Reviewer Review Type Date Requested Status
Lukáš Tinkl (community) Approve
Jonas G. Drange (community) Approve
Review via email: mp+291041@code.launchpad.net

Commit message

Show user-friendly city name for the timezone.

Description of the change

Use existing timezone-name gsettings field to store a user-friendly version of the timezone. This is a strategy already used on the desktop. This branch just brings it to Touch too.

https://code.launchpad.net/~mterry/unity8/timezone-name/+merge/291042 should land at the same. I don't know of any other consumers.

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

Since we're currently not getting any debs from ci, Michael, could you create arm debs either manually, in a silo (silo preferred so we can test both changes together?).

Revision history for this message
Michael Terry (mterry) wrote :

OK, check silo 33. It also has the geonames translation support (so when searching for timezones, you can see localized city names). But that's unrelated to this MP. Just a silo bonus.

Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

This is great. Currently, if I select the city “Bergen”, the tz is set to “Europe/Oslo”. Silo 33 presents the tz as “Bergen +2”.

Thanks!

review: Approve
Revision history for this message
Lukáš Tinkl (lukas-kde) wrote :

Worked well in my testing too (in silo 33)

review: Approve
Revision history for this message
Lukáš Tinkl (lukas-kde) wrote :

Minor nitpick:

QString TimeDate::timeZoneName()

should be const

Revision history for this message
Michael Terry (mterry) wrote :

But if it's const, it can't call initializeTimeZone. Maybe lazily-initializing the timezone info isn't worth the const-uncleanliness... But I figured I'd follow timeZone()'s lead here.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2016-03-25 20:53:47 +0000
3+++ debian/changelog 2016-04-05 20:30:13 +0000
4@@ -1,3 +1,9 @@
5+ubuntu-system-settings (0.4+16.04.20160325-0ubuntu1) UNRELEASED; urgency=medium
6+
7+ * Bump version number for change in TimeDate plugin API
8+
9+ -- Michael Terry <mterry@ubuntu.com> Tue, 05 Apr 2016 15:16:11 -0400
10+
11 ubuntu-system-settings (0.3+16.04.20160325-0ubuntu1) xenial; urgency=medium
12
13 * Bump Ubuntu.Content import to 1.3 to prevent mixed version imports
14
15=== modified file 'debian/control'
16--- debian/control 2016-03-23 08:46:51 +0000
17+++ debian/control 2016-04-05 20:30:13 +0000
18@@ -72,6 +72,7 @@
19 gsettings-desktop-schemas,
20 gsettings-ubuntu-schemas (>= 0.0.4),
21 indicator-bluetooth (>> 0.0.6+13.10.20131010),
22+ indicator-datetime,
23 indicator-network (>= 0.7.1),
24 indicator-power (>= 12.10.6+15.04.20150130),
25 powerd (>= 0.15) | gnome-settings-daemon,
26
27=== modified file 'plugins/time-date/ChooseTimeZone.qml'
28--- plugins/time-date/ChooseTimeZone.qml 2015-10-16 13:42:50 +0000
29+++ plugins/time-date/ChooseTimeZone.qml 2016-04-05 20:30:13 +0000
30@@ -22,7 +22,7 @@
31 import SystemSettings 1.0
32 import Ubuntu.Components 1.3
33 import Ubuntu.Components.ListItems 1.3 as ListItem
34-import Ubuntu.SystemSettings.TimeDate 1.0
35+import Ubuntu.SystemSettings.TimeDate 1.1
36
37 ItemPage {
38 title: i18n.tr("Time zone")
39@@ -54,7 +54,7 @@
40
41 ListItem.Standard {
42 anchors.top: setTimeZoneSelector.bottom
43- text: timeDatePanel.timeZone
44+ text: timeDatePanel.timeZoneName
45 enabled: false
46 visible: showAllUI && setTimeZoneSelector.selectedIndex == 0 // Automatically
47 }
48@@ -103,7 +103,7 @@
49 // are highlighted.
50 onClicked: {
51 locationsListView.manuallySelected = displayName
52- timeDatePanel.timeZone = timeZone
53+ timeDatePanel.setTimeZone(timeZone, city);
54 }
55 selected: locationsListView.manuallySelected === "" ?
56 timeDatePanel.timeZone == timeZone :
57
58=== modified file 'plugins/time-date/PageComponent.qml'
59--- plugins/time-date/PageComponent.qml 2015-10-16 13:42:50 +0000
60+++ plugins/time-date/PageComponent.qml 2016-04-05 20:30:13 +0000
61@@ -23,7 +23,7 @@
62 import Ubuntu.Components 1.3
63 import Ubuntu.Components.ListItems 1.3 as ListItem
64 import Ubuntu.Components.Popups 1.3
65-import Ubuntu.SystemSettings.TimeDate 1.0
66+import Ubuntu.SystemSettings.TimeDate 1.1
67
68 ItemPage {
69 id: root
70@@ -65,8 +65,7 @@
71 ListItem.SingleValue {
72 objectName: "timeZone"
73 id: timeZone
74- //e.g. America/New_York -> America/New York
75- text: timeDatePanel.timeZone.replace("_", " ")
76+ text: timeDatePanel.timeZoneName
77 value: getUTCOffset()
78 progression: true
79 onClicked: pageStack.push(Qt.resolvedUrl("ChooseTimeZone.qml"), {
80
81=== modified file 'plugins/time-date/plugin.cpp'
82--- plugins/time-date/plugin.cpp 2014-07-23 13:53:48 +0000
83+++ plugins/time-date/plugin.cpp 2016-04-05 20:30:13 +0000
84@@ -29,7 +29,7 @@
85 {
86 Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.TimeDate"));
87
88- qmlRegisterType<TimeDate>(uri, 1, 0, "UbuntuTimeDatePanel");
89+ qmlRegisterType<TimeDate>(uri, 1, 1, "UbuntuTimeDatePanel");
90 }
91
92 void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
93
94=== modified file 'plugins/time-date/timedate.cpp'
95--- plugins/time-date/timedate.cpp 2016-02-23 20:23:18 +0000
96+++ plugins/time-date/timedate.cpp 2016-04-05 20:30:13 +0000
97@@ -37,6 +37,7 @@
98 "/org/freedesktop/timedate1",
99 "org.freedesktop.timedate1",
100 m_systemBusConnection),
101+ m_indicatorSettings(g_settings_new("com.canonical.indicator.datetime")),
102 m_timeZoneModel()
103 {
104 connect (&m_serviceWatcher,
105@@ -68,19 +69,35 @@
106 QString TimeDate::timeZone()
107 {
108 if (m_currentTimeZone.isEmpty() || m_currentTimeZone.isNull())
109- m_currentTimeZone = getTimeZone();
110+ initializeTimeZone();
111
112 return m_currentTimeZone;
113 }
114
115-QString TimeDate::getTimeZone()
116-{
117- QVariant tz(m_timeDateInterface.property("Timezone"));
118-
119- if (tz.isValid())
120- return tz.toString();
121-
122- return QString();
123+QString TimeDate::timeZoneName()
124+{
125+ if (m_currentTimeZoneName.isEmpty() || m_currentTimeZoneName.isNull())
126+ initializeTimeZone();
127+
128+ return m_currentTimeZoneName;
129+}
130+
131+void TimeDate::initializeTimeZone()
132+{
133+ // Get timezone from authoritative source
134+ m_currentTimeZone = m_timeDateInterface.property("Timezone").toString();
135+ if (m_currentTimeZone.isEmpty())
136+ return;
137+
138+ // And get saved user-visible name if we have one
139+ g_autofree gchar *gtzname = g_settings_get_string(m_indicatorSettings, "timezone-name");
140+ QString tzname(gtzname);
141+ int space = tzname.indexOf(' ');
142+ if (space > 0 && tzname.left(space) == m_currentTimeZone && tzname.size() > space + 1) {
143+ m_currentTimeZoneName = tzname.mid(space + 1);
144+ } else {
145+ m_currentTimeZoneName = m_currentTimeZone.split('/').last().replace('_', ' ');
146+ }
147 }
148
149 bool TimeDate::useNTP()
150@@ -114,10 +131,7 @@
151
152 if (changed_properties.contains("Timezone")) {
153 QString tz(changed_properties["Timezone"].toString());
154- if (tz != m_currentTimeZone) {
155- m_currentTimeZone = tz;
156- Q_EMIT timeZoneChanged();
157- }
158+ setTimeZone(tz);
159 }
160
161 if (changed_properties.contains("NTP")) {
162@@ -143,9 +157,26 @@
163 setUpInterface();
164 }
165
166-void TimeDate::setTimeZone(QString &time_zone)
167+void TimeDate::setTimeZone(const QString &time_zone, const QString &time_zone_name)
168 {
169- m_timeDateInterface.call("SetTimezone", time_zone, false);
170+ if (m_currentTimeZone != time_zone ||
171+ (!time_zone_name.isEmpty() && m_currentTimeZoneName != time_zone_name))
172+ {
173+ auto name = time_zone_name;
174+ if (name.isEmpty())
175+ name = time_zone.split('/').last().replace('_', ' ');
176+
177+ auto reply = m_timeDateInterface.call("SetTimezone", time_zone, false);
178+ if (reply.errorName().isEmpty()) {
179+ m_currentTimeZone = time_zone;
180+ m_currentTimeZoneName = name;
181+
182+ auto combined = QString("%1 %2").arg(time_zone, name);
183+ g_settings_set_string(m_indicatorSettings, "timezone-name", combined.toUtf8().data());
184+
185+ Q_EMIT timeZoneChanged();
186+ }
187+ }
188 }
189
190 QAbstractItemModel *TimeDate::getTimeZoneModel()
191@@ -175,4 +206,5 @@
192 }
193
194 TimeDate::~TimeDate() {
195+ g_clear_object (&m_indicatorSettings);
196 }
197
198=== modified file 'plugins/time-date/timedate.h'
199--- plugins/time-date/timedate.h 2014-12-08 17:28:29 +0000
200+++ plugins/time-date/timedate.h 2016-04-05 20:30:13 +0000
201@@ -28,13 +28,16 @@
202 #include <QDBusServiceWatcher>
203 #include <QObject>
204 #include <QProcess>
205+#include <gio/gio.h>
206
207 class TimeDate : public QObject
208 {
209 Q_OBJECT
210 Q_PROPERTY (QString timeZone
211 READ timeZone
212- WRITE setTimeZone
213+ NOTIFY timeZoneChanged)
214+ Q_PROPERTY (QString timeZoneName
215+ READ timeZoneName
216 NOTIFY timeZoneChanged)
217 Q_PROPERTY (QAbstractItemModel *timeZoneModel
218 READ getTimeZoneModel
219@@ -53,8 +56,9 @@
220 public:
221 explicit TimeDate(QObject *parent = 0);
222 ~TimeDate();
223- void setTimeZone (QString &time_zone);
224+ Q_INVOKABLE void setTimeZone (const QString &time_zone, const QString &time_zone_name = QString());
225 QString timeZone();
226+ QString timeZoneName();
227 bool useNTP();
228 QAbstractItemModel *getTimeZoneModel();
229 QString getFilter();
230@@ -76,13 +80,15 @@
231 private:
232 bool m_useNTP;
233 QString m_currentTimeZone;
234+ QString m_currentTimeZoneName;
235 QDBusConnection m_systemBusConnection;
236 QDBusServiceWatcher m_serviceWatcher;
237 QDBusInterface m_timeDateInterface;
238+ GSettings *m_indicatorSettings;
239 QString m_objectPath;
240 TimeZoneLocationModel m_timeZoneModel;
241 QString m_filter;
242- QString getTimeZone();
243+ void initializeTimeZone();
244 bool getUseNTP();
245 void setUpInterface();
246

Subscribers

People subscribed via source and target branches