[virt-tools-list] [PATCH virt-viewer 10/11] remote-viewer: Make ovirt-foreign-menu a property
Eduardo Lima (Etrunko)
etrunko at redhat.com
Mon Jul 18 02:13:10 UTC 2016
The OvirtForeignMenu pointer is needed by the new ISO list dialog, and
we make it acessible via property to avoid interdependency between
objects.
Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
---
src/remote-viewer-iso-list-dialog.c | 20 +++++++++++++++-----
src/remote-viewer-iso-list-dialog.h | 3 ++-
src/remote-viewer.c | 36 ++++++++++++++++++++++++++++++++++++
src/virt-viewer-window.c | 16 +++++++++++++++-
4 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/src/remote-viewer-iso-list-dialog.c b/src/remote-viewer-iso-list-dialog.c
index b3972ac..996c1f2 100644
--- a/src/remote-viewer-iso-list-dialog.c
+++ b/src/remote-viewer-iso-list-dialog.c
@@ -34,6 +34,7 @@ struct _RemoteViewerISOListDialogPrivate
{
GtkBuilder *builder;
GtkWidget *notebook;
+ OvirtForeignMenu *foreign_menu;
};
enum RemoteViewerIsoListDialogPages
@@ -106,10 +107,19 @@ remote_viewer_iso_list_dialog_init(RemoteViewerISOListDialog *self)
}
GtkWidget *
-remote_viewer_iso_list_dialog_new(GtkWindow *parent)
+remote_viewer_iso_list_dialog_new(GtkWindow *parent, OvirtForeignMenu *foreign_menu)
{
- return g_object_new(REMOTE_VIEWER_TYPE_ISO_LIST_DIALOG,
- "title", _("Change CD"),
- "transient-for", parent,
- NULL);
+ GtkWidget *dialog;
+ RemoteViewerISOListDialog *self;
+
+ g_return_val_if_fail(foreign_menu != NULL, NULL);
+
+ dialog = g_object_new(REMOTE_VIEWER_TYPE_ISO_LIST_DIALOG,
+ "title", _("Change CD"),
+ "transient-for", parent,
+ NULL);
+
+ self = REMOTE_VIEWER_ISO_LIST_DIALOG(dialog);
+ self->priv->foreign_menu = foreign_menu;
+ return dialog;
}
diff --git a/src/remote-viewer-iso-list-dialog.h b/src/remote-viewer-iso-list-dialog.h
index def841b..ee7c70f 100644
--- a/src/remote-viewer-iso-list-dialog.h
+++ b/src/remote-viewer-iso-list-dialog.h
@@ -22,6 +22,7 @@
#define __REMOTE_VIEWER_ISO_LIST_DIALOG_H__
#include <gtk/gtk.h>
+#include "ovirt-foreign-menu.h"
G_BEGIN_DECLS
@@ -51,7 +52,7 @@ struct _RemoteViewerISOListDialogClass
GType remote_viewer_iso_list_dialog_get_type(void) G_GNUC_CONST;
-GtkWidget *remote_viewer_iso_list_dialog_new(GtkWindow *parent);
+GtkWidget *remote_viewer_iso_list_dialog_new(GtkWindow *parent, OvirtForeignMenu *foreign_menu);
G_END_DECLS
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 95130dc..e4e41c4 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -67,6 +67,13 @@ G_DEFINE_TYPE (RemoteViewer, remote_viewer, VIRT_VIEWER_TYPE_APP)
#define GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), REMOTE_VIEWER_TYPE, RemoteViewerPrivate))
+enum RemoteViewerProperties {
+ PROP_0,
+#ifdef HAVE_OVIRT
+ PROP_OVIRT_FOREIGN_MENU,
+#endif
+};
+
#ifdef HAVE_OVIRT
static OvirtVm * choose_vm(GtkWindow *main_window,
char **vm_name,
@@ -213,6 +220,25 @@ end:
}
static void
+remote_viewer_get_property(GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ RemoteViewer *self = REMOTE_VIEWER(object);
+ RemoteViewerPrivate *priv = self->priv;
+
+ switch (property_id) {
+#ifdef HAVE_OVIRT
+ case PROP_OVIRT_FOREIGN_MENU:
+ g_value_set_pointer(value, priv->ovirt_foreign_menu);
+ break;
+#endif
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
remote_viewer_class_init (RemoteViewerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -222,6 +248,7 @@ remote_viewer_class_init (RemoteViewerClass *klass)
g_type_class_add_private (klass, sizeof (RemoteViewerPrivate));
+ object_class->get_property = remote_viewer_get_property;
object_class->dispose = remote_viewer_dispose;
g_app_class->local_command_line = remote_viewer_local_command_line;
@@ -235,6 +262,15 @@ remote_viewer_class_init (RemoteViewerClass *klass)
#else
(void) gtk_app_class;
#endif
+
+#ifdef HAVE_OVIRT
+ g_object_class_install_property(object_class,
+ PROP_OVIRT_FOREIGN_MENU,
+ g_param_spec_pointer("ovirt-foreign-menu",
+ "oVirt Foreign Menu",
+ "Object which is used as interface to oVirt",
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+#endif
}
static void
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 867fb86..76fe80f 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -1072,11 +1072,25 @@ virt_viewer_window_menu_change_cd_activate(GtkWidget *menu G_GNUC_UNUSED,
{
VirtViewerWindowPrivate *priv = self->priv;
static GtkWidget *dialog = NULL;
+ GValue foreign_menu = G_VALUE_INIT;
if (dialog)
return;
- dialog = remote_viewer_iso_list_dialog_new(GTK_WINDOW(priv->window));
+ g_value_init(&foreign_menu, G_TYPE_POINTER);
+ g_object_get_property(G_OBJECT(priv->app), "ovirt-foreign-menu", &foreign_menu);
+ dialog = remote_viewer_iso_list_dialog_new(GTK_WINDOW(priv->window),
+ g_value_get_pointer(&foreign_menu));
+ g_value_unset(&foreign_menu);
+
+ if (!dialog) {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(priv->window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Unable do connnect to oVirt"));
+ }
+
g_signal_connect(dialog, "response", G_CALLBACK(iso_dialog_response), &dialog);
gtk_widget_show_all(dialog);
gtk_dialog_run(GTK_DIALOG(dialog));
--
2.7.4
More information about the virt-tools-list
mailing list