[libgdata] documents: update title search to Drive v2



commit 0a92ea82c69d95bef5c3f6664883e551ffb6e792
Author: Alberto Mardegan <alberto mardegan canonical com>
Date:   Mon Nov 23 17:16:13 2015 +0200

    documents: update title search to Drive v2
    
    The title must be passed as part of the "q" parameter.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758524

 gdata/services/documents/gdata-documents-query.c |   37 +++++++++++++++++-----
 1 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-query.c 
b/gdata/services/documents/gdata-documents-query.c
index 38958ce..ab04d36 100644
--- a/gdata/services/documents/gdata-documents-query.c
+++ b/gdata/services/documents/gdata-documents-query.c
@@ -361,17 +361,38 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
        if (priv->show_folders == FALSE)
                _gdata_query_add_q_internal (self, "mimeType!='application/vnd.google-apps.folder'");
 
-       /* Chain up to the parent class */
-       GDATA_QUERY_CLASS (gdata_documents_query_parent_class)->get_query_uri (self, feed_uri, query_uri, 
params_started);
-
        if (priv->title != NULL) {
-               APPEND_SEP
-               g_string_append (query_uri, "title=");
-               g_string_append_uri_escaped (query_uri, priv->title, NULL, FALSE);
-               if (priv->exact_title == TRUE)
-                       g_string_append (query_uri, "&title-exact=true");
+               GString *title_query;
+               const gchar *ptr, *ptr_end;
+
+               title_query = g_string_new ("title");
+               if (priv->exact_title) {
+                       g_string_append_c (title_query, '=');
+               } else {
+                       g_string_append (title_query, " contains ");
+               }
+               g_string_append_c (title_query, '\'');
+
+               for (ptr = priv->title; ptr != NULL; ptr = ptr_end) {
+                       /* Escape any "'" and "\" found in the title with a "\" */
+                       ptr_end = strpbrk (ptr, "\'\\");
+                       if (ptr_end == NULL) {
+                               g_string_append (title_query, ptr);
+                       } else {
+                               g_string_append_len (title_query, ptr, ptr_end - ptr);
+                               g_string_append_c (title_query, '\\');
+                               g_string_append_c (title_query, *ptr_end);
+                       }
+               }
+
+               g_string_append_c (title_query, '\'');
+               _gdata_query_add_q_internal (self, title_query->str);
+               g_string_free (title_query, TRUE);
        }
 
+       /* Chain up to the parent class */
+       GDATA_QUERY_CLASS (gdata_documents_query_parent_class)->get_query_uri (self, feed_uri, query_uri, 
params_started);
+
        /* https://developers.google.com/drive/v2/reference/files/list */
        max_results = gdata_query_get_max_results (self);
        if (max_results > 0) {


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