Blob Blame History Raw
From 448989f9c46bbc4ec54627f6cf4c9648c919cc12 Mon Sep 17 00:00:00 2001
From: Christophe Fergeau <cfergeau@redhat.com>
Date: Fri, 27 Sep 2013 17:53:04 +0200
Subject: [PATCH] ovirt: Use OvirtForeignMenu class

After the previous commit which introduced the OvirtForeignMenu
class, we can now make use of it in the remote-viewer UI code.

Resolves: rhbz#1127156
(cherry picked from commit 3df1e5a17a315d1421f3b34df3f078f0c1505d9d)
---
 src/remote-viewer.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 26f0634..2b9b24d 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -30,6 +30,7 @@
 
 #ifdef HAVE_OVIRT
 #include <govirt/govirt.h>
+#include "ovirt-foreign-menu.h"
 #endif
 
 #ifdef HAVE_SPICE_GTK
@@ -56,6 +57,9 @@ struct _RemoteViewerPrivate {
 #endif
     GtkWidget *controller_menu;
     GtkWidget *foreign_menu;
+#ifdef HAVE_OVIRT
+    OvirtForeignMenu *ovirt_foreign_menu;
+#endif
     gboolean open_recent_dialog;
 
     gboolean default_title; /* Whether the window title was set by the user, or
@@ -99,6 +103,13 @@ remote_viewer_dispose (GObject *object)
         priv->ctrl_foreign_menu = NULL;
     }
 
+#ifdef HAVE_OVIRT
+    if (priv->ovirt_foreign_menu) {
+        g_object_unref(priv->ovirt_foreign_menu);
+        priv->ovirt_foreign_menu = NULL;
+    }
+#endif
+
     G_OBJECT_CLASS(remote_viewer_parent_class)->dispose (object);
 }
 #endif
@@ -418,6 +429,34 @@ spice_ctrl_menu_updated(RemoteViewer *self)
     g_hash_table_foreach(windows, spice_menu_update_each, self);
 }
 
+#ifdef HAVE_OVIRT
+static void
+ovirt_foreign_menu_update(RemoteViewer *app, VirtViewerWindow *win)
+{
+    GtkWidget *menu = g_object_get_data(G_OBJECT(win), "foreign-menu");
+    GtkWidget *submenu;
+    GtkMenuShell *shell = GTK_MENU_SHELL(gtk_builder_get_object(virt_viewer_window_get_builder(win), "top-menu"));
+
+    if (app->priv->ovirt_foreign_menu == NULL) {
+        /* nothing to do */
+        return;
+    }
+    if (menu == NULL) {
+        menu = gtk_menu_item_new_with_label(_("_Change CD"));
+        gtk_menu_item_set_use_underline(GTK_MENU_ITEM(menu), TRUE);
+        gtk_menu_shell_append(shell, menu);
+        g_object_set_data_full(G_OBJECT(win), "foreign-menu",
+                               g_object_ref(menu),
+                               (GDestroyNotify)gtk_widget_destroy);
+    }
+
+    submenu = ovirt_foreign_menu_get_gtk_menu(app->priv->ovirt_foreign_menu);
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), submenu);
+
+    gtk_widget_show_all(menu);
+}
+#endif
+
 static void
 foreign_menu_update(RemoteViewer *self, VirtViewerWindow *win)
 {
@@ -455,6 +494,10 @@ foreign_menu_update_each(gpointer key G_GNUC_UNUSED,
                          gpointer user_data)
 {
     foreign_menu_update(REMOTE_VIEWER(user_data), VIRT_VIEWER_WINDOW(value));
+#ifdef HAVE_OVIRT
+    ovirt_foreign_menu_update(REMOTE_VIEWER(user_data),
+                              VIRT_VIEWER_WINDOW(value));
+#endif
 }
 
 static void
@@ -626,6 +669,9 @@ remote_viewer_window_added(VirtViewerApp *app G_GNUC_UNUSED,
 {
     spice_menu_update(REMOTE_VIEWER(app), win);
     foreign_menu_update(REMOTE_VIEWER(app), win);
+#ifdef HAVE_OVIRT
+    ovirt_foreign_menu_update(REMOTE_VIEWER(app), win);
+#endif
 }
 #endif
 
@@ -718,6 +764,36 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
 }
 
 
+static void
+ovirt_foreign_menu_changed(OvirtForeignMenu *foreign_menu G_GNUC_UNUSED,
+                           GParamSpec *pspec G_GNUC_UNUSED,
+                           VirtViewerApp *app)
+{
+    spice_foreign_menu_updated(REMOTE_VIEWER(app));
+}
+
+
+static void
+virt_viewer_app_set_ovirt_foreign_menu(VirtViewerApp *app,
+                                       OvirtForeignMenu *foreign_menu)
+{
+    RemoteViewer *self;
+    g_return_if_fail(REMOTE_VIEWER_IS(app));
+    g_return_if_fail(OVIRT_IS_FOREIGN_MENU(foreign_menu));
+
+    self = REMOTE_VIEWER(app);
+    if (self->priv->ovirt_foreign_menu != NULL) {
+        g_object_unref(G_OBJECT(self->priv->ovirt_foreign_menu));
+    }
+    self->priv->ovirt_foreign_menu = foreign_menu;
+    g_signal_connect(G_OBJECT(foreign_menu), "notify::file",
+                     (GCallback)ovirt_foreign_menu_changed, app);
+    g_signal_connect(G_OBJECT(foreign_menu), "notify::files",
+                     (GCallback)ovirt_foreign_menu_changed, app);
+    ovirt_foreign_menu_start(foreign_menu);
+}
+
+
 static gboolean
 create_ovirt_session(VirtViewerApp *app, const char *uri)
 {
@@ -807,6 +883,12 @@ create_ovirt_session(VirtViewerApp *app, const char *uri)
         goto error;
     }
 
+    {
+        OvirtForeignMenu *ovirt_menu = ovirt_foreign_menu_new(proxy);
+        g_object_set(G_OBJECT(ovirt_menu), "api", api, "vm", vm, NULL);
+        virt_viewer_app_set_ovirt_foreign_menu(app, ovirt_menu);
+    }
+
     virt_viewer_app_set_connect_info(app, NULL, ghost, gport, gtlsport,
                                      session_type, NULL, NULL, 0, NULL);