Merge lp:~larsu/indicator-power/use-gsettings-actions into lp:indicator-power/14.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Lars Karlitski
Approved revision: 218
Merged at revision: 217
Proposed branch: lp:~larsu/indicator-power/use-gsettings-actions
Merge into: lp:indicator-power/14.04
Diff against target: 125 lines (+10/-69)
1 file modified
src/service.c (+10/-69)
To merge this branch: bzr merge lp:~larsu/indicator-power/use-gsettings-actions
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Allison Karlitskaya (community) Approve
Sebastien Bacher Approve
Review via email: mp+197066@code.launchpad.net

Description of the change

Use GSettingsActions instead of g_settings_bind

This also fixes a bug: the actions were created stateless, but assigned a state later.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

looks fine to me, works/fixes the issue with glib 2.39 as well

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Allison Karlitskaya (desrt) wrote :

Looks pretty good -- but the fact that you're keeping the action around is suspicious. Can you look into that? Either it's being used in a way that would be valid for a GSimpleAction but not a GSettingsAction or it's not being used at all... Maybe there is more code that can be cut...

218. By Lars Karlitski

Don't keep GSettingsActions around

They were only kept around so that a notify handler could be disconnected.
Since the GSettings object is the canonical source of that data, it makes more
sense to listen to changes there instead of on the action objects.

That was already done for the one remaining key in the schema. This patch
changes that to rebuild the header when any key changes.

Revision history for this message
Allison Karlitskaya (desrt) wrote :

+ g_signal_connect_swapped (p->settings, "changed", G_CALLBACK(rebuild_header_now), self);

Strictly speaking, you should be disconnecting this...

Revision history for this message
Allison Karlitskaya (desrt) wrote :

...and you already are. Sorry -- misread the patch and didn't see that you were simply modifying an existing connection to the same object.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/service.c'
2--- src/service.c 2013-11-08 17:23:15 +0000
3+++ src/service.c 2013-11-29 15:40:05 +0000
4@@ -113,8 +113,6 @@
5
6 GSimpleActionGroup * actions;
7 GSimpleAction * header_action;
8- GSimpleAction * show_time_action;
9- GSimpleAction * show_percentage_action;
10 GSimpleAction * battery_level_action;
11 GSimpleAction * brightness_action;
12
13@@ -715,39 +713,12 @@
14 ****
15 ***/
16
17-/* toggles the state */
18-static void
19-on_toggle_action_activated (GSimpleAction * simple,
20- GVariant * parameter G_GNUC_UNUSED,
21- gpointer unused G_GNUC_UNUSED)
22-{
23- GVariant * v = g_action_get_state (G_ACTION (simple));
24- gboolean flag = g_variant_get_boolean (v);
25- g_simple_action_set_state (simple, g_variant_new_boolean (!flag));
26- g_variant_unref (v);
27-}
28-
29-static gboolean
30-settings_to_action_state (GValue * value,
31- GVariant * variant,
32- gpointer user_data G_GNUC_UNUSED)
33-{
34- g_value_set_variant (value, variant);
35- return TRUE;
36-}
37-
38-static GVariant *
39-action_state_to_settings (const GValue * value,
40- const GVariantType * expected_type G_GNUC_UNUSED,
41- gpointer user_data G_GNUC_UNUSED)
42-{
43- return g_value_dup_variant (value);
44-}
45-
46 static void
47 init_gactions (IndicatorPowerService * self)
48 {
49 GSimpleAction * a;
50+ GAction * show_time_action;
51+ GAction * show_percentage_action;
52 priv_t * p = self->priv;
53
54 GActionEntry entries[] = {
55@@ -781,32 +752,17 @@
56 p->brightness_action = a;
57
58 /* add the show-time action */
59- a = g_simple_action_new ("show-time", NULL);
60- g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_TIME_S,
61- a, "state",
62- G_SETTINGS_BIND_DEFAULT,
63- settings_to_action_state,
64- action_state_to_settings,
65- NULL, NULL);
66- g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self);
67- g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self);
68- g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a));
69- p->show_time_action = a;
70+ show_time_action = g_settings_create_action (p->settings, "show-time");
71+ g_action_map_add_action (G_ACTION_MAP(p->actions), show_time_action);
72
73 /* add the show-percentage action */
74- a = g_simple_action_new ("show-percentage", NULL);
75- g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_PERCENTAGE_S,
76- a, "state",
77- G_SETTINGS_BIND_DEFAULT,
78- settings_to_action_state,
79- action_state_to_settings,
80- NULL, NULL);
81- g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self);
82- g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self);
83- g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a));
84- p->show_percentage_action = a;
85+ show_percentage_action = g_settings_create_action (p->settings, "show-percentage");
86+ g_action_map_add_action (G_ACTION_MAP(p->actions), show_percentage_action);
87
88 rebuild_header_now (self);
89+
90+ g_object_unref (show_time_action);
91+ g_object_unref (show_percentage_action);
92 }
93
94 /***
95@@ -1009,20 +965,6 @@
96 g_clear_object (&p->settings);
97 }
98
99- if (p->show_time_action != NULL)
100- {
101- g_signal_handlers_disconnect_by_data (p->show_time_action, self);
102-
103- g_clear_object (&p->show_time_action);
104- }
105-
106- if (p->show_percentage_action != NULL)
107- {
108- g_signal_handlers_disconnect_by_data (p->show_percentage_action, self);
109-
110- g_clear_object (&p->show_percentage_action);
111- }
112-
113 g_clear_object (&p->brightness_action);
114 g_clear_object (&p->battery_level_action);
115 g_clear_object (&p->header_action);
116@@ -1057,8 +999,7 @@
117
118 init_gactions (self);
119
120- g_signal_connect_swapped (p->settings, "changed::" SETTINGS_ICON_POLICY_S,
121- G_CALLBACK(rebuild_header_now), self);
122+ g_signal_connect_swapped (p->settings, "changed", G_CALLBACK(rebuild_header_now), self);
123
124 p->own_id = g_bus_own_name (G_BUS_TYPE_SESSION,
125 BUS_NAME,

Subscribers

People subscribed via source and target branches