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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2017-02-27 23:35:21 +0000
+++ src/CMakeLists.txt 2017-03-02 17:18:33 +0000
@@ -18,6 +18,7 @@
18 UFWHelpers.vala18 UFWHelpers.vala
19 ZGUtilities.vala19 ZGUtilities.vala
2020
21 Views/AbstractServicePanel.vala
21 Views/FirewallPanel.vala22 Views/FirewallPanel.vala
22 Views/LockPanel.vala23 Views/LockPanel.vala
23 Views/TrackPanel.vala24 Views/TrackPanel.vala
2425
=== modified file 'src/Plug.vala'
--- src/Plug.vala 2017-03-01 23:31:31 +0000
+++ src/Plug.vala 2017-03-02 17:18:33 +0000
@@ -168,7 +168,6 @@
168 case "locking<sep>privacy-mode":168 case "locking<sep>privacy-mode":
169 stack.set_visible_child_name ("locking");169 stack.set_visible_child_name ("locking");
170 service_list.select_service_name ("locking");170 service_list.select_service_name ("locking");
171 tracking.focus_privacy_switch ();
172 break;171 break;
173 case "firewall":172 case "firewall":
174 stack.set_visible_child_name ("firewall");173 stack.set_visible_child_name ("firewall");
175174
=== added file 'src/Views/AbstractServicePanel.vala'
--- src/Views/AbstractServicePanel.vala 1970-01-01 00:00:00 +0000
+++ src/Views/AbstractServicePanel.vala 2017-03-02 17:18:33 +0000
@@ -0,0 +1,81 @@
1/*
2* Copyright (c) 2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
3*
4* This program is free software; you can redistribute it and/or
5* modify it under the terms of the GNU General Public
6* License as published by the Free Software Foundation; either
7* version 2 of the License, or (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12* General Public License for more details.
13*
14* You should have received a copy of the GNU General Public
15* License along with this program; if not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17* Boston, MA 02110-1301 USA
18*
19*/
20
21public abstract class ServicePanel : Gtk.Grid {
22 public Gtk.ButtonBox action_area;
23 public Gtk.Grid content_area;
24 public Gtk.Switch? status_switch;
25
26 public bool activatable { get; construct; }
27
28 public string description { get; construct; }
29 public string icon_name { get; construct; }
30 public string title { get; construct; }
31
32 public ServicePanel () {
33 Object (activatable: activatable,
34 icon_name: icon_name,
35 description: description,
36 title: title);
37 }
38
39 construct {
40 var header_icon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG);
41
42 var header_label = new Gtk.Label (title);
43 header_label.get_style_context ().add_class ("h2");
44
45 var header_area = new Gtk.Grid ();
46 header_area.column_spacing = 12;
47 header_area.add (header_icon);
48 header_area.add (header_label);
49
50 if (description != null) {
51 var description_icon = new Gtk.Image.from_icon_name ("help-info-symbolic", Gtk.IconSize.MENU);
52 description_icon.xalign = 0;
53 description_icon.tooltip_text = description;
54
55 header_area.add (description_icon);
56 }
57
58 if (activatable) {
59 status_switch = new Gtk.Switch ();
60 status_switch.hexpand = true;
61 status_switch.halign = Gtk.Align.END;
62 status_switch.valign = Gtk.Align.CENTER;
63 header_area.add (status_switch);
64 }
65
66 content_area = new Gtk.Grid ();
67 content_area.column_spacing = 12;
68 content_area.row_spacing = 12;
69
70 action_area = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
71 action_area.set_layout (Gtk.ButtonBoxStyle.END);
72 action_area.set_spacing (6);
73
74 margin = 12;
75 orientation = Gtk.Orientation.VERTICAL;
76 row_spacing = 24;
77 add (header_area);
78 add (content_area);
79 add (action_area);
80 }
81}
082
=== modified file 'src/Views/FirewallPanel.vala'
--- src/Views/FirewallPanel.vala 2017-03-01 22:38:37 +0000
+++ src/Views/FirewallPanel.vala 2017-03-02 17:18:33 +0000
@@ -20,14 +20,13 @@
20 * Authored by: Corentin Noël <tintou@mailoo.org>20 * Authored by: Corentin Noël <tintou@mailoo.org>
21 */21 */
2222
23public class SecurityPrivacy.FirewallPanel : Gtk.Grid {23public class SecurityPrivacy.FirewallPanel : ServicePanel {
24 private Gtk.ListStore list_store;24 private Gtk.ListStore list_store;
25 private Gtk.TreeView view;25 private Gtk.TreeView view;
26 private Gtk.Toolbar list_toolbar;26 private Gtk.Toolbar list_toolbar;
27 private bool loading = false;27 private bool loading = false;
28 private Gtk.Popover add_popover;28 private Gtk.Popover add_popover;
29 private Gtk.ToolButton remove_button;29 private Gtk.ToolButton remove_button;
30 public Gtk.Switch status_switch;
3130
32 private enum Columns {31 private enum Columns {
33 ACTION,32 ACTION,
@@ -40,22 +39,12 @@
40 }39 }
4140
42 public FirewallPanel () {41 public FirewallPanel () {
43 Object (column_spacing: 12,42 Object (activatable: true,
44 margin: 12,43 icon_name: "network-firewall",
45 row_spacing: 6);44 title: _("Firewall"));
46 }45 }
4746
48 construct {47 construct {
49 var status_icon = new Gtk.Image.from_icon_name ("network-firewall", Gtk.IconSize.DIALOG);
50
51 var status_label = new Gtk.Label (_("Firewall"));
52 status_label.get_style_context ().add_class ("h2");
53 status_label.hexpand = true;
54 status_label.xalign = 0;
55
56 status_switch = new Gtk.Switch ();
57 status_switch.valign = Gtk.Align.CENTER;
58
59 status_switch.notify["active"].connect (() => {48 status_switch.notify["active"].connect (() => {
60 if (loading == false) {49 if (loading == false) {
61 view.sensitive = status_switch.active;50 view.sensitive = status_switch.active;
@@ -64,10 +53,6 @@
64 show_rules ();53 show_rules ();
65 });54 });
6655
67 attach (status_icon, 0, 0, 1, 1);
68 attach (status_label, 1, 0, 1, 1);
69 attach (status_switch, 2, 0, 1, 1);
70
71 create_treeview ();56 create_treeview ();
7257
73 sensitive = false;58 sensitive = false;
@@ -264,9 +249,8 @@
264 view_grid.attach (list_toolbar, 0, 1, 1, 1);249 view_grid.attach (list_toolbar, 0, 1, 1, 1);
265250
266 var frame = new Gtk.Frame (null);251 var frame = new Gtk.Frame (null);
267 frame.margin_top = 12;
268 frame.add (view_grid);252 frame.add (view_grid);
269253
270 attach (frame, 0, 1, 3, 1);254 content_area.attach (frame, 0, 1, 3, 1);
271 }255 }
272}256}
273257
=== modified file 'src/Views/LocationPanel.vala'
--- src/Views/LocationPanel.vala 2017-03-01 22:38:37 +0000
+++ src/Views/LocationPanel.vala 2017-03-02 17:18:33 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2/*-2/*-
3 * Copyright (c) 2017 elementary LLC.3 * Copyright (c) 2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
4 * Copyright (C) 2017 David Hewitt <davidmhewitt@gmail.com> 4 * Copyright (C) 2017 David Hewitt <davidmhewitt@gmail.com>
5 *5 *
6 * This program is free software; you can redistribute it and/or modify6 * This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
20 * Authored by: David Hewitt <davidmhewitt@gmail.com>20 * Authored by: David Hewitt <davidmhewitt@gmail.com>
21 */21 */
2222
23public class SecurityPrivacy.LocationPanel : Gtk.Grid {23public class SecurityPrivacy.LocationPanel : ServicePanel {
2424
25 private GLib.Settings location_settings;25 private GLib.Settings location_settings;
26 private Variant remembered_apps;26 private Variant remembered_apps;
@@ -29,7 +29,6 @@
29 private Gtk.TreeView tree_view;29 private Gtk.TreeView tree_view;
30 private Gtk.Grid treeview_grid;30 private Gtk.Grid treeview_grid;
31 private Gtk.Stack disabled_stack;31 private Gtk.Stack disabled_stack;
32 public Gtk.Switch status_switch;
3332
34 private enum Columns {33 private enum Columns {
35 AUTHORIZED,34 AUTHORIZED,
@@ -39,28 +38,17 @@
39 N_COLUMNS38 N_COLUMNS
40 }39 }
4140
41 public LocationPanel () {
42 Object (activatable: true,
43 icon_name: "find-location",
44 title: _("Location Services"));
45 }
46
42 construct {47 construct {
43 column_spacing = 12;
44 row_spacing = 6;
45 margin = 12;
46
47 location_settings = new GLib.Settings ("org.pantheon.agent-geoclue2");48 location_settings = new GLib.Settings ("org.pantheon.agent-geoclue2");
48 disabled_stack = new Gtk.Stack ();49 disabled_stack = new Gtk.Stack ();
49 50
50 var status_icon = new Gtk.Image.from_icon_name ("find-location", Gtk.IconSize.DIALOG);51 content_area.attach (disabled_stack, 0, 1, 3, 1);
51
52 var status_label = new Gtk.Label (_("Location Services"));
53 status_label.get_style_context ().add_class ("h2");
54 status_label.hexpand = true;
55 status_label.xalign = 0;
56
57 status_switch = new Gtk.Switch ();
58 status_switch.valign = Gtk.Align.CENTER;
59
60 attach (status_icon, 0, 0, 1, 1);
61 attach (status_label, 1, 0, 1, 1);
62 attach (status_switch, 2, 0, 1, 1);
63 attach (disabled_stack, 0, 1, 3, 1);
64 52
65 create_treeview ();53 create_treeview ();
66 create_disabled_panel ();54 create_disabled_panel ();
@@ -144,7 +132,6 @@
144 scrolled.add (tree_view);132 scrolled.add (tree_view);
145133
146 treeview_grid = new Gtk.Grid ();134 treeview_grid = new Gtk.Grid ();
147 treeview_grid.margin_top = 12;
148 treeview_grid.row_spacing = 6;135 treeview_grid.row_spacing = 6;
149 treeview_grid.attach (locations_label, 0, 0, 1, 1);136 treeview_grid.attach (locations_label, 0, 0, 1, 1);
150 treeview_grid.attach (scrolled, 0, 1, 1, 1);137 treeview_grid.attach (scrolled, 0, 1, 1, 1);
151138
=== modified file 'src/Views/LockPanel.vala'
--- src/Views/LockPanel.vala 2017-03-01 22:38:37 +0000
+++ src/Views/LockPanel.vala 2017-03-02 17:18:33 +0000
@@ -20,15 +20,16 @@
20 * Authored by: Corentin Noël <corentin@elementary.io>20 * Authored by: Corentin Noël <corentin@elementary.io>
21 */21 */
2222
23public class SecurityPrivacy.LockPanel : Gtk.Grid {23public class SecurityPrivacy.LockPanel : ServicePanel {
2424
25 Settings locker;25 Settings locker;
2626
27 public LockPanel () {27 public LockPanel () {
28 column_spacing = 12;28 Object (icon_name: "system-lock-screen",
29 row_spacing = 6;29 title: _("Locking"));
30 margin = 12;30 }
3131
32 construct {
32 locker = new Settings ("apps.light-locker");33 locker = new Settings ("apps.light-locker");
3334
34 var lock_suspend_label = new Gtk.Label (_("Lock on sleep:"));35 var lock_suspend_label = new Gtk.Label (_("Lock on sleep:"));
@@ -66,15 +67,11 @@
66 lock_suspend_switch.halign = Gtk.Align.START;67 lock_suspend_switch.halign = Gtk.Align.START;
67 lock_sleep_switch.halign = Gtk.Align.START;68 lock_sleep_switch.halign = Gtk.Align.START;
6869
69 var expander_grid = new Gtk.Grid ();70 content_area.hexpand = true;
70 expander_grid.hexpand = true;71 content_area.halign = Gtk.Align.CENTER;
7172 content_area.attach (lock_suspend_label, 0, 0, 1, 1);
72 attach (expander_grid, 0, 0, 4, 1);73 content_area.attach (lock_sleep_label, 0, 1, 1, 1);
73 attach (lock_suspend_label, 1, 0, 1, 1);74 content_area.attach (lock_suspend_switch, 1, 0, 1, 1);
74 attach (lock_sleep_label, 1, 1, 1, 1);75 content_area.attach (lock_sleep_switch, 1, 1, 1, 1);
75 attach (lock_suspend_switch, 2, 0, 1, 1);
76 attach (lock_sleep_switch, 2, 1, 1, 1);
77
78 hexpand = true;
79 }76 }
80}77}
8178
=== modified file 'src/Views/TrackPanel.vala'
--- src/Views/TrackPanel.vala 2017-03-01 23:31:31 +0000
+++ src/Views/TrackPanel.vala 2017-03-02 17:18:33 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2/*-2/*-
3 * Copyright (c) 2014 elementary LLC. ((http://launchpad.net/switchboard-plug-security-privacy)3 * Copyright (c) 2014 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
4 *4 *
5 * This library is free software; you can redistribute it and/or5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public6 * modify it under the terms of the GNU Lesser General Public
@@ -20,14 +20,14 @@
20 * Authored by: Corentin Noël <tintou@mailoo.org>20 * Authored by: Corentin Noël <tintou@mailoo.org>
21 */21 */
2222
23public class SecurityPrivacy.TrackPanel : Gtk.Grid {23public class SecurityPrivacy.TrackPanel : ServicePanel {
24 private Widgets.ClearUsagePopover remove_popover;24 private Widgets.ClearUsagePopover remove_popover;
25 public Gtk.Switch record_switch;
2625
27 public TrackPanel () {26 public TrackPanel () {
28 Object (column_spacing: 12,27 Object (activatable: true,
29 margin: 12,28 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."),
30 row_spacing: 12);29 icon_name: "document-open-recent",
30 title: _("History"));
31 }31 }
3232
33 construct {33 construct {
@@ -43,30 +43,9 @@
43 description_frame.no_show_all = true;43 description_frame.no_show_all = true;
44 description_frame.add (alert);44 description_frame.add (alert);
4545
46 var header_image = new Gtk.Image.from_icon_name ("document-open-recent", Gtk.IconSize.DIALOG);46 status_switch.active = true;
47
48 var record_label = new Gtk.Label (_("History"));
49 record_label.get_style_context ().add_class ("h2");
50
51 record_switch = new Gtk.Switch ();
52 record_switch.active = true;
53 record_switch.valign = Gtk.Align.CENTER;
54
55 var info_button = new Gtk.Image.from_icon_name ("help-info-symbolic", Gtk.IconSize.MENU);
56 info_button.hexpand = true;
57 info_button.xalign = 0;
58 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.");
59
60 var header_grid = new Gtk.Grid ();
61 header_grid.column_spacing = 12;
62 header_grid.margin_bottom = 12;
63 header_grid.add (header_image);
64 header_grid.add (record_label);
65 header_grid.add (info_button);
66 header_grid.add (record_switch);
6747
68 var clear_data = new Gtk.ToggleButton.with_label (_("Clear History…"));48 var clear_data = new Gtk.ToggleButton.with_label (_("Clear History…"));
69 clear_data.halign = Gtk.Align.END;
70 clear_data.notify["active"].connect (() => {49 clear_data.notify["active"].connect (() => {
71 if (clear_data.active == false) {50 if (clear_data.active == false) {
72 remove_popover.hide ();51 remove_popover.hide ();
@@ -83,14 +62,14 @@
83 var include_treeview = new IncludeTreeView ();62 var include_treeview = new IncludeTreeView ();
84 var exclude_treeview = new ExcludeTreeView ();63 var exclude_treeview = new ExcludeTreeView ();
8564
86 attach (header_grid, 0, 0, 2, 1);65 content_area.attach (description_frame, 0, 1, 2, 1);
87 attach (description_frame, 0, 1, 2, 1);66 content_area.attach (include_treeview, 0, 1, 1, 1);
88 attach (include_treeview, 0, 1, 1, 1);67 content_area.attach (exclude_treeview, 1, 1, 1, 1);
89 attach (exclude_treeview, 1, 1, 1, 1);68
90 attach (clear_data, 1, 2, 1, 1);69 action_area.add (clear_data);
9170
92 record_switch.notify["active"].connect (() => {71 status_switch.notify["active"].connect (() => {
93 bool privacy_mode = !record_switch.active;72 bool privacy_mode = !status_switch.active;
94 include_treeview.visible = !privacy_mode;73 include_treeview.visible = !privacy_mode;
95 exclude_treeview.visible = !privacy_mode;74 exclude_treeview.visible = !privacy_mode;
96 description_frame.visible = privacy_mode;75 description_frame.visible = privacy_mode;
@@ -104,11 +83,7 @@
104 }83 }
105 });84 });
10685
107 record_switch.active = !blacklist.get_incognito ();86 status_switch.active = !blacklist.get_incognito ();
108 }
109
110 public void focus_privacy_switch () {
111 record_switch.grab_focus ();
112 }87 }
11388
114 private string get_operating_system_name () {89 private string get_operating_system_name () {
11590
=== modified file 'src/Widgets/ServiceList.vala'
--- src/Widgets/ServiceList.vala 2017-03-01 23:31:31 +0000
+++ src/Widgets/ServiceList.vala 2017-03-02 17:18:33 +0000
@@ -39,10 +39,10 @@
39 update_service_status (firewall_item, SecurityPrivacy.firewall.status_switch.active);39 update_service_status (firewall_item, SecurityPrivacy.firewall.status_switch.active);
40 });40 });
4141
42 update_service_status (privacy_item, SecurityPrivacy.tracking.record_switch.active);42 update_service_status (privacy_item, SecurityPrivacy.tracking.status_switch.active);
4343
44 SecurityPrivacy.tracking.record_switch.notify["active"].connect (() => {44 SecurityPrivacy.tracking.status_switch.notify["active"].connect (() => {
45 update_service_status (privacy_item, SecurityPrivacy.tracking.record_switch.active);45 update_service_status (privacy_item, SecurityPrivacy.tracking.status_switch.active);
46 });46 });
4747
48 if (SecurityPrivacy.LocationPanel.location_agent_installed ()) {48 if (SecurityPrivacy.LocationPanel.location_agent_installed ()) {

Subscribers

People subscribed via source and target branches