[virt-tools-list] [remote-viewer PATCH 5/7 v3] remote-viewer-connect: Changed hardcoded UI into XML

Lukas Venhoda lvenhoda at redhat.com
Mon Jun 15 10:47:32 UTC 2015


Hardcoded UI removed in favor of XML.
Added the new XML file for translation.
---
Changes since v2
 - Removed the error state response
    - It's not really needed, it's OK to just return FALSE and quit remote-viewer

Changes since v1
 - New patch
 - Contains change to XML only
---
 po/POTFILES.in                |   1 +
 src/Makefile.am               |   1 +
 src/remote-viewer-connect.c   |  88 +++++-------------------
 src/remote-viewer-connect.xml | 152 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 171 insertions(+), 71 deletions(-)
 create mode 100644 src/remote-viewer-connect.xml

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 111e8b5..9dcc6a3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@ data/virt-viewer-mime.xml.in
 src/gbinding.c
 src/remote-viewer-main.c
 src/remote-viewer.c
+[type: gettext/glade] src/remote-viewer-connect.xml
 [type: gettext/glade] src/virt-viewer-about.xml
 src/virt-viewer-app.c
 src/virt-viewer-auth.c
diff --git a/src/Makefile.am b/src/Makefile.am
index e012234..12d646c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,7 @@ builderxml_DATA =				\
 	virt-viewer-guest-details.xml	\
 	virt-viewer-vm-connection.xml	\
 	virt-viewer-preferences.xml		\
+	remote-viewer-connect.xml		\
 	$(NULL)

 EXTRA_DIST =					\
diff --git a/src/remote-viewer-connect.c b/src/remote-viewer-connect.c
index 601c314..3870c39 100644
--- a/src/remote-viewer-connect.c
+++ b/src/remote-viewer-connect.c
@@ -19,6 +19,7 @@
  */

 #include "remote-viewer-connect.h"
+#include "virt-viewer-util.h"
 #include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>

@@ -132,30 +133,14 @@ recent_item_activated_dialog_cb(GtkRecentChooser *chooser G_GNUC_UNUSED, gpointe
 }

 static void
-make_label_light(GtkLabel* label)
+make_label_small(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);
-}
-
 /**
 * remote_viewer_connect_dialog
 *
@@ -170,11 +155,9 @@ make_label_bold(GtkLabel* label)
 gboolean
 remote_viewer_connect_dialog(gchar **uri)
 {
-    GtkWidget *window, *box, *label, *entry, *recent, *connect_button, *cancel_button, *button_box;
-#if !GTK_CHECK_VERSION(3, 0, 0)
-    GtkWidget *alignment;
-#endif
+    GtkWidget *window, *label, *entry, *recent, *connect_button, *cancel_button;
     GtkRecentFilter *rfilter;
+    GtkBuilder *builder;

     ConnectionInfo ci = {
         FALSE,
@@ -184,47 +167,18 @@ remote_viewer_connect_dialog(gchar **uri)
     g_return_val_if_fail(uri && *uri == NULL, FALSE);

     /* Create the widgets */
-    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-    gtk_container_set_border_width(GTK_CONTAINER(window), 5);
-    box = gtk_vbox_new(FALSE, 6);
-    gtk_container_set_border_width(GTK_CONTAINER(box), 5);
-    gtk_container_add(GTK_CONTAINER(window), box);
-
-    label = gtk_label_new_with_mnemonic(_("_Connection Address"));
-    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-    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);
-    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_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(box), recent, TRUE, TRUE, 0);
-    gtk_label_set_mnemonic_widget(GTK_LABEL(label), recent);
+    builder = virt_viewer_util_load_ui("remote-viewer-connect.xml");
+    g_return_val_if_fail(builder != NULL, GTK_RESPONSE_NONE);
+
+    window = GTK_WIDGET(gtk_builder_get_object(builder, "remote-viewer-connection-window"));
+    connect_button = GTK_WIDGET(gtk_builder_get_object(builder, "connect-button"));
+    cancel_button = GTK_WIDGET(gtk_builder_get_object(builder, "cancel-button"));
+    label = GTK_WIDGET(gtk_builder_get_object(builder, "example-label"));
+    entry = GTK_WIDGET(gtk_builder_get_object(builder, "connection-address-entry"));
+
+    make_label_small(GTK_LABEL(label));
+
+    recent = GTK_WIDGET(gtk_builder_get_object(builder, "recent-chooser"));

     rfilter = gtk_recent_filter_new();
     gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
@@ -233,15 +187,6 @@ remote_viewer_connect_dialog(gchar **uri)
     gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recent), rfilter);
     gtk_recent_chooser_set_local_only(GTK_RECENT_CHOOSER(recent), FALSE);

-    button_box = gtk_hbutton_box_new();
-    gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_END);
-    connect_button = gtk_button_new_with_label("Connect");
-    cancel_button = gtk_button_new_with_label("Cancel");
-    gtk_box_pack_start(GTK_BOX(button_box), cancel_button, FALSE, TRUE, 0);
-    gtk_box_pack_start(GTK_BOX(button_box), connect_button, FALSE, TRUE, 1);
-
-    gtk_box_pack_start(GTK_BOX(box), button_box, FALSE, TRUE, 0);
-
     g_signal_connect(window, "key-press-event",
                      G_CALLBACK(key_pressed_cb), window);
     g_signal_connect(connect_button, "clicked",
@@ -276,6 +221,7 @@ remote_viewer_connect_dialog(gchar **uri)
         *uri = NULL;
     }

+    g_object_unref(builder);
     gtk_widget_destroy(window);

     return ci.response;
diff --git a/src/remote-viewer-connect.xml b/src/remote-viewer-connect.xml
new file mode 100644
index 0000000..dcd14cf
--- /dev/null
+++ b/src/remote-viewer-connect.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+  <object class="GtkWindow" id="remote-viewer-connection-window">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Connection details</property>
+    <child>
+      <object class="GtkVBox" id="main-box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">10</property>
+        <property name="spacing">20</property>
+        <child>
+          <object class="GtkVBox" id="connection-address-box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="connection-address-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Connection Address</property>
+                <property name="xalign">0</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="connection-address-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="example-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="sensitive">False</property>
+                <property name="label" translatable="yes">For example, spice://foo.example.org:5900</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkVBox" id="recent-chooser-box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="recent-chooser-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Recent connections</property>
+                <property name="xalign">0</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRecentChooserWidget" id="recent-chooser">
+                <property name="can_focus">False</property>
+                <property name="limit">20</property>
+                <property name="local_only">False</property>
+                <property name="show_icons">False</property>
+                <property name="sort_type">mru</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHButtonBox" id="button-box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="resize_mode">immediate</property>
+            <property name="spacing">6</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel-button">
+                <property name="label" translatable="yes">Cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="connect-button">
+                <property name="label" translatable="yes">Connect</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
--
2.4.2




More information about the virt-tools-list mailing list