[virt-tools-list] [PATCH virt-viewer 2/4] Run ISO dialog when 'Change CD' menu is activated

Eduardo Lima (Etrunko) etrunko at redhat.com
Mon Jan 23 19:28:14 UTC 2017


Also moves 'Change CD' menu item from the toplevel menu to a subitem
under 'File' toplevel menu.

In order to avoid object interdependency, it is necessary to make the
ovirt foreign-menu pointer from RemoteViewer, acessible via property, so
it can be passed to the dialog as an opaque GObject.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
---
 src/remote-viewer.c             | 37 +++++++++++++++++++++++++++++++++++++
 src/resources/ui/virt-viewer.ui | 19 ++++++++++---------
 src/virt-viewer-window.c        | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index c84a35b..29d7db1 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,
@@ -214,6 +221,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_object(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);
@@ -223,6 +249,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;
@@ -236,6 +263,16 @@ 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_object("ovirt-foreign-menu",
+                                                        "oVirt Foreign Menu",
+                                                        "Object which is used as interface to oVirt",
+                                                        OVIRT_TYPE_FOREIGN_MENU,
+                                                        G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+#endif
 }
 
 static void
diff --git a/src/resources/ui/virt-viewer.ui b/src/resources/ui/virt-viewer.ui
index 6e3c5ad..e9609ec 100644
--- a/src/resources/ui/virt-viewer.ui
+++ b/src/resources/ui/virt-viewer.ui
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
 <interface>
-  <!-- interface-requires gtk+ 2.6 -->
+  <requires lib="gtk+" version="3.0"/>
   <object class="GtkAccelGroup" id="accelgroup"/>
   <object class="GtkApplicationWindow" id="viewer">
     <property name="can_focus">False</property>
@@ -73,6 +74,14 @@
                           </object>
                         </child>
                         <child>
+                          <object class="GtkMenuItem" id="menu-change-cd">
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">_Change CD</property>
+                            <property name="use_underline">True</property>
+                            <signal name="activate" handler="virt_viewer_window_menu_change_cd_activate" swapped="no"/>
+                          </object>
+                        </child>
+                        <child>
                           <object class="GtkMenuItem" id="menu-preferences">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
@@ -247,14 +256,6 @@
                     </child>
                   </object>
                 </child>
-                <child>
-                  <object class="GtkMenuItem" id="menu-change-cd">
-                    <property name="use_action_appearance">False</property>
-                    <property name="can_focus">False</property>
-                    <property name="label" translatable="yes">_Change CD</property>
-                    <property name="use_underline">True</property>
-                  </object>
-                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 99fd102..8eda12e 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -43,6 +43,8 @@
 #include "virt-viewer-util.h"
 #include "virt-viewer-timed-revealer.h"
 
+#include "remote-viewer-iso-list-dialog.h"
+
 #define ZOOM_STEP 10
 
 /* Signal handlers for main window (move in a VirtViewerMainWindow?) */
@@ -62,6 +64,7 @@ void virt_viewer_window_menu_file_smartcard_insert(GtkWidget *menu, VirtViewerWi
 void virt_viewer_window_menu_file_smartcard_remove(GtkWidget *menu, VirtViewerWindow *self);
 void virt_viewer_window_menu_view_release_cursor(GtkWidget *menu, VirtViewerWindow *self);
 void virt_viewer_window_menu_preferences_cb(GtkWidget *menu, VirtViewerWindow *self);
+void virt_viewer_window_menu_change_cd_activate(GtkWidget *menu, VirtViewerWindow *self);
 
 
 /* Internal methods */
@@ -1056,6 +1059,40 @@ virt_viewer_window_menu_help_about(GtkWidget *menu G_GNUC_UNUSED,
     g_object_unref(G_OBJECT(about));
 }
 
+static void
+iso_dialog_response(GtkDialog *dialog,
+                    gint response_id,
+                    gpointer user_data G_GNUC_UNUSED)
+{
+    if (response_id == GTK_RESPONSE_NONE)
+        return;
+
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+}
+
+void
+virt_viewer_window_menu_change_cd_activate(GtkWidget *menu G_GNUC_UNUSED,
+                                           VirtViewerWindow *self)
+{
+    VirtViewerWindowPrivate *priv = self->priv;
+    GtkWidget *dialog;
+    GObject *foreign_menu;
+
+    g_object_get(G_OBJECT(priv->app), "ovirt-foreign-menu", &foreign_menu, NULL);
+    dialog = remote_viewer_iso_list_dialog_new(GTK_WINDOW(priv->window), foreign_menu);
+    g_object_unref(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 to connnect to oVirt"));
+
+    g_signal_connect(dialog, "response", G_CALLBACK(iso_dialog_response), NULL);
+    gtk_widget_show_all(dialog);
+    gtk_dialog_run(GTK_DIALOG(dialog));
+}
 
 static void
 virt_viewer_window_toolbar_setup(VirtViewerWindow *self)
-- 
2.9.3




More information about the virt-tools-list mailing list