placesview: show Computer item

GtkPlacesView widget manages persistent locations,
factoring out GtkPlacesSidebar functionality.

It, however, does not completely shows all sidebar
locations, since Computer is still missing.

Add a Computer item, adjusting some internal behavior
to make that possible.
This commit is contained in:
Georges Basile Stavracas Neto 2015-07-27 16:52:37 -03:00
parent 5134e4b3bd
commit a5e762e6a7
4 changed files with 64 additions and 2 deletions

View File

@ -342,16 +342,22 @@ activate_row (GtkPlacesView *view,
GtkPlacesViewPrivate *priv;
GVolume *volume;
GMount *mount;
GFile *file;
priv = gtk_places_view_get_instance_private (view);
mount = gtk_places_view_row_get_mount (row);
volume = gtk_places_view_row_get_volume (row);
file = gtk_places_view_row_get_file (row);
if (mount)
if (file)
{
emit_open_location (view, file, flags);
}
else if (mount)
{
GFile *location = g_mount_get_root (mount);
emit_open_location (view, location, GTK_PLACES_OPEN_NORMAL);
emit_open_location (view, location, flags);
g_object_unref (location);
}
@ -771,6 +777,7 @@ add_volume (GtkPlacesView *view,
"path", path ? path : "",
"volume", volume,
"mount", mount,
"file", NULL,
NULL);
insert_row (view, row, is_network);
@ -814,6 +821,7 @@ add_mount (GtkPlacesView *view,
"path", path ? path : "",
"volume", NULL,
"mount", mount,
"file", NULL,
NULL);
insert_row (view, row, is_network);
@ -846,6 +854,28 @@ add_drive (GtkPlacesView *view,
g_list_free_full (volumes, g_object_unref);
}
static void
add_computer (GtkPlacesView *view)
{
GtkWidget *row;
GIcon *icon;
GFile *file;
file = g_file_new_for_path ("/");
icon = g_themed_icon_new_with_default_fallbacks ("drive-harddisk");
row = g_object_new (GTK_TYPE_PLACES_VIEW_ROW,
"icon", icon,
"name", _("Computer"),
"path", "/",
"volume", NULL,
"mount", NULL,
"file", file,
NULL);
insert_row (view, row, FALSE);
}
static void
update_places (GtkPlacesView *view)
{
@ -872,6 +902,9 @@ update_places (GtkPlacesView *view)
gtk_widget_hide (priv->drives_box);
gtk_widget_hide (priv->network_grid);
/* Add "Computer" row */
add_computer (view);
/* Add currently connected drives */
drives = g_volume_monitor_get_connected_drives (priv->volume_monitor);

View File

@ -38,6 +38,7 @@ struct _GtkPlacesViewRow
GVolume *volume;
GMount *mount;
GFile *file;
};
G_DEFINE_TYPE (GtkPlacesViewRow, gtk_places_view_row, GTK_TYPE_LIST_BOX_ROW)
@ -49,6 +50,7 @@ enum {
PROP_PATH,
PROP_VOLUME,
PROP_MOUNT,
PROP_FILE,
LAST_PROP
};
@ -89,6 +91,10 @@ gtk_places_view_row_get_property (GObject *object,
g_value_set_object (value, self->mount);
break;
case PROP_FILE:
g_value_set_object (value, self->file);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -127,6 +133,10 @@ gtk_places_view_row_set_property (GObject *object,
gtk_widget_set_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
break;
case PROP_FILE:
self->file = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -176,6 +186,13 @@ gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
G_TYPE_MOUNT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_FILE] =
g_param_spec_object ("file",
P_("File represented by the row"),
P_("The file represented by the row, if any"),
G_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, LAST_PROP, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkplacesviewrow.ui");
@ -220,6 +237,14 @@ gtk_places_view_row_get_volume (GtkPlacesViewRow *row)
return row->volume;
}
GFile*
gtk_places_view_row_get_file (GtkPlacesViewRow *row)
{
g_return_val_if_fail (GTK_IS_PLACES_VIEW_ROW (row), NULL);
return row->file;
}
GtkWidget*
gtk_places_view_row_get_eject_button (GtkPlacesViewRow *row)
{

View File

@ -43,6 +43,8 @@ GMount* gtk_places_view_row_get_mount (GtkPlacesViewR
GVolume* gtk_places_view_row_get_volume (GtkPlacesViewRow *row);
GFile* gtk_places_view_row_get_file (GtkPlacesViewRow *row);
void gtk_places_view_row_set_busy (GtkPlacesViewRow *row,
gboolean is_busy);

View File

@ -53,6 +53,8 @@
<property name="justify">right</property>
<property name="ellipsize">middle</property>
<property name="xalign">1</property>
<property name="width_chars">15</property>
<property name="max_width_chars">15</property>
<style>
<class name="dim-label"/>
</style>