[tracker] TrackerDecorator: Avoid code duplication



commit 8efa92877cd402c219eda05fb7250623c78bc449
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Mon Jan 27 18:34:00 2014 -0500

    TrackerDecorator: Avoid code duplication
    
    query_append_rdf_type_filter() was copy/pasted in 2 modules,
    better share one internal function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719802

 src/libtracker-miner/Makefile.am                  |    1 +
 src/libtracker-miner/tracker-decorator-fs.c       |   29 +-----------------
 src/libtracker-miner/tracker-decorator-internal.h |   32 +++++++++++++++++++++
 src/libtracker-miner/tracker-decorator.c          |    9 +++--
 4 files changed, 40 insertions(+), 31 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 500140b..7a5b457 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -57,6 +57,7 @@ miner_sources =                                      \
        $(libtracker_miner_monitor_headers)            \
        tracker-decorator.c                            \
        tracker-decorator.h                            \
+       tracker-decorator-internal.h                   \
        tracker-decorator-fs.c                         \
        tracker-decorator-fs.h                         \
        tracker-miner-dbus.h                           \
diff --git a/src/libtracker-miner/tracker-decorator-fs.c b/src/libtracker-miner/tracker-decorator-fs.c
index ac8265d..8812aaa 100644
--- a/src/libtracker-miner/tracker-decorator-fs.c
+++ b/src/libtracker-miner/tracker-decorator-fs.c
@@ -24,6 +24,7 @@
 #include <libtracker-miner/tracker-storage.h>
 
 #include "tracker-decorator-fs.h"
+#include "tracker-decorator-internal.h"
 
 #define TRACKER_DECORATOR_FS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_DECORATOR_FS, 
TrackerDecoratorFSPrivate))
 
@@ -128,32 +129,6 @@ remove_files_cb (GObject *object,
 }
 
 static void
-query_append_rdf_type_filter (GString          *query,
-                              TrackerDecorator *decorator)
-{
-       const gchar **class_names;
-       gint i = 0;
-
-       class_names = tracker_decorator_get_class_names (decorator);
-
-       if (!class_names || !*class_names)
-               return;
-
-       g_string_append (query, "&& (");
-
-       while (class_names[i]) {
-               if (i != 0)
-                       g_string_append (query, "||");
-
-               g_string_append_printf (query, "EXISTS { ?urn a %s }",
-                                       class_names[i]);
-               i++;
-       }
-
-       g_string_append (query, ") ");
-}
-
-static void
 check_files (TrackerDecorator    *decorator,
              const gchar         *mount_point_urn,
              gboolean             available,
@@ -177,7 +152,7 @@ check_files (TrackerDecorator    *decorator,
                                "FILTER (! EXISTS { ?urn nie:dataSource <%s> } ",
                                data_source);
 
-       query_append_rdf_type_filter (query, decorator);
+       _tracker_decorator_query_append_rdf_type_filter (decorator, query);
 
        if (available)
                g_string_append (query, "&& BOUND(tracker:available(?urn))");
diff --git a/src/libtracker-miner/tracker-decorator-internal.h 
b/src/libtracker-miner/tracker-decorator-internal.h
new file mode 100644
index 0000000..e3fd2ef
--- /dev/null
+++ b/src/libtracker-miner/tracker-decorator-internal.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014 Carlos Garnacho  <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_MINER_DECORATOR_INTERNAL_H__
+#define __LIBTRACKER_MINER_DECORATOR_INTERNAL_H__
+
+#include "tracker-decorator.h"
+
+G_BEGIN_DECLS
+
+void _tracker_decorator_query_append_rdf_type_filter (TrackerDecorator *decorator,
+                                                      GString          *query);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_MINER_DECORATOR_INTERNAL_H__ */
diff --git a/src/libtracker-miner/tracker-decorator.c b/src/libtracker-miner/tracker-decorator.c
index 9a8e7b6..b45eeb8 100644
--- a/src/libtracker-miner/tracker-decorator.c
+++ b/src/libtracker-miner/tracker-decorator.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "tracker-decorator.h"
+#include "tracker-decorator-internal.h"
 
 #define QUERY_BATCH_SIZE 100
 #define DEFAULT_BATCH_SIZE 100
@@ -736,9 +737,9 @@ tracker_decorator_finalize (GObject *object)
        G_OBJECT_CLASS (tracker_decorator_parent_class)->finalize (object);
 }
 
-static void
-query_append_rdf_type_filter (GString          *query,
-                              TrackerDecorator *decorator)
+void
+_tracker_decorator_query_append_rdf_type_filter (TrackerDecorator *decorator,
+                                                 GString          *query)
 {
        const gchar **class_names;
        gint i = 0;
@@ -836,7 +837,7 @@ tracker_decorator_started (TrackerMiner *miner)
                                "FILTER (! EXISTS { ?urn nie:dataSource <%s> } ",
                                data_source);
 
-       query_append_rdf_type_filter (query, decorator);
+       _tracker_decorator_query_append_rdf_type_filter (decorator, query);
        g_string_append (query, "&& BOUND(tracker:available(?urn)))}");
 
        sparql_conn = tracker_miner_get_connection (miner);


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