[Pkg-privacy-commits] [nautilus-wipe] 11/37: NwProgressDialog: do not emit the same response from inside an emission chain

Intrigeri intrigeri at moszumanska.debian.org
Wed Dec 7 18:46:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to branch master
in repository nautilus-wipe.

commit 010cad7070ec5b15a8c3579718a41238fffa5182
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Mon Jul 18 16:57:50 2016 +0200

    NwProgressDialog: do not emit the same response from inside an emission chain
    
    Do not re-emit the same response through a set function when inside an
    emission chain already.  This avoids getting twice the signal when using
    the set method from inside the response handler.
---
 nautilus-wipe/nw-progress-dialog.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/nautilus-wipe/nw-progress-dialog.c b/nautilus-wipe/nw-progress-dialog.c
index 84a29e0..93c5536 100644
--- a/nautilus-wipe/nw-progress-dialog.c
+++ b/nautilus-wipe/nw-progress-dialog.c
@@ -39,6 +39,7 @@ struct _NwProgressDialogPrivate {
   gboolean        finished;
   gboolean        canceled;
   gboolean        auto_hide_action_area;
+  gint            current_response;
 };
 
 enum
@@ -130,6 +131,18 @@ nw_progress_dialog_response (GtkDialog *dialog,
   if (GTK_DIALOG_CLASS (nw_progress_dialog_parent_class)->response) {
     GTK_DIALOG_CLASS (nw_progress_dialog_parent_class)->response (dialog, response_id);
   }
+  
+  self->priv->current_response = GTK_RESPONSE_NONE;
+}
+
+static void
+nw_progress_dialog_before_response (NwProgressDialog *self,
+                                    gint              response)
+{
+  /* track currently emitted response to implement
+   * nw_progress_dialog_emit_response().  reset in
+   * nw_progress_dialog_response() */
+  self->priv->current_response = response;
 }
 
 static void
@@ -175,6 +188,7 @@ nw_progress_dialog_init (NwProgressDialog *self)
   self->priv->finished = FALSE;
   self->priv->canceled = FALSE;
   self->priv->auto_hide_action_area = FALSE;
+  self->priv->current_response = GTK_RESPONSE_NONE;
   
   gtk_container_set_border_width (GTK_CONTAINER (self), 5);
   content_area = gtk_dialog_get_content_area (GTK_DIALOG (self));
@@ -189,6 +203,9 @@ nw_progress_dialog_init (NwProgressDialog *self)
   gtk_widget_show (GTK_WIDGET (self->priv->progress));
   
   update_action_area_visibility (self, FALSE);
+  
+  g_signal_connect (self, "response",
+                    G_CALLBACK (nw_progress_dialog_before_response), NULL);
 }
 
 static void
@@ -256,6 +273,21 @@ nw_progress_dialog_class_init (NwProgressDialogClass *klass)
   g_type_class_add_private (klass, sizeof (NwProgressDialogPrivate));
 }
 
+/*
+ * Calls gtk_dialog_response() if not currently inside the emission chain of
+ * the same response.  This is useful in setters that want to emit the response
+ * signal to notify calling code, yet not when called from inside a response
+ * handler for this very response.
+ */
+static void
+nw_progress_dialog_emit_response (NwProgressDialog *self,
+                                  gint              response)
+{
+  if (self->priv->current_response != response) {
+    gtk_dialog_response (GTK_DIALOG (self), response);
+  }
+}
+
 
 /**
  * nw_progress_dialog_new:
@@ -484,7 +516,7 @@ nw_progress_dialog_cancel (NwProgressDialog *dialog)
     dialog->priv->canceled = TRUE;
     gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL,
                                        dialog->priv->canceled);
-    gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+    nw_progress_dialog_emit_response (dialog, GTK_RESPONSE_CANCEL);
   }
 }
 
@@ -516,8 +548,8 @@ nw_progress_dialog_finish (NwProgressDialog *dialog,
   }
   gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL,
                                      FALSE);
-  gtk_dialog_response (GTK_DIALOG (dialog),
-                       NW_PROGRESS_DIALOG_RESPONSE_COMPLETE);
+  nw_progress_dialog_emit_response (dialog,
+                                    NW_PROGRESS_DIALOG_RESPONSE_COMPLETE);
 }
 
 /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/nautilus-wipe.git



More information about the Pkg-privacy-commits mailing list