Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plug: inline namespace, cleanup, build UI earlier #166

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 110 additions & 158 deletions src/Plug.vala
Original file line number Diff line number Diff line change
@@ -1,191 +1,143 @@
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/*-
* Copyright (c) 2014-2018 elementary LLC. (https://elementary.io)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* SPDX-FileCopyrightText: 2014-2023 elementary, Inc. (https://elementary.io)
* Authored by: Corentin Noël <tintou@mailoo.org>
*/

namespace SecurityPrivacy {
public static Gtk.LockButton lock_button;
public static LocationPanel location;
public static FirewallPanel firewall;
public static HouseKeepingPanel housekeeping;
public static TrackPanel tracking;

public class Plug : Switchboard.Plug {
Gtk.Grid main_grid;
Gtk.Stack stack;

private const string FIREWALL = "firewall";
private const string HOUSEKEEPING = "housekeeping";
private const string HISTORY = "tracking";
private const string LOCKING = "locking";
private const string LOCATION = "location";

public Plug () {
GLib.Intl.bindtextdomain (Build.GETTEXT_PACKAGE, Build.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Build.GETTEXT_PACKAGE, "UTF-8");

Object (category: Category.PERSONAL,
code_name: "io.elementary.switchboard.security-privacy",
display_name: _("Security & Privacy"),
description: _("Configure firewall, screen lock, and activity information"),
icon: "preferences-system-privacy",
supported_settings: new Gee.TreeMap<string, string?> (null, null));

supported_settings.set ("privacy", HISTORY);
supported_settings.set ("privacy/location", LOCATION);
supported_settings.set ("privacy/trash", HOUSEKEEPING);
supported_settings.set ("security/firewall", FIREWALL);
supported_settings.set ("security/locking", LOCKING);
supported_settings.set ("security", null);

// DEPRECATED
supported_settings.set ("security/housekeeping", HOUSEKEEPING);
supported_settings.set ("security/privacy", HISTORY);
supported_settings.set ("security/privacy/location", LOCATION);
supported_settings.set ("security/screensaver", LOCKING);
}

public override Gtk.Widget get_widget () {
if (main_grid == null) {
main_grid = new Gtk.Grid ();
}

return main_grid;
}

public override void shown () {
if (main_grid.get_children ().length () > 0) {
return;
}

stack = new Gtk.Stack ();

var label = new Gtk.Label (_("Some settings require administrator rights to be changed"));

var infobar = new Gtk.InfoBar () {
message_type = Gtk.MessageType.INFO
};
infobar.get_content_area ().add (label);

var grid = new Gtk.Grid ();
grid.attach (infobar, 0, 0);
grid.attach (stack, 0, 1);
public class SecurityPrivacy.Plug : Switchboard.Plug {
private Polkit.Permission permission;
private Gtk.Paned paned;
private Gtk.Stack stack;

private const string FIREWALL = "firewall";
private const string HOUSEKEEPING = "housekeeping";
private const string HISTORY = "tracking";
private const string LOCKING = "locking";
private const string LOCATION = "location";

public Plug () {
GLib.Intl.bindtextdomain (Build.GETTEXT_PACKAGE, Build.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Build.GETTEXT_PACKAGE, "UTF-8");

Object (category: Category.PERSONAL,
code_name: "io.elementary.switchboard.security-privacy",
display_name: _("Security & Privacy"),
description: _("Configure firewall, screen lock, and activity information"),
icon: "preferences-system-privacy",
supported_settings: new Gee.TreeMap<string, string?> (null, null));

supported_settings.set ("privacy", HISTORY);
supported_settings.set ("privacy/location", LOCATION);
supported_settings.set ("privacy/trash", HOUSEKEEPING);
supported_settings.set ("security/firewall", FIREWALL);
supported_settings.set ("security/locking", LOCKING);
supported_settings.set ("security", null);

// DEPRECATED
supported_settings.set ("security/housekeeping", HOUSEKEEPING);
supported_settings.set ("security/privacy", HISTORY);
supported_settings.set ("security/privacy/location", LOCATION);
supported_settings.set ("security/screensaver", LOCKING);
}

public override Gtk.Widget get_widget () {
if (paned == null) {
try {
var permission = new Polkit.Permission.sync (
permission = new Polkit.Permission.sync (
"io.elementary.switchboard.security-privacy",
new Polkit.UnixProcess (Posix.getpid ())
);

lock_button = new Gtk.LockButton (permission);

infobar.revealed = false;
infobar.get_action_area ().add (lock_button);

stack.notify["visible-child-name"].connect (() => {
if (permission.allowed == false && stack.visible_child_name == "firewall") {
infobar.revealed = true;
} else {
infobar.revealed = false;
}
});

permission.notify["allowed"].connect (() => {
if (permission.allowed == false && stack.visible_child_name == "firewall") {
infobar.revealed = true;
} else {
infobar.revealed = false;
}
});
} catch (Error e) {
critical (e.message);
}

tracking = new TrackPanel ();
var label = new Gtk.Label (_("Some settings require administrator rights to be changed"));

var lock_button = new Gtk.LockButton (permission);

var infobar = new Gtk.InfoBar () {
message_type = INFO,
revealed = false
};
infobar.get_content_area ().add (label);
infobar.get_action_area ().add (lock_button);

var tracking = new TrackPanel ();
var locking = new LockPanel ();
firewall = new FirewallPanel ();
housekeeping = new HouseKeepingPanel ();
location = new LocationPanel ();
var firewall = new FirewallPanel (permission);
var housekeeping = new HouseKeepingPanel ();
var location = new LocationPanel ();

stack = new Gtk.Stack ();
stack.add_titled (tracking, HISTORY, _("Privacy"));
stack.add_titled (locking, LOCKING, _("Locking"));
stack.add_titled (firewall, FIREWALL, _("Firewall"));
stack.add_titled (housekeeping, HOUSEKEEPING, _("Housekeeping"));
stack.add_titled (location, LOCATION, _("Location Services"));

var box = new Gtk.Box (VERTICAL, 0);
box.add (infobar);
box.add (stack);

var settings_sidebar = new Granite.SettingsSidebar (stack);

var paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
paned.position = 200;
Marukesu marked this conversation as resolved.
Show resolved Hide resolved
paned = new Gtk.Paned (HORIZONTAL);
paned.add1 (settings_sidebar);
paned.add2 (grid);
paned.add2 (box);
paned.show_all ();

stack.notify["visible-child"].connect (() => {
infobar.revealed = stack.visible_child == firewall && !permission.allowed;
});

main_grid.add (paned);
main_grid.show_all ();
permission.notify["allowed"].connect (() => {
infobar.revealed = stack.visible_child == firewall && !permission.allowed;
});
}

public override void hidden () {
return paned;
}

}
public override void shown () { }

public override void search_callback (string location) {
if (main_grid.get_children ().length () == 0) {
shown ();
}
public override void hidden () { }

stack.set_visible_child_name (location);
}
public override void search_callback (string location) {
stack.set_visible_child_name (location);
}

// 'search' returns results like ("Keyboard → Behavior → Duration", "keyboard<sep>behavior")
public override async Gee.TreeMap<string, string> search (string search) {
var map = new Gee.TreeMap<string, string> (null, null);
map.set ("%s → %s".printf (display_name, _("History")), HISTORY);
map.set ("%s → %s → %s".printf (display_name, _("History"), _("Clear History")), HISTORY);
map.set ("%s → %s".printf (display_name, _("Locking")), LOCKING);
map.set ("%s → %s → %s".printf (display_name, _("Locking"), _("Lock on sleep")), HISTORY);
map.set ("%s → %s → %s".printf (display_name, _("Locking"), _("Lock after sceen turns off")), HISTORY);
map.set ("%s → %s".printf (display_name, _("Firewall")), FIREWALL);
map.set ("%s → %s".printf (display_name, _("Housekeeping")), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Automatically delete old temporary files")
), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Automatically delete old screenshot files")
), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Automatically delete old trashed files")
), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Number of days to keep trashed and temporary files")
), HOUSEKEEPING);
map.set ("%s → %s".printf (display_name, _("Location Services")), LOCATION);
return map;
}
// 'search' returns results like ("Keyboard → Behavior → Duration", "keyboard<sep>behavior")
public override async Gee.TreeMap<string, string> search (string search) {
var map = new Gee.TreeMap<string, string> (null, null);
map.set ("%s → %s".printf (display_name, _("History")), HISTORY);
map.set ("%s → %s → %s".printf (display_name, _("History"), _("Clear History")), HISTORY);
map.set ("%s → %s".printf (display_name, _("Locking")), LOCKING);
map.set ("%s → %s → %s".printf (display_name, _("Locking"), _("Lock on sleep")), HISTORY);
map.set ("%s → %s → %s".printf (display_name, _("Locking"), _("Lock after sceen turns off")), HISTORY);
map.set ("%s → %s".printf (display_name, _("Firewall")), FIREWALL);
map.set ("%s → %s".printf (display_name, _("Housekeeping")), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Automatically delete old temporary files")
), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Automatically delete old screenshot files")
), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Automatically delete old trashed files")
), HOUSEKEEPING);
map.set ("%s → %s → %s".printf (
display_name,
_("Housekeeping"),
_("Number of days to keep trashed and temporary files")
), HOUSEKEEPING);
map.set ("%s → %s".printf (display_name, _("Location Services")), LOCATION);
return map;
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/Views/FirewallPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/

public class SecurityPrivacy.FirewallPanel : Granite.SimpleSettingsPage {
public Polkit.Permission permission { get; construct; }

private Gtk.ListStore list_store;
private Gtk.TreeView view;
private Gtk.ActionBar actionbar;
Expand All @@ -42,10 +44,13 @@ public class SecurityPrivacy.FirewallPanel : Granite.SimpleSettingsPage {
N_COLUMNS
}

public FirewallPanel () {
Object (activatable: true,
icon_name: "network-firewall",
title: _("Firewall"));
public FirewallPanel (Polkit.Permission permission) {
Object (
activatable: true,
icon_name: "network-firewall",
title: _("Firewall"),
permission: permission
);
}

construct {
Expand All @@ -64,9 +69,9 @@ public class SecurityPrivacy.FirewallPanel : Granite.SimpleSettingsPage {

sensitive = false;

lock_button.get_permission ().notify["allowed"].connect (() => {
permission.notify["allowed"].connect (() => {
loading = true;
sensitive = lock_button.get_permission ().allowed;
sensitive = permission.allowed;
status_switch.active = UFWHelpers.get_status ();
list_store.clear ();
remove_button.sensitive = false;
Expand Down