Merge lp:~amigadave/gnome-control-center-signon/switch-mockup into lp:gnome-control-center-signon

Proposed by David King
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 143
Merged at revision: 134
Proposed branch: lp:~amigadave/gnome-control-center-signon/switch-mockup
Merge into: lp:gnome-control-center-signon
Diff against target: 294 lines (+173/-28)
3 files modified
src/cc-credentials-account-applications-model.vala (+5/-1)
src/cc-credentials-account-details-page.vala (+151/-23)
src/cc-credentials-accounts-model.vala (+17/-4)
To merge this branch: bzr merge lp:~amigadave/gnome-control-center-signon/switch-mockup
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+147624@code.launchpad.net

Commit message

Add switches to toggle the enabled state for application (really services)

Description of the change

Add switches to toggle the enabled state for application (really services)

* Add a non-functional switch to each application row
* Add an empty application switch activated handler
* Implement application service switch handler
* Use asynchronous store methods in AccountDetailsPage
* Avoid storing the account when a store is in progress
* Avoid unnecessarily changing the account enabled state in the UI

To post a comment you must log in.
Revision history for this message
Alberto Mardegan (mardy) wrote :

I will test the functionality soon. Meanwhile, I have a couple of suggestions about the code, which shouldn't affect the functionality.

73 + // Fetch current state from service.
74 + current_account.select_service (service);
75 + app_switch.active = current_account.get_enabled ();
76 + current_account.select_service (null);
77 +
78 + acc_service.set_data ("switch", app_switch);
79 + acc_service.enabled.connect (on_app_account_service_enabled);

This code (as well as on_app_account_service_enabled()), fits better inside the AccountApplicationSwitch class (maybe in the constructor).

246 + // Ignore service-level changes.
247 + // FIXME: http://code.google.com/p/accounts-sso/issues/detail?id=157
248 + if (service != "global")
249 + {
250 + return;
251 + }

Check the indentation (it appears correct here, but see the diff below). Also, in order to continue working when the libaccounts-glib issue is fixed, add a check for "null" as well.

review: Needs Fixing
Revision history for this message
Alberto Mardegan (mardy) wrote :

There is one bug: if you take an account which has only one service (identi.ca, for example) and disable the service, then disable the global account, you'll see that the global account is still enabled (you can use account-console to verify that).

The other issue is that when you disable the global account, all services are disabled. It's actually a UI preference, but I'd like better if the services stayed enabled (those that were enabled, at least) but their widget become disabled.
Besides the UI impact, this should also help you to keep the logic in the code cleaner, when one switch has only one function.

In any case, the switch widgets should be disabled when the global account is disabled.

140. By David King

Insulate againt a future libaccounts-glib bugfix

141. By David King

Refactor some code inside AccountApplicationSwitch

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
142. By David King

Refactor some code into AccountApplicationSwitch

Move the switch-specific signal handlers into the switch class.

143. By David King

Use synchronous store for the account application switches

Avoids a critical warning when two applications share the same service.

Revision history for this message
David King (amigadave) wrote :

Should be ready for merging now, please test!

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

Thanks, works very well now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/cc-credentials-account-applications-model.vala'
2--- src/cc-credentials-account-applications-model.vala 2012-09-18 11:06:40 +0000
3+++ src/cc-credentials-account-applications-model.vala 2013-02-18 11:18:30 +0000
4@@ -27,6 +27,8 @@
5 * @param description the description of the application
6 * @param plugin the plugin to configure account options, if any
7 * @param plugin_widget the widget to show when configuring account options
8+ * @param service_name the service name, as supplied to
9+ * Ag.Manager.get_service ()
10 */
11 public struct AccountApplicationRow
12 {
13@@ -35,6 +37,7 @@
14 public string description;
15 public Ap.ApplicationPlugin plugin;
16 public Gtk.Widget plugin_widget;
17+ public string service_name;
18 }
19 }
20
21@@ -165,7 +168,8 @@
22 icon = app_icon,
23 description = description_markup,
24 plugin = app_plugin,
25- plugin_widget = app_plugin_widget
26+ plugin_widget = app_plugin_widget,
27+ service_name = service_name
28 };
29
30 application_rows.prepend (application_row);
31
32=== modified file 'src/cc-credentials-account-details-page.vala'
33--- src/cc-credentials-account-details-page.vala 2012-10-25 14:42:58 +0000
34+++ src/cc-credentials-account-details-page.vala 2013-02-18 11:18:30 +0000
35@@ -38,6 +38,91 @@
36 }
37
38 /**
39+ * Switch widget, additionally storing an AccountApplicationRow.
40+ */
41+private class Cc.Credentials.AccountApplicationSwitch : Gtk.Switch
42+{
43+ public Ag.Account account { get; construct; }
44+ public Ag.Service service { get; construct; }
45+ bool store_in_progress;
46+
47+ public AccountApplicationSwitch (Ag.Account acc, Ag.Service serv)
48+ {
49+ Object (account: acc, service: serv);
50+ }
51+
52+ construct
53+ {
54+ store_in_progress = false;
55+
56+ // Fetch current state from service.
57+ account.select_service (service);
58+ active = account.get_enabled ();
59+ account.select_service (null);
60+
61+ account.set_data ("switch", this);
62+ account.enabled.connect (on_app_account_enabled);
63+ set_tooltip_text (_("Control whether this application integrates with Online Accounts"));
64+ notify["active"].connect (on_app_switch_activated);
65+ }
66+
67+ /**
68+ * Handle the account being enabled or disabled and update the switch state
69+ * accordingly.
70+ */
71+ private void on_app_account_enabled (Ag.Account account, string service,
72+ bool enabled)
73+ {
74+ // If the global account is toggled, toggle the switch sensitivity.
75+ if (service == "global" || service == null)
76+ {
77+ sensitive = enabled;
78+ return;
79+ }
80+
81+ if (this.service.get_name () == service && active != enabled)
82+ {
83+ active = enabled;
84+ }
85+ }
86+
87+ /**
88+ * Handle the per-application switch being activated.
89+ */
90+ private void on_app_switch_activated ()
91+ {
92+ // Toggle the enabled state.
93+ account.select_service (service);
94+ account.set_enabled (active);
95+ account.select_service (null);
96+
97+ try
98+ {
99+ account.store_blocking ();
100+ }
101+ catch (Ag.AccountsError err)
102+ {
103+ if (err is Ag.AccountsError.DELETED)
104+ {
105+ debug ("Enabled state changed during deletion of account ID: %u",
106+ account.id);
107+ }
108+ else if (err is Ag.AccountsError.STORE_IN_PROGRESS)
109+ {
110+ debug ("Enabled state changed while store in progress of account ID: %u",
111+ account.id);
112+ }
113+ else
114+ {
115+ critical ("Error changing enabled state of account: %s\nMessage: %s",
116+ account.get_display_name (),
117+ err.message);
118+ }
119+ }
120+ }
121+}
122+
123+/**
124 * Web credentials account details widget. Used inside a notebook page to list
125 * the applications that use an account, provide a switch to enable or disable
126 * the account and to provide a button for removing the account.
127@@ -60,6 +145,7 @@
128 private Ag.Account current_account;
129 private bool edit_options_button_present = false;
130 private bool needs_attention = false;
131+ private bool store_in_progress = false;
132
133 /**
134 * Pages for the action widget notebook.
135@@ -434,6 +520,9 @@
136 1,
137 1);
138
139+ var service = accounts_store.manager.get_service (application.service_name);
140+ var app_switch = new AccountApplicationSwitch (account, service);
141+
142 if (application.plugin_widget != null)
143 {
144 var button = new AccountApplicationButton (_("Options"),
145@@ -443,8 +532,18 @@
146 Gtk.PositionType.RIGHT,
147 1,
148 1);
149+ applications_grid.attach_next_to (app_switch,
150+ button,
151+ Gtk.PositionType.RIGHT,
152+ 1,
153+ 1);
154+
155 button.clicked.connect (on_options_button_clicked);
156 }
157+ else
158+ {
159+ applications_grid.attach (app_switch, 3, 0, 1, 1);
160+ }
161 }
162
163 /**
164@@ -557,33 +656,57 @@
165 }
166
167 /**
168+ * Asynchronously store the current account.
169+ */
170+ private void store_current_account ()
171+ {
172+ if (store_in_progress)
173+ {
174+ debug ("Enabled state changed while store in progress of account ID: %u",
175+ account.id);
176+ return;
177+ }
178+
179+ store_in_progress = true;
180+
181+ current_account.store_async.begin (null, (obj, res) =>
182+ {
183+ try
184+ {
185+ store_in_progress = false;
186+
187+ current_account.store_async.end (res);
188+ }
189+ catch (Ag.AccountsError err)
190+ {
191+ if (err is Ag.AccountsError.DELETED)
192+ {
193+ debug ("Enabled state changed during deletion of account ID: %u",
194+ account.id);
195+ }
196+ else if (err is Ag.AccountsError.STORE_IN_PROGRESS)
197+ {
198+ debug ("Enabled state changed while store in progress of account ID: %u",
199+ account.id);
200+ }
201+ else
202+ {
203+ critical ("Error changing enabled state of account: %s\nMessage: %s",
204+ current_account.get_display_name (),
205+ err.message);
206+ }
207+ }
208+ });
209+ }
210+
211+ /**
212 * Handle the account enabled switch being activated. Change the current
213 * account to be the same state as the switch.
214 */
215 private void on_enabled_switch_activated ()
216 {
217 current_account.set_enabled (enabled_switch.active);
218-
219- // FIXME: Use asynchronous account.store ().
220- try
221- {
222- current_account.store_blocking ();
223- }
224- catch (Ag.AccountsError err)
225- {
226- if (err is Ag.AccountsError.DELETED)
227- {
228- debug ("Enabled state changed during deletion of account ID: %u",
229- account.id);
230- return;
231- }
232- else
233- {
234- critical ("Error changing enabled state of account: %s\nMessage: %s",
235- current_account.get_display_name (),
236- err.message);
237- }
238- }
239+ store_current_account ();
240 }
241
242 /**
243@@ -598,9 +721,14 @@
244 * Handle the account being enabled or disabled from elsewhere, and update
245 * the switch state accordingly.
246 */
247- private void on_account_enabled ()
248+ private void on_account_enabled (string? service, bool enabled)
249 {
250- var enabled = current_account.get_enabled ();
251+ // Ignore service-level changes.
252+ // FIXME: http://code.google.com/p/accounts-sso/issues/detail?id=157
253+ if (service != "global" || service != null)
254+ {
255+ return;
256+ }
257
258 if (enabled != enabled_switch.active)
259 {
260
261=== modified file 'src/cc-credentials-accounts-model.vala'
262--- src/cc-credentials-accounts-model.vala 2012-09-28 10:23:35 +0000
263+++ src/cc-credentials-accounts-model.vala 2013-02-18 11:18:30 +0000
264@@ -425,13 +425,26 @@
265 string? service,
266 bool enabled)
267 {
268+ // Ignore service-level changes.
269+ // FIXME: http://code.google.com/p/accounts-sso/issues/detail?id=157
270+ if (service != "global" || service != null)
271+ {
272+ return;
273+ }
274+
275 Gtk.TreeIter iter;
276+ bool model_enabled;
277 if (find_iter_for_account_id (account.id, out iter))
278 {
279- this.set (iter,
280- ModelColumns.ACCOUNT_DESCRIPTION, format_account_description (account),
281- ModelColumns.ENABLED, enabled,
282- -1);
283+ this.get (iter, ModelColumns.ENABLED, out model_enabled);
284+
285+ if (model_enabled != enabled)
286+ {
287+ this.set (iter,
288+ ModelColumns.ACCOUNT_DESCRIPTION, format_account_description (account),
289+ ModelColumns.ENABLED, enabled,
290+ -1);
291+ }
292 }
293 else
294 {

Subscribers

People subscribed via source and target branches

to all changes: