summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacy Kuchciński <ignacykuchcinski@gmail.com>2022-02-25 16:54:10 +0100
committerAntónio Fernandes <antoniof@gnome.org>2022-08-23 18:32:03 +0000
commit5b954ee53543cbc9f56cf2fbbc5231df8a6d4235 (patch)
tree7ac1135dc3cfb585c16b04b0c73b701969a3b866
parent8fcb98f8a316e1cd34c16839a4e72854e80dc7bc (diff)
downloadnautilus-5b954ee53543cbc9f56cf2fbbc5231df8a6d4235.tar.gz
trash-bar: Remove trash infobar
Currently trash infobar contains actions for restoring files and emptying trash. This is misusing of the GtkInfoBar, as it should only be used to present some kind of status message, and having so many different buttons for actions is uncommon and resulted in https://gitlab.gnome.org/GNOME/nautilus/-/issues/2096 To fix that, remove the trash infobar altogether, with intention of rolling it into special-location-bar, as it will only have 1 button.
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/meson.build2
-rw-r--r--src/nautilus-trash-bar.c281
-rw-r--r--src/nautilus-trash-bar.h36
-rw-r--r--src/nautilus-window-slot.c115
5 files changed, 24 insertions, 411 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6bea74b37..0adfd1c0f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -57,7 +57,6 @@ src/nautilus-search-popover.c
src/nautilus-shell-search-provider.c
src/nautilus-special-location-bar.c
src/nautilus-toolbar.c
-src/nautilus-trash-bar.c
src/nautilus-ui-utilities.c
src/nautilus-vfs-file.c
src/nautilus-view.c
diff --git a/src/meson.build b/src/meson.build
index 339a50aa0..383920c3d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -129,8 +129,6 @@ libnautilus_sources = [
'nautilus-toolbar.c',
'nautilus-toolbar.h',
'nautilus-toolbar-menu-sections.h',
- 'nautilus-trash-bar.c',
- 'nautilus-trash-bar.h',
'nautilus-view.c',
'nautilus-view.h',
'nautilus-view-cell.c',
diff --git a/src/nautilus-trash-bar.c b/src/nautilus-trash-bar.c
deleted file mode 100644
index 558b88557..000000000
--- a/src/nautilus-trash-bar.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (C) 2006 Paolo Borelli <pborelli@katamail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Authors: Paolo Borelli <pborelli@katamail.com>
- *
- */
-
-#include "config.h"
-
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-
-#include "nautilus-trash-bar.h"
-
-#include "nautilus-dbus-launcher.h"
-#include "nautilus-global-preferences.h"
-#include "nautilus-files-view.h"
-#include "nautilus-file-operations.h"
-#include "nautilus-file-utilities.h"
-#include "nautilus-file.h"
-#include "nautilus-trash-monitor.h"
-#include "nautilus-ui-utilities.h"
-
-enum
-{
- PROP_VIEW = 1,
- NUM_PROPERTIES
-};
-
-enum
-{
- TRASH_BAR_RESPONSE_AUTODELETE = 1,
- TRASH_BAR_RESPONSE_EMPTY,
- TRASH_BAR_RESPONSE_RESTORE
-};
-
-struct _NautilusTrashBar
-{
- AdwBin parent_instance;
-
- NautilusFilesView *view;
- gulong selection_handler_id;
-};
-
-G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, ADW_TYPE_BIN)
-
-static void
-selection_changed_cb (NautilusFilesView *view,
- NautilusTrashBar *bar)
-{
- g_autolist (NautilusFile) selection = NULL;
- GtkWidget *info_bar;
- int count;
-
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- count = g_list_length (selection);
-
- info_bar = adw_bin_get_child (ADW_BIN (bar));
- gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (info_bar),
- TRASH_BAR_RESPONSE_RESTORE,
- (count > 0));
-}
-
-static void
-connect_view_and_update_button (NautilusTrashBar *bar)
-{
- bar->selection_handler_id = g_signal_connect (bar->view,
- "selection-changed",
- G_CALLBACK (selection_changed_cb),
- bar);
-
- selection_changed_cb (bar->view, bar);
-}
-
-static void
-nautilus_trash_bar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NautilusTrashBar *bar = NAUTILUS_TRASH_BAR (object);
-
- switch (prop_id)
- {
- case PROP_VIEW:
- {
- bar->view = g_value_get_object (value);
- connect_view_and_update_button (NAUTILUS_TRASH_BAR (object));
- }
- break;
-
- default:
- {
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
- break;
- }
-}
-
-static void
-nautilus_trash_bar_dispose (GObject *obj)
-{
- NautilusTrashBar *bar = NAUTILUS_TRASH_BAR (obj);
-
- g_clear_signal_handler (&bar->selection_handler_id, bar->view);
-
- G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->dispose (obj);
-}
-
-static void
-nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
- gboolean state,
- gpointer data)
-{
- NautilusTrashBar *bar;
- GtkWidget *info_bar;
-
- bar = NAUTILUS_TRASH_BAR (data);
-
- info_bar = adw_bin_get_child (ADW_BIN (bar));
- gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (info_bar),
- TRASH_BAR_RESPONSE_EMPTY,
- !nautilus_trash_monitor_is_empty ());
-}
-
-static void
-nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
-{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = nautilus_trash_bar_set_property;
- object_class->dispose = nautilus_trash_bar_dispose;
-
- g_object_class_install_property (object_class,
- PROP_VIEW,
- g_param_spec_object ("view",
- "view",
- "the NautilusFilesView",
- NAUTILUS_TYPE_FILES_VIEW,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-}
-
-static void
-trash_bar_response_cb (GtkInfoBar *infobar,
- gint response_id,
- gpointer user_data)
-{
- NautilusTrashBar *bar;
- GtkRoot *window;
-
- bar = NAUTILUS_TRASH_BAR (user_data);
- window = gtk_widget_get_root (GTK_WIDGET (bar));
-
- switch (response_id)
- {
- case TRASH_BAR_RESPONSE_AUTODELETE:
- {
- 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;
-
- case TRASH_BAR_RESPONSE_EMPTY:
- {
- nautilus_file_operations_empty_trash (GTK_WIDGET (window), TRUE, NULL);
- }
- break;
-
- case TRASH_BAR_RESPONSE_RESTORE:
- {
- g_autolist (NautilusFile) selection = NULL;
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (bar->view));
- nautilus_restore_files_from_trash (selection, GTK_WINDOW (window));
- }
- break;
-
- default:
- {
- }
- break;
- }
-}
-
-static void
-nautilus_trash_bar_init (NautilusTrashBar *bar)
-{
- GtkWidget *info_bar;
- GtkWidget *w;
- const gchar *subtitle_text;
- GtkWidget *label;
- GtkWidget *subtitle;
- PangoAttrList *attrs;
-
- info_bar = gtk_info_bar_new ();
- gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
- gtk_widget_show (info_bar);
- adw_bin_set_child (ADW_BIN (bar), info_bar);
-
- attrs = pango_attr_list_new ();
- pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
- label = gtk_label_new (_("Trash"));
- gtk_label_set_attributes (GTK_LABEL (label), attrs);
- pango_attr_list_unref (attrs);
-
- subtitle_text = _("Trashed items are automatically deleted after a period of time");
- subtitle = gtk_label_new (subtitle_text);
- gtk_widget_set_tooltip_text (subtitle, subtitle_text);
- gtk_label_set_ellipsize (GTK_LABEL (subtitle), PANGO_ELLIPSIZE_END);
-
- g_settings_bind (gnome_privacy_preferences,
- "remove-old-trash-files",
- subtitle,
- "visible",
- G_SETTINGS_BIND_GET);
-
- gtk_widget_show (label);
- gtk_info_bar_add_child (GTK_INFO_BAR (info_bar), label);
-
- gtk_info_bar_add_child (GTK_INFO_BAR (info_bar), subtitle);
-
- w = gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
- _("_Settings"),
- TRASH_BAR_RESPONSE_AUTODELETE);
- gtk_widget_set_tooltip_text (w,
- _("Display system controls for trash content"));
-
- w = gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
- _("_Restore"),
- TRASH_BAR_RESPONSE_RESTORE);
- gtk_widget_set_tooltip_text (w,
- _("Restore selected items to their original position"));
-
- w = gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
- /* Translators: "Empty" is an action (for the trash) , not a state */
- _("_Empty…"),
- TRASH_BAR_RESPONSE_EMPTY);
- gtk_widget_set_tooltip_text (w,
- _("Delete all items in the Trash"));
-
- g_signal_connect_object (nautilus_trash_monitor_get (),
- "trash-state-changed",
- G_CALLBACK (nautilus_trash_bar_trash_state_changed),
- bar,
- 0);
- nautilus_trash_bar_trash_state_changed (nautilus_trash_monitor_get (),
- FALSE, bar);
-
- g_signal_connect (info_bar, "response",
- G_CALLBACK (trash_bar_response_cb), bar);
-}
-
-GtkWidget *
-nautilus_trash_bar_new (NautilusFilesView *view)
-{
- return g_object_new (NAUTILUS_TYPE_TRASH_BAR,
- "view", view,
- NULL);
-}
diff --git a/src/nautilus-trash-bar.h b/src/nautilus-trash-bar.h
deleted file mode 100644
index 4f03f2edc..000000000
--- a/src/nautilus-trash-bar.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2006 Paolo Borelli <pborelli@katamail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Authors: Paolo Borelli <pborelli@katamail.com>
- *
- */
-
-#pragma once
-
-#include "nautilus-files-view.h"
-
-#include <gtk/gtk.h>
-#include <libadwaita-1/adwaita.h>
-
-G_BEGIN_DECLS
-
-#define NAUTILUS_TYPE_TRASH_BAR (nautilus_trash_bar_get_type ())
-
-G_DECLARE_FINAL_TYPE (NautilusTrashBar, nautilus_trash_bar, NAUTILUS, TRASH_BAR, AdwBin)
-
-GtkWidget *nautilus_trash_bar_new (NautilusFilesView *view);
-
-G_END_DECLS
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 21ae9035a..b06af53ca 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -26,13 +26,12 @@
#include "nautilus-application.h"
#include "nautilus-bookmark.h"
#include "nautilus-bookmark-list.h"
+#include "nautilus-files-view.h"
#include "nautilus-mime-actions.h"
#include "nautilus-places-view.h"
#include "nautilus-query-editor.h"
#include "nautilus-special-location-bar.h"
#include "nautilus-toolbar.h"
-#include "nautilus-trash-bar.h"
-#include "nautilus-trash-monitor.h"
#include "nautilus-view.h"
#include "nautilus-window.h"
#include "nautilus-x-content-bar.h"
@@ -172,9 +171,6 @@ static void nautilus_window_slot_set_search_visible (NautilusWindowSlot *self,
static gboolean nautilus_window_slot_get_search_visible (NautilusWindowSlot *self);
static void nautilus_window_slot_set_location (NautilusWindowSlot *self,
GFile *location);
-static void trash_state_changed_cb (NautilusTrashMonitor *monitor,
- gboolean is_empty,
- gpointer user_data);
static void update_search_information (NautilusWindowSlot *self);
static void real_set_extensions_background_menu (NautilusWindowSlot *self,
GMenuModel *menu);
@@ -1118,10 +1114,6 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
app = g_application_get_default ();
- g_signal_connect (nautilus_trash_monitor_get (),
- "trash-state-changed",
- G_CALLBACK (trash_state_changed_cb), self);
-
g_signal_connect_object (nautilus_preferences,
"changed::recursive-search",
G_CALLBACK (recursive_search_preferences_changed),
@@ -2531,55 +2523,6 @@ out:
}
static void
-trash_state_changed_cb (NautilusTrashMonitor *monitor,
- gboolean is_empty,
- gpointer user_data)
-{
- GFile *location;
- NautilusDirectory *directory;
- NautilusView *view;
-
- location = nautilus_window_slot_get_current_location (user_data);
- view = nautilus_window_slot_get_current_view (user_data);
-
- /* The signal 'trash-state-changed' could be emitted by NautilusTrashMonitor
- * while a NautilusWindowSlot is still initializing the content view.
- */
- if (location == NULL || view == NULL)
- {
- return;
- }
-
- directory = nautilus_directory_get (location);
-
- if (nautilus_directory_is_in_trash (directory))
- {
- if (nautilus_trash_monitor_is_empty ())
- {
- nautilus_window_slot_remove_extra_location_widgets (user_data);
- }
- else
- {
- nautilus_window_slot_setup_extra_location_widgets (user_data);
- }
- }
-}
-
-static void
-nautilus_window_slot_show_trash_bar (NautilusWindowSlot *self)
-{
- GtkWidget *bar;
- NautilusView *view;
-
- view = nautilus_window_slot_get_current_view (self);
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- bar = nautilus_trash_bar_new (NAUTILUS_FILES_VIEW (view));
- gtk_widget_show (bar);
-
- nautilus_window_slot_add_extra_location_widget (self, bar);
-}
-
-static void
nautilus_window_slot_show_special_location_bar (NautilusWindowSlot *self,
NautilusSpecialLocation special_location)
{
@@ -2694,6 +2637,11 @@ nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *self)
GFile *location;
FindMountData *data;
NautilusDirectory *directory;
+ NautilusFile *file;
+ GFile *scripts_file;
+ char *scripts_path;
+
+ scripts_path = nautilus_get_scripts_directory_path ();
location = nautilus_window_slot_get_current_location (self);
if (location == NULL)
@@ -2703,42 +2651,28 @@ nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *self)
directory = nautilus_directory_get (location);
- if (nautilus_directory_is_in_trash (directory))
+ scripts_file = g_file_new_for_path (scripts_path);
+ g_free (scripts_path);
+
+ file = nautilus_file_get (location);
+
+ if (nautilus_should_use_templates_directory () &&
+ nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_TEMPLATES))
{
- if (!nautilus_trash_monitor_is_empty ())
- {
- nautilus_window_slot_show_trash_bar (self);
- }
+ nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_TEMPLATES);
}
- else
+ else if (g_file_equal (location, scripts_file))
{
- NautilusFile *file;
- GFile *scripts_file;
- char *scripts_path = nautilus_get_scripts_directory_path ();
-
- scripts_file = g_file_new_for_path (scripts_path);
- g_free (scripts_path);
-
- file = nautilus_file_get (location);
-
- if (nautilus_should_use_templates_directory () &&
- nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_TEMPLATES))
- {
- nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_TEMPLATES);
- }
- else if (g_file_equal (location, scripts_file))
- {
- nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SCRIPTS);
- }
- else if (check_schema_available (FILE_SHARING_SCHEMA_ID) &&
- nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_PUBLIC_SHARE))
- {
- nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SHARING);
- }
-
- g_object_unref (scripts_file);
- nautilus_file_unref (file);
+ nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SCRIPTS);
}
+ else if (check_schema_available (FILE_SHARING_SCHEMA_ID) &&
+ nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_PUBLIC_SHARE))
+ {
+ nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SHARING);
+ }
+
+ g_object_unref (scripts_file);
+ nautilus_file_unref (file);
/* need the mount to determine if we should put up the x-content cluebar */
if (self->find_mount_cancellable != NULL)
@@ -2874,7 +2808,6 @@ nautilus_window_slot_dispose (GObject *object)
{
NautilusWindowSlot *self;
self = NAUTILUS_WINDOW_SLOT (object);
- g_signal_handlers_disconnect_by_data (nautilus_trash_monitor_get (), self);
g_signal_handlers_disconnect_by_data (nautilus_preferences, self);