[nautilus/wip/antoniof/gtk4-preparation-step-container-api: 16/20] floating-bar: Drop arbitrary multi-action API




commit 999842ba69d8ba769e31f70268fcaa601365e755
Author: António Fernandes <antoniof gnome org>
Date:   Thu Nov 25 15:12:40 2021 +0000

    floating-bar: Drop arbitrary multi-action API
    
    The only action we need is to stop loading.
    
    The code to cleanup actions relies on GtkContainer API, gone in GTK4.
    
    So, specialize the code on the stop button.

 src/nautilus-files-view.c   |  26 ++++-----
 src/nautilus-floating-bar.c | 130 ++++++++++++++++++++------------------------
 src/nautilus-floating-bar.h |   9 +--
 3 files changed, 73 insertions(+), 92 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 7a389c127..da291b81d 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -399,7 +399,7 @@ remove_loading_floating_bar (NautilusFilesView *view)
     }
 
     gtk_widget_hide (priv->floating_bar);
-    nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (priv->floating_bar));
+    nautilus_floating_bar_set_show_stop (NAUTILUS_FLOATING_BAR (priv->floating_bar), FALSE);
 }
 
 static void
@@ -409,14 +409,11 @@ real_setup_loading_floating_bar (NautilusFilesView *view)
 
     priv = nautilus_files_view_get_instance_private (view);
 
-    nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (priv->floating_bar));
     nautilus_floating_bar_set_primary_label (NAUTILUS_FLOATING_BAR (priv->floating_bar),
                                              nautilus_view_is_searching (NAUTILUS_VIEW (view)) ? 
_("Searching…") : _("Loading…"));
     nautilus_floating_bar_set_details_label (NAUTILUS_FLOATING_BAR (priv->floating_bar), NULL);
     nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (priv->floating_bar), priv->loading);
-    nautilus_floating_bar_add_action (NAUTILUS_FLOATING_BAR (priv->floating_bar),
-                                      "process-stop-symbolic",
-                                      NAUTILUS_FLOATING_BAR_ACTION_ID_STOP);
+    nautilus_floating_bar_set_show_stop (NAUTILUS_FLOATING_BAR (priv->floating_bar), priv->loading);
 
     gtk_widget_set_halign (priv->floating_bar, GTK_ALIGN_END);
     gtk_widget_show (priv->floating_bar);
@@ -461,19 +458,15 @@ setup_loading_floating_bar (NautilusFilesView *view)
 }
 
 static void
-floating_bar_action_cb (NautilusFloatingBar *floating_bar,
-                        gint                 action,
-                        NautilusFilesView   *view)
+floating_bar_stop_cb (NautilusFloatingBar *floating_bar,
+                      NautilusFilesView   *view)
 {
     NautilusFilesViewPrivate *priv;
 
     priv = nautilus_files_view_get_instance_private (view);
 
-    if (action == NAUTILUS_FLOATING_BAR_ACTION_ID_STOP)
-    {
-        remove_loading_floating_bar (view);
-        nautilus_window_slot_stop_loading (priv->slot);
-    }
+    remove_loading_floating_bar (view);
+    nautilus_window_slot_stop_loading (priv->slot);
 }
 
 static void
@@ -490,9 +483,10 @@ real_floating_bar_set_short_status (NautilusFilesView *view,
         return;
     }
 
-    nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (priv->floating_bar));
     nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (priv->floating_bar),
                                             FALSE);
+    nautilus_floating_bar_set_show_stop (NAUTILUS_FLOATING_BAR (priv->floating_bar),
+                                         FALSE);
 
     if (primary_status == NULL && detail_status == NULL)
     {
@@ -9944,8 +9938,8 @@ nautilus_files_view_init (NautilusFilesView *view)
     gtk_overlay_add_overlay (GTK_OVERLAY (priv->overlay), priv->floating_bar);
 
     g_signal_connect (priv->floating_bar,
-                      "action",
-                      G_CALLBACK (floating_bar_action_cb),
+                      "stop",
+                      G_CALLBACK (floating_bar_stop_cb),
                       view);
 
     priv->non_ready_files =
diff --git a/src/nautilus-floating-bar.c b/src/nautilus-floating-bar.c
index 973277a27..55a29a52e 100644
--- a/src/nautilus-floating-bar.c
+++ b/src/nautilus-floating-bar.c
@@ -38,6 +38,8 @@ struct _NautilusFloatingBar
     GtkWidget *details_label_widget;
     GtkWidget *spinner;
     gboolean show_spinner;
+    GtkWidget *stop_button;
+    gboolean show_stop;
     gboolean is_interactive;
     guint hover_timeout_id;
 };
@@ -47,12 +49,13 @@ enum
     PROP_PRIMARY_LABEL = 1,
     PROP_DETAILS_LABEL,
     PROP_SHOW_SPINNER,
+    PROP_SHOW_STOP,
     NUM_PROPERTIES
 };
 
 enum
 {
-    ACTION,
+    STOP,
     NUM_SIGNALS
 };
 
@@ -63,15 +66,10 @@ G_DEFINE_TYPE (NautilusFloatingBar, nautilus_floating_bar,
                GTK_TYPE_BOX);
 
 static void
-action_button_clicked_cb (GtkButton           *button,
-                          NautilusFloatingBar *self)
+stop_button_clicked_cb (GtkButton           *button,
+                        NautilusFloatingBar *self)
 {
-    gint action_id;
-
-    action_id = GPOINTER_TO_INT
-                    (g_object_get_data (G_OBJECT (button), "action-id"));
-
-    g_signal_emit (self, signals[ACTION], 0, action_id);
+    g_signal_emit (self, signals[STOP], 0);
 }
 
 static void
@@ -114,6 +112,12 @@ nautilus_floating_bar_get_property (GObject    *object,
         }
         break;
 
+        case PROP_SHOW_STOP:
+        {
+            g_value_set_boolean (value, self->show_stop);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -150,6 +154,12 @@ nautilus_floating_bar_set_property (GObject      *object,
         }
         break;
 
+        case PROP_SHOW_STOP:
+        {
+            nautilus_floating_bar_set_show_stop (self, g_value_get_boolean (value));
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -391,6 +401,7 @@ nautilus_floating_bar_constructed (GObject *obj)
 {
     NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj);
     GtkWidget *w, *box, *labels_box;
+    GtkStyleContext *context;
 
     G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->constructed (obj);
 
@@ -433,6 +444,19 @@ nautilus_floating_bar_constructed (GObject *obj)
     gtk_container_add (GTK_CONTAINER (labels_box), w);
     self->details_label_widget = w;
     gtk_widget_show (w);
+
+    w = gtk_button_new_from_icon_name ("process-stop-symbolic", GTK_ICON_SIZE_MENU);
+    context = gtk_widget_get_style_context (w);
+    gtk_style_context_add_class (context, "circular");
+    gtk_style_context_add_class (context, "flat");
+    gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
+    gtk_container_add (GTK_CONTAINER (self), w);
+    self->stop_button = w;
+    gtk_widget_set_visible (w, FALSE);
+    gtk_widget_set_no_show_all (w, TRUE);
+
+    g_signal_connect (self->stop_button, "clicked",
+                      G_CALLBACK (stop_button_clicked_cb), self);
 }
 
 static void
@@ -479,15 +503,19 @@ nautilus_floating_bar_class_init (NautilusFloatingBarClass *klass)
                               "Whether a spinner should be shown in the floating bar",
                               FALSE,
                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+    properties[PROP_SHOW_STOP] =
+        g_param_spec_boolean ("show-stop",
+                              "Show stop button",
+                              "Whether a stop button should be shown in the floating bar",
+                              FALSE,
+                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
-    signals[ACTION] =
-        g_signal_new ("action",
-                      G_TYPE_FROM_CLASS (klass),
-                      G_SIGNAL_RUN_LAST,
-                      0, NULL, NULL,
-                      g_cclosure_marshal_VOID__INT,
-                      G_TYPE_NONE, 1,
-                      G_TYPE_INT);
+    signals[STOP] = g_signal_new ("stop",
+                                  G_TYPE_FROM_CLASS (klass),
+                                  G_SIGNAL_RUN_LAST,
+                                  0, NULL, NULL,
+                                  g_cclosure_marshal_VOID__VOID,
+                                  G_TYPE_NONE, 0);
 
     g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
 }
@@ -545,6 +573,21 @@ nautilus_floating_bar_set_show_spinner (NautilusFloatingBar *self,
     }
 }
 
+void
+nautilus_floating_bar_set_show_stop (NautilusFloatingBar *self,
+                                     gboolean             show_stop)
+{
+    if (self->show_stop != show_stop)
+    {
+        self->show_stop = show_stop;
+        gtk_widget_set_visible (self->stop_button,
+                                show_stop);
+        self->is_interactive = show_stop;
+
+        g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_STOP]);
+    }
+}
+
 GtkWidget *
 nautilus_floating_bar_new (const gchar *primary_label,
                            const gchar *details_label,
@@ -558,56 +601,3 @@ nautilus_floating_bar_new (const gchar *primary_label,
                          "spacing", 8,
                          NULL);
 }
-
-void
-nautilus_floating_bar_add_action (NautilusFloatingBar *self,
-                                  const gchar         *icon_name,
-                                  gint                 action_id)
-{
-    GtkWidget *button;
-    GtkStyleContext *context;
-
-    button = gtk_button_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
-    context = gtk_widget_get_style_context (button);
-    gtk_style_context_add_class (context, "circular");
-    gtk_style_context_add_class (context, "flat");
-    gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
-    gtk_box_pack_end (GTK_BOX (self), button, FALSE, FALSE, 0);
-    gtk_widget_show (button);
-
-    g_object_set_data (G_OBJECT (button), "action-id",
-                       GINT_TO_POINTER (action_id));
-
-    g_signal_connect (button, "clicked",
-                      G_CALLBACK (action_button_clicked_cb), self);
-
-    self->is_interactive = TRUE;
-}
-
-void
-nautilus_floating_bar_cleanup_actions (NautilusFloatingBar *self)
-{
-    GtkWidget *widget;
-    GList *children, *l;
-    gpointer data;
-
-    children = gtk_container_get_children (GTK_CONTAINER (self));
-    l = children;
-
-    while (l != NULL)
-    {
-        widget = l->data;
-        data = g_object_get_data (G_OBJECT (widget), "action-id");
-        l = l->next;
-
-        if (data != NULL)
-        {
-            /* destroy this */
-            gtk_widget_destroy (widget);
-        }
-    }
-
-    g_list_free (children);
-
-    self->is_interactive = FALSE;
-}
diff --git a/src/nautilus-floating-bar.h b/src/nautilus-floating-bar.h
index 893e1dc1b..61256dad1 100644
--- a/src/nautilus-floating-bar.h
+++ b/src/nautilus-floating-bar.h
@@ -42,10 +42,7 @@ void        nautilus_floating_bar_set_labels        (NautilusFloatingBar *self,
                                                     const gchar *detail);
 void        nautilus_floating_bar_set_show_spinner (NautilusFloatingBar *self,
                                                    gboolean show_spinner);
+void        nautilus_floating_bar_set_show_stop (NautilusFloatingBar *self,
+                                                   gboolean show_spinner);
 
-void        nautilus_floating_bar_add_action       (NautilusFloatingBar *self,
-                                                   const gchar *icon_name,
-                                                   gint action_id);
-void        nautilus_floating_bar_cleanup_actions  (NautilusFloatingBar *self);
-
-void        nautilus_floating_bar_remove_hover_timeout (NautilusFloatingBar *self);
\ No newline at end of file
+void        nautilus_floating_bar_remove_hover_timeout (NautilusFloatingBar *self);


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