GHashTable *
parse_theme(gchar *file){
GHashTable *hash;
- xmlDoc *doc;
- xmlNode *root, *first_child, *node;
+ xmlDoc *doc = NULL;
+ xmlNode *root = NULL, *first_child, *node;
doc = xmlReadFile(file, NULL, 0);
+ if (!doc)
+ return NULL;
root = xmlDocGetRootElement(doc);
+ if (!root)
+ return NULL;
first_child = root->children;
hash = g_hash_table_new(g_str_hash, g_str_equal);
for (node = first_child; node; node = node->next){
// child =
//}
if (node->type == XML_ELEMENT_NODE){
- fprintf(stderr, "%s => %s\n", node->name, xmlNodeGetContent(node));
- g_hash_table_insert(hash, g_strdup(node->name), g_strdup(xmlNodeGetContent(node)));
+ //fprintf(stderr, "%s => %s\n", node->name, xmlNodeGetContent(node));
+ g_hash_table_insert(hash, g_strdup((gchar*)node->name), g_strdup((gchar*)xmlNodeGetContent(node)));
}
}
if (!(g_hash_table_lookup(hash, "category")))
- g_hash_table_insert(hash, g_strdup("category"), g_strdup("Unknown"));
+ g_hash_table_insert(hash, g_strdup("category"), g_strdup("Unknown"));
+ if (!(g_hash_table_lookup(hash, "name")))
+ g_hash_table_insert(hash, g_strdup("name"), g_strdup("Unknown"));
+
xmlFreeDoc(doc);
xmlCleanupParser();
return hash;
}
+/*******************************************************************************/
+gint compar (gpointer a, gpointer b){
+ return strcmp( (g_hash_table_lookup(a, "name")), (g_hash_table_lookup(b, "name")) );
+}
+
+
GSList *
get_list_exthemes(void){
Dirent *dp;
DIR *dir_fd;
GSList *store = NULL;
+ GHashTable *hash = NULL;
dir_fd = opendir(EXTHEME_PATH);
if(dir_fd){
if(!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
continue;
+ /* TO DO read only *.xml files */
if(dp->d_type == DT_REG || dp->d_type == DT_LNK){
- store = g_slist_append(store, parse_theme(g_strdup_printf("%s%s", EXTHEME_PATH, dp->d_name)));
+ hash = parse_theme(g_strdup_printf("%s%s", EXTHEME_PATH, dp->d_name));
+ if (hash)
+ store = g_slist_append(store, hash);
}
}
closedir(dir_fd);
}
+ store = g_slist_sort(store, (GCompareFunc)compar);
return store;
}