[gtranslator: 1/4] Queing messages and errors for infobar




commit 5dd4e9661056bb1d66d37de1b26aa799853474bd
Author: afshan ahmed khan <afshanahmeda2k gmail com>
Date:   Tue May 17 14:41:30 2022 +0530

    Queing messages and errors for infobar

 src/gtr-io-error-info-bar.c | 108 +++++++++++++++++++++++++++++++++-----------
 src/gtr-io-error-info-bar.h |  12 +++--
 src/gtr-tab.c               |  10 ++--
 3 files changed, 92 insertions(+), 38 deletions(-)
---
diff --git a/src/gtr-io-error-info-bar.c b/src/gtr-io-error-info-bar.c
index de90b416..709e1219 100644
--- a/src/gtr-io-error-info-bar.c
+++ b/src/gtr-io-error-info-bar.c
@@ -19,11 +19,29 @@
 
 #include "gtr-io-error-info-bar.h"
 #include "gtr-utils.h"
+#include "gtr-tab.h"
 
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
+static GArray * msg_queue_arr = NULL;
+
+enum msg_type
+{
+  INFO_MSG,
+  ERROR_MSG
+};
+
+typedef struct
+{
+  const gchar * primary_text;
+  const gchar * secondary_text;
+  enum msg_type message_type;
+} message_struct;
+
+static void show_info_bar (GtrTab * tab);
+
 static void
 set_contents (GtkInfoBar * infobar, GtkWidget * contents)
 {
@@ -109,57 +127,93 @@ set_info_bar_text_and_icon (GtkInfoBar * infobar,
  * Callback func called when warning button is clicked
  */
 static void
-warning_message_button_clicked (GtkWidget * widget,
-                                gint response_id, gpointer data)
+handle_info_bar_response(GtkWidget * infobar,gint response_id,
+                        GtrTab * tab)
 {
-  if (response_id == GTK_RESPONSE_CLOSE)
+  if (response_id == GTK_RESPONSE_OK || response_id == GTK_RESPONSE_CLOSE)
+  {
+    gtk_widget_hide (infobar);
+    message_struct msg_struct_temp = g_array_index (msg_queue_arr, message_struct, 0);
+    g_free ((gchar *)msg_struct_temp.primary_text);
+    g_free ((gchar *)msg_struct_temp.secondary_text);
+    msg_queue_arr = g_array_remove_index (msg_queue_arr, 0);
+
+    if (msg_queue_arr->len > 0)
     {
-      gtk_widget_hide (GTK_WIDGET (widget));
+      show_info_bar (tab);
     }
+  }
 }
 
-GtkWidget *
-create_error_info_bar (const gchar * primary_text,
-                       const gchar * secondary_text)
+static void
+show_info_bar (GtrTab * tab)
 {
   GtkWidget *infobar;
+  message_struct msg_struct_temp = g_array_index (msg_queue_arr, message_struct, 0);
+  const gchar * primary_text = msg_struct_temp.primary_text;
+  const gchar * secondary_text = msg_struct_temp.secondary_text;
+  enum msg_type message_type = msg_struct_temp.message_type;
+  gchar * icon_stock_id = NULL;
+
+  if (message_type == INFO_MSG)
+  {
+    infobar = gtk_info_bar_new_with_buttons (_("_OK"),
+                                             GTK_RESPONSE_OK, NULL);
+
+    gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
+
+    icon_stock_id = "dialog-information-symbolic";
+  }
+  else
+  {
+    infobar = gtk_info_bar_new_with_buttons (_("_Close"),
+                                             GTK_RESPONSE_CLOSE, NULL);
 
-  infobar = gtk_info_bar_new_with_buttons (_("_Close"),
-                                           GTK_RESPONSE_CLOSE, NULL);
+    gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_WARNING);
 
-  gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_WARNING);
+    icon_stock_id = "dialog-error-symbolic";
+  }
 
   set_info_bar_text_and_icon (GTK_INFO_BAR (infobar),
-                              "dialog-error-symbolic",
+                              icon_stock_id,
                               primary_text, secondary_text);
 
   g_signal_connect (G_OBJECT (infobar), "response",
-                    G_CALLBACK (warning_message_button_clicked), NULL);
+                    G_CALLBACK (handle_info_bar_response), tab);
 
   gtk_widget_show (infobar);
 
-  return infobar;
+  gtr_tab_set_info_bar(tab, infobar);
 }
 
-GtkWidget *
-create_info_info_bar (const gchar * primary_text,
-                      const gchar * secondary_text)
+void
+create_error_info_bar (const gchar * primary_text,
+                       const gchar * secondary_text,
+                       GtrTab * tab)
 {
-  GtkWidget *infobar;
+  message_struct msg_struct_temp = {g_strdup(primary_text), g_strdup(secondary_text), ERROR_MSG};
 
-  infobar = gtk_info_bar_new_with_buttons (_("_OK"),
-                                           GTK_RESPONSE_OK, NULL);
+  if (msg_queue_arr == NULL)
+    msg_queue_arr = g_array_new (FALSE, FALSE, sizeof(message_struct));
 
-  gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
+  g_array_append_val (msg_queue_arr, msg_struct_temp);
 
-  set_info_bar_text_and_icon (GTK_INFO_BAR (infobar),
-                              "dialog-information-symbolic",
-                              primary_text, secondary_text);
+  if (msg_queue_arr -> len == 1)
+    show_info_bar(tab);
+}
 
-  g_signal_connect (G_OBJECT (infobar), "response",
-                    G_CALLBACK (gtk_widget_hide), NULL);
+void
+create_info_info_bar (const gchar * primary_text,
+                      const gchar * secondary_text,
+                      GtrTab * tab )
+{
+  message_struct msg_struct_temp = {g_strdup(primary_text), g_strdup(secondary_text), INFO_MSG};
 
-  gtk_widget_show (infobar);
+  if (msg_queue_arr == NULL)
+    msg_queue_arr = g_array_new (FALSE, FALSE, sizeof(message_struct));
+
+  g_array_append_val (msg_queue_arr, msg_struct_temp);
 
-  return infobar;
+  if (msg_queue_arr->len == 1)
+    show_info_bar(tab);
 }
diff --git a/src/gtr-io-error-info-bar.h b/src/gtr-io-error-info-bar.h
index 4446dbb4..4b640333 100644
--- a/src/gtr-io-error-info-bar.h
+++ b/src/gtr-io-error-info-bar.h
@@ -19,15 +19,19 @@
 #ifndef __IO_ERROR_MESSAGE_AREA_H__
 #define __IO_ERROR_MESSAGE_AREA_H__
 
+#include "gtr-tab.h"
+
 #include <glib.h>
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
-  GtkWidget * create_error_info_bar (const gchar * primary_text,
-                                     const gchar * secondary_text);
+  void create_error_info_bar (const gchar * primary_text,
+                                     const gchar * secondary_text,
+                                     GtrTab * tab);
 
-  GtkWidget * create_info_info_bar (const gchar * primary_text,
-                                    const gchar * secondary_text);
+  void create_info_info_bar (const gchar * primary_text,
+                                    const gchar * secondary_text,
+                                    GtrTab * tab);
 
 G_END_DECLS
 #endif
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index d0179b6e..f4302eae 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -343,7 +343,6 @@ static void
 gtr_tab_edition_finished (GtrTab * tab, GtrMsg * msg)
 {
   gchar *message_error;
-  GtkWidget *infobar;
 
   /*
    * Checking message
@@ -354,9 +353,8 @@ gtr_tab_edition_finished (GtrTab * tab, GtrMsg * msg)
     {
       gtr_tab_block_movement (tab);
 
-      infobar = create_error_info_bar (_("There is an error in the message:"),
-                                       message_error);
-      gtr_tab_set_info_bar (tab, infobar);
+      create_error_info_bar (_("There is an error in the message:"),
+                                       message_error, tab);
       g_free (message_error);
     }
   else
@@ -1981,9 +1979,7 @@ gtr_tab_set_info (GtrTab * tab,
                   const char * primary,
                   const char * secondary)
 {
-  GtkWidget *infobar;
-  infobar = create_info_info_bar (primary, secondary);
-  gtr_tab_set_info_bar (tab, infobar);
+  create_info_info_bar (primary, secondary, tab);
 }
 
 GtrMsg *


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