[gnome-builder/wip/greeter] doap: add simple doap parser
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/greeter] doap: add simple doap parser
- Date: Sun, 10 May 2015 08:06:52 +0000 (UTC)
commit 4c1ccc642c9381ba68f655f32b6c270879c6dc43
Author: Christian Hergert <christian hergert me>
Date: Sun May 10 01:05:38 2015 -0700
doap: add simple doap parser
libide/Makefile.am | 8 +
libide/doap/ide-doap-person.c | 179 +++++++++++
libide/doap/ide-doap-person.h | 40 +++
libide/doap/ide-doap.c | 604 +++++++++++++++++++++++++++++++++++++
libide/doap/ide-doap.h | 56 ++++
libide/ide-enums.c.in | 1 +
libide/ide.h | 2 +
tests/Makefile.am | 7 +
tests/data/project1/project1.doap | 29 ++
tests/test-ide-doap.c | 76 +++++
10 files changed, 1002 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index b27772c..4e99207 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -37,6 +37,10 @@ libide_1_0_la_public_sources = \
directory/ide-directory-build-system.h \
directory/ide-directory-vcs.c \
directory/ide-directory-vcs.h \
+ doap/ide-doap.c \
+ doap/ide-doap.h \
+ doap/ide-doap-person.c \
+ doap/ide-doap-person.h \
editorconfig/ide-editorconfig-file-settings.c \
editorconfig/ide-editorconfig-file-settings.h \
git/ide-git-remote-callbacks.c \
@@ -316,12 +320,14 @@ libide_1_0_la_includes = \
-I$(top_srcdir)/contrib/egg \
-I$(top_srcdir)/contrib/libeditorconfig \
-I$(top_srcdir)/contrib/search \
+ -I$(top_srcdir)/contrib/xml \
-I$(srcdir) \
-I$(srcdir)/autotools \
-I$(srcdir)/c \
-I$(srcdir)/clang \
-I$(srcdir)/devhelp \
-I$(srcdir)/directory \
+ -I$(srcdir)/doap \
-I$(srcdir)/editorconfig \
-I$(srcdir)/gca \
-I$(srcdir)/git \
@@ -376,6 +382,7 @@ libide_1_0_la_LIBADD = \
$(top_builddir)/contrib/egg/libegg.la \
$(top_builddir)/contrib/libeditorconfig/libeditorconfig.la \
$(top_builddir)/contrib/search/libsearch.la \
+ $(top_builddir)/contrib/xml/libxml.la \
$(NULL)
libide_1_0_la_built_sources = \
@@ -387,6 +394,7 @@ libide_1_0_la_built_sources = \
glib_enum_h = ide-enums.h
glib_enum_c = ide-enums.c
glib_enum_headers = \
+ doap/ide-doap.h \
ide-buffer.h \
ide-diagnostic.h \
ide-highlighter.h \
diff --git a/libide/doap/ide-doap-person.c b/libide/doap/ide-doap-person.c
new file mode 100644
index 0000000..59a3840
--- /dev/null
+++ b/libide/doap/ide-doap-person.c
@@ -0,0 +1,179 @@
+/* ide-doap-person.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "ide-doap-person.h"
+#include "ide-macros.h"
+
+struct _IdeDoapPerson
+{
+ GObject parent_instance;
+
+ gchar *email;
+ gchar *name;
+};
+
+G_DEFINE_TYPE (IdeDoapPerson, ide_doap_person, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_EMAIL,
+ PROP_NAME,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+IdeDoapPerson *
+ide_doap_person_new (void)
+{
+ return g_object_new (IDE_TYPE_DOAP_PERSON, NULL);
+}
+
+const gchar *
+ide_doap_person_get_name (IdeDoapPerson *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP_PERSON (self), NULL);
+
+ return self->name;
+}
+
+void
+ide_doap_person_set_name (IdeDoapPerson *self,
+ const gchar *name)
+{
+ g_return_if_fail (IDE_IS_DOAP_PERSON (self));
+
+ if (!ide_str_equal0 (self->name, name))
+ {
+ g_free (self->name);
+ self->name = g_strdup (name);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_NAME]);
+ }
+}
+
+const gchar *
+ide_doap_person_get_email (IdeDoapPerson *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP_PERSON (self), NULL);
+
+ return self->email;
+}
+
+void
+ide_doap_person_set_email (IdeDoapPerson *self,
+ const gchar *email)
+{
+ g_return_if_fail (IDE_IS_DOAP_PERSON (self));
+
+ if (!ide_str_equal0 (self->email, email))
+ {
+ g_free (self->email);
+ self->email = g_strdup (email);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_EMAIL]);
+ }
+}
+
+static void
+ide_doap_person_finalize (GObject *object)
+{
+ IdeDoapPerson *self = (IdeDoapPerson *)object;
+
+ g_clear_pointer (&self->email, g_free);
+ g_clear_pointer (&self->name, g_free);
+
+ G_OBJECT_CLASS (ide_doap_person_parent_class)->finalize (object);
+}
+
+static void
+ide_doap_person_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeDoapPerson *self = IDE_DOAP_PERSON (object);
+
+ switch (prop_id)
+ {
+ case PROP_EMAIL:
+ g_value_set_string (value, ide_doap_person_get_email (self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string (value, ide_doap_person_get_name (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_doap_person_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeDoapPerson *self = IDE_DOAP_PERSON (object);
+
+ switch (prop_id)
+ {
+ case PROP_EMAIL:
+ ide_doap_person_set_email (self, g_value_get_string (value));
+ break;
+
+ case PROP_NAME:
+ ide_doap_person_set_name (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_doap_person_class_init (IdeDoapPersonClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ide_doap_person_finalize;
+ object_class->get_property = ide_doap_person_get_property;
+ object_class->set_property = ide_doap_person_set_property;
+
+ gParamSpecs [PROP_EMAIL] =
+ g_param_spec_string ("email",
+ _("Email"),
+ _("The email of the person."),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_NAME] =
+ g_param_spec_string ("name",
+ _("Name"),
+ _("The name of the person."),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
+}
+
+static void
+ide_doap_person_init (IdeDoapPerson *self)
+{
+}
diff --git a/libide/doap/ide-doap-person.h b/libide/doap/ide-doap-person.h
new file mode 100644
index 0000000..c5f6439
--- /dev/null
+++ b/libide/doap/ide-doap-person.h
@@ -0,0 +1,40 @@
+/* ide-doap-person.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_DOAP_PERSON_H
+#define IDE_DOAP_PERSON_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_DOAP_PERSON (ide_doap_person_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeDoapPerson, ide_doap_person, IDE, DOAP_PERSON, GObject)
+
+IdeDoapPerson *ide_doap_person_new (void);
+const gchar *ide_doap_person_get_name (IdeDoapPerson *self);
+void ide_doap_person_set_name (IdeDoapPerson *self,
+ const gchar *name);
+const gchar *ide_doap_person_get_email (IdeDoapPerson *self);
+void ide_doap_person_set_email (IdeDoapPerson *self,
+ const gchar *email);
+
+G_END_DECLS
+
+#endif /* IDE_DOAP_PERSON_H */
diff --git a/libide/doap/ide-doap.c b/libide/doap/ide-doap.c
new file mode 100644
index 0000000..8585f5d
--- /dev/null
+++ b/libide/doap/ide-doap.c
@@ -0,0 +1,604 @@
+/* ide-doap.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-doap"
+
+#include <glib/gi18n.h>
+
+#include "ide-doap.h"
+#include "ide-macros.h"
+
+#include "xml-reader.h"
+
+/*
+ * TODO: We don't do any XMLNS checking or anything here.
+ */
+
+struct _IdeDoap
+{
+ GObject parent_instance;
+
+ gchar *bug_database;
+ gchar *category;
+ gchar *description;
+ gchar *download_page;
+ gchar *homepage;;
+ gchar *name;
+ gchar *shortdesc;
+
+ GPtrArray *languages;
+ GList *maintainers;
+};
+
+G_DEFINE_QUARK (ide_doap_error, ide_doap_error)
+G_DEFINE_TYPE (IdeDoap, ide_doap, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_BUG_DATABASE,
+ PROP_CATEGORY,
+ PROP_DESCRIPTION,
+ PROP_DOWNLOAD_PAGE,
+ PROP_HOMEPAGE,
+ PROP_LANGUAGES,
+ PROP_NAME,
+ PROP_SHORTDESC,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+IdeDoap *
+ide_doap_new (void)
+{
+ return g_object_new (IDE_TYPE_DOAP, NULL);
+}
+
+const gchar *
+ide_doap_get_name (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->name;
+}
+
+const gchar *
+ide_doap_get_shortdesc (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->shortdesc;
+}
+
+const gchar *
+ide_doap_get_description (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->description;
+}
+
+const gchar *
+ide_doap_get_bug_database (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->bug_database;
+}
+
+const gchar *
+ide_doap_get_download_page (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->download_page;
+}
+
+const gchar *
+ide_doap_get_homepage (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->homepage;
+}
+
+const gchar *
+ide_doap_get_category (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->category;
+}
+
+/**
+ * ide_doap_get_languages:
+ *
+ * Returns: (transfer none): A #GStrv.
+ */
+gchar **
+ide_doap_get_languages (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ if (self->languages != NULL)
+ return (gchar **)self->languages->pdata;
+
+ return NULL;
+}
+
+static void
+ide_doap_set_bug_database (IdeDoap *self,
+ const gchar *bug_database)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->bug_database, bug_database))
+ {
+ g_free (self->bug_database);
+ self->bug_database = g_strdup (bug_database);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_BUG_DATABASE]);
+ }
+}
+
+static void
+ide_doap_set_category (IdeDoap *self,
+ const gchar *category)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->category, category))
+ {
+ g_free (self->category);
+ self->category = g_strdup (category);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_CATEGORY]);
+ }
+}
+
+static void
+ide_doap_set_description (IdeDoap *self,
+ const gchar *description)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->description, description))
+ {
+ g_free (self->description);
+ self->description = g_strdup (description);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DESCRIPTION]);
+ }
+}
+
+static void
+ide_doap_set_download_page (IdeDoap *self,
+ const gchar *download_page)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->download_page, download_page))
+ {
+ g_free (self->download_page);
+ self->download_page = g_strdup (download_page);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DOWNLOAD_PAGE]);
+ }
+}
+
+static void
+ide_doap_set_homepage (IdeDoap *self,
+ const gchar *homepage)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->homepage, homepage))
+ {
+ g_free (self->homepage);
+ self->homepage = g_strdup (homepage);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_HOMEPAGE]);
+ }
+}
+
+static void
+ide_doap_set_name (IdeDoap *self,
+ const gchar *name)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->name, name))
+ {
+ g_free (self->name);
+ self->name = g_strdup (name);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_NAME]);
+ }
+}
+
+static void
+ide_doap_set_shortdesc (IdeDoap *self,
+ const gchar *shortdesc)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if (!ide_str_equal0 (self->shortdesc, shortdesc))
+ {
+ g_free (self->shortdesc);
+ self->shortdesc = g_strdup (shortdesc);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_SHORTDESC]);
+ }
+}
+
+/**
+ * ide_doap_get_maintainers:
+ *
+ *
+ *
+ * Returns: (transfer none) (element-type IdeDoapPerson*): A #GList of #IdeDoapPerson.
+ */
+GList *
+ide_doap_get_maintainers (IdeDoap *self)
+{
+ g_return_val_if_fail (IDE_IS_DOAP (self), NULL);
+
+ return self->maintainers;
+}
+
+static void
+ide_doap_add_language (IdeDoap *self,
+ const gchar *language)
+{
+ g_return_if_fail (IDE_IS_DOAP (self));
+ g_return_if_fail (language != NULL);
+
+ if (self->languages == NULL)
+ {
+ self->languages = g_ptr_array_new_with_free_func (g_free);
+ g_ptr_array_add (self->languages, NULL);
+ }
+
+ g_assert (self->languages->len > 0);
+
+ g_ptr_array_index (self->languages, self->languages->len - 1) = g_strdup (language);
+ g_ptr_array_add (self->languages, NULL);
+
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_LANGUAGES]);
+}
+
+static void
+ide_doap_set_languages (IdeDoap *self,
+ gchar **languages)
+{
+ gsize i;
+
+ g_return_if_fail (IDE_IS_DOAP (self));
+
+ if ((self->languages != NULL) && (self->languages->len > 0))
+ g_ptr_array_remove_range (self->languages, 0, self->languages->len);
+
+ g_object_freeze_notify (G_OBJECT (self));
+ for (i = 0; languages [i]; i++)
+ ide_doap_add_language (self, languages [i]);
+ g_object_thaw_notify (G_OBJECT (self));
+}
+
+static void
+ide_doap_finalize (GObject *object)
+{
+ IdeDoap *self = (IdeDoap *)object;
+
+ g_clear_pointer (&self->bug_database, g_free);
+ g_clear_pointer (&self->category, g_free);
+ g_clear_pointer (&self->description, g_free);
+ g_clear_pointer (&self->download_page, g_free);
+ g_clear_pointer (&self->homepage, g_free);
+ g_clear_pointer (&self->languages, g_ptr_array_unref);
+ g_clear_pointer (&self->name, g_free);
+ g_clear_pointer (&self->shortdesc, g_free);
+
+ g_list_free_full (self->maintainers, g_object_unref);
+ self->maintainers = NULL;
+
+ G_OBJECT_CLASS (ide_doap_parent_class)->finalize (object);
+}
+
+static void
+ide_doap_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeDoap *self = IDE_DOAP (object);
+
+ switch (prop_id)
+ {
+ case PROP_BUG_DATABASE:
+ g_value_set_string (value, ide_doap_get_bug_database (self));
+ break;
+
+ case PROP_CATEGORY:
+ g_value_set_string (value, ide_doap_get_category (self));
+ break;
+
+ case PROP_DESCRIPTION:
+ g_value_set_string (value, ide_doap_get_description (self));
+ break;
+
+ case PROP_DOWNLOAD_PAGE:
+ g_value_set_string (value, ide_doap_get_download_page (self));
+ break;
+
+ case PROP_HOMEPAGE:
+ g_value_set_string (value, ide_doap_get_homepage (self));
+ break;
+
+ case PROP_LANGUAGES:
+ g_value_set_boxed (value, ide_doap_get_languages (self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string (value, ide_doap_get_name (self));
+ break;
+
+ case PROP_SHORTDESC:
+ g_value_set_string (value, ide_doap_get_shortdesc (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_doap_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeDoap *self = IDE_DOAP (object);
+
+ switch (prop_id)
+ {
+ case PROP_BUG_DATABASE:
+ ide_doap_set_bug_database (self, g_value_get_string (value));
+ break;
+
+ case PROP_CATEGORY:
+ ide_doap_set_category (self, g_value_get_string (value));
+ break;
+
+ case PROP_DESCRIPTION:
+ ide_doap_set_description (self, g_value_get_string (value));
+ break;
+
+ case PROP_DOWNLOAD_PAGE:
+ ide_doap_set_download_page (self, g_value_get_string (value));
+ break;
+
+ case PROP_HOMEPAGE:
+ ide_doap_set_homepage (self, g_value_get_string (value));
+ break;
+
+ case PROP_LANGUAGES:
+ ide_doap_set_languages (self, g_value_get_boxed (value));
+ break;
+
+ case PROP_NAME:
+ ide_doap_set_name (self, g_value_get_string (value));
+ break;
+
+ case PROP_SHORTDESC:
+ ide_doap_set_shortdesc (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_doap_class_init (IdeDoapClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ide_doap_finalize;
+ object_class->get_property = ide_doap_get_property;
+ object_class->set_property = ide_doap_set_property;
+
+ gParamSpecs [PROP_BUG_DATABASE] =
+ g_param_spec_string ("bug-database",
+ _("Bug Database"),
+ _("Bug Database"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_CATEGORY] =
+ g_param_spec_string ("category",
+ _("Category"),
+ _("Category"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_DESCRIPTION] =
+ g_param_spec_string ("description",
+ _("Description"),
+ _("Description"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_DOWNLOAD_PAGE] =
+ g_param_spec_string ("download-page",
+ _("Download Page"),
+ _("Download Page"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_HOMEPAGE] =
+ g_param_spec_string ("homepage",
+ _("Homepage"),
+ _("Homepage"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_LANGUAGES] =
+ g_param_spec_string ("languages",
+ _("Languages"),
+ _("Languages"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_NAME] =
+ g_param_spec_string ("name",
+ _("Name"),
+ _("Name"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gParamSpecs [PROP_SHORTDESC] =
+ g_param_spec_string ("shortdesc",
+ _("Shortdesc"),
+ _("Shortdesc"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
+}
+
+static void
+ide_doap_init (IdeDoap *self)
+{
+}
+
+static gboolean
+ide_doap_parse_maintainer (IdeDoap *self,
+ XmlReader *reader)
+{
+ g_assert (IDE_IS_DOAP (self));
+ g_assert (XML_IS_READER (reader));
+
+ if (!xml_reader_read (reader))
+ return FALSE;
+
+ do
+ {
+ if (xml_reader_is_a_local (reader, "Person") && xml_reader_read (reader))
+ {
+ g_autoptr(IdeDoapPerson) person = ide_doap_person_new ();
+
+ do
+ {
+ if (xml_reader_is_a_local (reader, "name"))
+ {
+ ide_doap_person_set_name (person, xml_reader_read_string (reader));
+ }
+ else if (xml_reader_is_a_local (reader, "mbox"))
+ {
+ gchar *str;
+
+ str = xml_reader_get_attribute (reader, "rdf:resource");
+ if (!ide_str_empty0 (str) && g_str_has_prefix (str, "mailto:"))
+ ide_doap_person_set_email (person, str + strlen ("mailto:"));
+ g_free (str);
+ }
+ }
+ while (xml_reader_read_to_next (reader));
+
+ if (ide_doap_person_get_name (person) || ide_doap_person_get_email (person))
+ self->maintainers = g_list_append (self->maintainers, g_object_ref (person));
+ }
+ }
+ while (xml_reader_read_to_next (reader));
+
+ return TRUE;
+}
+
+gboolean
+ide_doap_load_from_file (IdeDoap *self,
+ GFile *file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(XmlReader) reader = NULL;
+
+ g_return_val_if_fail (IDE_IS_DOAP (self), FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
+
+ reader = xml_reader_new ();
+
+ if (!xml_reader_load_from_file (reader, file, cancellable, error))
+ return FALSE;
+
+ if (!xml_reader_read_start_element (reader, "Project"))
+ {
+ g_set_error (error,
+ IDE_DOAP_ERROR,
+ IDE_DOAP_ERROR_INVALID_FORMAT,
+ "Project element is missing from doap.");
+ return FALSE;
+ }
+
+ g_object_freeze_notify (G_OBJECT (self));
+
+ xml_reader_read (reader);
+
+ do
+ {
+ const gchar *element_name;
+
+ element_name = xml_reader_get_local_name (reader);
+
+ if (ide_str_equal0 (element_name, "name") ||
+ ide_str_equal0 (element_name, "shortdesc") ||
+ ide_str_equal0 (element_name, "description"))
+ {
+ gchar *str;
+
+ str = xml_reader_read_string (reader);
+ if (str != NULL)
+ g_object_set (self, element_name, g_strstrip (str), NULL);
+ g_free (str);
+ }
+ else if (ide_str_equal0 (element_name, "category") ||
+ ide_str_equal0 (element_name, "homepage") ||
+ ide_str_equal0 (element_name, "download-page") ||
+ ide_str_equal0 (element_name, "bug-database"))
+ {
+ gchar *str;
+
+ str = xml_reader_get_attribute (reader, "rdf:resource");
+ if (str != NULL)
+ g_object_set (self, element_name, g_strstrip (str), NULL);
+ g_free (str);
+ }
+ else if (ide_str_equal0 (element_name, "programming-language"))
+ {
+ gchar *str;
+
+ str = xml_reader_read_string (reader);
+ if (!ide_str_empty0 (str))
+ ide_doap_add_language (self, g_strstrip (str));
+ g_free (str);
+ }
+ else if (ide_str_equal0 (element_name, "maintainer"))
+ {
+ if (!ide_doap_parse_maintainer (self, reader))
+ break;
+ }
+ }
+ while (xml_reader_read_to_next (reader));
+
+ g_object_thaw_notify (G_OBJECT (self));
+
+ return TRUE;
+}
diff --git a/libide/doap/ide-doap.h b/libide/doap/ide-doap.h
new file mode 100644
index 0000000..7faa574
--- /dev/null
+++ b/libide/doap/ide-doap.h
@@ -0,0 +1,56 @@
+/* ide-doap.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_DOAP_H
+#define IDE_DOAP_H
+
+#include <gio/gio.h>
+
+#include "ide-doap-person.h"
+
+G_BEGIN_DECLS
+
+#define IDE_DOAP_ERROR (ide_doap_error_quark())
+#define IDE_TYPE_DOAP (ide_doap_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeDoap, ide_doap, IDE, DOAP, GObject)
+
+typedef enum
+{
+ IDE_DOAP_ERROR_INVALID_FORMAT = 1,
+} IdeDoapError;
+
+IdeDoap *ide_doap_new (void);
+GQuark ide_doap_error_quark (void);
+gboolean ide_doap_load_from_file (IdeDoap *self,
+ GFile *file,
+ GCancellable *cancellable,
+ GError **error);
+const gchar *ide_doap_get_name (IdeDoap *self);
+const gchar *ide_doap_get_shortdesc (IdeDoap *self);
+const gchar *ide_doap_get_description (IdeDoap *self);
+const gchar *ide_doap_get_bug_database (IdeDoap *self);
+const gchar *ide_doap_get_download_page (IdeDoap *self);
+const gchar *ide_doap_get_homepage (IdeDoap *self);
+const gchar *ide_doap_get_category (IdeDoap *self);
+gchar **ide_doap_get_languages (IdeDoap *self);
+GList *ide_doap_get_maintainers (IdeDoap *self);
+
+G_END_DECLS
+
+#endif /* IDE_DOAP_H */
diff --git a/libide/ide-enums.c.in b/libide/ide-enums.c.in
index 36e5034..96c780a 100644
--- a/libide/ide-enums.c.in
+++ b/libide/ide-enums.c.in
@@ -7,6 +7,7 @@
#include "ide-buffer.h"
#include "ide-diagnostic.h"
+#include "ide-doap.h"
#include "ide-highlighter.h"
#include "ide-indent-style.h"
#include "ide-source-view.h"
diff --git a/libide/ide.h b/libide/ide.h
index 1679d08..06e5869 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -96,6 +96,8 @@ G_BEGIN_DECLS
#include "devhelp/ide-devhelp-search-result.h"
#include "directory/ide-directory-build-system.h"
#include "directory/ide-directory-vcs.h"
+#include "doap/ide-doap.h"
+#include "doap/ide-doap-person.h"
#include "editorconfig/ide-editorconfig-file-settings.h"
#include "git/ide-git-remote-callbacks.h"
#include "git/ide-git-search-result.h"
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3d8c36e..5be26eb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -47,6 +47,12 @@ test_ide_buffer_CFLAGS = $(tests_cflags)
test_ide_buffer_LDADD = $(tests_libs)
+TESTS += test-ide-doap
+test_ide_doap_SOURCES = test-ide-doap.c
+test_ide_doap_CFLAGS = $(tests_cflags)
+test_ide_doap_LDADD = $(tests_libs)
+
+
TESTS += test-ide-file-settings
test_ide_file_settings_SOURCES = test-ide-file-settings.c
test_ide_file_settings_CFLAGS = $(tests_cflags)
@@ -108,6 +114,7 @@ check_PROGRAMS = $(TESTS) $(misc_programs)
EXTRA_DIST = \
data/project1/configure.ac \
data/project1/.editorconfig \
+ data/project1/project1.doap \
$(NULL)
-include $(top_srcdir)/git.mk
diff --git a/tests/data/project1/project1.doap b/tests/data/project1/project1.doap
new file mode 100644
index 0000000..5a8802d
--- /dev/null
+++ b/tests/data/project1/project1.doap
@@ -0,0 +1,29 @@
+<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns:gnome="http://api.gnome.org/doap-extensions#"
+ xmlns="http://usefulinc.com/ns/doap#">
+
+ <name xml:lang="en">Project One</name>
+ <shortdesc xml:lang="en">
+ Short Description of Project1
+ </shortdesc>
+ <description xml:lang="en">
+ Long Description
+ </description>
+ <homepage rdf:resource="https://example.org/" />
+ <download-page rdf:resource="https://download.example.org/" />
+ <bug-database rdf:resource="https://bugs.example.org/" />
+
+ <category rdf:resource="http://api.gnome.org/doap-extensions#apps" />
+ <programming-language>C</programming-language>
+ <programming-language>JavaScript</programming-language>
+ <programming-language>Python</programming-language>
+
+ <maintainer>
+ <foaf:Person>
+ <foaf:name>Some Name</foaf:name>
+ <foaf:mbox rdf:resource="mailto:example example org" />
+ </foaf:Person>
+ </maintainer>
+</Project>
diff --git a/tests/test-ide-doap.c b/tests/test-ide-doap.c
new file mode 100644
index 0000000..714dd50
--- /dev/null
+++ b/tests/test-ide-doap.c
@@ -0,0 +1,76 @@
+/* test-ide-doap.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ide.h>
+
+static void
+test_load_from_file (void)
+{
+ IdeDoap *doap;
+ GList *list;
+ IdeDoapPerson *person;
+ GError *error = NULL;
+ GFile *file;
+ gboolean ret;
+ gchar **langs;
+
+ doap = ide_doap_new ();
+ g_object_add_weak_pointer (G_OBJECT (doap), (gpointer *)&doap);
+
+ file = g_file_new_for_path (TEST_DATA_DIR"/project1/project1.doap");
+
+ ret = ide_doap_load_from_file (doap, file, NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (ret, ==, TRUE);
+
+ g_assert_cmpstr (ide_doap_get_name (doap), ==, "Project One");
+ g_assert_cmpstr (ide_doap_get_shortdesc (doap), ==, "Short Description of Project1");
+ g_assert_cmpstr (ide_doap_get_description (doap), ==, "Long Description");
+ g_assert_cmpstr (ide_doap_get_homepage (doap), ==, "https://example.org/");
+ g_assert_cmpstr (ide_doap_get_download_page (doap), ==, "https://download.example.org/");
+ g_assert_cmpstr (ide_doap_get_bug_database (doap), ==, "https://bugs.example.org/");
+
+ langs = ide_doap_get_languages (doap);
+ g_assert (langs != NULL);
+ g_assert_cmpstr (langs [0], ==, "C");
+ g_assert_cmpstr (langs [1], ==, "JavaScript");
+ g_assert_cmpstr (langs [2], ==, "Python");
+
+ list = ide_doap_get_maintainers (doap);
+ g_assert (list != NULL);
+ g_assert (list->data != NULL);
+ g_assert (list->next == NULL);
+
+ person = list->data;
+ g_assert_cmpstr (ide_doap_person_get_name (person), ==, "Some Name");
+ g_assert_cmpstr (ide_doap_person_get_email (person), ==, "example example org");
+
+ g_object_unref (doap);
+ g_assert (doap == NULL);
+
+ g_clear_object (&file);
+}
+
+gint
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Ide/Doap/load_from_file", test_load_from_file);
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]