[libgdata] documents: Split out the code to map a content type to a GType



commit 49f3b9d86f6f21bc2414fd18cebbedfa551c29a3
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jun 12 16:04:44 2015 +0200

    documents: Split out the code to map a content type to a GType
    
    We will need this in gdata_documents_service_finish_upload.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 Makefile.am                                      |    2 +
 gdata/services/documents/gdata-documents-feed.c  |   27 +---------
 gdata/services/documents/gdata-documents-utils.c |   64 ++++++++++++++++++++++
 gdata/services/documents/gdata-documents-utils.h |   32 +++++++++++
 4 files changed, 100 insertions(+), 25 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 1944ddd..996a24e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -294,6 +294,7 @@ gdata_documents_headers = \
        gdata/services/documents/gdata-documents-spreadsheet.h  \
        gdata/services/documents/gdata-documents-upload-query.h \
        gdata/services/documents/gdata-documents-access-rule.h
+private_headers += gdata/services/documents/gdata-documents-utils.h
 gdatadocumentsinclude_HEADERS = \
        $(gdata_documents_headers)                              \
        gdata/services/documents/gdata-documents-enums.h
@@ -433,6 +434,7 @@ gdata_sources = \
        gdata/services/documents/gdata-documents-query.c        \
        gdata/services/documents/gdata-documents-upload-query.c \
        gdata/services/documents/gdata-documents-access-rule.c  \
+       gdata/services/documents/gdata-documents-utils.c        \
        \
        gdata/services/picasaweb/gdata-picasaweb-album.c        \
        gdata/services/picasaweb/gdata-picasaweb-query.c        \
diff --git a/gdata/services/documents/gdata-documents-feed.c b/gdata/services/documents/gdata-documents-feed.c
index 2f7324e..98210c4 100644
--- a/gdata/services/documents/gdata-documents-feed.c
+++ b/gdata/services/documents/gdata-documents-feed.c
@@ -40,13 +40,7 @@
 #include <string.h>
 
 #include "gdata-documents-feed.h"
-#include "gdata-documents-entry.h"
-#include "gdata-documents-spreadsheet.h"
-#include "gdata-documents-text.h"
-#include "gdata-documents-presentation.h"
-#include "gdata-documents-folder.h"
-#include "gdata-documents-drawing.h"
-#include "gdata-documents-pdf.h"
+#include "gdata-documents-utils.h"
 #include "gdata-types.h"
 #include "gdata-private.h"
 #include "gdata-service.h"
@@ -177,24 +171,7 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
                        }
 
                        if (g_strcmp0 (kind, "drive#file") == 0) {
-
-                               /* MIME types: https://developers.google.com/drive/web/mime-types */
-
-                               if (g_strcmp0 (mime_type, "application/vnd.google-apps.folder") == 0) {
-                                       entry_type = GDATA_TYPE_DOCUMENTS_FOLDER;
-                               } else if (g_strcmp0 (mime_type, "application/pdf") == 0) {
-                                       entry_type = GDATA_TYPE_DOCUMENTS_PDF;
-                               } else if (g_strcmp0 (mime_type, "application/vnd.google-apps.document") == 
0) {
-                                       entry_type = GDATA_TYPE_DOCUMENTS_TEXT;
-                               } else if (g_strcmp0 (mime_type, "application/vnd.google-apps.drawing") == 0) 
{
-                                       entry_type = GDATA_TYPE_DOCUMENTS_DRAWING;
-                               } else if (g_strcmp0 (mime_type, "application/vnd.google-apps.presentation") 
== 0) {
-                                       entry_type = GDATA_TYPE_DOCUMENTS_PRESENTATION;
-                               } else if (g_strcmp0 (mime_type, "application/vnd.google-apps.spreadsheet") 
== 0) {
-                                       entry_type = GDATA_TYPE_DOCUMENTS_SPREADSHEET;
-                               } else {
-                                       entry_type = GDATA_TYPE_DOCUMENTS_DOCUMENT;
-                               }
+                               entry_type = gdata_documents_utils_get_type_from_content_type (mime_type);
                        } else {
                                g_warning ("%s files are not handled yet", kind);
                        }
diff --git a/gdata/services/documents/gdata-documents-utils.c 
b/gdata/services/documents/gdata-documents-utils.c
new file mode 100644
index 0000000..1f7e44c
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-utils.c
@@ -0,0 +1,64 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Red Hat, Inc. 2015
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * 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"
+#include "gdata-documents-folder.h"
+#include "gdata-documents-drawing.h"
+#include "gdata-documents-pdf.h"
+#include "gdata-documents-utils.h"
+
+/*
+ * gdata_documents_utils_get_type_from_content_type:
+ * @content_type: the content type
+ *
+ * Maps @content_type to a #GType representing a #GDataDocumentsEntry
+ * sub-class.
+ *
+ * Return value: a #GType corresponding to @content_type
+ *
+ * Since: UNRELEASED
+ */
+GType
+gdata_documents_utils_get_type_from_content_type (const gchar *content_type)
+{
+       GType retval;
+
+       /* MIME types: https://developers.google.com/drive/web/mime-types */
+
+       if (g_strcmp0 (content_type, "application/vnd.google-apps.folder") == 0) {
+               retval = GDATA_TYPE_DOCUMENTS_FOLDER;
+       } else if (g_strcmp0 (content_type, "application/pdf") == 0) {
+               retval = GDATA_TYPE_DOCUMENTS_PDF;
+       } else if (g_strcmp0 (content_type, "application/vnd.google-apps.document") == 0) {
+               retval = GDATA_TYPE_DOCUMENTS_TEXT;
+       } else if (g_strcmp0 (content_type, "application/vnd.google-apps.drawing") == 0) {
+               retval = GDATA_TYPE_DOCUMENTS_DRAWING;
+       } else if (g_strcmp0 (content_type, "application/vnd.google-apps.presentation") == 0) {
+               retval = GDATA_TYPE_DOCUMENTS_PRESENTATION;
+       } else if (g_strcmp0 (content_type, "application/vnd.google-apps.spreadsheet") == 0) {
+               retval = GDATA_TYPE_DOCUMENTS_SPREADSHEET;
+       } else {
+               retval = GDATA_TYPE_DOCUMENTS_DOCUMENT;
+       }
+
+       return retval;
+}
diff --git a/gdata/services/documents/gdata-documents-utils.h 
b/gdata/services/documents/gdata-documents-utils.h
new file mode 100644
index 0000000..66a058b
--- /dev/null
+++ b/gdata/services/documents/gdata-documents-utils.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Red Hat, Inc. 2015
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDATA_DOCUMENTS_UTILS_H
+#define GDATA_DOCUMENTS_UTILS_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL GType gdata_documents_utils_get_type_from_content_type (const gchar *content_type);
+
+G_END_DECLS
+
+#endif /* !GDATA_DOCUMENTS_UTILS_H */


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