[libgdata/wip/rishi/drive: 8/9] Port gdata_documents_service_remove_entry_from_folder to Drive v2



commit dbb51f027bfdb61235e7c2154b85d7b2b4ab5fe3
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Sep 27 20:20:15 2016 +0200

    Port gdata_documents_service_remove_entry_from_folder to Drive v2
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 gdata/services/documents/gdata-documents-service.c |   63 ++++++++++----------
 1 files changed, 31 insertions(+), 32 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-service.c 
b/gdata/services/documents/gdata-documents-service.c
index 2e7b146..cb12ce5 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -1345,10 +1345,10 @@ GDataDocumentsEntry *
 gdata_documents_service_remove_entry_from_folder (GDataDocumentsService *self, GDataDocumentsEntry *entry, 
GDataDocumentsFolder *folder,
                                                   GCancellable *cancellable, GError **error)
 {
-       const gchar *folder_id, *entry_id;
-       SoupMessage *message;
-       guint status;
-       gchar *uri;
+       const gchar *folder_id;
+       GList *i;
+       GList *parent_folders_list;
+       GDataLink *folder_link = NULL;
 
        g_return_val_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self), NULL);
        g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (entry), NULL);
@@ -1363,42 +1363,41 @@ gdata_documents_service_remove_entry_from_folder (GDataDocumentsService *self, G
                return NULL;
        }
 
-       /* Get the document ID */
-       folder_id = gdata_documents_entry_get_resource_id (GDATA_DOCUMENTS_ENTRY (folder));
-       entry_id = gdata_documents_entry_get_resource_id (entry);
+       folder_id = gdata_entry_get_id (GDATA_ENTRY (folder));
        g_assert (folder_id != NULL);
-       g_assert (entry_id != NULL);
 
-       uri = _gdata_service_build_uri ("%s://docs.google.com/feeds/default/private/full/%s/contents/%s", 
_gdata_service_get_scheme (),
-                                       folder_id, entry_id);
-       message = _gdata_service_build_message (GDATA_SERVICE (self), get_documents_authorization_domain (), 
SOUP_METHOD_DELETE, uri,
-                                               gdata_entry_get_etag (GDATA_ENTRY (entry)), TRUE);
-       g_free (uri);
+       parent_folders_list = gdata_entry_look_up_links (GDATA_ENTRY (entry), GDATA_LINK_PARENT);
+       for (i = parent_folders_list; i != NULL; i = i->next) {
+               GDataLink *_link = GDATA_LINK (i->data);
+               const gchar *uri;
+               gsize uri_prefix_len;
 
-       /* Send the message */
-       status = _gdata_service_send_message (GDATA_SERVICE (self), message, cancellable, error);
+               /* HACK: Extract the ID from the GDataLink:uri by removing the prefix. Ignore links which
+                * don't have the prefix. */
+               uri = gdata_link_get_uri (_link);
+               uri_prefix_len = strlen (GDATA_DOCUMENTS_URI_PREFIX);
+               if (g_str_has_prefix (uri, GDATA_DOCUMENTS_URI_PREFIX)) {
+                       const gchar *id;
 
-       if (status == SOUP_STATUS_NONE || status == SOUP_STATUS_CANCELLED) {
-               /* Redirect error or cancelled */
-               g_object_unref (message);
-               return NULL;
-       } else if (status != SOUP_STATUS_OK) {
-               /* Error */
-               GDataServiceClass *klass = GDATA_SERVICE_GET_CLASS (self);
-               g_assert (klass->parse_error_response != NULL);
-               klass->parse_error_response (GDATA_SERVICE (self), GDATA_OPERATION_UPDATE, status, 
message->reason_phrase,
-                                            message->response_body->data, message->response_body->length, 
error);
-               g_object_unref (message);
+                       id = uri + uri_prefix_len;
+                       if (g_strcmp0 (folder_id, id) == 0) {
+                               folder_link = _link;
+                               break;
+                       }
+               }
+       }
+
+       g_list_free (parent_folders_list);
+
+       if (folder_link == NULL) {
+               g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NOT_FOUND, _("Parent 
folder not found"));
                return NULL;
        }
 
-       g_object_unref (message);
+       gdata_entry_remove_link (GDATA_ENTRY (entry), folder_link);
 
-       /* HACK: Google's servers don't return an updated copy of the entry, so we have to query for it again.
-        * See: http://code.google.com/p/gdata-issues/issues/detail?id=1380 */
-       return GDATA_DOCUMENTS_ENTRY (gdata_service_query_single_entry (GDATA_SERVICE (self), 
get_documents_authorization_domain (),
-                                                                       gdata_entry_get_id (GDATA_ENTRY 
(entry)), NULL,
-                                                                       G_OBJECT_TYPE (entry), cancellable, 
error));
+       return GDATA_DOCUMENTS_ENTRY (gdata_service_update_entry (GDATA_SERVICE (self), 
get_documents_authorization_domain (), GDATA_ENTRY (entry),
+                                                                 cancellable, error));
 }
 
 typedef struct {


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