Use GtkTrashMonitor instead of an API to set the trash state

This lets us remove two entry points, gtk_places_sidebar_set_show_trash(),
and gtk_places_sidebar_set_trash_is_full().

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
This commit is contained in:
Federico Mena Quintero 2013-01-10 15:06:01 -06:00
parent ee261203cb
commit 439a770efa
2 changed files with 38 additions and 42 deletions

View File

@ -81,6 +81,7 @@
#include "gtkseparatormenuitem.h" #include "gtkseparatormenuitem.h"
#include "gtksettings.h" #include "gtksettings.h"
#include "gtkstock.h" #include "gtkstock.h"
#include "gtktrashmonitor.h"
#include "gtktreeselection.h" #include "gtktreeselection.h"
#include "gtktreednd.h" #include "gtktreednd.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
@ -92,13 +93,17 @@
#define DO_NOT_COMPILE 0 #define DO_NOT_COMPILE 0
struct _GtkPlacesSidebar { struct _GtkPlacesSidebar {
GtkScrolledWindow parent; GtkScrolledWindow parent;
GtkTreeView *tree_view;
GtkCellRenderer *eject_icon_cell_renderer; GtkTreeView *tree_view;
char *uri; GtkCellRenderer *eject_icon_cell_renderer;
GtkListStore *store; char *uri;
GtkBookmarksManager *bookmarks_manager; GtkListStore *store;
GVolumeMonitor *volume_monitor; GtkBookmarksManager *bookmarks_manager;
GVolumeMonitor *volume_monitor;
GtkTrashMonitor *trash_monitor;
gulong trash_monitor_changed_id;
gboolean devices_header_added; gboolean devices_header_added;
gboolean bookmarks_header_added; gboolean bookmarks_header_added;
@ -121,8 +126,6 @@ struct _GtkPlacesSidebar {
char *hostname; char *hostname;
guint show_desktop : 1; guint show_desktop : 1;
guint show_trash : 1;
guint trash_is_full : 1;
guint accept_uri_drops : 1; guint accept_uri_drops : 1;
}; };
@ -201,8 +204,6 @@ enum {
#define ICON_NAME_FILESYSTEM "drive-harddisk-symbolic" #define ICON_NAME_FILESYSTEM "drive-harddisk-symbolic"
#define ICON_NAME_EJECT "media-eject-symbolic" #define ICON_NAME_EJECT "media-eject-symbolic"
#define ICON_NAME_NETWORK "network-workgroup-symbolic" #define ICON_NAME_NETWORK "network-workgroup-symbolic"
#define ICON_NAME_TRASH "user-trash-symbolic"
#define ICON_NAME_TRASH_FULL "user-trash-full-symbolic"
#define ICON_NAME_FOLDER_DESKTOP "user-desktop" #define ICON_NAME_FOLDER_DESKTOP "user-desktop"
#define ICON_NAME_FOLDER_DOCUMENTS "folder-documents-symbolic" #define ICON_NAME_FOLDER_DOCUMENTS "folder-documents-symbolic"
@ -796,16 +797,15 @@ update_places (GtkPlacesSidebar *sidebar)
/* XDG directories */ /* XDG directories */
add_special_dirs (sidebar); add_special_dirs (sidebar);
if (sidebar->show_trash) { /* Trash */
mount_uri = "trash:///"; /* No need to strdup */ mount_uri = "trash:///"; /* No need to strdup */
icon = g_themed_icon_new (sidebar->trash_is_full ? ICON_NAME_TRASH_FULL : ICON_NAME_TRASH); icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
add_place (sidebar, PLACES_BUILT_IN, add_place (sidebar, PLACES_BUILT_IN,
SECTION_COMPUTER, SECTION_COMPUTER,
_("Trash"), icon, mount_uri, _("Trash"), icon, mount_uri,
NULL, NULL, NULL, 0, NULL, NULL, NULL, 0,
_("Open the trash")); _("Open the trash"));
g_object_unref (icon); g_object_unref (icon);
}
/* Application-side shortcuts */ /* Application-side shortcuts */
add_application_shortcuts (sidebar); add_application_shortcuts (sidebar);
@ -3302,6 +3302,13 @@ tree_view_set_activate_on_single_click (GtkTreeView *tree_view)
NULL); NULL);
} }
static void
trash_monitor_trash_state_changed_cb (GtkTrashMonitor *monitor,
GtkPlacesSidebar *sidebar)
{
update_places (sidebar);
}
static void static void
gtk_places_sidebar_init (GtkPlacesSidebar *sidebar) gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
@ -3318,6 +3325,10 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
sidebar->bookmarks_manager = _gtk_bookmarks_manager_new (bookmarks_changed_cb, sidebar); sidebar->bookmarks_manager = _gtk_bookmarks_manager_new (bookmarks_changed_cb, sidebar);
sidebar->trash_monitor = _gtk_trash_monitor_get ();
sidebar->trash_monitor_changed_id = g_signal_connect (sidebar->trash_monitor, "trash-state-changed",
G_CALLBACK (trash_monitor_trash_state_changed_cb), sidebar);
sidebar->shortcuts = NULL; sidebar->shortcuts = NULL;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar), gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar),
@ -3524,6 +3535,12 @@ gtk_places_sidebar_dispose (GObject *object)
sidebar->popup_menu = NULL; sidebar->popup_menu = NULL;
} }
if (sidebar->trash_monitor) {
g_signal_handler_disconnect (sidebar->trash_monitor, sidebar->trash_monitor_changed_id);
sidebar->trash_monitor_changed_id = 0;
g_clear_object (&sidebar->trash_monitor);
}
g_clear_object (&sidebar->store); g_clear_object (&sidebar->store);
g_slist_free_full (sidebar->shortcuts, g_object_unref); g_slist_free_full (sidebar->shortcuts, g_object_unref);
@ -3856,24 +3873,6 @@ gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar, gboolean show_de
update_places (sidebar); update_places (sidebar);
} }
void
gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, gboolean show_trash)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
sidebar->show_trash = !!show_trash;
update_places (sidebar);
}
void
gtk_places_sidebar_set_trash_is_full (GtkPlacesSidebar *sidebar, gboolean is_full)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
sidebar->trash_is_full = !!is_full;
update_places (sidebar);
}
void void
gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops) gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops)
{ {

View File

@ -61,9 +61,6 @@ GFile *gtk_places_sidebar_get_selected_location (GtkPlacesSidebar *sidebar);
void gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar, gboolean show_desktop); void gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar, gboolean show_desktop);
void gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, gboolean show_trash);
void gtk_places_sidebar_set_trash_is_full (GtkPlacesSidebar *sidebar, gboolean is_full);
void gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops); void gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops);
void gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar, GFile *location); void gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar, GFile *location);