placesview: show Disconnect instead of Eject

Since we're dealing with networks, terms like "Eject" or
the eject button are misleading, since we're not actually
ejecting but disconnecting.

Fix that by showing the appropriate icon and tooltip.
This commit is contained in:
Georges Basile Stavracas Neto 2015-08-10 15:35:56 -03:00
parent 0dff248516
commit e548c71394
4 changed files with 55 additions and 3 deletions

View File

@ -701,6 +701,7 @@ add_volume (GtkPlacesView *view,
"volume", volume,
"mount", mount,
"file", NULL,
"is-network", is_network,
NULL);
insert_row (view, row, is_network);
@ -748,6 +749,7 @@ add_mount (GtkPlacesView *view,
"volume", NULL,
"mount", mount,
"file", NULL,
"is-network", is_network,
NULL);
insert_row (view, row, is_network);
@ -1314,10 +1316,12 @@ build_popup_menu (GtkPlacesView *view,
GtkWidget *item;
GMount *mount;
GFile *file;
gboolean is_network;
priv = gtk_places_view_get_instance_private (view);
mount = gtk_places_view_row_get_mount (row);
file = gtk_places_view_row_get_file (row);
is_network = gtk_places_view_row_get_is_network (row);
priv->popup_menu = gtk_menu_new ();
gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu),
@ -1373,7 +1377,7 @@ build_popup_menu (GtkPlacesView *view,
/* Mount/Unmount items */
if (mount)
{
item = gtk_menu_item_new_with_mnemonic (_("_Unmount"));
item = gtk_menu_item_new_with_mnemonic (is_network ? P_("_Disconnect") : P_("_Unmount"));
g_signal_connect (item,
"activate",
G_CALLBACK (unmount_cb),
@ -1383,7 +1387,7 @@ build_popup_menu (GtkPlacesView *view,
}
else
{
item = gtk_menu_item_new_with_mnemonic (_("_Mount"));
item = gtk_menu_item_new_with_mnemonic (is_network ? P_("_Connect") : P_("_Mount"));
g_signal_connect (item,
"activate",
G_CALLBACK (mount_cb),

View File

@ -31,6 +31,7 @@ struct _GtkPlacesViewRow
GtkSpinner *busy_spinner;
GtkButton *eject_button;
GtkImage *eject_icon;
GtkEventBox *event_box;
GtkImage *icon_image;
GtkLabel *name_label;
@ -39,6 +40,8 @@ struct _GtkPlacesViewRow
GVolume *volume;
GMount *mount;
GFile *file;
gint is_network : 1;
};
G_DEFINE_TYPE (GtkPlacesViewRow, gtk_places_view_row, GTK_TYPE_LIST_BOX_ROW)
@ -51,6 +54,7 @@ enum {
PROP_VOLUME,
PROP_MOUNT,
PROP_FILE,
PROP_IS_NETWORK,
LAST_PROP
};
@ -107,6 +111,10 @@ gtk_places_view_row_get_property (GObject *object,
g_value_set_object (value, self->file);
break;
case PROP_IS_NETWORK:
g_value_set_boolean (value, self->is_network);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -149,6 +157,10 @@ gtk_places_view_row_set_property (GObject *object,
g_set_object (&self->file, g_value_get_object (value));
break;
case PROP_IS_NETWORK:
gtk_places_view_row_set_is_network (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -206,12 +218,20 @@ gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
G_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_IS_NETWORK] =
g_param_spec_boolean ("is-network",
P_("Whether the row represents a network location"),
P_("Whether the row represents a network location"),
FALSE,
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");
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, busy_spinner);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, eject_button);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, eject_icon);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, event_box);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, icon_image);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, name_label);
@ -282,3 +302,26 @@ gtk_places_view_row_set_busy (GtkPlacesViewRow *row,
gtk_widget_set_visible (GTK_WIDGET (row->busy_spinner), is_busy);
}
gboolean
gtk_places_view_row_get_is_network (GtkPlacesViewRow *row)
{
g_return_val_if_fail (GTK_IS_PLACES_VIEW_ROW (row), FALSE);
return row->is_network;
}
void
gtk_places_view_row_set_is_network (GtkPlacesViewRow *row,
gboolean is_network)
{
if (row->is_network != is_network)
{
row->is_network = is_network;
gtk_image_set_from_icon_name (row->eject_icon,
is_network ? "network-offline-symbolic" : "media-eject-symbolic",
GTK_ICON_SIZE_BUTTON);
gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? P_("Disconnect") : P_("Unmount"));
}
}

View File

@ -48,6 +48,11 @@ GFile* gtk_places_view_row_get_file (GtkPlacesViewR
void gtk_places_view_row_set_busy (GtkPlacesViewRow *row,
gboolean is_busy);
gboolean gtk_places_view_row_get_is_network (GtkPlacesViewRow *row);
void gtk_places_view_row_set_is_network (GtkPlacesViewRow *row,
gboolean is_network);
G_END_DECLS
#endif /* GTK_PLACES_VIEW_ROW_H */

View File

@ -72,7 +72,7 @@
<property name="valign">center</property>
<property name="tooltip-text" translatable="yes">Unmount</property>
<child>
<object class="GtkImage">
<object class="GtkImage" id="eject_icon">
<property name="visible">True</property>
<property name="icon_name">media-eject-symbolic</property>
<property name="icon_size">1</property>