[virt-tools-list] [PATCH] Allow user to set a window title for remote-viewer

Daniel P. Berrange berrange at redhat.com
Tue Oct 9 16:25:43 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

Currently the remote viewer windows get the URI as their
title. Provide a --title STRING arg to remote-viewer to
let the user override the title with something more
meaningful to them.

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 man/remote-viewer.pod    |  4 ++++
 src/remote-viewer-main.c |  5 ++++-
 src/remote-viewer.c      |  8 +++++---
 src/remote-viewer.h      |  4 +++-
 src/virt-viewer-app.c    | 20 +++++++++++++++++---
 src/virt-viewer-app.h    |  2 ++
 6 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/man/remote-viewer.pod b/man/remote-viewer.pod
index ed61a55..e8337ed 100644
--- a/man/remote-viewer.pod
+++ b/man/remote-viewer.pod
@@ -38,6 +38,10 @@ Zoom level of the display window in percentage. Range 10-200.
 
 Start with the window maximised to fullscreen
 
+=item -t TITLE, --title TITLE
+
+Set the window title to B<TITLE>
+
 =item --spice-controller
 
 Use the SPICE controller to initialize the connection with the SPICE
diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
index 615e758..f92ef13 100644
--- a/src/remote-viewer-main.c
+++ b/src/remote-viewer-main.c
@@ -196,6 +196,7 @@ main(int argc, char **argv)
     int zoom = 100;
     gchar **args = NULL;
     gchar *uri = NULL;
+    char *title = NULL;
     gboolean verbose = FALSE;
     gboolean debug = FALSE;
     gboolean direct = FALSE;
@@ -209,6 +210,8 @@ main(int argc, char **argv)
           remote_viewer_version, N_("Display version information"), NULL },
         { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
           N_("Display verbose information"), NULL },
+        { "title", 't', 0, G_OPTION_ARG_STRING, &title,
+          N_("Set window title"), NULL },
         { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct,
           N_("Direct connection with no automatic tunnels"), NULL },
         { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom,
@@ -304,7 +307,7 @@ main(int argc, char **argv)
         g_object_set(viewer, "guest-name", "defined by Spice controller", NULL);
     } else {
 #endif
-        viewer = remote_viewer_new(uri, verbose);
+        viewer = remote_viewer_new(uri, title, verbose);
         g_object_set(viewer, "guest-name", uri, NULL);
 #if HAVE_SPICE_GTK
     }
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 77c1414..55df838 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -181,11 +181,12 @@ remote_viewer_init(RemoteViewer *self)
 }
 
 RemoteViewer *
-remote_viewer_new(const gchar *uri, gboolean verbose)
+remote_viewer_new(const gchar *uri, const gchar *title, gboolean verbose)
 {
     return g_object_new(REMOTE_VIEWER_TYPE,
                         "guri", uri,
                         "verbose", verbose,
+                        "title", title,
                         NULL);
 }
 
@@ -609,7 +610,7 @@ spice_ctrl_notified(SpiceCtrlController *ctrl,
                                   &value);
         }
     } else if (g_str_equal(pspec->name, "title")) {
-        g_object_set_property(G_OBJECT(app), "title", &value);
+        virt_viewer_app_set_title(app, g_value_get_string(&value));
     } else if (g_str_equal(pspec->name, "display-flags")) {
         guint flags = g_value_get_uint(&value);
         gboolean fullscreen = flags & CONTROLLER_SET_FULL_SCREEN;
@@ -768,7 +769,8 @@ remote_viewer_start(VirtViewerApp *app)
         g_return_val_if_fail(guri != NULL, FALSE);
 
         DEBUG_LOG("Opening display to %s", guri);
-        g_object_set(app, "title", guri, NULL);
+        if (virt_viewer_app_get_title(app) == NULL)
+            virt_viewer_app_set_title(app, guri);
 
         if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0 || type == NULL) {
             virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI"));
diff --git a/src/remote-viewer.h b/src/remote-viewer.h
index a465b7e..de701e0 100644
--- a/src/remote-viewer.h
+++ b/src/remote-viewer.h
@@ -48,7 +48,9 @@ typedef struct {
 
 GType remote_viewer_get_type (void);
 
-RemoteViewer* remote_viewer_new(const gchar *uri, gboolean verbose);
+RemoteViewer* remote_viewer_new(const gchar *uri,
+                                const gchar *title,
+                                gboolean verbose);
 RemoteViewer* remote_viewer_new_with_controller(gboolean verbose);
 
 G_END_DECLS
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index a95687a..2e6c895 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1245,9 +1245,7 @@ virt_viewer_app_set_property (GObject *object, guint property_id,
         break;
 
     case PROP_TITLE:
-        g_free(priv->title);
-        priv->title = g_value_dup_string(value);
-        virt_viewer_app_set_all_window_subtitles(self);
+        virt_viewer_app_set_title(self, g_value_get_string(value));
         break;
 
     case PROP_ENABLE_ACCEL:
@@ -1494,6 +1492,22 @@ virt_viewer_app_class_init (VirtViewerAppClass *klass)
                      G_TYPE_OBJECT);
 }
 
+const char *virt_viewer_app_get_title(VirtViewerApp *self)
+{
+    g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL);
+
+    return self->priv->title;
+}
+
+void virt_viewer_app_set_title(VirtViewerApp *self, const char *title)
+{
+    g_return_if_fail(VIRT_VIEWER_IS_APP(self));
+
+    g_free(self->priv->title);
+    self->priv->title = g_strdup(title);
+    virt_viewer_app_set_all_window_subtitles(self);
+}
+
 void
 virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct)
 {
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 5dc95dd..812a7fe 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -60,6 +60,8 @@ typedef struct {
 
 GType virt_viewer_app_get_type (void);
 
+const char *virt_viewer_app_get_title(VirtViewerApp *app);
+void virt_viewer_app_set_title(VirtViewerApp *app, const char *title);
 void virt_viewer_app_set_debug(gboolean debug);
 gboolean virt_viewer_app_start(VirtViewerApp *app);
 void virt_viewer_app_quit(VirtViewerApp *self);
-- 
1.7.11.2




More information about the virt-tools-list mailing list