Merge lp:~elementary-pantheon/switchboard-plug-security-privacy/abstract-service-panel into lp:~elementary-apps/switchboard-plug-security-privacy/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: David Hewitt
Approved revision: 317
Merged at revision: 317
Proposed branch: lp:~elementary-pantheon/switchboard-plug-security-privacy/abstract-service-panel
Merge into: lp:~elementary-apps/switchboard-plug-security-privacy/trunk
Diff against target: 415 lines (+126/-102)
8 files modified
src/CMakeLists.txt (+1/-0)
src/Plug.vala (+0/-1)
src/Views/AbstractServicePanel.vala (+81/-0)
src/Views/FirewallPanel.vala (+5/-21)
src/Views/LocationPanel.vala (+9/-22)
src/Views/LockPanel.vala (+11/-14)
src/Views/TrackPanel.vala (+16/-41)
src/Widgets/ServiceList.vala (+3/-3)
To merge this branch: bzr merge lp:~elementary-pantheon/switchboard-plug-security-privacy/abstract-service-panel
Reviewer Review Type Date Requested Status
David Hewitt code, function Approve
Review via email: mp+318808@code.launchpad.net

Commit message

Create AbstractServicePanel and use it for each page

Description of the change

This branch creates an abstract service panel and uses it. The main purpose here is to make sure that we keep the layout and design of each panel consistent and to make it easier to build future panels.

The abstract service panel comes with three areas: header_area, content_area, and action_area. The first one is private and you only interact with it by setting the icon_name, title, description?, and activatable properties of the panel. The latter are public and the naming should be familiar and predictable if you've used Gtk.Dialog

To post a comment you must log in.
316. By Danielle Foré

get rid of a weird method

317. By Danielle Foré

get rid of some extra margins

Revision history for this message
David Hewitt (davidmhewitt) wrote :

This is good. Definitely simplifies the code in the panels. I think we should maybe look at making the AlertView when a service is disabled and the enabled/disabled status indicators a bit more generic too, so there's not as much repeated code there.

But this is a really good start.

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2017-02-27 23:35:21 +0000
3+++ src/CMakeLists.txt 2017-03-02 17:18:33 +0000
4@@ -18,6 +18,7 @@
5 UFWHelpers.vala
6 ZGUtilities.vala
7
8+ Views/AbstractServicePanel.vala
9 Views/FirewallPanel.vala
10 Views/LockPanel.vala
11 Views/TrackPanel.vala
12
13=== modified file 'src/Plug.vala'
14--- src/Plug.vala 2017-03-01 23:31:31 +0000
15+++ src/Plug.vala 2017-03-02 17:18:33 +0000
16@@ -168,7 +168,6 @@
17 case "locking<sep>privacy-mode":
18 stack.set_visible_child_name ("locking");
19 service_list.select_service_name ("locking");
20- tracking.focus_privacy_switch ();
21 break;
22 case "firewall":
23 stack.set_visible_child_name ("firewall");
24
25=== added file 'src/Views/AbstractServicePanel.vala'
26--- src/Views/AbstractServicePanel.vala 1970-01-01 00:00:00 +0000
27+++ src/Views/AbstractServicePanel.vala 2017-03-02 17:18:33 +0000
28@@ -0,0 +1,81 @@
29+/*
30+* Copyright (c) 2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
31+*
32+* This program is free software; you can redistribute it and/or
33+* modify it under the terms of the GNU General Public
34+* License as published by the Free Software Foundation; either
35+* version 2 of the License, or (at your option) any later version.
36+*
37+* This program is distributed in the hope that it will be useful,
38+* but WITHOUT ANY WARRANTY; without even the implied warranty of
39+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40+* General Public License for more details.
41+*
42+* You should have received a copy of the GNU General Public
43+* License along with this program; if not, write to the
44+* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
45+* Boston, MA 02110-1301 USA
46+*
47+*/
48+
49+public abstract class ServicePanel : Gtk.Grid {
50+ public Gtk.ButtonBox action_area;
51+ public Gtk.Grid content_area;
52+ public Gtk.Switch? status_switch;
53+
54+ public bool activatable { get; construct; }
55+
56+ public string description { get; construct; }
57+ public string icon_name { get; construct; }
58+ public string title { get; construct; }
59+
60+ public ServicePanel () {
61+ Object (activatable: activatable,
62+ icon_name: icon_name,
63+ description: description,
64+ title: title);
65+ }
66+
67+ construct {
68+ var header_icon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG);
69+
70+ var header_label = new Gtk.Label (title);
71+ header_label.get_style_context ().add_class ("h2");
72+
73+ var header_area = new Gtk.Grid ();
74+ header_area.column_spacing = 12;
75+ header_area.add (header_icon);
76+ header_area.add (header_label);
77+
78+ if (description != null) {
79+ var description_icon = new Gtk.Image.from_icon_name ("help-info-symbolic", Gtk.IconSize.MENU);
80+ description_icon.xalign = 0;
81+ description_icon.tooltip_text = description;
82+
83+ header_area.add (description_icon);
84+ }
85+
86+ if (activatable) {
87+ status_switch = new Gtk.Switch ();
88+ status_switch.hexpand = true;
89+ status_switch.halign = Gtk.Align.END;
90+ status_switch.valign = Gtk.Align.CENTER;
91+ header_area.add (status_switch);
92+ }
93+
94+ content_area = new Gtk.Grid ();
95+ content_area.column_spacing = 12;
96+ content_area.row_spacing = 12;
97+
98+ action_area = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
99+ action_area.set_layout (Gtk.ButtonBoxStyle.END);
100+ action_area.set_spacing (6);
101+
102+ margin = 12;
103+ orientation = Gtk.Orientation.VERTICAL;
104+ row_spacing = 24;
105+ add (header_area);
106+ add (content_area);
107+ add (action_area);
108+ }
109+}
110
111=== modified file 'src/Views/FirewallPanel.vala'
112--- src/Views/FirewallPanel.vala 2017-03-01 22:38:37 +0000
113+++ src/Views/FirewallPanel.vala 2017-03-02 17:18:33 +0000
114@@ -20,14 +20,13 @@
115 * Authored by: Corentin Noël <tintou@mailoo.org>
116 */
117
118-public class SecurityPrivacy.FirewallPanel : Gtk.Grid {
119+public class SecurityPrivacy.FirewallPanel : ServicePanel {
120 private Gtk.ListStore list_store;
121 private Gtk.TreeView view;
122 private Gtk.Toolbar list_toolbar;
123 private bool loading = false;
124 private Gtk.Popover add_popover;
125 private Gtk.ToolButton remove_button;
126- public Gtk.Switch status_switch;
127
128 private enum Columns {
129 ACTION,
130@@ -40,22 +39,12 @@
131 }
132
133 public FirewallPanel () {
134- Object (column_spacing: 12,
135- margin: 12,
136- row_spacing: 6);
137+ Object (activatable: true,
138+ icon_name: "network-firewall",
139+ title: _("Firewall"));
140 }
141
142 construct {
143- var status_icon = new Gtk.Image.from_icon_name ("network-firewall", Gtk.IconSize.DIALOG);
144-
145- var status_label = new Gtk.Label (_("Firewall"));
146- status_label.get_style_context ().add_class ("h2");
147- status_label.hexpand = true;
148- status_label.xalign = 0;
149-
150- status_switch = new Gtk.Switch ();
151- status_switch.valign = Gtk.Align.CENTER;
152-
153 status_switch.notify["active"].connect (() => {
154 if (loading == false) {
155 view.sensitive = status_switch.active;
156@@ -64,10 +53,6 @@
157 show_rules ();
158 });
159
160- attach (status_icon, 0, 0, 1, 1);
161- attach (status_label, 1, 0, 1, 1);
162- attach (status_switch, 2, 0, 1, 1);
163-
164 create_treeview ();
165
166 sensitive = false;
167@@ -264,9 +249,8 @@
168 view_grid.attach (list_toolbar, 0, 1, 1, 1);
169
170 var frame = new Gtk.Frame (null);
171- frame.margin_top = 12;
172 frame.add (view_grid);
173
174- attach (frame, 0, 1, 3, 1);
175+ content_area.attach (frame, 0, 1, 3, 1);
176 }
177 }
178
179=== modified file 'src/Views/LocationPanel.vala'
180--- src/Views/LocationPanel.vala 2017-03-01 22:38:37 +0000
181+++ src/Views/LocationPanel.vala 2017-03-02 17:18:33 +0000
182@@ -1,6 +1,6 @@
183 // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
184 /*-
185- * Copyright (c) 2017 elementary LLC.
186+ * Copyright (c) 2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
187 * Copyright (C) 2017 David Hewitt <davidmhewitt@gmail.com>
188 *
189 * This program is free software; you can redistribute it and/or modify
190@@ -20,7 +20,7 @@
191 * Authored by: David Hewitt <davidmhewitt@gmail.com>
192 */
193
194-public class SecurityPrivacy.LocationPanel : Gtk.Grid {
195+public class SecurityPrivacy.LocationPanel : ServicePanel {
196
197 private GLib.Settings location_settings;
198 private Variant remembered_apps;
199@@ -29,7 +29,6 @@
200 private Gtk.TreeView tree_view;
201 private Gtk.Grid treeview_grid;
202 private Gtk.Stack disabled_stack;
203- public Gtk.Switch status_switch;
204
205 private enum Columns {
206 AUTHORIZED,
207@@ -39,28 +38,17 @@
208 N_COLUMNS
209 }
210
211+ public LocationPanel () {
212+ Object (activatable: true,
213+ icon_name: "find-location",
214+ title: _("Location Services"));
215+ }
216+
217 construct {
218- column_spacing = 12;
219- row_spacing = 6;
220- margin = 12;
221-
222 location_settings = new GLib.Settings ("org.pantheon.agent-geoclue2");
223 disabled_stack = new Gtk.Stack ();
224
225- var status_icon = new Gtk.Image.from_icon_name ("find-location", Gtk.IconSize.DIALOG);
226-
227- var status_label = new Gtk.Label (_("Location Services"));
228- status_label.get_style_context ().add_class ("h2");
229- status_label.hexpand = true;
230- status_label.xalign = 0;
231-
232- status_switch = new Gtk.Switch ();
233- status_switch.valign = Gtk.Align.CENTER;
234-
235- attach (status_icon, 0, 0, 1, 1);
236- attach (status_label, 1, 0, 1, 1);
237- attach (status_switch, 2, 0, 1, 1);
238- attach (disabled_stack, 0, 1, 3, 1);
239+ content_area.attach (disabled_stack, 0, 1, 3, 1);
240
241 create_treeview ();
242 create_disabled_panel ();
243@@ -144,7 +132,6 @@
244 scrolled.add (tree_view);
245
246 treeview_grid = new Gtk.Grid ();
247- treeview_grid.margin_top = 12;
248 treeview_grid.row_spacing = 6;
249 treeview_grid.attach (locations_label, 0, 0, 1, 1);
250 treeview_grid.attach (scrolled, 0, 1, 1, 1);
251
252=== modified file 'src/Views/LockPanel.vala'
253--- src/Views/LockPanel.vala 2017-03-01 22:38:37 +0000
254+++ src/Views/LockPanel.vala 2017-03-02 17:18:33 +0000
255@@ -20,15 +20,16 @@
256 * Authored by: Corentin Noël <corentin@elementary.io>
257 */
258
259-public class SecurityPrivacy.LockPanel : Gtk.Grid {
260+public class SecurityPrivacy.LockPanel : ServicePanel {
261
262 Settings locker;
263
264 public LockPanel () {
265- column_spacing = 12;
266- row_spacing = 6;
267- margin = 12;
268+ Object (icon_name: "system-lock-screen",
269+ title: _("Locking"));
270+ }
271
272+ construct {
273 locker = new Settings ("apps.light-locker");
274
275 var lock_suspend_label = new Gtk.Label (_("Lock on sleep:"));
276@@ -66,15 +67,11 @@
277 lock_suspend_switch.halign = Gtk.Align.START;
278 lock_sleep_switch.halign = Gtk.Align.START;
279
280- var expander_grid = new Gtk.Grid ();
281- expander_grid.hexpand = true;
282-
283- attach (expander_grid, 0, 0, 4, 1);
284- attach (lock_suspend_label, 1, 0, 1, 1);
285- attach (lock_sleep_label, 1, 1, 1, 1);
286- attach (lock_suspend_switch, 2, 0, 1, 1);
287- attach (lock_sleep_switch, 2, 1, 1, 1);
288-
289- hexpand = true;
290+ content_area.hexpand = true;
291+ content_area.halign = Gtk.Align.CENTER;
292+ content_area.attach (lock_suspend_label, 0, 0, 1, 1);
293+ content_area.attach (lock_sleep_label, 0, 1, 1, 1);
294+ content_area.attach (lock_suspend_switch, 1, 0, 1, 1);
295+ content_area.attach (lock_sleep_switch, 1, 1, 1, 1);
296 }
297 }
298
299=== modified file 'src/Views/TrackPanel.vala'
300--- src/Views/TrackPanel.vala 2017-03-01 23:31:31 +0000
301+++ src/Views/TrackPanel.vala 2017-03-02 17:18:33 +0000
302@@ -1,6 +1,6 @@
303 // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
304 /*-
305- * Copyright (c) 2014 elementary LLC. ((http://launchpad.net/switchboard-plug-security-privacy)
306+ * Copyright (c) 2014 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
307 *
308 * This library is free software; you can redistribute it and/or
309 * modify it under the terms of the GNU Lesser General Public
310@@ -20,14 +20,14 @@
311 * Authored by: Corentin Noël <tintou@mailoo.org>
312 */
313
314-public class SecurityPrivacy.TrackPanel : Gtk.Grid {
315+public class SecurityPrivacy.TrackPanel : ServicePanel {
316 private Widgets.ClearUsagePopover remove_popover;
317- public Gtk.Switch record_switch;
318
319 public TrackPanel () {
320- Object (column_spacing: 12,
321- margin: 12,
322- row_spacing: 12);
323+ Object (activatable: true,
324+ description: _("This operating system can gather useful statistics about file and app usage to provide extra functionality. If other people can see or access your account, you may wish to limit which items are recorded."),
325+ icon_name: "document-open-recent",
326+ title: _("History"));
327 }
328
329 construct {
330@@ -43,30 +43,9 @@
331 description_frame.no_show_all = true;
332 description_frame.add (alert);
333
334- var header_image = new Gtk.Image.from_icon_name ("document-open-recent", Gtk.IconSize.DIALOG);
335-
336- var record_label = new Gtk.Label (_("History"));
337- record_label.get_style_context ().add_class ("h2");
338-
339- record_switch = new Gtk.Switch ();
340- record_switch.active = true;
341- record_switch.valign = Gtk.Align.CENTER;
342-
343- var info_button = new Gtk.Image.from_icon_name ("help-info-symbolic", Gtk.IconSize.MENU);
344- info_button.hexpand = true;
345- info_button.xalign = 0;
346- info_button.tooltip_text = _("This operating system can gather useful statistics about file and app usage to provide extra functionality. If other people can see or access your account, you may wish to limit which items are recorded.");
347-
348- var header_grid = new Gtk.Grid ();
349- header_grid.column_spacing = 12;
350- header_grid.margin_bottom = 12;
351- header_grid.add (header_image);
352- header_grid.add (record_label);
353- header_grid.add (info_button);
354- header_grid.add (record_switch);
355+ status_switch.active = true;
356
357 var clear_data = new Gtk.ToggleButton.with_label (_("Clear History…"));
358- clear_data.halign = Gtk.Align.END;
359 clear_data.notify["active"].connect (() => {
360 if (clear_data.active == false) {
361 remove_popover.hide ();
362@@ -83,14 +62,14 @@
363 var include_treeview = new IncludeTreeView ();
364 var exclude_treeview = new ExcludeTreeView ();
365
366- attach (header_grid, 0, 0, 2, 1);
367- attach (description_frame, 0, 1, 2, 1);
368- attach (include_treeview, 0, 1, 1, 1);
369- attach (exclude_treeview, 1, 1, 1, 1);
370- attach (clear_data, 1, 2, 1, 1);
371-
372- record_switch.notify["active"].connect (() => {
373- bool privacy_mode = !record_switch.active;
374+ content_area.attach (description_frame, 0, 1, 2, 1);
375+ content_area.attach (include_treeview, 0, 1, 1, 1);
376+ content_area.attach (exclude_treeview, 1, 1, 1, 1);
377+
378+ action_area.add (clear_data);
379+
380+ status_switch.notify["active"].connect (() => {
381+ bool privacy_mode = !status_switch.active;
382 include_treeview.visible = !privacy_mode;
383 exclude_treeview.visible = !privacy_mode;
384 description_frame.visible = privacy_mode;
385@@ -104,11 +83,7 @@
386 }
387 });
388
389- record_switch.active = !blacklist.get_incognito ();
390- }
391-
392- public void focus_privacy_switch () {
393- record_switch.grab_focus ();
394+ status_switch.active = !blacklist.get_incognito ();
395 }
396
397 private string get_operating_system_name () {
398
399=== modified file 'src/Widgets/ServiceList.vala'
400--- src/Widgets/ServiceList.vala 2017-03-01 23:31:31 +0000
401+++ src/Widgets/ServiceList.vala 2017-03-02 17:18:33 +0000
402@@ -39,10 +39,10 @@
403 update_service_status (firewall_item, SecurityPrivacy.firewall.status_switch.active);
404 });
405
406- update_service_status (privacy_item, SecurityPrivacy.tracking.record_switch.active);
407+ update_service_status (privacy_item, SecurityPrivacy.tracking.status_switch.active);
408
409- SecurityPrivacy.tracking.record_switch.notify["active"].connect (() => {
410- update_service_status (privacy_item, SecurityPrivacy.tracking.record_switch.active);
411+ SecurityPrivacy.tracking.status_switch.notify["active"].connect (() => {
412+ update_service_status (privacy_item, SecurityPrivacy.tracking.status_switch.active);
413 });
414
415 if (SecurityPrivacy.LocationPanel.location_agent_installed ()) {

Subscribers

People subscribed via source and target branches