[nautilus] location-entry: use GFile instead of an uri for last_location
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] location-entry: use GFile instead of an uri for last_location
- Date: Mon, 22 Oct 2012 17:35:17 +0000 (UTC)
commit d09413bcff9b62af6ea58d003ffe2b76c792a57f
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Oct 22 12:43:01 2012 -0400
location-entry: use GFile instead of an uri for last_location
We will create a GFile internally and most of the times we have a GFile
already, so change NautilusLocationEntry to just use a GFile too.
src/nautilus-location-entry.c | 55 ++++++++++++++++++-----------------------
src/nautilus-location-entry.h | 4 +-
src/nautilus-window-menus.c | 6 +++-
src/nautilus-window-private.h | 2 +-
src/nautilus-window.c | 17 +++---------
5 files changed, 37 insertions(+), 47 deletions(-)
---
diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c
index 887f176..e3ff04a 100644
--- a/src/nautilus-location-entry.c
+++ b/src/nautilus-location-entry.c
@@ -74,7 +74,7 @@ struct NautilusLocationEntryDetails {
guint idle_id;
- char *last_uri;
+ GFile *last_location;
gboolean has_special_text;
gboolean setting_special_text;
@@ -130,9 +130,8 @@ nautilus_location_entry_update_action (NautilusLocationEntry *entry)
{
const char *current_text;
GFile *location;
- GFile *last_location;
- if (entry->details->last_uri == NULL){
+ if (entry->details->last_location == NULL){
nautilus_location_entry_set_secondary_action (entry,
NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
return;
@@ -140,9 +139,8 @@ nautilus_location_entry_update_action (NautilusLocationEntry *entry)
current_text = gtk_entry_get_text (GTK_ENTRY (entry));
location = g_file_parse_name (current_text);
- last_location = g_file_parse_name (entry->details->last_uri);
- if (g_file_equal (last_location, location)) {
+ if (g_file_equal (entry->details->last_location, location)) {
nautilus_location_entry_set_secondary_action (entry,
NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR);
} else {
@@ -151,7 +149,6 @@ nautilus_location_entry_update_action (NautilusLocationEntry *entry)
}
g_object_unref (location);
- g_object_unref (last_location);
}
static int
@@ -188,37 +185,35 @@ nautilus_location_entry_update_current_uri (NautilusLocationEntry *entry,
}
void
-nautilus_location_entry_set_uri (NautilusLocationEntry *entry,
- const char *uri)
+nautilus_location_entry_set_location (NautilusLocationEntry *entry,
+ GFile *location)
{
- char *formatted_uri;
- GFile *file;
+ gchar *uri, *formatted_uri;
- g_assert (uri != NULL);
+ g_assert (location != NULL);
/* Note: This is called in reaction to external changes, and
* thus should not emit the LOCATION_CHANGED signal. */
+ uri = g_file_get_uri (location);
+ formatted_uri = g_file_get_parse_name (location);
if (eel_uri_is_search (uri)) {
- nautilus_location_entry_set_special_text (entry,
- "");
+ nautilus_location_entry_set_special_text (entry, "");
} else {
- file = g_file_new_for_uri (uri);
- formatted_uri = g_file_get_parse_name (file);
- g_object_unref (file);
- nautilus_location_entry_update_current_uri (entry,
- formatted_uri);
- g_free (formatted_uri);
+ nautilus_location_entry_update_current_uri (entry, formatted_uri);
}
- /* remember the original uri for later comparison */
-
- if (entry->details->last_uri != uri) {
- g_free (entry->details->last_uri);
- entry->details->last_uri = g_strdup (uri);
+ /* remember the original location for later comparison */
+ if (!entry->details->last_location ||
+ !g_file_equal (entry->details->last_location, location)) {
+ g_clear_object (&entry->details->last_location);
+ entry->details->last_location = g_object_ref (location);
}
nautilus_location_entry_update_action (entry);
+
+ g_free (uri);
+ g_free (formatted_uri);
}
static void
@@ -289,8 +284,10 @@ drag_data_received_callback (GtkWidget *widget,
}
}
- nautilus_location_entry_set_uri (self, names[0]);
+ location = g_file_new_for_uri (names[0]);
+ nautilus_location_entry_set_location (self, location);
emit_location_changed (self);
+ g_object_unref (location);
if (new_windows_for_extras) {
int i;
@@ -511,8 +508,7 @@ finalize (GObject *object)
g_object_unref (entry->details->completer);
g_free (entry->details->special_text);
- g_free (entry->details->last_uri);
- entry->details->last_uri = NULL;
+ g_clear_object (&entry->details->last_location);
G_OBJECT_CLASS (nautilus_location_entry_parent_class)->finalize (object);
}
@@ -609,10 +605,7 @@ nautilus_location_entry_activate (GtkEntry *entry)
static void
nautilus_location_entry_cancel (NautilusLocationEntry *entry)
{
- char *last_uri;
-
- last_uri = entry->details->last_uri;
- nautilus_location_entry_set_uri (entry, last_uri);
+ nautilus_location_entry_set_location (entry, entry->details->last_location);
}
static void
diff --git a/src/nautilus-location-entry.h b/src/nautilus-location-entry.h
index 31e4c29..21e30e9 100644
--- a/src/nautilus-location-entry.h
+++ b/src/nautilus-location-entry.h
@@ -66,8 +66,8 @@ void nautilus_location_entry_set_special_text (NautilusLocationEntry *
const char *special_text);
void nautilus_location_entry_set_secondary_action (NautilusLocationEntry *entry,
NautilusLocationEntryAction secondary_action);
-void nautilus_location_entry_set_uri (NautilusLocationEntry *entry,
- const char *location);
+void nautilus_location_entry_set_location (NautilusLocationEntry *entry,
+ GFile *location);
void nautilus_location_entry_focus (NautilusLocationEntry *entry);
#endif /* NAUTILUS_LOCATION_ENTRY_H */
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 6d19186..0c7b0d0 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -430,7 +430,11 @@ static void
action_prompt_for_location_callback (GtkAction *action,
NautilusWindow *window)
{
- nautilus_window_prompt_for_location (window, "/");
+ GFile *location;
+
+ location = g_file_new_for_path ("/");
+ nautilus_window_prompt_for_location (window, location);
+ g_object_unref (location);
}
static void
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index e908a79..382a160 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -103,7 +103,7 @@ void nautilus_window_set_active_slot (Nautil
NautilusWindowSlot *slot);
void nautilus_window_prompt_for_location (NautilusWindow *window,
- const char *initial);
+ GFile *location);
/* sync window GUI with current slot. Used when changing slots,
* and when updating the slot state.
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index b09bd5e..d7a31c7 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -442,18 +442,15 @@ nautilus_window_sync_allow_stop (NautilusWindow *window,
void
nautilus_window_prompt_for_location (NautilusWindow *window,
- const char *initial)
+ GFile *location)
{
GtkWidget *entry;
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
+ g_return_if_fail (G_IS_FILE (location));
entry = nautilus_window_ensure_location_entry (window);
-
- if (initial) {
- nautilus_location_entry_set_uri (NAUTILUS_LOCATION_ENTRY (entry),
- initial);
- }
+ nautilus_location_entry_set_location (NAUTILUS_LOCATION_ENTRY (entry), location);
}
/* Code should never force the window taller than this size.
@@ -719,17 +716,13 @@ nautilus_window_sync_location_widgets (NautilusWindow *window)
/* Change the location bar and path bar to match the current location. */
if (slot->location != NULL) {
- char *uri;
GtkWidget *location_entry;
GtkWidget *path_bar;
location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->details->toolbar));
- path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->details->toolbar));
+ nautilus_location_entry_set_location (NAUTILUS_LOCATION_ENTRY (location_entry), slot->location);
- /* this may be NULL if we just created the slot */
- uri = nautilus_window_slot_get_location_uri (slot);
- nautilus_location_entry_set_uri (NAUTILUS_LOCATION_ENTRY (location_entry), uri);
- g_free (uri);
+ path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->details->toolbar));
nautilus_path_bar_set_path (NAUTILUS_PATH_BAR (path_bar), slot->location);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]