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

TrackPanel: make clear history a dialog #168

Merged
merged 4 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
2 changes: 1 addition & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ src/Views/TrackPanel.vala
src/Views/LocationPanel.vala
src/Widgets/AppChooser.vala
src/Widgets/AppRow.vala
src/Widgets/ClearUsagePopover.vala
src/Widgets/ClearUsageDialog.vala
src/Widgets/ExcludeTreeView.vala
src/Widgets/IncludeTreeView.vala
26 changes: 10 additions & 16 deletions src/Views/TrackPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
public class SecurityPrivacy.TrackPanel : Granite.SimpleSettingsPage {
public static SecurityPrivacy.Blacklist blacklist { get; private set; }

private Widgets.ClearUsagePopover remove_popover;

public TrackPanel () {
Object (
activatable: true,
Expand Down Expand Up @@ -54,19 +52,7 @@ public class SecurityPrivacy.TrackPanel : Granite.SimpleSettingsPage {

status_switch.active = true;

var clear_data = new Gtk.ToggleButton.with_label (_("Clear History…"));
clear_data.notify["active"].connect (() => {
if (clear_data.active == false) {
remove_popover.hide ();
} else {
remove_popover.show_all ();
}
});

remove_popover = new Widgets.ClearUsagePopover (clear_data);
remove_popover.closed.connect (() => {
clear_data.active = false;
});
var clear_button = new Gtk.Button.with_label (_("Clear History…"));

var include_treeview = new IncludeTreeView ();
var exclude_treeview = new ExcludeTreeView ();
Expand All @@ -75,7 +61,7 @@ public class SecurityPrivacy.TrackPanel : Granite.SimpleSettingsPage {
content_area.attach (include_treeview, 0, 1, 1, 1);
content_area.attach (exclude_treeview, 1, 1, 1, 1);

action_area.add (clear_data);
action_area.add (clear_button);

status_switch.notify["active"].connect (() => {
bool privacy_mode = !status_switch.active;
Expand All @@ -97,6 +83,14 @@ public class SecurityPrivacy.TrackPanel : Granite.SimpleSettingsPage {
status_switch.active = !blacklist.get_incognito ();

update_status_switch ();

clear_button.clicked.connect (() => {
var clear_dialog = new Widgets.ClearUsageDialog () {
modal = true,
transient_for = (Gtk.Window) get_toplevel ()
};
clear_dialog.present ();
});
}

private static string get_operating_system_name () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
/*-
* Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
*
* 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
* Lesser 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 <corentin@elementaryos.org>
*/

public class SecurityPrivacy.Widgets.ClearUsagePopover : Gtk.Popover {
public class SecurityPrivacy.Widgets.ClearUsageDialog : Granite.MessageDialog {
private Granite.Widgets.DatePicker to_datepicker;
private Granite.Widgets.DatePicker from_datepicker;
private Gtk.RadioButton all_time_radio;
Expand All @@ -31,16 +16,19 @@ public class SecurityPrivacy.Widgets.ClearUsagePopover : Gtk.Popover {

private List<Gtk.RecentInfo> items;

public ClearUsagePopover (Gtk.Widget? relative_to) {
Object (relative_to: relative_to);
public ClearUsageDialog () {
Object (
buttons: Gtk.ButtonsType.CANCEL,
image_icon: new ThemedIcon ("document-open-recent"),
badge_icon: new ThemedIcon ("edit-delete"),
primary_text: _("Clear system-collected file and app usage history"),
secondary_text: _("The data from the selected time frame will be permanently deleted and cannot be restored")
);
}

construct {
recent = new Gtk.RecentManager ();

var clear_label = new Gtk.Label (_("Remove system-collected file and application usage data from:"));
clear_label.halign = Gtk.Align.START;

past_hour_radio = new Gtk.RadioButton.with_label (null, _("The past hour"));
past_day_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("The past day"));
past_week_radio = new Gtk.RadioButton.with_label_from_widget (past_hour_radio, _("The past week"));
Expand All @@ -51,29 +39,31 @@ public class SecurityPrivacy.Widgets.ClearUsagePopover : Gtk.Popover {
var to_label = new Gtk.Label (_("To:"));
to_datepicker = new Granite.Widgets.DatePicker ();

var clear_button = new Gtk.Button.with_label (_("Clear Data"));
var grid = new Gtk.Grid () {
column_spacing = 12,
row_spacing = 6
};
grid.attach (past_hour_radio, 0, 1, 4);
grid.attach (past_day_radio, 0, 2, 4);
grid.attach (past_week_radio, 0, 3, 4);
grid.attach (from_radio, 0, 4);
grid.attach (from_datepicker, 1, 4);
grid.attach (to_label, 2, 4);
grid.attach (to_datepicker, 3, 4);
grid.attach (all_time_radio, 0, 5, 4);
grid.show_all ();

custom_bin.add (grid);

var clear_button = add_button (_("Clear History"), Gtk.ResponseType.APPLY);
clear_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
clear_button.halign = Gtk.Align.END;

var grid = new Gtk.Grid ();
grid.margin = 12;
grid.column_spacing = 12;
grid.row_spacing = 6;
grid.attach (clear_label, 0, 0, 4, 1);
grid.attach (past_hour_radio, 0, 1, 4, 1);
grid.attach (past_day_radio, 0, 2, 4, 1);
grid.attach (past_week_radio, 0, 3, 4, 1);
grid.attach (from_radio, 0, 4, 1, 1);
grid.attach (from_datepicker, 1, 4, 1, 1);
grid.attach (to_label, 2, 4, 1, 1);
grid.attach (to_datepicker, 3, 4, 1, 1);
grid.attach (all_time_radio, 0, 5, 4, 1);
grid.attach (clear_button, 0, 6, 4, 1);

add (grid);

clear_button.clicked.connect (() => {
on_clear_data ();

response.connect ((response) => {
if (response == Gtk.ResponseType.APPLY) {
on_clear_data ();
}

close ();
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plug_files = files(
'Views/LocationPanel.vala',
'Widgets/AppChooser.vala',
'Widgets/AppRow.vala',
'Widgets/ClearUsagePopover.vala',
'Widgets/ClearUsageDialog.vala',
'Widgets/ExcludeTreeView.vala',
'Widgets/IncludeTreeView.vala'
)
Expand Down