[virt-tools-list] [PATCH virt-viewer v3] Set a transient parent for GtkDialogs

Pavel Grunt pgrunt at redhat.com
Fri Dec 19 16:24:08 UTC 2014


Silence the Gtk 3.14 message:
"GtkDialog mapped without a transient parent. This is discouraged."
---
v3:
 - alignment was changed
---
 src/remote-viewer.c             | 26 ++++++++++++++++++--------
 src/virt-viewer-vm-connection.c |  5 ++++-
 src/virt-viewer-vm-connection.h |  4 +++-
 src/virt-viewer.c               | 10 +++++++---
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 818c421..65a5743 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -76,7 +76,10 @@ enum {
 };
 
 #ifdef HAVE_OVIRT
-static OvirtVm * choose_vm(char **vm_name, OvirtCollection *vms, GError **error);
+static OvirtVm * choose_vm(GtkWindow *main_window,
+                           char **vm_name,
+                           OvirtCollection *vms,
+                           GError **error);
 #endif
 
 static gboolean remote_viewer_start(VirtViewerApp *self);
@@ -84,7 +87,7 @@ static gboolean remote_viewer_start(VirtViewerApp *self);
 static gboolean remote_viewer_activate(VirtViewerApp *self, GError **error);
 static void remote_viewer_window_added(VirtViewerApp *self, VirtViewerWindow *win);
 static void spice_foreign_menu_updated(RemoteViewer *self);
-static gint connect_dialog(gchar **uri);
+static gint connect_dialog(GtkWindow *main_window, gchar **uri);
 #endif
 
 static void
@@ -836,6 +839,8 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
     gchar *host_subject = NULL;
     gchar *guid = NULL;
 
+    VirtViewerWindow *main_window;
+
     g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);
 
     if (!parse_ovirt_uri(uri, &rest_uri, &vm_name, &username)) {
@@ -865,7 +870,8 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
     }
     if (vm_name == NULL ||
         (vm = OVIRT_VM(ovirt_collection_lookup_resource(vms, vm_name))) == NULL) {
-        vm = choose_vm(&vm_name, vms, &error);
+        main_window = virt_viewer_app_get_main_window(app);
+        vm = choose_vm(virt_viewer_window_get_window(main_window), &vm_name, vms, &error);
         if (vm == NULL) {
             goto error;
         }
@@ -1048,7 +1054,7 @@ static void make_label_bold(GtkLabel* label)
 }
 
 static gint
-connect_dialog(gchar **uri)
+connect_dialog(GtkWindow *main_window, gchar **uri)
 {
     GtkWidget *dialog, *area, *box, *label, *entry, *recent;
 #if !GTK_CHECK_VERSION(3, 0, 0)
@@ -1059,7 +1065,7 @@ connect_dialog(gchar **uri)
 
     /* Create the widgets */
     dialog = gtk_dialog_new_with_buttons(_("Connection details"),
-                                         NULL,
+                                         main_window,
                                          GTK_DIALOG_DESTROY_WITH_PARENT,
                                          GTK_STOCK_CANCEL,
                                          GTK_RESPONSE_REJECT,
@@ -1138,7 +1144,7 @@ connect_dialog(gchar **uri)
 
 #ifdef HAVE_OVIRT
 static OvirtVm *
-choose_vm(char **vm_name, OvirtCollection *vms_collection, GError **error)
+choose_vm(GtkWindow *main_window, char **vm_name, OvirtCollection *vms_collection, GError **error)
 {
     GtkListStore *model;
     GtkTreeIter iter;
@@ -1162,7 +1168,9 @@ choose_vm(char **vm_name, OvirtCollection *vms_collection, GError **error)
        }
     }
 
-    *vm_name = virt_viewer_vm_connection_choose_name_dialog(GTK_TREE_MODEL(model), error);
+    *vm_name = virt_viewer_vm_connection_choose_name_dialog(main_window,
+                                                            GTK_TREE_MODEL(model),
+                                                            error);
     g_object_unref(model);
     if (*vm_name == NULL)
         return NULL;
@@ -1180,6 +1188,7 @@ remote_viewer_start(VirtViewerApp *app)
 
     RemoteViewer *self = REMOTE_VIEWER(app);
     RemoteViewerPrivate *priv = self->priv;
+    VirtViewerWindow *main_window;
     GFile *file = NULL;
     VirtViewerFile *vvfile = NULL;
     gboolean ret = FALSE;
@@ -1210,8 +1219,9 @@ remote_viewer_start(VirtViewerApp *app)
     } else {
 #endif
 retry_dialog:
+        main_window = virt_viewer_app_get_main_window(app);
         if (priv->open_recent_dialog) {
-            if (connect_dialog(&guri) != 0)
+            if (connect_dialog(virt_viewer_window_get_window(main_window), &guri) != 0)
                 return FALSE;
             g_object_set(app, "guri", guri, NULL);
         } else
diff --git a/src/virt-viewer-vm-connection.c b/src/virt-viewer-vm-connection.c
index 4a3feba..e15fd4f 100644
--- a/src/virt-viewer-vm-connection.c
+++ b/src/virt-viewer-vm-connection.c
@@ -43,7 +43,9 @@ treeselection_changed_cb(GtkTreeSelection *selection, gpointer userdata)
 }
 
 gchar*
-virt_viewer_vm_connection_choose_name_dialog(GtkTreeModel *model, GError **error)
+virt_viewer_vm_connection_choose_name_dialog(GtkWindow *main_window,
+                                             GtkTreeModel *model,
+                                             GError **error)
 {
     GtkBuilder *vm_connection;
     GtkWidget *dialog;
@@ -67,6 +69,7 @@ virt_viewer_vm_connection_choose_name_dialog(GtkTreeModel *model, GError **error
     g_return_val_if_fail(vm_connection != NULL, NULL);
 
     dialog = GTK_WIDGET(gtk_builder_get_object(vm_connection, "vm-connection-dialog"));
+    gtk_window_set_transient_for(GTK_WINDOW(dialog), main_window);
     button_connect = GTK_BUTTON(gtk_builder_get_object(vm_connection, "button-connect"));
     treeview = GTK_TREE_VIEW(gtk_builder_get_object(vm_connection, "treeview"));
     selection = GTK_TREE_SELECTION(gtk_builder_get_object(vm_connection, "treeview-selection"));
diff --git a/src/virt-viewer-vm-connection.h b/src/virt-viewer-vm-connection.h
index d198c89..8ce0bb2 100644
--- a/src/virt-viewer-vm-connection.h
+++ b/src/virt-viewer-vm-connection.h
@@ -24,7 +24,9 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 
-gchar* virt_viewer_vm_connection_choose_name_dialog(GtkTreeModel *model, GError **error);
+gchar* virt_viewer_vm_connection_choose_name_dialog(GtkWindow *main_window,
+                                                    GtkTreeModel *model,
+                                                    GError **error);
 
 #endif
 /*
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 193ef3a..13f130a 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -590,7 +590,7 @@ virt_viewer_dispose (GObject *object)
 }
 
 static virDomainPtr
-choose_vm(char **vm_name, virConnectPtr conn, GError **error)
+choose_vm(GtkWindow *main_window, char **vm_name, virConnectPtr conn, GError **error)
 {
     GtkListStore *model;
     GtkTreeIter iter;
@@ -611,7 +611,9 @@ choose_vm(char **vm_name, virConnectPtr conn, GError **error)
     }
     free(domains);
 
-    *vm_name = virt_viewer_vm_connection_choose_name_dialog(GTK_TREE_MODEL(model), error);
+    *vm_name = virt_viewer_vm_connection_choose_name_dialog(main_window,
+                                                            GTK_TREE_MODEL(model),
+                                                            error);
     g_object_unref(G_OBJECT(model));
     if (*vm_name == NULL)
         return NULL;
@@ -643,6 +645,7 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error)
     gboolean ret = FALSE;
     VirtViewer *self = VIRT_VIEWER(app);
     VirtViewerPrivate *priv = self->priv;
+    VirtViewerWindow *main_window;
     char uuid_string[VIR_UUID_STRING_BUFLEN];
     GError *err = NULL;
 
@@ -661,7 +664,8 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error)
             virt_viewer_app_show_status(app, _("Waiting for guest domain to be created"));
             goto wait;
         } else {
-            dom = choose_vm(&priv->domkey, priv->conn, &err);
+            main_window = virt_viewer_app_get_main_window(app);
+            dom = choose_vm(virt_viewer_window_get_window(main_window), &priv->domkey, priv->conn, &err);
             if (dom == NULL && err != NULL) {
                 goto cleanup;
             }
-- 
1.9.3




More information about the virt-tools-list mailing list