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:
@ -163,6 +163,7 @@ struct _GtkPlacesSidebar {
|
|||||||
guint drop_occured : 1;
|
guint drop_occured : 1;
|
||||||
guint show_desktop : 1;
|
guint show_desktop : 1;
|
||||||
guint show_connect_to_server : 1;
|
guint show_connect_to_server : 1;
|
||||||
|
guint local_only : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkPlacesSidebarClass {
|
struct _GtkPlacesSidebarClass {
|
||||||
@ -242,6 +243,7 @@ enum {
|
|||||||
PROP_OPEN_FLAGS,
|
PROP_OPEN_FLAGS,
|
||||||
PROP_SHOW_DESKTOP,
|
PROP_SHOW_DESKTOP,
|
||||||
PROP_SHOW_CONNECT_TO_SERVER,
|
PROP_SHOW_CONNECT_TO_SERVER,
|
||||||
|
PROP_LOCAL_ONLY,
|
||||||
NUM_PROPERTIES
|
NUM_PROPERTIES
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -650,6 +652,25 @@ get_desktop_directory_uri (void)
|
|||||||
return g_strconcat ("file://", name, NULL);
|
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
|
static void
|
||||||
add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
||||||
{
|
{
|
||||||
@ -662,6 +683,9 @@ add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
|||||||
|
|
||||||
file = G_FILE (l->data);
|
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. */
|
/* FIXME: we are getting file info synchronously. We may want to do it async at some point. */
|
||||||
info = g_file_query_info (file,
|
info = g_file_query_info (file,
|
||||||
"standard::display-name,standard::symbolic-icon",
|
"standard::display-name,standard::symbolic-icon",
|
||||||
@ -788,14 +812,17 @@ update_places (GtkPlacesSidebar *sidebar)
|
|||||||
add_special_dirs (sidebar);
|
add_special_dirs (sidebar);
|
||||||
|
|
||||||
/* Trash */
|
/* Trash */
|
||||||
mount_uri = "trash:///"; /* No need to strdup */
|
if (!sidebar->local_only)
|
||||||
icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
|
{
|
||||||
add_place (sidebar, PLACES_BUILT_IN,
|
mount_uri = "trash:///"; /* No need to strdup */
|
||||||
SECTION_COMPUTER,
|
icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
|
||||||
_("Trash"), icon, mount_uri,
|
add_place (sidebar, PLACES_BUILT_IN,
|
||||||
NULL, NULL, NULL, 0,
|
SECTION_COMPUTER,
|
||||||
_("Open the trash"));
|
_("Trash"), icon, mount_uri,
|
||||||
g_object_unref (icon);
|
NULL, NULL, NULL, 0,
|
||||||
|
_("Open the trash"));
|
||||||
|
g_object_unref (icon);
|
||||||
|
}
|
||||||
|
|
||||||
/* Application-side shortcuts */
|
/* Application-side shortcuts */
|
||||||
add_application_shortcuts (sidebar);
|
add_application_shortcuts (sidebar);
|
||||||
@ -1067,77 +1094,79 @@ update_places (GtkPlacesSidebar *sidebar)
|
|||||||
g_slist_free (bookmarks);
|
g_slist_free (bookmarks);
|
||||||
|
|
||||||
/* network */
|
/* network */
|
||||||
add_heading (sidebar, SECTION_NETWORK, _("Network"));
|
if (!sidebar->local_only)
|
||||||
|
|
||||||
mount_uri = "network:///";
|
|
||||||
icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK);
|
|
||||||
add_place (sidebar, PLACES_BUILT_IN,
|
|
||||||
SECTION_NETWORK,
|
|
||||||
_("Browse Network"), icon, mount_uri,
|
|
||||||
NULL, NULL, NULL, 0,
|
|
||||||
_("Browse the contents of the network"));
|
|
||||||
g_object_unref (icon);
|
|
||||||
|
|
||||||
if (sidebar->show_connect_to_server)
|
|
||||||
{
|
{
|
||||||
icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
|
add_heading (sidebar, SECTION_NETWORK, _("Network"));
|
||||||
add_place (sidebar, PLACES_CONNECT_TO_SERVER,
|
|
||||||
|
mount_uri = "network:///";
|
||||||
|
icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK);
|
||||||
|
add_place (sidebar, PLACES_BUILT_IN,
|
||||||
SECTION_NETWORK,
|
SECTION_NETWORK,
|
||||||
_("Connect to Server"), icon, NULL,
|
_("Browse Network"), icon, mount_uri,
|
||||||
NULL, NULL, NULL, 0,
|
NULL, NULL, NULL, 0,
|
||||||
_("Connect to a network server address"));
|
_("Browse the contents of the network"));
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
}
|
|
||||||
|
|
||||||
network_volumes = g_list_reverse (network_volumes);
|
if (sidebar->show_connect_to_server)
|
||||||
for (l = network_volumes; l != NULL; l = l->next)
|
|
||||||
{
|
|
||||||
volume = l->data;
|
|
||||||
mount = g_volume_get_mount (volume);
|
|
||||||
|
|
||||||
if (mount != NULL)
|
|
||||||
{
|
{
|
||||||
network_mounts = g_list_prepend (network_mounts, mount);
|
icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
|
||||||
continue;
|
add_place (sidebar, PLACES_CONNECT_TO_SERVER,
|
||||||
|
SECTION_NETWORK,
|
||||||
|
_("Connect to Server"), icon, NULL,
|
||||||
|
NULL, NULL, NULL, 0,
|
||||||
|
_("Connect to a network server address"));
|
||||||
|
g_object_unref (icon);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
icon = g_volume_get_symbolic_icon (volume);
|
|
||||||
name = g_volume_get_name (volume);
|
|
||||||
tooltip = g_strdup_printf (_("Mount and open %s"), name);
|
|
||||||
|
|
||||||
|
network_volumes = g_list_reverse (network_volumes);
|
||||||
|
for (l = network_volumes; l != NULL; l = l->next)
|
||||||
|
{
|
||||||
|
volume = l->data;
|
||||||
|
mount = g_volume_get_mount (volume);
|
||||||
|
|
||||||
|
if (mount != NULL)
|
||||||
|
{
|
||||||
|
network_mounts = g_list_prepend (network_mounts, mount);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
icon = g_volume_get_symbolic_icon (volume);
|
||||||
|
name = g_volume_get_name (volume);
|
||||||
|
tooltip = g_strdup_printf (_("Mount and open %s"), name);
|
||||||
|
|
||||||
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
||||||
|
SECTION_NETWORK,
|
||||||
|
name, icon, NULL,
|
||||||
|
NULL, volume, NULL, 0, tooltip);
|
||||||
|
g_object_unref (icon);
|
||||||
|
g_free (name);
|
||||||
|
g_free (tooltip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_mounts = g_list_reverse (network_mounts);
|
||||||
|
for (l = network_mounts; l != NULL; l = l->next)
|
||||||
|
{
|
||||||
|
mount = l->data;
|
||||||
|
root = g_mount_get_default_location (mount);
|
||||||
|
icon = g_mount_get_symbolic_icon (mount);
|
||||||
|
mount_uri = g_file_get_uri (root);
|
||||||
|
name = g_mount_get_name (mount);
|
||||||
|
tooltip = g_file_get_parse_name (root);
|
||||||
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
||||||
SECTION_NETWORK,
|
SECTION_NETWORK,
|
||||||
name, icon, NULL,
|
name, icon, mount_uri,
|
||||||
NULL, volume, NULL, 0, tooltip);
|
NULL, NULL, mount, 0, tooltip);
|
||||||
|
g_object_unref (root);
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
g_free (mount_uri);
|
||||||
g_free (tooltip);
|
g_free (tooltip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free_full (network_volumes, g_object_unref);
|
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)
|
|
||||||
{
|
|
||||||
mount = l->data;
|
|
||||||
root = g_mount_get_default_location (mount);
|
|
||||||
icon = g_mount_get_symbolic_icon (mount);
|
|
||||||
mount_uri = g_file_get_uri (root);
|
|
||||||
name = g_mount_get_name (mount);
|
|
||||||
tooltip = g_file_get_parse_name (root);
|
|
||||||
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
|
||||||
SECTION_NETWORK,
|
|
||||||
name, icon, mount_uri,
|
|
||||||
NULL, NULL, mount, 0, tooltip);
|
|
||||||
g_object_unref (root);
|
|
||||||
g_object_unref (icon);
|
|
||||||
g_free (name);
|
|
||||||
g_free (mount_uri);
|
|
||||||
g_free (tooltip);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free_full (network_mounts, g_object_unref);
|
g_list_free_full (network_mounts, g_object_unref);
|
||||||
|
|
||||||
/* restore original selection */
|
/* 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));
|
gtk_places_sidebar_set_show_connect_to_server (sidebar, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_LOCAL_ONLY:
|
||||||
|
gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||||
break;
|
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));
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_connect_to_server (sidebar));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_LOCAL_ONLY:
|
||||||
|
g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||||
break;
|
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"),
|
P_("Whether the sidebar includes a builtin shortcut to a 'Connect to server' dialog"),
|
||||||
FALSE,
|
FALSE,
|
||||||
G_PARAM_READWRITE);
|
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);
|
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;
|
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 *
|
static GSList *
|
||||||
find_shortcut_link (GtkPlacesSidebar *sidebar,
|
find_shortcut_link (GtkPlacesSidebar *sidebar,
|
||||||
GFile *location)
|
GFile *location)
|
||||||
|
|||||||
@ -106,6 +106,13 @@ GDK_AVAILABLE_IN_3_10
|
|||||||
void gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar *sidebar,
|
void gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar *sidebar,
|
||||||
gboolean show_connect_to_server);
|
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
|
GDK_AVAILABLE_IN_3_10
|
||||||
void gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar,
|
void gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar,
|
||||||
GFile *location);
|
GFile *location);
|
||||||
|
|||||||
Reference in New Issue
Block a user