Commit c4141a21 authored by Allison Karlitskaya's avatar Allison Karlitskaya

GtkPlacesSidebar: use shell-shows-desktop setting

Use the just-added shell-shows-desktop GtkSetting to determine if we
should also show the "Desktop" folder in the places sidebar.

https://bugzilla.gnome.org/show_bug.cgi?id=712302
parent a90bb7de
......@@ -130,6 +130,7 @@ struct _GtkPlacesSidebar {
GtkBookmarksManager *bookmarks_manager;
GVolumeMonitor *volume_monitor;
GtkTrashMonitor *trash_monitor;
GtkSettings *gtk_settings;
gulong trash_monitor_changed_id;
......@@ -161,6 +162,7 @@ struct _GtkPlacesSidebar {
guint mounting : 1;
guint drag_data_received : 1;
guint drop_occured : 1;
guint show_desktop_set : 1;
guint show_desktop : 1;
guint show_connect_to_server : 1;
guint local_only : 1;
......@@ -3662,6 +3664,30 @@ create_volume_monitor (GtkPlacesSidebar *sidebar)
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
}
static void
shell_shows_desktop_changed (GtkSettings *settings,
GParamSpec *pspec,
gpointer user_data)
{
GtkPlacesSidebar *sidebar = user_data;
gboolean b;
g_assert (settings == sidebar->gtk_settings);
/* Check if the user explicitly set this and, if so, don't change it. */
if (sidebar->show_desktop_set)
return;
g_object_get (settings, "gtk-shell-shows-desktop", &b, NULL);
if (b != sidebar->show_desktop)
{
sidebar->show_desktop = b;
update_places (sidebar);
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_DESKTOP]);
}
}
static void
gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
{
......@@ -3671,6 +3697,7 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
GtkTreeSelection *selection;
GIcon *eject;
GtkTargetList *target_list;
gboolean b;
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (sidebar)), GTK_STYLE_CLASS_SIDEBAR);
......@@ -3876,6 +3903,13 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
sidebar->drop_state = DROP_STATE_NORMAL;
sidebar->new_bookmark_index = -1;
/* Don't bother trying to trace this across hierarchy changes... */
sidebar->gtk_settings = gtk_settings_get_default ();
g_signal_connect (sidebar->gtk_settings, "notify::gtk-shell-shows-desktop",
G_CALLBACK (shell_shows_desktop_changed), sidebar);
g_object_get (sidebar->gtk_settings, "gtk-shell-shows-desktop", &b, NULL);
sidebar->show_desktop = b;
/* populate the sidebar */
update_places (sidebar);
}
......@@ -4010,6 +4044,12 @@ gtk_places_sidebar_dispose (GObject *object)
g_free (sidebar->hostname);
sidebar->hostname = NULL;
if (sidebar->gtk_settings)
{
g_signal_handlers_disconnect_by_func (sidebar->gtk_settings, shell_shows_desktop_changed, sidebar);
g_clear_object (&sidebar->gtk_settings);
}
G_OBJECT_CLASS (gtk_places_sidebar_parent_class)->dispose (object);
}
......@@ -4516,9 +4556,10 @@ gtk_places_sidebar_get_location (GtkPlacesSidebar *sidebar)
* @sidebar: a places sidebar
* @show_desktop: whether to show an item for the Desktop folder
*
* Sets whether the @sidebar should show an item for the Desktop folder; this is off by default.
* An application may want to turn this on if the desktop environment actually supports the
* notion of a desktop.
* Sets whether the @sidebar should show an item for the Desktop folder.
* The default value for this option is determined by the desktop
* environment and the user's configuration, but this function can be
* used to override it on a per-application basis.
*
* Since: 3.10
*/
......@@ -4528,6 +4569,12 @@ gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar,
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
/* Don't bother disconnecting from the GtkSettings -- it will just
* complicate things. Besides, it's highly unlikely that this will
* change while we're running, but we can ignore it if it does.
*/
sidebar->show_desktop_set = TRUE;
show_desktop = !!show_desktop;
if (sidebar->show_desktop != show_desktop)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment