[gtranslator: 7/9] Use response signal on native dialogs




commit 2f9a671b6c9c628927ee1986745084f58691a0f6
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Sun Mar 6 16:51:23 2022 +0100

    Use response signal on native dialogs

 src/gtr-actions-file.c                             |  7 +++-
 .../gtr-translation-memory-dialog.c                | 45 +++++++++++++---------
 2 files changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index d1a98571..851186e6 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -296,6 +296,8 @@ save_dialog_response_cb (GtkNativeDialog * dialog,
     {
       gtr_po_set_location (po, location);
 
+      g_object_unref (location);
+
       gtr_po_save_file (po, &error);
 
       if (error)
@@ -315,7 +317,10 @@ save_dialog_response_cb (GtkNativeDialog * dialog,
       /* We have to change the state of the tab */
       gtr_po_set_state (po, GTR_PO_STATE_SAVED);
     }
-  g_object_unref (location);
+  else
+    {
+      g_object_unref (location);
+    }
 }
 
 static void
diff --git a/src/translation-memory/gtr-translation-memory-dialog.c 
b/src/translation-memory/gtr-translation-memory-dialog.c
index 1456c5c9..d4442150 100644
--- a/src/translation-memory/gtr-translation-memory-dialog.c
+++ b/src/translation-memory/gtr-translation-memory-dialog.c
@@ -39,6 +39,31 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtrTranslationMemoryDialog, gtr_translation_memory_dialog, GTK_TYPE_DIALOG)
 
+static void
+native_response_cb (GtkNativeDialog *dialog, guint response, gpointer user_data)
+{
+  GtrTranslationMemoryDialog *dlg;
+  GtrTranslationMemoryDialogPrivate *priv;
+
+  dlg = GTR_TRANSLATION_MEMORY_DIALOG (user_data);
+  priv = gtr_translation_memory_dialog_get_instance_private (dlg);
+
+  if (response == GTK_RESPONSE_ACCEPT)
+    {
+      g_autofree char *filename = NULL;
+      GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
+
+      filename = gtk_file_chooser_get_filename (chooser);
+      gtk_entry_set_text (GTK_ENTRY (priv->directory_entry),
+                          filename);
+      g_settings_set_string (priv->tm_settings,
+                             "po-directory",
+                             filename);
+    }
+
+  gtk_native_dialog_destroy (dialog);
+}
+
 static void
 gtr_translation_memory_dialog_finalize (GObject *object)
 {
@@ -71,8 +96,6 @@ on_search_button_clicked (GtkButton                  *button,
                           GtrTranslationMemoryDialog *dlg)
 {
   GtkFileChooserNative *native;
-  gint res;
-  GtrTranslationMemoryDialogPrivate *priv = gtr_translation_memory_dialog_get_instance_private (dlg);
 
   native = gtk_file_chooser_native_new (_("Select PO directory"),
                                         GTK_WINDOW (dlg),
@@ -80,22 +103,8 @@ on_search_button_clicked (GtkButton                  *button,
                                         _("_OK"),
                                         _("_Cancel"));
 
-  res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
-  if (res == GTK_RESPONSE_ACCEPT)
-    {
-      char *filename;
-      GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
-
-      filename = gtk_file_chooser_get_filename (chooser);
-      gtk_entry_set_text (GTK_ENTRY (priv->directory_entry),
-                          filename);
-      g_settings_set_string (priv->tm_settings,
-                             "po-directory",
-                             filename);
-      g_free (filename);
-    }
-
-  g_object_unref (native);
+  g_signal_connect (native, "response", G_CALLBACK (native_response_cb), dlg);
+  gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
 }
 
 typedef struct _IdleData


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