[gnome-documents] Move some tracker helpers to gd-miner-tracker.c
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] Move some tracker helpers to gd-miner-tracker.c
- Date: Tue, 7 Aug 2012 17:46:04 +0000 (UTC)
commit 9482646b58a0c6ad8ab125853810e7d555ec4516
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Aug 1 14:35:57 2012 -0300
Move some tracker helpers to gd-miner-tracker.c
Remove the amount of code duplication here.
https://bugzilla.gnome.org/show_bug.cgi?id=681028
src/miner/gd-gdata-miner.c | 145 +++---------------------------------------
src/miner/gd-miner-tracker.c | 126 ++++++++++++++++++++++++++++++++++++
src/miner/gd-miner-tracker.h | 12 ++++
src/miner/gd-zpj-miner.c | 99 +----------------------------
4 files changed, 148 insertions(+), 234 deletions(-)
---
diff --git a/src/miner/gd-gdata-miner.c b/src/miner/gd-gdata-miner.c
index 836d499..4fd258d 100644
--- a/src/miner/gd-gdata-miner.c
+++ b/src/miner/gd-gdata-miner.c
@@ -44,133 +44,6 @@ struct _GdGDataMinerPrivate {
GList *pending_jobs;
};
-static gboolean
-_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connection,
- GCancellable *cancellable,
- GError **error,
- const gchar *resource,
- gboolean favorite)
-{
- GString *update;
- const gchar *op_str = NULL;
- gboolean retval = TRUE;
-
- if (favorite)
- op_str = "INSERT OR REPLACE";
- else
- op_str = "DELETE";
-
- update = g_string_new (NULL);
- g_string_append_printf
- (update,
- "%s { <%s> nao:hasTag nao:predefined-tag-favorite }",
- op_str, resource);
-
- g_debug ("Toggle favorite: query %s", update->str);
-
- tracker_sparql_connection_update (connection, update->str,
- G_PRIORITY_DEFAULT, cancellable,
- error);
-
- g_string_free (update, TRUE);
-
- if (*error != NULL)
- retval = FALSE;
-
- return retval;
-}
-
-static gchar*
-_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
- GCancellable *cancellable,
- GError **error,
- const gchar *email,
- const gchar *fullname)
-{
- GString *select, *insert;
- TrackerSparqlCursor *cursor = NULL;
- gchar *retval = NULL, *mail_uri = NULL;
- gboolean res;
- GVariant *insert_res;
- GVariantIter *iter;
- gchar *key = NULL, *val = NULL;
-
- mail_uri = g_strconcat ("mailto:", email, NULL);
- select = g_string_new (NULL);
- g_string_append_printf (select,
- "SELECT ?urn WHERE { ?urn a nco:Contact . "
- "?urn nco:hasEmailAddress ?mail . "
- "FILTER (fn:contains(?mail, \"%s\" )) }", mail_uri);
-
- cursor = tracker_sparql_connection_query (connection,
- select->str,
- cancellable, error);
-
- g_string_free (select, TRUE);
-
- if (*error != NULL)
- goto out;
-
- res = tracker_sparql_cursor_next (cursor, cancellable, error);
-
- if (*error != NULL)
- goto out;
-
- if (res)
- {
- /* return the found resource */
- retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
- g_debug ("Found resource in the store: %s", retval);
- goto out;
- }
-
- /* not found, create the resource */
- insert = g_string_new (NULL);
-
- g_string_append_printf (insert,
- "INSERT { <%s> a nco:EmailAddress ; nco:emailAddress \"%s\" . "
- "_:res a nco:Contact ; nco:hasEmailAddress <%s> ; nco:fullname \"%s\" . }",
- mail_uri, email,
- mail_uri, fullname);
-
- insert_res =
- tracker_sparql_connection_update_blank (connection, insert->str,
- G_PRIORITY_DEFAULT, cancellable, error);
-
- g_string_free (insert, TRUE);
-
- if (*error != NULL)
- goto out;
-
- /* the result is an "aaa{ss}" variant */
- g_variant_get (insert_res, "aaa{ss}", &iter);
- g_variant_iter_next (iter, "aa{ss}", &iter);
- g_variant_iter_next (iter, "a{ss}", &iter);
- g_variant_iter_next (iter, "{ss}", &key, &val);
-
- g_variant_iter_free (iter);
- g_variant_unref (insert_res);
-
- if (g_strcmp0 (key, "res") == 0)
- {
- retval = val;
- }
- else
- {
- g_free (val);
- goto out;
- }
-
- g_debug ("Created a new contact resource: %s", retval);
-
- out:
- g_clear_object (&cursor);
- g_free (mail_uri);
-
- return retval;
-}
-
-
typedef struct {
GdGDataMiner *self;
TrackerSparqlConnection *connection; /* borrowed from GdGDataMiner */
@@ -410,7 +283,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
}
}
- _tracker_sparql_connection_toggle_favorite
+ gd_miner_tracker_sparql_connection_toggle_favorite
(job->connection,
job->cancellable, error,
resource, starred);
@@ -443,10 +316,10 @@ account_miner_job_process_entry (AccountMinerJob *job,
author = l->data;
- contact_resource = _tracker_utils_ensure_contact_resource (job->connection,
- job->cancellable, error,
- gdata_author_get_email_address (author),
- gdata_author_get_name (author));
+ contact_resource = gd_miner_tracker_utils_ensure_contact_resource (job->connection,
+ job->cancellable, error,
+ gdata_author_get_email_address (author),
+ gdata_author_get_name (author));
if (*error != NULL)
goto out;
@@ -488,10 +361,10 @@ account_miner_job_process_entry (AccountMinerJob *job,
if (g_strcmp0 (scope_type, GDATA_ACCESS_SCOPE_DOMAIN) == 0)
continue;
- contact_resource = _tracker_utils_ensure_contact_resource (job->connection,
- job->cancellable, error,
- scope_value,
- "");
+ contact_resource = gd_miner_tracker_utils_ensure_contact_resource (job->connection,
+ job->cancellable, error,
+ scope_value,
+ "");
gd_miner_tracker_sparql_connection_insert_or_replace_triple
(job->connection,
diff --git a/src/miner/gd-miner-tracker.c b/src/miner/gd-miner-tracker.c
index 7d2e305..3a94657 100644
--- a/src/miner/gd-miner-tracker.c
+++ b/src/miner/gd-miner-tracker.c
@@ -206,3 +206,129 @@ gd_miner_tracker_sparql_connection_set_triple (TrackerSparqlConnection *connecti
out:
return retval;
}
+
+gboolean
+gd_miner_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *resource,
+ gboolean favorite)
+{
+ GString *update;
+ const gchar *op_str = NULL;
+ gboolean retval = TRUE;
+
+ if (favorite)
+ op_str = "INSERT OR REPLACE";
+ else
+ op_str = "DELETE";
+
+ update = g_string_new (NULL);
+ g_string_append_printf
+ (update,
+ "%s { <%s> nao:hasTag nao:predefined-tag-favorite }",
+ op_str, resource);
+
+ g_debug ("Toggle favorite: query %s", update->str);
+
+ tracker_sparql_connection_update (connection, update->str,
+ G_PRIORITY_DEFAULT, cancellable,
+ error);
+
+ g_string_free (update, TRUE);
+
+ if (*error != NULL)
+ retval = FALSE;
+
+ return retval;
+}
+
+gchar*
+gd_miner_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *email,
+ const gchar *fullname)
+{
+ GString *select, *insert;
+ TrackerSparqlCursor *cursor = NULL;
+ gchar *retval = NULL, *mail_uri = NULL;
+ gboolean res;
+ GVariant *insert_res;
+ GVariantIter *iter;
+ gchar *key = NULL, *val = NULL;
+
+ mail_uri = g_strconcat ("mailto:", email, NULL);
+ select = g_string_new (NULL);
+ g_string_append_printf (select,
+ "SELECT ?urn WHERE { ?urn a nco:Contact . "
+ "?urn nco:hasEmailAddress ?mail . "
+ "FILTER (fn:contains(?mail, \"%s\" )) }", mail_uri);
+
+ cursor = tracker_sparql_connection_query (connection,
+ select->str,
+ cancellable, error);
+
+ g_string_free (select, TRUE);
+
+ if (*error != NULL)
+ goto out;
+
+ res = tracker_sparql_cursor_next (cursor, cancellable, error);
+
+ if (*error != NULL)
+ goto out;
+
+ if (res)
+ {
+ /* return the found resource */
+ retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+ g_debug ("Found resource in the store: %s", retval);
+ goto out;
+ }
+
+ /* not found, create the resource */
+ insert = g_string_new (NULL);
+
+ g_string_append_printf (insert,
+ "INSERT { <%s> a nco:EmailAddress ; nco:emailAddress \"%s\" . "
+ "_:res a nco:Contact ; nco:hasEmailAddress <%s> ; nco:fullname \"%s\" . }",
+ mail_uri, email,
+ mail_uri, fullname);
+
+ insert_res =
+ tracker_sparql_connection_update_blank (connection, insert->str,
+ G_PRIORITY_DEFAULT, cancellable, error);
+
+ g_string_free (insert, TRUE);
+
+ if (*error != NULL)
+ goto out;
+
+ /* the result is an "aaa{ss}" variant */
+ g_variant_get (insert_res, "aaa{ss}", &iter);
+ g_variant_iter_next (iter, "aa{ss}", &iter);
+ g_variant_iter_next (iter, "a{ss}", &iter);
+ g_variant_iter_next (iter, "{ss}", &key, &val);
+
+ g_variant_iter_free (iter);
+ g_variant_unref (insert_res);
+
+ if (g_strcmp0 (key, "res") == 0)
+ {
+ retval = val;
+ }
+ else
+ {
+ g_free (val);
+ goto out;
+ }
+
+ g_debug ("Created a new contact resource: %s", retval);
+
+ out:
+ g_clear_object (&cursor);
+ g_free (mail_uri);
+
+ return retval;
+}
diff --git a/src/miner/gd-miner-tracker.h b/src/miner/gd-miner-tracker.h
index 362caad..878ce85 100644
--- a/src/miner/gd-miner-tracker.h
+++ b/src/miner/gd-miner-tracker.h
@@ -51,6 +51,18 @@ gboolean gd_miner_tracker_sparql_connection_set_triple (TrackerSparqlConnection
const gchar *property_name,
const gchar *property_value);
+gboolean gd_miner_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *resource,
+ gboolean favorite);
+
+gchar* gd_miner_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *email,
+ const gchar *fullname);
+
G_END_DECLS
#endif /* __GD_MINER_TRACKER_H__ */
diff --git a/src/miner/gd-zpj-miner.c b/src/miner/gd-zpj-miner.c
index 1797839..280da22 100644
--- a/src/miner/gd-zpj-miner.c
+++ b/src/miner/gd-zpj-miner.c
@@ -42,103 +42,6 @@ struct _GdZpjMinerPrivate {
GList *pending_jobs;
};
-static gchar*
-_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
- GCancellable *cancellable,
- GError **error,
- const gchar *graph,
- const gchar *fullname)
-{
- GString *select, *insert;
- TrackerSparqlCursor *cursor = NULL;
- gchar *retval = NULL;
- gboolean res;
- GVariant *insert_res;
- GVariantIter *iter;
- gchar *key = NULL, *val = NULL;
-
- select = g_string_new (NULL);
- g_string_append_printf (select,
- "SELECT ?urn WHERE {"
- " GRAPH <%s> {"
- " ?urn a nco:Contact ;"
- " nco:fullname \"%s\" ."
- " }"
- "}",
- graph,
- fullname);
-
- cursor = tracker_sparql_connection_query (connection,
- select->str,
- cancellable, error);
-
- g_string_free (select, TRUE);
-
- if (*error != NULL)
- goto out;
-
- res = tracker_sparql_cursor_next (cursor, cancellable, error);
-
- if (*error != NULL)
- goto out;
-
- if (res)
- {
- /* return the found resource */
- retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
- g_debug ("Found resource in the store: %s", retval);
- goto out;
- }
-
- /* not found, create the resource */
- insert = g_string_new (NULL);
-
- g_string_append_printf (insert,
- "INSERT {"
- " GRAPH <%s> {"
- " _:res a nco:Contact ;"
- " nco:fullname \"%s\" ."
- " }"
- "}",
- graph,
- fullname);
-
- insert_res =
- tracker_sparql_connection_update_blank (connection, insert->str,
- G_PRIORITY_DEFAULT, cancellable, error);
-
- g_string_free (insert, TRUE);
-
- if (*error != NULL)
- goto out;
-
- /* the result is an "aaa{ss}" variant */
- g_variant_get (insert_res, "aaa{ss}", &iter);
- g_variant_iter_next (iter, "aa{ss}", &iter);
- g_variant_iter_next (iter, "a{ss}", &iter);
- g_variant_iter_next (iter, "{ss}", &key, &val);
-
- g_variant_iter_free (iter);
- g_variant_unref (insert_res);
-
- if (g_strcmp0 (key, "res") == 0)
- {
- retval = val;
- }
- else
- {
- g_free (val);
- goto out;
- }
-
- g_debug ("Created a new contact resource: %s", retval);
-
- out:
- g_clear_object (&cursor);
-
- return retval;
-}
-
typedef struct {
GdZpjMiner *self;
TrackerSparqlConnection *connection; /* borrowed from GdZpjMiner */
@@ -368,7 +271,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
if (*error != NULL)
goto out;
- contact_resource = _tracker_utils_ensure_contact_resource
+ contact_resource = gd_miner_tracker_utils_ensure_contact_resource
(job->connection,
job->cancellable, error,
job->datasource_urn, zpj_skydrive_entry_get_from_name (entry));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]