[nautilus/gnome-3-6] search: simplify setting NautilusQuery



commit 636cab3274f5c55e3dc10f0d059a6a9a3709699c
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Sep 28 11:24:09 2012 -0400

    search: simplify setting NautilusQuery
    
    Assume we have a valid query object passed to
    nautilus_search_engine_set_query(), as that is always true in the
    current code.

 libnautilus-private/nautilus-search-directory.c    |   10 ++--------
 libnautilus-private/nautilus-search-engine-model.c |   13 +++----------
 .../nautilus-search-engine-simple.c                |   20 +++-----------------
 .../nautilus-search-engine-tracker.c               |   13 ++-----------
 libnautilus-private/nautilus-search-provider.c     |    1 +
 5 files changed, 11 insertions(+), 46 deletions(-)
---
diff --git a/libnautilus-private/nautilus-search-directory.c b/libnautilus-private/nautilus-search-directory.c
index c1c3ca0..c585605 100644
--- a/libnautilus-private/nautilus-search-directory.c
+++ b/libnautilus-private/nautilus-search-directory.c
@@ -763,10 +763,7 @@ search_dispose (GObject *object)
 		search->details->pending_callback_list = NULL;
 	}
 
-	if (search->details->query) {
-		g_object_unref (search->details->query);
-		search->details->query = NULL;
-	}
+	g_clear_object (&search->details->query);
 
 	if (search->details->engine) {
 		if (search->details->search_running) {
@@ -904,10 +901,7 @@ nautilus_search_directory_set_query (NautilusSearchDirectory *search,
 	if (search->details->query != query) {
 		search->details->modified = TRUE;
 
-		if (query) {
-			g_object_ref (query);
-		}
-
+		g_object_ref (query);
 		g_clear_object (&search->details->query);
 		search->details->query = query;
 
diff --git a/libnautilus-private/nautilus-search-engine-model.c b/libnautilus-private/nautilus-search-engine-model.c
index 73fc629..dadfe3a 100644
--- a/libnautilus-private/nautilus-search-engine-model.c
+++ b/libnautilus-private/nautilus-search-engine-model.c
@@ -151,8 +151,7 @@ nautilus_search_engine_model_start (NautilusSearchProvider *provider)
 		return;
 	}
 
-	if (model->details->query == NULL ||
-	    model->details->directory == NULL) {
+	if (model->details->directory == NULL) {
 		g_idle_add (emit_finished_idle_cb, model);
 		return;
 	}
@@ -187,14 +186,8 @@ nautilus_search_engine_model_set_query (NautilusSearchProvider *provider,
 
 	model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
 
-	if (query) {
-		g_object_ref (query);
-	}
-
-	if (model->details->query) {
-		g_object_unref (model->details->query);
-	}
-
+	g_object_ref (query);
+	g_clear_object (&model->details->query);
 	model->details->query = query;
 }
 
diff --git a/libnautilus-private/nautilus-search-engine-simple.c b/libnautilus-private/nautilus-search-engine-simple.c
index 8629a8a..7ee4917 100644
--- a/libnautilus-private/nautilus-search-engine-simple.c
+++ b/libnautilus-private/nautilus-search-engine-simple.c
@@ -81,11 +81,7 @@ finalize (GObject *object)
 	NautilusSearchEngineSimple *simple;
 
 	simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
-	
-	if (simple->details->query) {
-		g_object_unref (simple->details->query);
-		simple->details->query = NULL;
-	}
+	g_clear_object (&simple->details->query);
 
 	G_OBJECT_CLASS (nautilus_search_engine_simple_parent_class)->finalize (object);
 }
@@ -358,10 +354,6 @@ nautilus_search_engine_simple_start (NautilusSearchProvider *provider)
 	if (simple->details->active_search != NULL) {
 		return;
 	}
-
-	if (simple->details->query == NULL) {
-		return;
-	}
 	
 	data = search_thread_data_new (simple, simple->details->query);
 
@@ -392,14 +384,8 @@ nautilus_search_engine_simple_set_query (NautilusSearchProvider *provider,
 
 	simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
 
-	if (query) {
-		g_object_ref (query);
-	}
-
-	if (simple->details->query) {
-		g_object_unref (simple->details->query);
-	}
-
+	g_object_ref (query);
+	g_clear_object (&simple->details->query);
 	simple->details->query = query;
 }
 
diff --git a/libnautilus-private/nautilus-search-engine-tracker.c b/libnautilus-private/nautilus-search-engine-tracker.c
index 7b2c949..1f7d60d 100644
--- a/libnautilus-private/nautilus-search-engine-tracker.c
+++ b/libnautilus-private/nautilus-search-engine-tracker.c
@@ -227,9 +227,6 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
 		return;
 	}
 
-	if (tracker->details->query == NULL) {
-		return;
-	}
 
 	query_text = nautilus_query_get_text (tracker->details->query);
 	downcase = g_utf8_strdown (query_text, -1);
@@ -314,14 +311,8 @@ nautilus_search_engine_tracker_set_query (NautilusSearchProvider *provider,
 
 	tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
 
-	if (query) {
-		g_object_ref (query);
-	}
-
-	if (tracker->details->query) {
-		g_object_unref (tracker->details->query);
-	}
-
+	g_object_ref (query);
+	g_clear_object (&tracker->details->query);
 	tracker->details->query = query;
 }
 
diff --git a/libnautilus-private/nautilus-search-provider.c b/libnautilus-private/nautilus-search-provider.c
index 71fbb57..6d21906 100644
--- a/libnautilus-private/nautilus-search-provider.c
+++ b/libnautilus-private/nautilus-search-provider.c
@@ -115,6 +115,7 @@ nautilus_search_provider_set_query (NautilusSearchProvider *provider, NautilusQu
 {
 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
 	g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query != NULL);
+	g_return_if_fail (NAUTILUS_IS_QUERY (query));
 
 	NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query (provider, query);
 }



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