Merge lp:~larsu/indicator-datetime/dont-use-gdbusproxy into lp:indicator-datetime/15.10

Proposed by Lars Karlitski
Status: Rejected
Rejected by: Charles Kerr
Proposed branch: lp:~larsu/indicator-datetime/dont-use-gdbusproxy
Merge into: lp:indicator-datetime/15.10
Prerequisite: lp:~laney/indicator-datetime/timedated-timezone-property
Diff against target: 184 lines (+35/-107)
1 file modified
src/timezone-timedated.cpp (+35/-107)
To merge this branch: bzr merge lp:~larsu/indicator-datetime/dont-use-gdbusproxy
Reviewer Review Type Date Requested Status
Charles Kerr (community) Needs Resubmitting
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+270081@code.launchpad.net

Commit message

Use timedated's Timezone property to find out the current timezone and learn about changes to it

Description of the change

Use timedated's Timezone property to find out the current timezone and learn about changes to it

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Oh, this is quite nice. Thank you!

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :
review: Needs Resubmitting

Unmerged revisions

426. By Lars Karlitski

timezone-timedated: subscribe to PropertiesChanged directly

This avoids some unnecessary calls that GDBusProxy makes and the name
watching.

425. By Iain Lane

Make test-live-actions quit itself once the tz has been changed, the mock no longer does this

424. By Iain Lane

Avoid nested GMainLoops by reading from the file on startup

Restore some tests for this functionality.

423. By Iain Lane

Add some comments

422. By Iain Lane

Rename FileTimezone to TimedatedTimezone

421. By Iain Lane

Add a timeout so we can't hang forever

420. By Iain Lane

Use timedated's Timezone property instead of watching /etc/timezone

Still need to rename everything to not use "timezone-file"

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/timezone-timedated.cpp'
2--- src/timezone-timedated.cpp 2015-09-03 16:10:18 +0000
3+++ src/timezone-timedated.cpp 2015-09-03 16:10:18 +0000
4@@ -53,112 +53,42 @@
5
6 void clear()
7 {
8- if (m_bus_watch_id)
9- {
10- g_bus_unwatch_name (m_bus_watch_id);
11- m_bus_watch_id = 0;
12- }
13-
14- if (m_properties_changed_id)
15- {
16- g_signal_handler_disconnect(m_proxy, m_properties_changed_id);
17- m_properties_changed_id = 0;
18- }
19-
20- g_clear_object(&m_proxy);
21+ if (m_connection && m_signal_subscription_id)
22+ {
23+ g_dbus_connection_signal_unsubscribe (m_connection, m_signal_subscription_id);
24+ m_signal_subscription_id = 0;
25+ }
26+
27+ g_clear_object(&m_connection);
28 }
29
30- static void on_properties_changed(GDBusProxy *proxy G_GNUC_UNUSED,
31- GVariant *changed_properties /* a{sv} */,
32- GStrv invalidated_properties G_GNUC_UNUSED,
33+ static void on_properties_changed (GDBusConnection *connection G_GNUC_UNUSED,
34+ const gchar *sender_name G_GNUC_UNUSED,
35+ const gchar *object_path G_GNUC_UNUSED,
36+ const gchar *interface_name G_GNUC_UNUSED,
37+ const gchar *signal_name G_GNUC_UNUSED,
38+ GVariant *parameters,
39 gpointer gself)
40 {
41 auto self = static_cast<Impl*>(gself);
42- char *tz;
43-
44- if (g_variant_lookup(changed_properties, "Timezone", "s", &tz, NULL))
45- {
46- g_debug("on_properties_changed: got timezone '%s'", tz);
47+ const char *tz;
48+ GVariant *changed_properties;
49+ gchar **invalidated_properties;
50+
51+ g_variant_get (parameters, "(s@a{sv}^as)", NULL, &changed_properties, &invalidated_properties);
52+
53+ if (g_variant_lookup(changed_properties, "Timezone", "&s", &tz, NULL))
54 self->notify_timezone(tz);
55- g_free (tz);
56- }
57- }
58-
59- static void on_proxy_ready(GObject *object G_GNUC_UNUSED,
60- GAsyncResult *res,
61- gpointer gself)
62- {
63- auto self = static_cast<Impl*>(gself);
64- GError *error = nullptr;
65- self->m_proxy = g_dbus_proxy_new_finish(res, &error);
66-
67- if (error)
68- {
69- g_warning ("Couldn't create proxy to read timezone: %s", error->message);
70- goto out;
71- }
72-
73- /* Read the property */
74- GVariant *prop;
75- prop = g_dbus_proxy_get_cached_property(self->m_proxy, "Timezone");
76-
77- if (!prop || !g_variant_is_of_type(prop, G_VARIANT_TYPE_STRING))
78- {
79- g_warning("Couldn't read the Timezone property, defaulting to Etc/Utc");
80- self->notify_timezone("Etc/Utc");
81- goto out;
82- }
83-
84- const gchar *tz;
85- tz = g_variant_get_string(prop, nullptr);
86-
87- self->notify_timezone(tz);
88-
89- self->m_properties_changed_id = g_signal_connect(self->m_proxy,
90- "g-properties-changed",
91- (GCallback) on_properties_changed,
92- gself);
93-
94-out:
95- g_clear_pointer(&error, g_error_free);
96- g_clear_pointer(&prop, g_variant_unref);
97- }
98-
99- static void on_name_appeared(GDBusConnection *connection,
100- const gchar *name,
101- const gchar *name_owner G_GNUC_UNUSED,
102- gpointer gself G_GNUC_UNUSED)
103- {
104- g_debug ("timedate1 appeared");
105- g_dbus_proxy_new(connection,
106- G_DBUS_PROXY_FLAGS_NONE,
107- NULL,
108- name,
109- "/org/freedesktop/timedate1",
110- "org.freedesktop.timedate1",
111- nullptr,
112- on_proxy_ready,
113- gself);
114- }
115-
116- static void on_name_vanished(GDBusConnection *connection G_GNUC_UNUSED,
117- const gchar *name G_GNUC_UNUSED,
118- gpointer gself)
119- {
120- auto self = static_cast<Impl*>(gself);
121- g_debug ("timedate1 vanished");
122-
123- g_signal_handler_disconnect(self->m_proxy,
124- self->m_properties_changed_id);
125- self->m_properties_changed_id = 0;
126- g_clear_object(&self->m_proxy);
127- g_clear_pointer(&self->m_proxy, g_main_loop_unref);
128+ else if (g_strv_contains (invalidated_properties, "Timezone"))
129+ self->notify_timezone(self->get_timezone_from_file(self->m_filename));
130+
131+ g_variant_unref (changed_properties);
132+ g_strfreev (invalidated_properties);
133 }
134
135 void monitor_timezone_property()
136 {
137 GError *err = nullptr;
138- GDBusConnection *conn;
139
140 /*
141 * There is an unlikely race which happens if there is an activation
142@@ -170,7 +100,7 @@
143 * Make sure the bus is around at least until we add the match rules,
144 * otherwise things (tests) are sad.
145 */
146- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM,
147+ m_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM,
148 nullptr,
149 &err);
150
151@@ -181,15 +111,14 @@
152 return;
153 }
154
155- m_bus_watch_id = g_bus_watch_name_on_connection(conn,
156+ m_signal_subscription_id = g_dbus_connection_signal_subscribe(m_connection,
157 "org.freedesktop.timedate1",
158- G_BUS_NAME_WATCHER_FLAGS_NONE,
159- on_name_appeared,
160- on_name_vanished,
161- this,
162- nullptr);
163-
164- g_object_unref (conn);
165+ "org.freedesktop.DBus.Properties",
166+ "PropertiesChanged",
167+ "/org/freedesktop/timedate1",
168+ NULL, G_DBUS_SIGNAL_FLAGS_NONE,
169+ on_properties_changed,
170+ this, nullptr);
171 }
172
173 void notify_timezone(std::string new_timezone)
174@@ -256,9 +185,8 @@
175 ***/
176
177 TimedatedTimezone & m_owner;
178- unsigned long m_properties_changed_id = 0;
179- unsigned long m_bus_watch_id = 0;
180- GDBusProxy *m_proxy = nullptr;
181+ GDBusConnection *m_connection = nullptr;
182+ unsigned long m_signal_subscription_id = 0;
183 std::string m_filename;
184 };
185

Subscribers

People subscribed via source and target branches