From c6c4ed4e03ec8a02a462a412a0d7ac0c5af47a55 Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Tue, 28 Jan 2014 09:21:33 +0000
Subject: [PATCH] Modified position and connect dialogbox destroy control.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4969 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 .../utils/itti_analyzer/libui/ui_callbacks.c  | 33 +++++++++++++++++--
 .../utils/itti_analyzer/libui/ui_callbacks.h  |  2 ++
 .../itti_analyzer/libui/ui_main_screen.c      |  2 ++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/common/utils/itti_analyzer/libui/ui_callbacks.c b/common/utils/itti_analyzer/libui/ui_callbacks.c
index b499688045..3647c12166 100644
--- a/common/utils/itti_analyzer/libui/ui_callbacks.c
+++ b/common/utils/itti_analyzer/libui/ui_callbacks.c
@@ -637,6 +637,16 @@ gboolean ui_callback_on_auto_reconnect(GtkWidget *widget, gpointer data)
     return TRUE;
 }
 
+void ui_callback_dialogbox_connect_destroy(void)
+{
+    if (dialogbox_connect != NULL)
+    {
+        gtk_widget_destroy (dialogbox_connect);
+        dialogbox_connect = NULL;
+        g_message("Connect dialogbox destroyed");
+    }
+}
+
 gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
 {
     /* We have to retrieve the ip address and ui_port of remote host */
@@ -685,6 +695,8 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
                 "Connection lost!\n\n" "Trying to reconnect to %s:%d ..."
             };
             gint response;
+            gint x, y;
+            gint w, h;
 
             if (socket_connect_to_remote_host (ui_ip, ui_port, pipe_fd[1]) != 0)
             {
@@ -693,13 +705,31 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
                 return FALSE;
             }
 
+            /* Create dialog box for connect message:
+             * - non modal mode does not seems to work, don't set the parent window to allow some interactions with it!
+             */
             dialogbox_connect = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_OTHER,
                                                 GTK_BUTTONS_CANCEL, message_formats[start ? 0 : 1], ui_ip, ui_port);
             gtk_window_set_title (GTK_WINDOW(dialogbox_connect), "Connect");
 
+            /* Set the window at center of main window manually as there is no parent defined */
+            gtk_window_get_position (GTK_WINDOW(ui_main_data.window), &x, &y);
+            gtk_window_get_size (GTK_WINDOW(ui_main_data.window), &w, &h);
+            g_message("Main window position: %d,%d dimension: %d,%d", x, y, w, h);
+            x += w / 2;
+            y += h / 2;
+            g_message("Connect window position %d,%d", x, y);
+            gtk_window_set_gravity (GTK_WINDOW(dialogbox_connect), GDK_GRAVITY_CENTER);
+            gtk_window_move (GTK_WINDOW(dialogbox_connect), x, y);
+
             response = gtk_dialog_run (GTK_DIALOG (dialogbox_connect));
             g_message("Connect dialog response %s (%d)", gtk_get_respose_string(response), response);
 
+            if (response == GTK_RESPONSE_NONE)
+            {
+                /* Dialogbox has been destroyed when program is exited, do nothing */
+                return (TRUE);
+            }
             if (response == GTK_RESPONSE_OK)
             {
                 /* Connection is established */
@@ -720,8 +750,7 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
                 ui_enable_connect_button();
                 operation_running = FALSE;
             }
-            gtk_widget_destroy (dialogbox_connect);
-            dialogbox_connect = NULL;
+            ui_callback_dialogbox_connect_destroy ();
         }
     }
 
diff --git a/common/utils/itti_analyzer/libui/ui_callbacks.h b/common/utils/itti_analyzer/libui/ui_callbacks.h
index 1eb3b421f6..5266ff013b 100644
--- a/common/utils/itti_analyzer/libui/ui_callbacks.h
+++ b/common/utils/itti_analyzer/libui/ui_callbacks.h
@@ -33,6 +33,8 @@ gboolean ui_pipe_callback(gint source, gpointer user_data);
 gboolean ui_callback_on_auto_reconnect(GtkWidget *widget,
                                        gpointer data);
 
+void ui_callback_dialogbox_connect_destroy(void);
+
 gboolean ui_callback_on_connect(GtkWidget *widget,
                                 gpointer   data);
 
diff --git a/common/utils/itti_analyzer/libui/ui_main_screen.c b/common/utils/itti_analyzer/libui/ui_main_screen.c
index f53ed094d6..b326233fc8 100644
--- a/common/utils/itti_analyzer/libui/ui_main_screen.c
+++ b/common/utils/itti_analyzer/libui/ui_main_screen.c
@@ -15,6 +15,7 @@
 #include "logs.h"
 #include "rc.h"
 
+#include "ui_callbacks.h"
 #include "ui_interface.h"
 #include "ui_main_screen.h"
 #include "ui_menu_bar.h"
@@ -167,6 +168,7 @@ void ui_set_title(const char *fmt, ...)
 
 void ui_main_window_destroy (void)
 {
+    ui_callback_dialogbox_connect_destroy();
     ui_progressbar_window_destroy();
     gtk_main_quit();
 }
-- 
GitLab