Merge lp:~cjcurran/indicator-session/delay-apt-interaction into lp:indicator-session/0.1

Proposed by Conor Curran
Status: Merged
Approved by: Ted Gould
Approved revision: 212
Merged at revision: 212
Proposed branch: lp:~cjcurran/indicator-session/delay-apt-interaction
Merge into: lp:indicator-session/0.1
Diff against target: 282 lines (+112/-88)
1 file modified
src/apt-watcher.c (+112/-88)
To merge this branch: bzr merge lp:~cjcurran/indicator-session/delay-apt-interaction
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+75376@code.launchpad.net

Description of the change

fixes three bugs, reboot required label is supposed to be 'Restart to complete updates ...", reboot required signal property update signal was not being listened and now the apt interaction does not occur until 60 secs after start up"

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/apt-watcher.c'
2--- src/apt-watcher.c 2011-09-07 20:20:42 +0000
3+++ src/apt-watcher.c 2011-09-14 16:21:23 +0000
4@@ -71,10 +71,8 @@
5 gpointer user_data);
6 static void apt_watcher_transaction_state_real_update_cb (AptTransaction* trans,
7 gint update,
8- gpointer user_data);
9-
10-
11-
12+ gpointer user_data);
13+static gboolean apt_watcher_start_apt_interaction (gpointer data);
14
15 G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT);
16
17@@ -85,7 +83,17 @@
18 self->proxy_cancel = g_cancellable_new();
19 self->proxy = NULL;
20 self->reboot_query = 0;
21- self->current_transaction = NULL;
22+ self->current_transaction = NULL;
23+ g_timeout_add_seconds (60,
24+ apt_watcher_start_apt_interaction,
25+ self);
26+}
27+
28+static gboolean
29+apt_watcher_start_apt_interaction (gpointer data)
30+{
31+ g_return_val_if_fail (APT_IS_WATCHER (data), FALSE);
32+ AptWatcher* self = APT_WATCHER (data);
33 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
34 G_DBUS_PROXY_FLAGS_NONE,
35 NULL,
36@@ -95,6 +103,7 @@
37 self->proxy_cancel,
38 fetch_proxy_cb,
39 self);
40+ return FALSE;
41 }
42
43 static void
44@@ -154,7 +163,6 @@
45 self);
46 }
47
48-
49 static void
50 apt_watcher_on_name_appeared (GDBusConnection *connection,
51 const gchar *name,
52@@ -169,6 +177,8 @@
53 "the system bus",
54 name_owner);
55
56+ apt_watcher_query_reboot_status (user_data);
57+
58 g_dbus_proxy_call (watcher->proxy,
59 "UpgradeSystem",
60 g_variant_new("(b)", TRUE),
61@@ -176,9 +186,10 @@
62 -1,
63 NULL,
64 apt_watcher_upgrade_system_cb,
65- user_data);
66+ user_data);
67 }
68
69+
70 static void
71 apt_watcher_on_name_vanished (GDBusConnection *connection,
72 const gchar *name,
73@@ -261,60 +272,52 @@
74 AptWatcher* self = APT_WATCHER (user_data);
75
76 AptState state = (AptState)update;
77-
78- if (state == UP_TO_DATE){
79- dbusmenu_menuitem_property_set (self->apt_item,
80- DBUSMENU_MENUITEM_PROP_LABEL,
81- _("Software Up to Date"));
82- self->current_state = state;
83- }
84- else if (state == UPDATES_AVAILABLE){
85- dbusmenu_menuitem_property_set (self->apt_item,
86- DBUSMENU_MENUITEM_PROP_LABEL,
87- _("Updates Available…"));
88- self->current_state = state;
89- }
90- else if (state == UPGRADE_IN_PROGRESS){
91- dbusmenu_menuitem_property_set (self->apt_item,
92- DBUSMENU_MENUITEM_PROP_LABEL,
93- _("Updates Installing…"));
94- self->current_state = state;
95- }
96- else if (state == FINISHED){
97- gboolean query_again = FALSE;
98-
99- // Only query if the previous state was an upgrade.
100- if (self->current_state == UPGRADE_IN_PROGRESS){
101- if (self->reboot_query != 0){
102- g_source_remove (self->reboot_query);
103- self->reboot_query = 0;
104- }
105- // Wait a sec before querying for reboot status,
106- // race condition with Apt has been observed.
107- self->reboot_query = g_timeout_add_seconds (2,
108- apt_watcher_query_reboot_status,
109- self);
110- }
111- else{
112- query_again = TRUE;
113- }
114- self->current_state = state;
115-
116- g_object_unref (G_OBJECT(self->current_transaction));
117- self->current_transaction = NULL;
118-
119- // It is impossible to determine from a 'real' transaction whether
120- // updates are available ?
121- if (query_again){
122- g_dbus_proxy_call (self->proxy,
123- "UpgradeSystem",
124- g_variant_new("(b)", TRUE),
125- G_DBUS_CALL_FLAGS_NONE,
126- -1,
127- NULL,
128- apt_watcher_upgrade_system_cb,
129- self);
130- }
131+ if (self->current_state != RESTART_NEEDED)
132+ {
133+ if (state == UP_TO_DATE){
134+ dbusmenu_menuitem_property_set (self->apt_item,
135+ DBUSMENU_MENUITEM_PROP_LABEL,
136+ _("Software Up to Date"));
137+ self->current_state = state;
138+ }
139+ else if (state == UPDATES_AVAILABLE){
140+ dbusmenu_menuitem_property_set (self->apt_item,
141+ DBUSMENU_MENUITEM_PROP_LABEL,
142+ _("Updates Available…"));
143+ self->current_state = state;
144+ }
145+ else if (state == UPGRADE_IN_PROGRESS){
146+ dbusmenu_menuitem_property_set (self->apt_item,
147+ DBUSMENU_MENUITEM_PROP_LABEL,
148+ _("Updates Installing…"));
149+ self->current_state = state;
150+ }
151+ else if (state == FINISHED){
152+ gboolean query_again = FALSE;
153+
154+ // Only query if the previous state was an upgrade.
155+ if (self->current_state != UPGRADE_IN_PROGRESS){
156+ query_again = TRUE;
157+ }
158+ self->current_state = state;
159+
160+ g_object_unref (G_OBJECT(self->current_transaction));
161+ self->current_transaction = NULL;
162+
163+ // It is impossible to determine from a 'real' transaction whether
164+ // updates are available therefore it is necessary to check again via a
165+ // simulation whether there are updates available.
166+ if (query_again){
167+ g_dbus_proxy_call (self->proxy,
168+ "UpgradeSystem",
169+ g_variant_new("(b)", TRUE),
170+ G_DBUS_CALL_FLAGS_NONE,
171+ -1,
172+ NULL,
173+ apt_watcher_upgrade_system_cb,
174+ self);
175+ }
176+ }
177 }
178 }
179
180@@ -329,32 +332,32 @@
181 AptWatcher* self = APT_WATCHER (user_data);
182
183 AptState state = (AptState)update;
184-
185- if (state == UP_TO_DATE){
186- dbusmenu_menuitem_property_set (self->apt_item,
187- DBUSMENU_MENUITEM_PROP_LABEL,
188- _("Software Up to Date"));
189- if (self->reboot_query != 0){
190- g_source_remove (self->reboot_query);
191- self->reboot_query = 0;
192- }
193- self->reboot_query = g_timeout_add_seconds (2,
194- apt_watcher_query_reboot_status,
195- self);
196- }
197- else if (state == UPDATES_AVAILABLE){
198- dbusmenu_menuitem_property_set (self->apt_item,
199- DBUSMENU_MENUITEM_PROP_LABEL,
200- _("Updates Available…"));
201- }
202- else if (state == UPGRADE_IN_PROGRESS){
203- dbusmenu_menuitem_property_set (self->apt_item,
204- DBUSMENU_MENUITEM_PROP_LABEL,
205- _("Updates Installing…"));
206+ if (self->current_state != RESTART_NEEDED)
207+ {
208+ if (state == UP_TO_DATE){
209+ dbusmenu_menuitem_property_set (self->apt_item,
210+ DBUSMENU_MENUITEM_PROP_LABEL,
211+ _("Software Up to Date"));
212+ if (self->reboot_query != 0){
213+ g_source_remove (self->reboot_query);
214+ self->reboot_query = 0;
215+ }
216+ self->reboot_query = g_timeout_add_seconds (1,
217+ apt_watcher_query_reboot_status,
218+ self);
219+ }
220+ else if (state == UPDATES_AVAILABLE){
221+ dbusmenu_menuitem_property_set (self->apt_item,
222+ DBUSMENU_MENUITEM_PROP_LABEL,
223+ _("Updates Available…"));
224+ }
225+ else if (state == UPGRADE_IN_PROGRESS){
226+ dbusmenu_menuitem_property_set (self->apt_item,
227+ DBUSMENU_MENUITEM_PROP_LABEL,
228+ _("Updates Installing…"));
229+ }
230+ self->current_state = state;
231 }
232-
233- self->current_state = state;
234-
235 if (self->current_state != UPGRADE_IN_PROGRESS){
236 g_object_unref (G_OBJECT(self->current_transaction));
237 self->current_transaction = NULL;
238@@ -383,7 +386,6 @@
239 gboolean reboot;
240 g_variant_get (reboot_result, "b", &reboot);
241 g_debug ("apt_watcher_query_reboot_status: reboot prop = %i", reboot);
242-
243 if (reboot == FALSE){
244 dbusmenu_menuitem_property_set (self->apt_item,
245 DBUSMENU_MENUITEM_PROP_LABEL,
246@@ -396,7 +398,7 @@
247 else{
248 dbusmenu_menuitem_property_set (self->apt_item,
249 DBUSMENU_MENUITEM_PROP_LABEL,
250- _("Reboot Required"));
251+ _("Restart to complete updates…"));
252 dbusmenu_menuitem_property_set (self->apt_item,
253 DBUSMENU_MENUITEM_PROP_DISPOSITION,
254 DBUSMENU_MENUITEM_DISPOSITION_ALERT);
255@@ -446,6 +448,28 @@
256 G_CALLBACK(apt_watcher_transaction_state_real_update_cb), self);
257 }
258 }
259+ else if (g_strcmp0(signal_name, "PropertyChanged") == 0)
260+ {
261+ gchar* prop_name= NULL;
262+ GVariant* value = NULL;
263+ g_variant_get (parameters, "(sv)", &prop_name, &value);
264+ g_debug ("transaction prop update - prop = %s", prop_name);
265+
266+ if (g_strcmp0 (prop_name, "RebootRequired") == 0){
267+ gboolean reboot_required = FALSE;
268+ g_variant_get (value, "(b)", &reboot_required);
269+ if (reboot_required){
270+ dbusmenu_menuitem_property_set (self->apt_item,
271+ DBUSMENU_MENUITEM_PROP_LABEL,
272+ _("Restart to complete updates…"));
273+ dbusmenu_menuitem_property_set (self->apt_item,
274+ DBUSMENU_MENUITEM_PROP_DISPOSITION,
275+ DBUSMENU_MENUITEM_DISPOSITION_ALERT);
276+ self->current_state = RESTART_NEEDED;
277+ }
278+ }
279+ }
280+
281 g_variant_unref (parameters);
282 }
283

Subscribers

People subscribed via source and target branches