soc.2008.themes: c7606bfd: added a more generic function to read xm...
ffdragon at soc.pidgin.im
ffdragon at soc.pidgin.im
Mon Jun 16 17:45:55 EDT 2008
-----------------------------------------------------------------
Revision: c7606bfdc46d02cea069f8818e3f6d5fb77173e5
Ancestor: 02cf374dc9a8652fab64d8ccc2a51d309b7cf102
Author: ffdragon at soc.pidgin.im
Date: 2008-06-16T21:43:34
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/c7606bfdc46d02cea069f8818e3f6d5fb77173e5
Modified files:
libpurple/sound-loader.c libpurple/util.c
libpurple/xmlnode.c libpurple/xmlnode.h
ChangeLog:
added a more generic function to read xml files (and made the util version into a wrapper) so it can be used by the
theme loaders
-------------- next part --------------
============================================================
--- libpurple/sound-loader.c 7e5730acf1bb24edeed304d9b6c1ff49a4d1d9be
+++ libpurple/sound-loader.c 77164ecb5ed5729c14f4ef8f68b8496ea662a0f6
@@ -43,13 +43,6 @@ static PurpleThemeLoaderClass *parent_cl
#define THEME_EVENT_NAME "name"
#define THEME_EVENT_FILE "file"
-static xmlnode *
-purple_sound_read_xml_from_file(const char *filename)
-{
- return NULL;
-}
-
-
static PurpleSoundTheme *
purple_sound_loader_build(const gchar *dir)
{
@@ -70,7 +63,7 @@ purple_sound_loader_build(const gchar *d
/* Build the xml tree */
filename_full = g_build_filename(dir, filename, NULL);
- root_node = purple_sound_read_xml_from_file(filename_full);
+ root_node = xmlnode_from_file(dir, filename, "sound themes", "sound-loader");
g_return_val_if_fail(root_node != NULL, NULL);
/* Parse the tree */
============================================================
--- libpurple/util.c b58f7c93eaaefceb22a656cd92eef1fd1ec70ab9
+++ libpurple/util.c d9a3cd03db46cd543ce92e5469944d1cbbc7343d
@@ -2750,70 +2750,7 @@ purple_util_read_xml_from_file(const cha
xmlnode *
purple_util_read_xml_from_file(const char *filename, const char *description)
{
- const char *user_dir = purple_user_dir();
- gchar *filename_full;
- GError *error = NULL;
- gchar *contents = NULL;
- gsize length;
- xmlnode *node = NULL;
-
- g_return_val_if_fail(user_dir != NULL, NULL);
-
- purple_debug_info("util", "Reading file %s from directory %s\n",
- filename, user_dir);
-
- filename_full = g_build_filename(user_dir, filename, NULL);
-
- if (!g_file_test(filename_full, G_FILE_TEST_EXISTS))
- {
- purple_debug_info("util", "File %s does not exist (this is not "
- "necessarily an error)\n", filename_full);
- g_free(filename_full);
- return NULL;
- }
-
- if (!g_file_get_contents(filename_full, &contents, &length, &error))
- {
- purple_debug_error("util", "Error reading file %s: %s\n",
- filename_full, error->message);
- g_error_free(error);
- }
-
- if ((contents != NULL) && (length > 0))
- {
- node = xmlnode_from_str(contents, length);
-
- /* If we were unable to parse the file then save its contents to a backup file */
- if (node == NULL)
- {
- gchar *filename_temp;
-
- filename_temp = g_strdup_printf("%s~", filename);
- purple_debug_error("util", "Error parsing file %s. Renaming old "
- "file to %s\n", filename_full, filename_temp);
- purple_util_write_data_to_file(filename_temp, contents, length);
- g_free(filename_temp);
- }
-
- g_free(contents);
- }
-
- /* If we could not parse the file then show the user an error message */
- if (node == NULL)
- {
- gchar *title, *msg;
- title = g_strdup_printf(_("Error Reading %s"), filename);
- msg = g_strdup_printf(_("An error was encountered reading your "
- "%s. They have not been loaded, and the old file "
- "has been renamed to %s~."), description, filename_full);
- purple_notify_error(NULL, NULL, title, msg);
- g_free(title);
- g_free(msg);
- }
-
- g_free(filename_full);
-
- return node;
+ return xmlnode_from_file(purple_user_dir(), filename, description, "util");
}
/*
============================================================
--- libpurple/xmlnode.c efcedf1793b22ae335060f1adc2407dc964f30e0
+++ libpurple/xmlnode.c 83a66bb2505b22aab67fcaf8bba9283db1703e31
@@ -729,6 +729,78 @@ xmlnode *
}
xmlnode *
+xmlnode_from_file(const char *dir, const char *filename, const char *description, const char *process)
+{
+ gchar *filename_full;
+ GError *error = NULL;
+ gchar *contents = NULL;
+ gsize length;
+ xmlnode *node = NULL;
+
+ g_return_val_if_fail(dir != NULL, NULL);
+
+ purple_debug_info(process, "Reading file %s from directory %s\n",
+ filename, dir);
+
+ filename_full = g_build_filename(dir, filename, NULL);
+
+ if (!g_file_test(filename_full, G_FILE_TEST_EXISTS))
+ {
+ purple_debug_info(process, "File %s does not exist (this is not "
+ "necessarily an error)\n", filename_full);
+ g_free(filename_full);
+ return NULL;
+ }
+
+ if (!g_file_get_contents(filename_full, &contents, &length, &error))
+ {
+ purple_debug_error(process, "Error reading file %s: %s\n",
+ filename_full, error->message);
+ g_error_free(error);
+ }
+
+ if ((contents != NULL) && (length > 0))
+ {
+ node = xmlnode_from_str(contents, length);
+
+ /* If we were unable to parse the file then save its contents to a backup file */
+ if (node == NULL)
+ {
+ gchar *filename_temp, *filename_temp_full;
+
+ filename_temp = g_strdup_printf("%s~", filename);
+ filename_temp_full = g_build_filename(dir, filename_temp, NULL);
+
+ purple_debug_error("util", "Error parsing file %s. Renaming old "
+ "file to %s\n", filename_full, filename_temp);
+ purple_util_write_data_to_file_absolute(filename_temp_full, contents, length);
+
+ g_free(filename_temp_full);
+ g_free(filename_temp);
+ }
+
+ g_free(contents);
+ }
+
+ /* If we could not parse the file then show the user an error message */
+ if (node == NULL)
+ {
+ gchar *title, *msg;
+ title = g_strdup_printf(_("Error Reading %s"), filename);
+ msg = g_strdup_printf(_("An error was encountered reading your "
+ "%s. The file has not been loaded, and the old file "
+ "has been renamed to %s~."), description, filename_full);
+ purple_notify_error(NULL, NULL, title, msg);
+ g_free(title);
+ g_free(msg);
+ }
+
+ g_free(filename_full);
+
+ return node;
+}
+
+xmlnode *
xmlnode_copy(const xmlnode *src)
{
xmlnode *ret;
============================================================
--- libpurple/xmlnode.h f73fde22673b21debb1d446f81d715725367b377
+++ libpurple/xmlnode.h 82359d838b91847933034561dd626583d325dfa7
@@ -297,6 +297,20 @@ void xmlnode_free(xmlnode *node);
*/
void xmlnode_free(xmlnode *node);
+/**
+ * Creates a node from a XML File. Calling this on the
+ * root node of an XML document will parse the entire document
+ * into a tree of nodes, and return the xmlnode of the root.
+ *
+ * @param str The string of xml.
+ * @param description The description of the file being parsed
+ * @process The utility that is calling xmlnode_from_file
+ *
+ * @return The new node.
+ */
+xmlnode *xmlnode_from_file(const char *dir, const char *filename,
+ const char *description, const char *process);
+
#ifdef __cplusplus
}
#endif
More information about the Commits
mailing list