[libgdata] documents: Split out the code to get an ID from a GDataLink
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] documents: Split out the code to get an ID from a GDataLink
- Date: Wed, 9 Aug 2017 09:30:45 +0000 (UTC)
commit d71082cd83f4d2754279f6feb9f16955c495db5c
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Sep 30 11:33:08 2016 +0200
documents: Split out the code to get an ID from a GDataLink
https://bugzilla.gnome.org/show_bug.cgi?id=684920
gdata/services/documents/gdata-documents-entry.c | 30 ++++++-----------
gdata/services/documents/gdata-documents-service.c | 21 +++---------
gdata/services/documents/gdata-documents-utils.c | 34 ++++++++++++++++++++
gdata/services/documents/gdata-documents-utils.h | 2 +
4 files changed, 52 insertions(+), 35 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-entry.c
b/gdata/services/documents/gdata-documents-entry.c
index e3f89c1..5b10964 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -97,7 +97,6 @@
#include <config.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
-#include <string.h>
#include "gdata-documents-entry.h"
#include "gdata-parser.h"
@@ -868,25 +867,16 @@ get_json (GDataParsable *parsable, JsonBuilder *builder)
parent_folders_list = gdata_entry_look_up_links (GDATA_ENTRY (parsable), 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;
-
- /* 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;
-
- id = uri + uri_prefix_len;
- if (id[0] != '\0') {
- json_builder_begin_object (builder);
- json_builder_set_member_name (builder, "kind");
- json_builder_add_string_value (builder, "drive#fileLink");
- json_builder_set_member_name (builder, "id");
- json_builder_add_string_value (builder, id);
- json_builder_end_object (builder);
- }
+ const gchar *id;
+
+ id = gdata_documents_utils_get_id_from_link (_link);
+ if (id != NULL) {
+ json_builder_begin_object (builder);
+ json_builder_set_member_name (builder, "kind");
+ json_builder_add_string_value (builder, "drive#fileLink");
+ json_builder_set_member_name (builder, "id");
+ json_builder_add_string_value (builder, id);
+ json_builder_end_object (builder);
}
}
diff --git a/gdata/services/documents/gdata-documents-service.c
b/gdata/services/documents/gdata-documents-service.c
index d405af0..2e4fc83 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -1070,21 +1070,12 @@ gdata_documents_service_copy_document (GDataDocumentsService *self, GDataDocumen
parent_folders_list = gdata_entry_look_up_links (GDATA_ENTRY (document), 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;
-
- /* 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;
-
- id = uri + uri_prefix_len;
- if (id[0] != '\0') {
- parent_id = id;
- break;
- }
+ const gchar *id;
+
+ id = gdata_documents_utils_get_id_from_link (_link);
+ if (id != NULL) {
+ parent_id = id;
+ break;
}
}
diff --git a/gdata/services/documents/gdata-documents-utils.c
b/gdata/services/documents/gdata-documents-utils.c
index 64aa1ef..f60f71d 100644
--- a/gdata/services/documents/gdata-documents-utils.c
+++ b/gdata/services/documents/gdata-documents-utils.c
@@ -17,6 +17,8 @@
* License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <string.h>
+
#include "gdata-documents-spreadsheet.h"
#include "gdata-documents-text.h"
#include "gdata-documents-presentation.h"
@@ -118,3 +120,35 @@ gdata_documents_utils_get_content_type (GDataDocumentsEntry *entry)
return retval;
}
+
+/*
+ * gdata_documents_utils_get_id_from_link:
+ * @_link: a #GDataLink
+ *
+ * Returns the ID, if any, of the #GDataEntry pointed to by @_link.
+ *
+ * Return value: (nullable): ID of @_link, %NULL otherwise
+ *
+ * Since: UNRELEASED
+ */
+const gchar *
+gdata_documents_utils_get_id_from_link (GDataLink *_link)
+{
+ const gchar *retval = NULL;
+ const gchar *uri;
+
+ /* 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);
+ if (g_str_has_prefix (uri, GDATA_DOCUMENTS_URI_PREFIX)) {
+ const gchar *id;
+ gsize uri_prefix_len;
+
+ uri_prefix_len = strlen (GDATA_DOCUMENTS_URI_PREFIX);
+ id = uri + uri_prefix_len;
+ if (id[0] != '\0')
+ retval = id;
+ }
+
+ return retval;
+}
diff --git a/gdata/services/documents/gdata-documents-utils.h
b/gdata/services/documents/gdata-documents-utils.h
index 2e11bb8..48625d0 100644
--- a/gdata/services/documents/gdata-documents-utils.h
+++ b/gdata/services/documents/gdata-documents-utils.h
@@ -36,6 +36,8 @@ G_GNUC_INTERNAL GType gdata_documents_utils_get_type_from_content_type (const gc
G_GNUC_INTERNAL const gchar *gdata_documents_utils_get_content_type (GDataDocumentsEntry *entry);
+G_GNUC_INTERNAL const gchar *gdata_documents_utils_get_id_from_link (GDataLink *_link);
+
G_END_DECLS
#endif /* !GDATA_DOCUMENTS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]