[network-manager-applet/jklimes/team] editor: make Team config importing dialog modal and set parent window for it



commit 0807ad7b16e6e9e888711eec032cc32cd6284570
Author: Jiří Klimeš <jklimes redhat com>
Date:   Tue Oct 8 15:55:55 2013 +0200

    editor: make Team config importing dialog modal and set parent window for it
    
    Else the user could close the connection window and the dialog still refering
    to it would make the editor crash.

 src/connection-editor/page-team-port.c |   74 +++++++++++++++-----------------
 src/connection-editor/page-team.c      |   69 +++++++++++++-----------------
 2 files changed, 65 insertions(+), 78 deletions(-)
---
diff --git a/src/connection-editor/page-team-port.c b/src/connection-editor/page-team-port.c
index 280cf4e..1c8a55f 100644
--- a/src/connection-editor/page-team-port.c
+++ b/src/connection-editor/page-team-port.c
@@ -60,57 +60,53 @@ json_config_changed (GObject *object, CEPageTeamPort *self)
 }
 
 static void
-import_config_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
+import_button_clicked_cb (GtkWidget *widget, CEPageTeamPort *self)
 {
-       CEPageTeamPortPrivate *priv = CE_PAGE_TEAM_PORT_GET_PRIVATE (user_data);
+       CEPageTeamPortPrivate *priv = CE_PAGE_TEAM_PORT_GET_PRIVATE (self);
+       GtkWidget *dialog;
+       GtkWindow *toplevel;
        GtkTextBuffer *buffer;
        char *filename;
        char *buf = NULL;
        gsize buf_len;
-
-       if (response != GTK_RESPONSE_ACCEPT)
-               goto out;
-
-       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-       if (!filename) {
-               g_warning ("%s: didn't get a filename back from the chooser!", __func__);
-               goto out;
-       }
-
-       /* Put the file content into JSON config text view. */
-       // FIXME: do a cleverer file validity check
-       g_file_get_contents (filename, &buf, &buf_len, NULL);
-       if (buf_len > 100000) {
-               g_free (buf);
-               buf = g_strdup (_("Error: file doesn't contain a valid JSON configuration"));
-       }
-
-       buffer = gtk_text_view_get_buffer (priv->json_config_widget);
-       gtk_text_buffer_set_text (buffer, buf ? buf : "", -1);
-
-       g_free (filename);
-       g_free (buf);
-
-out:
-       gtk_widget_hide (dialog);
-       gtk_widget_destroy (dialog);
-}
-
-static void
-import_button_clicked_cb (GtkWidget *widget, CEPageTeamPort *self)
-{
-       GtkWidget *dialog;
+       
+       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (widget));
+       if (!gtk_widget_is_toplevel (GTK_WIDGET (toplevel)))
+               toplevel = NULL;
 
        dialog = gtk_file_chooser_dialog_new (_("Select file to import"),
-                                             NULL,
+                                             toplevel,
                                              GTK_FILE_CHOOSER_ACTION_OPEN,
                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                              GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                              NULL);
+       gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+       {
+               filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+               if (!filename) {
+                       g_warning ("%s: didn't get a filename back from the chooser!", __func__);
+                       goto out;
+               }
+
+               /* Put the file content into JSON config text view. */
+               // FIXME: do a cleverer file validity check
+               g_file_get_contents (filename, &buf, &buf_len, NULL);
+               if (buf_len > 100000) {
+                       g_free (buf);
+                       buf = g_strdup (_("Error: file doesn't contain a valid JSON configuration"));
+               }
+
+               buffer = gtk_text_view_get_buffer (priv->json_config_widget);
+               gtk_text_buffer_set_text (buffer, buf ? buf : "", -1);
+
+               g_free (filename);
+               g_free (buf);
+       }
 
-       g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (import_config_from_file_cb), self);
-       gtk_widget_show_all (dialog);
-       gtk_window_present (GTK_WINDOW (dialog));
+out:
+       gtk_widget_destroy (dialog);
 }
 
 static void
diff --git a/src/connection-editor/page-team.c b/src/connection-editor/page-team.c
index a14a4d8..4e7a490 100644
--- a/src/connection-editor/page-team.c
+++ b/src/connection-editor/page-team.c
@@ -71,57 +71,48 @@ json_config_changed (GObject *object, CEPageTeam *self)
 }
 
 static void
-import_config_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
+import_button_clicked_cb (GtkWidget *widget, CEPageTeam *self)
 {
-       CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (user_data);
+       CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self);
+       GtkWidget *dialog;
        GtkTextBuffer *buffer;
        char *filename;
        char *buf = NULL;
        gsize buf_len;
 
-       if (response != GTK_RESPONSE_ACCEPT)
-               goto out;
-
-       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-       if (!filename) {
-               g_warning ("%s: didn't get a filename back from the chooser!", __func__);
-               goto out;
-       }
-
-       /* Put the file content into JSON config text view. */
-       // FIXME: do a cleverer file validity check
-       g_file_get_contents (filename, &buf, &buf_len, NULL);
-       if (buf_len > 100000) {
-               g_free (buf);
-               buf = g_strdup (_("Error: file doesn't contain a valid JSON configuration"));
-       }
-
-       buffer = gtk_text_view_get_buffer (priv->json_config_widget);
-       gtk_text_buffer_set_text (buffer, buf ? buf : "", -1);
-
-       g_free (filename);
-       g_free (buf);
-
-out:
-       gtk_widget_hide (dialog);
-       gtk_widget_destroy (dialog);
-}
-
-static void
-import_button_clicked_cb (GtkWidget *widget, CEPageTeam *self)
-{
-       GtkWidget *dialog;
-
        dialog = gtk_file_chooser_dialog_new (_("Select file to import"),
-                                             NULL,
+                                             priv->toplevel,
                                              GTK_FILE_CHOOSER_ACTION_OPEN,
                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                              GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                              NULL);
+       gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+       {
+               filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+               if (!filename) {
+                       g_warning ("%s: didn't get a filename back from the chooser!", __func__);
+                       goto out;
+               }
+
+               /* Put the file content into JSON config text view. */
+               // FIXME: do a cleverer file validity check
+               g_file_get_contents (filename, &buf, &buf_len, NULL);
+               if (buf_len > 100000) {
+                       g_free (buf);
+                       buf = g_strdup (_("Error: file doesn't contain a valid JSON configuration"));
+               }
+
+               buffer = gtk_text_view_get_buffer (priv->json_config_widget);
+               gtk_text_buffer_set_text (buffer, buf ? buf : "", -1);
+
+               g_free (filename);
+               g_free (buf);
+       }
 
-       g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (import_config_from_file_cb), self);
-       gtk_widget_show_all (dialog);
-       gtk_window_present (GTK_WINDOW (dialog));
+out:
+       gtk_widget_destroy (dialog);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]