GtkPlacesSidebar: Add local-only

This is necessary to implement the filechooser property
of the same name.

https://bugzilla.gnome.org/show_bug.cgi?id=711574
This commit is contained in:
Matthias Clasen 2013-11-09 18:28:12 -05:00
parent bce6185494
commit 9e5a8b7ae1
2 changed files with 154 additions and 62 deletions

View File

@ -163,6 +163,7 @@ struct _GtkPlacesSidebar {
guint drop_occured : 1;
guint show_desktop : 1;
guint show_connect_to_server : 1;
guint local_only : 1;
};
struct _GtkPlacesSidebarClass {
@ -242,6 +243,7 @@ enum {
PROP_OPEN_FLAGS,
PROP_SHOW_DESKTOP,
PROP_SHOW_CONNECT_TO_SERVER,
PROP_LOCAL_ONLY,
NUM_PROPERTIES
};
@ -650,6 +652,25 @@ get_desktop_directory_uri (void)
return g_strconcat ("file://", name, NULL);
}
static gboolean
should_show_file (GtkPlacesSidebar *sidebar,
GFile *file)
{
gchar *path;
if (!sidebar->local_only)
return TRUE;
path = g_file_get_path (file);
if (path)
{
g_free (path);
return TRUE;
}
return FALSE;
}
static void
add_application_shortcuts (GtkPlacesSidebar *sidebar)
{
@ -662,6 +683,9 @@ add_application_shortcuts (GtkPlacesSidebar *sidebar)
file = G_FILE (l->data);
if (!should_show_file (sidebar, file))
continue;
/* FIXME: we are getting file info synchronously. We may want to do it async at some point. */
info = g_file_query_info (file,
"standard::display-name,standard::symbolic-icon",
@ -788,6 +812,8 @@ update_places (GtkPlacesSidebar *sidebar)
add_special_dirs (sidebar);
/* Trash */
if (!sidebar->local_only)
{
mount_uri = "trash:///"; /* No need to strdup */
icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
add_place (sidebar, PLACES_BUILT_IN,
@ -796,6 +822,7 @@ update_places (GtkPlacesSidebar *sidebar)
NULL, NULL, NULL, 0,
_("Open the trash"));
g_object_unref (icon);
}
/* Application-side shortcuts */
add_application_shortcuts (sidebar);
@ -1067,6 +1094,8 @@ update_places (GtkPlacesSidebar *sidebar)
g_slist_free (bookmarks);
/* network */
if (!sidebar->local_only)
{
add_heading (sidebar, SECTION_NETWORK, _("Network"));
mount_uri = "network:///";
@ -1116,8 +1145,6 @@ update_places (GtkPlacesSidebar *sidebar)
}
}
g_list_free_full (network_volumes, g_object_unref);
network_mounts = g_list_reverse (network_mounts);
for (l = network_mounts; l != NULL; l = l->next)
{
@ -1137,7 +1164,9 @@ update_places (GtkPlacesSidebar *sidebar)
g_free (mount_uri);
g_free (tooltip);
}
}
g_list_free_full (network_volumes, g_object_unref);
g_list_free_full (network_mounts, g_object_unref);
/* restore original selection */
@ -3824,6 +3853,10 @@ gtk_places_sidebar_set_property (GObject *obj,
gtk_places_sidebar_set_show_connect_to_server (sidebar, g_value_get_boolean (value));
break;
case PROP_LOCAL_ONLY:
gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@ -3856,6 +3889,10 @@ gtk_places_sidebar_get_property (GObject *obj,
g_value_set_boolean (value, gtk_places_sidebar_get_show_connect_to_server (sidebar));
break;
case PROP_LOCAL_ONLY:
g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@ -4155,6 +4192,12 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
P_("Whether the sidebar includes a builtin shortcut to a 'Connect to server' dialog"),
FALSE,
G_PARAM_READWRITE);
properties[PROP_LOCAL_ONLY] =
g_param_spec_boolean ("local-only",
P_("Local Only"),
P_("Whether the sidebar only includes local files"),
FALSE,
G_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -4503,6 +4546,48 @@ gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSidebar *sidebar)
return sidebar->show_connect_to_server;
}
/**
* gtk_places_sidebar_set_local_only:
* @sidebar: a places sidebar
* @local_only: whether to show only local files
*
* Sets whether the @sidebar should only show local files.
*
* Since: 3.12
*/
void
gtk_places_sidebar_set_local_only (GtkPlacesSidebar *sidebar,
gboolean local_only)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
local_only = !!local_only;
if (sidebar->local_only != local_only)
{
sidebar->local_only = local_only;
update_places (sidebar);
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_LOCAL_ONLY]);
}
}
/**
* gtk_places_sidebar_get_local_only:
* @sidebar: a places sidebar
*
* Returns the value previously set with gtk_places_sidebar_set_local_only().
*
* Return value: %TRUE if the sidebar will only show local files.
*
* Since: 3.12
*/
gboolean
gtk_places_sidebar_get_local_only (GtkPlacesSidebar *sidebar)
{
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
return sidebar->local_only;
}
static GSList *
find_shortcut_link (GtkPlacesSidebar *sidebar,
GFile *location)

View File

@ -106,6 +106,13 @@ GDK_AVAILABLE_IN_3_10
void gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar *sidebar,
gboolean show_connect_to_server);
GDK_AVAILABLE_IN_3_12
void gtk_places_sidebar_set_local_only (GtkPlacesSidebar *sidebar,
gboolean local_only);
GDK_AVAILABLE_IN_3_12
gboolean gtk_places_sidebar_get_local_only (GtkPlacesSidebar *sidebar);
GDK_AVAILABLE_IN_3_10
void gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar,
GFile *location);