changed license to GPL v2
[livewp] / applet / src / livewp-exthemes.c
index 84b9256..677f8d7 100644 (file)
@@ -7,8 +7,8 @@
  *       for the code
  * 
  * This software is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of
  * the License, or (at your option) any later version.
  * 
  * This software is distributed in the hope that it will be useful, but
 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){
@@ -40,7 +44,7 @@ parse_theme(gchar *file){
         //}
         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)));
+            g_hash_table_insert(hash, g_strdup((gchar*)node->name), g_strdup((gchar*)xmlNodeGetContent(node)));
         }
     }
     if (!(g_hash_table_lookup(hash, "category")))
@@ -64,6 +68,7 @@ get_list_exthemes(void){
     Dirent  *dp;
     DIR     *dir_fd;
     GSList *store = NULL;
+    GHashTable *hash = NULL;
     
     dir_fd = opendir(EXTHEME_PATH);
     if(dir_fd){
@@ -74,11 +79,13 @@ get_list_exthemes(void){
                 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, compar);
+    store = g_slist_sort(store, (GCompareFunc)compar);
     return store;
 }