[gnome-photos] searchbar: Use the more appropriate GAction API



commit 86671fcc4dcbd8ef8bea59420ae0ee7c7b99b6ab
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Aug 18 14:00:14 2017 +0200

    searchbar: Use the more appropriate GAction API
    
    PhotosSearchbar doesn't need to override the default state change
    handling of the GAction. It merely needs to react to it.
    
    Fallout from dbe9070d0cde3f60f7842b1fc9b268fdb50d7a4f
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786936

 src/photos-searchbar.c |   52 +++++++++++++++++++++++++++--------------------
 1 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/src/photos-searchbar.c b/src/photos-searchbar.c
index 054b145..7b9c434 100644
--- a/src/photos-searchbar.c
+++ b/src/photos-searchbar.c
@@ -53,22 +53,6 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosSearchbar, photos_searchbar, GTK_TYPE_SEARCH_B
 
 
 static void
-photos_searchbar_change_state (PhotosSearchbar *self, GVariant *value)
-{
-  PhotosSearchbarPrivate *priv;
-
-  priv = photos_searchbar_get_instance_private (self);
-
-  g_simple_action_set_state (G_SIMPLE_ACTION (priv->search), value);
-
-  if (g_variant_get_boolean (value))
-    photos_searchbar_show (self);
-  else
-    photos_searchbar_hide (self);
-}
-
-
-static void
 photos_searchbar_default_hide (PhotosSearchbar *self)
 {
   PhotosSearchbarPrivate *priv;
@@ -127,12 +111,38 @@ photos_searchbar_search_changed (PhotosSearchbar *self)
 
 
 static void
+photos_searchbar_update_visibility (PhotosSearchbar *self)
+{
+  PhotosSearchbarPrivate *priv;
+  GVariant *state = NULL;
+
+  priv = photos_searchbar_get_instance_private (self);
+
+  state = g_action_get_state (priv->search);
+  g_return_if_fail (state != NULL);
+
+  if (g_variant_get_boolean (state))
+    photos_searchbar_show (self);
+  else
+    photos_searchbar_hide (self);
+
+  g_variant_unref (state);
+}
+
+
+static void
+photos_searchbar_search_notify_state (PhotosSearchbar *self)
+{
+  photos_searchbar_update_visibility (self);
+}
+
+
+static void
 photos_searchbar_constructed (GObject *object)
 {
   PhotosSearchbar *self = PHOTOS_SEARCHBAR (object);
   PhotosSearchbarPrivate *priv;
   GApplication *app;
-  GVariant *state;
 
   priv = photos_searchbar_get_instance_private (self);
 
@@ -161,12 +171,10 @@ photos_searchbar_constructed (GObject *object)
    * dispose.
    */
   priv->search_state_id = g_signal_connect_swapped (priv->search,
-                                                    "change-state",
-                                                    G_CALLBACK (photos_searchbar_change_state),
+                                                    "notify::state",
+                                                    G_CALLBACK (photos_searchbar_search_notify_state),
                                                     self);
-  state = g_action_get_state (priv->search);
-  photos_searchbar_change_state (self, state);
-  g_variant_unref (state);
+  photos_searchbar_update_visibility (self);
 
   gtk_widget_show_all (GTK_WIDGET (self));
 }


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