[nautilus/wip/csoriano/slot-cleanup: 16/16] slot: use location property



commit eb6d31e070135872a4d2e8777312dedd4647d944
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Aug 28 21:11:52 2015 +0200

    slot: use location property
    
    We were using a custom signal that reports the previous
    location and the new one, given that was needed by files-view
    for its bookmarks in the file chooser.
    Previous patch removed that, so now the only client is the application
    which updates the dbus locations available to FileManager dbus.
    
    We want to have some consistency between the handling of the
    views/slots/windows, and we are moving forward to use properties
    instead of signals since makes it clearer and cleaner, and allow
    bindings and other nice things.
    
    For that, match what the view does and expose a location property
    on the slot.
    
    In future, if the window has some client that listen to the current
    viewed location, a property binding to the active slot would do.
    
    In this case, we can't bind the property to the one of the view, since
    there is still some management done on the slot, but this will change
    soon when we move the remaining location management to the view itself.

 src/nautilus-application.c |    9 +++----
 src/nautilus-window-slot.c |   53 ++++++++++++++++---------------------------
 2 files changed, 24 insertions(+), 38 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index a1f3f3f..bb6312c 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1145,10 +1145,9 @@ update_dbus_opened_locations (NautilusApplication *app)
 }
 
 static void
-on_slot_location_changed (NautilusWindowSlot *slot,
-                         const char         *from,
-                         const char         *to,
-                         NautilusApplication *application)
+on_slot_location_changed (NautilusWindowSlot  *slot,
+                          GParamSpec          *pspec,
+                          NautilusApplication *application)
 {
        update_dbus_opened_locations (application);
 }
@@ -1162,7 +1161,7 @@ on_slot_added (NautilusWindow      *window,
                update_dbus_opened_locations (application);
        }
 
-       g_signal_connect (slot, "location-changed", G_CALLBACK (on_slot_location_changed), application);
+       g_signal_connect (slot, "notify::location", G_CALLBACK (on_slot_location_changed), application);
 }
 
 static void
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 4e9becc..e4c2aca 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -53,7 +53,6 @@ G_DEFINE_TYPE (NautilusWindowSlot, nautilus_window_slot, GTK_TYPE_BOX);
 enum {
        ACTIVE,
        INACTIVE,
-       LOCATION_CHANGED,
        LAST_SIGNAL
 };
 
@@ -63,6 +62,7 @@ enum {
         PROP_ICON,
         PROP_VIEW_WIDGET,
        PROP_LOADING,
+        PROP_LOCATION,
        NUM_PROPERTIES
 };
 
@@ -138,7 +138,6 @@ static void hide_query_editor (NautilusWindowSlot *slot);
 static void nautilus_window_slot_sync_actions (NautilusWindowSlot *slot);
 static void nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *slot);
 static void nautilus_window_slot_disconnect_content_view (NautilusWindowSlot *slot);
-static void nautilus_window_slot_emit_location_change (NautilusWindowSlot *slot, GFile *from, GFile *to);
 static gboolean nautilus_window_slot_content_view_matches (NautilusWindowSlot *slot, const char *iid);
 static NautilusView* nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot, GFile *location);
 static void nautilus_window_slot_set_content_view (NautilusWindowSlot *slot, const char        *id);
@@ -146,6 +145,8 @@ static void nautilus_window_slot_set_loading (NautilusWindowSlot *slot, gboolean
 char * nautilus_window_slot_get_location_uri (NautilusWindowSlot *slot);
 static void nautilus_window_slot_set_search_visible (NautilusWindowSlot *slot,
                                                     gboolean            visible);
+static void nautilus_window_slot_set_location (NautilusWindowSlot *slot,
+                                               GFile              *location);
 
 static NautilusView*
 nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot,
@@ -534,6 +535,9 @@ nautilus_window_slot_set_property (GObject *object,
        case PROP_WINDOW:
                nautilus_window_slot_set_window (slot, g_value_get_object (value));
                break;
+       case PROP_LOCATION:
+               nautilus_window_slot_set_location (slot, g_value_get_object (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
@@ -564,6 +568,9 @@ nautilus_window_slot_get_property (GObject *object,
         case PROP_LOADING:
                 g_value_set_boolean (value, nautilus_window_slot_get_loading (slot));
                 break;
+        case PROP_LOCATION:
+                g_value_set_object (value, nautilus_window_slot_get_current_location (slot));
+                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
@@ -906,13 +913,14 @@ nautilus_window_slot_set_location (NautilusWindowSlot *slot,
        }
 
        nautilus_window_slot_update_title (slot);
-       nautilus_window_slot_emit_location_change (slot, old_location, location);
 
         nautilus_query_editor_set_location (slot->details->query_editor, location);
 
        if (old_location) {
                g_object_unref (old_location);
        }
+
+        g_object_notify_by_pspec (G_OBJECT (slot), properties[PROP_LOCATION]);
 }
 
 static void
@@ -1901,23 +1909,6 @@ found_mount_cb (GObject *source_object,
 }
 
 static void
-nautilus_window_slot_emit_location_change (NautilusWindowSlot *slot,
-                                          GFile *from,
-                                          GFile *to)
-{
-       char *from_uri = NULL;
-       char *to_uri = NULL;
-
-       if (from != NULL)
-               from_uri = g_file_get_uri (from);
-       if (to != NULL)
-               to_uri = g_file_get_uri (to);
-       g_signal_emit_by_name (slot, "location-changed", from_uri, to_uri);
-       g_free (to_uri);
-       g_free (from_uri);
-}
-
-static void
 nautilus_window_slot_show_trash_bar (NautilusWindowSlot *slot)
 {
        GtkWidget *bar;
@@ -2311,17 +2302,6 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
                              g_cclosure_marshal_VOID__VOID,
                              G_TYPE_NONE, 0);
 
-       signals[LOCATION_CHANGED] =
-               g_signal_new ("location-changed",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_generic,
-                             G_TYPE_NONE, 2,
-                             G_TYPE_STRING,
-                             G_TYPE_STRING);
-
         properties[PROP_ACTIVE] =
                 g_param_spec_boolean ("active",
                                       "Whether the slot is active",
@@ -2356,6 +2336,13 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
                                     GTK_TYPE_WIDGET,
                                     G_PARAM_READABLE);
 
+        properties[PROP_LOCATION] =
+               g_param_spec_object ("location",
+                                    "Current location visible on the slot",
+                                    "Either the location that is used currently, or the pending location. 
Clients will see the same value they set, and therefore it will be cosistent from clients point of view.",
+                                    G_TYPE_FILE,
+                                    G_PARAM_READWRITE);
+
        g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
        g_type_class_add_private (klass, sizeof (NautilusWindowSlotDetails));
 }
@@ -2406,11 +2393,11 @@ nautilus_window_slot_set_window (NautilusWindowSlot *slot,
 }
 
 /* nautilus_window_slot_update_title:
- * 
+ *
  * Re-calculate the slot title.
  * Called when the location or view has changed.
  * @slot: The NautilusWindowSlot in question.
- * 
+ *
  */
 void
 nautilus_window_slot_update_title (NautilusWindowSlot *slot)


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