[virt-tools-list] [PATCH virt-viewer] Improve remote-viewer connection dialog
Jonathon Jongsma
jjongsma at redhat.com
Fri Apr 11 21:43:12 UTC 2014
Based on the new design for the 'connect to server' dialog from Nautilus.
---
src/remote-viewer.c | 87 +++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 75 insertions(+), 12 deletions(-)
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index fe8b5a3..15d576b 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -843,6 +843,24 @@ error:
#endif
+static void entry_icon_release_cb(GtkEntry* entry, gpointer data G_GNUC_UNUSED)
+{
+ gtk_entry_set_text(entry, "");
+ gtk_widget_grab_focus(GTK_WIDGET(entry));
+}
+
+static void entry_changed_cb(GtkEditable* entry, gpointer data G_GNUC_UNUSED)
+{
+ gboolean rtl = (gtk_widget_get_direction(GTK_WIDGET(entry)) == GTK_TEXT_DIR_RTL);
+ gboolean active = gtk_entry_get_text_length(GTK_ENTRY(entry)) > 0;
+
+ g_object_set(entry,
+ "secondary-icon-name", active ? (rtl ? "edit-clear-rtl-symbolic" : "edit-clear-symbolic") : NULL,
+ "secondary-icon-activatable", active,
+ "secondary-icon-sensitive", active,
+ NULL);
+}
+
static void
recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpointer data)
{
@@ -868,12 +886,38 @@ recent_item_activated_dialog_cb(GtkRecentChooser *chooser G_GNUC_UNUSED, gpointe
gtk_dialog_response(GTK_DIALOG (data), GTK_RESPONSE_ACCEPT);
}
+static void make_label_light(GtkLabel* label)
+{
+ PangoAttrList* attributes = pango_attr_list_new();
+#if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(label)), "dim-label");
+#else
+ GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(label));
+ GdkColor* c = &style->text[GTK_STATE_INSENSITIVE];
+ pango_attr_list_insert(attributes, pango_attr_foreground_new(c->red, c->green, c->blue));
+#endif
+ pango_attr_list_insert(attributes, pango_attr_scale_new(0.9));
+ gtk_label_set_attributes(label, attributes);
+ pango_attr_list_unref(attributes);
+}
+
+static void make_label_bold(GtkLabel* label)
+{
+ PangoAttrList* attributes = pango_attr_list_new();
+ pango_attr_list_insert(attributes, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
+ gtk_label_set_attributes(label, attributes);
+ pango_attr_list_unref(attributes);
+
+}
+
static gint
connect_dialog(gchar **uri)
{
- GtkWidget *dialog, *area, *label, *entry, *recent;
+ GtkWidget *dialog, *area, *box, *label, *entry, *recent;
+#if !GTK_CHECK_VERSION(3, 0, 0)
+ GtkWidget *alignment;
+#endif
GtkRecentFilter *rfilter;
- GtkTable *table;
gint retval;
/* Create the widgets */
@@ -886,28 +930,47 @@ connect_dialog(gchar **uri)
GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+ gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- table = GTK_TABLE(gtk_table_new(1, 2, 0));
- gtk_box_pack_start(GTK_BOX(area), GTK_WIDGET(table), TRUE, TRUE, 0);
- gtk_table_set_row_spacings(table, 5);
- gtk_table_set_col_spacings(table, 5);
+ box = gtk_vbox_new(FALSE, 6);
+ gtk_container_set_border_width(GTK_CONTAINER(box), 5);
+ gtk_box_pack_start(GTK_BOX(area), box, TRUE, TRUE, 0);
- label = gtk_label_new(_("URL:"));
+ label = gtk_label_new_with_mnemonic(_("_Connection Address"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- gtk_table_attach_defaults(table, label, 0, 1, 0, 1);
+ gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
entry = GTK_WIDGET(gtk_entry_new());
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
g_object_set(entry, "width-request", 200, NULL);
- gtk_table_attach_defaults(table, entry, 1, 2, 0, 1);
+ g_signal_connect(entry, "changed", G_CALLBACK(entry_changed_cb), entry);
+ g_signal_connect(entry, "icon-release", G_CALLBACK(entry_icon_release_cb), entry);
+ gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
+ make_label_bold(GTK_LABEL(label));
+
+ label = gtk_label_new(_("For example, spice://foo.example.org:5900"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ make_label_light(GTK_LABEL(label));
+#if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
+ gtk_widget_set_margin_bottom(label, 12);
+#else
+ alignment = gtk_alignment_new(0, 0, 1, 1);
+ gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 12, 0, 0);
+ gtk_container_add(GTK_CONTAINER(alignment), label);
+ gtk_box_pack_start(GTK_BOX(box), alignment, TRUE, TRUE, 0);
+#endif
- label = gtk_label_new(_("Recent connections:"));
- gtk_box_pack_start(GTK_BOX(area), label, TRUE, TRUE, 0);
+ label = gtk_label_new_with_mnemonic(_("_Recent Connections"));
+ make_label_bold(GTK_LABEL(label));
+ gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
recent = GTK_WIDGET(gtk_recent_chooser_widget_new());
gtk_recent_chooser_set_show_icons(GTK_RECENT_CHOOSER(recent), FALSE);
gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(recent), GTK_RECENT_SORT_MRU);
- gtk_box_pack_start(GTK_BOX(area), recent, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(box), recent, TRUE, TRUE, 0);
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), recent);
rfilter = gtk_recent_filter_new();
gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
--
1.9.0
More information about the virt-tools-list
mailing list