summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacy Kuchciński <ignacykuchcinski@gmail.com>2022-08-12 13:01:27 +0200
committerAntónio Fernandes <antoniof@gnome.org>2022-08-23 18:32:03 +0000
commita83b9573e41610baf13f1a21c8fe488a2bb068a4 (patch)
tree3a0f77a75fe5382afc081a46096952e5ecfa8e8b
parent5b954ee53543cbc9f56cf2fbbc5231df8a6d4235 (diff)
downloadnautilus-a83b9573e41610baf13f1a21c8fe488a2bb068a4.tar.gz
special-location-bar: Add trash bar
After removing the separate trash bar, let's roll it into special location bar, as it only has 1 button now.
-rw-r--r--src/nautilus-special-location-bar.c70
-rw-r--r--src/nautilus-special-location-bar.h1
-rw-r--r--src/nautilus-window-slot.c38
3 files changed, 108 insertions, 1 deletions
diff --git a/src/nautilus-special-location-bar.c b/src/nautilus-special-location-bar.c
index 2c4c5d510..ae976454c 100644
--- a/src/nautilus-special-location-bar.c
+++ b/src/nautilus-special-location-bar.c
@@ -23,6 +23,7 @@
#include <string.h>
#include "nautilus-dbus-launcher.h"
+#include "nautilus-global-preferences.h"
#include "nautilus-special-location-bar.h"
#include "nautilus-enum-types.h"
@@ -46,6 +47,7 @@ enum
enum
{
SPECIAL_LOCATION_SHARING_RESPONSE = 1,
+ SPECIAL_LOCATION_TRASH_RESPONSE = 2,
};
G_DEFINE_TYPE (NautilusSpecialLocationBar, nautilus_special_location_bar, ADW_TYPE_BIN)
@@ -56,6 +58,7 @@ on_info_bar_response (GtkInfoBar *infobar,
gpointer user_data)
{
NautilusSpecialLocationBar *bar = user_data;
+ GtkRoot *window = gtk_widget_get_root (GTK_WIDGET (bar));
switch (bar->button_response)
{
@@ -68,7 +71,20 @@ on_info_bar_response (GtkInfoBar *infobar,
nautilus_dbus_launcher_call (nautilus_dbus_launcher_get (),
NAUTILUS_DBUS_LAUNCHER_SETTINGS,
"Activate",
- parameters, NULL);
+ parameters, GTK_WINDOW (window));
+ }
+ break;
+
+ case SPECIAL_LOCATION_TRASH_RESPONSE:
+ {
+ GVariant *parameters;
+
+ parameters = g_variant_new_parsed ("('launch-panel', [<('usage', @av [])>], "
+ "@a{sv} {})");
+ nautilus_dbus_launcher_call (nautilus_dbus_launcher_get (),
+ NAUTILUS_DBUS_LAUNCHER_SETTINGS,
+ "Activate",
+ parameters, GTK_WINDOW (window));
}
break;
@@ -79,6 +95,45 @@ on_info_bar_response (GtkInfoBar *infobar,
}
}
+static gchar *
+parse_old_files_age_preferences_value (void)
+{
+ guint old_files_age = g_settings_get_uint (gnome_privacy_preferences, "old-files-age");
+
+ switch (old_files_age)
+ {
+ case 0:
+ {
+ return g_strdup (_("Items in Trash older than 1 hour are automatically deleted"));
+ }
+
+ default:
+ {
+ return g_strdup_printf (ngettext ("Items in Trash older than %d day are automatically deleted",
+ "Items in Trash older than %d days are automatically deleted",
+ old_files_age),
+ old_files_age);
+ }
+ }
+}
+
+static void
+old_files_age_preferences_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data)
+{
+ NautilusSpecialLocationBar *bar;
+ g_autofree gchar *message = NULL;
+
+ g_assert (NAUTILUS_IS_SPECIAL_LOCATION_BAR (user_data));
+
+ bar = NAUTILUS_SPECIAL_LOCATION_BAR (user_data);
+
+ message = parse_old_files_age_preferences_value ();
+
+ gtk_label_set_text (GTK_LABEL (bar->label), message);
+}
+
static void
set_special_location (NautilusSpecialLocationBar *bar,
NautilusSpecialLocation location)
@@ -110,6 +165,19 @@ set_special_location (NautilusSpecialLocationBar *bar,
}
break;
+ case NAUTILUS_SPECIAL_LOCATION_TRASH:
+ {
+ message = parse_old_files_age_preferences_value ();
+ button_label = _("_Settings");
+ bar->button_response = SPECIAL_LOCATION_TRASH_RESPONSE;
+
+ g_signal_connect_object (gnome_privacy_preferences,
+ "changed::old-files-age",
+ G_CALLBACK (old_files_age_preferences_changed),
+ bar, 0);
+ }
+ break;
+
default:
{
g_assert_not_reached ();
diff --git a/src/nautilus-special-location-bar.h b/src/nautilus-special-location-bar.h
index 3680b58f0..52d67e3ca 100644
--- a/src/nautilus-special-location-bar.h
+++ b/src/nautilus-special-location-bar.h
@@ -31,6 +31,7 @@ typedef enum {
NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
NAUTILUS_SPECIAL_LOCATION_SCRIPTS,
NAUTILUS_SPECIAL_LOCATION_SHARING,
+ NAUTILUS_SPECIAL_LOCATION_TRASH,
} NautilusSpecialLocation;
GtkWidget *nautilus_special_location_bar_new (NautilusSpecialLocation location);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index b06af53ca..64ab6293d 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -1102,6 +1102,34 @@ recursive_search_preferences_changed (GSettings *settings,
}
static void
+remove_old_trash_files_preferences_changed (GSettings *settings,
+ gchar *key,
+ gpointer callback_data)
+{
+ NautilusWindowSlot *self;
+ GFile *location;
+ g_autoptr (NautilusDirectory) directory = NULL;
+
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (callback_data));
+
+ self = NAUTILUS_WINDOW_SLOT (callback_data);
+ location = nautilus_window_slot_get_current_location (self);
+ directory = nautilus_directory_get (location);
+
+ if (nautilus_directory_is_in_trash (directory))
+ {
+ if (g_settings_get_boolean (gnome_privacy_preferences, "remove-old-trash-files"))
+ {
+ nautilus_window_slot_setup_extra_location_widgets (self);
+ }
+ else
+ {
+ nautilus_window_slot_remove_extra_location_widgets (self);
+ }
+ }
+}
+
+static void
nautilus_window_slot_init (NautilusWindowSlot *self)
{
GApplication *app;
@@ -1119,6 +1147,11 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
G_CALLBACK (recursive_search_preferences_changed),
self, 0);
+ g_signal_connect_object (gnome_privacy_preferences,
+ "changed::remove-old-trash-files",
+ G_CALLBACK (remove_old_trash_files_preferences_changed),
+ self, 0);
+
self->slot_action_group = G_ACTION_GROUP (g_simple_action_group_new ());
g_action_map_add_action_entries (G_ACTION_MAP (self->slot_action_group),
slot_entries,
@@ -2670,6 +2703,11 @@ nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *self)
{
nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SHARING);
}
+ else if (nautilus_directory_is_in_trash (directory) &&
+ g_settings_get_boolean (gnome_privacy_preferences, "remove-old-trash-files"))
+ {
+ nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_TRASH);
+ }
g_object_unref (scripts_file);
nautilus_file_unref (file);