[virt-tools-list] [PATCH 05/12] Add window-added & window-removed signals

Daniel P. Berrange berrange at redhat.com
Thu Jan 26 16:22:34 UTC 2012


On Tue, Dec 13, 2011 at 08:35:03PM +0100, Marc-André Lureau wrote:
> ---
>  src/virt-viewer-app.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
>  src/virt-viewer-app.h |    5 +++++
>  2 files changed, 48 insertions(+), 1 deletions(-)
> 
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index a7867ba..3bc69f7 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -143,6 +143,14 @@ enum {
>  	PROP_TITLE,
>  };
>  
> +enum {
> +	SIGNAL_WINDOW_ADDED,
> +	SIGNAL_WINDOW_REMOVED,
> +	SIGNAL_LAST,
> +};
> +
> +static guint signals[SIGNAL_LAST];
> +
>  void
>  virt_viewer_app_set_debug(gboolean debug)
>  {
> @@ -442,12 +450,22 @@ virt_viewer_app_get_nth_window(VirtViewerApp *self, gint nth)
>  static gboolean
>  virt_viewer_app_remove_nth_window(VirtViewerApp *self, gint nth)
>  {
> +	VirtViewerWindow *win;
>  	gboolean removed;
>  
>  	g_return_val_if_fail(nth != 0, FALSE);
> -	removed = g_hash_table_remove(self->priv->windows, &nth);
> +
> +	win = virt_viewer_app_get_nth_window(self, nth);
> +	g_return_val_if_fail(win != NULL, FALSE);
> +
> +	removed = g_hash_table_steal(self->priv->windows, &nth);
>  	g_warn_if_fail(removed);
>  
> +	if (removed)
> +		g_signal_emit(self, signals[SIGNAL_WINDOW_REMOVED], 0, win);
> +
> +	g_object_unref(win);
> +
>  	return removed;
>  }
>  
> @@ -461,6 +479,8 @@ virt_viewer_app_set_nth_window(VirtViewerApp *self, gint nth, VirtViewerWindow *
>  	*key = nth;
>  	g_hash_table_insert(self->priv->windows, key, win);
>  	virt_viewer_app_set_window_subtitle(self, win, nth);
> +
> +	g_signal_emit(self, signals[SIGNAL_WINDOW_ADDED], 0, win);
>  }
>  
>  static void
> @@ -1218,6 +1238,27 @@ virt_viewer_app_class_init (VirtViewerAppClass *klass)
>  							    G_PARAM_WRITABLE |
>  							    G_PARAM_STATIC_STRINGS));
>  
> +	signals[SIGNAL_WINDOW_ADDED] =
> +		g_signal_new("window-added",
> +			     G_OBJECT_CLASS_TYPE(object_class),
> +			     G_SIGNAL_RUN_LAST,
> +			     G_STRUCT_OFFSET(VirtViewerAppClass, window_added),
> +			     NULL, NULL,
> +			     g_cclosure_marshal_VOID__OBJECT,
> +			     G_TYPE_NONE,
> +			     1,
> +			     G_TYPE_OBJECT);
> +
> +	signals[SIGNAL_WINDOW_REMOVED] =
> +		g_signal_new("window-removed",
> +			     G_OBJECT_CLASS_TYPE(object_class),
> +			     G_SIGNAL_RUN_LAST,
> +			     G_STRUCT_OFFSET(VirtViewerAppClass, window_removed),
> +			     NULL, NULL,
> +			     g_cclosure_marshal_VOID__OBJECT,
> +			     G_TYPE_NONE,
> +			     1,
> +			     G_TYPE_OBJECT);
>  }
>  
>  void
> @@ -1447,6 +1488,7 @@ virt_viewer_app_show_status(VirtViewerApp *self, const gchar *fmt, ...)
>  	gchar *text;
>  
>  	g_return_if_fail(VIRT_VIEWER_IS_APP(self));
> +	g_return_if_fail(fmt != NULL);
>  
>  	va_start(args, fmt);
>  	text = g_strdup_vprintf(fmt, args);
> diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
> index cc85dfa..93b2b58 100644
> --- a/src/virt-viewer-app.h
> +++ b/src/virt-viewer-app.h
> @@ -46,6 +46,11 @@ typedef struct {
>  typedef struct {
>          GObjectClass parent_class;
>  
> +        /* signals */
> +       void (*window_added) (VirtViewerApp *self, VirtViewerWindow *window);
> +       void (*window_removed) (VirtViewerApp *self, VirtViewerWindow *window);
> +
> +        /*< private >*/
>          gboolean (*start) (VirtViewerApp *self);
>          int (*initial_connect) (VirtViewerApp *self);
>          void (*deactivated) (VirtViewerApp *self);

ACK


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the virt-tools-list mailing list