soc.2008.themes: 383422f1: Added sound builder (implete still needs...

ffdragon at soc.pidgin.im ffdragon at soc.pidgin.im
Fri Jun 13 17:35:48 EDT 2008


-----------------------------------------------------------------
Revision: 383422f1fb5de68d77c6509a220d103faf6b6b1c
Ancestor: b6c5caa5dd6d371b6fb19ed7ee13e7825e8244e6
Author: ffdragon at soc.pidgin.im
Date: 2008-06-13T21:33:17
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/383422f1fb5de68d77c6509a220d103faf6b6b1c

Modified files:
        libpurple/sound-loader.c libpurple/theme-manager.c

ChangeLog: 

Added sound builder (implete still needs a good way to go from xml file to xml node)

-------------- next part --------------
============================================================
--- libpurple/sound-loader.c	2b8893e83b77418c380dfcec99f9a972656dd3f8
+++ libpurple/sound-loader.c	001c8020db062cd7282c3d4f3f066862ac74c911
@@ -22,14 +22,78 @@
  */
 
 #include "sound-loader.h"
+#include "util.h"
+#include "xmlnode.h"
+
 /*****************************************************************************
  * Sound Theme Builder                                                      
  *****************************************************************************/
+#define THEME_SUFFIX		".xml"
+#define THEME_NAME		"name"
+#define THEME_AUTHOR		"author"
+#define THEME_IMAGE		"image"
+#define THEME_DESCRIPTION	"description"
+#define THEME_SOUND_EVENT	"event"
+#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)
 {
-	return NULL; /*TODO: unimplemented*/
+	xmlnode *root_node, *sub_node;
+	gchar *filename, *filename_full, *image, *data;
+	GDir *gdir;
+	PurpleSoundTheme *theme;
+
+	/* Find the theme file */
+	gdir = g_dir_open(dir, 0, NULL);
+	g_return_val_if_fail(gdir != NULL, NULL);
+
+	while ((filename = g_strdup(g_dir_read_name(gdir))) != NULL && ! g_str_has_suffix(filename, THEME_SUFFIX))
+		g_free(filename);
+	
+	g_return_val_if_fail(filename != NULL, NULL);
+	
+	/* Build the xml tree */
+	filename_full = g_build_filename(dir, filename, NULL);
+	
+	root_node = purple_sound_read_xml_from_file(filename_full);
+	g_return_val_if_fail(root_node != NULL, NULL);
+
+	/* Parse the tree */
+	theme = purple_sound_theme_new();
+		
+	purple_theme_set_name(theme->parent, xmlnode_get_attrib(root_node, THEME_NAME));
+	purple_theme_set_author(theme->parent, xmlnode_get_attrib(root_node, THEME_AUTHOR));
+
+	image = g_build_filename(dir, xmlnode_get_attrib(root_node, THEME_IMAGE), NULL);
+	
+	sub_node = xmlnode_get_child(root_node, THEME_DESCRIPTION);
+	data = xmlnode_get_data(sub_node);
+	purple_theme_set_description(theme->parent, data);
+	xmlnode_free(sub_node);
+
+	while ((sub_node = xmlnode_get_child(root_node, THEME_SOUND_EVENT)) != NULL){
+		purple_sound_theme_set_file(theme,
+					    xmlnode_get_attrib(root_node, THEME_EVENT_NAME),
+					    xmlnode_get_attrib(root_node, THEME_EVENT_FILE));
+
+		xmlnode_free(sub_node);
+	}
+
+	xmlnode_free(root_node);	
+	g_dir_close(gdir);
+	g_free(filename_full);
+	g_free(image);
+	g_free(data);
+	return theme;
 }
 
 /******************************************************************************
@@ -37,11 +101,11 @@ static void
  *****************************************************************************/
 
 static void
-purple_sound_theme_loader_class_init (PurpleThemeLoaderClass *klass)
+purple_sound_theme_loader_class_init (PurpleSoundThemeLoaderClass *klass)
 {
-	PurpleThemeLoaderClass *loader_class = PURPLE_THEME_LOADER_CLASS(klass);
+	PurpleSoundThemeLoaderClass *loader_class = PURPLE_SOUND_THEME_LOADER_CLASS(klass);
 	
-	loader_class->_purple_theme_loader_build = purple_sound_loader_build;
+	loader_class->parent_class._purple_theme_loader_build = purple_sound_loader_build;
 }
 
 
============================================================
--- libpurple/theme-manager.c	b8682b52cfbd1080ac8a4976d5d7107c03dea722
+++ libpurple/theme-manager.c	093b3322f71821d8d2cf488f37b44d7d994e86ab
@@ -131,7 +131,7 @@ purple_theme_manager_build(const gchar *
 	/* Parses directory by root/name/purple/type */
 	while ((name = g_strdup(g_dir_read_name (rdir)))){
 		
-		purple_dir = g_strconcat(root, '/', name, '/', "purple", NULL);
+		purple_dir = g_build_filename(root, name, "purple", NULL);
 		dir =  g_dir_open(purple_dir, 0, NULL);	
 	
 		if (dir) {


More information about the Commits mailing list