[libgdata] documents: Split out the code to get the content type of an entry
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] documents: Split out the code to get the content type of an entry
- Date: Mon, 18 Jan 2016 10:17:14 +0000 (UTC)
commit e1036b08a1fecc9cafadb8d788c837cc2bd1f865
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jan 15 18:44:21 2016 +0100
documents: Split out the code to get the content type of an entry
We will need this in gdata_documents_document_get_download_uri.
https://bugzilla.gnome.org/show_bug.cgi?id=759180
gdata/services/documents/gdata-documents-entry.c | 21 +++---------
gdata/services/documents/gdata-documents-utils.c | 37 ++++++++++++++++++++-
gdata/services/documents/gdata-documents-utils.h | 6 +++-
3 files changed, 46 insertions(+), 18 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-entry.c
b/gdata/services/documents/gdata-documents-entry.c
index b1e37d3..ac713b7 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -2,7 +2,7 @@
/*
* GData Client
* Copyright (C) Thibault Saunier 2009 <saunierthibault gmail com>
- * Copyright (C) Red Hat, Inc. 2015
+ * Copyright (C) Red Hat, Inc. 2015, 2016
*
* GData Client is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -816,27 +816,18 @@ get_content_type (void)
static void
get_json (GDataParsable *parsable, JsonBuilder *builder)
{
- GList *categories;
GList *i;
GList *parent_folders_list;
+ const gchar *mime_type;
GDATA_PARSABLE_CLASS (gdata_documents_entry_parent_class)->get_json (parsable, builder);
/* Inserting files: https://developers.google.com/drive/v2/reference/files/insert */
- categories = gdata_entry_get_categories (GDATA_ENTRY (parsable));
- for (i = categories; i != NULL; i = i->next) {
- GDataCategory *category = GDATA_CATEGORY (i->data);
- const gchar *label;
- const gchar *scheme;
-
- label = gdata_category_get_label (category);
- scheme = gdata_category_get_scheme (category);
- if (label != NULL && label[0] != '\0' && g_strcmp0 (scheme,
"http://schemas.google.com/g/2005#kind") == 0) {
- json_builder_set_member_name (builder, "mimeType");
- json_builder_add_string_value (builder, label);
- break;
- }
+ mime_type = gdata_documents_utils_get_content_type (GDATA_DOCUMENTS_ENTRY (parsable));
+ if (mime_type != NULL) {
+ json_builder_set_member_name (builder, "mimeType");
+ json_builder_add_string_value (builder, mime_type);
}
/* Upload to a folder: https://developers.google.com/drive/v2/web/folder */
diff --git a/gdata/services/documents/gdata-documents-utils.c
b/gdata/services/documents/gdata-documents-utils.c
index ed71dac..046b3ec 100644
--- a/gdata/services/documents/gdata-documents-utils.c
+++ b/gdata/services/documents/gdata-documents-utils.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* GData Client
- * Copyright (C) Red Hat, Inc. 2015
+ * Copyright (C) Red Hat, Inc. 2015, 2016
*
* GData Client is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,6 @@
* License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gdata-documents-entry.h"
#include "gdata-documents-spreadsheet.h"
#include "gdata-documents-text.h"
#include "gdata-documents-presentation.h"
@@ -62,3 +61,37 @@ gdata_documents_utils_get_type_from_content_type (const gchar *content_type)
return retval;
}
+
+/*
+ * gdata_documents_utils_get_content_type:
+ * @entry: a #GDataDocumentsEntry
+ *
+ * Returns the content type of @entry, if any.
+ *
+ * Return value: (nullable): content type of @entry, %NULL otherwise
+ *
+ * Since: 0.17.5
+ */
+const gchar *
+gdata_documents_utils_get_content_type (GDataDocumentsEntry *entry)
+{
+ GList *categories;
+ GList *i;
+ const gchar *retval = NULL;
+
+ categories = gdata_entry_get_categories (GDATA_ENTRY (entry));
+ for (i = categories; i != NULL; i = i->next) {
+ GDataCategory *category = GDATA_CATEGORY (i->data);
+ const gchar *label;
+ const gchar *scheme;
+
+ label = gdata_category_get_label (category);
+ scheme = gdata_category_get_scheme (category);
+ if (label != NULL && label[0] != '\0' && g_strcmp0 (scheme,
"http://schemas.google.com/g/2005#kind") == 0) {
+ retval = label;
+ break;
+ }
+ }
+
+ return retval;
+}
diff --git a/gdata/services/documents/gdata-documents-utils.h
b/gdata/services/documents/gdata-documents-utils.h
index 01cc460..a2a4b99 100644
--- a/gdata/services/documents/gdata-documents-utils.h
+++ b/gdata/services/documents/gdata-documents-utils.h
@@ -1,7 +1,7 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* GData Client
- * Copyright (C) Red Hat, Inc. 2015
+ * Copyright (C) Red Hat, Inc. 2015, 2016
*
* GData Client is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,8 @@
#include <glib.h>
#include <glib-object.h>
+#include <gdata/services/documents/gdata-documents-entry.h>
+
G_BEGIN_DECLS
/* HACK: Used to convert GDataLink:uri to ID and vice-versa. */
@@ -30,6 +32,8 @@ G_BEGIN_DECLS
G_GNUC_INTERNAL GType gdata_documents_utils_get_type_from_content_type (const gchar *content_type);
+G_GNUC_INTERNAL const gchar *gdata_documents_utils_get_content_type (GDataDocumentsEntry *entry);
+
G_END_DECLS
#endif /* !GDATA_DOCUMENTS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]