gtranslator r3572 - trunk/src



Author: psanxiao
Date: Mon May 26 09:59:53 2008
New Revision: 3572
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3572&view=rev

Log:
	* utils.{ch}:
	Added functions gtranslator_xml_new_doc that
	create a new xmlDocPtr from a gchar and
	gtranslator_xml_open_file that open a xml file
	from filename.

	* profile.{ch}:
	Added functions gtranslator_profile_xml_new_entry that
	create a new xml with the values of the gtranslator
	profile object, gtranslator_profile_xml_get_entry that
	obtain the values from the xmlNodePtr and save them into
	gtranslator profile and gtranslator_profile_get_profiles_
	from_xml_file that obtain a list of profiles from a xml file.


Modified:
   trunk/src/ChangeLog
   trunk/src/profile.c
   trunk/src/profile.h
   trunk/src/utils.c
   trunk/src/utils.h

Modified: trunk/src/profile.c
==============================================================================
--- trunk/src/profile.c	(original)
+++ trunk/src/profile.c	Mon May 26 09:59:53 2008
@@ -18,6 +18,7 @@
  
 #include "profile.h"
 #include "preferences-dialog.h"
+#include "utils.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -224,3 +225,98 @@
 		g_free (profile->priv->plurals);
 	profile->priv->plurals = g_strdup (data);
 }
+
+/**
+ * gtranslator_profile_xml_new_entry:
+ * @doc: a #xmlDocPtr.
+ * @profile: a #GtranslatorProfile object.
+ *
+ * This function create a new #xmlNodePtr entry into #xmlDocPtr.
+ *
+ */
+void gtranslator_profile_xml_new_entry (xmlDocPtr doc, GtranslatorProfile *profile)
+{
+	xmlNodePtr root;
+	xmlNodePtr profile_node;
+	
+	root = xmlDocGetRootElement (doc);
+	profile_node = xmlNewChild (root, NULL, "profile", NULL);
+	xmlNewChild (profile_node, NULL, "profile_name", profile->priv->name);
+	xmlNewChild (profile_node, NULL, "author_name", profile->priv->author_name);
+	xmlNewChild (profile_node, NULL, "autor_email", profile->priv->author_email);
+	xmlNewChild (profile_node, NULL, "language_name", profile->priv->language_name);
+	xmlNewChild (profile_node, NULL, "language_code", profile->priv->language_code);
+	xmlNewChild (profile_node, NULL, "charset", profile->priv->charset);
+	xmlNewChild (profile_node, NULL, "encoding", profile->priv->encoding);
+	xmlNewChild (profile_node, NULL, "group_email", profile->priv->group_email);
+	xmlNewChild (profile_node, NULL, "plurals", profile->priv->plurals);
+}
+
+/**
+ * gtranslator_profile_xml_get_entry:
+ * @child: a #xmlNodePtr.
+ *
+ * This function get the values of the #xmlNodePtr and save them into
+ * a #GtranslatorProfile object.
+ *
+ * Returns: a #GtranslatorProfile object.
+ */ 
+GtranslatorProfile *gtranslator_profile_xml_get_entry (xmlNodePtr child)
+{
+  xmlNodePtr node;
+  GtranslatorProfile *profile;
+
+  profile = gtranslator_profile_new ();
+
+  node = child->xmlChildrenNode;
+
+  profile->priv->name = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->author_name = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->author_email = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->language_name = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->language_code = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->charset = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->encoding = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->group_email = xmlNodeGetContent (node);
+  node = node->next;
+  profile->priv->plurals = xmlNodeGetContent (node);
+
+  return profile;
+}
+
+/**
+ * gtranslator_profile_get_profiles_from_xml_file:
+ * @filename: a filename path.
+ *
+ * This function get the profiles saved in a xml file
+ * and return a #GList of #GtranslatorProfile objects.
+ *
+ * returns: a #GList
+ */  
+GList *gtranslator_profile_get_profiles_from_xml_file (gchar *filename)
+{
+  GList *profiles_list = NULL;
+  GtranslatorProfile *profile;
+  xmlNodePtr root, child;
+  xmlDocPtr doc;
+
+  doc = gtranslator_xml_open_file (filename);
+
+  root = xmlDocGetRootElement (doc);
+  child = root->xmlChildrenNode;
+
+  while (child != NULL) {
+    profile = gtranslator_profile_xml_get_entry (child);
+    profiles_list = g_list_append (profiles_list, profile);
+    child = child->next;
+  }
+  
+  return profiles_list;
+}

Modified: trunk/src/profile.h
==============================================================================
--- trunk/src/profile.h	(original)
+++ trunk/src/profile.h	Mon May 26 09:59:53 2008
@@ -21,6 +21,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
+#include <libxml/tree.h>
 
 /*
  * Utility Macros
@@ -94,4 +95,11 @@
 
 gchar 		*gtranslator_profile_get_plurals 	(GtranslatorProfile *profile);
 void 		 gtranslator_profile_set_plurals 	(GtranslatorProfile *profile, gchar *data);
+
+void		gtranslator_profile_xml_new_entry	(xmlDocPtr doc, GtranslatorProfile *profile);
+GtranslatorProfile
+               *gtranslator_profile_xml_get_entry      (xmlNodePtr child);
+
+GList          *gtranslator_profile_get_profiles_from_xml_file   (gchar *filename);
+
 #endif /* __PROFILE_H__ */

Modified: trunk/src/utils.c
==============================================================================
--- trunk/src/utils.c	(original)
+++ trunk/src/utils.c	Mon May 26 09:59:53 2008
@@ -30,6 +30,25 @@
 #include <glade/glade.h>
 #include <gtk/gtk.h>
 
+xmlDocPtr 
+gtranslator_xml_new_doc (const gchar *name) 
+{
+	xmlNodePtr root;
+	xmlDocPtr doc;
+	doc = xmlNewDoc ("1.0");
+	root = xmlNewDocNode (doc, NULL, name, NULL);
+	xmlDocSetRootElement (doc, root);
+	return doc;
+}
+
+xmlDocPtr 
+gtranslator_xml_open_file (const gchar *filename) 
+{
+  xmlDocPtr doc;
+  g_return_if_fail (filename != NULL);
+  doc = xmlParseFile (filename);
+  return doc;
+}
 
 GtkWidget *
 gtranslator_gtk_button_new_with_stock_icon (const gchar *label,

Modified: trunk/src/utils.h
==============================================================================
--- trunk/src/utils.h	(original)
+++ trunk/src/utils.h	Mon May 26 09:59:53 2008
@@ -24,6 +24,11 @@
 #include <gtk/gtkmenu.h>
 #include <gtk/gtkaboutdialog.h>
 #include <gtk/gtkwindow.h>
+#include <libxml/tree.h>
+
+xmlDocPtr      gtranslator_xml_new_doc (const gchar *name);
+
+xmlDocPtr      gtranslator_xml_open_file (const gchar *filename);
 
 GtkWidget     *gtranslator_gtk_button_new_with_stock_icon (const gchar *label,
 				      const gchar *stock_id);



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