[virt-tools-list] [PATCH virt-viewer 2/2] Improve window title when connected to newer spice-server
Jonathon Jongsma
jjongsma at redhat.com
Fri Feb 7 16:08:24 UTC 2014
anyone care to review these 2 patches?
----- Original Message -----
> From: "Jonathon Jongsma" <jjongsma at redhat.com>
> To: virt-tools-list at redhat.com
> Sent: Monday, January 20, 2014 4:14:58 PM
> Subject: [virt-tools-list] [PATCH virt-viewer 2/2] Improve window title when connected to newer spice-server
>
> Recent spice servers send the guest vm name and uuid to the client. We can
> use
> these values to display the proper vm name in the window title if a title is
> not
> specified on the commandline. We can also be smarter about the title in
> virt-viewer as well.
>
> If a title is specified on the comamndline (-t/--title=foo), we use that. If
> not,
> we fall back to the vm name. If that is empty, we fall back to the uri of
> the
> connection.
>
> Comparison between old behavior and new behavior
>
> Using new spice-server
> Command Old title New
> title
> ------- ---------
> ---------
> remote-viewer -t xyz spice://host:port xyz xyz
> remote-viewer spice://host:port spice://host:port
> <vnname>
> virt-viewer <vmname> <vmname>
> <vnname>
> virt-viewer <uuid> <uuid>
> <vnname>
>
> Using old spice-server
> Command Old title New
> title
> ------- ---------
> ---------
> remote-viewer -t xyz spice://host:port xyz xyz
> remote-viewer spice://host:port spice://host:port
> spice://host:port
> virt-viewer <vmname> <vmname>
> <vnname>
> virt-viewer <uuid> <uuid>
> <vmname>
> ---
> src/remote-viewer-main.c | 5 +++--
> src/remote-viewer.c | 13 ++----------
> src/remote-viewer.h | 2 +-
> src/virt-viewer-app.c | 54
> ++++++++++++++++++++++++++++--------------------
> src/virt-viewer-app.h | 2 --
> src/virt-viewer-file.c | 2 +-
> src/virt-viewer.c | 6 +-----
> 7 files changed, 40 insertions(+), 44 deletions(-)
>
> diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
> index 505074e..c0de02c 100644
> --- a/src/remote-viewer-main.c
> +++ b/src/remote-viewer-main.c
> @@ -160,8 +160,9 @@ main(int argc, char **argv)
> g_object_set(viewer, "guest-name", "defined by Spice controller",
> NULL);
> } else {
> #endif
> - viewer = remote_viewer_new(uri, title);
> - g_object_set(viewer, "guest-name", uri, NULL);
> + viewer = remote_viewer_new(uri);
> + if (title)
> + g_object_set(viewer, "title", title, NULL);
> #ifdef HAVE_SPICE_GTK
> }
> #endif
> diff --git a/src/remote-viewer.c b/src/remote-viewer.c
> index 768ff74..af9cbd4 100644
> --- a/src/remote-viewer.c
> +++ b/src/remote-viewer.c
> @@ -57,10 +57,6 @@ struct _RemoteViewerPrivate {
> GtkWidget *controller_menu;
> GtkWidget *foreign_menu;
> gboolean open_recent_dialog;
> -
> - gboolean default_title; /* Whether the window title was set by the user,
> or
> - is the default one (URI we are connecting to)
> */
> -
> };
>
> G_DEFINE_TYPE (RemoteViewer, remote_viewer, VIRT_VIEWER_TYPE_APP)
> @@ -225,11 +221,10 @@ remote_viewer_init(RemoteViewer *self)
> }
>
> RemoteViewer *
> -remote_viewer_new(const gchar *uri, const gchar *title)
> +remote_viewer_new(const gchar *uri)
> {
> return g_object_new(REMOTE_VIEWER_TYPE,
> "guri", uri,
> - "title", title,
> "open-recent-dialog", uri == NULL,
> NULL);
> }
> @@ -547,7 +542,7 @@ spice_ctrl_notified(SpiceCtrlController *ctrl,
> &value);
> }
> } else if (g_str_equal(pspec->name, "title")) {
> - virt_viewer_app_set_title(app, g_value_get_string(&value));
> + g_object_set(app, "title", g_value_get_string(&value), NULL);
> } else if (g_str_equal(pspec->name, "display-flags")) {
> guint flags = g_value_get_uint(&value);
> gboolean fullscreen = !!(flags & (CONTROLLER_SET_FULL_SCREEN |
> CONTROLLER_AUTO_DISPLAY_RES));
> @@ -987,10 +982,6 @@ retry_dialog:
> g_return_val_if_fail(guri != NULL, FALSE);
>
> DEBUG_LOG("Opening display to %s", guri);
> - if ((virt_viewer_app_get_title(app) == NULL) || priv->default_title)
> {
> - priv->default_title = TRUE;
> - virt_viewer_app_set_title(app, guri);
> - }
>
> file = g_file_new_for_commandline_arg(guri);
> if (g_file_query_exists(file, NULL)) {
> diff --git a/src/remote-viewer.h b/src/remote-viewer.h
> index 6035f94..6d445ca 100644
> --- a/src/remote-viewer.h
> +++ b/src/remote-viewer.h
> @@ -48,7 +48,7 @@ typedef struct {
>
> GType remote_viewer_get_type (void);
>
> -RemoteViewer* remote_viewer_new(const gchar *uri, const gchar *title);
> +RemoteViewer* remote_viewer_new(const gchar *uri);
> RemoteViewer* remote_viewer_new_with_controller(void);
>
> G_END_DECLS
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index 0cdf95a..6f29ae0 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -597,21 +597,37 @@ virt_viewer_app_trace(VirtViewerApp *self,
> }
> }
>
> +static const gchar*
> +virt_viewer_app_get_title(VirtViewerApp *self)
> +{
> + const gchar *title;
> + g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL);
> +
> + title = self->priv->title;
> + if (!title)
> + title = self->priv->guest_name;
> + if (!title)
> + title = self->priv->guri;
> +
> + return title;
> +}
> +
> static void
> virt_viewer_app_set_window_subtitle(VirtViewerApp *app,
> VirtViewerWindow *window,
> int nth)
> {
> gchar *subtitle = NULL;
> + const gchar *title = virt_viewer_app_get_title(app);
>
> - if (app->priv->title != NULL) {
> - gchar *d = strstr(app->priv->title, "%d");
> + if (title != NULL) {
> + gchar *d = strstr(title, "%d");
> if (d != NULL) {
> *d = '\0';
> - subtitle = g_strdup_printf("%s%d%s", app->priv->title, nth + 1,
> d + 2);
> + subtitle = g_strdup_printf("%s%d%s", title, nth + 1, d + 2);
> *d = '%';
> } else
> - subtitle = g_strdup_printf("%s (%d)", app->priv->title, nth +
> 1);
> + subtitle = g_strdup_printf("%s (%d)", title, nth + 1);
> }
>
> g_object_set(window, "subtitle", subtitle, NULL);
> @@ -1419,7 +1435,7 @@ virt_viewer_app_get_property (GObject *object, guint
> property_id,
> break;
>
> case PROP_TITLE:
> - g_value_set_string(value, priv->title);
> + g_value_set_string(value, virt_viewer_app_get_title(self));
> break;
>
> case PROP_ENABLE_ACCEL:
> @@ -1472,7 +1488,8 @@ virt_viewer_app_set_property (GObject *object, guint
> property_id,
> break;
>
> case PROP_TITLE:
> - virt_viewer_app_set_title(self, g_value_get_string(value));
> + g_free(self->priv->title);
> + self->priv->title = g_value_dup_string(value);
> break;
>
> case PROP_ENABLE_ACCEL:
> @@ -1558,6 +1575,12 @@ static gboolean opt_kiosk = FALSE;
> static gboolean opt_kiosk_quit = FALSE;
>
> static void
> +title_maybe_changed(VirtViewerApp *self, GParamSpec* pspec G_GNUC_UNUSED,
> gpointer user_data G_GNUC_UNUSED)
> +{
> + virt_viewer_app_set_all_window_subtitles(self);
> +}
> +
> +static void
> virt_viewer_app_init (VirtViewerApp *self)
> {
> GError *error = NULL;
> @@ -1587,6 +1610,9 @@ virt_viewer_app_init (VirtViewerApp *self)
>
> self->priv->verbose = opt_verbose;
> self->priv->quit_on_disconnect = opt_kiosk ? opt_kiosk_quit : TRUE;
> + g_signal_connect(self, "notify::guest-name",
> G_CALLBACK(title_maybe_changed), NULL);
> + g_signal_connect(self, "notify::title", G_CALLBACK(title_maybe_changed),
> NULL);
> + g_signal_connect(self, "notify::guri", G_CALLBACK(title_maybe_changed),
> NULL);
>
> virt_viewer_window_set_zoom_level(self->priv->main_window, opt_zoom);
> }
> @@ -1804,22 +1830,6 @@ 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 7c77957..5058281 100644
> --- a/src/virt-viewer-app.h
> +++ b/src/virt-viewer-app.h
> @@ -60,8 +60,6 @@ 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_maybe_quit(VirtViewerApp *self, VirtViewerWindow
> *window);
> diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
> index 639d96e..09f76b3 100644
> --- a/src/virt-viewer-file.c
> +++ b/src/virt-viewer-file.c
> @@ -632,7 +632,7 @@ virt_viewer_file_fill_app(VirtViewerFile* self,
> VirtViewerApp *app, GError **err
> }
>
> if (virt_viewer_file_is_set(self, "title"))
> - virt_viewer_app_set_title(app, virt_viewer_file_get_title(self));
> + g_object_set(app, "title", virt_viewer_file_get_title(self), NULL);
>
>
> virt_viewer_app_clear_hotkeys(app);
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index e1553fd..679075a 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -409,7 +409,7 @@ virt_viewer_update_display(VirtViewer *self, virDomainPtr
> dom)
> virt_viewer_app_trace(app, "Guest %s is running, determining display",
> priv->domkey);
>
> - g_object_set(app, "title", virDomainGetName(dom), NULL);
> + g_object_set(app, "guest-name", virDomainGetName(dom), NULL);
>
> if (!virt_viewer_app_has_session(app)) {
> if (!virt_viewer_extract_connect_info(self, dom))
> @@ -757,10 +757,6 @@ virt_viewer_new(const char *uri,
> app = VIRT_VIEWER_APP(self);
> priv = self->priv;
>
> - /* Set initial title based on guest name arg, which can be a ID,
> - * UUID, or NAME string. To be replaced with the real guest name later
> - */
> - g_object_set(app, "title", name, NULL);
> virt_viewer_app_set_direct(app, direct);
> virt_viewer_app_set_attach(app, attach);
>
> --
> 1.8.4.2
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
>
More information about the virt-tools-list
mailing list